@@ -0,0 +1,109 | |||
|
1 | #include <limits.h> | |
|
2 | #include <QDebug> | |
|
3 | #include "barchartseriesbase.h" | |
|
4 | #include "bargroup.h" | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
7 | ||
|
8 | BarChartSeriesBase::BarChartSeriesBase(QObject *parent) | |
|
9 | : QChartSeries(parent) | |
|
10 | { | |
|
11 | } | |
|
12 | ||
|
13 | bool BarChartSeriesBase::setData(QAbstractItemModel* model) | |
|
14 | { | |
|
15 | mModel = model; | |
|
16 | return true; | |
|
17 | } | |
|
18 | ||
|
19 | int BarChartSeriesBase::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 BarChartSeriesBase::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 BarChartSeriesBase::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 BarChartSeriesBase::countRows() | |
|
76 | { | |
|
77 | return mModel->rowCount(); | |
|
78 | } | |
|
79 | ||
|
80 | int BarChartSeriesBase::countColumns() | |
|
81 | { | |
|
82 | return mModel->columnCount(); | |
|
83 | } | |
|
84 | ||
|
85 | int BarChartSeriesBase::countTotalItems() | |
|
86 | { | |
|
87 | return mModel->rowCount() * mModel->columnCount(); | |
|
88 | } | |
|
89 | ||
|
90 | int BarChartSeriesBase::valueAt(int row, int column) | |
|
91 | { | |
|
92 | QModelIndex index = mModel->index(row,column); | |
|
93 | return mModel->data(index).toInt(); | |
|
94 | } | |
|
95 | ||
|
96 | int BarChartSeriesBase::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_barchartseriesbase.cpp" | |
|
108 | ||
|
109 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,49 | |||
|
1 | #ifndef BARCHARTSERIESBASE_H | |
|
2 | #define BARCHARTSERIESBASE_H | |
|
3 | ||
|
4 | #include <QList> | |
|
5 | #include <QAbstractItemModel> | |
|
6 | #include "qchartseries.h" | |
|
7 | #include "qchartglobal.h" | |
|
8 | ||
|
9 | class BarGroupBase; | |
|
10 | ||
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
12 | ||
|
13 | // Container for series | |
|
14 | class QTCOMMERCIALCHART_EXPORT BarChartSeriesBase : public QChartSeries | |
|
15 | { | |
|
16 | Q_OBJECT | |
|
17 | protected: | |
|
18 | BarChartSeriesBase(QObject* parent=0); | |
|
19 | ||
|
20 | public: | |
|
21 | // from QChartSeries | |
|
22 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeInvalid; } | |
|
23 | ||
|
24 | // TODO: Better data model? | |
|
25 | virtual bool setData(QAbstractItemModel* model); | |
|
26 | ||
|
27 | // Methods to find out minimum and maximum values of data | |
|
28 | int min(); | |
|
29 | int max(); | |
|
30 | int maxColumnSum(); // returns maximum sum of items in all columns. | |
|
31 | ||
|
32 | int countRows(); | |
|
33 | int countColumns(); // Count items in one series. | |
|
34 | int countTotalItems(); | |
|
35 | int valueAt(int row, int column); | |
|
36 | ||
|
37 | int columnSum(int column); | |
|
38 | ||
|
39 | public Q_SLOTS: | |
|
40 | ||
|
41 | private: | |
|
42 | ||
|
43 | QAbstractItemModel* mModel; | |
|
44 | BarGroupBase* mBarGroup; | |
|
45 | }; | |
|
46 | ||
|
47 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
48 | ||
|
49 | #endif // BARCHARTSERIESBASE_H |
@@ -0,0 +1,122 | |||
|
1 | #include "bargroupbase.h" | |
|
2 | #include "bar_p.h" | |
|
3 | #include "barlabel_p.h" | |
|
4 | #include "separator_p.h" | |
|
5 | #include "barchartseriesbase.h" | |
|
6 | #include <QDebug> | |
|
7 | ||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
9 | ||
|
10 | BarGroupBase::BarGroupBase(BarChartSeriesBase& series, QGraphicsItem *parent) | |
|
11 | : ChartItem(parent) | |
|
12 | ,mSeries(series) | |
|
13 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
|
14 | ,mLayoutSet(false) | |
|
15 | ,mLayoutDirty(true) | |
|
16 | ,mTheme(0) | |
|
17 | ,mSeparatorsVisible(true) | |
|
18 | { | |
|
19 | dataChanged(); | |
|
20 | } | |
|
21 | ||
|
22 | void BarGroupBase::setSeparatorsVisible(bool visible) | |
|
23 | { | |
|
24 | mSeparatorsVisible = visible; | |
|
25 | } | |
|
26 | ||
|
27 | void BarGroupBase::setSize(const QSizeF& size) | |
|
28 | { | |
|
29 | mWidth = size.width(); | |
|
30 | mHeight = size.height(); | |
|
31 | layoutChanged(); | |
|
32 | mLayoutSet = true; | |
|
33 | } | |
|
34 | ||
|
35 | void BarGroupBase::setPlotDomain(const PlotDomain& data) | |
|
36 | { | |
|
37 | qDebug() << "BarGroupBase::setPlotDomain"; | |
|
38 | // TODO: | |
|
39 | } | |
|
40 | ||
|
41 | void BarGroupBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
42 | { | |
|
43 | if (!mLayoutSet) { | |
|
44 | qDebug() << "BarGroupBase::paint called without layout set. Aborting."; | |
|
45 | return; | |
|
46 | } | |
|
47 | if (mLayoutDirty) { | |
|
48 | // Layout or data has changed. Need to redraw. | |
|
49 | foreach(QGraphicsItem* i, childItems()) { | |
|
50 | i->paint(painter,option,widget); | |
|
51 | } | |
|
52 | } | |
|
53 | } | |
|
54 | ||
|
55 | QRectF BarGroupBase::boundingRect() const | |
|
56 | { | |
|
57 | return QRectF(0,0,mWidth,mHeight); | |
|
58 | } | |
|
59 | ||
|
60 | void BarGroupBase::themeChanged(ChartTheme *theme) | |
|
61 | { | |
|
62 | mTheme = theme; | |
|
63 | } | |
|
64 | ||
|
65 | void BarGroupBase::setBarWidth( int w ) | |
|
66 | { | |
|
67 | mBarDefaultWidth = w; | |
|
68 | } | |
|
69 | ||
|
70 | int BarGroupBase::addColor( QColor color ) | |
|
71 | { | |
|
72 | int colorIndex = mColors.count(); | |
|
73 | mColors.append(color); | |
|
74 | return colorIndex; | |
|
75 | } | |
|
76 | ||
|
77 | void BarGroupBase::resetColors() | |
|
78 | { | |
|
79 | mColors.clear(); | |
|
80 | } | |
|
81 | ||
|
82 | void BarGroupBase::dataChanged() | |
|
83 | { | |
|
84 | qDebug() << "BarGroupBase::dataChanged"; | |
|
85 | ||
|
86 | // Find out maximum and minimum of all series | |
|
87 | mMax = mSeries.max(); | |
|
88 | mMin = mSeries.min(); | |
|
89 | ||
|
90 | // Delete old bars | |
|
91 | foreach (QGraphicsItem* item, childItems()) { | |
|
92 | delete item; | |
|
93 | } | |
|
94 | ||
|
95 | // Create new graphic items for bars | |
|
96 | int totalItems = mSeries.countTotalItems(); | |
|
97 | for (int i=0; i<totalItems; i++) { | |
|
98 | Bar *bar = new Bar(this); | |
|
99 | childItems().append(bar); | |
|
100 | } | |
|
101 | ||
|
102 | // TODO: labels from series. This creates just some example labels | |
|
103 | int count = mSeries.countColumns(); | |
|
104 | for (int i=0; i<count; i++) { | |
|
105 | BarLabel* label = new BarLabel(this); | |
|
106 | QString text("Label " + QString::number(i)); | |
|
107 | label->set(text); | |
|
108 | childItems().append(label); | |
|
109 | } | |
|
110 | ||
|
111 | count = mSeries.countColumns() - 1; // There is one less separator than columns | |
|
112 | for (int i=0; i<count; i++) { | |
|
113 | Separator* sep = new Separator(this); | |
|
114 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme | |
|
115 | childItems().append(sep); | |
|
116 | } | |
|
117 | ||
|
118 | // TODO: if (autolayout) { layoutChanged() } or something | |
|
119 | mLayoutDirty = true; | |
|
120 | } | |
|
121 | ||
|
122 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,64 | |||
|
1 | #ifndef BARGROUPBASE_H | |
|
2 | #define BARGROUPBASE_H | |
|
3 | ||
|
4 | #include "charttheme_p.h" | |
|
5 | #include "chartitem_p.h" | |
|
6 | //#include "barlabel_p.h" | |
|
7 | //#include "bar_p.h" | |
|
8 | #include "barchartseriesbase.h" | |
|
9 | #include <QGraphicsItem> | |
|
10 | ||
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
12 | ||
|
13 | // Base Class for bar groups. Common implemantation of different groups. Not to be instantiated. | |
|
14 | ||
|
15 | class BarGroupBase : public ChartItem, public ChartThemeObserver | |
|
16 | { | |
|
17 | ||
|
18 | public: | |
|
19 | BarGroupBase(BarChartSeriesBase& series, QGraphicsItem *parent = 0); | |
|
20 | void setSeparatorsVisible(bool visible = true); | |
|
21 | ||
|
22 | public: // From ChartItem | |
|
23 | void setSize(const QSizeF &size); | |
|
24 | void setPlotDomain(const PlotDomain& data); | |
|
25 | ||
|
26 | // From QGraphicsItem | |
|
27 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
|
28 | QRectF boundingRect() const; | |
|
29 | ||
|
30 | // From ChartThemeObserver | |
|
31 | void themeChanged(ChartTheme *theme); | |
|
32 | ||
|
33 | // TODO: these may change with layout awarness. | |
|
34 | void setBarWidth( int w ); | |
|
35 | int addColor( QColor color ); | |
|
36 | void resetColors(); | |
|
37 | ||
|
38 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
|
39 | virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes | |
|
40 | ||
|
41 | protected: | |
|
42 | ||
|
43 | BarChartSeriesBase& mSeries; | |
|
44 | ||
|
45 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) | |
|
46 | int mMax; | |
|
47 | ||
|
48 | int mHeight; // Layout spesific | |
|
49 | int mWidth; | |
|
50 | int mBarDefaultWidth; | |
|
51 | ||
|
52 | bool mLayoutSet; // True, if component has been laid out. | |
|
53 | bool mLayoutDirty; | |
|
54 | ||
|
55 | QList<QColor> mColors; // List of colors for series for now | |
|
56 | ||
|
57 | ChartTheme* mTheme; | |
|
58 | bool mSeparatorsVisible; | |
|
59 | ||
|
60 | }; | |
|
61 | ||
|
62 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
63 | ||
|
64 | #endif // BARGROUPBASE_H |
@@ -0,0 +1,49 | |||
|
1 | #include "separator_p.h" | |
|
2 | #include <QDebug> | |
|
3 | #include <QPainter> | |
|
4 | ||
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
6 | ||
|
7 | Separator::Separator(QGraphicsItem *parent) | |
|
8 | : ChartItem(parent) | |
|
9 | { | |
|
10 | } | |
|
11 | ||
|
12 | void Separator::setPos(qreal x, qreal y) | |
|
13 | { | |
|
14 | mXpos = x; | |
|
15 | mYpos = y; | |
|
16 | } | |
|
17 | ||
|
18 | void Separator::setColor(QColor color) | |
|
19 | { | |
|
20 | mColor = color; | |
|
21 | } | |
|
22 | ||
|
23 | void Separator::setSize(const QSizeF &size) | |
|
24 | { | |
|
25 | mWidth = size.width(); | |
|
26 | mHeight = size.height(); | |
|
27 | } | |
|
28 | ||
|
29 | void Separator::setPlotDomain(const PlotDomain& data) | |
|
30 | { | |
|
31 | ||
|
32 | } | |
|
33 | ||
|
34 | void Separator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
35 | { | |
|
36 | qDebug() << "separator::paint" << boundingRect(); | |
|
37 | QPen pen(mColor); | |
|
38 | painter->setPen(pen); | |
|
39 | painter->drawLine(mXpos,mYpos,mXpos,mHeight); | |
|
40 | } | |
|
41 | ||
|
42 | QRectF Separator::boundingRect() const | |
|
43 | { | |
|
44 | QRectF r(mXpos,mYpos,mWidth,mHeight); | |
|
45 | return r; | |
|
46 | } | |
|
47 | ||
|
48 | ||
|
49 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,36 | |||
|
1 | #ifndef SEPARATOR_H | |
|
2 | #define SEPARATOR_H | |
|
3 | ||
|
4 | #include "chartitem_p.h" | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
7 | ||
|
8 | class Separator : public ChartItem | |
|
9 | { | |
|
10 | public: | |
|
11 | Separator(QGraphicsItem *parent = 0); | |
|
12 | ||
|
13 | void setPos(qreal x, qreal y); | |
|
14 | void setColor(QColor color); | |
|
15 | ||
|
16 | // From ChartItem | |
|
17 | void setSize(const QSizeF &size); | |
|
18 | void setPlotDomain(const PlotDomain& data); | |
|
19 | ||
|
20 | // From QGraphicsItem | |
|
21 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
|
22 | QRectF boundingRect() const; | |
|
23 | ||
|
24 | private: | |
|
25 | ||
|
26 | QColor mColor; | |
|
27 | qreal mXpos; | |
|
28 | qreal mYpos; | |
|
29 | qreal mHeight; | |
|
30 | qreal mWidth; | |
|
31 | ||
|
32 | }; | |
|
33 | ||
|
34 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
35 | ||
|
36 | #endif // SEPARATOR_H |
@@ -1,80 +1,13 | |||
|
1 | 1 | #include <QDebug> |
|
2 | 2 | #include "barchartseries.h" |
|
3 | #include "bargroup.h" | |
|
3 | ||
|
4 | 4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | 5 | |
|
6 | 6 | BarChartSeries::BarChartSeries(QObject *parent) |
|
7 |
: |
|
|
8 | { | |
|
9 | } | |
|
10 | ||
|
11 | bool BarChartSeries::setData(QAbstractItemModel* model) | |
|
12 | { | |
|
13 | mModel = model; | |
|
14 | return true; | |
|
15 | } | |
|
16 | ||
|
17 | int BarChartSeries::min() | |
|
18 | { | |
|
19 | Q_ASSERT(mModel->rowCount() > 0); | |
|
20 | Q_ASSERT(mModel->columnCount() > 0); | |
|
21 | ||
|
22 | // TODO: make min and max members and update them when data changes. | |
|
23 | // This is slower since they are checked every time, even if data is same since previous call. | |
|
24 | int min = INT_MAX; | |
|
25 | ||
|
26 | for (int i=0; i <mModel->rowCount(); i++) { | |
|
27 | for(int j=0; j<mModel->columnCount(); j++) { | |
|
28 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
|
29 | if (temp < min) { | |
|
30 | min = temp; | |
|
31 | } | |
|
32 | } | |
|
33 | } | |
|
34 | return min; | |
|
35 | } | |
|
36 | ||
|
37 | int BarChartSeries::max() | |
|
38 | { | |
|
39 | Q_ASSERT(mModel->rowCount() > 0); | |
|
40 | Q_ASSERT(mModel->columnCount() > 0); | |
|
41 | ||
|
42 | // TODO: make min and max members and update them when data changes. | |
|
43 | // This is slower since they are checked every time, even if data is same since previous call. | |
|
44 | int max = INT_MIN; | |
|
45 | ||
|
46 | for (int i=0; i <mModel->rowCount(); i++) { | |
|
47 | for(int j=0; j<mModel->columnCount(); j++) { | |
|
48 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
|
49 | if (temp > max) { | |
|
50 | max = temp; | |
|
51 | } | |
|
52 | } | |
|
53 | } | |
|
54 | return max; | |
|
55 | } | |
|
56 | ||
|
57 | ||
|
58 | int BarChartSeries::countRows() | |
|
59 | { | |
|
60 | return mModel->rowCount(); | |
|
61 | } | |
|
62 | ||
|
63 | int BarChartSeries::countColumns() | |
|
64 | { | |
|
65 | return mModel->columnCount(); | |
|
66 | } | |
|
67 | ||
|
68 | int BarChartSeries::countTotalItems() | |
|
69 | { | |
|
70 | return mModel->rowCount() * mModel->columnCount(); | |
|
71 | } | |
|
72 | ||
|
73 | int BarChartSeries::valueAt(int row, int column) | |
|
7 | : BarChartSeriesBase(parent) | |
|
74 | 8 | { |
|
75 | return mModel->data(mModel->index(row,column)).toInt(); | |
|
76 | 9 | } |
|
77 | 10 | |
|
78 | 11 | #include "moc_barchartseries.cpp" |
|
79 | 12 | |
|
80 | 13 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,45 +1,30 | |||
|
1 | 1 | #ifndef BARCHARTSERIES_H |
|
2 | 2 | #define BARCHARTSERIES_H |
|
3 | 3 | |
|
4 | 4 | #include <QList> |
|
5 | 5 | #include <QAbstractItemModel> |
|
6 |
#include " |
|
|
7 | #include "qchartglobal.h" | |
|
6 | #include "barchartseriesbase.h" | |
|
8 | 7 | |
|
9 | // TODO: Can this class be combined with series? | |
|
10 | 8 | class BarGroup; |
|
11 | 9 | |
|
12 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
13 | 11 | |
|
14 | 12 | // Container for series |
|
15 |
class QTCOMMERCIALCHART_EXPORT BarChartSeries : public |
|
|
13 | class QTCOMMERCIALCHART_EXPORT BarChartSeries : public BarChartSeriesBase | |
|
16 | 14 | { |
|
17 | 15 | Q_OBJECT |
|
18 | 16 | public: |
|
19 | 17 | BarChartSeries(QObject* parent=0); |
|
20 | 18 | |
|
21 |
// from |
|
|
19 | // from BarChartSeriesBase | |
|
22 | 20 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; } |
|
23 | 21 | |
|
24 | // TODO: Better data model? | |
|
25 | virtual bool setData(QAbstractItemModel* model); | |
|
26 | ||
|
27 | // Methods to find out minimum and maximum values of data | |
|
28 | int min(); | |
|
29 | int max(); | |
|
30 | int countRows(); | |
|
31 | int countColumns(); // Count items in one series. | |
|
32 | int countTotalItems(); | |
|
33 | int valueAt(int row, int column); | |
|
34 | ||
|
35 | public Q_SLOTS: | |
|
36 | ||
|
37 | 22 | private: |
|
38 | 23 | |
|
39 | 24 | QAbstractItemModel* mModel; |
|
40 | 25 | BarGroup* mBarGroup; |
|
41 | 26 | }; |
|
42 | 27 | |
|
43 | 28 | QTCOMMERCIALCHART_END_NAMESPACE |
|
44 | 29 | |
|
45 | 30 | #endif // BARCHARTSERIES_H |
@@ -1,157 +1,65 | |||
|
1 | 1 | #include "bargroup.h" |
|
2 | 2 | #include "bar_p.h" |
|
3 | 3 | #include "barlabel_p.h" |
|
4 | 4 | #include <QDebug> |
|
5 | 5 | |
|
6 | 6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | 7 | |
|
8 | 8 | BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) : |
|
9 | ChartItem(parent) | |
|
10 | ,mSeries(series) | |
|
11 | ,mBarDefaultWidth(10) | |
|
12 | ,mLayoutSet(false) | |
|
13 | ,mLayoutDirty(true) | |
|
9 | BarGroupBase(series,parent) | |
|
14 | 10 | { |
|
15 | dataChanged(); | |
|
16 | } | |
|
17 | ||
|
18 | void BarGroup::setSize(const QSizeF& size) | |
|
19 | { | |
|
20 | qDebug() << "BarGroup::setSize"; | |
|
21 | mWidth = size.width(); | |
|
22 | mHeight = size.height(); | |
|
23 | layoutChanged(); | |
|
24 | mLayoutSet = true; | |
|
25 | } | |
|
26 | ||
|
27 | void BarGroup::setPlotDomain(const PlotDomain& data) | |
|
28 | { | |
|
29 | qDebug() << "BarGroup::setPlotDomain"; | |
|
30 | // TODO: | |
|
31 | mPlotDomain = data; | |
|
32 | } | |
|
33 | ||
|
34 | void BarGroup::setBarWidth( int w ) | |
|
35 | { | |
|
36 | mBarDefaultWidth = w; | |
|
37 | } | |
|
38 | ||
|
39 | int BarGroup::addColor( QColor color ) | |
|
40 | { | |
|
41 | int colorIndex = mColors.count(); | |
|
42 | mColors.append(color); | |
|
43 | return colorIndex; | |
|
44 | } | |
|
45 | ||
|
46 | void BarGroup::resetColors() | |
|
47 | { | |
|
48 | mColors.clear(); | |
|
49 | } | |
|
50 | ||
|
51 | void BarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
52 | { | |
|
53 | if (!mLayoutSet) { | |
|
54 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
|
55 | return; | |
|
56 | } | |
|
57 | if (mLayoutDirty) { | |
|
58 | // Layout or data has changed. Need to redraw. | |
|
59 | foreach(QGraphicsItem* i, childItems()) { | |
|
60 | i->paint(painter,option,widget); | |
|
61 | mLayoutDirty = false; | |
|
62 | } | |
|
63 | } | |
|
64 | } | |
|
65 | ||
|
66 | QRectF BarGroup::boundingRect() const | |
|
67 | { | |
|
68 | return QRectF(0,0,mWidth,mHeight); | |
|
69 | } | |
|
70 | ||
|
71 | ||
|
72 | void BarGroup::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 | // TODO: labels from series. This creates just some example labels | |
|
94 | int count = mSeries.countColumns(); | |
|
95 | for (int i=0; i<count; i++) { | |
|
96 | BarLabel* label = new BarLabel(this); | |
|
97 | QString text("Label " + QString::number(i)); | |
|
98 | label->set(text); | |
|
99 | childItems().append(label); | |
|
100 | } | |
|
101 | ||
|
102 | // TODO: if (autolayout) { layoutChanged() } or something | |
|
103 | mLayoutDirty = true; | |
|
11 | mBarDefaultWidth = 10; | |
|
104 | 12 | } |
|
105 | 13 | |
|
106 | 14 | void BarGroup::layoutChanged() |
|
107 | 15 | { |
|
108 | 16 | // Scale bars to new layout |
|
109 | 17 | // Layout for bars: |
|
110 | 18 | if (mSeries.countRows() <= 0) { |
|
111 | 19 | // Nothing to do. |
|
112 | 20 | return; |
|
113 | 21 | } |
|
114 | 22 | |
|
115 | 23 | // TODO: better way to auto-layout? |
|
116 | 24 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
117 | 25 | int columnCount = mSeries.countColumns(); |
|
118 | 26 | int rowCount = mSeries.countRows(); |
|
119 | 27 | |
|
120 | 28 | qreal tW = mWidth; |
|
121 | 29 | qreal tH = mHeight; |
|
122 | 30 | qreal tM = mMax; |
|
123 | 31 | qreal scale = (tH/tM); |
|
124 | 32 | |
|
125 | 33 | qreal tC = columnCount+1; |
|
126 | 34 | qreal xStepPerSeries = (tW/tC); |
|
127 | 35 | |
|
128 | 36 | // Scaling. |
|
129 | 37 | int itemIndex(0); |
|
130 | 38 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); |
|
131 | 39 | |
|
132 | 40 | for (int column=0; column < columnCount; column++) { |
|
133 | 41 | qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); |
|
134 | 42 | qreal yPos = mHeight; |
|
135 | 43 | for (int row = 0; row < rowCount; row++) { |
|
136 | 44 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
137 | 45 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
138 | 46 | |
|
139 | 47 | // TODO: width settable per bar? |
|
140 | 48 | bar->resize(mBarDefaultWidth, barHeight); |
|
141 | 49 | bar->setColor(mColors.at(row)); |
|
142 | 50 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); |
|
143 | 51 | itemIndex++; |
|
144 | 52 | xPos += mBarDefaultWidth; |
|
145 | 53 | } |
|
146 | 54 | |
|
147 | 55 | // TODO: Layout for labels, remove magic number |
|
148 | 56 | xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); |
|
149 | 57 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
150 | 58 | label->setPos(xPos, mHeight + 20); |
|
151 | 59 | labelIndex++; |
|
152 | 60 | } |
|
153 | 61 | |
|
154 | 62 | mLayoutDirty = true; |
|
155 | 63 | } |
|
156 | 64 | |
|
157 | 65 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +1,28 | |||
|
1 | 1 | #ifndef QBARGROUP_H |
|
2 | 2 | #define QBARGROUP_H |
|
3 | 3 | |
|
4 |
#include " |
|
|
5 | #include "bar_p.h" | |
|
4 | #include "bargroupbase.h" | |
|
6 | 5 | #include "barchartseries.h" |
|
7 | 6 | #include <QGraphicsItem> |
|
8 | 7 | |
|
9 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 9 | |
|
11 | class BarGroup : public ChartItem | |
|
10 | // Base class for bar groups | |
|
11 | ||
|
12 | class BarGroup : public BarGroupBase | |
|
12 | 13 | { |
|
13 | 14 | public: |
|
14 | 15 | explicit BarGroup(BarChartSeries& series, QGraphicsItem *parent = 0); |
|
15 | 16 | |
|
16 | public: // from ChartItem | |
|
17 | void setSize(const QSizeF &size); | |
|
18 | void setPlotDomain(const PlotDomain& data); | |
|
19 | ||
|
20 | // Layout "api" | |
|
21 | void setPos(qreal x, qreal y); | |
|
22 | void setBarWidth( int w ); // Default width for each bar | |
|
23 | ||
|
24 | int addColor( QColor color ); | |
|
25 | void resetColors(); | |
|
26 | ||
|
27 | // From QGraphicsItem | |
|
28 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
|
29 | QRectF boundingRect() const; | |
|
30 | ||
|
31 | 17 | private: |
|
32 | 18 | |
|
33 | void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
|
19 | // From BarGroupBase | |
|
34 | 20 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
35 | 21 | |
|
36 | 22 | private: |
|
37 | ||
|
38 | 23 | // Data |
|
39 | BarChartSeries& mSeries; | |
|
40 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) | |
|
41 | int mMax; | |
|
42 | ||
|
43 | int mHeight; // Layout spesific | |
|
44 | int mWidth; | |
|
45 | int mBarDefaultWidth; | |
|
46 | ||
|
47 | bool mLayoutSet; // True, if component has been laid out. | |
|
48 | bool mLayoutDirty; | |
|
49 | ||
|
50 | QList<QColor> mColors; // List of colors for series for now | |
|
51 | ||
|
52 | PlotDomain mPlotDomain; | |
|
53 | 24 | }; |
|
54 | 25 | |
|
55 | 26 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | 27 | |
|
57 | 28 | #endif // QBARGROUP_H |
@@ -1,111 +1,17 | |||
|
1 | 1 | #include "percentbarchartseries.h" |
|
2 | 2 | |
|
3 | 3 | #include <limits.h> |
|
4 | 4 | #include <QDebug> |
|
5 | 5 | #include "percentbarchartseries.h" |
|
6 | 6 | |
|
7 | 7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 8 | |
|
9 | 9 | PercentBarChartSeries::PercentBarChartSeries(QObject *parent) : |
|
10 |
|
|
|
10 | BarChartSeriesBase(parent) | |
|
11 | 11 | { |
|
12 | 12 | } |
|
13 | 13 | |
|
14 | bool PercentBarChartSeries::setData(QAbstractItemModel* model) | |
|
15 | { | |
|
16 | mModel = model; | |
|
17 | return true; | |
|
18 | } | |
|
19 | ||
|
20 | int PercentBarChartSeries::min() | |
|
21 | { | |
|
22 | Q_ASSERT(mModel->rowCount() > 0); | |
|
23 | Q_ASSERT(mModel->columnCount() > 0); | |
|
24 | ||
|
25 | // TODO: make min and max members and update them when data changes. | |
|
26 | // This is slower since they are checked every time, even if data is same since previous call. | |
|
27 | int min = INT_MAX; | |
|
28 | ||
|
29 | for (int i=0; i <mModel->rowCount(); i++) { | |
|
30 | for(int j=0; j<mModel->columnCount(); j++) { | |
|
31 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
|
32 | if (temp < min) { | |
|
33 | min = temp; | |
|
34 | } | |
|
35 | } | |
|
36 | } | |
|
37 | return min; | |
|
38 | } | |
|
39 | ||
|
40 | int PercentBarChartSeries::max() | |
|
41 | { | |
|
42 | Q_ASSERT(mModel->rowCount() > 0); | |
|
43 | Q_ASSERT(mModel->columnCount() > 0); | |
|
44 | ||
|
45 | // TODO: make min and max members and update them when data changes. | |
|
46 | // This is slower since they are checked every time, even if data is same since previous call. | |
|
47 | int max = INT_MIN; | |
|
48 | ||
|
49 | for (int i=0; i <mModel->rowCount(); i++) { | |
|
50 | for(int j=0; j<mModel->columnCount(); j++) { | |
|
51 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
|
52 | if (temp > max) { | |
|
53 | max = temp; | |
|
54 | } | |
|
55 | } | |
|
56 | } | |
|
57 | return max; | |
|
58 | } | |
|
59 | ||
|
60 | int PercentBarChartSeries::maxColumnSum() | |
|
61 | { | |
|
62 | Q_ASSERT(mModel->rowCount() > 0); | |
|
63 | Q_ASSERT(mModel->columnCount() > 0); | |
|
64 | ||
|
65 | int max = INT_MIN; | |
|
66 | ||
|
67 | for (int col=0; col <mModel->columnCount(); col++) { | |
|
68 | int sum = columnSum(col); | |
|
69 | if (sum > max) { | |
|
70 | max = sum; | |
|
71 | } | |
|
72 | } | |
|
73 | return max; | |
|
74 | } | |
|
75 | ||
|
76 | int PercentBarChartSeries::countRows() | |
|
77 | { | |
|
78 | return mModel->rowCount(); | |
|
79 | } | |
|
80 | ||
|
81 | int PercentBarChartSeries::countColumns() | |
|
82 | { | |
|
83 | return mModel->columnCount(); | |
|
84 | } | |
|
85 | ||
|
86 | int PercentBarChartSeries::countTotalItems() | |
|
87 | { | |
|
88 | return mModel->rowCount() * mModel->columnCount(); | |
|
89 | } | |
|
90 | ||
|
91 | int PercentBarChartSeries::valueAt(int row, int column) | |
|
92 | { | |
|
93 | QModelIndex index = mModel->index(row,column); | |
|
94 | return mModel->data(index).toInt(); | |
|
95 | } | |
|
96 | ||
|
97 | int PercentBarChartSeries::columnSum(int column) | |
|
98 | { | |
|
99 | int sum(0); | |
|
100 | int count = mModel->rowCount(); | |
|
101 | ||
|
102 | for (int row = 0; row < count; row++) { | |
|
103 | sum += mModel->data(mModel->index(row,column)).toInt(); | |
|
104 | } | |
|
105 | return sum; | |
|
106 | } | |
|
107 | ||
|
108 | 14 | #include "moc_percentbarchartseries.cpp" |
|
109 | 15 | |
|
110 | 16 | QTCOMMERCIALCHART_END_NAMESPACE |
|
111 | 17 |
@@ -1,47 +1,32 | |||
|
1 | 1 | #ifndef PERCENTBARCHARTSERIES_H |
|
2 | 2 | #define PERCENTBARCHARTSERIES_H |
|
3 | 3 | |
|
4 | 4 | #include <QList> |
|
5 | 5 | #include <QAbstractItemModel> |
|
6 |
#include " |
|
|
6 | #include "barchartseriesbase.h" | |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | class PercentBarGroup; |
|
11 | 11 | |
|
12 |
class QTCOMMERCIALCHART_EXPORT PercentBarChartSeries : public |
|
|
12 | class QTCOMMERCIALCHART_EXPORT PercentBarChartSeries : public BarChartSeriesBase | |
|
13 | 13 | { |
|
14 | 14 | Q_OBJECT |
|
15 | 15 | public: |
|
16 | 16 | PercentBarChartSeries(QObject* parent=0); |
|
17 | 17 | |
|
18 |
// from |
|
|
18 | // from BarChartSeriesBase | |
|
19 | 19 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; } |
|
20 | 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 | 21 | public Q_SLOTS: |
|
37 | 22 | |
|
38 | 23 | private: |
|
39 | 24 | |
|
40 | 25 | QAbstractItemModel* mModel; |
|
41 | 26 | PercentBarGroup* mPercentBarGroup; |
|
42 | 27 | }; |
|
43 | 28 | |
|
44 | 29 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | 30 | |
|
46 | 31 | |
|
47 | 32 | #endif // PERCENTBARCHARTSERIES_H |
@@ -1,152 +1,73 | |||
|
1 | 1 | #include "percentbargroup.h" |
|
2 | 2 | #include "bar_p.h" |
|
3 | 3 | #include "barlabel_p.h" |
|
4 | #include "separator_p.h" | |
|
4 | 5 | #include <QDebug> |
|
5 | 6 | |
|
6 | 7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | 8 | |
|
8 | PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : | |
|
9 | ChartItem(parent) | |
|
10 | ,mSeries(series) | |
|
11 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
|
12 | ,mLayoutSet(false) | |
|
13 | ,mLayoutDirty(true) | |
|
14 | { | |
|
15 | dataChanged(); | |
|
16 | } | |
|
17 | ||
|
18 | ||
|
19 | void PercentBarGroup::setSize(const QSizeF& size) | |
|
20 | { | |
|
21 | // qDebug() << "PercentBarGroup::setSize"; | |
|
22 | mWidth = size.width(); | |
|
23 | mHeight = size.height(); | |
|
24 | layoutChanged(); | |
|
25 | mLayoutSet = true; | |
|
26 | } | |
|
27 | ||
|
28 | void PercentBarGroup::setPlotDomain(const PlotDomain& data) | |
|
29 | { | |
|
30 | qDebug() << "PercentBarGroup::setPlotDomain"; | |
|
31 | // TODO: | |
|
32 | } | |
|
33 | 9 | |
|
34 | void PercentBarGroup::setBarWidth( int w ) | |
|
35 | { | |
|
36 | mBarDefaultWidth = w; | |
|
37 | } | |
|
38 | ||
|
39 | int PercentBarGroup::addColor( QColor color ) | |
|
40 | { | |
|
41 | int colorIndex = mColors.count(); | |
|
42 | mColors.append(color); | |
|
43 | return colorIndex; | |
|
44 | } | |
|
45 | ||
|
46 | void PercentBarGroup::resetColors() | |
|
47 | { | |
|
48 | mColors.clear(); | |
|
49 | } | |
|
50 | ||
|
51 | void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
52 | { | |
|
53 | if (!mLayoutSet) { | |
|
54 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
|
55 | return; | |
|
56 | } | |
|
57 | if (mLayoutDirty) { | |
|
58 | // Layout or data has changed. Need to redraw. | |
|
59 | foreach(QGraphicsItem* i, childItems()) { | |
|
60 | i->paint(painter,option,widget); | |
|
61 | } | |
|
62 | mLayoutDirty = false; | |
|
63 | } | |
|
64 | } | |
|
65 | ||
|
66 | QRectF PercentBarGroup::boundingRect() const | |
|
67 | { | |
|
68 | return QRectF(0,0,mWidth,mHeight); | |
|
69 | } | |
|
70 | ||
|
71 | ||
|
72 | void PercentBarGroup::dataChanged() | |
|
10 | PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : | |
|
11 | BarGroupBase(series, parent) | |
|
73 | 12 | { |
|
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 | // TODO: labels from series. This creates just some example labels | |
|
94 | int count = mSeries.countColumns(); | |
|
95 | for (int i=0; i<count; i++) { | |
|
96 | BarLabel* label = new BarLabel(this); | |
|
97 | QString text("Label " + QString::number(i)); | |
|
98 | label->set(text); | |
|
99 | childItems().append(label); | |
|
100 | } | |
|
101 | ||
|
102 | // TODO: if (autolayout) { layoutChanged() } or something | |
|
103 | mLayoutDirty = true; | |
|
104 | 13 | } |
|
105 | 14 | |
|
106 | 15 | void PercentBarGroup::layoutChanged() |
|
107 | 16 | { |
|
108 | 17 | // Scale bars to new layout |
|
109 | 18 | // Layout for bars: |
|
110 | 19 | if (mSeries.countRows() <= 0) { |
|
111 | 20 | // Nothing to do. |
|
112 | 21 | return; |
|
113 | 22 | } |
|
114 | 23 | |
|
115 | 24 | // TODO: better way to auto-layout |
|
116 | 25 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
117 | 26 | int count = mSeries.countColumns(); |
|
118 | 27 | int itemIndex(0); |
|
119 | 28 | qreal tW = mWidth; |
|
120 | 29 | qreal tC = count+1; |
|
121 | 30 | qreal xStep = (tW/tC); |
|
122 | 31 | // qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); |
|
123 | 32 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
124 | 33 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); |
|
125 | 34 | |
|
126 | 35 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
127 | 36 | qreal colSum = mSeries.columnSum(column); |
|
128 | 37 | qreal h = mHeight; |
|
129 | 38 | qreal scale = (h / colSum); |
|
130 | 39 | qreal yPos = h; |
|
131 | 40 | for (int row=0; row < mSeries.countRows(); row++) { |
|
132 | 41 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
133 | 42 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
134 | 43 | |
|
135 | 44 | // TODO: width settable per bar? |
|
136 | 45 | bar->resize(mBarDefaultWidth, barHeight); |
|
137 | 46 | bar->setColor(mColors.at(row)); |
|
138 | 47 | bar->setPos(xPos, yPos-barHeight); |
|
139 | 48 | itemIndex++; |
|
140 | 49 | yPos -= barHeight; |
|
141 | 50 | } |
|
142 | 51 | |
|
143 | 52 | // TODO: Layout for labels, remove magic number |
|
144 | 53 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
145 | 54 | label->setPos(xPos, mHeight + 20); |
|
146 | 55 | labelIndex++; |
|
147 | 56 | xPos += xStep; |
|
148 | 57 | } |
|
58 | ||
|
59 | // Position separators | |
|
60 | int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? | |
|
61 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. | |
|
62 | for (int s=0; s < mSeries.countColumns() - 1; s++) { | |
|
63 | Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex)); | |
|
64 | sep->setPos(xPos,0); | |
|
65 | sep->setSize(QSizeF(1,mHeight)); | |
|
66 | xPos += xStep; | |
|
67 | separatorIndex++; | |
|
68 | } | |
|
69 | ||
|
149 | 70 | mLayoutDirty = true; |
|
150 | 71 | } |
|
151 | 72 | |
|
152 | 73 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +1,28 | |||
|
1 | 1 | #ifndef PERCENTBARGROUP_H |
|
2 | 2 | #define PERCENTBARGROUP_H |
|
3 | 3 | |
|
4 | 4 | #include "chartitem_p.h" |
|
5 | 5 | #include "bar_p.h" |
|
6 | 6 | #include "percentbarchartseries.h" |
|
7 | #include "bargroupbase.h" | |
|
7 | 8 | #include <QGraphicsItem> |
|
8 | 9 | |
|
9 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 11 | |
|
11 |
class PercentBarGroup : public |
|
|
12 | class PercentBarGroup : public BarGroupBase | |
|
12 | 13 | { |
|
13 | 14 | public: |
|
14 | 15 | PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent = 0); |
|
15 | 16 | |
|
16 | public: // From ChartItem | |
|
17 | void setSize(const QSizeF &size); | |
|
18 | void setPlotDomain(const PlotDomain& data); | |
|
19 | ||
|
20 | public: | |
|
21 | // Layout "api" | |
|
22 | void setPos(qreal x, qreal y); | |
|
23 | void setBarWidth( int w ); // Default width for each bar | |
|
24 | ||
|
25 | int addColor( QColor color ); | |
|
26 | void resetColors(); | |
|
27 | ||
|
28 | // From QGraphicsItem | |
|
29 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
|
30 | QRectF boundingRect() const; | |
|
31 | ||
|
32 | 17 | private: |
|
33 | 18 | |
|
34 | void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
|
35 | 19 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
36 | 20 | |
|
37 | 21 | private: |
|
38 | 22 | |
|
39 | 23 | // Data |
|
40 | PercentBarChartSeries& mSeries; | |
|
41 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) | |
|
42 | int mMax; | |
|
43 | ||
|
44 | int mHeight; // Layout spesific | |
|
45 | int mWidth; | |
|
46 | int mBarDefaultWidth; | |
|
47 | ||
|
48 | bool mLayoutSet; // True, if component has been laid out. | |
|
49 | bool mLayoutDirty; | |
|
50 | ||
|
51 | QList<QColor> mColors; // List of colors for series for now | |
|
52 | ||
|
53 | 24 | }; |
|
54 | 25 | |
|
55 | 26 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | 27 | |
|
57 | 28 | #endif // PERCENTBARGROUP_H |
@@ -1,109 +1,15 | |||
|
1 | 1 | #include <limits.h> |
|
2 | 2 | #include <QDebug> |
|
3 | 3 | #include "stackedbarchartseries.h" |
|
4 | 4 | |
|
5 | 5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | 6 | |
|
7 | 7 | StackedBarChartSeries::StackedBarChartSeries(QObject *parent) : |
|
8 |
|
|
|
8 | BarChartSeriesBase(parent) | |
|
9 | 9 | { |
|
10 | 10 | } |
|
11 | 11 | |
|
12 | bool StackedBarChartSeries::setData(QAbstractItemModel* model) | |
|
13 | { | |
|
14 | mModel = model; | |
|
15 | return true; | |
|
16 | } | |
|
17 | ||
|
18 | int StackedBarChartSeries::min() | |
|
19 | { | |
|
20 | Q_ASSERT(mModel->rowCount() > 0); | |
|
21 | Q_ASSERT(mModel->columnCount() > 0); | |
|
22 | ||
|
23 | // TODO: make min and max members and update them when data changes. | |
|
24 | // This is slower since they are checked every time, even if data is same since previous call. | |
|
25 | int min = INT_MAX; | |
|
26 | ||
|
27 | for (int i=0; i <mModel->rowCount(); i++) { | |
|
28 | for(int j=0; j<mModel->columnCount(); j++) { | |
|
29 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
|
30 | if (temp < min) { | |
|
31 | min = temp; | |
|
32 | } | |
|
33 | } | |
|
34 | } | |
|
35 | return min; | |
|
36 | } | |
|
37 | ||
|
38 | int StackedBarChartSeries::max() | |
|
39 | { | |
|
40 | Q_ASSERT(mModel->rowCount() > 0); | |
|
41 | Q_ASSERT(mModel->columnCount() > 0); | |
|
42 | ||
|
43 | // TODO: make min and max members and update them when data changes. | |
|
44 | // This is slower since they are checked every time, even if data is same since previous call. | |
|
45 | int max = INT_MIN; | |
|
46 | ||
|
47 | for (int i=0; i <mModel->rowCount(); i++) { | |
|
48 | for(int j=0; j<mModel->columnCount(); j++) { | |
|
49 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
|
50 | if (temp > max) { | |
|
51 | max = temp; | |
|
52 | } | |
|
53 | } | |
|
54 | } | |
|
55 | return max; | |
|
56 | } | |
|
57 | ||
|
58 | int StackedBarChartSeries::maxColumnSum() | |
|
59 | { | |
|
60 | Q_ASSERT(mModel->rowCount() > 0); | |
|
61 | Q_ASSERT(mModel->columnCount() > 0); | |
|
62 | ||
|
63 | int max = INT_MIN; | |
|
64 | ||
|
65 | for (int col=0; col <mModel->columnCount(); col++) { | |
|
66 | int sum = columnSum(col); | |
|
67 | if (sum > max) { | |
|
68 | max = sum; | |
|
69 | } | |
|
70 | } | |
|
71 | return max; | |
|
72 | } | |
|
73 | ||
|
74 | int StackedBarChartSeries::countRows() | |
|
75 | { | |
|
76 | return mModel->rowCount(); | |
|
77 | } | |
|
78 | ||
|
79 | int StackedBarChartSeries::countColumns() | |
|
80 | { | |
|
81 | return mModel->columnCount(); | |
|
82 | } | |
|
83 | ||
|
84 | int StackedBarChartSeries::countTotalItems() | |
|
85 | { | |
|
86 | return mModel->rowCount() * mModel->columnCount(); | |
|
87 | } | |
|
88 | ||
|
89 | int StackedBarChartSeries::valueAt(int row, int column) | |
|
90 | { | |
|
91 | QModelIndex index = mModel->index(row,column); | |
|
92 | return mModel->data(index).toInt(); | |
|
93 | } | |
|
94 | ||
|
95 | int StackedBarChartSeries::columnSum(int column) | |
|
96 | { | |
|
97 | int sum(0); | |
|
98 | int count = mModel->rowCount(); | |
|
99 | ||
|
100 | for (int row = 0; row < count; row++) { | |
|
101 | sum += mModel->data(mModel->index(row,column)).toInt(); | |
|
102 | } | |
|
103 | return sum; | |
|
104 | } | |
|
105 | ||
|
106 | 12 | #include "moc_stackedbarchartseries.cpp" |
|
107 | 13 | |
|
108 | 14 | QTCOMMERCIALCHART_END_NAMESPACE |
|
109 | 15 |
@@ -1,47 +1,31 | |||
|
1 | 1 | #ifndef STACKEDBARCHARTSERIES_H |
|
2 | 2 | #define STACKEDBARCHARTSERIES_H |
|
3 | 3 | |
|
4 | 4 | #include <QList> |
|
5 | 5 | #include <QAbstractItemModel> |
|
6 |
#include " |
|
|
6 | #include "barchartseriesbase.h" | |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | class StackedBarGroup; |
|
11 | 11 | |
|
12 |
class QTCOMMERCIALCHART_EXPORT StackedBarChartSeries : public |
|
|
12 | class QTCOMMERCIALCHART_EXPORT StackedBarChartSeries : public BarChartSeriesBase | |
|
13 | 13 | { |
|
14 | 14 | Q_OBJECT |
|
15 | 15 | public: |
|
16 | 16 | StackedBarChartSeries(QObject* parent=0); |
|
17 | 17 | |
|
18 | 18 | // from QChartSeries |
|
19 | 19 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; } |
|
20 | 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 | private: | |
|
35 | int columnSum(int column); | |
|
36 | ||
|
37 | 21 | public Q_SLOTS: |
|
38 | 22 | |
|
39 | 23 | private: |
|
40 | 24 | |
|
41 | 25 | QAbstractItemModel* mModel; |
|
42 | 26 | StackedBarGroup* mStackedBarGroup; |
|
43 | 27 | }; |
|
44 | 28 | |
|
45 | 29 | QTCOMMERCIALCHART_END_NAMESPACE |
|
46 | 30 | |
|
47 | 31 | #endif // STACKEDBARCHARTSERIES_H |
@@ -1,192 +1,81 | |||
|
1 | 1 | #include "stackedbargroup.h" |
|
2 | 2 | #include "bar_p.h" |
|
3 | 3 | #include "barlabel_p.h" |
|
4 | #include "separator_p.h" | |
|
4 | 5 | #include <QDebug> |
|
5 | 6 | #include <QPainter> |
|
6 | 7 | |
|
7 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 9 | |
|
9 | 10 | StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : |
|
10 | ChartItem(parent) | |
|
11 | ,mSeries(series) | |
|
12 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |
|
13 | ,mLayoutSet(false) | |
|
14 | ,mLayoutDirty(true) | |
|
15 | ,mTheme(0) | |
|
16 | ,mSeparatorsVisible(true) | |
|
11 | BarGroupBase(series,parent) | |
|
17 | 12 | { |
|
18 | dataChanged(); | |
|
19 | } | |
|
20 | ||
|
21 | void StackedBarGroup::setSeparatorsVisible(bool visible) | |
|
22 | { | |
|
23 | mSeparatorsVisible = visible; | |
|
24 | } | |
|
25 | ||
|
26 | void StackedBarGroup::setSize(const QSizeF& size) | |
|
27 | { | |
|
28 | mWidth = size.width(); | |
|
29 | mHeight = size.height(); | |
|
30 | layoutChanged(); | |
|
31 | mLayoutSet = true; | |
|
32 | } | |
|
33 | ||
|
34 | void StackedBarGroup::setPlotDomain(const PlotDomain& data) | |
|
35 | { | |
|
36 | qDebug() << "StackedBarGroup::setPlotDomain"; | |
|
37 | // TODO: | |
|
38 | } | |
|
39 | ||
|
40 | void StackedBarGroup::themeChanged(ChartTheme *theme) | |
|
41 | { | |
|
42 | mTheme = theme; | |
|
43 | } | |
|
44 | ||
|
45 | void StackedBarGroup::setBarWidth( int w ) | |
|
46 | { | |
|
47 | mBarDefaultWidth = w; | |
|
48 | } | |
|
49 | ||
|
50 | int StackedBarGroup::addColor( QColor color ) | |
|
51 | { | |
|
52 | int colorIndex = mColors.count(); | |
|
53 | mColors.append(color); | |
|
54 | return colorIndex; | |
|
55 | } | |
|
56 | ||
|
57 | void StackedBarGroup::resetColors() | |
|
58 | { | |
|
59 | mColors.clear(); | |
|
60 | } | |
|
61 | ||
|
62 | void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
63 | { | |
|
64 | if (!mLayoutSet) { | |
|
65 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
|
66 | return; | |
|
67 | } | |
|
68 | if (mLayoutDirty) { | |
|
69 | // Layout or data has changed. Need to redraw. | |
|
70 | foreach(QGraphicsItem* i, childItems()) { | |
|
71 | i->paint(painter,option,widget); | |
|
72 | } | |
|
73 | if (mSeparatorsVisible) { | |
|
74 | //TODO: own class for separators (graphicsitem), because they may have style etc later. | |
|
75 | // this is just to see that the positions are calculated correctly. | |
|
76 | QPen pen(QColor(0,0,255,255)); | |
|
77 | painter->setPen(pen); | |
|
78 | for (int i=0; i<mSeparatorPositions.count(); i++ ) { | |
|
79 | qreal xp = mSeparatorPositions.at(i); | |
|
80 | painter->drawLine(xp,0,xp,mHeight); | |
|
81 | } | |
|
82 | } | |
|
83 | // mLayoutDirty = false; | |
|
84 | } | |
|
85 | ||
|
86 | } | |
|
87 | ||
|
88 | QRectF StackedBarGroup::boundingRect() const | |
|
89 | { | |
|
90 | return QRectF(0,0,mWidth,mHeight); | |
|
91 | } | |
|
92 | ||
|
93 | ||
|
94 | void StackedBarGroup::dataChanged() | |
|
95 | { | |
|
96 | qDebug() << "QBarChart::dataChanged"; | |
|
97 | ||
|
98 | // Find out maximum and minimum of all series | |
|
99 | mMax = mSeries.max(); | |
|
100 | mMin = mSeries.min(); | |
|
101 | ||
|
102 | // Delete old bars | |
|
103 | // Is this correct way to delete childItems? | |
|
104 | foreach (QGraphicsItem* item, childItems()) { | |
|
105 | delete item; | |
|
106 | } | |
|
107 | ||
|
108 | // Create new graphic items for bars | |
|
109 | int totalItems = mSeries.countTotalItems(); | |
|
110 | for (int i=0; i<totalItems; i++) { | |
|
111 | Bar *bar = new Bar(this); | |
|
112 | childItems().append(bar); | |
|
113 | } | |
|
114 | ||
|
115 | // TODO: labels from series. This creates just some example labels | |
|
116 | int count = mSeries.countColumns(); | |
|
117 | for (int i=0; i<count; i++) { | |
|
118 | BarLabel* label = new BarLabel(this); | |
|
119 | QString text("Label " + QString::number(i)); | |
|
120 | label->set(text); | |
|
121 | childItems().append(label); | |
|
122 | } | |
|
123 | ||
|
124 | mSeparatorPositions.clear(); | |
|
125 | ||
|
126 | // TODO: if (autolayout) { layoutChanged() } or something | |
|
127 | mLayoutDirty = true; | |
|
128 | 13 | } |
|
129 | 14 | |
|
130 | 15 | void StackedBarGroup::layoutChanged() |
|
131 | 16 | { |
|
132 | 17 | // Scale bars to new layout |
|
133 | 18 | // Layout for bars: |
|
134 | 19 | if (mSeries.countRows() <= 0) { |
|
135 | 20 | // Nothing to do. |
|
136 | 21 | return; |
|
137 | 22 | } |
|
138 | 23 | |
|
139 | 24 | if (mSeries.countColumns() == 0) { |
|
140 | 25 | // Nothing to do |
|
141 | 26 | return; |
|
142 | 27 | } |
|
143 | 28 | |
|
144 | 29 | // TODO: better way to auto-layout |
|
145 | 30 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
146 | 31 | // TODO: use temp variable for column count... |
|
147 | 32 | qreal maxSum = mSeries.maxColumnSum(); |
|
148 | 33 | qreal h = mHeight; |
|
149 | 34 | qreal scale = (h / maxSum); |
|
150 | 35 | |
|
151 | 36 | int itemIndex(0); |
|
152 | 37 | qreal tW = mWidth; |
|
153 | 38 | qreal tC = mSeries.countColumns() + 1; |
|
154 | 39 | qreal xStep = (tW/tC); |
|
155 | 40 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
156 | 41 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); |
|
157 | 42 | |
|
158 | 43 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
159 | 44 | qreal yPos = h; |
|
160 | 45 | for (int row=0; row < mSeries.countRows(); row++) { |
|
161 | 46 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
162 | 47 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
163 | 48 | |
|
164 | 49 | // TODO: width settable per bar? |
|
165 | 50 | // TODO: how to get color for series(x) from theme? |
|
166 | 51 | // mTheme->themeForSeries(); |
|
167 | 52 | bar->resize(mBarDefaultWidth, barHeight); |
|
168 | 53 | bar->setColor(mColors.at(row)); |
|
169 | 54 | bar->setPos(xPos, yPos-barHeight); |
|
170 | 55 | itemIndex++; |
|
171 | 56 | yPos -= barHeight; |
|
172 | 57 | } |
|
173 | 58 | |
|
174 | 59 | // TODO: Layout for labels, remove magic number |
|
175 | 60 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
176 | 61 | label->setPos(xPos, mHeight + 20); |
|
177 | 62 | labelIndex++; |
|
178 | 63 | xPos += xStep; |
|
179 | 64 | } |
|
180 | 65 | |
|
66 | ||
|
181 | 67 | // Position separators |
|
182 | mSeparatorPositions.clear(); | |
|
183 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. | |
|
68 | int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? | |
|
69 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. | |
|
184 | 70 | for (int s=0; s < mSeries.countColumns() - 1; s++) { |
|
185 | mSeparatorPositions.append(xPos); | |
|
71 | Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex)); | |
|
72 | sep->setPos(xPos,0); | |
|
73 | sep->setSize(QSizeF(1,mHeight)); | |
|
186 | 74 | xPos += xStep; |
|
75 | separatorIndex++; | |
|
187 | 76 | } |
|
188 | 77 | |
|
189 | 78 | mLayoutDirty = true; |
|
190 | 79 | } |
|
191 | 80 | |
|
192 | 81 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,69 +1,26 | |||
|
1 | 1 | #ifndef STACKEDBARGROUP_H |
|
2 | 2 | #define STACKEDBARGROUP_H |
|
3 | 3 | |
|
4 |
#include " |
|
|
5 | #include "chartitem_p.h" | |
|
6 | #include "barlabel_p.h" | |
|
7 | #include "bar_p.h" | |
|
4 | #include "bargroupbase.h" | |
|
8 | 5 | #include "stackedbarchartseries.h" |
|
9 | 6 | #include <QGraphicsItem> |
|
10 | 7 | |
|
11 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | 9 | |
|
13 | // TODO: derive this from ChartObjectInterface, when setSize is back in ChartItem | |
|
14 | class StackedBarGroup : public ChartItem, public ChartThemeObserver | |
|
10 | class StackedBarGroup : public BarGroupBase | |
|
15 | 11 | { |
|
16 | 12 | public: |
|
17 | 13 | StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent = 0); |
|
18 | 14 | |
|
19 | // Bar chart spesific | |
|
20 | void setSeparatorsVisible(bool visible = true); | |
|
21 | ||
|
22 | public: // From ChartItem | |
|
23 | void setSize(const QSizeF &size); | |
|
24 | void setPlotDomain(const PlotDomain& data); | |
|
25 | ||
|
26 | // From ChartThemeObserver | |
|
27 | void themeChanged(ChartTheme *theme); | |
|
28 | ||
|
29 | public: // Layout "api" | |
|
30 | void setPos(qreal x, qreal y); | |
|
31 | void setBarWidth( int w ); // Default width for each bar | |
|
32 | ||
|
33 | int addColor( QColor color ); | |
|
34 | void resetColors(); | |
|
35 | ||
|
36 | // From QGraphicsItem | |
|
37 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
|
38 | QRectF boundingRect() const; | |
|
39 | ||
|
40 | 15 | private: |
|
41 | ||
|
42 | void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
|
16 | // From BarGroupBase | |
|
43 | 17 | void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
44 | 18 | |
|
45 | 19 | private: |
|
46 | 20 | |
|
47 | 21 | // Data |
|
48 | StackedBarChartSeries& mSeries; | |
|
49 | int mMin; // Min and max values of data. (updated when data is changed, used when drawing) | |
|
50 | int mMax; | |
|
51 | ||
|
52 | int mHeight; // Layout spesific | |
|
53 | int mWidth; | |
|
54 | int mBarDefaultWidth; | |
|
55 | ||
|
56 | bool mLayoutSet; // True, if component has been laid out. | |
|
57 | bool mLayoutDirty; | |
|
58 | ||
|
59 | QList<QColor> mColors; // List of colors for series for now | |
|
60 | ||
|
61 | ChartTheme* mTheme; | |
|
62 | bool mSeparatorsVisible; | |
|
63 | QList<qreal> mSeparatorPositions; | |
|
64 | ||
|
65 | 22 | }; |
|
66 | 23 | |
|
67 | 24 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | 25 | |
|
69 | 26 | #endif // STACKEDBARGROUP_H |
@@ -1,116 +1,122 | |||
|
1 | 1 | !include( ../common.pri ) { |
|
2 | 2 | error( Couldn't find the common.pri file! ) |
|
3 | 3 | } |
|
4 | 4 | |
|
5 | 5 | TARGET = QtCommercialChart |
|
6 | 6 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
7 | 7 | TEMPLATE = lib |
|
8 | 8 | QT += core \ |
|
9 | 9 | gui |
|
10 | 10 | |
|
11 | 11 | CONFIG += debug_and_release |
|
12 | 12 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
13 | 13 | |
|
14 | 14 | SOURCES += \ |
|
15 | 15 | barchart/barchartseries.cpp \ |
|
16 | 16 | barchart/bargroup.cpp \ |
|
17 | 17 | barchart/bar.cpp \ |
|
18 | 18 | barchart/stackedbarchartseries.cpp \ |
|
19 | 19 | barchart/stackedbargroup.cpp \ |
|
20 | 20 | barchart/percentbarchartseries.cpp \ |
|
21 | 21 | barchart/percentbargroup.cpp \ |
|
22 | 22 | barchart/barlabel.cpp \ |
|
23 | 23 | xylinechart/qxychartseries.cpp \ |
|
24 | 24 | xylinechart/xylinechartitem.cpp \ |
|
25 | 25 | plotdomain.cpp \ |
|
26 | 26 | qscatterseries.cpp \ |
|
27 | 27 | qpieseries.cpp \ |
|
28 | 28 | qchart.cpp \ |
|
29 | 29 | axisitem.cpp \ |
|
30 | 30 | qchartwidget.cpp \ |
|
31 | 31 | pieslice.cpp \ |
|
32 | 32 | qchartview.cpp \ |
|
33 | 33 | qchartseries.cpp \ |
|
34 | 34 | qchartaxis.cpp \ |
|
35 | charttheme.cpp | |
|
35 | charttheme.cpp \ | |
|
36 | barchart/separator.cpp \ | |
|
37 | barchart/bargroupbase.cpp \ | |
|
38 | barchart/barchartseriesbase.cpp | |
|
36 | 39 | |
|
37 | 40 | PRIVATE_HEADERS += \ |
|
38 | 41 | xylinechart/xylinechartitem_p.h \ |
|
39 | 42 | barchart/barlabel_p.h \ |
|
40 | 43 | barchart/bar_p.h \ |
|
44 | barchart/separator_p.h \ | |
|
41 | 45 | plotdomain_p.h \ |
|
42 | 46 | qscatterseries_p.h \ |
|
43 | 47 | qpieseries_p.h \ |
|
44 | 48 | pieslice.h \ |
|
45 | 49 | axisitem_p.h \ |
|
46 | 50 | chartitem_p.h \ |
|
47 | 51 | charttheme_p.h |
|
48 | 52 | |
|
49 | 53 | PUBLIC_HEADERS += \ |
|
50 | 54 | qchartseries.h \ |
|
51 | 55 | qscatterseries.h \ |
|
52 | 56 | qpieseries.h \ |
|
53 | 57 | qchart.h \ |
|
54 | 58 | qchartwidget.h \ |
|
55 | 59 | qchartglobal.h \ |
|
56 | 60 | xylinechart/qxychartseries.h \ |
|
57 | 61 | barchart/barchartseries.h \ |
|
58 | 62 | barchart/bargroup.h \ |
|
59 | 63 | barchart/stackedbarchartseries.h \ |
|
60 | 64 | barchart/stackedbargroup.h \ |
|
61 | 65 | barchart/percentbarchartseries.h \ |
|
62 | 66 | barchart/percentbargroup.h \ |
|
67 | barchart/barchartseriesbase.h \ | |
|
68 | barchart/bargroupbase.h \ | |
|
63 | 69 | qchartview.h \ |
|
64 | 70 | qchartaxis.h |
|
65 | 71 | |
|
66 | 72 | HEADERS += $$PUBLIC_HEADERS |
|
67 | 73 | HEADERS += $$PRIVATE_HEADERS |
|
68 | 74 | |
|
69 | 75 | INCLUDEPATH += xylinechart \ |
|
70 | 76 | barchart \ |
|
71 | 77 | . |
|
72 | 78 | |
|
73 | 79 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
74 | 80 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
75 | 81 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
76 | 82 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
77 | 83 | |
|
78 | 84 | |
|
79 | 85 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
80 | 86 | |
|
81 | 87 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
82 | 88 | public_headers.files = $$PUBLIC_HEADERS |
|
83 | 89 | target.path = $$[QT_INSTALL_LIBS] |
|
84 | 90 | INSTALLS += target \ |
|
85 | 91 | public_headers |
|
86 | 92 | |
|
87 | 93 | |
|
88 | 94 | install_build_headers.name = bild_headers |
|
89 | 95 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
90 | 96 | install_build_headers.input = PUBLIC_HEADERS |
|
91 | 97 | install_build_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} $$CHART_BUILD_HEADER_DIR |
|
92 | 98 | install_build_headers.CONFIG += target_predeps no_link |
|
93 | 99 | QMAKE_EXTRA_COMPILERS += install_build_headers |
|
94 | 100 | |
|
95 | 101 | chartversion.target = qchartversion_p.h |
|
96 | 102 | chartversion.commands = @echo "build_time" > $$chartversion.target; |
|
97 | 103 | chartversion.depends = $$HEADERS $$SOURCES |
|
98 | 104 | PRE_TARGETDEPS += qchartversion_p.h |
|
99 | 105 | QMAKE_CLEAN+= qchartversion_p.h |
|
100 | 106 | QMAKE_EXTRA_TARGETS += chartversion |
|
101 | 107 | |
|
102 | 108 | unix:QMAKE_DISTCLEAN += -r $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
103 | 109 | win32:QMAKE_DISTCLEAN += /Q $$CHART_BUILD_HEADER_DIR $$CHART_BUILD_LIB_DIR |
|
104 | 110 | |
|
105 | 111 | |
|
106 | 112 | |
|
107 | 113 | |
|
108 | 114 | |
|
109 | 115 | |
|
110 | 116 | |
|
111 | 117 | |
|
112 | 118 | |
|
113 | 119 | |
|
114 | 120 | |
|
115 | 121 | |
|
116 | 122 |
General Comments 0
You need to be logged in to leave comments.
Login now