@@ -1,42 +1,33 | |||||
1 | /*! |
|
1 | /*! | |
2 | \example examples/splinechart |
|
2 | \example examples/splinechart | |
3 | \title SplineChart Example |
|
3 | \title SplineChart Example | |
4 | \subtitle |
|
4 | \subtitle | |
5 |
|
5 | |||
6 | The example shows how to create simple spline chart. |
|
6 | The example shows how to create simple spline chart. | |
7 |
|
7 | |||
8 | \image splinechart_example |
|
8 | \image splinechart_example | |
9 |
|
9 | |||
10 | To create spline chart we need to put our data into QSplineSeries. QSplineSeries automatically calculates spline segment control points that are needed to properly draw the spline. |
|
10 | To create spline chart we need to put our data into QSplineSeries. QSplineSeries automatically calculates spline segment control points that are needed to properly draw the spline. | |
11 |
|
11 | |||
12 |
\snippet ../examples/splinechart/ |
|
12 | \snippet ../examples/splinechart/main.cpp 1 | |
13 |
|
13 | |||
14 | Customize the look of the spline, by setting its pen's color and pen's width |
|
14 | Customize the look of the spline, by setting its pen's color and pen's width | |
15 |
|
15 | |||
16 |
\snippet ../examples/splinechart/ |
|
16 | \snippet ../examples/splinechart/main.cpp 2 | |
17 |
|
17 | |||
18 | Now lets add some data points to the series. |
|
18 | Now lets add some data points to the series. | |
19 |
|
19 | |||
20 |
\snippet ../examples/splinechart/ |
|
20 | \snippet ../examples/splinechart/main.cpp 3 | |
21 |
|
21 | |||
22 |
The data series has been populated. To display it on a chart we create QChart |
|
22 | The data series has been populated. To display it on a chart we create QChart object and add the data series to it. We also set the title and the values range on y axis, so that our chart is better visible. | |
23 |
|
23 | |||
24 |
\snippet ../examples/splinechart/ |
|
24 | \snippet ../examples/splinechart/main.cpp 4 | |
25 |
|
25 | |||
26 | Then we add two buttons for adding and removing data points. Buttons clicked() signals are connected to handler functions. |
|
26 | Then we created a QChartView object with QChart as a parameter. This way we don't need to create QGraphicsView scene ourselves. We also set the Antialiasing on to have the rendered lines look nicer. | |
27 |
|
27 | |||
28 |
\snippet ../examples/splinechart/ |
|
28 | \snippet ../examples/splinechart/main.cpp 5 | |
29 |
|
29 | |||
30 | In the end we add the chart and the buttons to the widget's layout. |
|
30 | In the end we set the QChartView as the windows's central widget. | |
31 |
|
||||
32 | \snippet ../examples/splinechart/splinewidget.cpp 5 |
|
|||
33 |
|
||||
34 | Here is the handler function for add new data point button: |
|
|||
35 |
|
||||
36 | \snippet ../examples/splinechart/splinewidget.cpp add point |
|
|||
37 |
|
||||
38 | And here is one for remove the last data point in the series: |
|
|||
39 |
|
||||
40 | \snippet ../examples/splinechart/splinewidget.cpp remove point |
|
|||
41 |
|
31 | |||
|
32 | \snippet ../examples/splinechart/main.cpp 6 | |||
42 | */ |
|
33 | */ |
@@ -1,68 +1,71 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QSplineSeries> |
|
24 | #include <QSplineSeries> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
27 | |||
28 | int main(int argc, char *argv[]) |
|
28 | int main(int argc, char *argv[]) | |
29 | { |
|
29 | { | |
30 | QApplication a(argc, argv); |
|
30 | QApplication a(argc, argv); | |
31 |
|
31 | |||
32 | //![1] |
|
32 | //![1] | |
33 | QSplineSeries* series = new QSplineSeries(); |
|
33 | QSplineSeries* series = new QSplineSeries(); | |
|
34 | //![1] | |||
|
35 | ||||
|
36 | //![2] | |||
34 | QPen red(Qt::red); |
|
37 | QPen red(Qt::red); | |
35 | red.setWidth(3); |
|
38 | red.setWidth(3); | |
36 | series->setPen(red); |
|
39 | series->setPen(red); | |
37 |
|
|
40 | //![2] | |
38 |
|
41 | |||
39 |
|
|
42 | //![3] | |
40 | series->append(0, 6); |
|
43 | series->append(0, 6); | |
41 | series->append(2, 4); |
|
44 | series->append(2, 4); | |
42 | series->append(3, 8); |
|
45 | series->append(3, 8); | |
43 | series->append(7, 4); |
|
46 | series->append(7, 4); | |
44 | series->append(10, 5); |
|
47 | series->append(10, 5); | |
45 | *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); |
|
48 | *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); | |
46 |
|
|
49 | //![3] | |
47 |
|
50 | |||
48 |
|
|
51 | //![4] | |
49 | QChart* chart = new QChart(); |
|
52 | QChart* chart = new QChart(); | |
50 | chart->addSeries(series); |
|
53 | chart->addSeries(series); | |
51 | chart->setTitle("Simple spline chart example"); |
|
54 | chart->setTitle("Simple spline chart example"); | |
52 | chart->axisY()->setRange(0, 10); |
|
55 | chart->axisY()->setRange(0, 10); | |
53 |
|
|
56 | //![4] | |
54 |
|
57 | |||
55 |
|
|
58 | //![5] | |
56 | QChartView* chartView = new QChartView(chart); |
|
59 | QChartView* chartView = new QChartView(chart); | |
57 | chartView->setRenderHint(QPainter::Antialiasing); |
|
60 | chartView->setRenderHint(QPainter::Antialiasing); | |
58 |
|
|
61 | //![5] | |
59 |
|
62 | |||
60 |
|
|
63 | //![6] | |
61 | QMainWindow window; |
|
64 | QMainWindow window; | |
62 | window.setCentralWidget(chartView); |
|
65 | window.setCentralWidget(chartView); | |
63 | window.resize(400, 300); |
|
66 | window.resize(400, 300); | |
64 | window.show(); |
|
67 | window.show(); | |
65 |
|
|
68 | //![6] | |
66 |
|
69 | |||
67 | return a.exec(); |
|
70 | return a.exec(); | |
68 | } |
|
71 | } |
@@ -1,459 +1,472 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QDebug> |
|
21 | #include <QDebug> | |
22 | #include "qbarseries.h" |
|
22 | #include "qbarseries.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "barchartmodel_p.h" |
|
24 | #include "barchartmodel_p.h" | |
25 | #include <QAbstractItemModel> |
|
25 | #include <QAbstractItemModel> | |
26 | #include <QModelIndex> |
|
26 | #include <QModelIndex> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QBarSeries |
|
31 | \class QBarSeries | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief part of QtCommercial chart API. | |
33 |
|
33 | |||
34 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
34 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
35 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
35 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
36 | by QStringList. |
|
36 | by QStringList. | |
37 |
|
37 | |||
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
40 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \fn virtual QSeriesType QBarSeries::type() const |
|
44 | \fn virtual QSeriesType QBarSeries::type() const | |
45 | \brief Returns type of series. |
|
45 | \brief Returns type of series. | |
46 | \sa QSeries, QSeriesType |
|
46 | \sa QSeries, QSeriesType | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
50 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
51 | \brief \internal \a pos \a tip |
|
51 | \brief \internal \a pos \a tip | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
55 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
56 | QBarSeries is QObject which is a child of a \a parent. |
|
56 | QBarSeries is QObject which is a child of a \a parent. | |
57 | */ |
|
57 | */ | |
58 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), |
|
58 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), | |
59 | m_internalModel(new BarChartModel(categories, this)) |
|
59 | m_internalModel(new BarChartModel(categories, this)) | |
60 | { |
|
60 | { | |
61 | m_model = 0; |
|
61 | m_model = 0; | |
62 | m_mapCategories = -1; |
|
62 | m_mapCategories = -1; | |
63 | m_mapBarBottom = -1; |
|
63 | m_mapBarBottom = -1; | |
64 | m_mapBarTop = -1; |
|
64 | m_mapBarTop = -1; | |
65 | m_mapFirst = 0; |
|
65 | m_mapFirst = 0; | |
66 | m_mapCount = 0; |
|
66 | m_mapCount = 0; | |
67 | m_mapOrientation = Qt::Vertical; |
|
67 | m_mapOrientation = Qt::Vertical; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | Adds a set of bars to series. Takes ownership of \a set. |
|
71 | Adds a set of bars to series. Takes ownership of \a set. | |
72 | Connects the clicked(QString, Qt::MouseButtons) signal |
|
72 | Connects the clicked(QString, Qt::MouseButtons) signal | |
73 | of \a set to this series |
|
73 | of \a set to this series | |
74 | */ |
|
74 | */ | |
75 | void QBarSeries::appendBarSet(QBarSet *set) |
|
75 | void QBarSeries::appendBarSet(QBarSet *set) | |
76 | { |
|
76 | { | |
77 | m_internalModel->appendBarSet(set); |
|
77 | m_internalModel->appendBarSet(set); | |
78 | connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
78 | connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
79 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
79 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
80 | emit restructuredBars(); |
|
80 | emit restructuredBars(); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
84 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
85 | Disconnects the clicked(QString, Qt::MouseButtons) signal |
|
85 | Disconnects the clicked(QString, Qt::MouseButtons) signal | |
86 | of \a set from this series |
|
86 | of \a set from this series | |
87 | */ |
|
87 | */ | |
88 | void QBarSeries::removeBarSet(QBarSet *set) |
|
88 | void QBarSeries::removeBarSet(QBarSet *set) | |
89 | { |
|
89 | { | |
90 | disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
90 | disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
91 | m_internalModel->removeBarSet(set); |
|
91 | m_internalModel->removeBarSet(set); | |
92 | emit restructuredBars(); |
|
92 | emit restructuredBars(); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
96 | Adds a list of barsets to series. Takes ownership of \a sets. | |
97 | Connects the clicked(QString, Qt::MouseButtons) signals |
|
97 | Connects the clicked(QString, Qt::MouseButtons) signals | |
98 | of \a sets to this series |
|
98 | of \a sets to this series | |
99 | */ |
|
99 | */ | |
100 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) |
|
100 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) | |
101 | { |
|
101 | { | |
102 | foreach (QBarSet* barset, sets) { |
|
102 | foreach (QBarSet* barset, sets) { | |
103 | m_internalModel->appendBarSet(barset); |
|
103 | m_internalModel->appendBarSet(barset); | |
104 | connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
104 | connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
105 | connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
105 | connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
106 | } |
|
106 | } | |
107 | emit restructuredBars(); |
|
107 | emit restructuredBars(); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | Removes a list of barsets from series. Releases ownership of \a set. Doesnt delete \a sets. |
|
111 | Removes a list of barsets from series. Releases ownership of \a sets. Doesnt delete \a sets. | |
112 | Disconnects the clicked(QString, Qt::MouseButtons) signal |
|
112 | Disconnects the clicked(QString, Qt::MouseButtons) signal | |
113 | of \a sets from this series |
|
113 | of \a sets from this series | |
114 | */ |
|
114 | */ | |
115 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) |
|
115 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) | |
116 | { |
|
116 | { | |
117 | foreach (QBarSet* barset, sets) { |
|
117 | foreach (QBarSet* barset, sets) { | |
118 | disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
118 | disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
119 | m_internalModel->removeBarSet(barset); |
|
119 | m_internalModel->removeBarSet(barset); | |
120 | } |
|
120 | } | |
121 | emit restructuredBars(); |
|
121 | emit restructuredBars(); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
|
124 | /*! | |||
|
125 | Inserts new \a set on the \a i position. | |||
|
126 | The barset that is currently at this postion is moved to postion i + 1 | |||
|
127 | */ | |||
124 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
128 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |
125 | { |
|
129 | { | |
126 | m_internalModel->insertBarSet(i, set); |
|
130 | m_internalModel->insertBarSet(i, set); | |
127 | // emit barsetChanged(); |
|
131 | // emit barsetChanged(); | |
128 | } |
|
132 | } | |
129 |
|
133 | |||
|
134 | /*! | |||
|
135 | Inserts new \a category on the \a i position. | |||
|
136 | The category that is currently at this postion is moved to postion i + 1 | |||
|
137 | \sa removeCategory() | |||
|
138 | */ | |||
130 | void QBarSeries::insertCategory(int i, QString category) |
|
139 | void QBarSeries::insertCategory(int i, QString category) | |
131 | { |
|
140 | { | |
132 | m_internalModel->insertCategory(i, category); |
|
141 | m_internalModel->insertCategory(i, category); | |
133 | } |
|
142 | } | |
134 |
|
143 | |||
|
144 | /*! | |||
|
145 | Removes the category specified by \a i | |||
|
146 | \sa insertCategory() | |||
|
147 | */ | |||
135 | void QBarSeries::removeCategory(int i) |
|
148 | void QBarSeries::removeCategory(int i) | |
136 | { |
|
149 | { | |
137 | m_internalModel->removeCategory(i); |
|
150 | m_internalModel->removeCategory(i); | |
138 | } |
|
151 | } | |
139 |
|
152 | |||
140 | /*! |
|
153 | /*! | |
141 | Returns number of sets in series. |
|
154 | Returns number of sets in series. | |
142 | */ |
|
155 | */ | |
143 | int QBarSeries::barsetCount() const |
|
156 | int QBarSeries::barsetCount() const | |
144 | { |
|
157 | { | |
145 | // if(m_model) |
|
158 | // if(m_model) | |
146 | // return m_mapBarTop - m_mapBarBottom; |
|
159 | // return m_mapBarTop - m_mapBarBottom; | |
147 | // else |
|
160 | // else | |
148 | return m_internalModel->barsetCount(); |
|
161 | return m_internalModel->barsetCount(); | |
149 | } |
|
162 | } | |
150 |
|
163 | |||
151 | /*! |
|
164 | /*! | |
152 | Returns number of categories in series |
|
165 | Returns number of categories in series | |
153 | */ |
|
166 | */ | |
154 | int QBarSeries::categoryCount() const |
|
167 | int QBarSeries::categoryCount() const | |
155 | { |
|
168 | { | |
156 | return m_internalModel->categoryCount(); |
|
169 | return m_internalModel->categoryCount(); | |
157 | } |
|
170 | } | |
158 |
|
171 | |||
159 | /*! |
|
172 | /*! | |
160 | Returns a list of sets in series. Keeps ownership of sets. |
|
173 | Returns a list of sets in series. Keeps ownership of sets. | |
161 | */ |
|
174 | */ | |
162 | QList<QBarSet*> QBarSeries::barSets() const |
|
175 | QList<QBarSet*> QBarSeries::barSets() const | |
163 | { |
|
176 | { | |
164 | return m_internalModel->barSets(); |
|
177 | return m_internalModel->barSets(); | |
165 | } |
|
178 | } | |
166 |
|
179 | |||
167 | /*! |
|
180 | /*! | |
168 | \internal \a index |
|
181 | \internal \a index | |
169 | */ |
|
182 | */ | |
170 | QBarSet* QBarSeries::barsetAt(int index) |
|
183 | QBarSet* QBarSeries::barsetAt(int index) | |
171 | { |
|
184 | { | |
172 | return m_internalModel->barsetAt(index); |
|
185 | return m_internalModel->barsetAt(index); | |
173 | } |
|
186 | } | |
174 |
|
187 | |||
175 | /*! |
|
188 | /*! | |
176 | \internal \a category |
|
189 | \internal \a category | |
177 | */ |
|
190 | */ | |
178 | QString QBarSeries::categoryName(int category) |
|
191 | QString QBarSeries::categoryName(int category) | |
179 | { |
|
192 | { | |
180 | return m_internalModel->categoryName(category); |
|
193 | return m_internalModel->categoryName(category); | |
181 | } |
|
194 | } | |
182 |
|
195 | |||
183 | /*! |
|
196 | /*! | |
184 | Enables or disables tooltip depending on parameter \a enabled. |
|
197 | Enables or disables tooltip depending on parameter \a enabled. | |
185 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
198 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
186 | Calling without parameter \a enabled, enables the tooltip |
|
199 | Calling without parameter \a enabled, enables the tooltip | |
187 | */ |
|
200 | */ | |
188 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
201 | void QBarSeries::setToolTipEnabled(bool enabled) | |
189 | { |
|
202 | { | |
190 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
203 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
191 | if (enabled) { |
|
204 | if (enabled) { | |
192 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
205 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
193 | QBarSet *set = m_internalModel->barsetAt(i); |
|
206 | QBarSet *set = m_internalModel->barsetAt(i); | |
194 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
207 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
195 | } |
|
208 | } | |
196 | } else { |
|
209 | } else { | |
197 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
210 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
198 | QBarSet *set = m_internalModel->barsetAt(i); |
|
211 | QBarSet *set = m_internalModel->barsetAt(i); | |
199 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
212 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
200 | } |
|
213 | } | |
201 | } |
|
214 | } | |
202 | } |
|
215 | } | |
203 |
|
216 | |||
204 |
|
217 | |||
205 | /*! |
|
218 | /*! | |
206 | \internal \a category |
|
219 | \internal \a category | |
207 | */ |
|
220 | */ | |
208 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) |
|
221 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) | |
209 | { |
|
222 | { | |
210 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); |
|
223 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
211 | } |
|
224 | } | |
212 |
|
225 | |||
213 | /*! |
|
226 | /*! | |
214 | \internal |
|
227 | \internal | |
215 | */ |
|
228 | */ | |
216 | qreal QBarSeries::min() |
|
229 | qreal QBarSeries::min() | |
217 | { |
|
230 | { | |
218 | return m_internalModel->min(); |
|
231 | return m_internalModel->min(); | |
219 | } |
|
232 | } | |
220 |
|
233 | |||
221 | /*! |
|
234 | /*! | |
222 | \internal |
|
235 | \internal | |
223 | */ |
|
236 | */ | |
224 | qreal QBarSeries::max() |
|
237 | qreal QBarSeries::max() | |
225 | { |
|
238 | { | |
226 | return m_internalModel->max(); |
|
239 | return m_internalModel->max(); | |
227 | } |
|
240 | } | |
228 |
|
241 | |||
229 | /*! |
|
242 | /*! | |
230 | \internal \a set \a category |
|
243 | \internal \a set \a category | |
231 | */ |
|
244 | */ | |
232 | qreal QBarSeries::valueAt(int set, int category) |
|
245 | qreal QBarSeries::valueAt(int set, int category) | |
233 | { |
|
246 | { | |
234 | return m_internalModel->valueAt(set, category); |
|
247 | return m_internalModel->valueAt(set, category); | |
235 | } |
|
248 | } | |
236 |
|
249 | |||
237 | /*! |
|
250 | /*! | |
238 | \internal \a set \a category |
|
251 | \internal \a set \a category | |
239 | */ |
|
252 | */ | |
240 | qreal QBarSeries::percentageAt(int set, int category) |
|
253 | qreal QBarSeries::percentageAt(int set, int category) | |
241 | { |
|
254 | { | |
242 | return m_internalModel->percentageAt(set, category); |
|
255 | return m_internalModel->percentageAt(set, category); | |
243 | } |
|
256 | } | |
244 |
|
257 | |||
245 | /*! |
|
258 | /*! | |
246 | \internal \a category |
|
259 | \internal \a category | |
247 | */ |
|
260 | */ | |
248 | qreal QBarSeries::categorySum(int category) |
|
261 | qreal QBarSeries::categorySum(int category) | |
249 | { |
|
262 | { | |
250 | return m_internalModel->categorySum(category); |
|
263 | return m_internalModel->categorySum(category); | |
251 | } |
|
264 | } | |
252 |
|
265 | |||
253 | /*! |
|
266 | /*! | |
254 | \internal \a category |
|
267 | \internal \a category | |
255 | */ |
|
268 | */ | |
256 | qreal QBarSeries::absoluteCategorySum(int category) |
|
269 | qreal QBarSeries::absoluteCategorySum(int category) | |
257 | { |
|
270 | { | |
258 | return m_internalModel->absoluteCategorySum(category); |
|
271 | return m_internalModel->absoluteCategorySum(category); | |
259 | } |
|
272 | } | |
260 |
|
273 | |||
261 | /*! |
|
274 | /*! | |
262 | \internal |
|
275 | \internal | |
263 | */ |
|
276 | */ | |
264 | qreal QBarSeries::maxCategorySum() |
|
277 | qreal QBarSeries::maxCategorySum() | |
265 | { |
|
278 | { | |
266 | return m_internalModel->maxCategorySum(); |
|
279 | return m_internalModel->maxCategorySum(); | |
267 | } |
|
280 | } | |
268 |
|
281 | |||
269 | /*! |
|
282 | /*! | |
270 | \internal |
|
283 | \internal | |
271 | */ |
|
284 | */ | |
272 | BarChartModel& QBarSeries::modelInternal() |
|
285 | BarChartModel& QBarSeries::modelInternal() | |
273 | { |
|
286 | { | |
274 | return *m_internalModel; |
|
287 | return *m_internalModel; | |
275 | } |
|
288 | } | |
276 |
|
289 | |||
277 | /*! |
|
290 | /*! | |
278 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) |
|
291 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) | |
279 | Sets the \a model to be used as a data source |
|
292 | Sets the \a model to be used as a data source | |
280 | */ |
|
293 | */ | |
281 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
294 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
282 | { |
|
295 | { | |
283 | // disconnect signals from old model |
|
296 | // disconnect signals from old model | |
284 | if(m_model) |
|
297 | if(m_model) | |
285 | { |
|
298 | { | |
286 | disconnect(m_model, 0, this, 0); |
|
299 | disconnect(m_model, 0, this, 0); | |
287 | m_mapCategories = -1; |
|
300 | m_mapCategories = -1; | |
288 | m_mapBarBottom = -1; |
|
301 | m_mapBarBottom = -1; | |
289 | m_mapBarTop = -1; |
|
302 | m_mapBarTop = -1; | |
290 | m_mapFirst = 0; |
|
303 | m_mapFirst = 0; | |
291 | m_mapCount = 0; |
|
304 | m_mapCount = 0; | |
292 | m_mapOrientation = Qt::Vertical; |
|
305 | m_mapOrientation = Qt::Vertical; | |
293 | } |
|
306 | } | |
294 |
|
307 | |||
295 | // set new model |
|
308 | // set new model | |
296 | if(model) |
|
309 | if(model) | |
297 | { |
|
310 | { | |
298 | m_model = model; |
|
311 | m_model = model; | |
299 | return true; |
|
312 | return true; | |
300 | } |
|
313 | } | |
301 | else |
|
314 | else | |
302 | { |
|
315 | { | |
303 | m_model = 0; |
|
316 | m_model = 0; | |
304 | return false; |
|
317 | return false; | |
305 | } |
|
318 | } | |
306 | } |
|
319 | } | |
307 |
|
320 | |||
308 | /*! |
|
321 | /*! | |
309 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
322 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
310 | Sets column/row specified by \a categories to be used as a list of bar series categories. |
|
323 | Sets column/row specified by \a categories to be used as a list of bar series categories. | |
311 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. |
|
324 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. | |
312 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. |
|
325 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. | |
313 | All the columns/rows inbetween those two values are also used as data for bar sets. |
|
326 | All the columns/rows inbetween those two values are also used as data for bar sets. | |
314 | The \a orientation paramater specifies whether the data is in columns or in rows. |
|
327 | The \a orientation paramater specifies whether the data is in columns or in rows. | |
315 | */ |
|
328 | */ | |
316 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
329 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
317 | { |
|
330 | { | |
318 | if (!m_model) |
|
331 | if (!m_model) | |
319 | return; |
|
332 | return; | |
320 |
|
333 | |||
321 | m_mapCategories = categories; |
|
334 | m_mapCategories = categories; | |
322 | m_mapBarBottom = bottomBoundry; |
|
335 | m_mapBarBottom = bottomBoundry; | |
323 | m_mapBarTop = topBoundry; |
|
336 | m_mapBarTop = topBoundry; | |
324 | // m_mapFirst = 1; |
|
337 | // m_mapFirst = 1; | |
325 | m_mapOrientation = orientation; |
|
338 | m_mapOrientation = orientation; | |
326 |
|
339 | |||
327 | // connect the signals |
|
340 | // connect the signals | |
328 | if (m_mapOrientation == Qt::Vertical) { |
|
341 | if (m_mapOrientation == Qt::Vertical) { | |
329 | m_mapCount = m_model->rowCount() - m_mapFirst; |
|
342 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
330 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
343 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
331 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
344 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
332 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), |
|
345 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
333 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
346 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
334 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), |
|
347 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
335 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
348 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
336 | } else { |
|
349 | } else { | |
337 | m_mapCount = m_model->columnCount() - m_mapFirst; |
|
350 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
338 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
351 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
339 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
352 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
340 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), |
|
353 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
341 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
354 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
342 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), |
|
355 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
343 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
356 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
344 | } |
|
357 | } | |
345 |
|
358 | |||
346 | // create the initial bars |
|
359 | // create the initial bars | |
347 | delete m_internalModel; |
|
360 | delete m_internalModel; | |
348 | if (m_mapOrientation == Qt::Vertical) { |
|
361 | if (m_mapOrientation == Qt::Vertical) { | |
349 | QStringList categories; |
|
362 | QStringList categories; | |
350 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
363 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
351 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
364 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
352 | m_internalModel = new BarChartModel(categories, this); |
|
365 | m_internalModel = new BarChartModel(categories, this); | |
353 |
|
366 | |||
354 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
367 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
355 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
368 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
356 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
369 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
357 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
370 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
358 | appendBarSet(barSet); |
|
371 | appendBarSet(barSet); | |
359 | } |
|
372 | } | |
360 | } else { |
|
373 | } else { | |
361 | QStringList categories; |
|
374 | QStringList categories; | |
362 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
375 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
363 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
376 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
364 | m_internalModel = new BarChartModel(categories, this); |
|
377 | m_internalModel = new BarChartModel(categories, this); | |
365 |
|
378 | |||
366 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
379 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
367 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
380 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
368 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
381 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
369 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
382 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
370 | appendBarSet(barSet); |
|
383 | appendBarSet(barSet); | |
371 | } |
|
384 | } | |
372 | } |
|
385 | } | |
373 | } |
|
386 | } | |
374 |
|
387 | |||
375 | /*! |
|
388 | /*! | |
376 | \internal |
|
389 | \internal | |
377 | */ |
|
390 | */ | |
378 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
391 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
379 | { |
|
392 | { | |
380 | Q_UNUSED(bottomRight) |
|
393 | Q_UNUSED(bottomRight) | |
381 |
|
394 | |||
382 | if (m_mapOrientation == Qt::Vertical) |
|
395 | if (m_mapOrientation == Qt::Vertical) | |
383 | { |
|
396 | { | |
384 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
397 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
385 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) |
|
398 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
386 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
399 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
387 | } |
|
400 | } | |
388 | else |
|
401 | else | |
389 | { |
|
402 | { | |
390 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
403 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
391 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) |
|
404 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
392 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
405 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
393 | } |
|
406 | } | |
394 | } |
|
407 | } | |
395 |
|
408 | |||
396 | /*! |
|
409 | /*! | |
397 | \internal |
|
410 | \internal | |
398 | */ |
|
411 | */ | |
399 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) |
|
412 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
400 | { |
|
413 | { | |
401 | if (m_mapOrientation == Qt::Vertical) { |
|
414 | if (m_mapOrientation == Qt::Vertical) { | |
402 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); |
|
415 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
403 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
416 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
404 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
417 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
405 | } |
|
418 | } | |
406 | } else { |
|
419 | } else { | |
407 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); |
|
420 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
408 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
421 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
409 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
422 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
410 | } |
|
423 | } | |
411 | } |
|
424 | } | |
412 | emit restructuredBars(); |
|
425 | emit restructuredBars(); | |
413 | } |
|
426 | } | |
414 |
|
427 | |||
415 | /*! |
|
428 | /*! | |
416 | \internal |
|
429 | \internal | |
417 | */ |
|
430 | */ | |
418 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
431 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
419 | { |
|
432 | { | |
420 | Q_UNUSED(parent) |
|
433 | Q_UNUSED(parent) | |
421 | Q_UNUSED(end) |
|
434 | Q_UNUSED(end) | |
422 |
|
435 | |||
423 | removeCategory(start - m_mapFirst); |
|
436 | removeCategory(start - m_mapFirst); | |
424 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
437 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
425 | { |
|
438 | { | |
426 | barsetAt(i)->removeValue(start - m_mapFirst); |
|
439 | barsetAt(i)->removeValue(start - m_mapFirst); | |
427 | } |
|
440 | } | |
428 | emit restructuredBars(); |
|
441 | emit restructuredBars(); | |
429 | } |
|
442 | } | |
430 |
|
443 | |||
431 | void QBarSeries::barsetChanged() |
|
444 | void QBarSeries::barsetChanged() | |
432 | { |
|
445 | { | |
433 | emit updatedBars(); |
|
446 | emit updatedBars(); | |
434 | } |
|
447 | } | |
435 |
|
448 | |||
436 | QBarCategories QBarSeries::categories() const |
|
449 | QBarCategories QBarSeries::categories() const | |
437 | { |
|
450 | { | |
438 | QBarCategories categories; |
|
451 | QBarCategories categories; | |
439 | int count = m_internalModel->categoryCount(); |
|
452 | int count = m_internalModel->categoryCount(); | |
440 | for (int i=1; i <= count; i++) { |
|
453 | for (int i=1; i <= count; i++) { | |
441 | categories.insert(i, m_internalModel->categoryName(i - 1)); |
|
454 | categories.insert(i, m_internalModel->categoryName(i - 1)); | |
442 | } |
|
455 | } | |
443 | return categories; |
|
456 | return categories; | |
444 | } |
|
457 | } | |
445 |
|
458 | |||
446 | /*! |
|
459 | /*! | |
447 | Sets the visibility of labels in series to \a visible |
|
460 | Sets the visibility of labels in series to \a visible | |
448 | */ |
|
461 | */ | |
449 | void QBarSeries::setLabelsVisible(bool visible) |
|
462 | void QBarSeries::setLabelsVisible(bool visible) | |
450 | { |
|
463 | { | |
451 | foreach (QBarSet* s, barSets()) { |
|
464 | foreach (QBarSet* s, barSets()) { | |
452 | s->setLabelsVisible(visible); |
|
465 | s->setLabelsVisible(visible); | |
453 | } |
|
466 | } | |
454 | } |
|
467 | } | |
455 |
|
468 | |||
456 |
|
469 | |||
457 | #include "moc_qbarseries.cpp" |
|
470 | #include "moc_qbarseries.cpp" | |
458 |
|
471 | |||
459 | QTCOMMERCIALCHART_END_NAMESPACE |
|
472 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,274 +1,283 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include <QDebug> |
|
22 | #include <QDebug> | |
23 | #include <QToolTip> |
|
23 | #include <QToolTip> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \class QBarSet |
|
28 | \class QBarSet | |
29 | \brief part of QtCommercial chart API. |
|
29 | \brief part of QtCommercial chart API. | |
30 |
|
30 | |||
31 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
31 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
32 | First value of set is assumed to belong to first category, second to second category and so on. |
|
32 | First value of set is assumed to belong to first category, second to second category and so on. | |
33 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
33 | If set has fewer values than there are categories, then the missing values are assumed to be | |
34 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
34 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
35 |
|
35 | |||
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
38 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries | |
39 | */ |
|
39 | */ | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \fn void QBarSet::clicked(QString category, Qt::MouseButtons button) |
|
42 | \fn void QBarSet::clicked(QString category, Qt::MouseButtons button) | |
43 | \brief signals that set has been clicked |
|
43 | \brief signals that set has been clicked | |
44 | Parameter \a category describes on which category was clicked |
|
44 | Parameter \a category describes on which category was clicked | |
45 | Parameter \a button mouse button |
|
45 | Parameter \a button mouse button | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | \fn void QBarSet::hoverEnter(QPoint pos) |
|
49 | \fn void QBarSet::hoverEnter(QPoint pos) | |
50 | \brief signals that mouse has entered over the set at position \a pos. |
|
50 | \brief signals that mouse has entered over the set at position \a pos. | |
51 | */ |
|
51 | */ | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | \fn void QBarSet::hoverLeave() |
|
54 | \fn void QBarSet::hoverLeave() | |
55 | \brief signals that mouse has left from the set. |
|
55 | \brief signals that mouse has left from the set. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \fn void QBarSet::setLabelssVisible(bool visible = true) |
|
59 | \fn void QBarSet::setLabelssVisible(bool visible = true) | |
60 | \brief Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. |
|
60 | \brief Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) |
|
64 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) | |
65 | \brief \internal \a pos \a tip |
|
65 | \brief \internal \a pos \a tip | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
70 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
71 | */ |
|
71 | */ | |
72 | QBarSet::QBarSet(QString name, QObject *parent) |
|
72 | QBarSet::QBarSet(QString name, QObject *parent) | |
73 | : QObject(parent) |
|
73 | : QObject(parent) | |
74 | ,m_name(name) |
|
74 | ,m_name(name) | |
75 | ,m_labelsVisible(false) |
|
75 | ,m_labelsVisible(false) | |
76 | { |
|
76 | { | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | Sets new \a name for set. |
|
80 | Sets new \a name for set. | |
81 | */ |
|
81 | */ | |
82 | void QBarSet::setName(QString name) |
|
82 | void QBarSet::setName(QString name) | |
83 | { |
|
83 | { | |
84 | m_name = name; |
|
84 | m_name = name; | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | Returns name of the set. |
|
88 | Returns name of the set. | |
89 | */ |
|
89 | */ | |
90 | QString QBarSet::name() const |
|
90 | QString QBarSet::name() const | |
91 | { |
|
91 | { | |
92 | return m_name; |
|
92 | return m_name; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | Appends new value \a value to the end of set. |
|
96 | Appends new value \a value to the end of set. | |
97 | */ |
|
97 | */ | |
98 | QBarSet& QBarSet::operator << (const qreal &value) |
|
98 | QBarSet& QBarSet::operator << (const qreal &value) | |
99 | { |
|
99 | { | |
100 | m_values.append(value); |
|
100 | m_values.append(value); | |
101 | emit structureChanged(); |
|
101 | emit structureChanged(); | |
102 | return *this; |
|
102 | return *this; | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
|
105 | /*! | |||
|
106 | Inserts new \a value on the \a i position. | |||
|
107 | The value that is currently at this postion is moved to postion i + 1 | |||
|
108 | \sa removeValue() | |||
|
109 | */ | |||
105 | void QBarSet::insertValue(int i, qreal value) |
|
110 | void QBarSet::insertValue(int i, qreal value) | |
106 | { |
|
111 | { | |
107 | m_values.insert(i, value); |
|
112 | m_values.insert(i, value); | |
108 | } |
|
113 | } | |
109 |
|
114 | |||
|
115 | /*! | |||
|
116 | Removes the value specified by \a i | |||
|
117 | \sa insertValue() | |||
|
118 | */ | |||
110 | void QBarSet::removeValue(int i) |
|
119 | void QBarSet::removeValue(int i) | |
111 | { |
|
120 | { | |
112 | m_values.removeAt(i); |
|
121 | m_values.removeAt(i); | |
113 | } |
|
122 | } | |
114 |
|
123 | |||
115 | /*! |
|
124 | /*! | |
116 | Returns count of values in set. |
|
125 | Returns count of values in set. | |
117 | */ |
|
126 | */ | |
118 | int QBarSet::count() const |
|
127 | int QBarSet::count() const | |
119 | { |
|
128 | { | |
120 | return m_values.count(); |
|
129 | return m_values.count(); | |
121 | } |
|
130 | } | |
122 |
|
131 | |||
123 | /*! |
|
132 | /*! | |
124 | Returns value of set indexed by \a index |
|
133 | Returns value of set indexed by \a index | |
125 | */ |
|
134 | */ | |
126 | qreal QBarSet::valueAt(int index) const |
|
135 | qreal QBarSet::valueAt(int index) const | |
127 | { |
|
136 | { | |
128 | return m_values.at(index); |
|
137 | return m_values.at(index); | |
129 | } |
|
138 | } | |
130 |
|
139 | |||
131 | /*! |
|
140 | /*! | |
132 | Sets a new value \a value to set, indexed by \a index |
|
141 | Sets a new value \a value to set, indexed by \a index | |
133 | */ |
|
142 | */ | |
134 | void QBarSet::setValue(int index, qreal value) |
|
143 | void QBarSet::setValue(int index, qreal value) | |
135 | { |
|
144 | { | |
136 | m_values.replace(index,value); |
|
145 | m_values.replace(index,value); | |
137 | emit valueChanged(); |
|
146 | emit valueChanged(); | |
138 | } |
|
147 | } | |
139 |
|
148 | |||
140 | /*! |
|
149 | /*! | |
141 | Returns total sum of all values in barset. |
|
150 | Returns total sum of all values in barset. | |
142 | */ |
|
151 | */ | |
143 | qreal QBarSet::total() const |
|
152 | qreal QBarSet::total() const | |
144 | { |
|
153 | { | |
145 | qreal total(0); |
|
154 | qreal total(0); | |
146 | for (int i=0; i < m_values.count(); i++) { |
|
155 | for (int i=0; i < m_values.count(); i++) { | |
147 | total += m_values.at(i); |
|
156 | total += m_values.at(i); | |
148 | } |
|
157 | } | |
149 | return total; |
|
158 | return total; | |
150 | } |
|
159 | } | |
151 |
|
160 | |||
152 | /*! |
|
161 | /*! | |
153 | Sets pen for set. Bars of this set are drawn using \a pen |
|
162 | Sets pen for set. Bars of this set are drawn using \a pen | |
154 | */ |
|
163 | */ | |
155 | void QBarSet::setPen(const QPen &pen) |
|
164 | void QBarSet::setPen(const QPen &pen) | |
156 | { |
|
165 | { | |
157 | m_pen = pen; |
|
166 | m_pen = pen; | |
158 | emit valueChanged(); |
|
167 | emit valueChanged(); | |
159 | } |
|
168 | } | |
160 |
|
169 | |||
161 | /*! |
|
170 | /*! | |
162 | Returns pen of the set. |
|
171 | Returns pen of the set. | |
163 | */ |
|
172 | */ | |
164 | QPen QBarSet::pen() const |
|
173 | QPen QBarSet::pen() const | |
165 | { |
|
174 | { | |
166 | return m_pen; |
|
175 | return m_pen; | |
167 | } |
|
176 | } | |
168 |
|
177 | |||
169 | /*! |
|
178 | /*! | |
170 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
179 | Sets brush for the set. Bars of this set are drawn using \a brush | |
171 | */ |
|
180 | */ | |
172 | void QBarSet::setBrush(const QBrush &brush) |
|
181 | void QBarSet::setBrush(const QBrush &brush) | |
173 | { |
|
182 | { | |
174 | m_brush = brush; |
|
183 | m_brush = brush; | |
175 | emit valueChanged(); |
|
184 | emit valueChanged(); | |
176 | } |
|
185 | } | |
177 |
|
186 | |||
178 | /*! |
|
187 | /*! | |
179 | Returns brush of the set. |
|
188 | Returns brush of the set. | |
180 | */ |
|
189 | */ | |
181 | QBrush QBarSet::brush() const |
|
190 | QBrush QBarSet::brush() const | |
182 | { |
|
191 | { | |
183 | return m_brush; |
|
192 | return m_brush; | |
184 | } |
|
193 | } | |
185 |
|
194 | |||
186 | /*! |
|
195 | /*! | |
187 | Sets \a pen of the values that are drawn on top of this barset |
|
196 | Sets \a pen of the values that are drawn on top of this barset | |
188 | */ |
|
197 | */ | |
189 | void QBarSet::setLabelPen(const QPen &pen) |
|
198 | void QBarSet::setLabelPen(const QPen &pen) | |
190 | { |
|
199 | { | |
191 | m_labelPen = pen; |
|
200 | m_labelPen = pen; | |
192 | emit valueChanged(); |
|
201 | emit valueChanged(); | |
193 | } |
|
202 | } | |
194 |
|
203 | |||
195 | /*! |
|
204 | /*! | |
196 | Returns pen of the values that are drawn on top of this barset |
|
205 | Returns pen of the values that are drawn on top of this barset | |
197 | */ |
|
206 | */ | |
198 | QPen QBarSet::labelPen() const |
|
207 | QPen QBarSet::labelPen() const | |
199 | { |
|
208 | { | |
200 | return m_labelPen; |
|
209 | return m_labelPen; | |
201 | } |
|
210 | } | |
202 |
|
211 | |||
203 | /*! |
|
212 | /*! | |
204 | Sets \a brush of the values that are drawn on top of this barset |
|
213 | Sets \a brush of the values that are drawn on top of this barset | |
205 | */ |
|
214 | */ | |
206 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
215 | void QBarSet::setLabelBrush(const QBrush &brush) | |
207 | { |
|
216 | { | |
208 | m_labelBrush = brush; |
|
217 | m_labelBrush = brush; | |
209 | emit valueChanged(); |
|
218 | emit valueChanged(); | |
210 | } |
|
219 | } | |
211 |
|
220 | |||
212 | /*! |
|
221 | /*! | |
213 | Returns brush of the values that are drawn on top of this barset |
|
222 | Returns brush of the values that are drawn on top of this barset | |
214 | */ |
|
223 | */ | |
215 | QBrush QBarSet::labelBrush() const |
|
224 | QBrush QBarSet::labelBrush() const | |
216 | { |
|
225 | { | |
217 | return m_labelBrush; |
|
226 | return m_labelBrush; | |
218 | } |
|
227 | } | |
219 |
|
228 | |||
220 | /*! |
|
229 | /*! | |
221 | Sets the \a font for values that are drawn on top of this barset |
|
230 | Sets the \a font for values that are drawn on top of this barset | |
222 | */ |
|
231 | */ | |
223 | void QBarSet::setLabelFont(const QFont &font) |
|
232 | void QBarSet::setLabelFont(const QFont &font) | |
224 | { |
|
233 | { | |
225 | m_labelFont = font; |
|
234 | m_labelFont = font; | |
226 | emit valueChanged(); |
|
235 | emit valueChanged(); | |
227 | } |
|
236 | } | |
228 |
|
237 | |||
229 | /*! |
|
238 | /*! | |
230 | Returns the pen for values that are drawn on top of this set |
|
239 | Returns the pen for values that are drawn on top of this set | |
231 | */ |
|
240 | */ | |
232 | QFont QBarSet::labelFont() const |
|
241 | QFont QBarSet::labelFont() const | |
233 | { |
|
242 | { | |
234 | return m_labelFont; |
|
243 | return m_labelFont; | |
235 | } |
|
244 | } | |
236 |
|
245 | |||
237 | /*! |
|
246 | /*! | |
238 | Sets the visibility of barset values to \a visible |
|
247 | Sets the visibility of barset values to \a visible | |
239 | */ |
|
248 | */ | |
240 | void QBarSet::setLabelsVisible(bool visible) |
|
249 | void QBarSet::setLabelsVisible(bool visible) | |
241 | { |
|
250 | { | |
242 | m_labelsVisible = visible; |
|
251 | m_labelsVisible = visible; | |
243 | emit labelsVisibleChanged(visible); |
|
252 | emit labelsVisibleChanged(visible); | |
244 | } |
|
253 | } | |
245 |
|
254 | |||
246 | /*! |
|
255 | /*! | |
247 | Returns the visibility of values |
|
256 | Returns the visibility of values | |
248 | */ |
|
257 | */ | |
249 | bool QBarSet::labelsVisible() const |
|
258 | bool QBarSet::labelsVisible() const | |
250 | { |
|
259 | { | |
251 | return m_labelsVisible; |
|
260 | return m_labelsVisible; | |
252 | } |
|
261 | } | |
253 |
|
262 | |||
254 | /*! |
|
263 | /*! | |
255 | \internal \a pos |
|
264 | \internal \a pos | |
256 | */ |
|
265 | */ | |
257 | void QBarSet::barHoverEnterEvent(QPoint pos) |
|
266 | void QBarSet::barHoverEnterEvent(QPoint pos) | |
258 | { |
|
267 | { | |
259 | emit showToolTip(pos, m_name); |
|
268 | emit showToolTip(pos, m_name); | |
260 | emit hoverEnter(pos); |
|
269 | emit hoverEnter(pos); | |
261 | } |
|
270 | } | |
262 |
|
271 | |||
263 | /*! |
|
272 | /*! | |
264 | \internal |
|
273 | \internal | |
265 | */ |
|
274 | */ | |
266 | void QBarSet::barHoverLeaveEvent() |
|
275 | void QBarSet::barHoverLeaveEvent() | |
267 | { |
|
276 | { | |
268 | // Emit signal to user of charts |
|
277 | // Emit signal to user of charts | |
269 | emit hoverLeave(); |
|
278 | emit hoverLeave(); | |
270 | } |
|
279 | } | |
271 |
|
280 | |||
272 | #include "moc_qbarset.cpp" |
|
281 | #include "moc_qbarset.cpp" | |
273 |
|
282 | |||
274 | QTCOMMERCIALCHART_END_NAMESPACE |
|
283 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now