@@ -138,9 +138,9 int main(int argc, char *argv[]) | |||
|
138 | 138 | //! [6] |
|
139 | 139 | |
|
140 | 140 | // Disable axis, since they don't really apply to bar chart |
|
141 | drilldownChart->axisX()->setAxisVisible(false); | |
|
141 | // drilldownChart->axisX()->setAxisVisible(false); | |
|
142 | 142 | drilldownChart->axisX()->setGridVisible(false); |
|
143 | drilldownChart->axisX()->setLabelsVisible(false); | |
|
143 | // drilldownChart->axisX()->setLabelsVisible(false); | |
|
144 | 144 | |
|
145 | 145 | window.setCentralWidget(drilldownChart); |
|
146 | 146 | window.resize(400, 300); |
@@ -7,10 +7,9 | |||
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 |
BarPresenter::BarPresenter(QBarSeries *series, Q |
|
|
10 | BarPresenter::BarPresenter(QBarSeries *series, QChart *parent) : | |
|
11 | 11 | BarPresenterBase(series, parent) |
|
12 | 12 | { |
|
13 | mBarWidth = 5; | |
|
14 | 13 | } |
|
15 | 14 | |
|
16 | 15 | void BarPresenter::layoutChanged() |
@@ -14,7 +14,7 class BarPresenter : public BarPresenterBase | |||
|
14 | 14 | { |
|
15 | 15 | Q_OBJECT |
|
16 | 16 | public: |
|
17 |
explicit BarPresenter(QBarSeries *series, Q |
|
|
17 | explicit BarPresenter(QBarSeries *series, QChart *parent = 0); | |
|
18 | 18 | |
|
19 | 19 | private: |
|
20 | 20 |
@@ -5,19 +5,23 | |||
|
5 | 5 | #include "separator_p.h" |
|
6 | 6 | #include "qbarset.h" |
|
7 | 7 | #include "qbarseries.h" |
|
8 | #include "qchart.h" | |
|
9 | #include "qchartaxis.h" | |
|
10 | #include "qchartaxiscategories.h" | |
|
8 | 11 | #include <QDebug> |
|
9 | 12 | #include <QToolTip> |
|
10 | 13 | |
|
11 | 14 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | 15 | |
|
13 |
BarPresenterBase::BarPresenterBase(QBarSeries *series, Q |
|
|
16 | BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent) | |
|
14 | 17 | : ChartItem(parent) |
|
15 | ,mBarWidth(20) // TODO: remove hard coding, when we have layout code ready | |
|
16 | 18 | ,mLayoutSet(false) |
|
17 | 19 | ,mSeparatorsEnabled(false) |
|
18 | 20 | ,mSeries(series) |
|
21 | ,mChart(parent) | |
|
19 | 22 | { |
|
20 | 23 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); |
|
24 | initAxisLabels(); | |
|
21 | 25 | dataChanged(); |
|
22 | 26 | } |
|
23 | 27 | |
@@ -42,11 +46,6 QRectF BarPresenterBase::boundingRect() const | |||
|
42 | 46 | return QRectF(0,0,mWidth,mHeight); |
|
43 | 47 | } |
|
44 | 48 | |
|
45 | void BarPresenterBase::setBarWidth( int w ) | |
|
46 | { | |
|
47 | mBarWidth = w; | |
|
48 | } | |
|
49 | ||
|
50 | 49 | void BarPresenterBase::dataChanged() |
|
51 | 50 | { |
|
52 | 51 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
@@ -76,6 +75,7 void BarPresenterBase::dataChanged() | |||
|
76 | 75 | } |
|
77 | 76 | |
|
78 | 77 | // Create labels |
|
78 | /* | |
|
79 | 79 | int count = mSeries->categoryCount(); |
|
80 | 80 | for (int i=0; i<count; i++) { |
|
81 | 81 | BarLabel* label = new BarLabel(this); |
@@ -83,9 +83,10 void BarPresenterBase::dataChanged() | |||
|
83 | 83 | childItems().append(label); |
|
84 | 84 | mLabels.append(label); |
|
85 | 85 | } |
|
86 | */ | |
|
86 | 87 | |
|
87 | 88 | // Create separators |
|
88 | count = mSeries->categoryCount() - 1; // There is one less separator than columns | |
|
89 | int count = mSeries->categoryCount() - 1; // There is one less separator than columns | |
|
89 | 90 | for (int i=0; i<count; i++) { |
|
90 | 91 | Separator* sep = new Separator(this); |
|
91 | 92 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme |
@@ -106,6 +107,31 void BarPresenterBase::dataChanged() | |||
|
106 | 107 | } |
|
107 | 108 | } |
|
108 | 109 | |
|
110 | void BarPresenterBase::initAxisLabels() | |
|
111 | { | |
|
112 | int count = mSeries->categoryCount(); | |
|
113 | if (0 == count) { | |
|
114 | return; | |
|
115 | } | |
|
116 | ||
|
117 | mChart->axisX()->setTicksCount(count); | |
|
118 | ||
|
119 | qreal min = 0; | |
|
120 | qreal max = mSeries->categoryCount(); | |
|
121 | ||
|
122 | mChart->axisX()->setMin(min); | |
|
123 | mChart->axisX()->setMax(max); | |
|
124 | qreal step = (max-min)/count; | |
|
125 | QChartAxisCategories& categories = mChart->axisX()->categories(); | |
|
126 | categories.clear(); | |
|
127 | for (int i=0; i<count; i++) { | |
|
128 | qDebug() << "initAxisLabels" << min << mSeries->categoryName(i); | |
|
129 | categories.insert(min,mSeries->categoryName(i)); | |
|
130 | min += step; | |
|
131 | } | |
|
132 | mChart->axisX()->setLabelsVisible(true); | |
|
133 | } | |
|
134 | ||
|
109 | 135 | //handlers |
|
110 | 136 | |
|
111 | 137 | void BarPresenterBase::handleModelChanged(int index) |
@@ -116,10 +142,24 void BarPresenterBase::handleModelChanged(int index) | |||
|
116 | 142 | |
|
117 | 143 | void BarPresenterBase::handleDomainChanged(const Domain& domain) |
|
118 | 144 | { |
|
119 |
|
|
|
120 | // TODO: Figure out the use case for this. | |
|
121 | // Affects the size of visible item, so layout is changed. | |
|
122 | // layoutChanged(); | |
|
145 | qDebug() << "BarPresenterBase::handleDomainChanged"; | |
|
146 | /* | |
|
147 | int count = mSeries->categoryCount(); | |
|
148 | if (0 == count) { | |
|
149 | return; | |
|
150 | } | |
|
151 | ||
|
152 | // Position labels to domain | |
|
153 | qreal min = domain.minX(); | |
|
154 | qreal max = domain.maxX(); | |
|
155 | qreal step = (max-min)/count; | |
|
156 | QChartAxisCategories& categories = mChart->axisX()->categories(); | |
|
157 | categories.clear(); | |
|
158 | for (int i=0; i<count; i++) { | |
|
159 | categories.insert(min,mSeries->categoryName(i)); | |
|
160 | min += step; | |
|
161 | } | |
|
162 | */ | |
|
123 | 163 | } |
|
124 | 164 | |
|
125 | 165 | void BarPresenterBase::handleGeometryChanged(const QRectF& rect) |
@@ -13,6 +13,8 class Bar; | |||
|
13 | 13 | class BarLabel; |
|
14 | 14 | class Separator; |
|
15 | 15 | class BarValue; |
|
16 | class QChartAxisCategories; | |
|
17 | class QChart; | |
|
16 | 18 | |
|
17 | 19 | // Common implemantation of different presenters. Not to be instantiated. |
|
18 | 20 | // TODO: combine this with BarPresenter and derive other presenters from it? |
@@ -20,7 +22,7 class BarPresenterBase : public QObject, public ChartItem | |||
|
20 | 22 | { |
|
21 | 23 | Q_OBJECT |
|
22 | 24 | public: |
|
23 |
BarPresenterBase(QBarSeries *series, Q |
|
|
25 | BarPresenterBase(QBarSeries *series, QChart *parent = 0); | |
|
24 | 26 | virtual ~BarPresenterBase(); |
|
25 | 27 | |
|
26 | 28 | public: |
@@ -28,13 +30,13 public: | |||
|
28 | 30 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
29 | 31 | QRectF boundingRect() const; |
|
30 | 32 | |
|
31 | // TODO: these may change with layout awarness. | |
|
32 | void setBarWidth( int w ); | |
|
33 | ||
|
34 | 33 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it |
|
35 | 34 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
36 | 35 | virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes |
|
37 | 36 | |
|
37 | protected: | |
|
38 | void initAxisLabels(); | |
|
39 | ||
|
38 | 40 | public slots: |
|
39 | 41 | void handleModelChanged(int index); |
|
40 | 42 | void handleDomainChanged(const Domain& domain); |
@@ -60,7 +62,7 protected: | |||
|
60 | 62 | QList<BarLabel*> mLabels; |
|
61 | 63 | QList<Separator*> mSeparators; |
|
62 | 64 | QList<BarValue*> mFloatingValues; |
|
63 | ||
|
65 | QChart* mChart; | |
|
64 | 66 | }; |
|
65 | 67 | |
|
66 | 68 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -9,7 +9,7 | |||
|
9 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 10 | |
|
11 | 11 | |
|
12 |
PercentBarPresenter::PercentBarPresenter(QBarSeries *series, Q |
|
|
12 | PercentBarPresenter::PercentBarPresenter(QBarSeries *series, QChart *parent) : | |
|
13 | 13 | BarPresenterBase(series, parent) |
|
14 | 14 | { |
|
15 | 15 | } |
@@ -13,7 +13,7 class PercentBarPresenter : public BarPresenterBase | |||
|
13 | 13 | { |
|
14 | 14 | Q_OBJECT |
|
15 | 15 | public: |
|
16 |
PercentBarPresenter(QBarSeries *series, Q |
|
|
16 | PercentBarPresenter(QBarSeries *series, QChart *parent = 0); | |
|
17 | 17 | |
|
18 | 18 | private: |
|
19 | 19 |
@@ -118,6 +118,7 QString QBarSeries::categoryName(int category) | |||
|
118 | 118 | */ |
|
119 | 119 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
120 | 120 | { |
|
121 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
|
121 | 122 | if (enabled) { |
|
122 | 123 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
123 | 124 | QBarSet *set = mModel->setAt(i); |
@@ -8,7 +8,7 | |||
|
8 | 8 | |
|
9 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 10 | |
|
11 |
StackedBarPresenter::StackedBarPresenter(QBarSeries *series, Q |
|
|
11 | StackedBarPresenter::StackedBarPresenter(QBarSeries *series, QChart *parent) : | |
|
12 | 12 | BarPresenterBase(series,parent) |
|
13 | 13 | { |
|
14 | 14 | } |
@@ -66,8 +66,8 void StackedBarPresenter::layoutChanged() | |||
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | // TODO: Layout for labels, remove magic number |
|
69 | BarLabel* label = mLabels.at(labelIndex); | |
|
70 | label->setPos(xPos, mHeight + 20); | |
|
69 | // BarLabel* label = mLabels.at(labelIndex); | |
|
70 | // label->setPos(xPos, mHeight + 20); | |
|
71 | 71 | labelIndex++; |
|
72 | 72 | xPos += xStep; |
|
73 | 73 | } |
General Comments 0
You need to be logged in to leave comments.
Login now