@@ -1,79 +1,80 | |||||
1 | #include <QDebug> |
|
1 | #include <QDebug> | |
2 | #include "barchartseries.h" |
|
2 | #include "barchartseries.h" | |
3 | #include "bargroup.h" |
|
3 | #include "bargroup.h" | |
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
5 | |||
6 | BarChartSeries::BarChartSeries(QObject *parent) |
|
6 | BarChartSeries::BarChartSeries(QObject *parent) | |
7 | : QChartSeries(parent) |
|
7 | : QChartSeries(parent) | |
8 | { |
|
8 | { | |
9 | } |
|
9 | } | |
10 |
|
10 | |||
11 | bool BarChartSeries::setData(QAbstractItemModel* model) |
|
11 | bool BarChartSeries::setData(QAbstractItemModel* model) | |
12 | { |
|
12 | { | |
13 | mModel = model; |
|
13 | mModel = model; | |
|
14 | return true; | |||
14 | } |
|
15 | } | |
15 |
|
16 | |||
16 | int BarChartSeries::min() |
|
17 | int BarChartSeries::min() | |
17 | { |
|
18 | { | |
18 | Q_ASSERT(mModel->rowCount() > 0); |
|
19 | Q_ASSERT(mModel->rowCount() > 0); | |
19 | Q_ASSERT(mModel->columnCount() > 0); |
|
20 | Q_ASSERT(mModel->columnCount() > 0); | |
20 |
|
21 | |||
21 | // TODO: make min and max members and update them when data changes. |
|
22 | // TODO: make min and max members and update them when data changes. | |
22 | // This is slower since they are checked every time, even if data is same since previous call. |
|
23 | // This is slower since they are checked every time, even if data is same since previous call. | |
23 | int min = INT_MAX; |
|
24 | int min = INT_MAX; | |
24 |
|
25 | |||
25 | for (int i=0; i <mModel->rowCount(); i++) { |
|
26 | for (int i=0; i <mModel->rowCount(); i++) { | |
26 | for(int j=0; j<mModel->columnCount(); j++) { |
|
27 | for(int j=0; j<mModel->columnCount(); j++) { | |
27 | int temp = mModel->data(mModel->index(i,j)).toInt(); |
|
28 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
28 | if (temp < min) { |
|
29 | if (temp < min) { | |
29 | min = temp; |
|
30 | min = temp; | |
30 | } |
|
31 | } | |
31 | } |
|
32 | } | |
32 | } |
|
33 | } | |
33 | return min; |
|
34 | return min; | |
34 | } |
|
35 | } | |
35 |
|
36 | |||
36 | int BarChartSeries::max() |
|
37 | int BarChartSeries::max() | |
37 | { |
|
38 | { | |
38 | Q_ASSERT(mModel->rowCount() > 0); |
|
39 | Q_ASSERT(mModel->rowCount() > 0); | |
39 | Q_ASSERT(mModel->columnCount() > 0); |
|
40 | Q_ASSERT(mModel->columnCount() > 0); | |
40 |
|
41 | |||
41 | // TODO: make min and max members and update them when data changes. |
|
42 | // TODO: make min and max members and update them when data changes. | |
42 | // This is slower since they are checked every time, even if data is same since previous call. |
|
43 | // This is slower since they are checked every time, even if data is same since previous call. | |
43 | int max = INT_MIN; |
|
44 | int max = INT_MIN; | |
44 |
|
45 | |||
45 | for (int i=0; i <mModel->rowCount(); i++) { |
|
46 | for (int i=0; i <mModel->rowCount(); i++) { | |
46 | for(int j=0; j<mModel->columnCount(); j++) { |
|
47 | for(int j=0; j<mModel->columnCount(); j++) { | |
47 | int temp = mModel->data(mModel->index(i,j)).toInt(); |
|
48 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
48 | if (temp > max) { |
|
49 | if (temp > max) { | |
49 | max = temp; |
|
50 | max = temp; | |
50 | } |
|
51 | } | |
51 | } |
|
52 | } | |
52 | } |
|
53 | } | |
53 | return max; |
|
54 | return max; | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
56 |
|
57 | |||
57 | int BarChartSeries::countRows() |
|
58 | int BarChartSeries::countRows() | |
58 | { |
|
59 | { | |
59 | return mModel->rowCount(); |
|
60 | return mModel->rowCount(); | |
60 | } |
|
61 | } | |
61 |
|
62 | |||
62 | int BarChartSeries::countColumns() |
|
63 | int BarChartSeries::countColumns() | |
63 | { |
|
64 | { | |
64 | return mModel->columnCount(); |
|
65 | return mModel->columnCount(); | |
65 | } |
|
66 | } | |
66 |
|
67 | |||
67 | int BarChartSeries::countTotalItems() |
|
68 | int BarChartSeries::countTotalItems() | |
68 | { |
|
69 | { | |
69 | return mModel->rowCount() * mModel->columnCount(); |
|
70 | return mModel->rowCount() * mModel->columnCount(); | |
70 | } |
|
71 | } | |
71 |
|
72 | |||
72 | int BarChartSeries::valueAt(int row, int column) |
|
73 | int BarChartSeries::valueAt(int row, int column) | |
73 | { |
|
74 | { | |
74 | return mModel->data(mModel->index(row,column)).toInt(); |
|
75 | return mModel->data(mModel->index(row,column)).toInt(); | |
75 | } |
|
76 | } | |
76 |
|
77 | |||
77 | #include "moc_barchartseries.cpp" |
|
78 | #include "moc_barchartseries.cpp" | |
78 |
|
79 | |||
79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
80 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,157 +1,157 | |||||
1 | #include "bargroup.h" |
|
1 | #include "bargroup.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) : |
|
8 | BarGroup::BarGroup(BarChartSeries& series, QGraphicsItem *parent) : | |
9 | ChartItem(parent) |
|
9 | ChartItem(parent) | |
10 | ,mSeries(series) |
|
10 | ,mSeries(series) | |
|
11 | ,mBarDefaultWidth(10) | |||
11 | ,mLayoutSet(false) |
|
12 | ,mLayoutSet(false) | |
12 | ,mLayoutDirty(true) |
|
13 | ,mLayoutDirty(true) | |
13 | ,mBarDefaultWidth(10) |
|
|||
14 | { |
|
14 | { | |
15 | dataChanged(); |
|
15 | dataChanged(); | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | void BarGroup::setSize(const QSizeF& size) |
|
18 | void BarGroup::setSize(const QSizeF& 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 | mPlotDomain = data; | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | void BarGroup::setBarWidth( int w ) |
|
34 | void BarGroup::setBarWidth( int w ) | |
35 | { |
|
35 | { | |
36 | mBarDefaultWidth = w; |
|
36 | mBarDefaultWidth = w; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | int BarGroup::addColor( QColor color ) |
|
39 | int BarGroup::addColor( QColor color ) | |
40 | { |
|
40 | { | |
41 | int colorIndex = mColors.count(); |
|
41 | int colorIndex = mColors.count(); | |
42 | mColors.append(color); |
|
42 | mColors.append(color); | |
43 | return colorIndex; |
|
43 | return colorIndex; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void BarGroup::resetColors() |
|
46 | void BarGroup::resetColors() | |
47 | { |
|
47 | { | |
48 | mColors.clear(); |
|
48 | mColors.clear(); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void BarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
51 | void BarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
52 | { |
|
52 | { | |
53 | if (!mLayoutSet) { |
|
53 | if (!mLayoutSet) { | |
54 | qDebug() << "QBarChart::paint called without layout set. Aborting."; |
|
54 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
55 | return; |
|
55 | return; | |
56 | } |
|
56 | } | |
57 | if (mLayoutDirty) { |
|
57 | if (mLayoutDirty) { | |
58 | // Layout or data has changed. Need to redraw. |
|
58 | // Layout or data has changed. Need to redraw. | |
59 | foreach(QGraphicsItem* i, childItems()) { |
|
59 | foreach(QGraphicsItem* i, childItems()) { | |
60 | i->paint(painter,option,widget); |
|
60 | i->paint(painter,option,widget); | |
61 | mLayoutDirty = false; |
|
61 | mLayoutDirty = false; | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QRectF BarGroup::boundingRect() const |
|
66 | QRectF BarGroup::boundingRect() const | |
67 | { |
|
67 | { | |
68 | return QRectF(0,0,mWidth,mHeight); |
|
68 | return QRectF(0,0,mWidth,mHeight); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | void BarGroup::dataChanged() |
|
72 | void BarGroup::dataChanged() | |
73 | { |
|
73 | { | |
74 | qDebug() << "QBarChart::dataChanged mSeries"; |
|
74 | qDebug() << "QBarChart::dataChanged mSeries"; | |
75 |
|
75 | |||
76 | // Find out maximum and minimum of all series |
|
76 | // Find out maximum and minimum of all series | |
77 | mMax = mSeries.max(); |
|
77 | mMax = mSeries.max(); | |
78 | mMin = mSeries.min(); |
|
78 | mMin = mSeries.min(); | |
79 |
|
79 | |||
80 | // Delete old bars |
|
80 | // Delete old bars | |
81 | // Is this correct way to delete childItems? |
|
81 | // Is this correct way to delete childItems? | |
82 | foreach (QGraphicsItem* item, childItems()) { |
|
82 | foreach (QGraphicsItem* item, childItems()) { | |
83 | delete item; |
|
83 | delete item; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | // Create new graphic items for bars |
|
86 | // Create new graphic items for bars | |
87 | int totalItems = mSeries.countTotalItems(); |
|
87 | int totalItems = mSeries.countTotalItems(); | |
88 | for (int i=0; i<totalItems; i++) { |
|
88 | for (int i=0; i<totalItems; i++) { | |
89 | Bar *bar = new Bar(this); |
|
89 | Bar *bar = new Bar(this); | |
90 | childItems().append(bar); |
|
90 | childItems().append(bar); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | // TODO: labels from series. This creates just some example labels |
|
93 | // TODO: labels from series. This creates just some example labels | |
94 | int count = mSeries.countColumns(); |
|
94 | int count = mSeries.countColumns(); | |
95 | for (int i=0; i<count; i++) { |
|
95 | for (int i=0; i<count; i++) { | |
96 | BarLabel* label = new BarLabel(this); |
|
96 | BarLabel* label = new BarLabel(this); | |
97 | QString text("Label " + QString::number(i)); |
|
97 | QString text("Label " + QString::number(i)); | |
98 | label->set(text); |
|
98 | label->set(text); | |
99 | childItems().append(label); |
|
99 | childItems().append(label); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | // TODO: if (autolayout) { layoutChanged() } or something |
|
102 | // TODO: if (autolayout) { layoutChanged() } or something | |
103 | mLayoutDirty = true; |
|
103 | mLayoutDirty = true; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void BarGroup::layoutChanged() |
|
106 | void BarGroup::layoutChanged() | |
107 | { |
|
107 | { | |
108 | // Scale bars to new layout |
|
108 | // Scale bars to new layout | |
109 | // Layout for bars: |
|
109 | // Layout for bars: | |
110 | if (mSeries.countRows() <= 0) { |
|
110 | if (mSeries.countRows() <= 0) { | |
111 | // Nothing to do. |
|
111 | // Nothing to do. | |
112 | return; |
|
112 | return; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | // TODO: better way to auto-layout? |
|
115 | // TODO: better way to auto-layout? | |
116 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
116 | // Use reals for accurancy (we might get some compiler warnings... :) | |
117 | int columnCount = mSeries.countColumns(); |
|
117 | int columnCount = mSeries.countColumns(); | |
118 | int rowCount = mSeries.countRows(); |
|
118 | int rowCount = mSeries.countRows(); | |
119 |
|
119 | |||
120 | qreal tW = mWidth; |
|
120 | qreal tW = mWidth; | |
121 | qreal tH = mHeight; |
|
121 | qreal tH = mHeight; | |
122 | qreal tM = mMax; |
|
122 | qreal tM = mMax; | |
123 | qreal scale = (tH/tM); |
|
123 | qreal scale = (tH/tM); | |
124 |
|
124 | |||
125 | qreal tC = columnCount+1; |
|
125 | qreal tC = columnCount+1; | |
126 | qreal xStepPerSeries = (tW/tC); |
|
126 | qreal xStepPerSeries = (tW/tC); | |
127 |
|
127 | |||
128 | // Scaling. |
|
128 | // Scaling. | |
129 | int itemIndex(0); |
|
129 | int itemIndex(0); | |
130 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); |
|
130 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); | |
131 |
|
131 | |||
132 | for (int column=0; column < columnCount; column++) { |
|
132 | for (int column=0; column < columnCount; column++) { | |
133 | qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); |
|
133 | qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); | |
134 | qreal yPos = mHeight; |
|
134 | qreal yPos = mHeight; | |
135 | for (int row = 0; row < rowCount; row++) { |
|
135 | for (int row = 0; row < rowCount; row++) { | |
136 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
136 | qreal barHeight = mSeries.valueAt(row, column) * scale; | |
137 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
137 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
138 |
|
138 | |||
139 | // TODO: width settable per bar? |
|
139 | // TODO: width settable per bar? | |
140 | bar->resize(mBarDefaultWidth, barHeight); |
|
140 | bar->resize(mBarDefaultWidth, barHeight); | |
141 | bar->setColor(mColors.at(row)); |
|
141 | bar->setColor(mColors.at(row)); | |
142 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); |
|
142 | bar->setPos(xPos, yPos-barHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight); | |
143 | itemIndex++; |
|
143 | itemIndex++; | |
144 | xPos += mBarDefaultWidth; |
|
144 | xPos += mBarDefaultWidth; | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | // TODO: Layout for labels, remove magic number |
|
147 | // TODO: Layout for labels, remove magic number | |
148 | xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); |
|
148 | xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2)); | |
149 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
149 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
150 | label->setPos(xPos, mHeight + 20); |
|
150 | label->setPos(xPos, mHeight + 20); | |
151 | labelIndex++; |
|
151 | labelIndex++; | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | mLayoutDirty = true; |
|
154 | mLayoutDirty = true; | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | QTCOMMERCIALCHART_END_NAMESPACE |
|
157 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,110 +1,111 | |||||
1 | #include "percentbarchartseries.h" |
|
1 | #include "percentbarchartseries.h" | |
2 |
|
2 | |||
3 | #include <limits.h> |
|
3 | #include <limits.h> | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 | #include "percentbarchartseries.h" |
|
5 | #include "percentbarchartseries.h" | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | PercentBarChartSeries::PercentBarChartSeries(QObject *parent) : |
|
9 | PercentBarChartSeries::PercentBarChartSeries(QObject *parent) : | |
10 | QChartSeries(parent) |
|
10 | QChartSeries(parent) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | bool PercentBarChartSeries::setData(QAbstractItemModel* model) |
|
14 | bool PercentBarChartSeries::setData(QAbstractItemModel* model) | |
15 | { |
|
15 | { | |
16 | mModel = model; |
|
16 | mModel = model; | |
|
17 | return true; | |||
17 | } |
|
18 | } | |
18 |
|
19 | |||
19 | int PercentBarChartSeries::min() |
|
20 | int PercentBarChartSeries::min() | |
20 | { |
|
21 | { | |
21 | Q_ASSERT(mModel->rowCount() > 0); |
|
22 | Q_ASSERT(mModel->rowCount() > 0); | |
22 | Q_ASSERT(mModel->columnCount() > 0); |
|
23 | Q_ASSERT(mModel->columnCount() > 0); | |
23 |
|
24 | |||
24 | // TODO: make min and max members and update them when data changes. |
|
25 | // 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 | // This is slower since they are checked every time, even if data is same since previous call. | |
26 | int min = INT_MAX; |
|
27 | int min = INT_MAX; | |
27 |
|
28 | |||
28 | for (int i=0; i <mModel->rowCount(); i++) { |
|
29 | for (int i=0; i <mModel->rowCount(); i++) { | |
29 | for(int j=0; j<mModel->columnCount(); j++) { |
|
30 | for(int j=0; j<mModel->columnCount(); j++) { | |
30 | int temp = mModel->data(mModel->index(i,j)).toInt(); |
|
31 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
31 | if (temp < min) { |
|
32 | if (temp < min) { | |
32 | min = temp; |
|
33 | min = temp; | |
33 | } |
|
34 | } | |
34 | } |
|
35 | } | |
35 | } |
|
36 | } | |
36 | return min; |
|
37 | return min; | |
37 | } |
|
38 | } | |
38 |
|
39 | |||
39 | int PercentBarChartSeries::max() |
|
40 | int PercentBarChartSeries::max() | |
40 | { |
|
41 | { | |
41 | Q_ASSERT(mModel->rowCount() > 0); |
|
42 | Q_ASSERT(mModel->rowCount() > 0); | |
42 | Q_ASSERT(mModel->columnCount() > 0); |
|
43 | Q_ASSERT(mModel->columnCount() > 0); | |
43 |
|
44 | |||
44 | // TODO: make min and max members and update them when data changes. |
|
45 | // 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 | // This is slower since they are checked every time, even if data is same since previous call. | |
46 | int max = INT_MIN; |
|
47 | int max = INT_MIN; | |
47 |
|
48 | |||
48 | for (int i=0; i <mModel->rowCount(); i++) { |
|
49 | for (int i=0; i <mModel->rowCount(); i++) { | |
49 | for(int j=0; j<mModel->columnCount(); j++) { |
|
50 | for(int j=0; j<mModel->columnCount(); j++) { | |
50 | int temp = mModel->data(mModel->index(i,j)).toInt(); |
|
51 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
51 | if (temp > max) { |
|
52 | if (temp > max) { | |
52 | max = temp; |
|
53 | max = temp; | |
53 | } |
|
54 | } | |
54 | } |
|
55 | } | |
55 | } |
|
56 | } | |
56 | return max; |
|
57 | return max; | |
57 | } |
|
58 | } | |
58 |
|
59 | |||
59 | int PercentBarChartSeries::maxColumnSum() |
|
60 | int PercentBarChartSeries::maxColumnSum() | |
60 | { |
|
61 | { | |
61 | Q_ASSERT(mModel->rowCount() > 0); |
|
62 | Q_ASSERT(mModel->rowCount() > 0); | |
62 | Q_ASSERT(mModel->columnCount() > 0); |
|
63 | Q_ASSERT(mModel->columnCount() > 0); | |
63 |
|
64 | |||
64 | int max = INT_MIN; |
|
65 | int max = INT_MIN; | |
65 |
|
66 | |||
66 | for (int col=0; col <mModel->columnCount(); col++) { |
|
67 | for (int col=0; col <mModel->columnCount(); col++) { | |
67 | int sum = columnSum(col); |
|
68 | int sum = columnSum(col); | |
68 | if (sum > max) { |
|
69 | if (sum > max) { | |
69 | max = sum; |
|
70 | max = sum; | |
70 | } |
|
71 | } | |
71 | } |
|
72 | } | |
72 | return max; |
|
73 | return max; | |
73 | } |
|
74 | } | |
74 |
|
75 | |||
75 | int PercentBarChartSeries::countRows() |
|
76 | int PercentBarChartSeries::countRows() | |
76 | { |
|
77 | { | |
77 | return mModel->rowCount(); |
|
78 | return mModel->rowCount(); | |
78 | } |
|
79 | } | |
79 |
|
80 | |||
80 | int PercentBarChartSeries::countColumns() |
|
81 | int PercentBarChartSeries::countColumns() | |
81 | { |
|
82 | { | |
82 | return mModel->columnCount(); |
|
83 | return mModel->columnCount(); | |
83 | } |
|
84 | } | |
84 |
|
85 | |||
85 | int PercentBarChartSeries::countTotalItems() |
|
86 | int PercentBarChartSeries::countTotalItems() | |
86 | { |
|
87 | { | |
87 | return mModel->rowCount() * mModel->columnCount(); |
|
88 | return mModel->rowCount() * mModel->columnCount(); | |
88 | } |
|
89 | } | |
89 |
|
90 | |||
90 | int PercentBarChartSeries::valueAt(int row, int column) |
|
91 | int PercentBarChartSeries::valueAt(int row, int column) | |
91 | { |
|
92 | { | |
92 | QModelIndex index = mModel->index(row,column); |
|
93 | QModelIndex index = mModel->index(row,column); | |
93 | return mModel->data(index).toInt(); |
|
94 | return mModel->data(index).toInt(); | |
94 | } |
|
95 | } | |
95 |
|
96 | |||
96 | int PercentBarChartSeries::columnSum(int column) |
|
97 | int PercentBarChartSeries::columnSum(int column) | |
97 | { |
|
98 | { | |
98 | int sum(0); |
|
99 | int sum(0); | |
99 | int count = mModel->rowCount(); |
|
100 | int count = mModel->rowCount(); | |
100 |
|
101 | |||
101 | for (int row = 0; row < count; row++) { |
|
102 | for (int row = 0; row < count; row++) { | |
102 | sum += mModel->data(mModel->index(row,column)).toInt(); |
|
103 | sum += mModel->data(mModel->index(row,column)).toInt(); | |
103 | } |
|
104 | } | |
104 | return sum; |
|
105 | return sum; | |
105 | } |
|
106 | } | |
106 |
|
107 | |||
107 | #include "moc_percentbarchartseries.cpp" |
|
108 | #include "moc_percentbarchartseries.cpp" | |
108 |
|
109 | |||
109 | QTCOMMERCIALCHART_END_NAMESPACE |
|
110 | QTCOMMERCIALCHART_END_NAMESPACE | |
110 |
|
111 |
@@ -1,152 +1,152 | |||||
1 | #include "percentbargroup.h" |
|
1 | #include "percentbargroup.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : |
|
8 | PercentBarGroup::PercentBarGroup(PercentBarChartSeries& series, QGraphicsItem *parent) : | |
9 | ChartItem(parent) |
|
9 | ChartItem(parent) | |
10 | ,mSeries(series) |
|
10 | ,mSeries(series) | |
|
11 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |||
11 | ,mLayoutSet(false) |
|
12 | ,mLayoutSet(false) | |
12 | ,mLayoutDirty(true) |
|
13 | ,mLayoutDirty(true) | |
13 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready |
|
|||
14 | { |
|
14 | { | |
15 | dataChanged(); |
|
15 | dataChanged(); | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | void PercentBarGroup::setSize(const QSizeF& size) |
|
19 | void PercentBarGroup::setSize(const QSizeF& size) | |
20 | { |
|
20 | { | |
21 | // qDebug() << "PercentBarGroup::setSize"; |
|
21 | // qDebug() << "PercentBarGroup::setSize"; | |
22 | mWidth = size.width(); |
|
22 | mWidth = size.width(); | |
23 | mHeight = size.height(); |
|
23 | mHeight = size.height(); | |
24 | layoutChanged(); |
|
24 | layoutChanged(); | |
25 | mLayoutSet = true; |
|
25 | mLayoutSet = true; | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | void PercentBarGroup::setPlotDomain(const PlotDomain& data) |
|
28 | void PercentBarGroup::setPlotDomain(const PlotDomain& data) | |
29 | { |
|
29 | { | |
30 | qDebug() << "PercentBarGroup::setPlotDomain"; |
|
30 | qDebug() << "PercentBarGroup::setPlotDomain"; | |
31 | // TODO: |
|
31 | // TODO: | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | void PercentBarGroup::setBarWidth( int w ) |
|
34 | void PercentBarGroup::setBarWidth( int w ) | |
35 | { |
|
35 | { | |
36 | mBarDefaultWidth = w; |
|
36 | mBarDefaultWidth = w; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | int PercentBarGroup::addColor( QColor color ) |
|
39 | int PercentBarGroup::addColor( QColor color ) | |
40 | { |
|
40 | { | |
41 | int colorIndex = mColors.count(); |
|
41 | int colorIndex = mColors.count(); | |
42 | mColors.append(color); |
|
42 | mColors.append(color); | |
43 | return colorIndex; |
|
43 | return colorIndex; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void PercentBarGroup::resetColors() |
|
46 | void PercentBarGroup::resetColors() | |
47 | { |
|
47 | { | |
48 | mColors.clear(); |
|
48 | mColors.clear(); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
51 | void PercentBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
52 | { |
|
52 | { | |
53 | if (!mLayoutSet) { |
|
53 | if (!mLayoutSet) { | |
54 | qDebug() << "QBarChart::paint called without layout set. Aborting."; |
|
54 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
55 | return; |
|
55 | return; | |
56 | } |
|
56 | } | |
57 | if (mLayoutDirty) { |
|
57 | if (mLayoutDirty) { | |
58 | // Layout or data has changed. Need to redraw. |
|
58 | // Layout or data has changed. Need to redraw. | |
59 | foreach(QGraphicsItem* i, childItems()) { |
|
59 | foreach(QGraphicsItem* i, childItems()) { | |
60 | i->paint(painter,option,widget); |
|
60 | i->paint(painter,option,widget); | |
61 | } |
|
61 | } | |
62 | mLayoutDirty = false; |
|
62 | mLayoutDirty = false; | |
63 | } |
|
63 | } | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QRectF PercentBarGroup::boundingRect() const |
|
66 | QRectF PercentBarGroup::boundingRect() const | |
67 | { |
|
67 | { | |
68 | return QRectF(0,0,mWidth,mHeight); |
|
68 | return QRectF(0,0,mWidth,mHeight); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | void PercentBarGroup::dataChanged() |
|
72 | void PercentBarGroup::dataChanged() | |
73 | { |
|
73 | { | |
74 | qDebug() << "QBarChart::dataChanged mSeries"; |
|
74 | qDebug() << "QBarChart::dataChanged mSeries"; | |
75 |
|
75 | |||
76 | // Find out maximum and minimum of all series |
|
76 | // Find out maximum and minimum of all series | |
77 | mMax = mSeries.max(); |
|
77 | mMax = mSeries.max(); | |
78 | mMin = mSeries.min(); |
|
78 | mMin = mSeries.min(); | |
79 |
|
79 | |||
80 | // Delete old bars |
|
80 | // Delete old bars | |
81 | // Is this correct way to delete childItems? |
|
81 | // Is this correct way to delete childItems? | |
82 | foreach (QGraphicsItem* item, childItems()) { |
|
82 | foreach (QGraphicsItem* item, childItems()) { | |
83 | delete item; |
|
83 | delete item; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | // Create new graphic items for bars |
|
86 | // Create new graphic items for bars | |
87 | int totalItems = mSeries.countTotalItems(); |
|
87 | int totalItems = mSeries.countTotalItems(); | |
88 | for (int i=0; i<totalItems; i++) { |
|
88 | for (int i=0; i<totalItems; i++) { | |
89 | Bar *bar = new Bar(this); |
|
89 | Bar *bar = new Bar(this); | |
90 | childItems().append(bar); |
|
90 | childItems().append(bar); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | // TODO: labels from series. This creates just some example labels |
|
93 | // TODO: labels from series. This creates just some example labels | |
94 | int count = mSeries.countColumns(); |
|
94 | int count = mSeries.countColumns(); | |
95 | for (int i=0; i<count; i++) { |
|
95 | for (int i=0; i<count; i++) { | |
96 | BarLabel* label = new BarLabel(this); |
|
96 | BarLabel* label = new BarLabel(this); | |
97 | QString text("Label " + QString::number(i)); |
|
97 | QString text("Label " + QString::number(i)); | |
98 | label->set(text); |
|
98 | label->set(text); | |
99 | childItems().append(label); |
|
99 | childItems().append(label); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | // TODO: if (autolayout) { layoutChanged() } or something |
|
102 | // TODO: if (autolayout) { layoutChanged() } or something | |
103 | mLayoutDirty = true; |
|
103 | mLayoutDirty = true; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void PercentBarGroup::layoutChanged() |
|
106 | void PercentBarGroup::layoutChanged() | |
107 | { |
|
107 | { | |
108 | // Scale bars to new layout |
|
108 | // Scale bars to new layout | |
109 | // Layout for bars: |
|
109 | // Layout for bars: | |
110 | if (mSeries.countRows() <= 0) { |
|
110 | if (mSeries.countRows() <= 0) { | |
111 | // Nothing to do. |
|
111 | // Nothing to do. | |
112 | return; |
|
112 | return; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | // TODO: better way to auto-layout |
|
115 | // TODO: better way to auto-layout | |
116 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
116 | // Use reals for accurancy (we might get some compiler warnings... :) | |
117 | int count = mSeries.countColumns(); |
|
117 | int count = mSeries.countColumns(); | |
118 | int itemIndex(0); |
|
118 | int itemIndex(0); | |
119 | qreal tW = mWidth; |
|
119 | qreal tW = mWidth; | |
120 | qreal tC = count+1; |
|
120 | qreal tC = count+1; | |
121 | qreal xStep = (tW/tC); |
|
121 | qreal xStep = (tW/tC); | |
122 | // qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); |
|
122 | // qreal xPos = ((tW/tC) + mBarDefaultWidth / 2); | |
123 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
123 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
124 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); |
|
124 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); | |
125 |
|
125 | |||
126 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
126 | for (int column = 0; column < mSeries.countColumns(); column++) { | |
127 | qreal colSum = mSeries.columnSum(column); |
|
127 | qreal colSum = mSeries.columnSum(column); | |
128 | qreal h = mHeight; |
|
128 | qreal h = mHeight; | |
129 | qreal scale = (h / colSum); |
|
129 | qreal scale = (h / colSum); | |
130 | qreal yPos = h; |
|
130 | qreal yPos = h; | |
131 | for (int row=0; row < mSeries.countRows(); row++) { |
|
131 | for (int row=0; row < mSeries.countRows(); row++) { | |
132 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
132 | qreal barHeight = mSeries.valueAt(row, column) * scale; | |
133 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
133 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
134 |
|
134 | |||
135 | // TODO: width settable per bar? |
|
135 | // TODO: width settable per bar? | |
136 | bar->resize(mBarDefaultWidth, barHeight); |
|
136 | bar->resize(mBarDefaultWidth, barHeight); | |
137 | bar->setColor(mColors.at(row)); |
|
137 | bar->setColor(mColors.at(row)); | |
138 | bar->setPos(xPos, yPos-barHeight); |
|
138 | bar->setPos(xPos, yPos-barHeight); | |
139 | itemIndex++; |
|
139 | itemIndex++; | |
140 | yPos -= barHeight; |
|
140 | yPos -= barHeight; | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | // TODO: Layout for labels, remove magic number |
|
143 | // TODO: Layout for labels, remove magic number | |
144 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
144 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
145 | label->setPos(xPos, mHeight + 20); |
|
145 | label->setPos(xPos, mHeight + 20); | |
146 | labelIndex++; |
|
146 | labelIndex++; | |
147 | xPos += xStep; |
|
147 | xPos += xStep; | |
148 | } |
|
148 | } | |
149 | mLayoutDirty = true; |
|
149 | mLayoutDirty = true; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | QTCOMMERCIALCHART_END_NAMESPACE |
|
152 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,108 +1,109 | |||||
1 | #include <limits.h> |
|
1 | #include <limits.h> | |
2 | #include <QDebug> |
|
2 | #include <QDebug> | |
3 | #include "stackedbarchartseries.h" |
|
3 | #include "stackedbarchartseries.h" | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | StackedBarChartSeries::StackedBarChartSeries(QObject *parent) : |
|
7 | StackedBarChartSeries::StackedBarChartSeries(QObject *parent) : | |
8 | QChartSeries(parent) |
|
8 | QChartSeries(parent) | |
9 | { |
|
9 | { | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
12 | bool StackedBarChartSeries::setData(QAbstractItemModel* model) |
|
12 | bool StackedBarChartSeries::setData(QAbstractItemModel* model) | |
13 | { |
|
13 | { | |
14 | mModel = model; |
|
14 | mModel = model; | |
|
15 | return true; | |||
15 | } |
|
16 | } | |
16 |
|
17 | |||
17 | int StackedBarChartSeries::min() |
|
18 | int StackedBarChartSeries::min() | |
18 | { |
|
19 | { | |
19 | Q_ASSERT(mModel->rowCount() > 0); |
|
20 | Q_ASSERT(mModel->rowCount() > 0); | |
20 | Q_ASSERT(mModel->columnCount() > 0); |
|
21 | Q_ASSERT(mModel->columnCount() > 0); | |
21 |
|
22 | |||
22 | // TODO: make min and max members and update them when data changes. |
|
23 | // 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 | // This is slower since they are checked every time, even if data is same since previous call. | |
24 | int min = INT_MAX; |
|
25 | int min = INT_MAX; | |
25 |
|
26 | |||
26 | for (int i=0; i <mModel->rowCount(); i++) { |
|
27 | for (int i=0; i <mModel->rowCount(); i++) { | |
27 | for(int j=0; j<mModel->columnCount(); j++) { |
|
28 | for(int j=0; j<mModel->columnCount(); j++) { | |
28 | int temp = mModel->data(mModel->index(i,j)).toInt(); |
|
29 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
29 | if (temp < min) { |
|
30 | if (temp < min) { | |
30 | min = temp; |
|
31 | min = temp; | |
31 | } |
|
32 | } | |
32 | } |
|
33 | } | |
33 | } |
|
34 | } | |
34 | return min; |
|
35 | return min; | |
35 | } |
|
36 | } | |
36 |
|
37 | |||
37 | int StackedBarChartSeries::max() |
|
38 | int StackedBarChartSeries::max() | |
38 | { |
|
39 | { | |
39 | Q_ASSERT(mModel->rowCount() > 0); |
|
40 | Q_ASSERT(mModel->rowCount() > 0); | |
40 | Q_ASSERT(mModel->columnCount() > 0); |
|
41 | Q_ASSERT(mModel->columnCount() > 0); | |
41 |
|
42 | |||
42 | // TODO: make min and max members and update them when data changes. |
|
43 | // 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 | // This is slower since they are checked every time, even if data is same since previous call. | |
44 | int max = INT_MIN; |
|
45 | int max = INT_MIN; | |
45 |
|
46 | |||
46 | for (int i=0; i <mModel->rowCount(); i++) { |
|
47 | for (int i=0; i <mModel->rowCount(); i++) { | |
47 | for(int j=0; j<mModel->columnCount(); j++) { |
|
48 | for(int j=0; j<mModel->columnCount(); j++) { | |
48 | int temp = mModel->data(mModel->index(i,j)).toInt(); |
|
49 | int temp = mModel->data(mModel->index(i,j)).toInt(); | |
49 | if (temp > max) { |
|
50 | if (temp > max) { | |
50 | max = temp; |
|
51 | max = temp; | |
51 | } |
|
52 | } | |
52 | } |
|
53 | } | |
53 | } |
|
54 | } | |
54 | return max; |
|
55 | return max; | |
55 | } |
|
56 | } | |
56 |
|
57 | |||
57 | int StackedBarChartSeries::maxColumnSum() |
|
58 | int StackedBarChartSeries::maxColumnSum() | |
58 | { |
|
59 | { | |
59 | Q_ASSERT(mModel->rowCount() > 0); |
|
60 | Q_ASSERT(mModel->rowCount() > 0); | |
60 | Q_ASSERT(mModel->columnCount() > 0); |
|
61 | Q_ASSERT(mModel->columnCount() > 0); | |
61 |
|
62 | |||
62 | int max = INT_MIN; |
|
63 | int max = INT_MIN; | |
63 |
|
64 | |||
64 | for (int col=0; col <mModel->columnCount(); col++) { |
|
65 | for (int col=0; col <mModel->columnCount(); col++) { | |
65 | int sum = columnSum(col); |
|
66 | int sum = columnSum(col); | |
66 | if (sum > max) { |
|
67 | if (sum > max) { | |
67 | max = sum; |
|
68 | max = sum; | |
68 | } |
|
69 | } | |
69 | } |
|
70 | } | |
70 | return max; |
|
71 | return max; | |
71 | } |
|
72 | } | |
72 |
|
73 | |||
73 | int StackedBarChartSeries::countRows() |
|
74 | int StackedBarChartSeries::countRows() | |
74 | { |
|
75 | { | |
75 | return mModel->rowCount(); |
|
76 | return mModel->rowCount(); | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | int StackedBarChartSeries::countColumns() |
|
79 | int StackedBarChartSeries::countColumns() | |
79 | { |
|
80 | { | |
80 | return mModel->columnCount(); |
|
81 | return mModel->columnCount(); | |
81 | } |
|
82 | } | |
82 |
|
83 | |||
83 | int StackedBarChartSeries::countTotalItems() |
|
84 | int StackedBarChartSeries::countTotalItems() | |
84 | { |
|
85 | { | |
85 | return mModel->rowCount() * mModel->columnCount(); |
|
86 | return mModel->rowCount() * mModel->columnCount(); | |
86 | } |
|
87 | } | |
87 |
|
88 | |||
88 | int StackedBarChartSeries::valueAt(int row, int column) |
|
89 | int StackedBarChartSeries::valueAt(int row, int column) | |
89 | { |
|
90 | { | |
90 | QModelIndex index = mModel->index(row,column); |
|
91 | QModelIndex index = mModel->index(row,column); | |
91 | return mModel->data(index).toInt(); |
|
92 | return mModel->data(index).toInt(); | |
92 | } |
|
93 | } | |
93 |
|
94 | |||
94 | int StackedBarChartSeries::columnSum(int column) |
|
95 | int StackedBarChartSeries::columnSum(int column) | |
95 | { |
|
96 | { | |
96 | int sum(0); |
|
97 | int sum(0); | |
97 | int count = mModel->rowCount(); |
|
98 | int count = mModel->rowCount(); | |
98 |
|
99 | |||
99 | for (int row = 0; row < count; row++) { |
|
100 | for (int row = 0; row < count; row++) { | |
100 | sum += mModel->data(mModel->index(row,column)).toInt(); |
|
101 | sum += mModel->data(mModel->index(row,column)).toInt(); | |
101 | } |
|
102 | } | |
102 | return sum; |
|
103 | return sum; | |
103 | } |
|
104 | } | |
104 |
|
105 | |||
105 | #include "moc_stackedbarchartseries.cpp" |
|
106 | #include "moc_stackedbarchartseries.cpp" | |
106 |
|
107 | |||
107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
108 | QTCOMMERCIALCHART_END_NAMESPACE | |
108 |
|
109 |
@@ -1,192 +1,192 | |||||
1 | #include "stackedbargroup.h" |
|
1 | #include "stackedbargroup.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barlabel_p.h" |
|
3 | #include "barlabel_p.h" | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 | #include <QPainter> |
|
5 | #include <QPainter> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : |
|
9 | StackedBarGroup::StackedBarGroup(StackedBarChartSeries& series, QGraphicsItem *parent) : | |
10 | ChartItem(parent) |
|
10 | ChartItem(parent) | |
11 | ,mSeries(series) |
|
11 | ,mSeries(series) | |
|
12 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready | |||
12 | ,mLayoutSet(false) |
|
13 | ,mLayoutSet(false) | |
13 | ,mLayoutDirty(true) |
|
14 | ,mLayoutDirty(true) | |
14 | ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready |
|
|||
15 | ,mTheme(0) |
|
15 | ,mTheme(0) | |
16 | ,mSeparatorsVisible(true) |
|
16 | ,mSeparatorsVisible(true) | |
17 | { |
|
17 | { | |
18 | dataChanged(); |
|
18 | dataChanged(); | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | void StackedBarGroup::setSeparatorsVisible(bool visible) |
|
21 | void StackedBarGroup::setSeparatorsVisible(bool visible) | |
22 | { |
|
22 | { | |
23 | mSeparatorsVisible = visible; |
|
23 | mSeparatorsVisible = visible; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | void StackedBarGroup::setSize(const QSizeF& size) |
|
26 | void StackedBarGroup::setSize(const QSizeF& size) | |
27 | { |
|
27 | { | |
28 | mWidth = size.width(); |
|
28 | mWidth = size.width(); | |
29 | mHeight = size.height(); |
|
29 | mHeight = size.height(); | |
30 | layoutChanged(); |
|
30 | layoutChanged(); | |
31 | mLayoutSet = true; |
|
31 | mLayoutSet = true; | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | void StackedBarGroup::setPlotDomain(const PlotDomain& data) |
|
34 | void StackedBarGroup::setPlotDomain(const PlotDomain& data) | |
35 | { |
|
35 | { | |
36 | qDebug() << "StackedBarGroup::setPlotDomain"; |
|
36 | qDebug() << "StackedBarGroup::setPlotDomain"; | |
37 | // TODO: |
|
37 | // TODO: | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void StackedBarGroup::themeChanged(ChartTheme *theme) |
|
40 | void StackedBarGroup::themeChanged(ChartTheme *theme) | |
41 | { |
|
41 | { | |
42 | mTheme = theme; |
|
42 | mTheme = theme; | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | void StackedBarGroup::setBarWidth( int w ) |
|
45 | void StackedBarGroup::setBarWidth( int w ) | |
46 | { |
|
46 | { | |
47 | mBarDefaultWidth = w; |
|
47 | mBarDefaultWidth = w; | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | int StackedBarGroup::addColor( QColor color ) |
|
50 | int StackedBarGroup::addColor( QColor color ) | |
51 | { |
|
51 | { | |
52 | int colorIndex = mColors.count(); |
|
52 | int colorIndex = mColors.count(); | |
53 | mColors.append(color); |
|
53 | mColors.append(color); | |
54 | return colorIndex; |
|
54 | return colorIndex; | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void StackedBarGroup::resetColors() |
|
57 | void StackedBarGroup::resetColors() | |
58 | { |
|
58 | { | |
59 | mColors.clear(); |
|
59 | mColors.clear(); | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
62 | void StackedBarGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
63 | { |
|
63 | { | |
64 | if (!mLayoutSet) { |
|
64 | if (!mLayoutSet) { | |
65 | qDebug() << "QBarChart::paint called without layout set. Aborting."; |
|
65 | qDebug() << "QBarChart::paint called without layout set. Aborting."; | |
66 | return; |
|
66 | return; | |
67 | } |
|
67 | } | |
68 | if (mLayoutDirty) { |
|
68 | if (mLayoutDirty) { | |
69 | // Layout or data has changed. Need to redraw. |
|
69 | // Layout or data has changed. Need to redraw. | |
70 | foreach(QGraphicsItem* i, childItems()) { |
|
70 | foreach(QGraphicsItem* i, childItems()) { | |
71 | i->paint(painter,option,widget); |
|
71 | i->paint(painter,option,widget); | |
72 | } |
|
72 | } | |
73 | if (mSeparatorsVisible) { |
|
73 | if (mSeparatorsVisible) { | |
74 | //TODO: own class for separators (graphicsitem), because they may have style etc later. |
|
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. |
|
75 | // this is just to see that the positions are calculated correctly. | |
76 | QPen pen(QColor(0,0,255,255)); |
|
76 | QPen pen(QColor(0,0,255,255)); | |
77 | painter->setPen(pen); |
|
77 | painter->setPen(pen); | |
78 | for (int i=0; i<mSeparatorPositions.count(); i++ ) { |
|
78 | for (int i=0; i<mSeparatorPositions.count(); i++ ) { | |
79 | qreal xp = mSeparatorPositions.at(i); |
|
79 | qreal xp = mSeparatorPositions.at(i); | |
80 | painter->drawLine(xp,0,xp,mHeight); |
|
80 | painter->drawLine(xp,0,xp,mHeight); | |
81 | } |
|
81 | } | |
82 | } |
|
82 | } | |
83 | // mLayoutDirty = false; |
|
83 | // mLayoutDirty = false; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | QRectF StackedBarGroup::boundingRect() const |
|
88 | QRectF StackedBarGroup::boundingRect() const | |
89 | { |
|
89 | { | |
90 | return QRectF(0,0,mWidth,mHeight); |
|
90 | return QRectF(0,0,mWidth,mHeight); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 |
|
93 | |||
94 | void StackedBarGroup::dataChanged() |
|
94 | void StackedBarGroup::dataChanged() | |
95 | { |
|
95 | { | |
96 | qDebug() << "QBarChart::dataChanged"; |
|
96 | qDebug() << "QBarChart::dataChanged"; | |
97 |
|
97 | |||
98 | // Find out maximum and minimum of all series |
|
98 | // Find out maximum and minimum of all series | |
99 | mMax = mSeries.max(); |
|
99 | mMax = mSeries.max(); | |
100 | mMin = mSeries.min(); |
|
100 | mMin = mSeries.min(); | |
101 |
|
101 | |||
102 | // Delete old bars |
|
102 | // Delete old bars | |
103 | // Is this correct way to delete childItems? |
|
103 | // Is this correct way to delete childItems? | |
104 | foreach (QGraphicsItem* item, childItems()) { |
|
104 | foreach (QGraphicsItem* item, childItems()) { | |
105 | delete item; |
|
105 | delete item; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | // Create new graphic items for bars |
|
108 | // Create new graphic items for bars | |
109 | int totalItems = mSeries.countTotalItems(); |
|
109 | int totalItems = mSeries.countTotalItems(); | |
110 | for (int i=0; i<totalItems; i++) { |
|
110 | for (int i=0; i<totalItems; i++) { | |
111 | Bar *bar = new Bar(this); |
|
111 | Bar *bar = new Bar(this); | |
112 | childItems().append(bar); |
|
112 | childItems().append(bar); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | // TODO: labels from series. This creates just some example labels |
|
115 | // TODO: labels from series. This creates just some example labels | |
116 | int count = mSeries.countColumns(); |
|
116 | int count = mSeries.countColumns(); | |
117 | for (int i=0; i<count; i++) { |
|
117 | for (int i=0; i<count; i++) { | |
118 | BarLabel* label = new BarLabel(this); |
|
118 | BarLabel* label = new BarLabel(this); | |
119 | QString text("Label " + QString::number(i)); |
|
119 | QString text("Label " + QString::number(i)); | |
120 | label->set(text); |
|
120 | label->set(text); | |
121 | childItems().append(label); |
|
121 | childItems().append(label); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | mSeparatorPositions.clear(); |
|
124 | mSeparatorPositions.clear(); | |
125 |
|
125 | |||
126 | // TODO: if (autolayout) { layoutChanged() } or something |
|
126 | // TODO: if (autolayout) { layoutChanged() } or something | |
127 | mLayoutDirty = true; |
|
127 | mLayoutDirty = true; | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void StackedBarGroup::layoutChanged() |
|
130 | void StackedBarGroup::layoutChanged() | |
131 | { |
|
131 | { | |
132 | // Scale bars to new layout |
|
132 | // Scale bars to new layout | |
133 | // Layout for bars: |
|
133 | // Layout for bars: | |
134 | if (mSeries.countRows() <= 0) { |
|
134 | if (mSeries.countRows() <= 0) { | |
135 | // Nothing to do. |
|
135 | // Nothing to do. | |
136 | return; |
|
136 | return; | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | if (mSeries.countColumns() == 0) { |
|
139 | if (mSeries.countColumns() == 0) { | |
140 | // Nothing to do |
|
140 | // Nothing to do | |
141 | return; |
|
141 | return; | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | // TODO: better way to auto-layout |
|
144 | // TODO: better way to auto-layout | |
145 | // Use reals for accurancy (we might get some compiler warnings... :) |
|
145 | // Use reals for accurancy (we might get some compiler warnings... :) | |
146 | // TODO: use temp variable for column count... |
|
146 | // TODO: use temp variable for column count... | |
147 | qreal maxSum = mSeries.maxColumnSum(); |
|
147 | qreal maxSum = mSeries.maxColumnSum(); | |
148 | qreal h = mHeight; |
|
148 | qreal h = mHeight; | |
149 | qreal scale = (h / maxSum); |
|
149 | qreal scale = (h / maxSum); | |
150 |
|
150 | |||
151 | int itemIndex(0); |
|
151 | int itemIndex(0); | |
152 | qreal tW = mWidth; |
|
152 | qreal tW = mWidth; | |
153 | qreal tC = mSeries.countColumns() + 1; |
|
153 | qreal tC = mSeries.countColumns() + 1; | |
154 | qreal xStep = (tW/tC); |
|
154 | qreal xStep = (tW/tC); | |
155 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); |
|
155 | qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); | |
156 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); |
|
156 | int labelIndex = mSeries.countColumns() * mSeries.countRows(); | |
157 |
|
157 | |||
158 | for (int column = 0; column < mSeries.countColumns(); column++) { |
|
158 | for (int column = 0; column < mSeries.countColumns(); column++) { | |
159 | qreal yPos = h; |
|
159 | qreal yPos = h; | |
160 | for (int row=0; row < mSeries.countRows(); row++) { |
|
160 | for (int row=0; row < mSeries.countRows(); row++) { | |
161 | qreal barHeight = mSeries.valueAt(row, column) * scale; |
|
161 | qreal barHeight = mSeries.valueAt(row, column) * scale; | |
162 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); |
|
162 | Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex)); | |
163 |
|
163 | |||
164 | // TODO: width settable per bar? |
|
164 | // TODO: width settable per bar? | |
165 | // TODO: how to get color for series(x) from theme? |
|
165 | // TODO: how to get color for series(x) from theme? | |
166 | // mTheme->themeForSeries(); |
|
166 | // mTheme->themeForSeries(); | |
167 | bar->resize(mBarDefaultWidth, barHeight); |
|
167 | bar->resize(mBarDefaultWidth, barHeight); | |
168 | bar->setColor(mColors.at(row)); |
|
168 | bar->setColor(mColors.at(row)); | |
169 | bar->setPos(xPos, yPos-barHeight); |
|
169 | bar->setPos(xPos, yPos-barHeight); | |
170 | itemIndex++; |
|
170 | itemIndex++; | |
171 | yPos -= barHeight; |
|
171 | yPos -= barHeight; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | // TODO: Layout for labels, remove magic number |
|
174 | // TODO: Layout for labels, remove magic number | |
175 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); |
|
175 | BarLabel* label = reinterpret_cast<BarLabel*> (childItems().at(labelIndex)); | |
176 | label->setPos(xPos, mHeight + 20); |
|
176 | label->setPos(xPos, mHeight + 20); | |
177 | labelIndex++; |
|
177 | labelIndex++; | |
178 | xPos += xStep; |
|
178 | xPos += xStep; | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | // Position separators |
|
181 | // Position separators | |
182 | mSeparatorPositions.clear(); |
|
182 | mSeparatorPositions.clear(); | |
183 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. |
|
183 | xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. | |
184 | for (int s=0; s < mSeries.countColumns() - 1; s++) { |
|
184 | for (int s=0; s < mSeries.countColumns() - 1; s++) { | |
185 | mSeparatorPositions.append(xPos); |
|
185 | mSeparatorPositions.append(xPos); | |
186 | xPos += xStep; |
|
186 | xPos += xStep; | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | mLayoutDirty = true; |
|
189 | mLayoutDirty = true; | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | QTCOMMERCIALCHART_END_NAMESPACE |
|
192 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,140 +1,140 | |||||
1 | #include "qscatterseries.h" |
|
1 | #include "qscatterseries.h" | |
2 | #include "qscatterseries_p.h" |
|
2 | #include "qscatterseries_p.h" | |
3 | #include "qchart.h" |
|
3 | #include "qchart.h" | |
4 | #include <QPainter> |
|
4 | #include <QPainter> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | //#define QSeriesData QList<qreal> |
|
10 | //#define QSeriesData QList<qreal> | |
11 |
|
11 | |||
12 | QScatterSeriesPrivate::QScatterSeriesPrivate(QGraphicsItem *parent) : |
|
12 | QScatterSeriesPrivate::QScatterSeriesPrivate(QGraphicsItem *parent) : | |
13 | ChartItem(parent), |
|
13 | ChartItem(parent), | |
|
14 | m_boundingRect(), | |||
14 | m_markerColor(QColor()), |
|
15 | m_markerColor(QColor()), | |
15 |
m_visibleChartArea() |
|
16 | m_visibleChartArea() | |
16 | m_boundingRect() |
|
|||
17 | { |
|
17 | { | |
18 | if (parent) |
|
18 | if (parent) | |
19 | m_boundingRect = parent->boundingRect(); |
|
19 | m_boundingRect = parent->boundingRect(); | |
20 | } |
|
20 | } | |
21 |
|
21 | |||
22 | void QScatterSeriesPrivate::changeGeometry() |
|
22 | void QScatterSeriesPrivate::changeGeometry() | |
23 | { |
|
23 | { | |
24 | if (m_boundingRect.isValid()) { |
|
24 | if (m_boundingRect.isValid()) { | |
25 | prepareGeometryChange(); |
|
25 | prepareGeometryChange(); | |
26 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); |
|
26 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); | |
27 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); |
|
27 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); | |
28 | m_scenex.clear(); |
|
28 | m_scenex.clear(); | |
29 | m_sceney.clear(); |
|
29 | m_sceney.clear(); | |
30 |
|
30 | |||
31 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing |
|
31 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing | |
32 | foreach(qreal x, m_x) |
|
32 | foreach(qreal x, m_x) | |
33 | m_scenex.append(m_boundingRect.left() + x * scalex - m_visibleChartArea.m_minX * scalex); |
|
33 | m_scenex.append(m_boundingRect.left() + x * scalex - m_visibleChartArea.m_minX * scalex); | |
34 |
|
34 | |||
35 | foreach(qreal y, m_y) |
|
35 | foreach(qreal y, m_y) | |
36 | m_sceney.append(m_boundingRect.bottom() - y * scaley + m_visibleChartArea.m_minY * scaley); |
|
36 | m_sceney.append(m_boundingRect.bottom() - y * scaley + m_visibleChartArea.m_minY * scaley); | |
37 | } |
|
37 | } | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void QScatterSeriesPrivate::setSize(const QSizeF &size) |
|
40 | void QScatterSeriesPrivate::setSize(const QSizeF &size) | |
41 | { |
|
41 | { | |
42 | // m_boundingRect = QRectF(pos().x(), pos().y(), size.width(), size.height()); |
|
42 | // m_boundingRect = QRectF(pos().x(), pos().y(), size.width(), size.height()); | |
43 | m_boundingRect = QRectF(0, 0, size.width(), size.height()); |
|
43 | m_boundingRect = QRectF(0, 0, size.width(), size.height()); | |
44 | changeGeometry(); |
|
44 | changeGeometry(); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void QScatterSeriesPrivate::themeChanged(ChartTheme *theme) |
|
47 | void QScatterSeriesPrivate::themeChanged(ChartTheme *theme) | |
48 | { |
|
48 | { | |
49 | m_theme = theme->themeForSeries(); |
|
49 | m_theme = theme->themeForSeries(); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void QScatterSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain) |
|
52 | void QScatterSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain) | |
53 | { |
|
53 | { | |
54 | m_visibleChartArea = plotDomain; |
|
54 | m_visibleChartArea = plotDomain; | |
55 | changeGeometry(); |
|
55 | changeGeometry(); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | QRectF QScatterSeriesPrivate::boundingRect() const |
|
58 | QRectF QScatterSeriesPrivate::boundingRect() const | |
59 | { |
|
59 | { | |
60 | return m_boundingRect; |
|
60 | return m_boundingRect; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) |
|
63 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) | |
64 | { |
|
64 | { | |
65 | // TODO: The opacity should be user definable? |
|
65 | // TODO: The opacity should be user definable? | |
66 | //brush.setColor(QColor(255, 82, 0, 100)); |
|
66 | //brush.setColor(QColor(255, 82, 0, 100)); | |
67 | if (m_markerColor.isValid()) { |
|
67 | if (m_markerColor.isValid()) { | |
68 | QPen pen = painter->pen(); |
|
68 | QPen pen = painter->pen(); | |
69 | QBrush brush = pen.brush(); |
|
69 | QBrush brush = pen.brush(); | |
70 | brush.setColor(m_markerColor); |
|
70 | brush.setColor(m_markerColor); | |
71 | pen.setBrush(brush); |
|
71 | pen.setBrush(brush); | |
72 | pen.setWidth(4); |
|
72 | pen.setWidth(4); | |
73 | painter->setPen(pen); |
|
73 | painter->setPen(pen); | |
74 | } |
|
74 | } | |
75 | else |
|
75 | else | |
76 | painter->setPen(m_theme.markerPen); |
|
76 | painter->setPen(m_theme.markerPen); | |
77 | // brush.setColor(m_theme..lineColor); |
|
77 | // brush.setColor(m_theme..lineColor); | |
78 |
|
78 | |||
79 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize |
|
79 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize | |
80 | // event right after construction or maybe given a size during initialization |
|
80 | // event right after construction or maybe given a size during initialization | |
81 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { |
|
81 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { | |
82 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) |
|
82 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) | |
83 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); |
|
83 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); | |
84 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); |
|
84 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); | |
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | QScatterSeries::QScatterSeries(QObject *parent) : |
|
88 | QScatterSeries::QScatterSeries(QObject *parent) : | |
89 | QChartSeries(parent), |
|
89 | QChartSeries(parent), | |
90 | d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent))) |
|
90 | d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent))) | |
91 | { |
|
91 | { | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | bool QScatterSeries::setData(QList<qreal> xlist, QList<qreal> ylist) |
|
94 | bool QScatterSeries::setData(QList<qreal> xlist, QList<qreal> ylist) | |
95 | { |
|
95 | { | |
96 | // TODO: validate data |
|
96 | // TODO: validate data | |
97 | d->m_x = xlist; |
|
97 | d->m_x = xlist; | |
98 | d->m_y = ylist; |
|
98 | d->m_y = ylist; | |
99 |
|
99 | |||
100 | // TODO: the following updates the visible chart area setting of the series, we would instead |
|
100 | // TODO: the following updates the visible chart area setting of the series, we would instead | |
101 | // need to update the _chart's_ visible area... this would require a callback or |
|
101 | // need to update the _chart's_ visible area... this would require a callback or | |
102 | // similar to the parenting QChart object... |
|
102 | // similar to the parenting QChart object... | |
103 | foreach (qreal x, d->m_x) { |
|
103 | foreach (qreal x, d->m_x) { | |
104 | d->m_visibleChartArea.m_minX = qMin(d->m_visibleChartArea.m_minX, x); |
|
104 | d->m_visibleChartArea.m_minX = qMin(d->m_visibleChartArea.m_minX, x); | |
105 | d->m_visibleChartArea.m_maxX = qMax(d->m_visibleChartArea.m_maxX, x); |
|
105 | d->m_visibleChartArea.m_maxX = qMax(d->m_visibleChartArea.m_maxX, x); | |
106 | } |
|
106 | } | |
107 | foreach (qreal y, d->m_y) { |
|
107 | foreach (qreal y, d->m_y) { | |
108 | d->m_visibleChartArea.m_minY = qMin(d->m_visibleChartArea.m_minY, y); |
|
108 | d->m_visibleChartArea.m_minY = qMin(d->m_visibleChartArea.m_minY, y); | |
109 | d->m_visibleChartArea.m_maxY = qMax(d->m_visibleChartArea.m_maxY, y); |
|
109 | d->m_visibleChartArea.m_maxY = qMax(d->m_visibleChartArea.m_maxY, y); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | d->changeGeometry(); |
|
112 | d->changeGeometry(); | |
113 |
|
113 | |||
114 | return true; |
|
114 | return true; | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void QScatterSeries::setMarkerColor(QColor color) |
|
117 | void QScatterSeries::setMarkerColor(QColor color) | |
118 | { |
|
118 | { | |
119 | d->m_markerColor = color; |
|
119 | d->m_markerColor = color; | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | QColor QScatterSeries::markerColor() |
|
122 | QColor QScatterSeries::markerColor() | |
123 | { |
|
123 | { | |
124 | return d->m_markerColor; |
|
124 | return d->m_markerColor; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | // TODO: |
|
127 | // TODO: | |
128 | //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) |
|
128 | //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) | |
129 | //{ |
|
129 | //{ | |
130 | // d->rescale(xscale, yscale); |
|
130 | // d->rescale(xscale, yscale); | |
131 | //} |
|
131 | //} | |
132 |
|
132 | |||
133 | QScatterSeries::~QScatterSeries() |
|
133 | QScatterSeries::~QScatterSeries() | |
134 | { |
|
134 | { | |
135 | delete d; |
|
135 | delete d; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | #include "moc_qscatterseries.cpp" |
|
138 | #include "moc_qscatterseries.cpp" | |
139 |
|
139 | |||
140 | QTCOMMERCIALCHART_END_NAMESPACE |
|
140 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,16 +1,15 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QDeclarativeEngine> |
|
2 | #include <QDeclarativeEngine> | |
3 | #include "qmlapplicationviewer.h" |
|
3 | #include "qmlapplicationviewer.h" | |
4 | #include "chart.h" |
|
|||
5 |
|
4 | |||
6 | Q_DECL_EXPORT int main(int argc, char *argv[]) |
|
5 | Q_DECL_EXPORT int main(int argc, char *argv[]) | |
7 | { |
|
6 | { | |
8 | QScopedPointer<QApplication> app(createApplication(argc, argv)); |
|
7 | QScopedPointer<QApplication> app(createApplication(argc, argv)); | |
9 | QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create()); |
|
8 | QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create()); | |
10 |
|
9 | |||
11 | viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); |
|
10 | viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); | |
12 | viewer->setMainQmlFile(QLatin1String("qml/qmlchart/main.qml")); |
|
11 | viewer->setMainQmlFile(QLatin1String("qml/qmlchart/main.qml")); | |
13 | viewer->showExpanded(); |
|
12 | viewer->showExpanded(); | |
14 |
|
13 | |||
15 | return app->exec(); |
|
14 | return app->exec(); | |
16 | } |
|
15 | } |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now