##// END OF EJS Templates
percent bar chart
sauimone -
r101:5389336c8e0d
parent child
Show More
@@ -0,0 +1,6
1 #include "chartwidget.h"
2
3 ChartWidget::ChartWidget(QWidget *parent) :
4 QChartView(parent)
5 {
6 }
@@ -0,0 +1,21
1 #ifndef CHARTWIDGET_H
2 #define CHARTWIDGET_H
3
4 #include <qchartview.h>
5
6 QTCOMMERCIALCHART_USE_NAMESPACE
7
8
9 class ChartWidget : public QChartView
10 {
11 Q_OBJECT
12 public:
13 explicit ChartWidget(QWidget *parent = 0);
14
15 signals:
16
17 public slots:
18
19 };
20
21 #endif // CHARTWIDGET_H
@@ -0,0 +1,88
1 #include <QApplication>
2 #include <QMainWindow>
3 #include <QStandardItemModel>
4 #include <percentbarchartseries.h>
5 #include "chartwidget.h"
6
7 QTCOMMERCIALCHART_USE_NAMESPACE
8
9 int main(int argc, char *argv[])
10 {
11 QApplication a(argc, argv);
12 QMainWindow window;
13
14 PercentBarChartSeries* series0 = new PercentBarChartSeries();
15
16 // Create some test data to chart
17 QStandardItemModel dataModel(5,10);
18 QModelIndex index;
19 index = dataModel.index(0,0);
20
21 // Series 0
22 dataModel.setData(dataModel.index(0,0),1);
23 dataModel.setData(dataModel.index(0,1),2);
24 dataModel.setData(dataModel.index(0,2),3);
25 dataModel.setData(dataModel.index(0,3),4);
26 dataModel.setData(dataModel.index(0,4),5);
27 dataModel.setData(dataModel.index(0,5),6);
28 dataModel.setData(dataModel.index(0,6),7);
29 dataModel.setData(dataModel.index(0,7),8);
30 dataModel.setData(dataModel.index(0,8),9);
31 dataModel.setData(dataModel.index(0,9),10);
32
33 // Series 1, some other items missing
34 dataModel.setData(dataModel.index(1,0),5);
35 dataModel.setData(dataModel.index(1,3),4);
36 dataModel.setData(dataModel.index(1,5),7);
37 dataModel.setData(dataModel.index(1,6),8);
38 dataModel.setData(dataModel.index(1,8),9);
39 dataModel.setData(dataModel.index(1,9),9);
40
41 // Series 2
42 dataModel.setData(dataModel.index(2,0),3);
43 dataModel.setData(dataModel.index(2,1),5);
44 dataModel.setData(dataModel.index(2,2),8);
45 dataModel.setData(dataModel.index(2,3),13);
46 dataModel.setData(dataModel.index(2,4),8);
47 dataModel.setData(dataModel.index(2,5),5);
48 dataModel.setData(dataModel.index(2,6),3);
49 dataModel.setData(dataModel.index(2,7),2);
50 dataModel.setData(dataModel.index(2,8),1);
51 dataModel.setData(dataModel.index(2,9),1);
52
53 // Series 3
54 dataModel.setData(dataModel.index(3,0),5);
55 dataModel.setData(dataModel.index(3,1),6);
56 dataModel.setData(dataModel.index(3,2),7);
57 dataModel.setData(dataModel.index(3,3),3);
58 dataModel.setData(dataModel.index(3,4),4);
59 dataModel.setData(dataModel.index(3,5),5);
60 dataModel.setData(dataModel.index(3,6),8);
61 dataModel.setData(dataModel.index(3,7),9);
62 dataModel.setData(dataModel.index(3,8),10);
63 dataModel.setData(dataModel.index(3,9),5);
64
65 // Series 4
66 dataModel.setData(dataModel.index(4,0),9);
67 dataModel.setData(dataModel.index(4,1),7);
68 dataModel.setData(dataModel.index(4,2),5);
69 dataModel.setData(dataModel.index(4,3),3);
70 dataModel.setData(dataModel.index(4,4),1);
71 dataModel.setData(dataModel.index(4,5),2);
72 dataModel.setData(dataModel.index(4,6),4);
73 dataModel.setData(dataModel.index(4,7),6);
74 dataModel.setData(dataModel.index(4,8),8);
75 dataModel.setData(dataModel.index(4,9),10);
76
77 series0->setData(&dataModel);
78
79 ChartWidget* chartWidget = new ChartWidget(&window);
80 chartWidget->addSeries(series0);
81
82 window.setCentralWidget(chartWidget);
83 window.resize(400, 300);
84 window.show();
85
86 return a.exec();
87 }
88
@@ -0,0 +1,17
1 !include( ../../common.pri ) {
2 error( "Couldn't find the common.pri file!" )
3 }
4
5 !include( ../../integrated.pri ) {
6 error( "Couldn't find the integrated.pri file !")
7 }
8
9 TARGET = percentbarchart
10 TEMPLATE = app
11 QT += core gui
12 SOURCES += main.cpp \
13 chartwidget.cpp
14
15 HEADERS += \
16 chartwidget.h
17
@@ -0,0 +1,110
1 #include "percentbarchartseries.h"
2
3 #include <limits.h>
4 #include <QDebug>
5 #include "percentbarchartseries.h"
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
9 PercentBarChartSeries::PercentBarChartSeries(QObject *parent) :
10 QChartSeries(parent)
11 {
12 }
13
14 bool PercentBarChartSeries::setData(QAbstractItemModel* model)
15 {
16 mModel = model;
17 }
18
19 int PercentBarChartSeries::min()
20 {
21 Q_ASSERT(mModel->rowCount() > 0);
22 Q_ASSERT(mModel->columnCount() > 0);
23
24 // TODO: make min and max members and update them when data changes.
25 // This is slower since they are checked every time, even if data is same since previous call.
26 int min = INT_MAX;
27
28 for (int i=0; i <mModel->rowCount(); i++) {
29 for(int j=0; j<mModel->columnCount(); j++) {
30 int temp = mModel->data(mModel->index(i,j)).toInt();
31 if (temp < min) {
32 min = temp;
33 }
34 }
35 }
36 return min;
37 }
38
39 int PercentBarChartSeries::max()
40 {
41 Q_ASSERT(mModel->rowCount() > 0);
42 Q_ASSERT(mModel->columnCount() > 0);
43
44 // TODO: make min and max members and update them when data changes.
45 // This is slower since they are checked every time, even if data is same since previous call.
46 int max = INT_MIN;
47
48 for (int i=0; i <mModel->rowCount(); i++) {
49 for(int j=0; j<mModel->columnCount(); j++) {
50 int temp = mModel->data(mModel->index(i,j)).toInt();
51 if (temp > max) {
52 max = temp;
53 }
54 }
55 }
56 return max;
57 }
58
59 int PercentBarChartSeries::maxColumnSum()
60 {
61 Q_ASSERT(mModel->rowCount() > 0);
62 Q_ASSERT(mModel->columnCount() > 0);
63
64 int max = INT_MIN;
65
66 for (int col=0; col <mModel->columnCount(); col++) {
67 int sum = columnSum(col);
68 if (sum > max) {
69 max = sum;
70 }
71 }
72 return max;
73 }
74
75 int PercentBarChartSeries::countRows()
76 {
77 return mModel->rowCount();
78 }
79
80 int PercentBarChartSeries::countColumns()
81 {
82 return mModel->columnCount();
83 }
84
85 int PercentBarChartSeries::countTotalItems()
86 {
87 return mModel->rowCount() * mModel->columnCount();
88 }
89
90 int PercentBarChartSeries::valueAt(int row, int column)
91 {
92 QModelIndex index = mModel->index(row,column);
93 return mModel->data(index).toInt();
94 }
95
96 int PercentBarChartSeries::columnSum(int column)
97 {
98 int sum(0);
99 int count = mModel->rowCount();
100
101 for (int row = 0; row < count; row++) {
102 sum += mModel->data(mModel->index(row,column)).toInt();
103 }
104 return sum;
105 }
106
107 #include "moc_percentbarchartseries.cpp"
108
109 QTCOMMERCIALCHART_END_NAMESPACE
110
@@ -0,0 +1,47
1 #ifndef PERCENTBARCHARTSERIES_H
2 #define PERCENTBARCHARTSERIES_H
3
4 #include <QList>
5 #include <QAbstractItemModel>
6 #include "qchartseries.h"
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10 class PercentBarGroup;
11
12 class QTCOMMERCIALCHART_EXPORT PercentBarChartSeries : public QChartSeries
13 {
14 Q_OBJECT
15 public:
16 PercentBarChartSeries(QObject* parent=0);
17
18 // from QChartSeries
19 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; }
20
21 // TODO: Better data model?
22 virtual bool setData(QAbstractItemModel* model);
23
24 // Methods to find out minimum and maximum values of data
25 int min();
26 int max();
27 int maxColumnSum(); // returns maximum sum of items in all columns.
28
29 int countRows();
30 int countColumns();
31 int countTotalItems();
32 int valueAt(int row, int column);
33
34 int columnSum(int column);
35
36 public Q_SLOTS:
37
38 private:
39
40 QAbstractItemModel* mModel;
41 PercentBarGroup* mPercentBarGroup;
42 };
43
44 QTCOMMERCIALCHART_END_NAMESPACE
45
46
47 #endif // PERCENTBARCHARTSERIES_H
@@ -0,0 +1,136
1 #include "percentbargroup.h"
2
3 #include "stackedbargroup.h"
4 #include "bar.h"
5 #include <QDebug>
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
9 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) :
10 ChartItem(parent)
11 ,mSeries(series)
12 ,mLayoutSet(false)
13 ,mLayoutDirty(true)
14 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
15 {
16 dataChanged();
17 }
18
19
20 void StackedBarGroup::setSize(const QSize& size)
21 {
22 qDebug() << "StackedBarGroup::setSize";
23 mWidth = size.width();
24 mHeight = size.height();
25 layoutChanged();
26 mLayoutSet = true;
27 }
28
29 void StackedBarGroup::setPlotDomain(const PlotDomain& data)
30 {
31 qDebug() << "StackedBarGroup::setPlotDomain";
32 // TODO:
33 }
34
35 void StackedBarGroup::setBarWidth( int w )
36 {
37 mBarDefaultWidth = w;
38 }
39
40 int StackedBarGroup::addColor( QColor color )
41 {
42 int colorIndex = mColors.count();
43 mColors.append(color);
44 return colorIndex;
45 }
46
47 void StackedBarGroup::resetColors()
48 {
49 mColors.clear();
50 }
51
52 void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
53 {
54 if (!mLayoutSet) {
55 qDebug() << "QBarChart::paint called without layout set. Aborting.";
56 return;
57 }
58 if (mLayoutDirty) {
59 // Layout or data has changed. Need to redraw.
60 foreach(QGraphicsItem* i, childItems()) {
61 i->paint(painter,option,widget);
62 }
63 }
64 }
65
66 QRectF StackedBarGroup::boundingRect() const
67 {
68 return QRectF(0,0,mWidth,mHeight);
69 }
70
71
72 void StackedBarGroup::dataChanged()
73 {
74 qDebug() << "QBarChart::dataChanged mSeries";
75
76 // Find out maximum and minimum of all series
77 mMax = mSeries.max();
78 mMin = mSeries.min();
79
80 // Delete old bars
81 // Is this correct way to delete childItems?
82 foreach (QGraphicsItem* item, childItems()) {
83 delete item;
84 }
85
86 // Create new graphic items for bars
87 int totalItems = mSeries.countTotalItems();
88 for (int i=0; i<totalItems; i++) {
89 Bar *bar = new Bar(this);
90 childItems().append(bar);
91 }
92
93 mLayoutDirty = true;
94 }
95
96 void StackedBarGroup::layoutChanged()
97 {
98 // Scale bars to new layout
99 // Layout for bars:
100 if (mSeries.countRows() <= 0) {
101 // Nothing to do.
102 return;
103 }
104
105 // TODO: better way to auto-layout
106 // Use reals for accurancy (we might get some compiler warnings... :)
107 qreal maxSum = mSeries.maxColumnSum();
108 qreal h = mHeight;
109 qreal scale = (h / maxSum);
110
111 int count = mSeries.countColumns();
112 int itemIndex(0);
113 qreal tW = mWidth;
114 qreal tC = count+1;
115 qreal xStep = (tW/tC);
116 qreal xPos = ((tW/tC) + mBarDefaultWidth / 2);
117
118 for (int column = 0; column < mSeries.countColumns(); column++) {
119 qreal yPos = h;
120 for (int row=0; row < mSeries.countRows(); row++) {
121 qreal barHeight = mSeries.valueAt(row, column) * scale;
122 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
123
124 // TODO: width settable per bar?
125 bar->resize(mBarDefaultWidth, barHeight);
126 bar->setColor(mColors.at(row));
127 bar->setPos(xPos, yPos);
128 itemIndex++;
129 yPos -= barHeight;
130 }
131 xPos += xStep;
132 }
133 mLayoutDirty = true;
134 }
135
136 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,55
1 #ifndef PERCENTBARGROUP_H
2 #define PERCENTBARGROUP_H
3
4 #include "chartitem_p.h"
5 #include "bar.h"
6 #include "percentbarchartseries.h"
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10 class PercentBarGroup : public ChartItem
11 {
12 public:
13 PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent = 0);
14
15 // From ChartItem
16 virtual void setSize(const QSize& size);
17 virtual void setPlotDomain(const PlotDomain& data);
18
19 // Layout "api"
20 void setPos(qreal x, qreal y);
21 void setBarWidth( int w ); // Default width for each bar
22
23 int addColor( QColor color );
24 void resetColors();
25
26 // From QGraphicsItem
27 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
28 QRectF boundingRect() const;
29
30 private:
31
32 void dataChanged(); // data of series has changed -> need to recalculate bar sizes
33 void layoutChanged(); // layout has changed -> need to recalculate bar sizes
34
35 private:
36
37 // Data
38 PercentBarChartSeries& mSeries;
39 int mMin; // Min and max values of data. (updated when data is changed, used when drawing)
40 int mMax;
41
42 int mHeight; // Layout spesific
43 int mWidth;
44 int mBarDefaultWidth;
45
46 bool mLayoutSet; // True, if component has been laid out.
47 bool mLayoutDirty;
48
49 QList<QColor> mColors; // List of colors for series for now
50
51 };
52
53 QTCOMMERCIALCHART_END_NAMESPACE
54
55 #endif // PERCENTBARGROUP_H
@@ -28,6 +28,7 void BarGroup::setPlotDomain(const PlotDomain& data)
28 {
28 {
29 qDebug() << "BarGroup::setPlotDomain";
29 qDebug() << "BarGroup::setPlotDomain";
30 // TODO:
30 // TODO:
31 mPlotDomain = data;
31 }
32 }
32
33
33 void BarGroup::setBarWidth( int w )
34 void BarGroup::setBarWidth( int w )
@@ -100,7 +101,7 void BarGroup::layoutChanged()
100 return;
101 return;
101 }
102 }
102
103
103 // TODO: better way to auto-layout
104 // TODO: better way to auto-layout?
104 // Use reals for accurancy (we might get some compiler warnings... :)
105 // Use reals for accurancy (we might get some compiler warnings... :)
105 int columnCount = mSeries.countColumns();
106 int columnCount = mSeries.countColumns();
106 int rowCount = mSeries.countRows();
107 int rowCount = mSeries.countRows();
@@ -113,17 +114,12 void BarGroup::layoutChanged()
113 qreal tC = columnCount+1;
114 qreal tC = columnCount+1;
114 qreal xStepPerSeries = (tW/tC);
115 qreal xStepPerSeries = (tW/tC);
115
116
116 //qint startPos = (mWidth / (count+1)) - mSeries.countSeries() * mBarDefaultWidth /2;
117 // qDebug() << "XPOS:" << xPos;
118
119 qDebug() << "XSTEP:" << xStepPerSeries;
117 qDebug() << "XSTEP:" << xStepPerSeries;
120
118
121 // TODO: Correct the calculations...
122 // Scaling.
119 // Scaling.
123 int itemIndex(0);
120 int itemIndex(0);
124 for (int column=0; column < columnCount; column++) {
121 for (int column=0; column < columnCount; column++) {
125 qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2));
122 qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2));
126 qDebug() << "XPOS:" << xPos;
127 for (int row = 0; row < rowCount; row++) {
123 for (int row = 0; row < rowCount; row++) {
128 qreal barHeight = mSeries.valueAt(row, column) * scale;
124 qreal barHeight = mSeries.valueAt(row, column) * scale;
129 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
125 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
@@ -137,22 +133,6 void BarGroup::layoutChanged()
137 }
133 }
138 }
134 }
139
135
140 /*
141 for (int series = 0; series < mSeries.countRows(); series++) {
142 for (int item=0; item < mSeries.countColumns(); item++) {
143 qreal barHeight = mSeries.valueAt(series, item) * scale;
144 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
145
146 // TODO: width settable per bar?
147 bar->resize(mBarDefaultWidth, barHeight);
148 bar->setColor(mColors.at(series));
149 bar->setPos(xPos, mHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight);
150 itemIndex++;
151 xPos += mBarDefaultWidth;
152 }
153 xPos = xStepPerSeries * series;
154 }
155 */
156 mLayoutDirty = true;
136 mLayoutDirty = true;
157 }
137 }
158
138
@@ -47,6 +47,8 private:
47 bool mLayoutDirty;
47 bool mLayoutDirty;
48
48
49 QList<QColor> mColors; // List of colors for series for now
49 QList<QColor> mColors; // List of colors for series for now
50
51 PlotDomain mPlotDomain;
50 };
52 };
51
53
52 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,10 +1,10
1 #include "stackedbargroup.h"
1 #include "percentbargroup.h"
2 #include "bar.h"
2 #include "bar.h"
3 #include <QDebug>
3 #include <QDebug>
4
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) :
7 PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) :
8 ChartItem(parent)
8 ChartItem(parent)
9 ,mSeries(series)
9 ,mSeries(series)
10 ,mLayoutSet(false)
10 ,mLayoutSet(false)
@@ -15,39 +15,39 StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *p
15 }
15 }
16
16
17
17
18 void StackedBarGroup::setSize(const QSize& size)
18 void PercentBarGroup::setSize(const QSize& size)
19 {
19 {
20 qDebug() << "StackedBarGroup::setSize";
20 qDebug() << "PercentBarGroup::setSize";
21 mWidth = size.width();
21 mWidth = size.width();
22 mHeight = size.height();
22 mHeight = size.height();
23 layoutChanged();
23 layoutChanged();
24 mLayoutSet = true;
24 mLayoutSet = true;
25 }
25 }
26
26
27 void StackedBarGroup::setPlotDomain(const PlotDomain& data)
27 void PercentBarGroup::setPlotDomain(const PlotDomain& data)
28 {
28 {
29 qDebug() << "StackedBarGroup::setPlotDomain";
29 qDebug() << "PercentBarGroup::setPlotDomain";
30 // TODO:
30 // TODO:
31 }
31 }
32
32
33 void StackedBarGroup::setBarWidth( int w )
33 void PercentBarGroup::setBarWidth( int w )
34 {
34 {
35 mBarDefaultWidth = w;
35 mBarDefaultWidth = w;
36 }
36 }
37
37
38 int StackedBarGroup::addColor( QColor color )
38 int PercentBarGroup::addColor( QColor color )
39 {
39 {
40 int colorIndex = mColors.count();
40 int colorIndex = mColors.count();
41 mColors.append(color);
41 mColors.append(color);
42 return colorIndex;
42 return colorIndex;
43 }
43 }
44
44
45 void StackedBarGroup::resetColors()
45 void PercentBarGroup::resetColors()
46 {
46 {
47 mColors.clear();
47 mColors.clear();
48 }
48 }
49
49
50 void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
50 void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
51 {
51 {
52 if (!mLayoutSet) {
52 if (!mLayoutSet) {
53 qDebug() << "QBarChart::paint called without layout set. Aborting.";
53 qDebug() << "QBarChart::paint called without layout set. Aborting.";
@@ -61,13 +61,13 void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
61 }
61 }
62 }
62 }
63
63
64 QRectF StackedBarGroup::boundingRect() const
64 QRectF PercentBarGroup::boundingRect() const
65 {
65 {
66 return QRectF(0,0,mWidth,mHeight);
66 return QRectF(0,0,mWidth,mHeight);
67 }
67 }
68
68
69
69
70 void StackedBarGroup::dataChanged()
70 void PercentBarGroup::dataChanged()
71 {
71 {
72 qDebug() << "QBarChart::dataChanged mSeries";
72 qDebug() << "QBarChart::dataChanged mSeries";
73
73
@@ -91,7 +91,7 void StackedBarGroup::dataChanged()
91 mLayoutDirty = true;
91 mLayoutDirty = true;
92 }
92 }
93
93
94 void StackedBarGroup::layoutChanged()
94 void PercentBarGroup::layoutChanged()
95 {
95 {
96 // Scale bars to new layout
96 // Scale bars to new layout
97 // Layout for bars:
97 // Layout for bars:
@@ -102,10 +102,6 void StackedBarGroup::layoutChanged()
102
102
103 // TODO: better way to auto-layout
103 // TODO: better way to auto-layout
104 // Use reals for accurancy (we might get some compiler warnings... :)
104 // Use reals for accurancy (we might get some compiler warnings... :)
105 qreal maxSum = mSeries.maxColumnSum();
106 qreal h = mHeight;
107 qreal scale = (h / maxSum);
108
109 int count = mSeries.countColumns();
105 int count = mSeries.countColumns();
110 int itemIndex(0);
106 int itemIndex(0);
111 qreal tW = mWidth;
107 qreal tW = mWidth;
@@ -114,6 +110,9 void StackedBarGroup::layoutChanged()
114 qreal xPos = ((tW/tC) + mBarDefaultWidth / 2);
110 qreal xPos = ((tW/tC) + mBarDefaultWidth / 2);
115
111
116 for (int column = 0; column < mSeries.countColumns(); column++) {
112 for (int column = 0; column < mSeries.countColumns(); column++) {
113 qreal colSum = mSeries.columnSum(column);
114 qreal h = mHeight;
115 qreal scale = (h / colSum);
117 qreal yPos = h;
116 qreal yPos = h;
118 for (int row=0; row < mSeries.countRows(); row++) {
117 for (int row=0; row < mSeries.countRows(); row++) {
119 qreal barHeight = mSeries.valueAt(row, column) * scale;
118 qreal barHeight = mSeries.valueAt(row, column) * scale;
@@ -9,6 +9,8
9 #include "bargroup.h"
9 #include "bargroup.h"
10 #include "stackedbarchartseries.h"
10 #include "stackedbarchartseries.h"
11 #include "stackedbargroup.h"
11 #include "stackedbargroup.h"
12 #include "percentbarchartseries.h"
13 #include "percentbargroup.h"
12
14
13 #include "xylinechartitem_p.h"
15 #include "xylinechartitem_p.h"
14 #include "plotdomain_p.h"
16 #include "plotdomain_p.h"
@@ -115,6 +117,23 void QChart::addSeries(QChartSeries* series)
115 childItems().append(stackedBarGroup);
117 childItems().append(stackedBarGroup);
116 break;
118 break;
117 }
119 }
120 case QChartSeries::SeriesTypePercentBar: {
121
122 qDebug() << "barSeries added";
123 PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
124 PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this);
125
126 // Add some fugly colors for 5 fist series...
127 percentBarGroup->addColor(QColor(255,0,0,128));
128 percentBarGroup->addColor(QColor(255,255,0,128));
129 percentBarGroup->addColor(QColor(0,255,0,128));
130 percentBarGroup->addColor(QColor(0,0,255,128));
131 percentBarGroup->addColor(QColor(255,128,0,128));
132
133 m_chartItems<<percentBarGroup;
134 childItems().append(percentBarGroup);
135 break;
136 }
118 case QChartSeries::SeriesTypeScatter: {
137 case QChartSeries::SeriesTypeScatter: {
119 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
138 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
120 scatterSeries->d->setParentItem(this);
139 scatterSeries->d->setParentItem(this);
@@ -164,6 +183,10 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
164 series = new StackedBarChartSeries(this);
183 series = new StackedBarChartSeries(this);
165 break;
184 break;
166 }
185 }
186 case QChartSeries::SeriesTypePercentBar: {
187 series = new PercentBarChartSeries(this);
188 break;
189 }
167 case QChartSeries::SeriesTypeScatter: {
190 case QChartSeries::SeriesTypeScatter: {
168 series = new QScatterSeries(this);
191 series = new QScatterSeries(this);
169 break;
192 break;
@@ -16,6 +16,7 public:
16 // SeriesTypeArea,
16 // SeriesTypeArea,
17 SeriesTypeBar,
17 SeriesTypeBar,
18 SeriesTypeStackedBar,
18 SeriesTypeStackedBar,
19 SeriesTypePercentBar,
19 SeriesTypePie,
20 SeriesTypePie,
20 SeriesTypeScatter
21 SeriesTypeScatter
21 // SeriesTypeSpline
22 // SeriesTypeSpline
@@ -17,6 +17,8 SOURCES += \
17 barchart/bar.cpp \
17 barchart/bar.cpp \
18 barchart/stackedbarchartseries.cpp \
18 barchart/stackedbarchartseries.cpp \
19 barchart/stackedbargroup.cpp \
19 barchart/stackedbargroup.cpp \
20 barchart/percentbarchartseries.cpp \
21 barchart/percentbargroup.cpp \
20 xylinechart/qxychartseries.cpp \
22 xylinechart/qxychartseries.cpp \
21 xylinechart/xylinechartitem.cpp \
23 xylinechart/xylinechartitem.cpp \
22 plotdomain.cpp \
24 plotdomain.cpp \
@@ -50,6 +52,8 PUBLIC_HEADERS += \
50 barchart/bargroup.h \
52 barchart/bargroup.h \
51 barchart/stackedbarchartseries.h \
53 barchart/stackedbarchartseries.h \
52 barchart/stackedbargroup.h \
54 barchart/stackedbargroup.h \
55 barchart/percentbarchartseries.h \
56 barchart/percentbargroup.h \
53 qchartview.h \
57 qchartview.h \
54 qchartaxis.h
58 qchartaxis.h
55
59
General Comments 0
You need to be logged in to leave comments. Login now