##// 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
@@ -1,159 +1,139
1 #include "bargroup.h"
1 #include "bargroup.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 BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) :
7 BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) :
8 ChartItem(parent)
8 ChartItem(parent)
9 ,mSeries(series)
9 ,mSeries(series)
10 ,mLayoutSet(false)
10 ,mLayoutSet(false)
11 ,mLayoutDirty(true)
11 ,mLayoutDirty(true)
12 ,mBarDefaultWidth(10)
12 ,mBarDefaultWidth(10)
13 {
13 {
14 dataChanged();
14 dataChanged();
15 }
15 }
16
16
17
17
18 void BarGroup::setSize(const QSize& size)
18 void BarGroup::setSize(const QSize& size)
19 {
19 {
20 qDebug() << "BarGroup::setSize";
20 qDebug() << "BarGroup::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 BarGroup::setPlotDomain(const PlotDomain& data)
27 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 )
34 {
35 {
35 mBarDefaultWidth = w;
36 mBarDefaultWidth = w;
36 }
37 }
37
38
38 int BarGroup::addColor( QColor color )
39 int BarGroup::addColor( QColor color )
39 {
40 {
40 int colorIndex = mColors.count();
41 int colorIndex = mColors.count();
41 mColors.append(color);
42 mColors.append(color);
42 return colorIndex;
43 return colorIndex;
43 }
44 }
44
45
45 void BarGroup::resetColors()
46 void BarGroup::resetColors()
46 {
47 {
47 mColors.clear();
48 mColors.clear();
48 }
49 }
49
50
50 void BarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
51 void BarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
51 {
52 {
52 if (!mLayoutSet) {
53 if (!mLayoutSet) {
53 qDebug() << "QBarChart::paint called without layout set. Aborting.";
54 qDebug() << "QBarChart::paint called without layout set. Aborting.";
54 return;
55 return;
55 }
56 }
56 if (mLayoutDirty) {
57 if (mLayoutDirty) {
57 // Layout or data has changed. Need to redraw.
58 // Layout or data has changed. Need to redraw.
58 foreach(QGraphicsItem* i, childItems()) {
59 foreach(QGraphicsItem* i, childItems()) {
59 i->paint(painter,option,widget);
60 i->paint(painter,option,widget);
60 }
61 }
61 }
62 }
62 }
63 }
63
64
64 QRectF BarGroup::boundingRect() const
65 QRectF BarGroup::boundingRect() const
65 {
66 {
66 return QRectF(0,0,mWidth,mHeight);
67 return QRectF(0,0,mWidth,mHeight);
67 }
68 }
68
69
69
70
70 void BarGroup::dataChanged()
71 void BarGroup::dataChanged()
71 {
72 {
72 qDebug() << "QBarChart::dataChanged mSeries";
73 qDebug() << "QBarChart::dataChanged mSeries";
73
74
74 // Find out maximum and minimum of all series
75 // Find out maximum and minimum of all series
75 mMax = mSeries.max();
76 mMax = mSeries.max();
76 mMin = mSeries.min();
77 mMin = mSeries.min();
77
78
78 // Delete old bars
79 // Delete old bars
79 // Is this correct way to delete childItems?
80 // Is this correct way to delete childItems?
80 foreach (QGraphicsItem* item, childItems()) {
81 foreach (QGraphicsItem* item, childItems()) {
81 delete item;
82 delete item;
82 }
83 }
83
84
84 // Create new graphic items for bars
85 // Create new graphic items for bars
85 int totalItems = mSeries.countTotalItems();
86 int totalItems = mSeries.countTotalItems();
86 for (int i=0; i<totalItems; i++) {
87 for (int i=0; i<totalItems; i++) {
87 Bar *bar = new Bar(this);
88 Bar *bar = new Bar(this);
88 childItems().append(bar);
89 childItems().append(bar);
89 }
90 }
90
91
91 mLayoutDirty = true;
92 mLayoutDirty = true;
92 }
93 }
93
94
94 void BarGroup::layoutChanged()
95 void BarGroup::layoutChanged()
95 {
96 {
96 // Scale bars to new layout
97 // Scale bars to new layout
97 // Layout for bars:
98 // Layout for bars:
98 if (mSeries.countRows() <= 0) {
99 if (mSeries.countRows() <= 0) {
99 // Nothing to do.
100 // Nothing to do.
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();
107
108
108 qreal tW = mWidth;
109 qreal tW = mWidth;
109 qreal tH = mHeight;
110 qreal tH = mHeight;
110 qreal tM = mMax;
111 qreal tM = mMax;
111 qreal scale = (tH/tM);
112 qreal scale = (tH/tM);
112
113
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));
130
126
131 // TODO: width settable per bar?
127 // TODO: width settable per bar?
132 bar->resize(mBarDefaultWidth, barHeight);
128 bar->resize(mBarDefaultWidth, barHeight);
133 bar->setColor(mColors.at(row));
129 bar->setColor(mColors.at(row));
134 bar->setPos(xPos, mHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight);
130 bar->setPos(xPos, mHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight);
135 itemIndex++;
131 itemIndex++;
136 xPos += mBarDefaultWidth;
132 xPos += mBarDefaultWidth;
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
159 QTCOMMERCIALCHART_END_NAMESPACE
139 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,54 +1,56
1 #ifndef QBARGROUP_H
1 #ifndef QBARGROUP_H
2 #define QBARGROUP_H
2 #define QBARGROUP_H
3
3
4 #include "chartitem_p.h"
4 #include "chartitem_p.h"
5 #include "bar.h"
5 #include "bar.h"
6 #include "barchartseries.h"
6 #include "barchartseries.h"
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class BarGroup : public ChartItem
10 class BarGroup : public ChartItem
11 {
11 {
12 public:
12 public:
13 explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0);
13 explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0);
14
14
15 // From ChartItem
15 // From ChartItem
16 virtual void setSize(const QSize& size);
16 virtual void setSize(const QSize& size);
17 virtual void setPlotDomain(const PlotDomain& data);
17 virtual void setPlotDomain(const PlotDomain& data);
18
18
19 // Layout "api"
19 // Layout "api"
20 void setPos(qreal x, qreal y);
20 void setPos(qreal x, qreal y);
21 void setBarWidth( int w ); // Default width for each bar
21 void setBarWidth( int w ); // Default width for each bar
22
22
23 int addColor( QColor color );
23 int addColor( QColor color );
24 void resetColors();
24 void resetColors();
25
25
26 // From QGraphicsItem
26 // From QGraphicsItem
27 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
27 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
28 QRectF boundingRect() const;
28 QRectF boundingRect() const;
29
29
30 private:
30 private:
31
31
32 void dataChanged(); // data of series has changed -> need to recalculate bar sizes
32 void dataChanged(); // data of series has changed -> need to recalculate bar sizes
33 void layoutChanged(); // layout has changed -> need to recalculate bar sizes
33 void layoutChanged(); // layout has changed -> need to recalculate bar sizes
34
34
35 private:
35 private:
36
36
37 // Data
37 // Data
38 BarChartSeries& mSeries;
38 BarChartSeries& mSeries;
39 int mMin; // Min and max values of data. (updated when data is changed, used when drawing)
39 int mMin; // Min and max values of data. (updated when data is changed, used when drawing)
40 int mMax;
40 int mMax;
41
41
42 int mHeight; // Layout spesific
42 int mHeight; // Layout spesific
43 int mWidth;
43 int mWidth;
44 int mBarDefaultWidth;
44 int mBarDefaultWidth;
45
45
46 bool mLayoutSet; // True, if component has been laid out.
46 bool mLayoutSet; // True, if component has been laid out.
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
53
55
54 #endif // QBARGROUP_H
56 #endif // QBARGROUP_H
@@ -1,134 +1,133
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)
11 ,mLayoutDirty(true)
11 ,mLayoutDirty(true)
12 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
12 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
13 {
13 {
14 dataChanged();
14 dataChanged();
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.";
54 return;
54 return;
55 }
55 }
56 if (mLayoutDirty) {
56 if (mLayoutDirty) {
57 // Layout or data has changed. Need to redraw.
57 // Layout or data has changed. Need to redraw.
58 foreach(QGraphicsItem* i, childItems()) {
58 foreach(QGraphicsItem* i, childItems()) {
59 i->paint(painter,option,widget);
59 i->paint(painter,option,widget);
60 }
60 }
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
74 // Find out maximum and minimum of all series
74 // Find out maximum and minimum of all series
75 mMax = mSeries.max();
75 mMax = mSeries.max();
76 mMin = mSeries.min();
76 mMin = mSeries.min();
77
77
78 // Delete old bars
78 // Delete old bars
79 // Is this correct way to delete childItems?
79 // Is this correct way to delete childItems?
80 foreach (QGraphicsItem* item, childItems()) {
80 foreach (QGraphicsItem* item, childItems()) {
81 delete item;
81 delete item;
82 }
82 }
83
83
84 // Create new graphic items for bars
84 // Create new graphic items for bars
85 int totalItems = mSeries.countTotalItems();
85 int totalItems = mSeries.countTotalItems();
86 for (int i=0; i<totalItems; i++) {
86 for (int i=0; i<totalItems; i++) {
87 Bar *bar = new Bar(this);
87 Bar *bar = new Bar(this);
88 childItems().append(bar);
88 childItems().append(bar);
89 }
89 }
90
90
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:
98 if (mSeries.countRows() <= 0) {
98 if (mSeries.countRows() <= 0) {
99 // Nothing to do.
99 // Nothing to do.
100 return;
100 return;
101 }
101 }
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;
112 qreal tC = count+1;
108 qreal tC = count+1;
113 qreal xStep = (tW/tC);
109 qreal xStep = (tW/tC);
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;
120 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
119 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
121
120
122 // TODO: width settable per bar?
121 // TODO: width settable per bar?
123 bar->resize(mBarDefaultWidth, barHeight);
122 bar->resize(mBarDefaultWidth, barHeight);
124 bar->setColor(mColors.at(row));
123 bar->setColor(mColors.at(row));
125 bar->setPos(xPos, yPos);
124 bar->setPos(xPos, yPos);
126 itemIndex++;
125 itemIndex++;
127 yPos -= barHeight;
126 yPos -= barHeight;
128 }
127 }
129 xPos += xStep;
128 xPos += xStep;
130 }
129 }
131 mLayoutDirty = true;
130 mLayoutDirty = true;
132 }
131 }
133
132
134 QTCOMMERCIALCHART_END_NAMESPACE
133 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,427 +1,450
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartseries.h"
2 #include "qchartseries.h"
3 #include "qscatterseries.h"
3 #include "qscatterseries.h"
4 #include "qscatterseries_p.h"
4 #include "qscatterseries_p.h"
5 #include "qpieseries.h"
5 #include "qpieseries.h"
6 #include "qxychartseries.h"
6 #include "qxychartseries.h"
7 #include "qchartaxis.h"
7 #include "qchartaxis.h"
8 #include "barchartseries.h"
8 #include "barchartseries.h"
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"
15 #include "axisitem_p.h"
17 #include "axisitem_p.h"
16 #include <QGraphicsScene>
18 #include <QGraphicsScene>
17 #include <QDebug>
19 #include <QDebug>
18
20
19 QTCOMMERCIALCHART_BEGIN_NAMESPACE
21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
20
22
21 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
23 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
22 m_backgroundItem(0),
24 m_backgroundItem(0),
23 m_titleItem(0),
25 m_titleItem(0),
24 m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)),
26 m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)),
25 m_plotDataIndex(0),
27 m_plotDataIndex(0),
26 m_marginSize(0)
28 m_marginSize(0)
27 {
29 {
28 // TODO: the default theme?
30 // TODO: the default theme?
29 setTheme(QChart::ChartThemeDefault);
31 setTheme(QChart::ChartThemeDefault);
30
32
31 PlotDomain domain;
33 PlotDomain domain;
32 m_plotDomainList<<domain;
34 m_plotDomainList<<domain;
33 m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this);
35 m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this);
34 m_chartItems<<m_axisXItem;
36 m_chartItems<<m_axisXItem;
35 m_chartItems<<m_axisYItem.at(0);
37 m_chartItems<<m_axisYItem.at(0);
36 }
38 }
37
39
38 QChart::~QChart(){}
40 QChart::~QChart(){}
39
41
40 QRectF QChart::boundingRect() const
42 QRectF QChart::boundingRect() const
41 {
43 {
42 return m_rect;
44 return m_rect;
43 }
45 }
44
46
45 void QChart::addSeries(QChartSeries* series)
47 void QChart::addSeries(QChartSeries* series)
46 {
48 {
47 // TODO: we should check the series not already added
49 // TODO: we should check the series not already added
48
50
49 m_chartSeries << series;
51 m_chartSeries << series;
50
52
51 switch(series->type())
53 switch(series->type())
52 {
54 {
53 case QChartSeries::SeriesTypeLine: {
55 case QChartSeries::SeriesTypeLine: {
54
56
55 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
57 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
56 // Use color defined by theme in case the series does not define a custom color
58 // Use color defined by theme in case the series does not define a custom color
57
59
58 if (!xyseries->pen().color().isValid() && m_themeColors.count()) //TODO: wtf
60 if (!xyseries->pen().color().isValid() && m_themeColors.count()) //TODO: wtf
59 xyseries->setPen(nextColor());
61 xyseries->setPen(nextColor());
60
62
61 m_plotDataIndex = 0 ;
63 m_plotDataIndex = 0 ;
62 m_plotDomainList.resize(1);
64 m_plotDomainList.resize(1);
63
65
64 PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
66 PlotDomain& domain = m_plotDomainList[m_plotDataIndex];
65
67
66 for (int i = 0 ; i < xyseries->count() ; i++)
68 for (int i = 0 ; i < xyseries->count() ; i++)
67 {
69 {
68 qreal x = xyseries->x(i);
70 qreal x = xyseries->x(i);
69 qreal y = xyseries->y(i);
71 qreal y = xyseries->y(i);
70 domain.m_minX = qMin(domain.m_minX,x);
72 domain.m_minX = qMin(domain.m_minX,x);
71 domain.m_minY = qMin(domain.m_minY,y);
73 domain.m_minY = qMin(domain.m_minY,y);
72 domain.m_maxX = qMax(domain.m_maxX,x);
74 domain.m_maxX = qMax(domain.m_maxX,x);
73 domain.m_maxY = qMax(domain.m_maxY,y);
75 domain.m_maxY = qMax(domain.m_maxY,y);
74 }
76 }
75
77
76 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
78 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
77 m_chartItems<<item;
79 m_chartItems<<item;
78
80
79 foreach(ChartItem* i ,m_chartItems)
81 foreach(ChartItem* i ,m_chartItems)
80 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
82 i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex));
81
83
82 break;
84 break;
83 }
85 }
84 case QChartSeries::SeriesTypeBar: {
86 case QChartSeries::SeriesTypeBar: {
85
87
86 qDebug() << "barSeries added";
88 qDebug() << "barSeries added";
87 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
89 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
88 BarGroup* barGroup = new BarGroup(*barSeries,this);
90 BarGroup* barGroup = new BarGroup(*barSeries,this);
89
91
90 // Add some fugly colors for 5 fist series...
92 // Add some fugly colors for 5 fist series...
91 barGroup->addColor(QColor(255,0,0,128));
93 barGroup->addColor(QColor(255,0,0,128));
92 barGroup->addColor(QColor(255,255,0,128));
94 barGroup->addColor(QColor(255,255,0,128));
93 barGroup->addColor(QColor(0,255,0,128));
95 barGroup->addColor(QColor(0,255,0,128));
94 barGroup->addColor(QColor(0,0,255,128));
96 barGroup->addColor(QColor(0,0,255,128));
95 barGroup->addColor(QColor(255,128,0,128));
97 barGroup->addColor(QColor(255,128,0,128));
96
98
97 m_chartItems<<barGroup;
99 m_chartItems<<barGroup;
98 childItems().append(barGroup);
100 childItems().append(barGroup);
99 break;
101 break;
100 }
102 }
101 case QChartSeries::SeriesTypeStackedBar: {
103 case QChartSeries::SeriesTypeStackedBar: {
102
104
103 qDebug() << "barSeries added";
105 qDebug() << "barSeries added";
104 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
106 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
105 StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this);
107 StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this);
106
108
107 // Add some fugly colors for 5 fist series...
109 // Add some fugly colors for 5 fist series...
108 stackedBarGroup->addColor(QColor(255,0,0,128));
110 stackedBarGroup->addColor(QColor(255,0,0,128));
109 stackedBarGroup->addColor(QColor(255,255,0,128));
111 stackedBarGroup->addColor(QColor(255,255,0,128));
110 stackedBarGroup->addColor(QColor(0,255,0,128));
112 stackedBarGroup->addColor(QColor(0,255,0,128));
111 stackedBarGroup->addColor(QColor(0,0,255,128));
113 stackedBarGroup->addColor(QColor(0,0,255,128));
112 stackedBarGroup->addColor(QColor(255,128,0,128));
114 stackedBarGroup->addColor(QColor(255,128,0,128));
113
115
114 m_chartItems<<stackedBarGroup;
116 m_chartItems<<stackedBarGroup;
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);
121 // Set pre-defined colors in case the series has no colors defined
140 // Set pre-defined colors in case the series has no colors defined
122 if (!scatterSeries->markerColor().isValid())
141 if (!scatterSeries->markerColor().isValid())
123 scatterSeries->setMarkerColor(nextColor());
142 scatterSeries->setMarkerColor(nextColor());
124 connect(this, SIGNAL(sizeChanged(QRectF)),
143 connect(this, SIGNAL(sizeChanged(QRectF)),
125 scatterSeries, SLOT(chartSizeChanged(QRectF)));
144 scatterSeries, SLOT(chartSizeChanged(QRectF)));
126 // QColor nextColor = m_themeColors.takeFirst();
145 // QColor nextColor = m_themeColors.takeFirst();
127 // nextColor.setAlpha(150); // TODO: default opacity?
146 // nextColor.setAlpha(150); // TODO: default opacity?
128 // scatterSeries->setMarkerColor(nextColor);
147 // scatterSeries->setMarkerColor(nextColor);
129 break;
148 break;
130 }
149 }
131 case QChartSeries::SeriesTypePie: {
150 case QChartSeries::SeriesTypePie: {
132 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
151 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
133 for (int i(0); i < pieSeries->sliceCount(); i++) {
152 for (int i(0); i < pieSeries->sliceCount(); i++) {
134 if (!pieSeries->sliceColor(i).isValid())
153 if (!pieSeries->sliceColor(i).isValid())
135 pieSeries->setSliceColor(i, nextColor());
154 pieSeries->setSliceColor(i, nextColor());
136 }
155 }
137 connect(this, SIGNAL(sizeChanged(QRectF)),
156 connect(this, SIGNAL(sizeChanged(QRectF)),
138 pieSeries, SLOT(chartSizeChanged(QRectF)));
157 pieSeries, SLOT(chartSizeChanged(QRectF)));
139
158
140 // Set pre-defined colors in case the series has no colors defined
159 // Set pre-defined colors in case the series has no colors defined
141 // TODO: how to define the color for all the slices of a pie?
160 // TODO: how to define the color for all the slices of a pie?
142 // for (int (i); i < pieSeries.sliceCount(); i++)
161 // for (int (i); i < pieSeries.sliceCount(); i++)
143 break;
162 break;
144 }
163 }
145 }
164 }
146 }
165 }
147
166
148 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
167 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
149 {
168 {
150 // TODO: support also other types; not only scatter and pie
169 // TODO: support also other types; not only scatter and pie
151
170
152 QChartSeries *series(0);
171 QChartSeries *series(0);
153
172
154 switch (type) {
173 switch (type) {
155 case QChartSeries::SeriesTypeLine: {
174 case QChartSeries::SeriesTypeLine: {
156 series = QXYChartSeries::create();
175 series = QXYChartSeries::create();
157 break;
176 break;
158 }
177 }
159 case QChartSeries::SeriesTypeBar: {
178 case QChartSeries::SeriesTypeBar: {
160 series = new BarChartSeries(this);
179 series = new BarChartSeries(this);
161 break;
180 break;
162 }
181 }
163 case QChartSeries::SeriesTypeStackedBar: {
182 case QChartSeries::SeriesTypeStackedBar: {
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;
170 }
193 }
171 case QChartSeries::SeriesTypePie: {
194 case QChartSeries::SeriesTypePie: {
172 series = new QPieSeries(this);
195 series = new QPieSeries(this);
173 break;
196 break;
174 }
197 }
175 default:
198 default:
176 Q_ASSERT(false);
199 Q_ASSERT(false);
177 break;
200 break;
178 }
201 }
179
202
180 addSeries(series);
203 addSeries(series);
181 return series;
204 return series;
182 }
205 }
183
206
184 void QChart::setSize(const QSize& size)
207 void QChart::setSize(const QSize& size)
185 {
208 {
186 m_rect = QRect(QPoint(0,0),size);
209 m_rect = QRect(QPoint(0,0),size);
187 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
210 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
188
211
189 //recaculate title
212 //recaculate title
190 if(m_titleItem){
213 if(m_titleItem){
191 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
214 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
192 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
215 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
193
216
194 }
217 }
195
218
196 //recalculate background gradient
219 //recalculate background gradient
197 if(m_backgroundItem){
220 if(m_backgroundItem){
198 m_backgroundItem->setRect(rect);
221 m_backgroundItem->setRect(rect);
199 if(m_bacgroundOrinetation==HorizonatlGradientOrientation)
222 if(m_bacgroundOrinetation==HorizonatlGradientOrientation)
200 m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(),0);
223 m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(),0);
201 else
224 else
202 m_backgroundGradient.setFinalStop(0,m_backgroundItem->rect().height());
225 m_backgroundGradient.setFinalStop(0,m_backgroundItem->rect().height());
203
226
204 m_backgroundItem->setBrush(m_backgroundGradient);
227 m_backgroundItem->setBrush(m_backgroundGradient);
205 }
228 }
206
229
207 //resize elements
230 //resize elements
208 foreach (ChartItem* item ,m_chartItems) {
231 foreach (ChartItem* item ,m_chartItems) {
209 item->setPos(rect.topLeft());
232 item->setPos(rect.topLeft());
210 item->setSize(rect.size());
233 item->setSize(rect.size());
211
234
212 }
235 }
213 // TODO: TTD for setting scale
236 // TODO: TTD for setting scale
214 //emit scaleChanged(100, 100);
237 //emit scaleChanged(100, 100);
215 // TODO: calculate the origo
238 // TODO: calculate the origo
216 // TODO: not sure if emitting a signal here is the best from performance point of view
239 // TODO: not sure if emitting a signal here is the best from performance point of view
217 emit sizeChanged(QRectF(0, 0, size.width(), size.height()));
240 emit sizeChanged(QRectF(0, 0, size.width(), size.height()));
218
241
219 update();
242 update();
220 }
243 }
221
244
222 void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation)
245 void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation)
223 {
246 {
224
247
225 if(!m_backgroundItem){
248 if(!m_backgroundItem){
226 m_backgroundItem = new QGraphicsRectItem(this);
249 m_backgroundItem = new QGraphicsRectItem(this);
227 m_backgroundItem->setZValue(-1);
250 m_backgroundItem->setZValue(-1);
228 }
251 }
229
252
230 m_bacgroundOrinetation = orientation;
253 m_bacgroundOrinetation = orientation;
231 m_backgroundGradient.setColorAt( 0.0, startColor);
254 m_backgroundGradient.setColorAt( 0.0, startColor);
232 m_backgroundGradient.setColorAt( 1.0, endColor);
255 m_backgroundGradient.setColorAt( 1.0, endColor);
233 m_backgroundGradient.setStart(0,0);
256 m_backgroundGradient.setStart(0,0);
234
257
235 if(orientation == VerticalGradientOrientation){
258 if(orientation == VerticalGradientOrientation){
236 m_backgroundGradient.setFinalStop(0,m_rect.height());
259 m_backgroundGradient.setFinalStop(0,m_rect.height());
237 }else{
260 }else{
238 m_backgroundGradient.setFinalStop(m_rect.width(),0);
261 m_backgroundGradient.setFinalStop(m_rect.width(),0);
239 }
262 }
240
263
241 m_backgroundItem->setBrush(m_backgroundGradient);
264 m_backgroundItem->setBrush(m_backgroundGradient);
242 m_backgroundItem->setPen(Qt::NoPen);
265 m_backgroundItem->setPen(Qt::NoPen);
243 m_backgroundItem->update();
266 m_backgroundItem->update();
244 }
267 }
245
268
246 void QChart::setTitle(const QString& title,const QFont& font)
269 void QChart::setTitle(const QString& title,const QFont& font)
247 {
270 {
248 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
271 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
249 m_titleItem->setPlainText(title);
272 m_titleItem->setPlainText(title);
250 m_titleItem->setFont(font);
273 m_titleItem->setFont(font);
251 }
274 }
252
275
253 int QChart::margin() const
276 int QChart::margin() const
254 {
277 {
255 return m_marginSize;
278 return m_marginSize;
256 }
279 }
257
280
258 void QChart::setMargin(int margin)
281 void QChart::setMargin(int margin)
259 {
282 {
260 m_marginSize = margin;
283 m_marginSize = margin;
261 }
284 }
262
285
263 void QChart::setTheme(QChart::ChartThemeId theme)
286 void QChart::setTheme(QChart::ChartThemeId theme)
264 {
287 {
265 // if (theme != m_currentTheme) {
288 // if (theme != m_currentTheme) {
266 m_themeColors.clear();
289 m_themeColors.clear();
267
290
268 // TODO: define color themes
291 // TODO: define color themes
269 switch (theme) {
292 switch (theme) {
270 case QChart::ChartThemeDefault:
293 case QChart::ChartThemeDefault:
271 // TODO: define the default theme based on the OS
294 // TODO: define the default theme based on the OS
272 m_themeColors.append(QColor(QRgb(0xff000000)));
295 m_themeColors.append(QColor(QRgb(0xff000000)));
273 m_themeColors.append(QColor(QRgb(0xff707070)));
296 m_themeColors.append(QColor(QRgb(0xff707070)));
274 setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
297 setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
275 break;
298 break;
276 case QChart::ChartThemeVanilla:
299 case QChart::ChartThemeVanilla:
277 m_themeColors.append(QColor(217, 197, 116));
300 m_themeColors.append(QColor(217, 197, 116));
278 m_themeColors.append(QColor(214, 168, 150));
301 m_themeColors.append(QColor(214, 168, 150));
279 m_themeColors.append(QColor(160, 160, 113));
302 m_themeColors.append(QColor(160, 160, 113));
280 m_themeColors.append(QColor(210, 210, 52));
303 m_themeColors.append(QColor(210, 210, 52));
281 m_themeColors.append(QColor(136, 114, 58));
304 m_themeColors.append(QColor(136, 114, 58));
282
305
283 setBackground(QColor(QRgb(0xff9d844d)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
306 setBackground(QColor(QRgb(0xff9d844d)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
284 break;
307 break;
285 case QChart::ChartThemeIcy:
308 case QChart::ChartThemeIcy:
286 m_themeColors.append(QColor(0, 3, 165));
309 m_themeColors.append(QColor(0, 3, 165));
287 m_themeColors.append(QColor(49, 52, 123));
310 m_themeColors.append(QColor(49, 52, 123));
288 m_themeColors.append(QColor(71, 114, 187));
311 m_themeColors.append(QColor(71, 114, 187));
289 m_themeColors.append(QColor(48, 97, 87));
312 m_themeColors.append(QColor(48, 97, 87));
290 m_themeColors.append(QColor(19, 71, 90));
313 m_themeColors.append(QColor(19, 71, 90));
291 m_themeColors.append(QColor(110, 70, 228));
314 m_themeColors.append(QColor(110, 70, 228));
292
315
293 setBackground(QColor(QRgb(0xffe4ffff)), QColor(QRgb(0xffe4ffff)), VerticalGradientOrientation);
316 setBackground(QColor(QRgb(0xffe4ffff)), QColor(QRgb(0xffe4ffff)), VerticalGradientOrientation);
294 break;
317 break;
295 case QChart::ChartThemeGrayscale:
318 case QChart::ChartThemeGrayscale:
296 m_themeColors.append(QColor(0, 0, 0));
319 m_themeColors.append(QColor(0, 0, 0));
297 m_themeColors.append(QColor(50, 50, 50));
320 m_themeColors.append(QColor(50, 50, 50));
298 m_themeColors.append(QColor(100, 100, 100));
321 m_themeColors.append(QColor(100, 100, 100));
299 m_themeColors.append(QColor(140, 140, 140));
322 m_themeColors.append(QColor(140, 140, 140));
300 m_themeColors.append(QColor(180, 180, 180));
323 m_themeColors.append(QColor(180, 180, 180));
301
324
302 setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
325 setBackground(QColor(QRgb(0xffffffff)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
303 break;
326 break;
304 case QChart::ChartThemeUnnamed1:
327 case QChart::ChartThemeUnnamed1:
305 m_themeColors.append(QColor(QRgb(0xff3fa9f5)));
328 m_themeColors.append(QColor(QRgb(0xff3fa9f5)));
306 m_themeColors.append(QColor(QRgb(0xff7AC943)));
329 m_themeColors.append(QColor(QRgb(0xff7AC943)));
307 m_themeColors.append(QColor(QRgb(0xffFF931E)));
330 m_themeColors.append(QColor(QRgb(0xffFF931E)));
308 m_themeColors.append(QColor(QRgb(0xffFF1D25)));
331 m_themeColors.append(QColor(QRgb(0xffFF1D25)));
309 m_themeColors.append(QColor(QRgb(0xffFF7BAC)));
332 m_themeColors.append(QColor(QRgb(0xffFF7BAC)));
310
333
311 setBackground(QColor(QRgb(0xfff3dc9e)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
334 setBackground(QColor(QRgb(0xfff3dc9e)), QColor(QRgb(0xffafafaf)), VerticalGradientOrientation);
312 break;
335 break;
313 default:
336 default:
314 Q_ASSERT(false);
337 Q_ASSERT(false);
315 break;
338 break;
316 }
339 }
317
340
318 if(m_backgroundItem){
341 if(m_backgroundItem){
319 m_backgroundItem->setBrush(m_backgroundGradient);
342 m_backgroundItem->setBrush(m_backgroundGradient);
320 m_backgroundItem->setPen(Qt::NoPen);
343 m_backgroundItem->setPen(Qt::NoPen);
321 }
344 }
322
345
323 foreach(QChartSeries* series, m_chartSeries) {
346 foreach(QChartSeries* series, m_chartSeries) {
324 // TODO: other series interested on themes?
347 // TODO: other series interested on themes?
325 if (series->type() == QChartSeries::SeriesTypeLine) {
348 if (series->type() == QChartSeries::SeriesTypeLine) {
326 QXYChartSeries *lineseries = reinterpret_cast<QXYChartSeries *>(series);
349 QXYChartSeries *lineseries = reinterpret_cast<QXYChartSeries *>(series);
327 lineseries->setPen(nextColor());
350 lineseries->setPen(nextColor());
328 } else if (series->type() == QChartSeries::SeriesTypeScatter) {
351 } else if (series->type() == QChartSeries::SeriesTypeScatter) {
329 QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
352 QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
330 scatter->setMarkerColor(nextColor());
353 scatter->setMarkerColor(nextColor());
331 } else if (series->type() == QChartSeries::SeriesTypePie) {
354 } else if (series->type() == QChartSeries::SeriesTypePie) {
332 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
355 QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series);
333 for (int i(0); i < pieSeries->sliceCount(); i++)
356 for (int i(0); i < pieSeries->sliceCount(); i++)
334 pieSeries->setSliceColor(i, nextColor());
357 pieSeries->setSliceColor(i, nextColor());
335 }
358 }
336 }
359 }
337 update();
360 update();
338 }
361 }
339
362
340 QColor QChart::nextColor()
363 QColor QChart::nextColor()
341 {
364 {
342 QColor nextColor = m_themeColors.first();
365 QColor nextColor = m_themeColors.first();
343 m_themeColors.move(0, m_themeColors.size() - 1);
366 m_themeColors.move(0, m_themeColors.size() - 1);
344 return nextColor;
367 return nextColor;
345 }
368 }
346
369
347 void QChart::zoomInToRect(const QRect& rectangle)
370 void QChart::zoomInToRect(const QRect& rectangle)
348 {
371 {
349
372
350 if(!rectangle.isValid()) return;
373 if(!rectangle.isValid()) return;
351
374
352 qreal margin = this->margin();
375 qreal margin = this->margin();
353
376
354 QRect rect = rectangle.normalized();
377 QRect rect = rectangle.normalized();
355 rect.translate(-margin, -margin);
378 rect.translate(-margin, -margin);
356
379
357 PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex];
380 PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex];
358
381
359 PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin);
382 PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin);
360
383
361 m_plotDomainList.resize(m_plotDataIndex + 1);
384 m_plotDomainList.resize(m_plotDataIndex + 1);
362 m_plotDomainList<<domain;
385 m_plotDomainList<<domain;
363 m_plotDataIndex++;
386 m_plotDataIndex++;
364
387
365 foreach (ChartItem* item ,m_chartItems)
388 foreach (ChartItem* item ,m_chartItems)
366 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
389 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
367 update();
390 update();
368 }
391 }
369
392
370 void QChart::zoomIn()
393 void QChart::zoomIn()
371 {
394 {
372 if (m_plotDataIndex < m_plotDomainList.count() - 1) {
395 if (m_plotDataIndex < m_plotDomainList.count() - 1) {
373 m_plotDataIndex++;
396 m_plotDataIndex++;
374 foreach (ChartItem* item ,m_chartItems)
397 foreach (ChartItem* item ,m_chartItems)
375 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
398 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
376 update();
399 update();
377 } else {
400 } else {
378 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
401 QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
379 rect.setWidth(rect.width()/2);
402 rect.setWidth(rect.width()/2);
380 rect.setHeight(rect.height()/2);
403 rect.setHeight(rect.height()/2);
381 rect.moveCenter(m_rect.center());
404 rect.moveCenter(m_rect.center());
382 zoomInToRect(rect);
405 zoomInToRect(rect);
383 }
406 }
384 }
407 }
385
408
386 void QChart::zoomOut()
409 void QChart::zoomOut()
387 {
410 {
388 if (m_plotDataIndex > 0) {
411 if (m_plotDataIndex > 0) {
389 m_plotDataIndex--;
412 m_plotDataIndex--;
390 foreach (ChartItem* item ,m_chartItems)
413 foreach (ChartItem* item ,m_chartItems)
391 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
414 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
392 update();
415 update();
393 }
416 }
394 }
417 }
395
418
396 void QChart::zoomReset()
419 void QChart::zoomReset()
397 {
420 {
398 if (m_plotDataIndex > 0) {
421 if (m_plotDataIndex > 0) {
399 m_plotDataIndex = 0;
422 m_plotDataIndex = 0;
400 foreach (ChartItem* item ,m_chartItems)
423 foreach (ChartItem* item ,m_chartItems)
401 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
424 item->setPlotDomain(m_plotDomainList[m_plotDataIndex]);
402 update();
425 update();
403 }
426 }
404 }
427 }
405
428
406 void QChart::setAxisX(const QChartAxis& axis)
429 void QChart::setAxisX(const QChartAxis& axis)
407 {
430 {
408 setAxis(m_axisXItem,axis);
431 setAxis(m_axisXItem,axis);
409 }
432 }
410 void QChart::setAxisY(const QChartAxis& axis)
433 void QChart::setAxisY(const QChartAxis& axis)
411 {
434 {
412 setAxis(m_axisYItem.at(0),axis);
435 setAxis(m_axisYItem.at(0),axis);
413 }
436 }
414
437
415 void QChart::setAxisY(const QList<QChartAxis>& axis)
438 void QChart::setAxisY(const QList<QChartAxis>& axis)
416 {
439 {
417 //TODO not implemented
440 //TODO not implemented
418 }
441 }
419
442
420 void QChart::setAxis(AxisItem *item, const QChartAxis& axis)
443 void QChart::setAxis(AxisItem *item, const QChartAxis& axis)
421 {
444 {
422 item->setVisible(axis.isAxisVisible());
445 item->setVisible(axis.isAxisVisible());
423 }
446 }
424
447
425 #include "moc_qchart.cpp"
448 #include "moc_qchart.cpp"
426
449
427 QTCOMMERCIALCHART_END_NAMESPACE
450 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,48 +1,49
1 #ifndef QCHARTSERIES_H
1 #ifndef QCHARTSERIES_H
2 #define QCHARTSERIES_H
2 #define QCHARTSERIES_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QObject>
5 #include <QObject>
6 #include <QAbstractItemModel>
6 #include <QAbstractItemModel>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject
10 class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject
11 {
11 {
12 Q_OBJECT
12 Q_OBJECT
13 public:
13 public:
14 enum QChartSeriesType {
14 enum QChartSeriesType {
15 SeriesTypeLine = 0,
15 SeriesTypeLine = 0,
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
22 };
23 };
23
24
24 protected:
25 protected:
25 QChartSeries(QObject *parent = 0):QObject(parent){};
26 QChartSeries(QObject *parent = 0):QObject(parent){};
26
27
27 public:
28 public:
28 virtual ~QChartSeries(){};
29 virtual ~QChartSeries(){};
29
30
30 // Factory method
31 // Factory method
31 static QChartSeries* create(QChartSeriesType type, QObject* parent = 0 );
32 static QChartSeries* create(QChartSeriesType type, QObject* parent = 0 );
32
33
33 // Pure virtual
34 // Pure virtual
34 virtual QChartSeriesType type() const = 0;
35 virtual QChartSeriesType type() const = 0;
35
36
36 virtual bool setData(QList<int> data) { return false; }
37 virtual bool setData(QList<int> data) { return false; }
37 virtual bool setData(QList<qreal> data) { return false; }
38 virtual bool setData(QList<qreal> data) { return false; }
38 virtual bool setData(QList<qreal> x, QList<qreal> y){ return false; }
39 virtual bool setData(QList<qreal> x, QList<qreal> y){ return false; }
39
40
40 // Prototype for data model. TODO: remove the other setData methods and use something like this for now?
41 // Prototype for data model. TODO: remove the other setData methods and use something like this for now?
41 virtual bool setData(QAbstractItemModel* model) { return false; }
42 virtual bool setData(QAbstractItemModel* model) { return false; }
42
43
43 };
44 };
44
45
45 QTCOMMERCIALCHART_END_NAMESPACE
46 QTCOMMERCIALCHART_END_NAMESPACE
46
47
47 #endif
48 #endif
48
49
@@ -1,95 +1,99
1 !include( ../common.pri ) {
1 !include( ../common.pri ) {
2 error( Couldn't find the common.pri file! )
2 error( Couldn't find the common.pri file! )
3 }
3 }
4
4
5 TARGET = QtCommercialChart
5 TARGET = QtCommercialChart
6 DESTDIR = $$CHART_BUILD_LIB_DIR
6 DESTDIR = $$CHART_BUILD_LIB_DIR
7 TEMPLATE = lib
7 TEMPLATE = lib
8 QT += core \
8 QT += core \
9 gui
9 gui
10
10
11 CONFIG += debug_and_release
11 CONFIG += debug_and_release
12 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
12 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
13
13
14 SOURCES += \
14 SOURCES += \
15 barchart/barchartseries.cpp \
15 barchart/barchartseries.cpp \
16 barchart/bargroup.cpp \
16 barchart/bargroup.cpp \
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 \
23 qscatterseries.cpp \
25 qscatterseries.cpp \
24 qpieseries.cpp \
26 qpieseries.cpp \
25 qchart.cpp \
27 qchart.cpp \
26 axisitem.cpp \
28 axisitem.cpp \
27 qchartwidget.cpp \
29 qchartwidget.cpp \
28 pieslice.cpp \
30 pieslice.cpp \
29 qchartview.cpp \
31 qchartview.cpp \
30 qchartseries.cpp \
32 qchartseries.cpp \
31 qchartaxis.cpp
33 qchartaxis.cpp
32
34
33 PRIVATE_HEADERS += \
35 PRIVATE_HEADERS += \
34 xylinechart/xylinechartitem_p.h \
36 xylinechart/xylinechartitem_p.h \
35 plotdomain_p.h \
37 plotdomain_p.h \
36 qscatterseries_p.h \
38 qscatterseries_p.h \
37 pieslice.h \
39 pieslice.h \
38 axisitem_p.h \
40 axisitem_p.h \
39 chartitem_p.h
41 chartitem_p.h
40
42
41 PUBLIC_HEADERS += \
43 PUBLIC_HEADERS += \
42 qchartseries.h \
44 qchartseries.h \
43 qscatterseries.h \
45 qscatterseries.h \
44 qpieseries.h \
46 qpieseries.h \
45 qchart.h \
47 qchart.h \
46 qchartwidget.h \
48 qchartwidget.h \
47 qchartglobal.h \
49 qchartglobal.h \
48 xylinechart/qxychartseries.h \
50 xylinechart/qxychartseries.h \
49 barchart/barchartseries.h \
51 barchart/barchartseries.h \
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
56 HEADERS += $$PUBLIC_HEADERS
60 HEADERS += $$PUBLIC_HEADERS
57 HEADERS += $$PRIVATE_HEADERS
61 HEADERS += $$PRIVATE_HEADERS
58
62
59 INCLUDEPATH += xylinechart \
63 INCLUDEPATH += xylinechart \
60 barchart \
64 barchart \
61 .
65 .
62
66
63 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
67 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
64 MOC_DIR = $$CHART_BUILD_DIR/lib
68 MOC_DIR = $$CHART_BUILD_DIR/lib
65 UI_DIR = $$CHART_BUILD_DIR/lib
69 UI_DIR = $$CHART_BUILD_DIR/lib
66 RCC_DIR = $$CHART_BUILD_DIR/lib
70 RCC_DIR = $$CHART_BUILD_DIR/lib
67
71
68
72
69 DEFINES += QTCOMMERCIALCHART_LIBRARY
73 DEFINES += QTCOMMERCIALCHART_LIBRARY
70
74
71 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
75 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
72 public_headers.files = $$PUBLIC_HEADERS
76 public_headers.files = $$PUBLIC_HEADERS
73 target.path = $$[QT_INSTALL_LIBS]
77 target.path = $$[QT_INSTALL_LIBS]
74 INSTALLS += target \
78 INSTALLS += target \
75 public_headers
79 public_headers
76
80
77
81
78 install_build_headers.name = bild_headers
82 install_build_headers.name = bild_headers
79 install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h
83 install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h
80 install_build_headers.input = PUBLIC_HEADERS
84 install_build_headers.input = PUBLIC_HEADERS
81 install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR
85 install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR
82 install_build_headers.CONFIG += target_predeps no_link
86 install_build_headers.CONFIG += target_predeps no_link
83 QMAKE_EXTRA_COMPILERS += install_build_headers
87 QMAKE_EXTRA_COMPILERS += install_build_headers
84
88
85 chartversion.target = qchartversion_p.h
89 chartversion.target = qchartversion_p.h
86 chartversion.commands = @echo "build_time" > $$chartversion.target;
90 chartversion.commands = @echo "build_time" > $$chartversion.target;
87 chartversion.depends = $$HEADERS $$SOURCES
91 chartversion.depends = $$HEADERS $$SOURCES
88 PRE_TARGETDEPS += qchartversion_p.h
92 PRE_TARGETDEPS += qchartversion_p.h
89 QMAKE_CLEAN+= qchartversion_p.h
93 QMAKE_CLEAN+= qchartversion_p.h
90 QMAKE_EXTRA_TARGETS += chartversion
94 QMAKE_EXTRA_TARGETS += chartversion
91
95
92 unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
96 unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
93 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
97 win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR
94
98
95
99
General Comments 0
You need to be logged in to leave comments. Login now