@@ -49,13 +49,14 int main(int argc, char *argv[]) | |||
|
49 | 49 | //! [4] |
|
50 | 50 | // Enable tooltip |
|
51 | 51 | series->setToolTipEnabled(); |
|
52 | series->setSeparatorsVisible(true); | |
|
52 | 53 | |
|
53 | 54 | // Connect clicked signal of set to toggle floating values of set. |
|
54 | // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values. | |
|
55 | 55 | QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues())); |
|
56 | 56 | QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues())); |
|
57 | 57 | QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues())); |
|
58 | 58 | QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues())); |
|
59 | QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues())); | |
|
59 | 60 | //! [4] |
|
60 | 61 | |
|
61 | 62 | //! [5] |
@@ -68,9 +69,7 int main(int argc, char *argv[]) | |||
|
68 | 69 | //! [5] |
|
69 | 70 | |
|
70 | 71 | //! [6] |
|
71 | chartView->axisX()->setAxisVisible(false); | |
|
72 | 72 | chartView->axisX()->setGridVisible(false); |
|
73 | chartView->axisX()->setLabelsVisible(false); | |
|
74 | 73 | //! [6] |
|
75 | 74 | |
|
76 | 75 | window.setCentralWidget(chartView); |
@@ -50,11 +50,11 int main(int argc, char *argv[]) | |||
|
50 | 50 | series->setToolTipEnabled(); |
|
51 | 51 | |
|
52 | 52 | // Connect clicked signal of set to toggle floating values of set. |
|
53 | // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values. | |
|
54 | 53 | QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues())); |
|
55 | 54 | QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues())); |
|
56 | 55 | QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues())); |
|
57 | 56 | QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues())); |
|
57 | QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues())); | |
|
58 | 58 | //! [4] |
|
59 | 59 | |
|
60 | 60 | //! [5] |
@@ -67,9 +67,7 int main(int argc, char *argv[]) | |||
|
67 | 67 | //! [5] |
|
68 | 68 | |
|
69 | 69 | //! [6] |
|
70 | chartView->axisX()->setAxisVisible(false); | |
|
71 | 70 | chartView->axisX()->setGridVisible(false); |
|
72 | chartView->axisX()->setLabelsVisible(false); | |
|
73 | 71 | //! [6] |
|
74 | 72 | |
|
75 | 73 | window.setCentralWidget(chartView); |
@@ -1,6 +1,7 | |||
|
1 | 1 | #include "barpresenter_p.h" |
|
2 | 2 | #include "bar_p.h" |
|
3 | 3 | #include "barvalue_p.h" |
|
4 | #include "separator_p.h" | |
|
4 | 5 | #include "qbarset.h" |
|
5 | 6 | #include <QDebug> |
|
6 | 7 | |
@@ -34,12 +35,12 void BarPresenter::layoutChanged() | |||
|
34 | 35 | qreal tM = mSeries->max(); |
|
35 | 36 | qreal scale = (tH/tM); |
|
36 | 37 | qreal tC = categoryCount + 1; |
|
37 | mBarWidth = tW / ((categoryCount * setCount) + tC); | |
|
38 | qreal xStepPerCategory = (tW/tC) + mBarWidth; | |
|
38 | qreal categoryWidth = tW/tC; | |
|
39 | mBarWidth = categoryWidth / (setCount+1); | |
|
39 | 40 | |
|
40 | 41 | int itemIndex(0); |
|
41 | 42 | for (int category=0; category < categoryCount; category++) { |
|
42 |
qreal xPos = |
|
|
43 | qreal xPos = categoryWidth * category + categoryWidth /2; | |
|
43 | 44 | qreal yPos = mHeight; |
|
44 | 45 | for (int set = 0; set < setCount; set++) { |
|
45 | 46 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
@@ -54,10 +55,19 void BarPresenter::layoutChanged() | |||
|
54 | 55 | } |
|
55 | 56 | } |
|
56 | 57 | |
|
58 | // Position separators | |
|
59 | qreal xPos = categoryWidth + categoryWidth/2 - mBarWidth /2; | |
|
60 | for (int s=0; s < mSeparators.count(); s++) { | |
|
61 | Separator* sep = mSeparators.at(s); | |
|
62 | sep->setPos(xPos,0); | |
|
63 | sep->setSize(QSizeF(1,mHeight)); | |
|
64 | xPos += categoryWidth; | |
|
65 | } | |
|
66 | ||
|
57 | 67 | // Position floating values |
|
58 | 68 | itemIndex = 0; |
|
59 | 69 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
60 |
qreal xPos = |
|
|
70 | qreal xPos = categoryWidth * category + categoryWidth/2 + mBarWidth/2; | |
|
61 | 71 | qreal yPos = mHeight; |
|
62 | 72 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
63 | 73 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
@@ -15,11 +15,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
15 | 15 | BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent) |
|
16 | 16 | : ChartItem(parent) |
|
17 | 17 | ,mLayoutSet(false) |
|
18 | ,mSeparatorsEnabled(false) | |
|
19 | 18 | ,mSeries(series) |
|
20 | 19 | ,mChart(parent) |
|
21 | 20 | { |
|
22 | 21 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); |
|
22 | connect(series,SIGNAL(enableSeparators(bool)),this,SLOT(enableSeparators(bool))); | |
|
23 | enableSeparators(series->separatorsVisible()); | |
|
23 | 24 | initAxisLabels(); |
|
24 | 25 | dataChanged(); |
|
25 | 26 | } |
@@ -27,6 +28,7 BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent) | |||
|
27 | 28 | BarPresenterBase::~BarPresenterBase() |
|
28 | 29 | { |
|
29 | 30 | disconnect(this,SLOT(showToolTip(QPoint,QString))); |
|
31 | disconnect(this,SLOT(enableSeparators(bool))); | |
|
30 | 32 | } |
|
31 | 33 | |
|
32 | 34 | void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
@@ -77,7 +79,7 void BarPresenterBase::dataChanged() | |||
|
77 | 79 | for (int i=0; i<count; i++) { |
|
78 | 80 | Separator* sep = new Separator(this); |
|
79 | 81 | sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme |
|
80 |
sep->setVisible(mSeparators |
|
|
82 | sep->setVisible(mSeries->separatorsVisible()); | |
|
81 | 83 | childItems().append(sep); |
|
82 | 84 | mSeparators.append(sep); |
|
83 | 85 | } |
@@ -170,7 +172,6 void BarPresenterBase::enableSeparators(bool enabled) | |||
|
170 | 172 | for (int i=0; i<mSeparators.count(); i++) { |
|
171 | 173 | mSeparators.at(i)->setVisible(enabled); |
|
172 | 174 | } |
|
173 | mSeparatorsEnabled = enabled; | |
|
174 | 175 | } |
|
175 | 176 | |
|
176 | 177 | #include "moc_barpresenterbase_p.cpp" |
@@ -53,7 +53,6 protected: | |||
|
53 | 53 | qreal mBarWidth; |
|
54 | 54 | |
|
55 | 55 | bool mLayoutSet; // True, if component has been laid out. |
|
56 | bool mSeparatorsEnabled; | |
|
57 | 56 | |
|
58 | 57 | // Not owned. |
|
59 | 58 | QBarSeries* mSeries; |
@@ -137,10 +137,10 void QBarSeries::setToolTipEnabled(bool enabled) | |||
|
137 | 137 | Separators are visual elements that are drawn between categories. |
|
138 | 138 | Calling without parameter \a enabled, enables the separators |
|
139 | 139 | */ |
|
140 |
void QBarSeries::setSeparators |
|
|
140 | void QBarSeries::setSeparatorsVisible(bool visible) | |
|
141 | 141 | { |
|
142 | // TODO: toggle | |
|
143 |
|
|
|
142 | mSeparatorsVisible = visible; | |
|
143 | emit enableSeparators(visible); | |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | |
@@ -217,6 +217,11 BarChartModel& QBarSeries::model() | |||
|
217 | 217 | return *mModel; |
|
218 | 218 | } |
|
219 | 219 | |
|
220 | bool QBarSeries::separatorsVisible() | |
|
221 | { | |
|
222 | return mSeparatorsVisible; | |
|
223 | } | |
|
224 | ||
|
220 | 225 | #include "moc_qbarseries.cpp" |
|
221 | 226 | |
|
222 | 227 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -39,6 +39,7 public: | |||
|
39 | 39 | qreal categorySum(int category); |
|
40 | 40 | qreal maxCategorySum(); |
|
41 | 41 | BarChartModel& model(); |
|
42 | bool separatorsVisible(); | |
|
42 | 43 | // <--- TO PIMPL |
|
43 | 44 | |
|
44 | 45 | signals: |
@@ -48,12 +49,13 signals: | |||
|
48 | 49 | |
|
49 | 50 | // TODO: internal signals, these to private implementation. |
|
50 | 51 | // TODO: TO PIMPL ---> |
|
52 | void enableSeparators(bool enable); | |
|
51 | 53 | void showToolTip(QPoint pos, QString tip); |
|
52 | 54 | // <--- TO PIMPL |
|
53 | 55 | |
|
54 | 56 | public Q_SLOTS: |
|
55 | 57 | void setToolTipEnabled(bool enabled=true); // enables tooltips |
|
56 |
void setSeparators |
|
|
58 | void setSeparatorsVisible(bool visible=true); // enables separators between categories | |
|
57 | 59 | |
|
58 | 60 | // TODO: TO PIMPL ---> |
|
59 | 61 | void barsetClicked(QString category); |
@@ -62,6 +64,7 public Q_SLOTS: | |||
|
62 | 64 | |
|
63 | 65 | protected: |
|
64 | 66 | BarChartModel* mModel; |
|
67 | bool mSeparatorsVisible; | |
|
65 | 68 | }; |
|
66 | 69 | |
|
67 | 70 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -272,7 +272,7 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS | |||
|
272 | 272 | // TODO: new implementation of setFloatingValuesEnabled with signals |
|
273 | 273 | //series->setFloatingValuesEnabled(true); |
|
274 | 274 | series->setToolTipEnabled(true); |
|
275 |
series->setSeparators |
|
|
275 | series->setSeparatorsVisible(false); | |
|
276 | 276 | m_chartView->addSeries(series); |
|
277 | 277 | setCurrentSeries(series); |
|
278 | 278 | } else if (seriesName == "Spline") { |
General Comments 0
You need to be logged in to leave comments.
Login now