Changeset - 224950d13c1d
[Not reviewed]
barplot
0 3 0
Hasan Yavuz Ă–ZDERYA - 8 years ago 2017-10-07 09:14:03
hy@ozderya.net
set border color for bars according to background
3 files changed with 14 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/barchart.cpp
Show inline comments
 
@@ -30,12 +30,17 @@ BarChart::BarChart(ChannelManager* chann
 

	
 
void BarChart::resample()
 
{
 
    setSamples(chartData());
 
}
 

	
 
void BarChart::setBorderColor(QColor color)
 
{
 
    borderColor = color;
 
}
 

	
 
QVector<double> BarChart::chartData() const
 
{
 
    unsigned numChannels = _channelMan->numOfChannels();
 
    unsigned numOfSamples = _channelMan->numOfSamples();
 
    QVector<double> data(numChannels);
 
    for (unsigned i = 0; i < numChannels; i++)
 
@@ -56,13 +61,15 @@ QwtColumnSymbol* BarChart::specialSymbol
 
    auto info = _channelMan->infoModel();
 
    auto color = info->color(sampleIndex);
 

	
 
    QwtColumnSymbol* symbol = new QwtColumnSymbol(QwtColumnSymbol::Box);
 
    symbol->setLineWidth(1);
 
    symbol->setFrameStyle(QwtColumnSymbol::Plain);
 
    symbol->setPalette(QPalette(color));
 
    QPalette pal(color);
 
    pal.setColor(QPalette::Dark, borderColor);
 
    symbol->setPalette(pal);
 

	
 
    return symbol;
 
}
 

	
 
void BarChart::drawSample(
 
        QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap,
src/barchart.h
Show inline comments
 
@@ -17,31 +17,35 @@
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef BARCHART_H
 
#define BARCHART_H
 

	
 
#include <QColor>
 
#include <qwt_plot_barchart.h>
 
#include <qwt_column_symbol.h>
 
#include "channelmanager.h"
 

	
 
class BarChart : public QwtPlotBarChart
 
{
 
public:
 
    explicit BarChart(ChannelManager* channelMan);
 

	
 
    void resample();
 
    void setBorderColor(QColor color);
 

	
 
    QwtColumnSymbol* specialSymbol(int sampleIndex, const QPointF&) const;
 

	
 
    void drawSample(
 
        QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap,
 
        const QRectF &canvasRect, const QwtInterval &boundingInterval,
 
        int index, const QPointF &sample ) const;
 

	
 
private:
 
    ChannelManager* _channelMan;
 
    QColor borderColor;
 

	
 
    QVector<double> chartData() const;
 
};
 

	
 

	
 
#endif // BARCHART_H
src/barplot.cpp
Show inline comments
 
@@ -43,13 +43,15 @@ void BarPlot::update()
 

	
 
void BarPlot::darkBackground(bool enabled)
 
{
 
    if (enabled)
 
    {
 
        setCanvasBackground(QBrush(Qt::black));
 
        barChart.setBorderColor(Qt::white);
 
    }
 
    else
 
    {
 
        setCanvasBackground(QBrush(Qt::white));
 
        barChart.setBorderColor(Qt::black);
 
    }
 
    replot();
 
}
0 comments (0 inline, 0 general)