@@ -1,112 +1,112 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "tablewidget.h" |
|
22 | 22 | #include "customtablemodel.h" |
|
23 | 23 | #include <QGridLayout> |
|
24 | 24 | #include <QTableView> |
|
25 | 25 | #include <QChart> |
|
26 | 26 | #include <QChartView> |
|
27 | 27 | #include <QLineSeries> |
|
28 | 28 | #include <QVXYModelMapper> |
|
29 |
#include <Q |
|
|
29 | #include <QBarSeries> | |
|
30 | 30 | #include <QBarSet> |
|
31 | 31 | #include <QVBarModelMapper> |
|
32 | 32 | #include <QHeaderView> |
|
33 | 33 | #include <QCategoriesAxis> |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | TableWidget::TableWidget(QWidget *parent) |
|
38 | 38 | : QWidget(parent) |
|
39 | 39 | { |
|
40 | 40 | // create simple model for storing data |
|
41 | 41 | // user's table data model |
|
42 | 42 | //! [1] |
|
43 | 43 | CustomTableModel *model = new CustomTableModel; |
|
44 | 44 | //! [1] |
|
45 | 45 | |
|
46 | 46 | //! [2] |
|
47 | 47 | // create table view and add model to it |
|
48 | 48 | QTableView *tableView = new QTableView; |
|
49 | 49 | tableView->setModel(model); |
|
50 | 50 | tableView->setMinimumWidth(300); |
|
51 | 51 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
52 | 52 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
53 | 53 | //! [2] |
|
54 | 54 | |
|
55 | 55 | //! [3] |
|
56 | 56 | QChart *chart = new QChart; |
|
57 | 57 | chart->setAnimationOptions(QChart::AllAnimations); |
|
58 | 58 | //! [3] |
|
59 | 59 | |
|
60 | 60 | // series 1 |
|
61 | 61 | //! [4] |
|
62 |
Q |
|
|
62 | QBarSeries *series = new QBarSeries; | |
|
63 | 63 | |
|
64 | 64 | int first = 3; |
|
65 | 65 | int count = 5; |
|
66 | 66 | QVBarModelMapper *mapper = new QVBarModelMapper(this); |
|
67 | 67 | mapper->setFirstBarSetColumn(1); |
|
68 | 68 | mapper->setLastBarSetColumn(4); |
|
69 | 69 | mapper->setFirstRow(first); |
|
70 | 70 | mapper->setRowCount(count); |
|
71 | 71 | mapper->setSeries(series); |
|
72 | 72 | mapper->setModel(model); |
|
73 | 73 | chart->addSeries(series); |
|
74 | 74 | //! [4] |
|
75 | 75 | |
|
76 | 76 | //! [5] |
|
77 | 77 | // for storing color hex from the series |
|
78 | 78 | QString seriesColorHex = "#000000"; |
|
79 | 79 | |
|
80 | 80 | // get the color of the series and use it for showing the mapped area |
|
81 | 81 | QList<QBarSet*> barsets = series->barSets(); |
|
82 | 82 | for (int i = 0; i < barsets.count(); i++) { |
|
83 | 83 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
84 | 84 | model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count())); |
|
85 | 85 | } |
|
86 | 86 | //! [5] |
|
87 | 87 | |
|
88 | 88 | //! [6] |
|
89 | 89 | QStringList categories; |
|
90 | 90 | categories << "April" << "May" << "June" << "July" << "August"; |
|
91 | 91 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
92 | 92 | axis->append(categories); |
|
93 | 93 | chart->createDefaultAxes(); |
|
94 | 94 | chart->setAxisX(axis, series); |
|
95 | 95 | //! [6] |
|
96 | 96 | |
|
97 | 97 | //! [7] |
|
98 | 98 | QChartView *chartView = new QChartView(chart); |
|
99 | 99 | chartView->setRenderHint(QPainter::Antialiasing); |
|
100 | 100 | chartView->setMinimumSize(640, 480); |
|
101 | 101 | //! [7] |
|
102 | 102 | |
|
103 | 103 | //! [8] |
|
104 | 104 | // create main layout |
|
105 | 105 | QGridLayout* mainLayout = new QGridLayout; |
|
106 | 106 | mainLayout->addWidget(tableView, 1, 0); |
|
107 | 107 | mainLayout->addWidget(chartView, 1, 1); |
|
108 | 108 | mainLayout->setColumnStretch(1, 1); |
|
109 | 109 | mainLayout->setColumnStretch(0, 0); |
|
110 | 110 | setLayout(mainLayout); |
|
111 | 111 | //! [8] |
|
112 | 112 | } |
@@ -1,92 +1,92 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QApplication> |
|
22 | 22 | #include <QMainWindow> |
|
23 | 23 | #include <QChartView> |
|
24 |
#include <Q |
|
|
24 | #include <QBarSeries> | |
|
25 | 25 | #include <QBarSet> |
|
26 | 26 | #include <QLegend> |
|
27 | 27 | #include <QCategoriesAxis> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | int main(int argc, char *argv[]) |
|
32 | 32 | { |
|
33 | 33 | QApplication a(argc, argv); |
|
34 | 34 | |
|
35 | 35 | //![1] |
|
36 | 36 | QBarSet *set0 = new QBarSet("Jane"); |
|
37 | 37 | QBarSet *set1 = new QBarSet("John"); |
|
38 | 38 | QBarSet *set2 = new QBarSet("Axel"); |
|
39 | 39 | QBarSet *set3 = new QBarSet("Mary"); |
|
40 | 40 | QBarSet *set4 = new QBarSet("Samantha"); |
|
41 | 41 | |
|
42 | 42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
43 | 43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
44 | 44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
45 | 45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
46 | 46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
47 | 47 | //![1] |
|
48 | 48 | |
|
49 | 49 | //![2] |
|
50 |
Q |
|
|
50 | QBarSeries* series = new QBarSeries(); | |
|
51 | 51 | series->append(set0); |
|
52 | 52 | series->append(set1); |
|
53 | 53 | series->append(set2); |
|
54 | 54 | series->append(set3); |
|
55 | 55 | series->append(set4); |
|
56 | 56 | |
|
57 | 57 | //![2] |
|
58 | 58 | |
|
59 | 59 | //![3] |
|
60 | 60 | QChart* chart = new QChart(); |
|
61 | 61 | chart->addSeries(series); |
|
62 |
chart->setTitle("Simple |
|
|
62 | chart->setTitle("Simple barchart example"); | |
|
63 | 63 | chart->createDefaultAxes(); |
|
64 | 64 | //![3] |
|
65 | 65 | |
|
66 | 66 | //![4] |
|
67 | 67 | QStringList categories; |
|
68 | 68 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
69 | 69 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
70 | 70 | axis->append(categories); |
|
71 | 71 | chart->setAxisX(axis,series); |
|
72 | 72 | //![4] |
|
73 | 73 | |
|
74 | 74 | //![5] |
|
75 | 75 | chart->legend()->setVisible(true); |
|
76 | 76 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
77 | 77 | //![5] |
|
78 | 78 | |
|
79 | 79 | //![6] |
|
80 | 80 | QChartView* chartView = new QChartView(chart); |
|
81 | 81 | chartView->setRenderHint(QPainter::Antialiasing); |
|
82 | 82 | //![6] |
|
83 | 83 | |
|
84 | 84 | //![7] |
|
85 | 85 | QMainWindow window; |
|
86 | 86 | window.setCentralWidget(chartView); |
|
87 | 87 | window.resize(400, 300); |
|
88 | 88 | window.show(); |
|
89 | 89 | //![7] |
|
90 | 90 | |
|
91 | 91 | return a.exec(); |
|
92 | 92 | } |
@@ -1,262 +1,262 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "mainwidget.h" |
|
22 | 22 | #include <QChart> |
|
23 | 23 | #include <QChartView> |
|
24 | 24 | #include <QPushButton> |
|
25 | 25 | #include <QLabel> |
|
26 | 26 | #include <QDebug> |
|
27 | 27 | #include <QBarSet> |
|
28 |
#include <Q |
|
|
28 | #include <QBarSeries> | |
|
29 | 29 | #include <QLegend> |
|
30 | 30 | #include <QFormLayout> |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | MainWidget::MainWidget(QWidget *parent) : |
|
35 | 35 | QWidget(parent) |
|
36 | 36 | { |
|
37 | 37 | // Create buttons for ui |
|
38 | 38 | m_buttonLayout = new QGridLayout(); |
|
39 | 39 | QPushButton *detachLegendButton = new QPushButton("detach legend"); |
|
40 | 40 | connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(detachLegend())); |
|
41 | 41 | m_buttonLayout->addWidget(detachLegendButton, 0, 0); |
|
42 | 42 | QPushButton *attachLegendButton = new QPushButton("attach legend"); |
|
43 | 43 | connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend())); |
|
44 | 44 | m_buttonLayout->addWidget(attachLegendButton, 1, 0); |
|
45 | 45 | |
|
46 | 46 | QPushButton *addSetButton = new QPushButton("add barset"); |
|
47 | 47 | connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset())); |
|
48 | 48 | m_buttonLayout->addWidget(addSetButton, 2, 0); |
|
49 | 49 | QPushButton *removeBarsetButton = new QPushButton("remove barset"); |
|
50 | 50 | connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset())); |
|
51 | 51 | m_buttonLayout->addWidget(removeBarsetButton, 3, 0); |
|
52 | 52 | |
|
53 | 53 | QPushButton *leftButton = new QPushButton("Align legend left"); |
|
54 | 54 | connect(leftButton, SIGNAL(clicked()), this, SLOT(setLegendLeft())); |
|
55 | 55 | m_buttonLayout->addWidget(leftButton, 4, 0); |
|
56 | 56 | |
|
57 | 57 | QPushButton *rightButton = new QPushButton("Align legend right"); |
|
58 | 58 | connect(rightButton, SIGNAL(clicked()), this, SLOT(setLegendRight())); |
|
59 | 59 | m_buttonLayout->addWidget(rightButton, 5, 0); |
|
60 | 60 | |
|
61 | 61 | QPushButton *topButton = new QPushButton("Align legend top"); |
|
62 | 62 | connect(topButton, SIGNAL(clicked()), this, SLOT(setLegendTop())); |
|
63 | 63 | m_buttonLayout->addWidget(topButton, 6, 0); |
|
64 | 64 | |
|
65 | 65 | QPushButton *bottomButton = new QPushButton("Align legend bottom"); |
|
66 | 66 | connect(bottomButton, SIGNAL(clicked()), this, SLOT(setLegendBottom())); |
|
67 | 67 | m_buttonLayout->addWidget(bottomButton, 7, 0); |
|
68 | 68 | |
|
69 | 69 | QPushButton *boldButton = new QPushButton("Toggle bold"); |
|
70 | 70 | connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); |
|
71 | 71 | m_buttonLayout->addWidget(boldButton, 8, 0); |
|
72 | 72 | |
|
73 | 73 | QPushButton *italicButton = new QPushButton("Toggle italic"); |
|
74 | 74 | connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic())); |
|
75 | 75 | m_buttonLayout->addWidget(italicButton, 9, 0); |
|
76 | 76 | |
|
77 | 77 | m_legendPosX = new QDoubleSpinBox(); |
|
78 | 78 | m_legendPosY = new QDoubleSpinBox(); |
|
79 | 79 | m_legendWidth = new QDoubleSpinBox(); |
|
80 | 80 | m_legendHeight = new QDoubleSpinBox(); |
|
81 | 81 | |
|
82 | 82 | connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
83 | 83 | connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
84 | 84 | connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
85 | 85 | connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
86 | 86 | |
|
87 | 87 | QFormLayout* legendLayout = new QFormLayout(); |
|
88 | 88 | legendLayout->addRow("Horizontal position", m_legendPosX); |
|
89 | 89 | legendLayout->addRow("Vertical position", m_legendPosY); |
|
90 | 90 | legendLayout->addRow("Width", m_legendWidth); |
|
91 | 91 | legendLayout->addRow("Height", m_legendHeight); |
|
92 | 92 | m_legendSettings = new QGroupBox("Detached legend"); |
|
93 | 93 | m_legendSettings->setLayout(legendLayout); |
|
94 | 94 | m_buttonLayout->addWidget(m_legendSettings); |
|
95 | 95 | m_legendSettings->setVisible(false); |
|
96 | 96 | |
|
97 | 97 | // Create chart view with the chart |
|
98 | 98 | m_chart = new QChart(); |
|
99 | 99 | m_chartView = new QChartView(m_chart, this); |
|
100 | 100 | |
|
101 | 101 | // Create spinbox to modify font size |
|
102 | 102 | m_fontSize = new QDoubleSpinBox(); |
|
103 | 103 | m_fontSize->setValue(m_chart->legend()->font().pointSizeF()); |
|
104 | 104 | connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged())); |
|
105 | 105 | |
|
106 | 106 | QFormLayout* fontLayout = new QFormLayout(); |
|
107 | 107 | fontLayout->addRow("Legend font size", m_fontSize); |
|
108 | 108 | |
|
109 | 109 | // Create layout for grid and detached legend |
|
110 | 110 | m_mainLayout = new QGridLayout(); |
|
111 | 111 | m_mainLayout->addLayout(m_buttonLayout, 0, 0); |
|
112 | 112 | m_mainLayout->addLayout(fontLayout,1,0); |
|
113 | 113 | m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
114 | 114 | setLayout(m_mainLayout); |
|
115 | 115 | |
|
116 | 116 | createSeries(); |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | void MainWidget::createSeries() |
|
120 | 120 | { |
|
121 |
m_series = new Q |
|
|
121 | m_series = new QBarSeries(); | |
|
122 | 122 | addBarset(); |
|
123 | 123 | addBarset(); |
|
124 | 124 | addBarset(); |
|
125 | 125 | addBarset(); |
|
126 | 126 | |
|
127 | 127 | m_chart->addSeries(m_series); |
|
128 | 128 | m_chart->setTitle("Legend detach example"); |
|
129 | 129 | m_chart->createDefaultAxes(); |
|
130 | 130 | //![1] |
|
131 | 131 | m_chart->legend()->setVisible(true); |
|
132 | 132 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
133 | 133 | //![1] |
|
134 | 134 | |
|
135 | 135 | //TODO:m_chart->axisY()->setNiceNumbersEnabled(true); |
|
136 | 136 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 139 | void MainWidget::showLegendSpinbox() |
|
140 | 140 | { |
|
141 | 141 | m_legendSettings->setVisible(true); |
|
142 | 142 | QRectF chartViewRect = m_chartView->rect(); |
|
143 | 143 | |
|
144 | 144 | m_legendPosX->setMinimum(0); |
|
145 | 145 | m_legendPosX->setMaximum(chartViewRect.width()); |
|
146 | 146 | m_legendPosX->setValue(150); |
|
147 | 147 | |
|
148 | 148 | m_legendPosY->setMinimum(0); |
|
149 | 149 | m_legendPosY->setMaximum(chartViewRect.height()); |
|
150 | 150 | m_legendPosY->setValue(150); |
|
151 | 151 | |
|
152 | 152 | m_legendWidth->setMinimum(0); |
|
153 | 153 | m_legendWidth->setMaximum(chartViewRect.width()); |
|
154 | 154 | m_legendWidth->setValue(150); |
|
155 | 155 | |
|
156 | 156 | m_legendHeight->setMinimum(0); |
|
157 | 157 | m_legendHeight->setMaximum(chartViewRect.height()); |
|
158 | 158 | m_legendHeight->setValue(75); |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | void MainWidget::hideLegendSpinbox() |
|
162 | 162 | { |
|
163 | 163 | m_legendSettings->setVisible(false); |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | |
|
167 | 167 | void MainWidget::detachLegend() |
|
168 | 168 | { |
|
169 | 169 | //![2] |
|
170 | 170 | QLegend *legend = m_chart->legend(); |
|
171 | 171 | legend->detachFromChart(); |
|
172 | 172 | |
|
173 | 173 | m_chart->legend()->setBackgroundVisible(true); |
|
174 | 174 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); |
|
175 | 175 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); |
|
176 | 176 | //![2] |
|
177 | 177 | |
|
178 | 178 | showLegendSpinbox(); |
|
179 | 179 | updateLegendLayout(); |
|
180 | 180 | update(); |
|
181 | 181 | } |
|
182 | 182 | |
|
183 | 183 | |
|
184 | 184 | void MainWidget::attachLegend() |
|
185 | 185 | { |
|
186 | 186 | //![3] |
|
187 | 187 | QLegend *legend = m_chart->legend(); |
|
188 | 188 | legend->attachToChart(); |
|
189 | 189 | m_chart->legend()->setBackgroundVisible(false); |
|
190 | 190 | //![3] |
|
191 | 191 | |
|
192 | 192 | hideLegendSpinbox(); |
|
193 | 193 | update(); |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | void MainWidget::addBarset() |
|
197 | 197 | { |
|
198 | 198 | QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series->count())); |
|
199 | 199 | qreal delta = m_series->count() * 0.1; |
|
200 | 200 | *barSet << 1 + delta << 2 + delta << 3 + delta << 4 + delta; |
|
201 | 201 | m_series->append(barSet); |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | void MainWidget::removeBarset() |
|
205 | 205 | { |
|
206 | 206 | QList<QBarSet*> sets = m_series->barSets(); |
|
207 | 207 | if (sets.count() > 0) { |
|
208 | 208 | m_series->remove(sets.at(sets.count()-1)); |
|
209 | 209 | } |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | void MainWidget::setLegendLeft() |
|
213 | 213 | { |
|
214 | 214 | m_chart->legend()->setAlignment(Qt::AlignLeft); |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | void MainWidget::setLegendRight() |
|
218 | 218 | { |
|
219 | 219 | m_chart->legend()->setAlignment(Qt::AlignRight); |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | void MainWidget::setLegendTop() |
|
223 | 223 | { |
|
224 | 224 | m_chart->legend()->setAlignment(Qt::AlignTop); |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | void MainWidget::setLegendBottom() |
|
228 | 228 | { |
|
229 | 229 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
230 | 230 | } |
|
231 | 231 | |
|
232 | 232 | void MainWidget::toggleBold() |
|
233 | 233 | { |
|
234 | 234 | QFont font = m_chart->legend()->font(); |
|
235 | 235 | font.setBold(!font.bold()); |
|
236 | 236 | m_chart->legend()->setFont(font); |
|
237 | 237 | } |
|
238 | 238 | |
|
239 | 239 | void MainWidget::toggleItalic() |
|
240 | 240 | { |
|
241 | 241 | QFont font = m_chart->legend()->font(); |
|
242 | 242 | font.setItalic(!font.italic()); |
|
243 | 243 | m_chart->legend()->setFont(font); |
|
244 | 244 | } |
|
245 | 245 | |
|
246 | 246 | void MainWidget::fontSizeChanged() |
|
247 | 247 | { |
|
248 | 248 | QFont font = m_chart->legend()->font(); |
|
249 | 249 | font.setPointSizeF(m_fontSize->value()); |
|
250 | 250 | m_chart->legend()->setFont(font); |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | void MainWidget::updateLegendLayout() |
|
254 | 254 | { |
|
255 | 255 | //![4] |
|
256 | 256 | m_chart->legend()->setGeometry(QRectF(m_legendPosX->value() |
|
257 | 257 | ,m_legendPosY->value() |
|
258 | 258 | ,m_legendWidth->value() |
|
259 | 259 | ,m_legendHeight->value())); |
|
260 | 260 | m_chart->legend()->update(); |
|
261 | 261 | //![4] |
|
262 | 262 | } |
@@ -1,86 +1,86 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef MAINWIDGET_H |
|
22 | 22 | #define MAINWIDGET_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qchart.h" |
|
26 | 26 | #include "qchartview.h" |
|
27 | 27 | #include <QWidget> |
|
28 | 28 | #include <QGraphicsWidget> |
|
29 | 29 | #include <QGridLayout> |
|
30 | 30 | #include <QGraphicsGridLayout> |
|
31 | 31 | #include <QDoubleSpinBox> |
|
32 | 32 | #include <QGroupBox> |
|
33 |
#include <Q |
|
|
33 | #include <QBarSeries> | |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class MainWidget : public QWidget |
|
38 | 38 | { |
|
39 | 39 | Q_OBJECT |
|
40 | 40 | public: |
|
41 | 41 | explicit MainWidget(QWidget *parent = 0); |
|
42 | 42 | void createSeries(); |
|
43 | 43 | void showLegendSpinbox(); |
|
44 | 44 | void hideLegendSpinbox(); |
|
45 | 45 | |
|
46 | 46 | signals: |
|
47 | 47 | |
|
48 | 48 | public slots: |
|
49 | 49 | void detachLegend(); |
|
50 | 50 | void attachLegend(); |
|
51 | 51 | void addBarset(); |
|
52 | 52 | void removeBarset(); |
|
53 | 53 | |
|
54 | 54 | void setLegendLeft(); |
|
55 | 55 | void setLegendRight(); |
|
56 | 56 | void setLegendTop(); |
|
57 | 57 | void setLegendBottom(); |
|
58 | 58 | |
|
59 | 59 | void toggleBold(); |
|
60 | 60 | void toggleItalic(); |
|
61 | 61 | void fontSizeChanged(); |
|
62 | 62 | |
|
63 | 63 | void updateLegendLayout(); |
|
64 | 64 | |
|
65 | 65 | |
|
66 | 66 | private: |
|
67 | 67 | |
|
68 | 68 | QChart *m_chart; |
|
69 |
Q |
|
|
69 | QBarSeries *m_series; | |
|
70 | 70 | |
|
71 | 71 | QChartView *m_chartView; |
|
72 | 72 | QGridLayout *m_mainLayout; |
|
73 | 73 | QGridLayout *m_buttonLayout; |
|
74 | 74 | QGridLayout *m_fontLayout; |
|
75 | 75 | |
|
76 | 76 | QDoubleSpinBox *m_fontSize; |
|
77 | 77 | |
|
78 | 78 | // For detached layout |
|
79 | 79 | QGroupBox* m_legendSettings; |
|
80 | 80 | QDoubleSpinBox *m_legendPosX; |
|
81 | 81 | QDoubleSpinBox *m_legendPosY; |
|
82 | 82 | QDoubleSpinBox *m_legendWidth; |
|
83 | 83 | QDoubleSpinBox *m_legendHeight; |
|
84 | 84 | }; |
|
85 | 85 | |
|
86 | 86 | #endif // MAINWIDGET_H |
@@ -1,393 +1,393 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativebarseries.h" |
|
22 | 22 | #include "declarativechart.h" |
|
23 | 23 | #include <QBarSet> |
|
24 | 24 | #include <QVBarModelMapper> |
|
25 | 25 | #include <QHBarModelMapper> |
|
26 | 26 | #include <QAbstractAxis> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : |
|
31 | 31 | QBarSet("", parent) |
|
32 | 32 | { |
|
33 | 33 | connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int))); |
|
34 | 34 | connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int))); |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | void DeclarativeBarSet::handleCountChanged(int index, int count) |
|
38 | 38 | { |
|
39 | 39 | Q_UNUSED(index) |
|
40 | 40 | Q_UNUSED(count) |
|
41 | 41 | emit countChanged(QBarSet::count()); |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | QVariantList DeclarativeBarSet::values() |
|
45 | 45 | { |
|
46 | 46 | QVariantList values; |
|
47 | 47 | for (int i(0); i < count(); i++) |
|
48 | 48 | values.append(QVariant(QBarSet::at(i))); |
|
49 | 49 | return values; |
|
50 | 50 | } |
|
51 | 51 | |
|
52 | 52 | void DeclarativeBarSet::setValues(QVariantList values) |
|
53 | 53 | { |
|
54 | 54 | while (count()) |
|
55 | 55 | remove(count() - 1); |
|
56 | 56 | |
|
57 | 57 | for (int i(0); i < values.count(); i++) { |
|
58 | 58 | if (values.at(i).canConvert(QVariant::Double)) |
|
59 | 59 | QBarSet::append(values[i].toDouble()); |
|
60 | 60 | } |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | DeclarativeAbstractBarSeries::DeclarativeAbstractBarSeries(QDeclarativeItem *parent) : |
|
64 | 64 | QAbstractBarSeries(parent) |
|
65 | 65 | { |
|
66 | 66 | connect(this, SIGNAL(barsetsAdded(QList<QBarSet*>)), this, SLOT(handleAdded(QList<QBarSet*>))); |
|
67 | 67 | connect(this, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleRemoved(QList<QBarSet*>))); |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | void DeclarativeAbstractBarSeries::handleAdded(QList<QBarSet* > barsets) |
|
71 | 71 | { |
|
72 | 72 | foreach(QBarSet *b, barsets) { |
|
73 | 73 | DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b); |
|
74 | 74 | emit added(barset); |
|
75 | 75 | } |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | void DeclarativeAbstractBarSeries::handleRemoved(QList<QBarSet* > barsets) |
|
79 | 79 | { |
|
80 | 80 | foreach(QBarSet *b, barsets) { |
|
81 | 81 | DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b); |
|
82 | 82 | emit removed(barset); |
|
83 | 83 | } |
|
84 | 84 | } |
|
85 | 85 | |
|
86 | 86 | void DeclarativeAbstractBarSeries::classBegin() |
|
87 | 87 | { |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | void DeclarativeAbstractBarSeries::componentComplete() |
|
91 | 91 | { |
|
92 | 92 | foreach(QObject *child, children()) { |
|
93 | 93 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
94 | 94 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
95 | 95 | } else if (qobject_cast<QVBarModelMapper *>(child)) { |
|
96 | 96 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
97 | 97 | mapper->setSeries(this); |
|
98 | 98 | } else if (qobject_cast<QHBarModelMapper *>(child)) { |
|
99 | 99 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
100 | 100 | mapper->setSeries(this); |
|
101 | 101 | } |
|
102 | 102 | } |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | void DeclarativeAbstractBarSeries::setAxisX(QAbstractAxis *axis) |
|
106 | 106 | { |
|
107 | 107 | chart()->setAxisX(axis, this); |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | QAbstractAxis *DeclarativeAbstractBarSeries::axisX() |
|
111 | 111 | { |
|
112 | 112 | return chart()->axisX(this); |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | void DeclarativeAbstractBarSeries::setAxisY(QAbstractAxis *axis) |
|
116 | 116 | { |
|
117 | 117 | chart()->setAxisY(axis, this); |
|
118 | 118 | } |
|
119 | 119 | |
|
120 | 120 | QAbstractAxis *DeclarativeAbstractBarSeries::axisY() |
|
121 | 121 | { |
|
122 | 122 | return chart()->axisY(this); |
|
123 | 123 | } |
|
124 | 124 | |
|
125 | 125 | QDeclarativeListProperty<QObject> DeclarativeAbstractBarSeries::seriesChildren() |
|
126 | 126 | { |
|
127 | 127 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); |
|
128 | 128 | } |
|
129 | 129 | |
|
130 | 130 | void DeclarativeAbstractBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
131 | 131 | { |
|
132 | 132 | // Empty implementation; the children are parsed in componentComplete instead |
|
133 | 133 | Q_UNUSED(list); |
|
134 | 134 | Q_UNUSED(element); |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | DeclarativeBarSet *DeclarativeAbstractBarSeries::at(int index) |
|
138 | 138 | { |
|
139 | 139 | QList<QBarSet*> setList = barSets(); |
|
140 | 140 | if (index >= 0 && index < setList.count()) |
|
141 | 141 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
142 | 142 | |
|
143 | 143 | return 0; |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | DeclarativeBarSet *DeclarativeAbstractBarSeries::insert(int index, QString label, QVariantList values) |
|
147 | 147 | { |
|
148 | 148 | int insertIndex = index; |
|
149 | 149 | if (insertIndex < 0) |
|
150 | 150 | insertIndex = 0; |
|
151 | 151 | else if (insertIndex > count()) |
|
152 | 152 | insertIndex = count(); |
|
153 | 153 | |
|
154 | 154 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
155 | 155 | barset->setLabel(label); |
|
156 | 156 | barset->setValues(values); |
|
157 | 157 | if (QAbstractBarSeries::insert(insertIndex, barset)) |
|
158 | 158 | return barset; |
|
159 | 159 | delete barset; |
|
160 | 160 | return 0; |
|
161 | 161 | } |
|
162 | 162 | |
|
163 |
Declarative |
|
|
164 |
Q |
|
|
163 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | |
|
164 | QBarSeries(parent) | |
|
165 | 165 | { |
|
166 | 166 | } |
|
167 | 167 | |
|
168 |
void Declarative |
|
|
168 | void DeclarativeBarSeries::classBegin() | |
|
169 | 169 | { |
|
170 | 170 | } |
|
171 | 171 | |
|
172 |
void Declarative |
|
|
172 | void DeclarativeBarSeries::componentComplete() | |
|
173 | 173 | { |
|
174 | 174 | foreach(QObject *child, children()) { |
|
175 | 175 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
176 | 176 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
177 | 177 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
178 | 178 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
179 | 179 | mapper->setSeries(this); |
|
180 | 180 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
181 | 181 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
182 | 182 | mapper->setSeries(this); |
|
183 | 183 | } |
|
184 | 184 | } |
|
185 | 185 | } |
|
186 | 186 | |
|
187 |
void Declarative |
|
|
187 | void DeclarativeBarSeries::setAxisX(QAbstractAxis *axis) | |
|
188 | 188 | { |
|
189 | 189 | chart()->setAxisX(axis, this); |
|
190 | 190 | } |
|
191 | 191 | |
|
192 |
QAbstractAxis *Declarative |
|
|
192 | QAbstractAxis *DeclarativeBarSeries::axisX() | |
|
193 | 193 | { |
|
194 | 194 | return chart()->axisX(this); |
|
195 | 195 | } |
|
196 | 196 | |
|
197 |
void Declarative |
|
|
197 | void DeclarativeBarSeries::setAxisY(QAbstractAxis *axis) | |
|
198 | 198 | { |
|
199 | 199 | chart()->setAxisY(axis, this); |
|
200 | 200 | } |
|
201 | 201 | |
|
202 |
QAbstractAxis *Declarative |
|
|
202 | QAbstractAxis *DeclarativeBarSeries::axisY() | |
|
203 | 203 | { |
|
204 | 204 | return chart()->axisY(this); |
|
205 | 205 | } |
|
206 | 206 | |
|
207 |
QDeclarativeListProperty<QObject> Declarative |
|
|
207 | QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren() | |
|
208 | 208 | { |
|
209 | 209 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); |
|
210 | 210 | } |
|
211 | 211 | |
|
212 |
void Declarative |
|
|
212 | void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
|
213 | 213 | { |
|
214 | 214 | // Empty implementation; the children are parsed in componentComplete instead |
|
215 | 215 | Q_UNUSED(list); |
|
216 | 216 | Q_UNUSED(element); |
|
217 | 217 | } |
|
218 | 218 | |
|
219 |
DeclarativeBarSet *Declarative |
|
|
219 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) | |
|
220 | 220 | { |
|
221 | 221 | QList<QBarSet*> setList = barSets(); |
|
222 | 222 | if (index >= 0 && index < setList.count()) |
|
223 | 223 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
224 | 224 | |
|
225 | 225 | return 0; |
|
226 | 226 | } |
|
227 | 227 | |
|
228 |
DeclarativeBarSet *Declarative |
|
|
228 | DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values) | |
|
229 | 229 | { |
|
230 | 230 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
231 | 231 | barset->setLabel(label); |
|
232 | 232 | barset->setValues(values); |
|
233 |
if (Q |
|
|
233 | if (QBarSeries::insert(index, barset)) | |
|
234 | 234 | return barset; |
|
235 | 235 | delete barset; |
|
236 | 236 | return 0; |
|
237 | 237 | } |
|
238 | 238 | |
|
239 | 239 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : |
|
240 | 240 | QStackedBarSeries(parent) |
|
241 | 241 | { |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | void DeclarativeStackedBarSeries::classBegin() |
|
245 | 245 | { |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | void DeclarativeStackedBarSeries::componentComplete() |
|
249 | 249 | { |
|
250 | 250 | foreach(QObject *child, children()) { |
|
251 | 251 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
252 | 252 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
253 | 253 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
254 | 254 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
255 | 255 | mapper->setSeries(this); |
|
256 | 256 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
257 | 257 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
258 | 258 | mapper->setSeries(this); |
|
259 | 259 | } |
|
260 | 260 | } |
|
261 | 261 | } |
|
262 | 262 | |
|
263 | 263 | void DeclarativeStackedBarSeries::setAxisX(QAbstractAxis *axis) |
|
264 | 264 | { |
|
265 | 265 | chart()->setAxisX(axis, this); |
|
266 | 266 | } |
|
267 | 267 | |
|
268 | 268 | QAbstractAxis *DeclarativeStackedBarSeries::axisX() |
|
269 | 269 | { |
|
270 | 270 | return chart()->axisX(this); |
|
271 | 271 | } |
|
272 | 272 | |
|
273 | 273 | void DeclarativeStackedBarSeries::setAxisY(QAbstractAxis *axis) |
|
274 | 274 | { |
|
275 | 275 | chart()->setAxisY(axis, this); |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | QAbstractAxis *DeclarativeStackedBarSeries::axisY() |
|
279 | 279 | { |
|
280 | 280 | return chart()->axisY(this); |
|
281 | 281 | } |
|
282 | 282 | |
|
283 | 283 | QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() |
|
284 | 284 | { |
|
285 | 285 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); |
|
286 | 286 | } |
|
287 | 287 | |
|
288 | 288 | void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
289 | 289 | { |
|
290 | 290 | // Empty implementation; the children are parsed in componentComplete instead |
|
291 | 291 | Q_UNUSED(list); |
|
292 | 292 | Q_UNUSED(element); |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) |
|
296 | 296 | { |
|
297 | 297 | QList<QBarSet*> setList = barSets(); |
|
298 | 298 | if (index >= 0 && index < setList.count()) |
|
299 | 299 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
300 | 300 | |
|
301 | 301 | return 0; |
|
302 | 302 | } |
|
303 | 303 | |
|
304 | 304 | DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values) |
|
305 | 305 | { |
|
306 | 306 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
307 | 307 | barset->setLabel(label); |
|
308 | 308 | barset->setValues(values); |
|
309 | 309 | if (QStackedBarSeries::insert(index, barset)) |
|
310 | 310 | return barset; |
|
311 | 311 | delete barset; |
|
312 | 312 | return 0; |
|
313 | 313 | } |
|
314 | 314 | |
|
315 | 315 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : |
|
316 | 316 | QPercentBarSeries(parent) |
|
317 | 317 | { |
|
318 | 318 | } |
|
319 | 319 | |
|
320 | 320 | void DeclarativePercentBarSeries::classBegin() |
|
321 | 321 | { |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | void DeclarativePercentBarSeries::componentComplete() |
|
325 | 325 | { |
|
326 | 326 | foreach(QObject *child, children()) { |
|
327 | 327 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
328 | 328 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
329 | 329 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
330 | 330 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
331 | 331 | mapper->setSeries(this); |
|
332 | 332 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
333 | 333 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
334 | 334 | mapper->setSeries(this); |
|
335 | 335 | } |
|
336 | 336 | } |
|
337 | 337 | } |
|
338 | 338 | |
|
339 | 339 | void DeclarativePercentBarSeries::setAxisX(QAbstractAxis *axis) |
|
340 | 340 | { |
|
341 | 341 | chart()->setAxisX(axis, this); |
|
342 | 342 | } |
|
343 | 343 | |
|
344 | 344 | QAbstractAxis *DeclarativePercentBarSeries::axisX() |
|
345 | 345 | { |
|
346 | 346 | return chart()->axisX(this); |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | void DeclarativePercentBarSeries::setAxisY(QAbstractAxis *axis) |
|
350 | 350 | { |
|
351 | 351 | chart()->setAxisY(axis, this); |
|
352 | 352 | } |
|
353 | 353 | |
|
354 | 354 | QAbstractAxis *DeclarativePercentBarSeries::axisY() |
|
355 | 355 | { |
|
356 | 356 | return chart()->axisY(this); |
|
357 | 357 | } |
|
358 | 358 | |
|
359 | 359 | QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() |
|
360 | 360 | { |
|
361 | 361 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
365 | 365 | { |
|
366 | 366 | // Empty implementation; the children are parsed in componentComplete instead |
|
367 | 367 | Q_UNUSED(list); |
|
368 | 368 | Q_UNUSED(element); |
|
369 | 369 | } |
|
370 | 370 | |
|
371 | 371 | DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) |
|
372 | 372 | { |
|
373 | 373 | QList<QBarSet*> setList = barSets(); |
|
374 | 374 | if (index >= 0 && index < setList.count()) |
|
375 | 375 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
376 | 376 | |
|
377 | 377 | return 0; |
|
378 | 378 | } |
|
379 | 379 | |
|
380 | 380 | DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values) |
|
381 | 381 | { |
|
382 | 382 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
383 | 383 | barset->setLabel(label); |
|
384 | 384 | barset->setValues(values); |
|
385 | 385 | if (QPercentBarSeries::insert(index, barset)) |
|
386 | 386 | return barset; |
|
387 | 387 | delete barset; |
|
388 | 388 | return 0; |
|
389 | 389 | } |
|
390 | 390 | |
|
391 | 391 | #include "moc_declarativebarseries.cpp" |
|
392 | 392 | |
|
393 | 393 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,189 +1,190 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVEBARSERIES_H |
|
22 | 22 | #define DECLARATIVEBARSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 |
#include "q |
|
|
25 | #include "qabstractbarseries.h" | |
|
26 | #include "qbarseries.h" | |
|
26 | 27 | #include "qstackedbarseries.h" |
|
27 | 28 | #include "qpercentbarseries.h" |
|
28 | 29 | #include "qbarset.h" |
|
29 | 30 | #include "qabstractaxis.h" |
|
30 | 31 | #include <QDeclarativeItem> |
|
31 | 32 | #include <QDeclarativeParserStatus> |
|
32 | 33 | |
|
33 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 35 | |
|
35 | 36 | class QChart; |
|
36 | 37 | |
|
37 | 38 | class DeclarativeBarSet : public QBarSet |
|
38 | 39 | { |
|
39 | 40 | Q_OBJECT |
|
40 | 41 | Q_PROPERTY(QVariantList values READ values WRITE setValues) |
|
41 | 42 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
42 | 43 | |
|
43 | 44 | public: |
|
44 | 45 | explicit DeclarativeBarSet(QObject *parent = 0); |
|
45 | 46 | QVariantList values(); |
|
46 | 47 | void setValues(QVariantList values); |
|
47 | 48 | |
|
48 | 49 | public: // From QBarSet |
|
49 | 50 | Q_INVOKABLE void append(qreal value) { QBarSet::append(value); } |
|
50 | 51 | Q_INVOKABLE void remove(const int index, const int count = 1) { QBarSet::remove(index, count); } |
|
51 | 52 | Q_INVOKABLE void replace(int index, qreal value) { QBarSet::replace(index, value); } |
|
52 | 53 | Q_INVOKABLE qreal at(int index) { return QBarSet::at(index); } |
|
53 | 54 | |
|
54 | 55 | Q_SIGNALS: |
|
55 | 56 | void countChanged(int count); |
|
56 | 57 | |
|
57 | 58 | private Q_SLOTS: |
|
58 | 59 | void handleCountChanged(int index, int count); |
|
59 | 60 | }; |
|
60 | 61 | |
|
61 | 62 | class DeclarativeAbstractBarSeries : public QAbstractBarSeries, public QDeclarativeParserStatus |
|
62 | 63 | { |
|
63 | 64 | Q_OBJECT |
|
64 | 65 | Q_INTERFACES(QDeclarativeParserStatus) |
|
65 | 66 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
66 | 67 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) |
|
67 | 68 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) |
|
68 | 69 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
69 | 70 | |
|
70 | 71 | public: |
|
71 | 72 | explicit DeclarativeAbstractBarSeries(QDeclarativeItem *parent = 0); |
|
72 | 73 | void setAxisX(QAbstractAxis *axis); |
|
73 | 74 | QAbstractAxis *axisX(); |
|
74 | 75 | void setAxisY(QAbstractAxis *axis); |
|
75 | 76 | QAbstractAxis *axisY(); |
|
76 | 77 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
77 | 78 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
78 | 79 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
79 | 80 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
80 | 81 | Q_INVOKABLE bool remove(QBarSet *barset) { return QAbstractBarSeries::remove(barset); } |
|
81 | 82 | Q_INVOKABLE void clear() { return QAbstractBarSeries::clear(); } |
|
82 | 83 | |
|
83 | 84 | public: // from QDeclarativeParserStatus |
|
84 | 85 | void classBegin(); |
|
85 | 86 | void componentComplete(); |
|
86 | 87 | |
|
87 | 88 | Q_SIGNALS: |
|
88 | 89 | void added(DeclarativeBarSet *barset); |
|
89 | 90 | void removed(DeclarativeBarSet *barset); |
|
90 | 91 | |
|
91 | 92 | public Q_SLOTS: |
|
92 | 93 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
93 | 94 | void handleAdded(QList<QBarSet* > barsets); |
|
94 | 95 | void handleRemoved(QList<QBarSet* > barsets); |
|
95 | 96 | }; |
|
96 | 97 | |
|
97 |
class Declarative |
|
|
98 | class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus | |
|
98 | 99 | { |
|
99 | 100 | Q_OBJECT |
|
100 | 101 | Q_INTERFACES(QDeclarativeParserStatus) |
|
101 | 102 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) |
|
102 | 103 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) |
|
103 | 104 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
104 | 105 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
105 | 106 | |
|
106 | 107 | public: |
|
107 |
explicit Declarative |
|
|
108 | explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); | |
|
108 | 109 | void setAxisX(QAbstractAxis *axis); |
|
109 | 110 | QAbstractAxis *axisX(); |
|
110 | 111 | void setAxisY(QAbstractAxis *axis); |
|
111 | 112 | QAbstractAxis *axisY(); |
|
112 | 113 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
113 | 114 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
114 | 115 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
115 | 116 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
116 |
Q_INVOKABLE bool remove(QBarSet *barset) { return Q |
|
|
117 |
Q_INVOKABLE void clear() { return Q |
|
|
117 | Q_INVOKABLE bool remove(QBarSet *barset) { return QBarSeries::remove(barset); } | |
|
118 | Q_INVOKABLE void clear() { return QBarSeries::clear(); } | |
|
118 | 119 | |
|
119 | 120 | public: // from QDeclarativeParserStatus |
|
120 | 121 | void classBegin(); |
|
121 | 122 | void componentComplete(); |
|
122 | 123 | |
|
123 | 124 | public Q_SLOTS: |
|
124 | 125 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
125 | 126 | }; |
|
126 | 127 | |
|
127 | 128 | class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativeParserStatus |
|
128 | 129 | { |
|
129 | 130 | Q_OBJECT |
|
130 | 131 | Q_INTERFACES(QDeclarativeParserStatus) |
|
131 | 132 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) |
|
132 | 133 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) |
|
133 | 134 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
134 | 135 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
135 | 136 | |
|
136 | 137 | public: |
|
137 | 138 | explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0); |
|
138 | 139 | void setAxisX(QAbstractAxis *axis); |
|
139 | 140 | QAbstractAxis *axisX(); |
|
140 | 141 | void setAxisY(QAbstractAxis *axis); |
|
141 | 142 | QAbstractAxis *axisY(); |
|
142 | 143 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
143 | 144 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
144 | 145 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
145 | 146 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
146 | 147 | Q_INVOKABLE bool remove(QBarSet *barset) { return QStackedBarSeries::remove(barset); } |
|
147 | 148 | Q_INVOKABLE void clear() { return QStackedBarSeries::clear(); } |
|
148 | 149 | |
|
149 | 150 | public: // from QDeclarativeParserStatus |
|
150 | 151 | void classBegin(); |
|
151 | 152 | void componentComplete(); |
|
152 | 153 | |
|
153 | 154 | public Q_SLOTS: |
|
154 | 155 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
155 | 156 | }; |
|
156 | 157 | |
|
157 | 158 | class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus |
|
158 | 159 | { |
|
159 | 160 | Q_OBJECT |
|
160 | 161 | Q_INTERFACES(QDeclarativeParserStatus) |
|
161 | 162 | Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) |
|
162 | 163 | Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) |
|
163 | 164 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) |
|
164 | 165 | Q_CLASSINFO("DefaultProperty", "seriesChildren") |
|
165 | 166 | |
|
166 | 167 | public: |
|
167 | 168 | explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0); |
|
168 | 169 | void setAxisX(QAbstractAxis *axis); |
|
169 | 170 | QAbstractAxis *axisX(); |
|
170 | 171 | void setAxisY(QAbstractAxis *axis); |
|
171 | 172 | QAbstractAxis *axisY(); |
|
172 | 173 | QDeclarativeListProperty<QObject> seriesChildren(); |
|
173 | 174 | Q_INVOKABLE DeclarativeBarSet *at(int index); |
|
174 | 175 | Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } |
|
175 | 176 | Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); |
|
176 | 177 | Q_INVOKABLE bool remove(QBarSet *barset) { return QPercentBarSeries::remove(barset); } |
|
177 | 178 | Q_INVOKABLE void clear() { return QPercentBarSeries::clear(); } |
|
178 | 179 | |
|
179 | 180 | public: // from QDeclarativeParserStatus |
|
180 | 181 | void classBegin(); |
|
181 | 182 | void componentComplete(); |
|
182 | 183 | |
|
183 | 184 | public Q_SLOTS: |
|
184 | 185 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
185 | 186 | }; |
|
186 | 187 | |
|
187 | 188 | QTCOMMERCIALCHART_END_NAMESPACE |
|
188 | 189 | |
|
189 | 190 | #endif // DECLARATIVEBARSERIES_H |
@@ -1,498 +1,498 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativechart.h" |
|
22 | 22 | #include <QPainter> |
|
23 | 23 | #include "declarativelineseries.h" |
|
24 | 24 | #include "declarativeareaseries.h" |
|
25 | 25 | #include "declarativebarseries.h" |
|
26 | 26 | #include "declarativepieseries.h" |
|
27 | 27 | #include "declarativesplineseries.h" |
|
28 | 28 | #include "declarativescatterseries.h" |
|
29 | 29 | #include "qcategoriesaxis.h" |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | /*! |
|
34 | 34 | \qmlclass ChartView DeclarativeChart |
|
35 | 35 | |
|
36 | 36 | ChartView element is the parent that is responsible for showing different chart series types. |
|
37 | 37 | |
|
38 | 38 | The following QML shows how to create a simple chart with one pie series: |
|
39 | 39 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
40 | 40 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
41 | 41 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
42 | 42 | |
|
43 | 43 | \beginfloatleft |
|
44 | 44 | \image examples_qmlpiechart.png |
|
45 | 45 | \endfloat |
|
46 | 46 | \clearfloat |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \qmlproperty Theme ChartView::theme |
|
51 | 51 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
52 | 52 | widths and chart background. |
|
53 | 53 | */ |
|
54 | 54 | |
|
55 | 55 | /*! |
|
56 | 56 | \qmlproperty Animation ChartView::animation |
|
57 | 57 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
58 | 58 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
59 | 59 | */ |
|
60 | 60 | |
|
61 | 61 | /*! |
|
62 | 62 | \qmlproperty Font ChartView::titleFont |
|
63 | 63 | The title font of the chart |
|
64 | 64 | |
|
65 | 65 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \qmlproperty string ChartView::title |
|
70 | 70 | The title of the chart, shown on top of the chart. |
|
71 | 71 | \sa ChartView::titleColor |
|
72 | 72 | */ |
|
73 | 73 | |
|
74 | 74 | /*! |
|
75 | 75 | \qmlproperty string ChartView::titleColor |
|
76 | 76 | The color of the title text. |
|
77 | 77 | */ |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | \qmlproperty Axis ChartView::axisX |
|
81 | 81 | The x-axis of the chart. |
|
82 | 82 | */ |
|
83 | 83 | |
|
84 | 84 | /*! |
|
85 | 85 | \qmlproperty Axis ChartView::axisY |
|
86 | 86 | The default y-axis of the chart. |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty Legend ChartView::legend |
|
91 | 91 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \qmlproperty int ChartView::count |
|
96 | 96 | The count of series added to the chart. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \qmlproperty color ChartView::backgroundColor |
|
101 | 101 | The color of the chart's background. By default background color is defined by chart theme. |
|
102 | 102 | \sa ChartView::theme |
|
103 | 103 | */ |
|
104 | 104 | |
|
105 | 105 | /*! |
|
106 | 106 | \qmlproperty bool ChartView::dropShadowEnabled |
|
107 | 107 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
108 | 108 | */ |
|
109 | 109 | |
|
110 | 110 | /*! |
|
111 | 111 | \qmlproperty real ChartView::topMargin |
|
112 | 112 | The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin |
|
113 | 113 | area of the chart view. Top margin area is also used by legend, if aligned to top. |
|
114 | 114 | */ |
|
115 | 115 | |
|
116 | 116 | /*! |
|
117 | 117 | \qmlproperty real ChartView::bottomMargin |
|
118 | 118 | The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by |
|
119 | 119 | legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks. |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \qmlproperty real ChartView::leftMargin |
|
124 | 124 | The space between the left side of chart view and the left side of the plot area. The left margin area may be used by |
|
125 | 125 | legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks. |
|
126 | 126 | */ |
|
127 | 127 | |
|
128 | 128 | /*! |
|
129 | 129 | \qmlproperty real ChartView::rightMargin |
|
130 | 130 | The space between the right side of chart view and the right side of the plot area. The right margin area may be used |
|
131 | 131 | by legend (if aligned to right). |
|
132 | 132 | */ |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
136 | 136 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
137 | 137 | the count property of the chart. |
|
138 | 138 | */ |
|
139 | 139 | |
|
140 | 140 | /*! |
|
141 | 141 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
142 | 142 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name) |
|
147 | 147 | Creates a series object of \a type to the chart. For example: |
|
148 | 148 | \code |
|
149 | 149 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series"); |
|
150 | 150 | scatter.markerSize = 22; |
|
151 | 151 | scatter.append(1.1, 2.0); |
|
152 | 152 | \endcode |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) |
|
157 | 157 | The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported. |
|
158 | 158 | */ |
|
159 | 159 | |
|
160 | 160 | /*! |
|
161 | 161 | \qmlmethod ChartView::zoomY(real factor) |
|
162 | 162 | Zooms in by \a factor on the center of the chart. |
|
163 | 163 | */ |
|
164 | 164 | |
|
165 | 165 | /*! |
|
166 | 166 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
167 | 167 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
168 | 168 | \sa Axis::min, Axis::max |
|
169 | 169 | */ |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | \qmlmethod ChartView::scrollRight(real pixels) |
|
173 | 173 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
174 | 174 | \sa Axis::min, Axis::max |
|
175 | 175 | */ |
|
176 | 176 | |
|
177 | 177 | /*! |
|
178 | 178 | \qmlmethod ChartView::scrollUp(real pixels) |
|
179 | 179 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
180 | 180 | \sa Axis::min, Axis::max |
|
181 | 181 | */ |
|
182 | 182 | |
|
183 | 183 | /*! |
|
184 | 184 | \qmlmethod ChartView::scrollDown(real pixels) |
|
185 | 185 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
186 | 186 | \sa Axis::min, Axis::max |
|
187 | 187 | */ |
|
188 | 188 | |
|
189 | 189 | /*! |
|
190 | 190 | \qmlsignal ChartView::onTopMarginChanged(real margin) |
|
191 | 191 | The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
192 | 192 | related properties of the legend or chart title. |
|
193 | 193 | */ |
|
194 | 194 | |
|
195 | 195 | /*! |
|
196 | 196 | \qmlsignal ChartView::onBottomMarginChanged(real margin) |
|
197 | 197 | The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
198 | 198 | related properties of the legend or chart title. |
|
199 | 199 | */ |
|
200 | 200 | |
|
201 | 201 | /*! |
|
202 | 202 | \qmlsignal ChartView::onLeftMarginChanged(real margin) |
|
203 | 203 | The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
204 | 204 | related properties of the legend or chart title. |
|
205 | 205 | */ |
|
206 | 206 | |
|
207 | 207 | /*! |
|
208 | 208 | \qmlsignal ChartView::onRightMarginChanged(real margin) |
|
209 | 209 | The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
210 | 210 | related properties of the legend or chart title. |
|
211 | 211 | */ |
|
212 | 212 | |
|
213 | 213 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
214 | 214 | : QDeclarativeItem(parent), |
|
215 | 215 | m_chart(new QChart(this)) |
|
216 | 216 | { |
|
217 | 217 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
218 | 218 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
219 | 219 | m_chartMargins = m_chart->margins(); |
|
220 | 220 | connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF))); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | void DeclarativeChart::handleMarginsChanged(QRectF newMargins) |
|
224 | 224 | { |
|
225 | 225 | if (m_chartMargins.top() != newMargins.top()) |
|
226 | 226 | topMarginChanged(m_chart->margins().top()); |
|
227 | 227 | if (m_chartMargins.bottom() != newMargins.bottom()) |
|
228 | 228 | bottomMarginChanged(m_chart->margins().bottom()); |
|
229 | 229 | if (m_chartMargins.left() != newMargins.left()) |
|
230 | 230 | leftMarginChanged(m_chart->margins().left()); |
|
231 | 231 | if (m_chartMargins.right() != newMargins.right()) |
|
232 | 232 | rightMarginChanged(m_chart->margins().right()); |
|
233 | 233 | |
|
234 | 234 | m_chartMargins = m_chart->margins(); |
|
235 | 235 | } |
|
236 | 236 | |
|
237 | 237 | DeclarativeChart::~DeclarativeChart() |
|
238 | 238 | { |
|
239 | 239 | delete m_chart; |
|
240 | 240 | } |
|
241 | 241 | |
|
242 | 242 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
243 | 243 | { |
|
244 | 244 | if (event->type() == QEvent::ChildAdded) { |
|
245 | 245 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
246 | 246 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
247 | 247 | } |
|
248 | 248 | } |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | void DeclarativeChart::componentComplete() |
|
252 | 252 | { |
|
253 | 253 | foreach(QObject *child, children()) { |
|
254 | 254 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
255 | 255 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; |
|
256 | 256 | // TODO: how about optional y-axis? |
|
257 | 257 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); |
|
258 | 258 | } |
|
259 | 259 | } |
|
260 | 260 | QDeclarativeItem::componentComplete(); |
|
261 | 261 | } |
|
262 | 262 | |
|
263 | 263 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
264 | 264 | { |
|
265 | 265 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
266 | 266 | if (newGeometry.isValid()) { |
|
267 | 267 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
268 | 268 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
269 | 269 | } |
|
270 | 270 | } |
|
271 | 271 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
272 | 272 | } |
|
273 | 273 | |
|
274 | 274 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
275 | 275 | { |
|
276 | 276 | Q_UNUSED(option) |
|
277 | 277 | Q_UNUSED(widget) |
|
278 | 278 | |
|
279 | 279 | // TODO: optimized? |
|
280 | 280 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
281 | 281 | } |
|
282 | 282 | |
|
283 | 283 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
284 | 284 | { |
|
285 | 285 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
286 | 286 | if (chartTheme != m_chart->theme()) |
|
287 | 287 | m_chart->setTheme(chartTheme); |
|
288 | 288 | } |
|
289 | 289 | |
|
290 | 290 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
291 | 291 | { |
|
292 | 292 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
296 | 296 | { |
|
297 | 297 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
298 | 298 | if (animationOptions != m_chart->animationOptions()) |
|
299 | 299 | m_chart->setAnimationOptions(animationOptions); |
|
300 | 300 | } |
|
301 | 301 | |
|
302 | 302 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
303 | 303 | { |
|
304 | 304 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
305 | 305 | return DeclarativeChart::AllAnimations; |
|
306 | 306 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
307 | 307 | return DeclarativeChart::GridAxisAnimations; |
|
308 | 308 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
309 | 309 | return DeclarativeChart::SeriesAnimations; |
|
310 | 310 | else |
|
311 | 311 | return DeclarativeChart::NoAnimation; |
|
312 | 312 | } |
|
313 | 313 | |
|
314 | 314 | void DeclarativeChart::setTitle(QString title) |
|
315 | 315 | { |
|
316 | 316 | if (title != m_chart->title()) |
|
317 | 317 | m_chart->setTitle(title); |
|
318 | 318 | } |
|
319 | 319 | QString DeclarativeChart::title() |
|
320 | 320 | { |
|
321 | 321 | return m_chart->title(); |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
325 | 325 | { |
|
326 | 326 | return m_chart->axisX(series); |
|
327 | 327 | } |
|
328 | 328 | |
|
329 | 329 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
330 | 330 | { |
|
331 | 331 | return m_chart->axisY(series); |
|
332 | 332 | } |
|
333 | 333 | |
|
334 | 334 | QLegend *DeclarativeChart::legend() |
|
335 | 335 | { |
|
336 | 336 | return m_chart->legend(); |
|
337 | 337 | } |
|
338 | 338 | |
|
339 | 339 | void DeclarativeChart::setTitleColor(QColor color) |
|
340 | 340 | { |
|
341 | 341 | QBrush b = m_chart->titleBrush(); |
|
342 | 342 | if (color != b.color()) { |
|
343 | 343 | b.setColor(color); |
|
344 | 344 | m_chart->setTitleBrush(b); |
|
345 | 345 | emit titleColorChanged(color); |
|
346 | 346 | } |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | QFont DeclarativeChart::titleFont() const |
|
350 | 350 | { |
|
351 | 351 | return m_chart->titleFont(); |
|
352 | 352 | } |
|
353 | 353 | |
|
354 | 354 | void DeclarativeChart::setTitleFont(const QFont& font) |
|
355 | 355 | { |
|
356 | 356 | m_chart->setTitleFont(font); |
|
357 | 357 | } |
|
358 | 358 | |
|
359 | 359 | QColor DeclarativeChart::titleColor() |
|
360 | 360 | { |
|
361 | 361 | return m_chart->titleBrush().color(); |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
365 | 365 | { |
|
366 | 366 | QBrush b = m_chart->backgroundBrush(); |
|
367 | 367 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
368 | 368 | b.setStyle(Qt::SolidPattern); |
|
369 | 369 | b.setColor(color); |
|
370 | 370 | m_chart->setBackgroundBrush(b); |
|
371 | 371 | emit backgroundColorChanged(); |
|
372 | 372 | } |
|
373 | 373 | } |
|
374 | 374 | |
|
375 | 375 | QColor DeclarativeChart::backgroundColor() |
|
376 | 376 | { |
|
377 | 377 | return m_chart->backgroundBrush().color(); |
|
378 | 378 | } |
|
379 | 379 | |
|
380 | 380 | int DeclarativeChart::count() |
|
381 | 381 | { |
|
382 | 382 | return m_chart->series().count(); |
|
383 | 383 | } |
|
384 | 384 | |
|
385 | 385 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
386 | 386 | { |
|
387 | 387 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
388 | 388 | m_chart->setDropShadowEnabled(enabled); |
|
389 | 389 | dropShadowEnabledChanged(enabled); |
|
390 | 390 | } |
|
391 | 391 | } |
|
392 | 392 | |
|
393 | 393 | bool DeclarativeChart::dropShadowEnabled() |
|
394 | 394 | { |
|
395 | 395 | return m_chart->isDropShadowEnabled(); |
|
396 | 396 | } |
|
397 | 397 | |
|
398 | 398 | qreal DeclarativeChart::topMargin() |
|
399 | 399 | { |
|
400 | 400 | return m_chart->margins().top(); |
|
401 | 401 | } |
|
402 | 402 | |
|
403 | 403 | qreal DeclarativeChart::bottomMargin() |
|
404 | 404 | { |
|
405 | 405 | return m_chart->margins().bottom(); |
|
406 | 406 | } |
|
407 | 407 | |
|
408 | 408 | qreal DeclarativeChart::leftMargin() |
|
409 | 409 | { |
|
410 | 410 | return m_chart->margins().left(); |
|
411 | 411 | } |
|
412 | 412 | |
|
413 | 413 | qreal DeclarativeChart::rightMargin() |
|
414 | 414 | { |
|
415 | 415 | return m_chart->margins().right(); |
|
416 | 416 | } |
|
417 | 417 | |
|
418 | 418 | void DeclarativeChart::zoom(qreal factor) |
|
419 | 419 | { |
|
420 | 420 | m_chart->zoom(factor); |
|
421 | 421 | } |
|
422 | 422 | |
|
423 | 423 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
424 | 424 | { |
|
425 | 425 | m_chart->scroll(pixels, 0); |
|
426 | 426 | } |
|
427 | 427 | |
|
428 | 428 | void DeclarativeChart::scrollRight(qreal pixels) |
|
429 | 429 | { |
|
430 | 430 | m_chart->scroll(-pixels, 0); |
|
431 | 431 | } |
|
432 | 432 | |
|
433 | 433 | void DeclarativeChart::scrollUp(qreal pixels) |
|
434 | 434 | { |
|
435 | 435 | m_chart->scroll(0, pixels); |
|
436 | 436 | } |
|
437 | 437 | |
|
438 | 438 | void DeclarativeChart::scrollDown(qreal pixels) |
|
439 | 439 | { |
|
440 | 440 | m_chart->scroll(0, -pixels); |
|
441 | 441 | } |
|
442 | 442 | |
|
443 | 443 | QAbstractSeries *DeclarativeChart::series(int index) |
|
444 | 444 | { |
|
445 | 445 | if (index < m_chart->series().count()) { |
|
446 | 446 | return m_chart->series().at(index); |
|
447 | 447 | } |
|
448 | 448 | return 0; |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
452 | 452 | { |
|
453 | 453 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
454 | 454 | if (series->name() == seriesName) |
|
455 | 455 | return series; |
|
456 | 456 | } |
|
457 | 457 | return 0; |
|
458 | 458 | } |
|
459 | 459 | |
|
460 | 460 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
461 | 461 | { |
|
462 | 462 | QAbstractSeries *series = 0; |
|
463 | 463 | switch (type) { |
|
464 | 464 | case DeclarativeChart::SeriesTypeLine: |
|
465 | 465 | series = new DeclarativeLineSeries(); |
|
466 | 466 | break; |
|
467 | 467 | case DeclarativeChart::SeriesTypeArea: |
|
468 | 468 | series = new DeclarativeAreaSeries(); |
|
469 | 469 | break; |
|
470 | 470 | case DeclarativeChart::SeriesTypeStackedBar: |
|
471 | 471 | // TODO |
|
472 | 472 | break; |
|
473 | 473 | case DeclarativeChart::SeriesTypePercentBar: |
|
474 | 474 | // TODO |
|
475 | 475 | break; |
|
476 |
case DeclarativeChart::SeriesType |
|
|
477 |
series = new Declarative |
|
|
476 | case DeclarativeChart::SeriesTypeBar: | |
|
477 | series = new DeclarativeBarSeries(); | |
|
478 | 478 | break; |
|
479 | 479 | case DeclarativeChart::SeriesTypePie: |
|
480 | 480 | series = new DeclarativePieSeries(); |
|
481 | 481 | break; |
|
482 | 482 | case DeclarativeChart::SeriesTypeScatter: |
|
483 | 483 | series = new DeclarativeScatterSeries(); |
|
484 | 484 | break; |
|
485 | 485 | case DeclarativeChart::SeriesTypeSpline: |
|
486 | 486 | series = new DeclarativeSplineSeries(); |
|
487 | 487 | break; |
|
488 | 488 | default: |
|
489 | 489 | qWarning() << "Illegal series type"; |
|
490 | 490 | } |
|
491 | 491 | series->setName(name); |
|
492 | 492 | m_chart->addSeries(series); |
|
493 | 493 | return series; |
|
494 | 494 | } |
|
495 | 495 | |
|
496 | 496 | #include "moc_declarativechart.cpp" |
|
497 | 497 | |
|
498 | 498 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,152 +1,151 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVECHART_H |
|
22 | 22 | #define DECLARATIVECHART_H |
|
23 | 23 | |
|
24 | 24 | #include <QtCore/QtGlobal> |
|
25 | 25 | #include <QDeclarativeItem> |
|
26 | 26 | #include <qchart.h> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | // TODO: Derive from QChart for easier definition of properties? |
|
31 | 31 | class DeclarativeChart : public QDeclarativeItem |
|
32 | 32 | // TODO: for QTQUICK2: extend QQuickPainterItem instead |
|
33 | 33 | //class DeclarativeChart : public QQuickPaintedItem, public Chart |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) |
|
37 | 37 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) |
|
38 | 38 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
39 | 39 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) |
|
40 | 40 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) |
|
41 | 41 | Q_PROPERTY(QAbstractAxis *axisX READ axisX) |
|
42 | 42 | Q_PROPERTY(QAbstractAxis *axisY READ axisY) |
|
43 | 43 | Q_PROPERTY(QLegend *legend READ legend) |
|
44 | 44 | Q_PROPERTY(int count READ count) |
|
45 | 45 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
46 | 46 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) |
|
47 | 47 | Q_PROPERTY(qreal topMargin READ topMargin NOTIFY topMarginChanged) |
|
48 | 48 | Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY bottomMarginChanged) |
|
49 | 49 | Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY leftMarginChanged) |
|
50 | 50 | Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY rightMarginChanged) |
|
51 | 51 | Q_ENUMS(Animation) |
|
52 | 52 | Q_ENUMS(Theme) |
|
53 | 53 | Q_ENUMS(SeriesType) |
|
54 | 54 | |
|
55 | 55 | public: |
|
56 | 56 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
|
57 | 57 | enum Theme { |
|
58 | 58 | ChartThemeLight = 0, |
|
59 | 59 | ChartThemeBlueCerulean, |
|
60 | 60 | ChartThemeDark, |
|
61 | 61 | ChartThemeBrownSand, |
|
62 | 62 | ChartThemeBlueNcs, |
|
63 | 63 | ChartThemeHighContrast, |
|
64 | 64 | ChartThemeBlueIcy |
|
65 | 65 | }; |
|
66 | 66 | |
|
67 | 67 | enum Animation { |
|
68 | 68 | NoAnimation = 0x0, |
|
69 | 69 | GridAxisAnimations = 0x1, |
|
70 | 70 | SeriesAnimations =0x2, |
|
71 | 71 | AllAnimations = 0x3 |
|
72 | 72 | }; |
|
73 | 73 | |
|
74 | 74 | enum SeriesType { |
|
75 | 75 | SeriesTypeLine, |
|
76 | 76 | SeriesTypeArea, |
|
77 | 77 | SeriesTypeBar, |
|
78 | 78 | SeriesTypeStackedBar, |
|
79 | 79 | SeriesTypePercentBar, |
|
80 | SeriesTypeGroupedBar, | |
|
81 | 80 | SeriesTypePie, |
|
82 | 81 | SeriesTypeScatter, |
|
83 | 82 | SeriesTypeSpline |
|
84 | 83 | }; |
|
85 | 84 | |
|
86 | 85 | public: |
|
87 | 86 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
88 | 87 | ~DeclarativeChart(); |
|
89 | 88 | |
|
90 | 89 | public: // From QDeclarativeItem/QGraphicsItem |
|
91 | 90 | void childEvent(QChildEvent *event); |
|
92 | 91 | void componentComplete(); |
|
93 | 92 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
94 | 93 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
95 | 94 | |
|
96 | 95 | public: |
|
97 | 96 | void setTheme(DeclarativeChart::Theme theme); |
|
98 | 97 | DeclarativeChart::Theme theme(); |
|
99 | 98 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
100 | 99 | DeclarativeChart::Animation animationOptions(); |
|
101 | 100 | void setTitle(QString title); |
|
102 | 101 | QString title(); |
|
103 | 102 | QLegend *legend(); |
|
104 | 103 | QFont titleFont() const; |
|
105 | 104 | void setTitleFont(const QFont& font); |
|
106 | 105 | void setTitleColor(QColor color); |
|
107 | 106 | QColor titleColor(); |
|
108 | 107 | void setBackgroundColor(QColor color); |
|
109 | 108 | QColor backgroundColor(); |
|
110 | 109 | int count(); |
|
111 | 110 | void setDropShadowEnabled(bool enabled); |
|
112 | 111 | bool dropShadowEnabled(); |
|
113 | 112 | qreal topMargin(); |
|
114 | 113 | qreal bottomMargin(); |
|
115 | 114 | qreal leftMargin(); |
|
116 | 115 | qreal rightMargin(); |
|
117 | 116 | |
|
118 | 117 | public: |
|
119 | 118 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
120 | 119 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
121 | 120 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); |
|
122 | 121 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); |
|
123 | 122 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); |
|
124 | 123 | Q_INVOKABLE void zoom(qreal factor); |
|
125 | 124 | Q_INVOKABLE void scrollLeft(qreal pixels); |
|
126 | 125 | Q_INVOKABLE void scrollRight(qreal pixels); |
|
127 | 126 | Q_INVOKABLE void scrollUp(qreal pixels); |
|
128 | 127 | Q_INVOKABLE void scrollDown(qreal pixels); |
|
129 | 128 | |
|
130 | 129 | Q_SIGNALS: |
|
131 | 130 | void axisLabelsChanged(); |
|
132 | 131 | void titleColorChanged(QColor color); |
|
133 | 132 | void backgroundColorChanged(); |
|
134 | 133 | void dropShadowEnabledChanged(bool enabled); |
|
135 | 134 | void topMarginChanged(qreal margin); |
|
136 | 135 | void bottomMarginChanged(qreal margin); |
|
137 | 136 | void leftMarginChanged(qreal margin); |
|
138 | 137 | void rightMarginChanged(qreal margin); |
|
139 | 138 | |
|
140 | 139 | public Q_SLOTS: |
|
141 | 140 | void handleMarginsChanged(QRectF newMargins); |
|
142 | 141 | |
|
143 | 142 | private: |
|
144 | 143 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
145 | 144 | // multi inheritance, so we now have a QChart as a member instead |
|
146 | 145 | QChart *m_chart; |
|
147 | 146 | QRectF m_chartMargins; |
|
148 | 147 | }; |
|
149 | 148 | |
|
150 | 149 | QTCOMMERCIALCHART_END_NAMESPACE |
|
151 | 150 | |
|
152 | 151 | #endif // DECLARATIVECHART_H |
@@ -1,108 +1,108 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtDeclarative/qdeclarativeextensionplugin.h> |
|
22 | 22 | #include <QtDeclarative/qdeclarative.h> |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | #include "qabstractaxis.h" |
|
25 | 25 | #include "qvaluesaxis.h" |
|
26 | 26 | #include "qcategoriesaxis.h" |
|
27 | 27 | #include "declarativechart.h" |
|
28 | 28 | #include "declarativexypoint.h" |
|
29 | 29 | #include "declarativelineseries.h" |
|
30 | 30 | #include "declarativesplineseries.h" |
|
31 | 31 | #include "declarativeareaseries.h" |
|
32 | 32 | #include "declarativescatterseries.h" |
|
33 | 33 | #include "declarativebarseries.h" |
|
34 | 34 | #include "declarativepieseries.h" |
|
35 | 35 | #include <QVXYModelMapper> |
|
36 | 36 | #include <QHXYModelMapper> |
|
37 | 37 | #include <QHPieModelMapper> |
|
38 | 38 | #include <QVPieModelMapper> |
|
39 | 39 | #include <QHBarModelMapper> |
|
40 | 40 | #include <QVBarModelMapper> |
|
41 | 41 | |
|
42 | 42 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
43 | 43 | |
|
44 | 44 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
45 | 45 | { |
|
46 | 46 | Q_OBJECT |
|
47 | 47 | public: |
|
48 | 48 | virtual void registerTypes(const char *uri) |
|
49 | 49 | { |
|
50 | 50 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
51 | 51 | |
|
52 | 52 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
53 | 53 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); |
|
54 | 54 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
55 | 55 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
56 | 56 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
57 | 57 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
58 |
qmlRegisterType<Declarative |
|
|
58 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); | |
|
59 | 59 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); |
|
60 | 60 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); |
|
61 | 61 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
62 | 62 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); |
|
63 | 63 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
64 | 64 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); |
|
65 | 65 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); |
|
66 | 66 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
67 | 67 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
68 | 68 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); |
|
69 | 69 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); |
|
70 | 70 | qmlRegisterType<QValuesAxis>(uri, 1, 0, "ValuesAxis"); |
|
71 | 71 | qmlRegisterType<QCategoriesAxis>(uri, 1, 0, "CategoriesAxis"); |
|
72 | 72 | |
|
73 | 73 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", |
|
74 | 74 | QLatin1String("Trying to create uncreatable: Legend.")); |
|
75 | 75 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", |
|
76 | 76 | QLatin1String("Trying to create uncreatable: XYSeries.")); |
|
77 | 77 | qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries", |
|
78 | 78 | QLatin1String("Trying to create uncreatable: QScatterSeries.")); |
|
79 | 79 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", |
|
80 | 80 | QLatin1String("Trying to create uncreatable: QPieSeries.")); |
|
81 | 81 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "QBarSet", |
|
82 | 82 | QLatin1String("Trying to create uncreatable: QBarSet.")); |
|
83 | 83 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", |
|
84 | 84 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
85 | 85 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
86 | 86 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
87 | 87 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
88 | 88 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
89 | 89 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", |
|
90 | 90 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); |
|
91 | 91 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
92 | 92 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
93 | 93 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", |
|
94 | 94 | QLatin1String("Trying to create uncreatable: AbstractAxis.")); |
|
95 | 95 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
96 | 96 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
97 | 97 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
98 | 98 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
99 | 99 | } |
|
100 | 100 | }; |
|
101 | 101 | |
|
102 | 102 | #include "plugin.moc" |
|
103 | 103 | |
|
104 | 104 | QTCOMMERCIALCHART_END_NAMESPACE |
|
105 | 105 | |
|
106 | 106 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
107 | 107 | |
|
108 | 108 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
@@ -1,77 +1,77 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef CHARTANIMATOR_P_H |
|
31 | 31 | #define CHARTANIMATOR_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qchartglobal.h" |
|
34 | 34 | #include "chartanimation_p.h" |
|
35 | 35 | #include "piechartitem_p.h" |
|
36 | 36 | #include "barchartitem_p.h" |
|
37 | 37 | #include <QPointF> |
|
38 | 38 | |
|
39 | 39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | 40 | |
|
41 | 41 | class ChartItem; |
|
42 | 42 | class ChartAxis; |
|
43 | 43 | class AreaChartItem; |
|
44 | 44 | class SplineChartItem; |
|
45 | 45 | class ScatterChartItem; |
|
46 | 46 | class LineChartItem; |
|
47 | 47 | class XYChartItem; |
|
48 | 48 | class XYAnimation; |
|
49 | 49 | |
|
50 | 50 | class ChartAnimator : public QObject |
|
51 | 51 | { |
|
52 | 52 | Q_OBJECT |
|
53 | 53 | public: |
|
54 | 54 | ChartAnimator(QObject *parent = 0); |
|
55 | 55 | virtual ~ChartAnimator(); |
|
56 | 56 | |
|
57 | 57 | void addAnimation(PieChartItem *item); |
|
58 |
void addAnimation(BarChartItem *item); |
|
|
58 | void addAnimation(BarChartItem *item); | |
|
59 | 59 | void addAnimation(StackedBarChartItem *item); |
|
60 | 60 | void addAnimation(PercentBarChartItem *item); |
|
61 | 61 | void removeAnimation(Chart *item); |
|
62 | 62 | |
|
63 | 63 | void addAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData, bool isEmpty); |
|
64 | 64 | void removeAnimation(PieChartItem *item, PieSliceItem *sliceItem); |
|
65 | 65 | void updateAnimation(PieChartItem *item, PieSliceItem *sliceItem, const PieSliceData &sliceData); |
|
66 | 66 | |
|
67 | 67 | void updateLayout(BarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); |
|
68 | 68 | void updateLayout(StackedBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); |
|
69 | 69 | void updateLayout(PercentBarChartItem *item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); |
|
70 | 70 | |
|
71 | 71 | private: |
|
72 | 72 | QMap<Chart *, ChartAnimation *> m_animations; |
|
73 | 73 | }; |
|
74 | 74 | |
|
75 | 75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
76 | 76 | |
|
77 | 77 | #endif |
@@ -1,40 +1,40 | |||
|
1 | 1 | INCLUDEPATH += $$PWD |
|
2 | 2 | DEPENDPATH += $$PWD |
|
3 | 3 | |
|
4 | 4 | SOURCES += \ |
|
5 | 5 | $$PWD/bar.cpp \ |
|
6 | 6 | $$PWD/barchartitem.cpp \ |
|
7 | 7 | $$PWD/percentbarchartitem.cpp \ |
|
8 | 8 | $$PWD/groupedbarchartitem.cpp \ |
|
9 | 9 | $$PWD/qabstractbarseries.cpp \ |
|
10 | 10 | $$PWD/qbarset.cpp \ |
|
11 | 11 | $$PWD/qpercentbarseries.cpp \ |
|
12 | 12 | $$PWD/qstackedbarseries.cpp \ |
|
13 |
$$PWD/q |
|
|
13 | $$PWD/qbarseries.cpp \ | |
|
14 | 14 | $$PWD/stackedbarchartitem.cpp \ |
|
15 | 15 | $$PWD/qbarmodelmapper.cpp \ |
|
16 | 16 | $$PWD/qvbarmodelmapper.cpp \ |
|
17 | 17 | $$PWD/qhbarmodelmapper.cpp |
|
18 | 18 | |
|
19 | 19 | PRIVATE_HEADERS += \ |
|
20 | 20 | $$PWD/bar_p.h \ |
|
21 | 21 | $$PWD/barchartitem_p.h \ |
|
22 | 22 | $$PWD/percentbarchartitem_p.h \ |
|
23 | 23 | $$PWD/stackedbarchartitem_p.h \ |
|
24 | 24 | $$PWD/groupedbarchartitem_p.h \ |
|
25 | 25 | $$PWD/qbarset_p.h \ |
|
26 | 26 | $$PWD/qabstractbarseries_p.h \ |
|
27 | 27 | $$PWD/qstackedbarseries_p.h\ |
|
28 | 28 | $$PWD/qpercentbarseries_p.h \ |
|
29 |
$$PWD/q |
|
|
29 | $$PWD/qbarseries_p.h \ | |
|
30 | 30 | $$PWD/qbarmodelmapper_p.h |
|
31 | 31 | |
|
32 | 32 | PUBLIC_HEADERS += \ |
|
33 | 33 | $$PWD/qabstractbarseries.h \ |
|
34 | 34 | $$PWD/qbarset.h \ |
|
35 | 35 | $$PWD/qpercentbarseries.h \ |
|
36 | 36 | $$PWD/qstackedbarseries.h \ |
|
37 |
$$PWD/q |
|
|
37 | $$PWD/qbarseries.h \ | |
|
38 | 38 | $$PWD/qbarmodelmapper.h \ |
|
39 | 39 | $$PWD/qvbarmodelmapper.h \ |
|
40 | 40 | $$PWD/qhbarmodelmapper.h |
@@ -1,735 +1,735 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qabstractbarseries.h" |
|
22 | 22 | #include "qabstractbarseries_p.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "qbarset_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "legendmarker_p.h" |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartanimator_p.h" |
|
30 | 30 | #include "qvaluesaxis.h" |
|
31 | 31 | #include "qcategoriesaxis.h" |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 34 | |
|
35 | 35 | /*! |
|
36 | 36 | \class QAbstractBarSeries |
|
37 | 37 | \brief Series for creating a bar chart |
|
38 | 38 | \mainclass |
|
39 | 39 | |
|
40 | 40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
41 | 41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
42 | 42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
43 | 43 | shows the x-values. |
|
44 | 44 | |
|
45 | 45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
46 | 46 | \image examples_barchart.png |
|
47 | 47 | |
|
48 | 48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
49 | 49 | */ |
|
50 | 50 | /*! |
|
51 | 51 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
52 | 52 | \inherits QAbstractSeries |
|
53 | 53 | |
|
54 | 54 | The following QML shows how to create a simple bar chart: |
|
55 | 55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
56 | 56 | |
|
57 | 57 | \beginfloatleft |
|
58 | 58 | \image demos_qmlchart6.png |
|
59 | 59 | \endfloat |
|
60 | 60 | \clearfloat |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QAbstractBarSeries::barWidth |
|
65 | 65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
66 | 66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
67 | 67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
68 |
Note that with Q |
|
|
69 |
\sa Q |
|
|
68 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
|
69 | \sa QBarSeries | |
|
70 | 70 | */ |
|
71 | 71 | /*! |
|
72 | 72 | \qmlproperty real AbstractBarSeries::barWidth |
|
73 | 73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
74 | 74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
75 | 75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
76 |
Note that with Q |
|
|
76 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
|
77 | 77 | */ |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | \property QAbstractBarSeries::count |
|
81 | 81 | Holds the number of sets in series. |
|
82 | 82 | */ |
|
83 | 83 | /*! |
|
84 | 84 | \qmlproperty int AbstractBarSeries::count |
|
85 | 85 | Holds the number of sets in series. |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | \property QAbstractBarSeries::labelsVisible |
|
90 | 90 | Defines the visibility of the labels in series |
|
91 | 91 | */ |
|
92 | 92 | /*! |
|
93 | 93 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
94 | 94 | Defines the visibility of the labels in series |
|
95 | 95 | */ |
|
96 | 96 | |
|
97 | 97 | /*! |
|
98 | 98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
99 | 99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
100 | 100 | Clicked bar inside set is indexed by \a index |
|
101 | 101 | */ |
|
102 | 102 | /*! |
|
103 | 103 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
104 | 104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
105 | 105 | Clicked bar inside set is indexed by \a index |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
110 | 110 | |
|
111 | 111 | The signal is emitted if mouse is hovered on top of series. |
|
112 | 112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
113 | 113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
114 | 114 | */ |
|
115 | 115 | /*! |
|
116 | 116 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
117 | 117 | |
|
118 | 118 | The signal is emitted if mouse is hovered on top of series. |
|
119 | 119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
120 | 120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \fn void QAbstractBarSeries::countChanged() |
|
125 | 125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | 128 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
129 | 129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
134 | 134 | This signal is emitted when labels visibility have changed. |
|
135 | 135 | \sa isLabelsVisible(), setLabelsVisible() |
|
136 | 136 | */ |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
140 | 140 | This signal is emitted when \a sets have been added to the series. |
|
141 | 141 | \sa append(), insert() |
|
142 | 142 | */ |
|
143 | 143 | /*! |
|
144 | 144 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) |
|
145 | 145 | Emitted when \a barset has been added to the series. |
|
146 | 146 | */ |
|
147 | 147 | |
|
148 | 148 | /*! |
|
149 | 149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
150 | 150 | This signal is emitted when \a sets have been removed from the series. |
|
151 | 151 | \sa remove() |
|
152 | 152 | */ |
|
153 | 153 | /*! |
|
154 | 154 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) |
|
155 | 155 | Emitted when \a barset has been removed from the series. |
|
156 | 156 | */ |
|
157 | 157 | |
|
158 | 158 | /*! |
|
159 | 159 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
160 | 160 | Returns bar set at \a index. Returns null if the index is not valid. |
|
161 | 161 | */ |
|
162 | 162 | |
|
163 | 163 | /*! |
|
164 | 164 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
165 | 165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
166 | 166 | For example: |
|
167 | 167 | \code |
|
168 | 168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
169 | 169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
170 | 170 | \endcode |
|
171 | 171 | */ |
|
172 | 172 | |
|
173 | 173 | /*! |
|
174 | 174 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
175 | 175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
176 | 176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
177 | 177 | appended. |
|
178 | 178 | \sa AbstractBarSeries::append() |
|
179 | 179 | */ |
|
180 | 180 | |
|
181 | 181 | /*! |
|
182 | 182 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
183 | 183 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
184 | 184 | */ |
|
185 | 185 | |
|
186 | 186 | /*! |
|
187 | 187 | \qmlmethod AbstractBarSeries::clear() |
|
188 | 188 | Removes all barsets from the series. |
|
189 | 189 | */ |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | Constructs empty QAbstractBarSeries. |
|
193 | 193 | QAbstractBarSeries is QObject which is a child of a \a parent. |
|
194 | 194 | */ |
|
195 | 195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
196 | 196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) |
|
197 | 197 | { |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | /*! |
|
201 | 201 | Destructs abstractbarseries and owned barsets. |
|
202 | 202 | */ |
|
203 | 203 | QAbstractBarSeries::~QAbstractBarSeries() |
|
204 | 204 | { |
|
205 | 205 | Q_D(QAbstractBarSeries); |
|
206 | 206 | if(d->m_dataset){ |
|
207 | 207 | d->m_dataset->removeSeries(this); |
|
208 | 208 | } |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | /*! |
|
212 | 212 | \internal |
|
213 | 213 | */ |
|
214 | 214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
215 | 215 | QAbstractSeries(d,parent) |
|
216 | 216 | { |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | 220 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
221 | 221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
222 | 222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
223 |
Note that with \link Q |
|
|
223 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
|
224 | 224 | */ |
|
225 | 225 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
226 | 226 | { |
|
227 | 227 | Q_D(QAbstractBarSeries); |
|
228 | 228 | d->setBarWidth(width); |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | Returns the width of the bars of the series. |
|
233 | 233 | \sa setBarWidth() |
|
234 | 234 | */ |
|
235 | 235 | qreal QAbstractBarSeries::barWidth() const |
|
236 | 236 | { |
|
237 | 237 | Q_D(const QAbstractBarSeries); |
|
238 | 238 | return d->barWidth(); |
|
239 | 239 | } |
|
240 | 240 | |
|
241 | 241 | /*! |
|
242 | 242 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
243 | 243 | Returns true, if appending succeeded. |
|
244 | 244 | */ |
|
245 | 245 | bool QAbstractBarSeries::append(QBarSet *set) |
|
246 | 246 | { |
|
247 | 247 | Q_D(QAbstractBarSeries); |
|
248 | 248 | bool success = d->append(set); |
|
249 | 249 | if (success) { |
|
250 | 250 | QList<QBarSet*> sets; |
|
251 | 251 | sets.append(set); |
|
252 | 252 | emit barsetsAdded(sets); |
|
253 | 253 | emit countChanged(); |
|
254 | 254 | } |
|
255 | 255 | return success; |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | /*! |
|
259 | 259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
260 | 260 | Returns true, if set was removed. |
|
261 | 261 | */ |
|
262 | 262 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
263 | 263 | { |
|
264 | 264 | Q_D(QAbstractBarSeries); |
|
265 | 265 | bool success = d->remove(set); |
|
266 | 266 | if (success) { |
|
267 | 267 | QList<QBarSet*> sets; |
|
268 | 268 | sets.append(set); |
|
269 | 269 | emit barsetsRemoved(sets); |
|
270 | 270 | emit countChanged(); |
|
271 | 271 | } |
|
272 | 272 | return success; |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | /*! |
|
276 | 276 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
277 | 277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
278 | 278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
279 | 279 | and function returns false. |
|
280 | 280 | */ |
|
281 | 281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
282 | 282 | { |
|
283 | 283 | Q_D(QAbstractBarSeries); |
|
284 | 284 | bool success = d->append(sets); |
|
285 | 285 | if (success) { |
|
286 | 286 | emit barsetsAdded(sets); |
|
287 | 287 | emit countChanged(); |
|
288 | 288 | } |
|
289 | 289 | return success; |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | /*! |
|
293 | 293 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
294 | 294 | Returns true, if inserting succeeded. |
|
295 | 295 | |
|
296 | 296 | */ |
|
297 | 297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
298 | 298 | { |
|
299 | 299 | Q_D(QAbstractBarSeries); |
|
300 | 300 | bool success = d->insert(index, set); |
|
301 | 301 | if (success) { |
|
302 | 302 | QList<QBarSet*> sets; |
|
303 | 303 | sets.append(set); |
|
304 | 304 | emit barsetsAdded(sets); |
|
305 | 305 | emit countChanged(); |
|
306 | 306 | } |
|
307 | 307 | return success; |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | /*! |
|
311 | 311 | Removes all of the bar sets from the series |
|
312 | 312 | */ |
|
313 | 313 | void QAbstractBarSeries::clear() |
|
314 | 314 | { |
|
315 | 315 | Q_D(QAbstractBarSeries); |
|
316 | 316 | QList<QBarSet *> sets = barSets(); |
|
317 | 317 | bool success = d->remove(sets); |
|
318 | 318 | if (success) { |
|
319 | 319 | emit barsetsRemoved(sets); |
|
320 | 320 | emit countChanged(); |
|
321 | 321 | } |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | /*! |
|
325 | 325 | Returns number of sets in series. |
|
326 | 326 | */ |
|
327 | 327 | int QAbstractBarSeries::count() const |
|
328 | 328 | { |
|
329 | 329 | Q_D(const QAbstractBarSeries); |
|
330 | 330 | return d->m_barSets.count(); |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | /*! |
|
334 | 334 | Returns a list of sets in series. Keeps ownership of sets. |
|
335 | 335 | */ |
|
336 | 336 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
337 | 337 | { |
|
338 | 338 | Q_D(const QAbstractBarSeries); |
|
339 | 339 | return d->m_barSets; |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | /*! |
|
343 | 343 | Sets the visibility of labels in series to \a visible |
|
344 | 344 | */ |
|
345 | 345 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
346 | 346 | { |
|
347 | 347 | Q_D(QAbstractBarSeries); |
|
348 | 348 | if (d->m_labelsVisible != visible) { |
|
349 | 349 | d->setLabelsVisible(visible); |
|
350 | 350 | emit labelsVisibleChanged(); |
|
351 | 351 | } |
|
352 | 352 | } |
|
353 | 353 | |
|
354 | 354 | /*! |
|
355 | 355 | Returns the visibility of labels |
|
356 | 356 | */ |
|
357 | 357 | bool QAbstractBarSeries::isLabelsVisible() const |
|
358 | 358 | { |
|
359 | 359 | Q_D(const QAbstractBarSeries); |
|
360 | 360 | return d->m_labelsVisible; |
|
361 | 361 | } |
|
362 | 362 | |
|
363 | 363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
364 | 364 | |
|
365 | 365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
366 | 366 | QAbstractSeriesPrivate(q), |
|
367 | 367 | m_barWidth(0.5), // Default value is 50% of category width |
|
368 | 368 | m_labelsVisible(false), |
|
369 | 369 | m_visible(true) |
|
370 | 370 | { |
|
371 | 371 | } |
|
372 | 372 | |
|
373 | 373 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
374 | 374 | { |
|
375 | 375 | // No categories defined. return count of longest set. |
|
376 | 376 | int count = 0; |
|
377 | 377 | for (int i=0; i<m_barSets.count(); i++) { |
|
378 | 378 | if (m_barSets.at(i)->count() > count) { |
|
379 | 379 | count = m_barSets.at(i)->count(); |
|
380 | 380 | } |
|
381 | 381 | } |
|
382 | 382 | |
|
383 | 383 | return count; |
|
384 | 384 | } |
|
385 | 385 | |
|
386 | 386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
387 | 387 | { |
|
388 | 388 | if (width < 0.0) { |
|
389 | 389 | width = 0.0; |
|
390 | 390 | } |
|
391 | 391 | m_barWidth = width; |
|
392 | 392 | emit updatedBars(); |
|
393 | 393 | } |
|
394 | 394 | |
|
395 | 395 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
396 | 396 | { |
|
397 | 397 | return m_barWidth; |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | 400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
401 | 401 | { |
|
402 | 402 | return m_barSets.at(index); |
|
403 | 403 | } |
|
404 | 404 | |
|
405 | 405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
406 | 406 | { |
|
407 | 407 | m_visible = visible; |
|
408 | 408 | emit updatedBars(); |
|
409 | 409 | } |
|
410 | 410 | |
|
411 | 411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
412 | 412 | { |
|
413 | 413 | m_labelsVisible = visible; |
|
414 | 414 | emit labelsVisibleChanged(visible); |
|
415 | 415 | } |
|
416 | 416 | |
|
417 | 417 | qreal QAbstractBarSeriesPrivate::min() |
|
418 | 418 | { |
|
419 | 419 | if (m_barSets.count() <= 0) { |
|
420 | 420 | return 0; |
|
421 | 421 | } |
|
422 | 422 | qreal min = INT_MAX; |
|
423 | 423 | |
|
424 | 424 | for (int i = 0; i < m_barSets.count(); i++) { |
|
425 | 425 | int categoryCount = m_barSets.at(i)->count(); |
|
426 | 426 | for (int j = 0; j < categoryCount; j++) { |
|
427 | 427 | qreal temp = m_barSets.at(i)->at(j); |
|
428 | 428 | if (temp < min) |
|
429 | 429 | min = temp; |
|
430 | 430 | } |
|
431 | 431 | } |
|
432 | 432 | return min; |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | qreal QAbstractBarSeriesPrivate::max() |
|
436 | 436 | { |
|
437 | 437 | if (m_barSets.count() <= 0) { |
|
438 | 438 | return 0; |
|
439 | 439 | } |
|
440 | 440 | qreal max = INT_MIN; |
|
441 | 441 | |
|
442 | 442 | for (int i = 0; i < m_barSets.count(); i++) { |
|
443 | 443 | int categoryCount = m_barSets.at(i)->count(); |
|
444 | 444 | for (int j = 0; j < categoryCount; j++) { |
|
445 | 445 | qreal temp = m_barSets.at(i)->at(j); |
|
446 | 446 | if (temp > max) |
|
447 | 447 | max = temp; |
|
448 | 448 | } |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | return max; |
|
452 | 452 | } |
|
453 | 453 | |
|
454 | 454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
455 | 455 | { |
|
456 | 456 | if ((set < 0) || (set >= m_barSets.count())) { |
|
457 | 457 | // No set, no value. |
|
458 | 458 | return 0; |
|
459 | 459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
460 | 460 | // No category, no value. |
|
461 | 461 | return 0; |
|
462 | 462 | } |
|
463 | 463 | |
|
464 | 464 | return m_barSets.at(set)->at(category); |
|
465 | 465 | } |
|
466 | 466 | |
|
467 | 467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
468 | 468 | { |
|
469 | 469 | if ((set < 0) || (set >= m_barSets.count())) { |
|
470 | 470 | // No set, no value. |
|
471 | 471 | return 0; |
|
472 | 472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
473 | 473 | // No category, no value. |
|
474 | 474 | return 0; |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | qreal value = m_barSets.at(set)->at(category); |
|
478 | 478 | qreal sum = categorySum(category); |
|
479 | 479 | if ( qFuzzyIsNull(sum) ) { |
|
480 | 480 | return 0; |
|
481 | 481 | } |
|
482 | 482 | |
|
483 | 483 | return value / sum; |
|
484 | 484 | } |
|
485 | 485 | |
|
486 | 486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
487 | 487 | { |
|
488 | 488 | qreal sum(0); |
|
489 | 489 | int count = m_barSets.count(); // Count sets |
|
490 | 490 | for (int set = 0; set < count; set++) { |
|
491 | 491 | if (category < m_barSets.at(set)->count()) |
|
492 | 492 | sum += m_barSets.at(set)->at(category); |
|
493 | 493 | } |
|
494 | 494 | return sum; |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
498 | 498 | { |
|
499 | 499 | qreal sum(0); |
|
500 | 500 | int count = m_barSets.count(); // Count sets |
|
501 | 501 | for (int set = 0; set < count; set++) { |
|
502 | 502 | if (category < m_barSets.at(set)->count()) |
|
503 | 503 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
504 | 504 | } |
|
505 | 505 | return sum; |
|
506 | 506 | } |
|
507 | 507 | |
|
508 | 508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
509 | 509 | { |
|
510 | 510 | qreal max = INT_MIN; |
|
511 | 511 | int count = categoryCount(); |
|
512 | 512 | for (int i = 0; i < count; i++) { |
|
513 | 513 | qreal sum = categorySum(i); |
|
514 | 514 | if (sum > max) |
|
515 | 515 | max = sum; |
|
516 | 516 | } |
|
517 | 517 | return max; |
|
518 | 518 | } |
|
519 | 519 | |
|
520 | 520 | qreal QAbstractBarSeriesPrivate::minX() |
|
521 | 521 | { |
|
522 | 522 | if (m_barSets.count() <= 0) { |
|
523 | 523 | return 0; |
|
524 | 524 | } |
|
525 | 525 | qreal min = INT_MAX; |
|
526 | 526 | |
|
527 | 527 | for (int i = 0; i < m_barSets.count(); i++) { |
|
528 | 528 | int categoryCount = m_barSets.at(i)->count(); |
|
529 | 529 | for (int j = 0; j < categoryCount; j++) { |
|
530 | 530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
531 | 531 | if (temp < min) |
|
532 | 532 | min = temp; |
|
533 | 533 | } |
|
534 | 534 | } |
|
535 | 535 | return min; |
|
536 | 536 | } |
|
537 | 537 | |
|
538 | 538 | qreal QAbstractBarSeriesPrivate::maxX() |
|
539 | 539 | { |
|
540 | 540 | if (m_barSets.count() <= 0) { |
|
541 | 541 | return 0; |
|
542 | 542 | } |
|
543 | 543 | qreal max = INT_MIN; |
|
544 | 544 | |
|
545 | 545 | for (int i = 0; i < m_barSets.count(); i++) { |
|
546 | 546 | int categoryCount = m_barSets.at(i)->count(); |
|
547 | 547 | for (int j = 0; j < categoryCount; j++) { |
|
548 | 548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
549 | 549 | if (temp > max) |
|
550 | 550 | max = temp; |
|
551 | 551 | } |
|
552 | 552 | } |
|
553 | 553 | |
|
554 | 554 | return max; |
|
555 | 555 | } |
|
556 | 556 | |
|
557 | 557 | |
|
558 | 558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
559 | 559 | { |
|
560 | 560 | qreal minX(domain.minX()); |
|
561 | 561 | qreal minY(domain.minY()); |
|
562 | 562 | qreal maxX(domain.maxX()); |
|
563 | 563 | qreal maxY(domain.maxY()); |
|
564 | 564 | int tickXCount(domain.tickXCount()); |
|
565 | 565 | int tickYCount(domain.tickYCount()); |
|
566 | 566 | |
|
567 | 567 | qreal seriesMinX = this->minX(); |
|
568 | 568 | qreal seriesMaxX = this->maxX(); |
|
569 | 569 | qreal y = max(); |
|
570 | 570 | minX = qMin(minX, seriesMinX - 0.5); |
|
571 | 571 | minY = qMin(minY, y); |
|
572 | 572 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
573 | 573 | maxY = qMax(maxY, y); |
|
574 | 574 | tickXCount = categoryCount()+1; |
|
575 | 575 | |
|
576 | 576 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
577 | 577 | } |
|
578 | 578 | |
|
579 | 579 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
580 | 580 | { |
|
581 | 581 | Q_Q(QAbstractBarSeries); |
|
582 | 582 | |
|
583 | 583 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
584 | 584 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
585 | 585 | presenter->animator()->addAnimation(bar); |
|
586 | 586 | } |
|
587 | 587 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
588 | 588 | return bar; |
|
589 | 589 | |
|
590 | 590 | } |
|
591 | 591 | |
|
592 | 592 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
593 | 593 | { |
|
594 | 594 | Q_Q(QAbstractBarSeries); |
|
595 | 595 | QList<LegendMarker*> markers; |
|
596 | 596 | foreach(QBarSet* set, q->barSets()) { |
|
597 | 597 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
598 | 598 | markers << marker; |
|
599 | 599 | } |
|
600 | 600 | |
|
601 | 601 | return markers; |
|
602 | 602 | } |
|
603 | 603 | |
|
604 | 604 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
605 | 605 | { |
|
606 | 606 | Q_Q(QAbstractBarSeries); |
|
607 | 607 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
608 | 608 | // Fail if set is already in list or set is null. |
|
609 | 609 | return false; |
|
610 | 610 | } |
|
611 | 611 | m_barSets.append(set); |
|
612 | 612 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
613 | 613 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
614 | 614 | emit restructuredBars(); // this notifies barchartitem |
|
615 | 615 | if (m_dataset) { |
|
616 | 616 | m_dataset->updateSeries(q); // this notifies legend |
|
617 | 617 | } |
|
618 | 618 | return true; |
|
619 | 619 | } |
|
620 | 620 | |
|
621 | 621 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
622 | 622 | { |
|
623 | 623 | Q_Q(QAbstractBarSeries); |
|
624 | 624 | if (!m_barSets.contains(set)) { |
|
625 | 625 | // Fail if set is not in list |
|
626 | 626 | return false; |
|
627 | 627 | } |
|
628 | 628 | m_barSets.removeOne(set); |
|
629 | 629 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
630 | 630 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
631 | 631 | emit restructuredBars(); // this notifies barchartitem |
|
632 | 632 | if (m_dataset) { |
|
633 | 633 | m_dataset->updateSeries(q); // this notifies legend |
|
634 | 634 | } |
|
635 | 635 | return true; |
|
636 | 636 | } |
|
637 | 637 | |
|
638 | 638 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
639 | 639 | { |
|
640 | 640 | Q_Q(QAbstractBarSeries); |
|
641 | 641 | foreach (QBarSet* set, sets) { |
|
642 | 642 | if ((set == 0) || (m_barSets.contains(set))) { |
|
643 | 643 | // Fail if any of the sets is null or is already appended. |
|
644 | 644 | return false; |
|
645 | 645 | } |
|
646 | 646 | if (sets.count(set) != 1) { |
|
647 | 647 | // Also fail if same set is more than once in given list. |
|
648 | 648 | return false; |
|
649 | 649 | } |
|
650 | 650 | } |
|
651 | 651 | |
|
652 | 652 | foreach (QBarSet* set, sets) { |
|
653 | 653 | m_barSets.append(set); |
|
654 | 654 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
655 | 655 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
656 | 656 | } |
|
657 | 657 | emit restructuredBars(); // this notifies barchartitem |
|
658 | 658 | if (m_dataset) { |
|
659 | 659 | m_dataset->updateSeries(q); // this notifies legend |
|
660 | 660 | } |
|
661 | 661 | return true; |
|
662 | 662 | } |
|
663 | 663 | |
|
664 | 664 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
665 | 665 | { |
|
666 | 666 | Q_Q(QAbstractBarSeries); |
|
667 | 667 | if (sets.count() == 0) { |
|
668 | 668 | return false; |
|
669 | 669 | } |
|
670 | 670 | foreach (QBarSet* set, sets) { |
|
671 | 671 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
672 | 672 | // Fail if any of the sets is null or is not in series |
|
673 | 673 | return false; |
|
674 | 674 | } |
|
675 | 675 | if (sets.count(set) != 1) { |
|
676 | 676 | // Also fail if same set is more than once in given list. |
|
677 | 677 | return false; |
|
678 | 678 | } |
|
679 | 679 | } |
|
680 | 680 | |
|
681 | 681 | foreach (QBarSet* set, sets) { |
|
682 | 682 | m_barSets.removeOne(set); |
|
683 | 683 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
684 | 684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
685 | 685 | } |
|
686 | 686 | |
|
687 | 687 | emit restructuredBars(); // this notifies barchartitem |
|
688 | 688 | if (m_dataset) { |
|
689 | 689 | m_dataset->updateSeries(q); // this notifies legend |
|
690 | 690 | } |
|
691 | 691 | return true; |
|
692 | 692 | } |
|
693 | 693 | |
|
694 | 694 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
695 | 695 | { |
|
696 | 696 | Q_Q(QAbstractBarSeries); |
|
697 | 697 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
698 | 698 | // Fail if set is already in list or set is null. |
|
699 | 699 | return false; |
|
700 | 700 | } |
|
701 | 701 | m_barSets.insert(index, set); |
|
702 | 702 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
703 | 703 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
704 | 704 | emit restructuredBars(); // this notifies barchartitem |
|
705 | 705 | if (m_dataset) { |
|
706 | 706 | m_dataset->updateSeries(q); // this notifies legend |
|
707 | 707 | } |
|
708 | 708 | return true; |
|
709 | 709 | } |
|
710 | 710 | |
|
711 | 711 | void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis) |
|
712 | 712 | { |
|
713 | 713 | Q_UNUSED(axis); |
|
714 | 714 | } |
|
715 | 715 | |
|
716 | 716 | void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis) |
|
717 | 717 | { |
|
718 | 718 | Q_UNUSED(axis) |
|
719 | 719 | } |
|
720 | 720 | |
|
721 | 721 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const |
|
722 | 722 | { |
|
723 | 723 | return QAbstractAxis::AxisTypeCategories; |
|
724 | 724 | } |
|
725 | 725 | |
|
726 | 726 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const |
|
727 | 727 | { |
|
728 | 728 | return QAbstractAxis::AxisTypeValues; |
|
729 | 729 | } |
|
730 | 730 | |
|
731 | 731 | #include "moc_qabstractbarseries.cpp" |
|
732 | 732 | #include "moc_qabstractbarseries_p.cpp" |
|
733 | 733 | |
|
734 | 734 | |
|
735 | 735 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,119 +1,119 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#include "q |
|
|
22 |
#include "q |
|
|
21 | #include "qbarseries.h" | |
|
22 | #include "qbarseries_p.h" | |
|
23 | 23 | #include "groupedbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | #include "qcategoriesaxis.h" |
|
28 | 28 | #include "qvaluesaxis.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 |
\class Q |
|
|
34 |
\brief Series for creating |
|
|
33 | \class QBarSeries | |
|
34 | \brief Series for creating bar chart | |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 |
Q |
|
|
38 |
as groups, where bars in same category are grouped next to each other. Q |
|
|
37 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
|
38 | as groups, where bars in same category are grouped next to each other. QBarSeries groups the data | |
|
39 | 39 | from sets to categories, which are defined by a QStringList. |
|
40 | 40 | |
|
41 | 41 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. |
|
42 | 42 | \image examples_groupedbarchart.png |
|
43 | 43 | |
|
44 | 44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries |
|
45 | 45 | */ |
|
46 | 46 | /*! |
|
47 |
\qmlclass |
|
|
47 | \qmlclass BarSeries QBarSeries | |
|
48 | 48 | \inherits AbstractBarSeries |
|
49 | 49 | |
|
50 | 50 | The following QML shows how to create a simple grouped bar chart: |
|
51 | 51 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
52 | 52 | \beginfloatleft |
|
53 | 53 | \image demos_qmlchart7.png |
|
54 | 54 | \endfloat |
|
55 | 55 | \clearfloat |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 |
Constructs empty Q |
|
|
60 |
Q |
|
|
59 | Constructs empty QBarSeries. | |
|
60 | QBarSeries is QObject which is a child of a \a parent. | |
|
61 | 61 | */ |
|
62 |
Q |
|
|
63 |
: QAbstractBarSeries(*new Q |
|
|
62 | QBarSeries::QBarSeries(QObject *parent) | |
|
63 | : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) | |
|
64 | 64 | { |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | Returns QChartSeries::SeriesTypeGroupedBar. |
|
69 | 69 | */ |
|
70 |
QAbstractSeries::SeriesType Q |
|
|
70 | QAbstractSeries::SeriesType QBarSeries::type() const | |
|
71 | 71 | { |
|
72 |
return QAbstractSeries::SeriesType |
|
|
72 | return QAbstractSeries::SeriesTypeBar; | |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 | 76 | |
|
77 |
Q |
|
|
77 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
|
78 | 78 | { |
|
79 | 79 | |
|
80 | 80 | } |
|
81 | 81 | |
|
82 |
void Q |
|
|
82 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
|
83 | 83 | { |
|
84 | 84 | qreal minX(domain.minX()); |
|
85 | 85 | qreal minY(domain.minY()); |
|
86 | 86 | qreal maxX(domain.maxX()); |
|
87 | 87 | qreal maxY(domain.maxY()); |
|
88 | 88 | int tickXCount(domain.tickXCount()); |
|
89 | 89 | int tickYCount(domain.tickYCount()); |
|
90 | 90 | |
|
91 | 91 | qreal x = categoryCount(); |
|
92 | 92 | qreal y = max(); |
|
93 | 93 | minX = qMin(minX, -0.5); |
|
94 | 94 | minY = qMin(minY, y); |
|
95 | 95 | maxX = qMax(maxX, x - 0.5); |
|
96 | 96 | maxY = qMax(maxY, y); |
|
97 | 97 | tickXCount = x+1; |
|
98 | 98 | |
|
99 | 99 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | |
|
103 |
Chart* Q |
|
|
103 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
|
104 | 104 | { |
|
105 |
Q_Q(Q |
|
|
105 | Q_Q(QBarSeries); | |
|
106 | 106 | |
|
107 | 107 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); |
|
108 | 108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
109 | 109 | presenter->animator()->addAnimation(bar); |
|
110 | 110 | } |
|
111 | 111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
112 | 112 | return bar; |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | |
|
116 |
#include "moc_q |
|
|
116 | #include "moc_qbarseries.cpp" | |
|
117 | 117 | |
|
118 | 118 | QTCOMMERCIALCHART_END_NAMESPACE |
|
119 | 119 |
@@ -1,45 +1,45 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef |
|
|
22 |
#define |
|
|
21 | #ifndef QBARSERIES_H | |
|
22 | #define QBARSERIES_H | |
|
23 | 23 | |
|
24 | 24 | #include <QStringList> |
|
25 | 25 | #include <qabstractbarseries.h> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 |
class Q |
|
|
29 | class QBarSeriesPrivate; | |
|
30 | 30 | |
|
31 |
class QTCOMMERCIALCHART_EXPORT Q |
|
|
31 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractBarSeries | |
|
32 | 32 | { |
|
33 | 33 | Q_OBJECT |
|
34 | 34 | public: |
|
35 |
explicit Q |
|
|
35 | explicit QBarSeries(QObject *parent = 0); | |
|
36 | 36 | QAbstractSeries::SeriesType type() const; |
|
37 | 37 | |
|
38 | 38 | private: |
|
39 |
Q_DECLARE_PRIVATE(Q |
|
|
40 |
Q_DISABLE_COPY(Q |
|
|
39 | Q_DECLARE_PRIVATE(QBarSeries) | |
|
40 | Q_DISABLE_COPY(QBarSeries) | |
|
41 | 41 | }; |
|
42 | 42 | |
|
43 | 43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
44 | 44 | |
|
45 |
#endif // |
|
|
45 | #endif // QBARSERIES_H |
@@ -1,52 +1,52 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 |
#ifndef Q |
|
|
31 |
#define Q |
|
|
30 | #ifndef QBARSERIES_P_H | |
|
31 | #define QBARSERIES_P_H | |
|
32 | 32 | |
|
33 | 33 | #include "qabstractbarseries_p.h" |
|
34 | 34 | #include "domain_p.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | |
|
39 |
class Q |
|
|
39 | class QBarSeriesPrivate: public QAbstractBarSeriesPrivate | |
|
40 | 40 | { |
|
41 | 41 | public: |
|
42 |
Q |
|
|
42 | QBarSeriesPrivate(QBarSeries* q); | |
|
43 | 43 | Chart* createGraphics(ChartPresenter* presenter); |
|
44 | 44 | void scaleDomain(Domain& domain); |
|
45 | 45 | |
|
46 | 46 | private: |
|
47 |
Q_DECLARE_PUBLIC(Q |
|
|
47 | Q_DECLARE_PUBLIC(QBarSeries) | |
|
48 | 48 | }; |
|
49 | 49 | |
|
50 | 50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | 51 | |
|
52 |
#endif // Q |
|
|
52 | #endif // QBARSERIES_P_H |
@@ -1,616 +1,616 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarset.h" |
|
22 | 22 | #include "qbarset_p.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \class QBarSet |
|
28 | 28 | \brief Building block for different bar charts |
|
29 | 29 | |
|
30 | 30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
31 | 31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
32 | 32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
33 | 33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
34 | 34 | |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 |
\sa QAbstractBarSeries, Q |
|
|
37 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries | |
|
38 | 38 | */ |
|
39 | 39 | /*! |
|
40 | 40 | \qmlclass BarSet QBarSet |
|
41 | 41 | |
|
42 | 42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
43 | 43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
44 | 44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
45 | 45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
46 |
\sa AbstractBarSeries, |
|
|
46 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries | |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \property QBarSet::label |
|
51 | 51 | Defines the label of the barSet. |
|
52 | 52 | */ |
|
53 | 53 | /*! |
|
54 | 54 | \qmlproperty string BarSet::label |
|
55 | 55 | Defines the label of the barSet. |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \property QBarSet::pen |
|
60 | 60 | \brief Defines the pen used by the barSet. |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QBarSet::brush |
|
65 | 65 | \brief Defines the brush used by the barSet. |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \property QBarSet::labelBrush |
|
70 | 70 | \brief Defines the brush used by the barSet's label. |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \property QBarSet::labelFont |
|
75 | 75 | \brief Defines the font used by the barSet's label. |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | 79 | \qmlproperty Font BarSet::labelFont |
|
80 | 80 | Defines the font used by the barSet's label. |
|
81 | 81 | |
|
82 | 82 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \property QBarSet::color |
|
87 | 87 | The fill (brush) color of the bar set. |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty color BarSet::color |
|
91 | 91 | The fill (brush) color of the bar set. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QBarSet::borderColor |
|
96 | 96 | The line (pen) color of the bar set. |
|
97 | 97 | */ |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty color BarSet::borderColor |
|
100 | 100 | The line (pen) color of the bar set. |
|
101 | 101 | */ |
|
102 | 102 | |
|
103 | 103 | /*! |
|
104 | 104 | \property QBarSet::labelColor |
|
105 | 105 | The text (label) color of the bar set. |
|
106 | 106 | */ |
|
107 | 107 | /*! |
|
108 | 108 | \qmlproperty color BarSet::labelColor |
|
109 | 109 | The text (label) color of the bar set. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \fn void QBarSet::clicked(int index) |
|
114 | 114 | |
|
115 | 115 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
116 | 116 | Clicked bar inside set is indexed by \a index |
|
117 | 117 | */ |
|
118 | 118 | |
|
119 | 119 | /*! |
|
120 | 120 | \fn void QBarSet::hovered(bool status) |
|
121 | 121 | |
|
122 | 122 | The signal is emitted if mouse is hovered on top of barset. |
|
123 | 123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | |
|
127 | 127 | /*! |
|
128 | 128 | \fn void QBarSet::labelChanged() |
|
129 | 129 | This signal is emitted when the label of the barSet has changed. |
|
130 | 130 | \sa label |
|
131 | 131 | */ |
|
132 | 132 | /*! |
|
133 | 133 | \qmlsignal BarSet::onLabelChanged() |
|
134 | 134 | This signal is emitted when the label of the barSet has changed. |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \fn void QBarSet::penChanged() |
|
139 | 139 | This signal is emitted when the pen of the barSet has changed. |
|
140 | 140 | \sa pen |
|
141 | 141 | */ |
|
142 | 142 | |
|
143 | 143 | /*! |
|
144 | 144 | \fn void QBarSet::brushChanged() |
|
145 | 145 | This signal is emitted when the brush of the barSet has changed. |
|
146 | 146 | \sa brush |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \fn void QBarSet::labelBrushChanged() |
|
151 | 151 | This signal is emitted when the brush of the barSet's label has changed. |
|
152 | 152 | \sa labelBrush |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \fn void QBarSet::labelFontChanged() |
|
157 | 157 | This signal is emitted when the font of the barSet's label has changed. |
|
158 | 158 | \sa labelBrush |
|
159 | 159 | */ |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | \fn void QBarSet::colorChanged(QColor) |
|
163 | 163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
164 | 164 | */ |
|
165 | 165 | /*! |
|
166 | 166 | \qmlsignal BarSet::onColorChanged(color color) |
|
167 | 167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
168 | 168 | */ |
|
169 | 169 | |
|
170 | 170 | /*! |
|
171 | 171 | \fn void QBarSet::borderColorChanged(QColor) |
|
172 | 172 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
173 | 173 | */ |
|
174 | 174 | /*! |
|
175 | 175 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
176 | 176 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
177 | 177 | */ |
|
178 | 178 | |
|
179 | 179 | /*! |
|
180 | 180 | \fn void QBarSet::labelColorChanged(QColor) |
|
181 | 181 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
182 | 182 | */ |
|
183 | 183 | /*! |
|
184 | 184 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
185 | 185 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
186 | 186 | */ |
|
187 | 187 | |
|
188 | 188 | /*! |
|
189 | 189 | \fn void QBarSet::valuesAdded(int index, int count) |
|
190 | 190 | This signal is emitted when new values have been added to the set. |
|
191 | 191 | Parameter \a index indicates the position of the first inserted value. |
|
192 | 192 | Parameter \a count is the number of iserted values. |
|
193 | 193 | \sa append(), insert() |
|
194 | 194 | */ |
|
195 | 195 | /*! |
|
196 | 196 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
197 | 197 | This signal is emitted when new values have been added to the set. |
|
198 | 198 | Parameter \a index indicates the position of the first inserted value. |
|
199 | 199 | Parameter \a count is the number of iserted values. |
|
200 | 200 | */ |
|
201 | 201 | |
|
202 | 202 | /*! |
|
203 | 203 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
204 | 204 | This signal is emitted values have been removed from the set. |
|
205 | 205 | Parameter \a index indicates the position of the first removed value. |
|
206 | 206 | Parameter \a count is the number of removed values. |
|
207 | 207 | \sa remove() |
|
208 | 208 | */ |
|
209 | 209 | /*! |
|
210 | 210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
211 | 211 | This signal is emitted values have been removed from the set. |
|
212 | 212 | Parameter \a index indicates the position of the first removed value. |
|
213 | 213 | Parameter \a count is the number of removed values. |
|
214 | 214 | */ |
|
215 | 215 | |
|
216 | 216 | /*! |
|
217 | 217 | \fn void QBarSet::valueChanged(int index) |
|
218 | 218 | This signal is emitted values the value in the set has been modified. |
|
219 | 219 | Parameter \a index indicates the position of the modified value. |
|
220 | 220 | \sa at() |
|
221 | 221 | */ |
|
222 | 222 | /*! |
|
223 | 223 | \qmlsignal BarSet::onValueChanged(int index) |
|
224 | 224 | This signal is emitted values the value in the set has been modified. |
|
225 | 225 | Parameter \a index indicates the position of the modified value. |
|
226 | 226 | */ |
|
227 | 227 | |
|
228 | 228 | /*! |
|
229 | 229 | \qmlproperty int BarSet::count |
|
230 | 230 | The count of values on the barset |
|
231 | 231 | */ |
|
232 | 232 | |
|
233 | 233 | /*! |
|
234 | 234 | \qmlproperty QVariantList BarSet::values |
|
235 | 235 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of |
|
236 | 236 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
237 | 237 | x-coordinate. For example: |
|
238 | 238 | \code |
|
239 | 239 | myBarSet1.values = [0, 5, 1, 5]; |
|
240 | 240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
241 | 241 | \endcode |
|
242 | 242 | */ |
|
243 | 243 | |
|
244 | 244 | /*! |
|
245 | 245 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
246 | 246 | */ |
|
247 | 247 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
248 | 248 | : QObject(parent) |
|
249 | 249 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
250 | 250 | { |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | /*! |
|
254 | 254 | Destroys the barset |
|
255 | 255 | */ |
|
256 | 256 | QBarSet::~QBarSet() |
|
257 | 257 | { |
|
258 | 258 | // NOTE: d_ptr destroyed by QObject |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | /*! |
|
262 | 262 | Sets new \a label for set. |
|
263 | 263 | */ |
|
264 | 264 | void QBarSet::setLabel(const QString label) |
|
265 | 265 | { |
|
266 | 266 | d_ptr->m_label = label; |
|
267 | 267 | emit labelChanged(); |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | /*! |
|
271 | 271 | Returns label of the set. |
|
272 | 272 | */ |
|
273 | 273 | QString QBarSet::label() const |
|
274 | 274 | { |
|
275 | 275 | return d_ptr->m_label; |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | 279 | Appends new value \a value to the end of set. |
|
280 | 280 | */ |
|
281 | 281 | void QBarSet::append(const qreal value) |
|
282 | 282 | { |
|
283 | 283 | // Convert to QPointF |
|
284 | 284 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
285 | 285 | } |
|
286 | 286 | |
|
287 | 287 | /*! |
|
288 | 288 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
289 | 289 | are appended to end of barset |
|
290 | 290 | \sa append() |
|
291 | 291 | */ |
|
292 | 292 | void QBarSet::append(const QList<qreal> &values) |
|
293 | 293 | { |
|
294 | 294 | int index = d_ptr->m_values.count(); |
|
295 | 295 | d_ptr->append(values); |
|
296 | 296 | emit valuesAdded(index, values.count()); |
|
297 | 297 | } |
|
298 | 298 | |
|
299 | 299 | /*! |
|
300 | 300 | Convinience operator. Same as append, with real \a value. |
|
301 | 301 | \sa append() |
|
302 | 302 | */ |
|
303 | 303 | QBarSet& QBarSet::operator << (const qreal &value) |
|
304 | 304 | { |
|
305 | 305 | // append(value); |
|
306 | 306 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
307 | 307 | return *this; |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | /*! |
|
311 | 311 | Inserts new \a value on the \a index position. |
|
312 | 312 | The value that is currently at this postion is moved to postion index + 1 |
|
313 | 313 | \sa remove() |
|
314 | 314 | */ |
|
315 | 315 | void QBarSet::insert(const int index, const qreal value) |
|
316 | 316 | { |
|
317 | 317 | d_ptr->insert(index, value); |
|
318 | 318 | emit valuesAdded(index,1); |
|
319 | 319 | } |
|
320 | 320 | |
|
321 | 321 | /*! |
|
322 | 322 | Removes \a count number of values from the set starting at \a index. |
|
323 | 323 | \sa insert() |
|
324 | 324 | */ |
|
325 | 325 | void QBarSet::remove(const int index, const int count) |
|
326 | 326 | { |
|
327 | 327 | int removedCount = d_ptr->remove(index,count); |
|
328 | 328 | if (removedCount > 0) { |
|
329 | 329 | emit valuesRemoved(index,removedCount); |
|
330 | 330 | } |
|
331 | 331 | return; |
|
332 | 332 | } |
|
333 | 333 | |
|
334 | 334 | /*! |
|
335 | 335 | Sets a new value \a value to set, indexed by \a index |
|
336 | 336 | */ |
|
337 | 337 | void QBarSet::replace(const int index, const qreal value) |
|
338 | 338 | { |
|
339 | 339 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
340 | 340 | d_ptr->replace(index,value); |
|
341 | 341 | emit valueChanged(index); |
|
342 | 342 | } |
|
343 | 343 | } |
|
344 | 344 | |
|
345 | 345 | |
|
346 | 346 | /*! |
|
347 | 347 | Returns value of set indexed by \a index. |
|
348 | 348 | If the index is out of bounds 0.0 is returned. |
|
349 | 349 | */ |
|
350 | 350 | qreal QBarSet::at(const int index) const |
|
351 | 351 | { |
|
352 | 352 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
353 | 353 | return 0; |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | return d_ptr->m_values.at(index).y(); |
|
357 | 357 | } |
|
358 | 358 | |
|
359 | 359 | /*! |
|
360 | 360 | Returns value of set indexed by \a index. |
|
361 | 361 | If the index is out of bounds 0.0 is returned. |
|
362 | 362 | */ |
|
363 | 363 | qreal QBarSet::operator [](const int index) const |
|
364 | 364 | { |
|
365 | 365 | return at(index); |
|
366 | 366 | } |
|
367 | 367 | |
|
368 | 368 | /*! |
|
369 | 369 | Returns count of values in set. |
|
370 | 370 | */ |
|
371 | 371 | int QBarSet::count() const |
|
372 | 372 | { |
|
373 | 373 | return d_ptr->m_values.count(); |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | /*! |
|
377 | 377 | Returns sum of all values in barset. |
|
378 | 378 | */ |
|
379 | 379 | qreal QBarSet::sum() const |
|
380 | 380 | { |
|
381 | 381 | qreal total(0); |
|
382 | 382 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
383 | 383 | total += d_ptr->m_values.at(i).y(); |
|
384 | 384 | } |
|
385 | 385 | return total; |
|
386 | 386 | } |
|
387 | 387 | |
|
388 | 388 | /*! |
|
389 | 389 | Sets pen for set. Bars of this set are drawn using \a pen |
|
390 | 390 | */ |
|
391 | 391 | void QBarSet::setPen(const QPen &pen) |
|
392 | 392 | { |
|
393 | 393 | if(d_ptr->m_pen!=pen){ |
|
394 | 394 | d_ptr->m_pen = pen; |
|
395 | 395 | emit d_ptr->updatedBars(); |
|
396 | 396 | emit penChanged(); |
|
397 | 397 | } |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | 400 | /*! |
|
401 | 401 | Returns pen of the set. |
|
402 | 402 | */ |
|
403 | 403 | QPen QBarSet::pen() const |
|
404 | 404 | { |
|
405 | 405 | return d_ptr->m_pen; |
|
406 | 406 | } |
|
407 | 407 | |
|
408 | 408 | /*! |
|
409 | 409 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
410 | 410 | */ |
|
411 | 411 | void QBarSet::setBrush(const QBrush &brush) |
|
412 | 412 | { |
|
413 | 413 | if(d_ptr->m_brush!=brush){ |
|
414 | 414 | d_ptr->m_brush = brush; |
|
415 | 415 | emit d_ptr->updatedBars(); |
|
416 | 416 | emit brushChanged(); |
|
417 | 417 | } |
|
418 | 418 | } |
|
419 | 419 | |
|
420 | 420 | /*! |
|
421 | 421 | Returns brush of the set. |
|
422 | 422 | */ |
|
423 | 423 | QBrush QBarSet::brush() const |
|
424 | 424 | { |
|
425 | 425 | return d_ptr->m_brush; |
|
426 | 426 | } |
|
427 | 427 | |
|
428 | 428 | /*! |
|
429 | 429 | Sets \a brush of the values that are drawn on top of this barset |
|
430 | 430 | */ |
|
431 | 431 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
432 | 432 | { |
|
433 | 433 | if(d_ptr->m_labelBrush!=brush){ |
|
434 | 434 | d_ptr->m_labelBrush = brush; |
|
435 | 435 | emit d_ptr->updatedBars(); |
|
436 | 436 | emit labelBrushChanged(); |
|
437 | 437 | } |
|
438 | 438 | } |
|
439 | 439 | |
|
440 | 440 | /*! |
|
441 | 441 | Returns brush of the values that are drawn on top of this barset |
|
442 | 442 | */ |
|
443 | 443 | QBrush QBarSet::labelBrush() const |
|
444 | 444 | { |
|
445 | 445 | return d_ptr->m_labelBrush; |
|
446 | 446 | } |
|
447 | 447 | |
|
448 | 448 | /*! |
|
449 | 449 | Sets the \a font for values that are drawn on top of this barset |
|
450 | 450 | */ |
|
451 | 451 | void QBarSet::setLabelFont(const QFont &font) |
|
452 | 452 | { |
|
453 | 453 | if(d_ptr->m_labelFont!=font) { |
|
454 | 454 | d_ptr->m_labelFont = font; |
|
455 | 455 | emit d_ptr->updatedBars(); |
|
456 | 456 | emit labelFontChanged(); |
|
457 | 457 | } |
|
458 | 458 | |
|
459 | 459 | } |
|
460 | 460 | |
|
461 | 461 | /*! |
|
462 | 462 | Returns the pen for values that are drawn on top of this barset |
|
463 | 463 | */ |
|
464 | 464 | QFont QBarSet::labelFont() const |
|
465 | 465 | { |
|
466 | 466 | return d_ptr->m_labelFont; |
|
467 | 467 | } |
|
468 | 468 | |
|
469 | 469 | /*! |
|
470 | 470 | Returns the color of the brush of barset. |
|
471 | 471 | */ |
|
472 | 472 | QColor QBarSet::color() |
|
473 | 473 | { |
|
474 | 474 | return brush().color(); |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | /*! |
|
478 | 478 | Sets the \a color of brush for this barset |
|
479 | 479 | */ |
|
480 | 480 | void QBarSet::setColor(QColor color) |
|
481 | 481 | { |
|
482 | 482 | QBrush b = brush(); |
|
483 | 483 | if (b.color() != color) { |
|
484 | 484 | b.setColor(color); |
|
485 | 485 | setBrush(b); |
|
486 | 486 | emit colorChanged(color); |
|
487 | 487 | } |
|
488 | 488 | } |
|
489 | 489 | |
|
490 | 490 | /*! |
|
491 | 491 | Returns the color of pen of this barset |
|
492 | 492 | */ |
|
493 | 493 | QColor QBarSet::borderColor() |
|
494 | 494 | { |
|
495 | 495 | return pen().color(); |
|
496 | 496 | } |
|
497 | 497 | |
|
498 | 498 | /*! |
|
499 | 499 | Sets the color of pen for this barset |
|
500 | 500 | */ |
|
501 | 501 | void QBarSet::setBorderColor(QColor color) |
|
502 | 502 | { |
|
503 | 503 | QPen p = pen(); |
|
504 | 504 | if (p.color() != color) { |
|
505 | 505 | p.setColor(color); |
|
506 | 506 | setPen(p); |
|
507 | 507 | emit borderColorChanged(color); |
|
508 | 508 | } |
|
509 | 509 | } |
|
510 | 510 | |
|
511 | 511 | /*! |
|
512 | 512 | Returns the color of labels of this barset |
|
513 | 513 | */ |
|
514 | 514 | QColor QBarSet::labelColor() |
|
515 | 515 | { |
|
516 | 516 | return labelBrush().color(); |
|
517 | 517 | } |
|
518 | 518 | |
|
519 | 519 | /*! |
|
520 | 520 | Sets the color of labels for this barset |
|
521 | 521 | */ |
|
522 | 522 | void QBarSet::setLabelColor(QColor color) |
|
523 | 523 | { |
|
524 | 524 | QBrush b = labelBrush(); |
|
525 | 525 | if (b.color() != color) { |
|
526 | 526 | b.setColor(color); |
|
527 | 527 | setLabelBrush(b); |
|
528 | 528 | emit labelColorChanged(color); |
|
529 | 529 | } |
|
530 | 530 | } |
|
531 | 531 | |
|
532 | 532 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
533 | 533 | |
|
534 | 534 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
535 | 535 | q_ptr(parent), |
|
536 | 536 | m_label(label) |
|
537 | 537 | { |
|
538 | 538 | } |
|
539 | 539 | |
|
540 | 540 | QBarSetPrivate::~QBarSetPrivate() |
|
541 | 541 | { |
|
542 | 542 | } |
|
543 | 543 | |
|
544 | 544 | void QBarSetPrivate::append(QPointF value) |
|
545 | 545 | { |
|
546 | 546 | m_values.append(value); |
|
547 | 547 | emit restructuredBars(); |
|
548 | 548 | } |
|
549 | 549 | |
|
550 | 550 | void QBarSetPrivate::append(QList<QPointF> values) |
|
551 | 551 | { |
|
552 | 552 | for (int i=0; i<values.count(); i++) { |
|
553 | 553 | m_values.append(values.at(i)); |
|
554 | 554 | } |
|
555 | 555 | emit restructuredBars(); |
|
556 | 556 | } |
|
557 | 557 | |
|
558 | 558 | void QBarSetPrivate::append(QList<qreal> values) |
|
559 | 559 | { |
|
560 | 560 | int index = m_values.count(); |
|
561 | 561 | for (int i=0; i<values.count(); i++) { |
|
562 | 562 | m_values.append(QPointF(index,values.at(i))); |
|
563 | 563 | index++; |
|
564 | 564 | } |
|
565 | 565 | emit restructuredBars(); |
|
566 | 566 | } |
|
567 | 567 | |
|
568 | 568 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
569 | 569 | { |
|
570 | 570 | m_values.insert(index, QPointF(index, value)); |
|
571 | 571 | emit restructuredBars(); |
|
572 | 572 | } |
|
573 | 573 | |
|
574 | 574 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
575 | 575 | { |
|
576 | 576 | m_values.insert(index, value); |
|
577 | 577 | emit restructuredBars(); |
|
578 | 578 | } |
|
579 | 579 | |
|
580 | 580 | int QBarSetPrivate::remove(const int index, const int count) |
|
581 | 581 | { |
|
582 | 582 | int removeCount = count; |
|
583 | 583 | |
|
584 | 584 | if ((index <0) || (m_values.count() == 0)) { |
|
585 | 585 | // Invalid index or not values in list, remove nothing. |
|
586 | 586 | return 0; |
|
587 | 587 | } else if ((index + count) > m_values.count()) { |
|
588 | 588 | // Trying to remove more items than list has. Limit amount to be removed. |
|
589 | 589 | removeCount = m_values.count() - index; |
|
590 | 590 | } |
|
591 | 591 | |
|
592 | 592 | int c = 0; |
|
593 | 593 | while (c < removeCount) { |
|
594 | 594 | m_values.removeAt(index); |
|
595 | 595 | c++; |
|
596 | 596 | } |
|
597 | 597 | emit restructuredBars(); |
|
598 | 598 | return removeCount; |
|
599 | 599 | } |
|
600 | 600 | |
|
601 | 601 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
602 | 602 | { |
|
603 | 603 | m_values.replace(index,QPointF(index,value)); |
|
604 | 604 | emit updatedBars(); |
|
605 | 605 | } |
|
606 | 606 | |
|
607 | 607 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
608 | 608 | { |
|
609 | 609 | m_values.replace(index,value); |
|
610 | 610 | emit updatedBars(); |
|
611 | 611 | } |
|
612 | 612 | |
|
613 | 613 | #include "moc_qbarset.cpp" |
|
614 | 614 | #include "moc_qbarset_p.cpp" |
|
615 | 615 | |
|
616 | 616 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,248 +1,248 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qvbarmodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QVBarModelMapper |
|
27 | 27 | \brief Vertical model mapper for bar series |
|
28 | 28 | \mainclass |
|
29 | 29 | |
|
30 | 30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
31 | 31 | Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. |
|
32 | 32 | Model mapper maintains equal size of all the BarSets. |
|
33 | 33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
34 | 34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
35 | 35 | */ |
|
36 | 36 | /*! |
|
37 | 37 | \qmlclass VBarModelMapper |
|
38 | 38 | \mainclass |
|
39 | 39 | |
|
40 | 40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source |
|
41 | 41 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. |
|
42 | 42 | VBarModelMapper keeps the series and the model in sync. |
|
43 | 43 | |
|
44 | 44 | The following QML example would create a bar series with three bar sets (assuming the |
|
45 | 45 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be |
|
46 | 46 | defined by the horizontal header (of the column). |
|
47 | 47 | \code |
|
48 |
|
|
|
48 | BarSeries { | |
|
49 | 49 | VBarModelMapper { |
|
50 | 50 | model: myCustomModel // QAbstractItemModel derived implementation |
|
51 | 51 | firstBarSetColumn: 1 |
|
52 | 52 | lastBarSetColumn: 3 |
|
53 | 53 | firstRow: 1 |
|
54 | 54 | } |
|
55 | 55 | } |
|
56 | 56 | \endcode |
|
57 | 57 | */ |
|
58 | 58 | |
|
59 | 59 | /*! |
|
60 | 60 | \property QVBarModelMapper::series |
|
61 | 61 | \brief Defines the QPieSeries object that is used by the mapper. |
|
62 | 62 | |
|
63 | 63 | All the data in the series is discarded when it is set to the mapper. |
|
64 | 64 | When new series is specified the old series is disconnected (it preserves its data) |
|
65 | 65 | */ |
|
66 | 66 | /*! |
|
67 | 67 | \qmlproperty AbstractBarSeries VBarModelMapper::series |
|
68 | 68 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
69 | 69 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
70 | 70 | */ |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | \property QVBarModelMapper::model |
|
74 | 74 | \brief Defines the model that is used by the mapper. |
|
75 | 75 | */ |
|
76 | 76 | /*! |
|
77 | 77 | \qmlproperty SomeModel VBarModelMapper::model |
|
78 | 78 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
79 | 79 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
80 | 80 | and modifying the data of the cells. |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \property QVBarModelMapper::firstBarSetColumn |
|
85 | 85 | \brief Defines which column of the model is used as the data source for the first bar set |
|
86 | 86 | Default value is: -1 (invalid mapping) |
|
87 | 87 | */ |
|
88 | 88 | /*! |
|
89 | 89 | \qmlproperty int VBarModelMapper::firstBarSetColumn |
|
90 | 90 | Defines which column of the model is used as the data source for the first bar set. Default value |
|
91 | 91 | is: -1 (invalid mapping). |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QVBarModelMapper::lastBarSetColumn |
|
96 | 96 | \brief Defines which column of the model is used as the data source for the last bar set |
|
97 | 97 | Default value is: -1 (invalid mapping) |
|
98 | 98 | */ |
|
99 | 99 | /*! |
|
100 | 100 | \qmlproperty int VBarModelMapper::lastBarSetColumn |
|
101 | 101 | Defines which column of the model is used as the data source for the last bar set. Default |
|
102 | 102 | value is: -1 (invalid mapping). |
|
103 | 103 | */ |
|
104 | 104 | |
|
105 | 105 | /*! |
|
106 | 106 | \property QVBarModelMapper::firstRow |
|
107 | 107 | \brief Defines which row of the model contains the first values of the QBarSets in the series. |
|
108 | 108 | Minimal and default value is: 0 |
|
109 | 109 | */ |
|
110 | 110 | /*! |
|
111 | 111 | \qmlproperty int VBarModelMapper::firstRow |
|
112 | 112 | Defines which row of the model contains the first values of the QBarSets in the series. |
|
113 | 113 | The default value is 0. |
|
114 | 114 | */ |
|
115 | 115 | |
|
116 | 116 | /*! |
|
117 | 117 | \property QVBarModelMapper::rowCount |
|
118 | 118 | \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries |
|
119 | 119 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
120 | 120 | */ |
|
121 | 121 | /*! |
|
122 | 122 | \qmlproperty int VBarModelMapper::rowCount |
|
123 | 123 | Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is |
|
124 | 124 | -1 (count limited by the number of rows in the model) |
|
125 | 125 | */ |
|
126 | 126 | |
|
127 | 127 | /*! |
|
128 | 128 | \fn void QVBarModelMapper::seriesReplaced() |
|
129 | 129 | |
|
130 | 130 | Emitted when the series to which mapper is connected to has changed. |
|
131 | 131 | */ |
|
132 | 132 | |
|
133 | 133 | /*! |
|
134 | 134 | \fn void QVBarModelMapper::modelReplaced() |
|
135 | 135 | |
|
136 | 136 | Emitted when the model to which mapper is connected to has changed. |
|
137 | 137 | */ |
|
138 | 138 | |
|
139 | 139 | /*! |
|
140 | 140 | \fn void QVBarModelMapper::firstBarSetColumnChanged() |
|
141 | 141 | Emitted when the firstBarSetColumn has changed. |
|
142 | 142 | */ |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | \fn void QVBarModelMapper::lastBarSetColumnChanged() |
|
146 | 146 | Emitted when the lastBarSetColumn has changed. |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \fn void QVBarModelMapper::firstRowChanged() |
|
151 | 151 | Emitted when the firstRow has changed. |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | 155 | \fn void QVBarModelMapper::rowCountChanged() |
|
156 | 156 | Emitted when the rowCount has changed. |
|
157 | 157 | */ |
|
158 | 158 | |
|
159 | 159 | /*! |
|
160 | 160 | Constructs a mapper object which is a child of \a parent. |
|
161 | 161 | */ |
|
162 | 162 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
163 | 163 | QBarModelMapper(parent) |
|
164 | 164 | { |
|
165 | 165 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | QAbstractItemModel* QVBarModelMapper::model() const |
|
169 | 169 | { |
|
170 | 170 | return QBarModelMapper::model(); |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | void QVBarModelMapper::setModel(QAbstractItemModel *model) |
|
174 | 174 | { |
|
175 | 175 | if (model != QBarModelMapper::model()) { |
|
176 | 176 | QBarModelMapper::setModel(model); |
|
177 | 177 | emit modelReplaced(); |
|
178 | 178 | } |
|
179 | 179 | } |
|
180 | 180 | |
|
181 | 181 | QAbstractBarSeries* QVBarModelMapper::series() const |
|
182 | 182 | { |
|
183 | 183 | return QBarModelMapper::series(); |
|
184 | 184 | } |
|
185 | 185 | |
|
186 | 186 | void QVBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
187 | 187 | { |
|
188 | 188 | if (series != QBarModelMapper::series()) { |
|
189 | 189 | QBarModelMapper::setSeries(series); |
|
190 | 190 | emit seriesReplaced(); |
|
191 | 191 | } |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | int QVBarModelMapper::firstBarSetColumn() const |
|
195 | 195 | { |
|
196 | 196 | return QBarModelMapper::firstBarSetSection(); |
|
197 | 197 | } |
|
198 | 198 | |
|
199 | 199 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
200 | 200 | { |
|
201 | 201 | if (firstBarSetColumn != firstBarSetSection()) { |
|
202 | 202 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
203 | 203 | emit firstBarSetColumnChanged(); |
|
204 | 204 | } |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | int QVBarModelMapper::lastBarSetColumn() const |
|
208 | 208 | { |
|
209 | 209 | return QBarModelMapper::lastBarSetSection(); |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
213 | 213 | { |
|
214 | 214 | if (lastBarSetColumn != lastBarSetSection()) { |
|
215 | 215 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
216 | 216 | emit lastBarSetColumnChanged(); |
|
217 | 217 | } |
|
218 | 218 | } |
|
219 | 219 | |
|
220 | 220 | int QVBarModelMapper::firstRow() const |
|
221 | 221 | { |
|
222 | 222 | return QBarModelMapper::first(); |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | void QVBarModelMapper::setFirstRow(int firstRow) |
|
226 | 226 | { |
|
227 | 227 | if (firstRow != first()) { |
|
228 | 228 | QBarModelMapper::setFirst(firstRow); |
|
229 | 229 | emit firstRowChanged(); |
|
230 | 230 | } |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | int QVBarModelMapper::rowCount() const |
|
234 | 234 | { |
|
235 | 235 | return QBarModelMapper::count(); |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | void QVBarModelMapper::setRowCount(int rowCount) |
|
239 | 239 | { |
|
240 | 240 | if (rowCount != count()) { |
|
241 | 241 | QBarModelMapper::setCount(rowCount); |
|
242 | 242 | emit firstRowChanged(); |
|
243 | 243 | } |
|
244 | 244 | } |
|
245 | 245 | |
|
246 | 246 | #include "moc_qvbarmodelmapper.cpp" |
|
247 | 247 | |
|
248 | 248 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,190 +1,189 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qabstractseries.h" |
|
22 | 22 | #include "qabstractseries_p.h" |
|
23 | 23 | #include "chartdataset_p.h" |
|
24 | 24 | |
|
25 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | /*! |
|
28 | 28 | \class QAbstractSeries |
|
29 | 29 | \brief Base class for all QtCommercial Chart series. |
|
30 | 30 | \mainclass |
|
31 | 31 | |
|
32 | 32 | Usually you use the series type specific inherited classes instead of the base class. |
|
33 | 33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, |
|
34 | 34 | QPercentBarSeries, QPieSeries |
|
35 | 35 | */ |
|
36 | 36 | /*! |
|
37 | 37 | \qmlclass AbstractSeries |
|
38 | 38 | AbstractSeries is the base class for all series. |
|
39 | 39 | The class cannot be instantiated by the user. |
|
40 | 40 | */ |
|
41 | 41 | |
|
42 | 42 | /*! |
|
43 | 43 | \enum QAbstractSeries::SeriesType |
|
44 | 44 | |
|
45 | 45 | The type of the series object. |
|
46 | 46 | |
|
47 | 47 | \value SeriesTypeLine |
|
48 | 48 | \value SeriesTypeArea |
|
49 | 49 | \value SeriesTypeBar |
|
50 | 50 | \value SeriesTypeStackedBar |
|
51 | 51 | \value SeriesTypePercentBar |
|
52 | \value SeriesTypeGroupedBar | |
|
53 | 52 | \value SeriesTypePie |
|
54 | 53 | \value SeriesTypeScatter |
|
55 | 54 | \value SeriesTypeSpline |
|
56 | 55 | */ |
|
57 | 56 | |
|
58 | 57 | /*! |
|
59 | 58 | \property QAbstractSeries::type |
|
60 | 59 | The type of the series. |
|
61 | 60 | */ |
|
62 | 61 | /*! |
|
63 | 62 | \qmlproperty ChartView.SeriesType AbstractSeries::type |
|
64 | 63 | The type of the series. |
|
65 | 64 | */ |
|
66 | 65 | |
|
67 | 66 | /*! |
|
68 | 67 | \property QAbstractSeries::name |
|
69 | 68 | \brief name of the series property. The name is shown in legend for QXYSeries. |
|
70 | 69 | */ |
|
71 | 70 | /*! |
|
72 | 71 | \qmlproperty string AbstractSeries::name |
|
73 | 72 | Name of the series. The name is shown in legend for QXYSeries. |
|
74 | 73 | */ |
|
75 | 74 | |
|
76 | 75 | /*! |
|
77 | 76 | \fn void QAbstractSeries::nameChanged() |
|
78 | 77 | This signal is emitted when the series name changes. |
|
79 | 78 | */ |
|
80 | 79 | /*! |
|
81 | 80 | \qmlsignal AbstractSeries::nameChanged() |
|
82 | 81 | This signal is emitted when the series name changes. |
|
83 | 82 | */ |
|
84 | 83 | |
|
85 | 84 | /*! |
|
86 | 85 | \property QAbstractSeries::visible |
|
87 | 86 | \brief whether the series is visible or not; true by default. |
|
88 | 87 | */ |
|
89 | 88 | |
|
90 | 89 | /*! |
|
91 | 90 | \fn void QAbstractSeries::visibleChanged() |
|
92 | 91 | Emitted when the series visibility changes. |
|
93 | 92 | */ |
|
94 | 93 | |
|
95 | 94 | /*! |
|
96 | 95 | \internal |
|
97 | 96 | \brief Constructs ChartSeries object with \a parent. |
|
98 | 97 | */ |
|
99 | 98 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
100 | 99 | QObject(parent), |
|
101 | 100 | d_ptr(&d) |
|
102 | 101 | { |
|
103 | 102 | } |
|
104 | 103 | |
|
105 | 104 | /*! |
|
106 | 105 | \brief Virtual destructor for the chart series. |
|
107 | 106 | */ |
|
108 | 107 | QAbstractSeries::~QAbstractSeries() |
|
109 | 108 | { |
|
110 | 109 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); |
|
111 | 110 | } |
|
112 | 111 | |
|
113 | 112 | void QAbstractSeries::setName(const QString& name) |
|
114 | 113 | { |
|
115 | 114 | if (name != d_ptr->m_name) { |
|
116 | 115 | d_ptr->m_name = name; |
|
117 | 116 | emit nameChanged(); |
|
118 | 117 | } |
|
119 | 118 | } |
|
120 | 119 | |
|
121 | 120 | QString QAbstractSeries::name() const |
|
122 | 121 | { |
|
123 | 122 | return d_ptr->m_name; |
|
124 | 123 | } |
|
125 | 124 | |
|
126 | 125 | /*! |
|
127 | 126 | Sets the visibility of series to \a visible |
|
128 | 127 | */ |
|
129 | 128 | void QAbstractSeries::setVisible(bool visible) |
|
130 | 129 | { |
|
131 | 130 | if (visible != d_ptr->m_visible) { |
|
132 | 131 | d_ptr->m_visible = visible; |
|
133 | 132 | emit visibleChanged(); |
|
134 | 133 | } |
|
135 | 134 | } |
|
136 | 135 | |
|
137 | 136 | /*! |
|
138 | 137 | Returns the visibility of series |
|
139 | 138 | */ |
|
140 | 139 | bool QAbstractSeries::isVisible() const |
|
141 | 140 | { |
|
142 | 141 | return d_ptr->m_visible; |
|
143 | 142 | } |
|
144 | 143 | |
|
145 | 144 | /*! |
|
146 | 145 | \brief Returns the chart where series belongs to. |
|
147 | 146 | |
|
148 | 147 | Set automatically when the series is added to the chart |
|
149 | 148 | and unset when the series is removed from the chart. |
|
150 | 149 | */ |
|
151 | 150 | QChart* QAbstractSeries::chart() const |
|
152 | 151 | { |
|
153 | 152 | return d_ptr->m_chart; |
|
154 | 153 | } |
|
155 | 154 | |
|
156 | 155 | void QAbstractSeries::adjustView() |
|
157 | 156 | { |
|
158 | 157 | //TODO: |
|
159 | 158 | } |
|
160 | 159 | |
|
161 | 160 | void QAbstractSeries::show() |
|
162 | 161 | { |
|
163 | 162 | setVisible(true); |
|
164 | 163 | } |
|
165 | 164 | |
|
166 | 165 | void QAbstractSeries::hide() |
|
167 | 166 | { |
|
168 | 167 | setVisible(false); |
|
169 | 168 | } |
|
170 | 169 | |
|
171 | 170 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 | 171 | |
|
173 | 172 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): |
|
174 | 173 | q_ptr(q), |
|
175 | 174 | m_chart(0), |
|
176 | 175 | m_dataset(0), |
|
177 | 176 | m_visible(true) |
|
178 | 177 | { |
|
179 | 178 | } |
|
180 | 179 | |
|
181 | 180 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
182 | 181 | { |
|
183 | 182 | } |
|
184 | 183 | |
|
185 | 184 | #include "moc_qabstractseries.cpp" |
|
186 | 185 | #include "moc_qabstractseries_p.cpp" |
|
187 | 186 | |
|
188 | 187 | QTCOMMERCIALCHART_END_NAMESPACE |
|
189 | 188 | |
|
190 | 189 |
@@ -1,85 +1,84 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QABSTRACTSERIES_H |
|
22 | 22 | #define QABSTRACTSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <qabstractaxis.h> |
|
26 | 26 | #include <QObject> |
|
27 | 27 | #include <QPen> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QAbstractSeriesPrivate; |
|
32 | 32 | class QChart; |
|
33 | 33 | |
|
34 | 34 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject |
|
35 | 35 | { |
|
36 | 36 | Q_OBJECT |
|
37 | 37 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
|
38 | 38 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
39 | 39 | Q_PROPERTY(SeriesType type READ type) |
|
40 | 40 | Q_ENUMS(SeriesType) |
|
41 | 41 | |
|
42 | 42 | public: |
|
43 | 43 | enum SeriesType { |
|
44 | 44 | SeriesTypeLine, |
|
45 | 45 | SeriesTypeArea, |
|
46 | 46 | SeriesTypeBar, |
|
47 | 47 | SeriesTypeStackedBar, |
|
48 | 48 | SeriesTypePercentBar, |
|
49 | SeriesTypeGroupedBar, | |
|
50 | 49 | SeriesTypePie, |
|
51 | 50 | SeriesTypeScatter, |
|
52 | 51 | SeriesTypeSpline |
|
53 | 52 | }; |
|
54 | 53 | |
|
55 | 54 | protected: |
|
56 | 55 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); |
|
57 | 56 | |
|
58 | 57 | public: |
|
59 | 58 | ~QAbstractSeries(); |
|
60 | 59 | virtual SeriesType type() const = 0; |
|
61 | 60 | |
|
62 | 61 | void setName(const QString& name); |
|
63 | 62 | QString name() const; |
|
64 | 63 | void setVisible(bool visible = true); |
|
65 | 64 | bool isVisible() const; |
|
66 | 65 | QChart* chart() const; |
|
67 | 66 | |
|
68 | 67 | void adjustView(); |
|
69 | 68 | void show(); |
|
70 | 69 | void hide(); |
|
71 | 70 | |
|
72 | 71 | Q_SIGNALS: |
|
73 | 72 | void nameChanged(); |
|
74 | 73 | void visibleChanged(); |
|
75 | 74 | |
|
76 | 75 | protected: |
|
77 | 76 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; |
|
78 | 77 | friend class ChartDataSet; |
|
79 | 78 | friend class ChartPresenter; |
|
80 | 79 | friend class QLegendPrivate; |
|
81 | 80 | }; |
|
82 | 81 | |
|
83 | 82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
84 | 83 | |
|
85 | 84 | #endif |
@@ -1,624 +1,624 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | #include <qabstractaxis.h> |
|
23 | 23 | #include <qvaluesaxis.h> |
|
24 | 24 | #include <qcategoriesaxis.h> |
|
25 | 25 | #include <qlineseries.h> |
|
26 | 26 | #include <qareaseries.h> |
|
27 | 27 | #include <qscatterseries.h> |
|
28 | 28 | #include <qsplineseries.h> |
|
29 | 29 | #include <qpieseries.h> |
|
30 |
#include <q |
|
|
30 | #include <qbarseries.h> | |
|
31 | 31 | #include <qpercentbarseries.h> |
|
32 | 32 | #include <qstackedbarseries.h> |
|
33 | 33 | #include <private/chartdataset_p.h> |
|
34 | 34 | #include <private/domain_p.h> |
|
35 | 35 | #include <tst_definitions.h> |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | Q_DECLARE_METATYPE(Domain *) |
|
40 | 40 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
41 | 41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
42 | 42 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
43 | 43 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
44 | 44 | Q_DECLARE_METATYPE(QLineSeries *) |
|
45 | 45 | |
|
46 | 46 | class tst_ChartDataSet: public QObject { |
|
47 | 47 | |
|
48 | 48 | Q_OBJECT |
|
49 | 49 | |
|
50 | 50 | public Q_SLOTS: |
|
51 | 51 | void initTestCase(); |
|
52 | 52 | void cleanupTestCase(); |
|
53 | 53 | void init(); |
|
54 | 54 | void cleanup(); |
|
55 | 55 | |
|
56 | 56 | private Q_SLOTS: |
|
57 | 57 | void chartdataset_data(); |
|
58 | 58 | void chartdataset(); |
|
59 | 59 | void addSeries_data(); |
|
60 | 60 | void addSeries(); |
|
61 | 61 | void setAxisX_data(); |
|
62 | 62 | void setAxisX(); |
|
63 | 63 | void setAxisY_data(); |
|
64 | 64 | void setAxisY(); |
|
65 | 65 | void removeSeries_data(); |
|
66 | 66 | void removeSeries(); |
|
67 | 67 | void removeAllSeries_data(); |
|
68 | 68 | void removeAllSeries(); |
|
69 | 69 | void seriesCount_data(); |
|
70 | 70 | void seriesCount(); |
|
71 | 71 | void seriesIndex_data(); |
|
72 | 72 | void seriesIndex(); |
|
73 | 73 | void domain_data(); |
|
74 | 74 | void domain(); |
|
75 | 75 | void zoomInDomain_data(); |
|
76 | 76 | void zoomInDomain(); |
|
77 | 77 | void zoomOutDomain_data(); |
|
78 | 78 | void zoomOutDomain(); |
|
79 | 79 | void scrollDomain_data(); |
|
80 | 80 | void scrollDomain(); |
|
81 | 81 | |
|
82 | 82 | private: |
|
83 | 83 | ChartDataSet* m_dataset; |
|
84 | 84 | }; |
|
85 | 85 | |
|
86 | 86 | void tst_ChartDataSet::initTestCase() |
|
87 | 87 | { |
|
88 | 88 | qRegisterMetaType<Domain*>(); |
|
89 | 89 | qRegisterMetaType<QAbstractAxis*>(); |
|
90 | 90 | qRegisterMetaType<QAbstractSeries*>(); |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | void tst_ChartDataSet::cleanupTestCase() |
|
94 | 94 | { |
|
95 | 95 | } |
|
96 | 96 | |
|
97 | 97 | void tst_ChartDataSet::init() |
|
98 | 98 | { |
|
99 | 99 | m_dataset = new ChartDataSet(); |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | |
|
103 | 103 | void tst_ChartDataSet::cleanup() |
|
104 | 104 | { |
|
105 | 105 | QList<QAbstractSeries*> series = m_dataset->series(); |
|
106 | 106 | foreach(QAbstractSeries* serie, series) |
|
107 | 107 | { |
|
108 | 108 | m_dataset->removeSeries(serie); |
|
109 | 109 | } |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | void tst_ChartDataSet::chartdataset_data() |
|
113 | 113 | { |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | void tst_ChartDataSet::chartdataset() |
|
117 | 117 | { |
|
118 | 118 | QVERIFY(m_dataset->axisX(0) == 0); |
|
119 | 119 | QVERIFY(m_dataset->axisY(0) == 0); |
|
120 | 120 | QLineSeries* series = new QLineSeries(this); |
|
121 | 121 | QCOMPARE(m_dataset->seriesIndex(series),-1); |
|
122 | 122 | QVERIFY(m_dataset->domain(series) == 0); |
|
123 | 123 | QVERIFY(m_dataset->axisX(series) == 0); |
|
124 | 124 | QVERIFY(m_dataset->axisY(series) == 0); |
|
125 | 125 | m_dataset->createDefaultAxes(); |
|
126 | 126 | } |
|
127 | 127 | |
|
128 | 128 | |
|
129 | 129 | void tst_ChartDataSet::addSeries_data() |
|
130 | 130 | { |
|
131 | 131 | QTest::addColumn<QAbstractSeries*>("series"); |
|
132 | 132 | |
|
133 | 133 | QAbstractSeries* line = new QLineSeries(this); |
|
134 | 134 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
135 | 135 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
136 | 136 | QAbstractSeries* spline = new QSplineSeries(this); |
|
137 | 137 | QAbstractSeries* pie = new QPieSeries(this); |
|
138 |
QAbstractSeries* bar = new Q |
|
|
138 | QAbstractSeries* bar = new QBarSeries(this); | |
|
139 | 139 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
140 | 140 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
141 | 141 | |
|
142 | 142 | QTest::newRow("line") << line; |
|
143 | 143 | QTest::newRow("area") << area; |
|
144 | 144 | QTest::newRow("scatter") << scatter; |
|
145 | 145 | QTest::newRow("spline") << spline; |
|
146 | 146 | QTest::newRow("pie") << pie; |
|
147 | 147 | QTest::newRow("bar") << bar; |
|
148 | 148 | QTest::newRow("percent") << percent; |
|
149 | 149 | QTest::newRow("stacked") << stacked; |
|
150 | 150 | } |
|
151 | 151 | |
|
152 | 152 | void tst_ChartDataSet::addSeries() |
|
153 | 153 | { |
|
154 | 154 | |
|
155 | 155 | QFETCH(QAbstractSeries*, series); |
|
156 | 156 | |
|
157 | 157 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
158 | 158 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
159 | 159 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
160 | 160 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
161 | 161 | |
|
162 | 162 | m_dataset->addSeries(series); |
|
163 | 163 | m_dataset->createDefaultAxes(); |
|
164 | 164 | if(series->type()==QAbstractSeries::SeriesTypePie){ |
|
165 | 165 | TRY_COMPARE(spy0.count(), 0); |
|
166 | 166 | }else{ |
|
167 | 167 | TRY_COMPARE(spy0.count(), 2); |
|
168 | 168 | } |
|
169 | 169 | TRY_COMPARE(spy1.count(), 0); |
|
170 | 170 | TRY_COMPARE(spy2.count(), 1); |
|
171 | 171 | TRY_COMPARE(spy3.count(), 0); |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | 174 | |
|
175 | 175 | void tst_ChartDataSet::setAxisX_data() |
|
176 | 176 | { |
|
177 | 177 | |
|
178 | 178 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
179 | 179 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
180 | 180 | QTest::addColumn<int>("axisCount"); |
|
181 | 181 | |
|
182 | 182 | QAbstractSeries* line = new QLineSeries(this); |
|
183 | 183 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
184 | 184 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
185 | 185 | QAbstractSeries* spline = new QSplineSeries(this); |
|
186 | 186 | QAbstractSeries* pie = new QPieSeries(this); |
|
187 |
QAbstractSeries* bar = new Q |
|
|
187 | QAbstractSeries* bar = new QBarSeries(this); | |
|
188 | 188 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
189 | 189 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
190 | 190 | |
|
191 | 191 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
192 | 192 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
193 | 193 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3; |
|
194 | 194 | |
|
195 | 195 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) |
|
196 | 196 | << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1; |
|
197 | 197 | |
|
198 | 198 | QList<QAbstractAxis*> axes0; |
|
199 | 199 | axes0 << new QValuesAxis(this) << new QValuesAxis(this); |
|
200 | 200 | axes0 << axes0.last(); |
|
201 | 201 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") |
|
202 | 202 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
203 | 203 | << axes0 << 2; |
|
204 | 204 | //TODO: add more test cases |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | void tst_ChartDataSet::setAxisX() |
|
208 | 208 | { |
|
209 | 209 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
210 | 210 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
211 | 211 | QFETCH(int, axisCount); |
|
212 | 212 | |
|
213 | 213 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
214 | 214 | |
|
215 | 215 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
216 | 216 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
217 | 217 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
218 | 218 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
219 | 219 | |
|
220 | 220 | foreach(QAbstractSeries* series, seriesList){ |
|
221 | 221 | m_dataset->addSeries(series); |
|
222 | 222 | } |
|
223 | 223 | |
|
224 | 224 | TRY_COMPARE(spy0.count(), 0); |
|
225 | 225 | TRY_COMPARE(spy1.count(), 0); |
|
226 | 226 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
227 | 227 | TRY_COMPARE(spy3.count(), 0); |
|
228 | 228 | |
|
229 | 229 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
230 | 230 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
231 | 231 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
232 | 232 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
233 | 233 | |
|
234 | 234 | for(int i=0 ; i < seriesList.count(); i++){ |
|
235 | 235 | m_dataset->setAxisX(seriesList.at(i),axisList.at(i)); |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | TRY_COMPARE(spy4.count(), axisCount); |
|
239 | 239 | TRY_COMPARE(spy5.count(), 0); |
|
240 | 240 | TRY_COMPARE(spy6.count(), 0); |
|
241 | 241 | TRY_COMPARE(spy7.count(), 0); |
|
242 | 242 | |
|
243 | 243 | for(int i=0 ; i < seriesList.count(); i++){ |
|
244 | 244 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); |
|
245 | 245 | } |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | void tst_ChartDataSet::setAxisY_data() |
|
249 | 249 | { |
|
250 | 250 | setAxisX_data(); |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | void tst_ChartDataSet::setAxisY() |
|
254 | 254 | { |
|
255 | 255 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
256 | 256 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
257 | 257 | QFETCH(int, axisCount); |
|
258 | 258 | |
|
259 | 259 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
260 | 260 | |
|
261 | 261 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
262 | 262 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
263 | 263 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
264 | 264 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
265 | 265 | |
|
266 | 266 | foreach(QAbstractSeries* series, seriesList){ |
|
267 | 267 | m_dataset->addSeries(series); |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | TRY_COMPARE(spy0.count(), 0); |
|
271 | 271 | TRY_COMPARE(spy1.count(), 0); |
|
272 | 272 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
273 | 273 | TRY_COMPARE(spy3.count(), 0); |
|
274 | 274 | |
|
275 | 275 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
276 | 276 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
277 | 277 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
278 | 278 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
279 | 279 | |
|
280 | 280 | for(int i=0 ; i < seriesList.count(); i++){ |
|
281 | 281 | m_dataset->setAxisY(seriesList.at(i),axisList.at(i)); |
|
282 | 282 | } |
|
283 | 283 | |
|
284 | 284 | TRY_COMPARE(spy4.count(), axisCount); |
|
285 | 285 | TRY_COMPARE(spy5.count(), 0); |
|
286 | 286 | TRY_COMPARE(spy6.count(), 0); |
|
287 | 287 | TRY_COMPARE(spy7.count(), 0); |
|
288 | 288 | |
|
289 | 289 | for(int i=0 ; i < seriesList.count(); i++){ |
|
290 | 290 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); |
|
291 | 291 | } |
|
292 | 292 | } |
|
293 | 293 | |
|
294 | 294 | void tst_ChartDataSet::removeSeries_data() |
|
295 | 295 | { |
|
296 | 296 | addSeries_data(); |
|
297 | 297 | } |
|
298 | 298 | |
|
299 | 299 | void tst_ChartDataSet::removeSeries() |
|
300 | 300 | { |
|
301 | 301 | QFETCH(QAbstractSeries*, series); |
|
302 | 302 | |
|
303 | 303 | m_dataset->addSeries(series); |
|
304 | 304 | m_dataset->createDefaultAxes(); |
|
305 | 305 | |
|
306 | 306 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
307 | 307 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
308 | 308 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
309 | 309 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
310 | 310 | |
|
311 | 311 | m_dataset->removeSeries(series); |
|
312 | 312 | |
|
313 | 313 | TRY_COMPARE(spy0.count(), 0); |
|
314 | 314 | if (series->type() == QAbstractSeries::SeriesTypePie) { |
|
315 | 315 | TRY_COMPARE(spy1.count(), 0); |
|
316 | 316 | } |
|
317 | 317 | else { |
|
318 | 318 | TRY_COMPARE(spy1.count(), 2); |
|
319 | 319 | } |
|
320 | 320 | TRY_COMPARE(spy2.count(), 0); |
|
321 | 321 | TRY_COMPARE(spy3.count(), 1); |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | void tst_ChartDataSet::removeAllSeries_data() |
|
325 | 325 | { |
|
326 | 326 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
327 | 327 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
328 | 328 | QTest::addColumn<int>("axisCount"); |
|
329 | 329 | |
|
330 | 330 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
331 | 331 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) |
|
332 | 332 | << new QScatterSeries(this)) |
|
333 | 333 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) |
|
334 | 334 | << new QValuesAxis(this)) << 3; |
|
335 | 335 | //TODO: |
|
336 | 336 | } |
|
337 | 337 | |
|
338 | 338 | void tst_ChartDataSet::removeAllSeries() |
|
339 | 339 | { |
|
340 | 340 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
341 | 341 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
342 | 342 | QFETCH(int, axisCount); |
|
343 | 343 | |
|
344 | 344 | foreach(QAbstractSeries* series, seriesList) { |
|
345 | 345 | m_dataset->addSeries(series); |
|
346 | 346 | } |
|
347 | 347 | |
|
348 | 348 | for (int i = 0; i < seriesList.count(); i++) { |
|
349 | 349 | m_dataset->setAxisX(seriesList.at(i), axisList.at(i)); |
|
350 | 350 | } |
|
351 | 351 | |
|
352 | 352 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
353 | 353 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
354 | 354 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
355 | 355 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
356 | 356 | |
|
357 | 357 | m_dataset->removeAllSeries(); |
|
358 | 358 | |
|
359 | 359 | TRY_COMPARE(spy0.count(), 0); |
|
360 | 360 | TRY_COMPARE(spy1.count(), axisCount); |
|
361 | 361 | TRY_COMPARE(spy2.count(), 0); |
|
362 | 362 | TRY_COMPARE(spy3.count(), seriesList.count()); |
|
363 | 363 | } |
|
364 | 364 | |
|
365 | 365 | |
|
366 | 366 | void tst_ChartDataSet::seriesCount_data() |
|
367 | 367 | { |
|
368 | 368 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
369 | 369 | QTest::addColumn<int>("seriesCount"); |
|
370 | 370 | |
|
371 | 371 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; |
|
372 | 372 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; |
|
373 | 373 | } |
|
374 | 374 | |
|
375 | 375 | void tst_ChartDataSet::seriesCount() |
|
376 | 376 | { |
|
377 | 377 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
378 | 378 | QFETCH(int, seriesCount); |
|
379 | 379 | |
|
380 | 380 | foreach(QAbstractSeries* series, seriesList){ |
|
381 | 381 | m_dataset->addSeries(series); |
|
382 | 382 | } |
|
383 | 383 | |
|
384 | 384 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
385 | 385 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
386 | 386 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
387 | 387 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
388 | 388 | |
|
389 | 389 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); |
|
390 | 390 | TRY_COMPARE(spy0.count(), 0); |
|
391 | 391 | TRY_COMPARE(spy1.count(), 0); |
|
392 | 392 | TRY_COMPARE(spy2.count(), 0); |
|
393 | 393 | TRY_COMPARE(spy3.count(), 0); |
|
394 | 394 | } |
|
395 | 395 | |
|
396 | 396 | void tst_ChartDataSet::seriesIndex_data() |
|
397 | 397 | { |
|
398 | 398 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
399 | 399 | |
|
400 | 400 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
401 | 401 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); |
|
402 | 402 | } |
|
403 | 403 | |
|
404 | 404 | void tst_ChartDataSet::seriesIndex() |
|
405 | 405 | { |
|
406 | 406 | |
|
407 | 407 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
408 | 408 | |
|
409 | 409 | foreach(QAbstractSeries* series, seriesList) { |
|
410 | 410 | m_dataset->addSeries(series); |
|
411 | 411 | } |
|
412 | 412 | |
|
413 | 413 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
414 | 414 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
415 | 415 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
416 | 416 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
417 | 417 | |
|
418 | 418 | for (int i = 0; i < seriesList.count(); i++) { |
|
419 | 419 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
420 | 420 | } |
|
421 | 421 | |
|
422 | 422 | TRY_COMPARE(spy0.count(), 0); |
|
423 | 423 | TRY_COMPARE(spy1.count(), 0); |
|
424 | 424 | TRY_COMPARE(spy2.count(), 0); |
|
425 | 425 | TRY_COMPARE(spy3.count(), 0); |
|
426 | 426 | |
|
427 | 427 | foreach(QAbstractSeries* series, seriesList) { |
|
428 | 428 | m_dataset->removeSeries(series); |
|
429 | 429 | } |
|
430 | 430 | |
|
431 | 431 | for (int i = 0; i < seriesList.count(); i++) { |
|
432 | 432 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | foreach(QAbstractSeries* series, seriesList) { |
|
436 | 436 | m_dataset->addSeries(series); |
|
437 | 437 | } |
|
438 | 438 | |
|
439 | 439 | for (int i = 0; i < seriesList.count(); i++) { |
|
440 | 440 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
441 | 441 | } |
|
442 | 442 | |
|
443 | 443 | m_dataset->removeSeries(seriesList.at(1)); |
|
444 | 444 | |
|
445 | 445 | for (int i = 0; i < seriesList.count(); i++) { |
|
446 | 446 | if (i != 1) |
|
447 | 447 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
448 | 448 | else |
|
449 | 449 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
450 | 450 | } |
|
451 | 451 | |
|
452 | 452 | m_dataset->addSeries(seriesList.at(1)); |
|
453 | 453 | |
|
454 | 454 | for (int i = 0; i < seriesList.count(); i++) { |
|
455 | 455 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
456 | 456 | } |
|
457 | 457 | |
|
458 | 458 | m_dataset->removeSeries(seriesList.at(2)); |
|
459 | 459 | |
|
460 | 460 | for (int i = 0; i < seriesList.count(); i++) { |
|
461 | 461 | if (i != 2) |
|
462 | 462 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
463 | 463 | else |
|
464 | 464 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
465 | 465 | } |
|
466 | 466 | |
|
467 | 467 | m_dataset->removeSeries(seriesList.at(0)); |
|
468 | 468 | |
|
469 | 469 | for (int i = 0; i < seriesList.count(); i++) { |
|
470 | 470 | if (i != 2 && i != 0) |
|
471 | 471 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
472 | 472 | else |
|
473 | 473 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
474 | 474 | } |
|
475 | 475 | |
|
476 | 476 | m_dataset->addSeries(seriesList.at(2)); |
|
477 | 477 | m_dataset->addSeries(seriesList.at(0)); |
|
478 | 478 | |
|
479 | 479 | for (int i = 0; i < seriesList.count(); i++) { |
|
480 | 480 | if (i == 2) |
|
481 | 481 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); |
|
482 | 482 | else if (i == 0) |
|
483 | 483 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); |
|
484 | 484 | else |
|
485 | 485 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
486 | 486 | } |
|
487 | 487 | |
|
488 | 488 | } |
|
489 | 489 | |
|
490 | 490 | void tst_ChartDataSet::domain_data() |
|
491 | 491 | { |
|
492 | 492 | addSeries_data(); |
|
493 | 493 | } |
|
494 | 494 | |
|
495 | 495 | void tst_ChartDataSet::domain() |
|
496 | 496 | { |
|
497 | 497 | QFETCH(QAbstractSeries*, series); |
|
498 | 498 | |
|
499 | 499 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
500 | 500 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
501 | 501 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
502 | 502 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
503 | 503 | |
|
504 | 504 | m_dataset->addSeries(series); |
|
505 | 505 | QVERIFY(m_dataset->domain(series)); |
|
506 | 506 | |
|
507 | 507 | |
|
508 | 508 | TRY_COMPARE(spy0.count(), 0); |
|
509 | 509 | TRY_COMPARE(spy1.count(), 0); |
|
510 | 510 | TRY_COMPARE(spy2.count(), 1); |
|
511 | 511 | |
|
512 | 512 | QList<QVariant> arguments = spy2.takeFirst(); |
|
513 | 513 | Domain *domain = (Domain *) arguments.at(1).value<Domain *>(); |
|
514 | 514 | QVERIFY(m_dataset->domain(series) == domain); |
|
515 | 515 | |
|
516 | 516 | TRY_COMPARE(spy3.count(), 0); |
|
517 | 517 | |
|
518 | 518 | } |
|
519 | 519 | |
|
520 | 520 | void tst_ChartDataSet::zoomInDomain_data() |
|
521 | 521 | { |
|
522 | 522 | QTest::addColumn<bool >("sameAxis"); |
|
523 | 523 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
524 | 524 | QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
525 | 525 | QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
526 | 526 | } |
|
527 | 527 | |
|
528 | 528 | void tst_ChartDataSet::zoomInDomain() |
|
529 | 529 | { |
|
530 | 530 | QFETCH(bool, sameAxis); |
|
531 | 531 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
532 | 532 | |
|
533 | 533 | foreach(QAbstractSeries* series, seriesList) { |
|
534 | 534 | m_dataset->addSeries(series); |
|
535 | 535 | } |
|
536 | 536 | |
|
537 | 537 | if(sameAxis) m_dataset->createDefaultAxes(); |
|
538 | 538 | |
|
539 | 539 | QList<QSignalSpy*> spyList; |
|
540 | 540 | |
|
541 | 541 | foreach(QAbstractSeries* series, seriesList) { |
|
542 | 542 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
543 | 543 | } |
|
544 | 544 | |
|
545 | 545 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
546 | 546 | |
|
547 | 547 | foreach(QSignalSpy* spy, spyList) { |
|
548 | 548 | TRY_COMPARE(spy->count(), 1); |
|
549 | 549 | } |
|
550 | 550 | |
|
551 | 551 | qDeleteAll(spyList); |
|
552 | 552 | } |
|
553 | 553 | |
|
554 | 554 | |
|
555 | 555 | |
|
556 | 556 | void tst_ChartDataSet::zoomOutDomain_data() |
|
557 | 557 | { |
|
558 | 558 | zoomInDomain_data(); |
|
559 | 559 | } |
|
560 | 560 | |
|
561 | 561 | void tst_ChartDataSet::zoomOutDomain() |
|
562 | 562 | { |
|
563 | 563 | QFETCH(bool, sameAxis); |
|
564 | 564 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
565 | 565 | |
|
566 | 566 | foreach(QAbstractSeries* series, seriesList) { |
|
567 | 567 | m_dataset->addSeries(series); |
|
568 | 568 | } |
|
569 | 569 | |
|
570 | 570 | if (sameAxis) |
|
571 | 571 | m_dataset->createDefaultAxes(); |
|
572 | 572 | |
|
573 | 573 | QList<QSignalSpy*> spyList; |
|
574 | 574 | |
|
575 | 575 | foreach(QAbstractSeries* series, seriesList) { |
|
576 | 576 | spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
577 | 577 | } |
|
578 | 578 | |
|
579 | 579 | m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
580 | 580 | |
|
581 | 581 | foreach(QSignalSpy* spy, spyList) { |
|
582 | 582 | TRY_COMPARE(spy->count(), 1); |
|
583 | 583 | } |
|
584 | 584 | |
|
585 | 585 | qDeleteAll (spyList); |
|
586 | 586 | } |
|
587 | 587 | |
|
588 | 588 | void tst_ChartDataSet::scrollDomain_data() |
|
589 | 589 | { |
|
590 | 590 | zoomInDomain_data(); |
|
591 | 591 | } |
|
592 | 592 | |
|
593 | 593 | void tst_ChartDataSet::scrollDomain() |
|
594 | 594 | { |
|
595 | 595 | QFETCH(bool, sameAxis); |
|
596 | 596 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
597 | 597 | |
|
598 | 598 | foreach(QAbstractSeries* series, seriesList) { |
|
599 | 599 | m_dataset->addSeries(series); |
|
600 | 600 | } |
|
601 | 601 | |
|
602 | 602 | if (sameAxis) |
|
603 | 603 | m_dataset->createDefaultAxes(); |
|
604 | 604 | |
|
605 | 605 | QList<QSignalSpy*> spyList; |
|
606 | 606 | |
|
607 | 607 | foreach(QAbstractSeries* series, seriesList) { |
|
608 | 608 | spyList |
|
609 | 609 | << new QSignalSpy(m_dataset->domain(series), |
|
610 | 610 | SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
611 | 611 | } |
|
612 | 612 | |
|
613 | 613 | m_dataset->scrollDomain(10, 10, QSize(1000, 1000)); |
|
614 | 614 | |
|
615 | 615 | foreach(QSignalSpy* spy, spyList) { |
|
616 | 616 | TRY_COMPARE(spy->count(), 1); |
|
617 | 617 | } |
|
618 | 618 | |
|
619 | 619 | qDeleteAll(spyList); |
|
620 | 620 | } |
|
621 | 621 | |
|
622 | 622 | QTEST_MAIN(tst_ChartDataSet) |
|
623 | 623 | #include "tst_chartdataset.moc" |
|
624 | 624 |
@@ -1,614 +1,614 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtCore/QString> |
|
22 | 22 | #include <QtTest/QtTest> |
|
23 | 23 | |
|
24 | 24 | #include <qchart.h> |
|
25 | 25 | #include <qchartview.h> |
|
26 |
#include <q |
|
|
26 | #include <qbarseries.h> | |
|
27 | 27 | #include <qbarset.h> |
|
28 | 28 | #include <qvbarmodelmapper.h> |
|
29 | 29 | #include <qhbarmodelmapper.h> |
|
30 | 30 | #include <QStandardItemModel> |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | class tst_qbarmodelmapper : public QObject |
|
35 | 35 | { |
|
36 | 36 | Q_OBJECT |
|
37 | 37 | |
|
38 | 38 | public: |
|
39 | 39 | tst_qbarmodelmapper(); |
|
40 | 40 | void createVerticalMapper(); |
|
41 | 41 | void createHorizontalMapper(); |
|
42 | 42 | |
|
43 | 43 | private Q_SLOTS: |
|
44 | 44 | void initTestCase(); |
|
45 | 45 | void cleanupTestCase(); |
|
46 | 46 | void init(); |
|
47 | 47 | void cleanup(); |
|
48 | 48 | void verticalMapper_data(); |
|
49 | 49 | void verticalMapper(); |
|
50 | 50 | void verticalMapperCustomMapping_data(); |
|
51 | 51 | void verticalMapperCustomMapping(); |
|
52 | 52 | void horizontalMapper_data(); |
|
53 | 53 | void horizontalMapper(); |
|
54 | 54 | void horizontalMapperCustomMapping_data(); |
|
55 | 55 | void horizontalMapperCustomMapping(); |
|
56 | 56 | void seriesUpdated(); |
|
57 | 57 | void verticalModelInsertRows(); |
|
58 | 58 | void verticalModelRemoveRows(); |
|
59 | 59 | void verticalModelInsertColumns(); |
|
60 | 60 | void verticalModelRemoveColumns(); |
|
61 | 61 | void horizontalModelInsertRows(); |
|
62 | 62 | void horizontalModelRemoveRows(); |
|
63 | 63 | void horizontalModelInsertColumns(); |
|
64 | 64 | void horizontalModelRemoveColumns(); |
|
65 | 65 | void modelUpdateCell(); |
|
66 | 66 | |
|
67 | 67 | private: |
|
68 | 68 | QStandardItemModel *m_model; |
|
69 | 69 | int m_modelRowCount; |
|
70 | 70 | int m_modelColumnCount; |
|
71 | 71 | |
|
72 | 72 | QVBarModelMapper *m_vMapper; |
|
73 | 73 | QHBarModelMapper *m_hMapper; |
|
74 | 74 | |
|
75 |
Q |
|
|
75 | QBarSeries *m_series; | |
|
76 | 76 | QChart *m_chart; |
|
77 | 77 | }; |
|
78 | 78 | |
|
79 | 79 | tst_qbarmodelmapper::tst_qbarmodelmapper(): |
|
80 | 80 | m_model(0), |
|
81 | 81 | m_modelRowCount(10), |
|
82 | 82 | m_modelColumnCount(8), |
|
83 | 83 | m_vMapper(0), |
|
84 | 84 | m_hMapper(0), |
|
85 | 85 | m_series(0), |
|
86 | 86 | m_chart(0) |
|
87 | 87 | { |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | void tst_qbarmodelmapper::createVerticalMapper() |
|
91 | 91 | { |
|
92 | 92 | m_vMapper = new QVBarModelMapper; |
|
93 | 93 | QVERIFY(m_vMapper->model() == 0); |
|
94 | 94 | m_vMapper->setFirstBarSetColumn(0); |
|
95 | 95 | m_vMapper->setLastBarSetColumn(4); |
|
96 | 96 | m_vMapper->setModel(m_model); |
|
97 | 97 | m_vMapper->setSeries(m_series); |
|
98 | 98 | } |
|
99 | 99 | |
|
100 | 100 | void tst_qbarmodelmapper::createHorizontalMapper() |
|
101 | 101 | { |
|
102 | 102 | m_hMapper = new QHBarModelMapper; |
|
103 | 103 | QVERIFY(m_hMapper->model() == 0); |
|
104 | 104 | m_hMapper->setFirstBarSetRow(0); |
|
105 | 105 | m_hMapper->setLastBarSetRow(4); |
|
106 | 106 | m_hMapper->setModel(m_model); |
|
107 | 107 | m_hMapper->setSeries(m_series); |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | void tst_qbarmodelmapper::init() |
|
111 | 111 | { |
|
112 |
m_series = new Q |
|
|
112 | m_series = new QBarSeries; | |
|
113 | 113 | m_chart->addSeries(m_series); |
|
114 | 114 | |
|
115 | 115 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); |
|
116 | 116 | for (int row = 0; row < m_modelRowCount; ++row) { |
|
117 | 117 | for (int column = 0; column < m_modelColumnCount; column++) { |
|
118 | 118 | m_model->setData(m_model->index(row, column), row * column); |
|
119 | 119 | } |
|
120 | 120 | } |
|
121 | 121 | } |
|
122 | 122 | |
|
123 | 123 | void tst_qbarmodelmapper::cleanup() |
|
124 | 124 | { |
|
125 | 125 | m_chart->removeSeries(m_series); |
|
126 | 126 | delete m_series; |
|
127 | 127 | m_series = 0; |
|
128 | 128 | |
|
129 | 129 | m_model->clear(); |
|
130 | 130 | m_model->deleteLater(); |
|
131 | 131 | m_model = 0; |
|
132 | 132 | |
|
133 | 133 | if (m_vMapper) { |
|
134 | 134 | m_vMapper->deleteLater(); |
|
135 | 135 | m_vMapper = 0; |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | if (m_hMapper) { |
|
139 | 139 | m_hMapper->deleteLater(); |
|
140 | 140 | m_hMapper = 0; |
|
141 | 141 | } |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | void tst_qbarmodelmapper::initTestCase() |
|
145 | 145 | { |
|
146 | 146 | m_chart = new QChart; |
|
147 | 147 | QChartView *chartView = new QChartView(m_chart); |
|
148 | 148 | chartView->show(); |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | void tst_qbarmodelmapper::cleanupTestCase() |
|
152 | 152 | { |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | void tst_qbarmodelmapper::verticalMapper_data() |
|
156 | 156 | { |
|
157 | 157 | QTest::addColumn<int>("firstBarSetColumn"); |
|
158 | 158 | QTest::addColumn<int>("lastBarSetColumn"); |
|
159 | 159 | QTest::addColumn<int>("expectedBarSetCount"); |
|
160 | 160 | QTest::newRow("lastBarSetColumn greater than firstBarSetColumn") << 0 << 1 << 2; |
|
161 | 161 | QTest::newRow("lastBarSetColumn equal to firstBarSetColumn") << 1 << 1 << 1; |
|
162 | 162 | QTest::newRow("lastBarSetColumn lesser than firstBarSetColumn") << 1 << 0 << 0; |
|
163 | 163 | QTest::newRow("invalid firstBarSetColumn and correct lastBarSetColumn") << -3 << 1 << 0; |
|
164 | 164 | QTest::newRow("firstBarSetColumn beyond the size of model and correct lastBarSetColumn") << m_modelColumnCount << 1 << 0; |
|
165 | 165 | QTest::newRow("firstBarSetColumn beyond the size of model and invalid lastBarSetColumn") << m_modelColumnCount << -1 << 0; |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | void tst_qbarmodelmapper::verticalMapper() |
|
169 | 169 | { |
|
170 | 170 | QFETCH(int, firstBarSetColumn); |
|
171 | 171 | QFETCH(int, lastBarSetColumn); |
|
172 | 172 | QFETCH(int, expectedBarSetCount); |
|
173 | 173 | |
|
174 |
m_series = new Q |
|
|
174 | m_series = new QBarSeries; | |
|
175 | 175 | |
|
176 | 176 | QVBarModelMapper *mapper = new QVBarModelMapper; |
|
177 | 177 | mapper->setFirstBarSetColumn(firstBarSetColumn); |
|
178 | 178 | mapper->setLastBarSetColumn(lastBarSetColumn); |
|
179 | 179 | mapper->setModel(m_model); |
|
180 | 180 | mapper->setSeries(m_series); |
|
181 | 181 | |
|
182 | 182 | m_chart->addSeries(m_series); |
|
183 | 183 | |
|
184 | 184 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
185 | 185 | QCOMPARE(mapper->firstBarSetColumn(), qMax(-1, firstBarSetColumn)); |
|
186 | 186 | QCOMPARE(mapper->lastBarSetColumn(), qMax(-1, lastBarSetColumn)); |
|
187 | 187 | |
|
188 | 188 | delete mapper; |
|
189 | 189 | mapper = 0; |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | void tst_qbarmodelmapper::verticalMapperCustomMapping_data() |
|
193 | 193 | { |
|
194 | 194 | QTest::addColumn<int>("first"); |
|
195 | 195 | QTest::addColumn<int>("countLimit"); |
|
196 | 196 | QTest::addColumn<int>("expectedBarSetCount"); |
|
197 | 197 | QTest::addColumn<int>("expectedCount"); |
|
198 | 198 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelRowCount; |
|
199 | 199 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelRowCount - 3; |
|
200 | 200 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelRowCount); |
|
201 | 201 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelRowCount - 3); |
|
202 | 202 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0 << 0; |
|
203 | 203 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0 << 0; |
|
204 | 204 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << 2 << m_modelRowCount; |
|
205 | 205 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelRowCount; |
|
206 | 206 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelRowCount; |
|
207 | 207 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelRowCount; |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | void tst_qbarmodelmapper::verticalMapperCustomMapping() |
|
211 | 211 | { |
|
212 | 212 | QFETCH(int, first); |
|
213 | 213 | QFETCH(int, countLimit); |
|
214 | 214 | QFETCH(int, expectedBarSetCount); |
|
215 | 215 | QFETCH(int, expectedCount); |
|
216 | 216 | |
|
217 |
m_series = new Q |
|
|
217 | m_series = new QBarSeries; | |
|
218 | 218 | |
|
219 | 219 | QCOMPARE(m_series->count(), 0); |
|
220 | 220 | |
|
221 | 221 | QVBarModelMapper *mapper = new QVBarModelMapper; |
|
222 | 222 | mapper->setFirstBarSetColumn(0); |
|
223 | 223 | mapper->setLastBarSetColumn(1); |
|
224 | 224 | mapper->setModel(m_model); |
|
225 | 225 | mapper->setSeries(m_series); |
|
226 | 226 | mapper->setFirstRow(first); |
|
227 | 227 | mapper->setRowCount(countLimit); |
|
228 | 228 | m_chart->addSeries(m_series); |
|
229 | 229 | |
|
230 | 230 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
231 | 231 | |
|
232 | 232 | if (expectedBarSetCount > 0) |
|
233 | 233 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); |
|
234 | 234 | |
|
235 | 235 | // change values column mapping to invalid |
|
236 | 236 | mapper->setFirstBarSetColumn(-1); |
|
237 | 237 | mapper->setLastBarSetColumn(1); |
|
238 | 238 | |
|
239 | 239 | QCOMPARE(m_series->count(), 0); |
|
240 | 240 | |
|
241 | 241 | delete mapper; |
|
242 | 242 | mapper = 0; |
|
243 | 243 | } |
|
244 | 244 | |
|
245 | 245 | void tst_qbarmodelmapper::horizontalMapper_data() |
|
246 | 246 | { |
|
247 | 247 | QTest::addColumn<int>("firstBarSetRow"); |
|
248 | 248 | QTest::addColumn<int>("lastBarSetRow"); |
|
249 | 249 | QTest::addColumn<int>("expectedBarSetCount"); |
|
250 | 250 | QTest::newRow("lastBarSetRow greater than firstBarSetRow") << 0 << 1 << 2; |
|
251 | 251 | QTest::newRow("lastBarSetRow equal to firstBarSetRow") << 1 << 1 << 1; |
|
252 | 252 | QTest::newRow("lastBarSetRow lesser than firstBarSetRow") << 1 << 0 << 0; |
|
253 | 253 | QTest::newRow("invalid firstBarSetRow and correct lastBarSetRow") << -3 << 1 << 0; |
|
254 | 254 | QTest::newRow("firstBarSetRow beyond the size of model and correct lastBarSetRow") << m_modelRowCount << 1 << 0; |
|
255 | 255 | QTest::newRow("firstBarSetRow beyond the size of model and invalid lastBarSetRow") << m_modelRowCount << -1 << 0; |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | void tst_qbarmodelmapper::horizontalMapper() |
|
259 | 259 | { |
|
260 | 260 | QFETCH(int, firstBarSetRow); |
|
261 | 261 | QFETCH(int, lastBarSetRow); |
|
262 | 262 | QFETCH(int, expectedBarSetCount); |
|
263 | 263 | |
|
264 |
m_series = new Q |
|
|
264 | m_series = new QBarSeries; | |
|
265 | 265 | |
|
266 | 266 | QHBarModelMapper *mapper = new QHBarModelMapper; |
|
267 | 267 | mapper->setFirstBarSetRow(firstBarSetRow); |
|
268 | 268 | mapper->setLastBarSetRow(lastBarSetRow); |
|
269 | 269 | mapper->setModel(m_model); |
|
270 | 270 | mapper->setSeries(m_series); |
|
271 | 271 | |
|
272 | 272 | m_chart->addSeries(m_series); |
|
273 | 273 | |
|
274 | 274 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
275 | 275 | QCOMPARE(mapper->firstBarSetRow(), qMax(-1, firstBarSetRow)); |
|
276 | 276 | QCOMPARE(mapper->lastBarSetRow(), qMax(-1, lastBarSetRow)); |
|
277 | 277 | |
|
278 | 278 | delete mapper; |
|
279 | 279 | mapper = 0; |
|
280 | 280 | } |
|
281 | 281 | |
|
282 | 282 | void tst_qbarmodelmapper::horizontalMapperCustomMapping_data() |
|
283 | 283 | { |
|
284 | 284 | QTest::addColumn<int>("first"); |
|
285 | 285 | QTest::addColumn<int>("countLimit"); |
|
286 | 286 | QTest::addColumn<int>("expectedBarSetCount"); |
|
287 | 287 | QTest::addColumn<int>("expectedCount"); |
|
288 | 288 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelColumnCount; |
|
289 | 289 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelColumnCount - 3; |
|
290 | 290 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelColumnCount); |
|
291 | 291 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelColumnCount - 3); |
|
292 | 292 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0 << 0; |
|
293 | 293 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0 << 0; |
|
294 | 294 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << 2 << m_modelColumnCount; |
|
295 | 295 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelColumnCount; |
|
296 | 296 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelColumnCount; |
|
297 | 297 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelColumnCount; |
|
298 | 298 | } |
|
299 | 299 | |
|
300 | 300 | void tst_qbarmodelmapper::horizontalMapperCustomMapping() |
|
301 | 301 | { |
|
302 | 302 | QFETCH(int, first); |
|
303 | 303 | QFETCH(int, countLimit); |
|
304 | 304 | QFETCH(int, expectedBarSetCount); |
|
305 | 305 | QFETCH(int, expectedCount); |
|
306 | 306 | |
|
307 |
m_series = new Q |
|
|
307 | m_series = new QBarSeries; | |
|
308 | 308 | |
|
309 | 309 | QCOMPARE(m_series->count(), 0); |
|
310 | 310 | |
|
311 | 311 | QHBarModelMapper *mapper = new QHBarModelMapper; |
|
312 | 312 | mapper->setFirstBarSetRow(0); |
|
313 | 313 | mapper->setLastBarSetRow(1); |
|
314 | 314 | mapper->setModel(m_model); |
|
315 | 315 | mapper->setSeries(m_series); |
|
316 | 316 | mapper->setFirstColumn(first); |
|
317 | 317 | mapper->setColumnCount(countLimit); |
|
318 | 318 | m_chart->addSeries(m_series); |
|
319 | 319 | |
|
320 | 320 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
321 | 321 | |
|
322 | 322 | if (expectedBarSetCount > 0) |
|
323 | 323 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); |
|
324 | 324 | |
|
325 | 325 | // change values column mapping to invalid |
|
326 | 326 | mapper->setFirstBarSetRow(-1); |
|
327 | 327 | mapper->setLastBarSetRow(1); |
|
328 | 328 | |
|
329 | 329 | QCOMPARE(m_series->count(), 0); |
|
330 | 330 | |
|
331 | 331 | delete mapper; |
|
332 | 332 | mapper = 0; |
|
333 | 333 | } |
|
334 | 334 | |
|
335 | 335 | void tst_qbarmodelmapper::seriesUpdated() |
|
336 | 336 | { |
|
337 | 337 | // setup the mapper |
|
338 | 338 | createVerticalMapper(); |
|
339 | 339 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
340 | 340 | QCOMPARE(m_vMapper->rowCount(), -1); |
|
341 | 341 | |
|
342 | 342 | m_series->barSets().first()->append(123); |
|
343 | 343 | QCOMPARE(m_model->rowCount(), m_modelRowCount + 1); |
|
344 | 344 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model |
|
345 | 345 | |
|
346 | 346 | m_series->barSets().last()->remove(0, m_modelRowCount); |
|
347 | 347 | QCOMPARE(m_model->rowCount(), 1); |
|
348 | 348 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model |
|
349 | 349 | |
|
350 | 350 | m_series->barSets().first()->replace(0, 444.0); |
|
351 | 351 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 444.0); |
|
352 | 352 | |
|
353 | 353 | m_series->barSets().first()->setLabel("Hello"); |
|
354 | 354 | QCOMPARE(m_model->headerData(0, Qt::Horizontal).toString(), QString("Hello")); |
|
355 | 355 | |
|
356 | 356 | QList<qreal> newValues; |
|
357 | 357 | newValues << 15 << 27 << 35 << 49; |
|
358 | 358 | m_series->barSets().first()->append(newValues); |
|
359 | 359 | QCOMPARE(m_model->rowCount(), 1 + newValues.count()); |
|
360 | 360 | |
|
361 | 361 | QList<QBarSet* > newBarSets; |
|
362 | 362 | QBarSet* newBarSet_1 = new QBarSet("New_1"); |
|
363 | 363 | newBarSet_1->append(101); |
|
364 | 364 | newBarSet_1->append(102); |
|
365 | 365 | newBarSet_1->append(103); |
|
366 | 366 | newBarSets.append(newBarSet_1); |
|
367 | 367 | |
|
368 | 368 | QBarSet* newBarSet_2 = new QBarSet("New_1"); |
|
369 | 369 | newBarSet_2->append(201); |
|
370 | 370 | newBarSet_2->append(202); |
|
371 | 371 | newBarSet_2->append(203); |
|
372 | 372 | newBarSets.append(newBarSet_2); |
|
373 | 373 | |
|
374 | 374 | m_series->append(newBarSets); |
|
375 | 375 | QCOMPARE(m_model->columnCount(), m_modelColumnCount + newBarSets.count()); |
|
376 | 376 | } |
|
377 | 377 | |
|
378 | 378 | void tst_qbarmodelmapper::verticalModelInsertRows() |
|
379 | 379 | { |
|
380 | 380 | // setup the mapper |
|
381 | 381 | createVerticalMapper(); |
|
382 | 382 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
383 | 383 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
384 | 384 | QVERIFY(m_vMapper->model() != 0); |
|
385 | 385 | |
|
386 | 386 | int insertCount = 4; |
|
387 | 387 | m_model->insertRows(3, insertCount); |
|
388 | 388 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
389 | 389 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount); |
|
390 | 390 | |
|
391 | 391 | int first = 3; |
|
392 | 392 | m_vMapper->setFirstRow(3); |
|
393 | 393 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
394 | 394 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount - first); |
|
395 | 395 | |
|
396 | 396 | m_model->insertRows(3, insertCount); |
|
397 | 397 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
398 | 398 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 2 * insertCount - first); |
|
399 | 399 | |
|
400 | 400 | int countLimit = 6; |
|
401 | 401 | m_vMapper->setRowCount(countLimit); |
|
402 | 402 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
403 | 403 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); |
|
404 | 404 | |
|
405 | 405 | m_model->insertRows(3, insertCount); |
|
406 | 406 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
407 | 407 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); |
|
408 | 408 | |
|
409 | 409 | m_vMapper->setFirstRow(0); |
|
410 | 410 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
411 | 411 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); |
|
412 | 412 | |
|
413 | 413 | m_vMapper->setRowCount(-1); |
|
414 | 414 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
415 | 415 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 3 * insertCount); |
|
416 | 416 | } |
|
417 | 417 | |
|
418 | 418 | void tst_qbarmodelmapper::verticalModelRemoveRows() |
|
419 | 419 | { |
|
420 | 420 | // setup the mapper |
|
421 | 421 | createVerticalMapper(); |
|
422 | 422 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
423 | 423 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
424 | 424 | QVERIFY(m_vMapper->model() != 0); |
|
425 | 425 | |
|
426 | 426 | int removeCount = 2; |
|
427 | 427 | m_model->removeRows(1, removeCount); |
|
428 | 428 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
429 | 429 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount); |
|
430 | 430 | |
|
431 | 431 | int first = 1; |
|
432 | 432 | m_vMapper->setFirstRow(first); |
|
433 | 433 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
434 | 434 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount - first); |
|
435 | 435 | |
|
436 | 436 | m_model->removeRows(1, removeCount); |
|
437 | 437 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
438 | 438 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 2 * removeCount - first); |
|
439 | 439 | |
|
440 | 440 | int countLimit = 3; |
|
441 | 441 | m_vMapper->setRowCount(countLimit); |
|
442 | 442 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
443 | 443 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); |
|
444 | 444 | |
|
445 | 445 | m_model->removeRows(1, removeCount); |
|
446 | 446 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
447 | 447 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); |
|
448 | 448 | |
|
449 | 449 | m_vMapper->setFirstRow(0); |
|
450 | 450 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
451 | 451 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); |
|
452 | 452 | |
|
453 | 453 | m_vMapper->setRowCount(-1); |
|
454 | 454 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
455 | 455 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 3 * removeCount); |
|
456 | 456 | } |
|
457 | 457 | |
|
458 | 458 | void tst_qbarmodelmapper::verticalModelInsertColumns() |
|
459 | 459 | { |
|
460 | 460 | // setup the mapper |
|
461 | 461 | createVerticalMapper(); |
|
462 | 462 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
463 | 463 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
464 | 464 | QVERIFY(m_vMapper->model() != 0); |
|
465 | 465 | |
|
466 | 466 | int insertCount = 4; |
|
467 | 467 | m_model->insertColumns(3, insertCount); |
|
468 | 468 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
469 | 469 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
470 | 470 | } |
|
471 | 471 | |
|
472 | 472 | void tst_qbarmodelmapper::verticalModelRemoveColumns() |
|
473 | 473 | { |
|
474 | 474 | // setup the mapper |
|
475 | 475 | createVerticalMapper(); |
|
476 | 476 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); |
|
477 | 477 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
478 | 478 | QVERIFY(m_vMapper->model() != 0); |
|
479 | 479 | |
|
480 | 480 | int removeCount = m_modelColumnCount - 2; |
|
481 | 481 | m_model->removeColumns(0, removeCount); |
|
482 | 482 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); |
|
483 | 483 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
484 | 484 | |
|
485 | 485 | // leave all the columns |
|
486 | 486 | m_model->removeColumns(0, m_modelColumnCount - removeCount); |
|
487 | 487 | QCOMPARE(m_series->count(), 0); |
|
488 | 488 | } |
|
489 | 489 | |
|
490 | 490 | void tst_qbarmodelmapper::horizontalModelInsertRows() |
|
491 | 491 | { |
|
492 | 492 | // setup the mapper |
|
493 | 493 | createHorizontalMapper(); |
|
494 | 494 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
495 | 495 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
496 | 496 | QVERIFY(m_hMapper->model() != 0); |
|
497 | 497 | |
|
498 | 498 | int insertCount = 4; |
|
499 | 499 | m_model->insertRows(3, insertCount); |
|
500 | 500 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
501 | 501 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
502 | 502 | } |
|
503 | 503 | |
|
504 | 504 | void tst_qbarmodelmapper::horizontalModelRemoveRows() |
|
505 | 505 | { |
|
506 | 506 | // setup the mapper |
|
507 | 507 | createHorizontalMapper(); |
|
508 | 508 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); |
|
509 | 509 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
510 | 510 | QVERIFY(m_hMapper->model() != 0); |
|
511 | 511 | |
|
512 | 512 | int removeCount = m_modelRowCount - 2; |
|
513 | 513 | m_model->removeRows(0, removeCount); |
|
514 | 514 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); |
|
515 | 515 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
516 | 516 | |
|
517 | 517 | // leave all the columns |
|
518 | 518 | m_model->removeRows(0, m_modelRowCount - removeCount); |
|
519 | 519 | QCOMPARE(m_series->count(), 0); |
|
520 | 520 | } |
|
521 | 521 | |
|
522 | 522 | void tst_qbarmodelmapper::horizontalModelInsertColumns() |
|
523 | 523 | { |
|
524 | 524 | // setup the mapper |
|
525 | 525 | createHorizontalMapper(); |
|
526 | 526 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
527 | 527 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
528 | 528 | QVERIFY(m_hMapper->model() != 0); |
|
529 | 529 | |
|
530 | 530 | int insertCount = 4; |
|
531 | 531 | m_model->insertColumns(3, insertCount); |
|
532 | 532 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
533 | 533 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount); |
|
534 | 534 | |
|
535 | 535 | int first = 3; |
|
536 | 536 | m_hMapper->setFirstColumn(3); |
|
537 | 537 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
538 | 538 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount - first); |
|
539 | 539 | |
|
540 | 540 | m_model->insertColumns(3, insertCount); |
|
541 | 541 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
542 | 542 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 2 * insertCount - first); |
|
543 | 543 | |
|
544 | 544 | int countLimit = 6; |
|
545 | 545 | m_hMapper->setColumnCount(countLimit); |
|
546 | 546 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
547 | 547 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); |
|
548 | 548 | |
|
549 | 549 | m_model->insertColumns(3, insertCount); |
|
550 | 550 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
551 | 551 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); |
|
552 | 552 | |
|
553 | 553 | m_hMapper->setFirstColumn(0); |
|
554 | 554 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
555 | 555 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); |
|
556 | 556 | |
|
557 | 557 | m_hMapper->setColumnCount(-1); |
|
558 | 558 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
559 | 559 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 3 * insertCount); |
|
560 | 560 | } |
|
561 | 561 | |
|
562 | 562 | void tst_qbarmodelmapper::horizontalModelRemoveColumns() |
|
563 | 563 | { |
|
564 | 564 | // setup the mapper |
|
565 | 565 | createHorizontalMapper(); |
|
566 | 566 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
567 | 567 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
568 | 568 | QVERIFY(m_hMapper->model() != 0); |
|
569 | 569 | |
|
570 | 570 | int removeCount = 2; |
|
571 | 571 | m_model->removeColumns(1, removeCount); |
|
572 | 572 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
573 | 573 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount); |
|
574 | 574 | |
|
575 | 575 | int first = 1; |
|
576 | 576 | m_hMapper->setFirstColumn(first); |
|
577 | 577 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
578 | 578 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount - first); |
|
579 | 579 | |
|
580 | 580 | m_model->removeColumns(1, removeCount); |
|
581 | 581 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
582 | 582 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 2 * removeCount - first); |
|
583 | 583 | |
|
584 | 584 | int countLimit = 3; |
|
585 | 585 | m_hMapper->setColumnCount(countLimit); |
|
586 | 586 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
587 | 587 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); |
|
588 | 588 | |
|
589 | 589 | m_model->removeColumns(1, removeCount); |
|
590 | 590 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
591 | 591 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); |
|
592 | 592 | |
|
593 | 593 | m_hMapper->setFirstColumn(0); |
|
594 | 594 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
595 | 595 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); |
|
596 | 596 | |
|
597 | 597 | m_hMapper->setColumnCount(-1); |
|
598 | 598 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
599 | 599 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 3 * removeCount); |
|
600 | 600 | } |
|
601 | 601 | |
|
602 | 602 | void tst_qbarmodelmapper::modelUpdateCell() |
|
603 | 603 | { |
|
604 | 604 | // setup the mapper |
|
605 | 605 | createVerticalMapper(); |
|
606 | 606 | |
|
607 | 607 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); |
|
608 | 608 | QCOMPARE(m_series->barSets().at(0)->at(1), 44.0); |
|
609 | 609 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); |
|
610 | 610 | } |
|
611 | 611 | |
|
612 | 612 | QTEST_MAIN(tst_qbarmodelmapper) |
|
613 | 613 | |
|
614 | 614 | #include "tst_qbarmodelmapper.moc" |
@@ -1,571 +1,571 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 |
#include <q |
|
|
22 | #include <qbarseries.h> | |
|
23 | 23 | #include <qbarset.h> |
|
24 | 24 | #include <qchartview.h> |
|
25 | 25 | #include <qchart.h> |
|
26 | 26 | #include "tst_definitions.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | Q_DECLARE_METATYPE(QBarSet*) |
|
31 | 31 | |
|
32 | 32 | class tst_QBarSeries : public QObject |
|
33 | 33 | { |
|
34 | 34 | Q_OBJECT |
|
35 | 35 | |
|
36 | 36 | public slots: |
|
37 | 37 | void initTestCase(); |
|
38 | 38 | void cleanupTestCase(); |
|
39 | 39 | void init(); |
|
40 | 40 | void cleanup(); |
|
41 | 41 | |
|
42 | 42 | private slots: |
|
43 | 43 | void qbarseries_data(); |
|
44 | 44 | void qbarseries(); |
|
45 | 45 | void type_data(); |
|
46 | 46 | void type(); |
|
47 | 47 | void append_data(); |
|
48 | 48 | void append(); |
|
49 | 49 | void remove_data(); |
|
50 | 50 | void remove(); |
|
51 | 51 | void appendList_data(); |
|
52 | 52 | void appendList(); |
|
53 | 53 | void count_data(); |
|
54 | 54 | void count(); |
|
55 | 55 | void barSets_data(); |
|
56 | 56 | void barSets(); |
|
57 | 57 | void setLabelsVisible_data(); |
|
58 | 58 | void setLabelsVisible(); |
|
59 | 59 | void mouseclicked_data(); |
|
60 | 60 | void mouseclicked(); |
|
61 | 61 | void mousehovered_data(); |
|
62 | 62 | void mousehovered(); |
|
63 | 63 | void clearWithAnimations(); |
|
64 | 64 | |
|
65 | 65 | private: |
|
66 |
Q |
|
|
67 |
Q |
|
|
66 | QBarSeries* m_barseries; | |
|
67 | QBarSeries* m_barseries_with_sets; | |
|
68 | 68 | |
|
69 | 69 | QList<QBarSet*> m_testSets; |
|
70 | 70 | |
|
71 | 71 | }; |
|
72 | 72 | |
|
73 | 73 | void tst_QBarSeries::initTestCase() |
|
74 | 74 | { |
|
75 | 75 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | void tst_QBarSeries::cleanupTestCase() |
|
79 | 79 | { |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | void tst_QBarSeries::init() |
|
83 | 83 | { |
|
84 |
m_barseries = new Q |
|
|
85 |
m_barseries_with_sets = new Q |
|
|
84 | m_barseries = new QBarSeries(); | |
|
85 | m_barseries_with_sets = new QBarSeries(); | |
|
86 | 86 | |
|
87 | 87 | for (int i=0; i<5; i++) { |
|
88 | 88 | m_testSets.append(new QBarSet("testset")); |
|
89 | 89 | m_barseries_with_sets->append(m_testSets.at(i)); |
|
90 | 90 | } |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | void tst_QBarSeries::cleanup() |
|
94 | 94 | { |
|
95 | 95 | foreach(QBarSet* s, m_testSets) { |
|
96 | 96 | m_barseries_with_sets->remove(s); |
|
97 | 97 | delete s; |
|
98 | 98 | } |
|
99 | 99 | m_testSets.clear(); |
|
100 | 100 | |
|
101 | 101 | delete m_barseries; |
|
102 | 102 | m_barseries = 0; |
|
103 | 103 | delete m_barseries_with_sets; |
|
104 | 104 | m_barseries_with_sets = 0; |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | void tst_QBarSeries::qbarseries_data() |
|
108 | 108 | { |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | void tst_QBarSeries::qbarseries() |
|
112 | 112 | { |
|
113 |
Q |
|
|
113 | QBarSeries *barseries = new QBarSeries(); | |
|
114 | 114 | QVERIFY(barseries != 0); |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | void tst_QBarSeries::type_data() |
|
118 | 118 | { |
|
119 | 119 | |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | void tst_QBarSeries::type() |
|
123 | 123 | { |
|
124 | 124 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
125 | 125 | } |
|
126 | 126 | |
|
127 | 127 | void tst_QBarSeries::append_data() |
|
128 | 128 | { |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | void tst_QBarSeries::append() |
|
132 | 132 | { |
|
133 | 133 | QVERIFY(m_barseries->count() == 0); |
|
134 | 134 | |
|
135 | 135 | bool ret = false; |
|
136 | 136 | |
|
137 | 137 | // Try adding barset |
|
138 | 138 | QBarSet *barset = new QBarSet("testset"); |
|
139 | 139 | ret = m_barseries->append(barset); |
|
140 | 140 | |
|
141 | 141 | QVERIFY(ret == true); |
|
142 | 142 | QVERIFY(m_barseries->count() == 1); |
|
143 | 143 | |
|
144 | 144 | // Try adding another set |
|
145 | 145 | QBarSet *barset2 = new QBarSet("testset2"); |
|
146 | 146 | ret = m_barseries->append(barset2); |
|
147 | 147 | |
|
148 | 148 | QVERIFY(ret == true); |
|
149 | 149 | QVERIFY(m_barseries->count() == 2); |
|
150 | 150 | |
|
151 | 151 | // Try adding same set again |
|
152 | 152 | ret = m_barseries->append(barset2); |
|
153 | 153 | QVERIFY(ret == false); |
|
154 | 154 | QVERIFY(m_barseries->count() == 2); |
|
155 | 155 | |
|
156 | 156 | // Try adding null set |
|
157 | 157 | ret = m_barseries->append(0); |
|
158 | 158 | QVERIFY(ret == false); |
|
159 | 159 | QVERIFY(m_barseries->count() == 2); |
|
160 | 160 | |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | 163 | void tst_QBarSeries::remove_data() |
|
164 | 164 | { |
|
165 | 165 | } |
|
166 | 166 | |
|
167 | 167 | void tst_QBarSeries::remove() |
|
168 | 168 | { |
|
169 | 169 | int count = m_testSets.count(); |
|
170 | 170 | QVERIFY(m_barseries_with_sets->count() == count); |
|
171 | 171 | |
|
172 | 172 | // Try to remove null pointer (should not remove, should not crash) |
|
173 | 173 | bool ret = false; |
|
174 | 174 | ret = m_barseries_with_sets->remove(0); |
|
175 | 175 | QVERIFY(ret == false); |
|
176 | 176 | QVERIFY(m_barseries_with_sets->count() == count); |
|
177 | 177 | |
|
178 | 178 | // Try to remove invalid pointer (should not remove, should not crash) |
|
179 | 179 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); |
|
180 | 180 | QVERIFY(ret == false); |
|
181 | 181 | QVERIFY(m_barseries_with_sets->count() == count); |
|
182 | 182 | |
|
183 | 183 | // remove some sets |
|
184 | 184 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); |
|
185 | 185 | QVERIFY(ret == true); |
|
186 | 186 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); |
|
187 | 187 | QVERIFY(ret == true); |
|
188 | 188 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); |
|
189 | 189 | QVERIFY(ret == true); |
|
190 | 190 | |
|
191 | 191 | QVERIFY(m_barseries_with_sets->count() == 2); |
|
192 | 192 | |
|
193 | 193 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
194 | 194 | |
|
195 | 195 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
196 | 196 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
197 | 197 | |
|
198 | 198 | // Try removing all sets again (should be ok, even if some sets have already been removed) |
|
199 | 199 | ret = false; |
|
200 | 200 | for (int i=0; i<count; i++) { |
|
201 | 201 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | QVERIFY(ret == true); |
|
205 | 205 | QVERIFY(m_barseries_with_sets->count() == 0); |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | void tst_QBarSeries::appendList_data() |
|
209 | 209 | { |
|
210 | 210 | |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | void tst_QBarSeries::appendList() |
|
214 | 214 | { |
|
215 | 215 | int count = 5; |
|
216 | 216 | QVERIFY(m_barseries->count() == 0); |
|
217 | 217 | |
|
218 | 218 | QList<QBarSet*> sets; |
|
219 | 219 | for (int i=0; i<count; i++) { |
|
220 | 220 | sets.append(new QBarSet("testset")); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | // Append new sets (should succeed, count should match the count of sets) |
|
224 | 224 | bool ret = false; |
|
225 | 225 | ret = m_barseries->append(sets); |
|
226 | 226 | QVERIFY(ret == true); |
|
227 | 227 | QVERIFY(m_barseries->count() == count); |
|
228 | 228 | |
|
229 | 229 | // Append same sets again (should fail, count should remain same) |
|
230 | 230 | ret = m_barseries->append(sets); |
|
231 | 231 | QVERIFY(ret == false); |
|
232 | 232 | QVERIFY(m_barseries->count() == count); |
|
233 | 233 | |
|
234 | 234 | // Try append empty list (should succeed, but count should remain same) |
|
235 | 235 | QList<QBarSet*> invalidList; |
|
236 | 236 | ret = m_barseries->append(invalidList); |
|
237 | 237 | QVERIFY(ret == true); |
|
238 | 238 | QVERIFY(m_barseries->count() == count); |
|
239 | 239 | |
|
240 | 240 | // Try append list with one new and one existing set (should fail, count remains same) |
|
241 | 241 | invalidList.append(new QBarSet("ok set")); |
|
242 | 242 | invalidList.append(sets.at(0)); |
|
243 | 243 | ret = m_barseries->append(invalidList); |
|
244 | 244 | QVERIFY(ret == false); |
|
245 | 245 | QVERIFY(m_barseries->count() == count); |
|
246 | 246 | |
|
247 | 247 | // Try append list with null pointers (should fail, count remains same) |
|
248 | 248 | QList<QBarSet*> invalidList2; |
|
249 | 249 | invalidList2.append(0); |
|
250 | 250 | invalidList2.append(0); |
|
251 | 251 | invalidList2.append(0); |
|
252 | 252 | ret = m_barseries->append(invalidList2); |
|
253 | 253 | QVERIFY(ret == false); |
|
254 | 254 | QVERIFY(m_barseries->count() == count); |
|
255 | 255 | } |
|
256 | 256 | |
|
257 | 257 | void tst_QBarSeries::count_data() |
|
258 | 258 | { |
|
259 | 259 | |
|
260 | 260 | } |
|
261 | 261 | |
|
262 | 262 | void tst_QBarSeries::count() |
|
263 | 263 | { |
|
264 | 264 | QVERIFY(m_barseries->count() == 0); |
|
265 | 265 | QVERIFY(m_barseries_with_sets->count() == m_testSets.count()); |
|
266 | 266 | } |
|
267 | 267 | |
|
268 | 268 | void tst_QBarSeries::barSets_data() |
|
269 | 269 | { |
|
270 | 270 | |
|
271 | 271 | } |
|
272 | 272 | |
|
273 | 273 | void tst_QBarSeries::barSets() |
|
274 | 274 | { |
|
275 | 275 | QVERIFY(m_barseries->barSets().count() == 0); |
|
276 | 276 | |
|
277 | 277 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
278 | 278 | QVERIFY(sets.count() == m_testSets.count()); |
|
279 | 279 | |
|
280 | 280 | for (int i=0; i<m_testSets.count(); i++) { |
|
281 | 281 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
282 | 282 | } |
|
283 | 283 | } |
|
284 | 284 | |
|
285 | 285 | void tst_QBarSeries::setLabelsVisible_data() |
|
286 | 286 | { |
|
287 | 287 | |
|
288 | 288 | } |
|
289 | 289 | |
|
290 | 290 | void tst_QBarSeries::setLabelsVisible() |
|
291 | 291 | { |
|
292 | 292 | // labels should be invisible by default |
|
293 | 293 | QVERIFY(m_barseries->isLabelsVisible() == false); |
|
294 | 294 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
295 | 295 | |
|
296 | 296 | // turn labels to visible |
|
297 | 297 | m_barseries_with_sets->setLabelsVisible(true); |
|
298 | 298 | // TODO: test the signal |
|
299 | 299 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
300 | 300 | |
|
301 | 301 | // turn labels to invisible |
|
302 | 302 | m_barseries_with_sets->setLabelsVisible(false); |
|
303 | 303 | // TODO: test the signal |
|
304 | 304 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
305 | 305 | |
|
306 | 306 | // without parameter, should turn labels to visible |
|
307 | 307 | m_barseries_with_sets->setLabelsVisible(); |
|
308 | 308 | // TODO: test the signal |
|
309 | 309 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
310 | 310 | } |
|
311 | 311 | |
|
312 | 312 | void tst_QBarSeries::mouseclicked_data() |
|
313 | 313 | { |
|
314 | 314 | |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | void tst_QBarSeries::mouseclicked() |
|
318 | 318 | { |
|
319 |
Q |
|
|
319 | QBarSeries* series = new QBarSeries(); | |
|
320 | 320 | |
|
321 | 321 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
322 | 322 | *set1 << 10 << 10 << 10; |
|
323 | 323 | series->append(set1); |
|
324 | 324 | |
|
325 | 325 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
326 | 326 | *set2 << 10 << 10 << 10; |
|
327 | 327 | series->append(set2); |
|
328 | 328 | |
|
329 | 329 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*))); |
|
330 | 330 | QSignalSpy setSpy1(set1, SIGNAL(clicked(int))); |
|
331 | 331 | QSignalSpy setSpy2(set2, SIGNAL(clicked(int))); |
|
332 | 332 | |
|
333 | 333 | QChartView view(new QChart()); |
|
334 | 334 | view.resize(400,300); |
|
335 | 335 | view.chart()->addSeries(series); |
|
336 | 336 | view.show(); |
|
337 | 337 | QTest::qWaitForWindowShown(&view); |
|
338 | 338 | |
|
339 | 339 | //==================================================================================== |
|
340 | 340 | // barset 1, bar 0 |
|
341 | 341 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142)); |
|
342 | 342 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
343 | 343 | |
|
344 | 344 | QCOMPARE(seriesSpy.count(), 1); |
|
345 | 345 | QCOMPARE(setSpy1.count(), 1); |
|
346 | 346 | QCOMPARE(setSpy2.count(), 0); |
|
347 | 347 | |
|
348 | 348 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
349 | 349 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
350 | 350 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
351 | 351 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
352 | 352 | |
|
353 | 353 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
354 | 354 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
355 | 355 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
356 | 356 | |
|
357 | 357 | //==================================================================================== |
|
358 | 358 | // barset 1, bar 1 |
|
359 | 359 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142)); |
|
360 | 360 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
361 | 361 | |
|
362 | 362 | QCOMPARE(seriesSpy.count(), 1); |
|
363 | 363 | QCOMPARE(setSpy1.count(), 1); |
|
364 | 364 | QCOMPARE(setSpy2.count(), 0); |
|
365 | 365 | |
|
366 | 366 | seriesSpyArg = seriesSpy.takeFirst(); |
|
367 | 367 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
368 | 368 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
369 | 369 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
370 | 370 | |
|
371 | 371 | setSpyArg = setSpy1.takeFirst(); |
|
372 | 372 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
373 | 373 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
374 | 374 | |
|
375 | 375 | //==================================================================================== |
|
376 | 376 | // barset 1, bar 2 |
|
377 | 377 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142)); |
|
378 | 378 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
379 | 379 | |
|
380 | 380 | QCOMPARE(seriesSpy.count(), 1); |
|
381 | 381 | QCOMPARE(setSpy1.count(), 1); |
|
382 | 382 | QCOMPARE(setSpy2.count(), 0); |
|
383 | 383 | |
|
384 | 384 | seriesSpyArg = seriesSpy.takeFirst(); |
|
385 | 385 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
386 | 386 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
387 | 387 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
388 | 388 | |
|
389 | 389 | setSpyArg = setSpy1.takeFirst(); |
|
390 | 390 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
391 | 391 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
392 | 392 | |
|
393 | 393 | //==================================================================================== |
|
394 | 394 | // barset 2, bar 0 |
|
395 | 395 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142)); |
|
396 | 396 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
397 | 397 | |
|
398 | 398 | QCOMPARE(seriesSpy.count(), 1); |
|
399 | 399 | QCOMPARE(setSpy1.count(), 0); |
|
400 | 400 | QCOMPARE(setSpy2.count(), 1); |
|
401 | 401 | |
|
402 | 402 | seriesSpyArg = seriesSpy.takeFirst(); |
|
403 | 403 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
404 | 404 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
405 | 405 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
406 | 406 | |
|
407 | 407 | setSpyArg = setSpy2.takeFirst(); |
|
408 | 408 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
409 | 409 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
410 | 410 | |
|
411 | 411 | //==================================================================================== |
|
412 | 412 | // barset 2, bar 1 |
|
413 | 413 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142)); |
|
414 | 414 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
415 | 415 | |
|
416 | 416 | QCOMPARE(seriesSpy.count(), 1); |
|
417 | 417 | QCOMPARE(setSpy1.count(), 0); |
|
418 | 418 | QCOMPARE(setSpy2.count(), 1); |
|
419 | 419 | |
|
420 | 420 | seriesSpyArg = seriesSpy.takeFirst(); |
|
421 | 421 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
422 | 422 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
423 | 423 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
424 | 424 | |
|
425 | 425 | setSpyArg = setSpy2.takeFirst(); |
|
426 | 426 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
427 | 427 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
428 | 428 | |
|
429 | 429 | //==================================================================================== |
|
430 | 430 | // barset 2, bar 2 |
|
431 | 431 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142)); |
|
432 | 432 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
433 | 433 | |
|
434 | 434 | QCOMPARE(seriesSpy.count(), 1); |
|
435 | 435 | QCOMPARE(setSpy1.count(), 0); |
|
436 | 436 | QCOMPARE(setSpy2.count(), 1); |
|
437 | 437 | |
|
438 | 438 | seriesSpyArg = seriesSpy.takeFirst(); |
|
439 | 439 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
440 | 440 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
441 | 441 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
442 | 442 | |
|
443 | 443 | setSpyArg = setSpy2.takeFirst(); |
|
444 | 444 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
445 | 445 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
446 | 446 | } |
|
447 | 447 | |
|
448 | 448 | void tst_QBarSeries::mousehovered_data() |
|
449 | 449 | { |
|
450 | 450 | |
|
451 | 451 | } |
|
452 | 452 | |
|
453 | 453 | void tst_QBarSeries::mousehovered() |
|
454 | 454 | { |
|
455 |
Q |
|
|
455 | QBarSeries* series = new QBarSeries(); | |
|
456 | 456 | |
|
457 | 457 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
458 | 458 | *set1 << 10 << 10 << 10; |
|
459 | 459 | series->append(set1); |
|
460 | 460 | |
|
461 | 461 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
462 | 462 | *set2 << 10 << 10 << 10; |
|
463 | 463 | series->append(set2); |
|
464 | 464 | |
|
465 | 465 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*))); |
|
466 | 466 | QSignalSpy setSpy1(set1, SIGNAL(hovered(bool))); |
|
467 | 467 | QSignalSpy setSpy2(set2, SIGNAL(hovered(bool))); |
|
468 | 468 | |
|
469 | 469 | QChartView view(new QChart()); |
|
470 | 470 | view.resize(400,300); |
|
471 | 471 | view.chart()->addSeries(series); |
|
472 | 472 | view.show(); |
|
473 | 473 | QTest::qWaitForWindowShown(&view); |
|
474 | 474 | |
|
475 | 475 | //this is hack since view does not get events otherwise |
|
476 | 476 | view.setMouseTracking(true); |
|
477 | 477 | |
|
478 | 478 | //======================================================================= |
|
479 | 479 | // move mouse to left border |
|
480 | 480 | QTest::mouseMove(view.viewport(), QPoint(0, 142)); |
|
481 | 481 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); |
|
482 | 482 | TRY_COMPARE(seriesSpy.count(), 0); |
|
483 | 483 | TRY_COMPARE(setSpy1.count(), 0); |
|
484 | 484 | TRY_COMPARE(setSpy2.count(), 0); |
|
485 | 485 | |
|
486 | 486 | //======================================================================= |
|
487 | 487 | // move mouse on top of set1 |
|
488 | 488 | QTest::mouseMove(view.viewport(), QPoint(102,142)); |
|
489 | 489 | TRY_COMPARE(seriesSpy.count(), 1); |
|
490 | 490 | TRY_COMPARE(setSpy1.count(), 1); |
|
491 | 491 | TRY_COMPARE(setSpy2.count(), 0); |
|
492 | 492 | |
|
493 | 493 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
494 | 494 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
495 | 495 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
496 | 496 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
497 | 497 | |
|
498 | 498 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
499 | 499 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
500 | 500 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
501 | 501 | |
|
502 | 502 | //======================================================================= |
|
503 | 503 | // move mouse from top of set1 to top of set2 |
|
504 | 504 | QTest::mouseMove(view.viewport(), QPoint(127,142)); |
|
505 | 505 | TRY_COMPARE(seriesSpy.count(), 2); |
|
506 | 506 | TRY_COMPARE(setSpy1.count(), 1); |
|
507 | 507 | TRY_COMPARE(setSpy2.count(), 1); |
|
508 | 508 | |
|
509 | 509 | // should leave set1 |
|
510 | 510 | seriesSpyArg = seriesSpy.takeFirst(); |
|
511 | 511 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
512 | 512 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
513 | 513 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
514 | 514 | |
|
515 | 515 | setSpyArg = setSpy1.takeFirst(); |
|
516 | 516 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
517 | 517 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
518 | 518 | |
|
519 | 519 | // should enter set2 |
|
520 | 520 | seriesSpyArg = seriesSpy.takeFirst(); |
|
521 | 521 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
522 | 522 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
523 | 523 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
524 | 524 | |
|
525 | 525 | setSpyArg = setSpy2.takeFirst(); |
|
526 | 526 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
527 | 527 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
528 | 528 | |
|
529 | 529 | //======================================================================= |
|
530 | 530 | // move mouse from top of set2 to background |
|
531 | 531 | QTest::mouseMove(view.viewport(), QPoint(127,0)); |
|
532 | 532 | TRY_COMPARE(seriesSpy.count(), 1); |
|
533 | 533 | TRY_COMPARE(setSpy1.count(), 0); |
|
534 | 534 | TRY_COMPARE(setSpy2.count(), 1); |
|
535 | 535 | |
|
536 | 536 | // should leave set2 |
|
537 | 537 | seriesSpyArg = seriesSpy.takeFirst(); |
|
538 | 538 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
539 | 539 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
540 | 540 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
541 | 541 | |
|
542 | 542 | setSpyArg = setSpy2.takeFirst(); |
|
543 | 543 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
544 | 544 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
545 | 545 | } |
|
546 | 546 | |
|
547 | 547 | void tst_QBarSeries::clearWithAnimations() |
|
548 | 548 | { |
|
549 |
Q |
|
|
549 | QBarSeries* series = new QBarSeries(); | |
|
550 | 550 | |
|
551 | 551 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
552 | 552 | *set1 << 10 << 10 << 10; |
|
553 | 553 | series->append(set1); |
|
554 | 554 | |
|
555 | 555 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
556 | 556 | *set2 << 10 << 10 << 10; |
|
557 | 557 | series->append(set2); |
|
558 | 558 | |
|
559 | 559 | QChartView view(new QChart()); |
|
560 | 560 | view.resize(400,300); |
|
561 | 561 | view.chart()->setAnimationOptions(QChart::SeriesAnimations); |
|
562 | 562 | view.chart()->addSeries(series); |
|
563 | 563 | view.show(); |
|
564 | 564 | |
|
565 | 565 | series->clear(); |
|
566 | 566 | } |
|
567 | 567 | |
|
568 | 568 | QTEST_MAIN(tst_QBarSeries) |
|
569 | 569 | |
|
570 | 570 | #include "tst_qbarseries.moc" |
|
571 | 571 |
@@ -1,488 +1,488 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | #include <qbarset.h> |
|
23 |
#include <q |
|
|
23 | #include <qbarseries.h> | |
|
24 | 24 | #include <qchartview.h> |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | class tst_QBarSet : public QObject |
|
29 | 29 | { |
|
30 | 30 | Q_OBJECT |
|
31 | 31 | |
|
32 | 32 | public slots: |
|
33 | 33 | void initTestCase(); |
|
34 | 34 | void cleanupTestCase(); |
|
35 | 35 | void init(); |
|
36 | 36 | void cleanup(); |
|
37 | 37 | |
|
38 | 38 | private slots: |
|
39 | 39 | void qbarset_data(); |
|
40 | 40 | void qbarset(); |
|
41 | 41 | void label_data(); |
|
42 | 42 | void label(); |
|
43 | 43 | void append_data(); |
|
44 | 44 | void append(); |
|
45 | 45 | void appendOperator_data(); |
|
46 | 46 | void appendOperator(); |
|
47 | 47 | void insert_data(); |
|
48 | 48 | void insert(); |
|
49 | 49 | void remove_data(); |
|
50 | 50 | void remove(); |
|
51 | 51 | void replace_data(); |
|
52 | 52 | void replace(); |
|
53 | 53 | void at_data(); |
|
54 | 54 | void at(); |
|
55 | 55 | void atOperator_data(); |
|
56 | 56 | void atOperator(); |
|
57 | 57 | void count_data(); |
|
58 | 58 | void count(); |
|
59 | 59 | void sum_data(); |
|
60 | 60 | void sum(); |
|
61 | 61 | void customize(); |
|
62 | 62 | |
|
63 | 63 | private: |
|
64 | 64 | QBarSet* m_barset; |
|
65 | 65 | }; |
|
66 | 66 | |
|
67 | 67 | void tst_QBarSet::initTestCase() |
|
68 | 68 | { |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | void tst_QBarSet::cleanupTestCase() |
|
72 | 72 | { |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | void tst_QBarSet::init() |
|
76 | 76 | { |
|
77 | 77 | m_barset = new QBarSet(QString("label")); |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | void tst_QBarSet::cleanup() |
|
81 | 81 | { |
|
82 | 82 | delete m_barset; |
|
83 | 83 | m_barset = 0; |
|
84 | 84 | } |
|
85 | 85 | |
|
86 | 86 | void tst_QBarSet::qbarset_data() |
|
87 | 87 | { |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | void tst_QBarSet::qbarset() |
|
91 | 91 | { |
|
92 | 92 | QBarSet barset(QString("label")); |
|
93 | 93 | QCOMPARE(barset.label(), QString("label")); |
|
94 | 94 | QCOMPARE(barset.count(), 0); |
|
95 | 95 | QVERIFY(qFuzzyIsNull(barset.sum())); |
|
96 | 96 | } |
|
97 | 97 | |
|
98 | 98 | void tst_QBarSet::label_data() |
|
99 | 99 | { |
|
100 | 100 | QTest::addColumn<QString> ("label"); |
|
101 | 101 | QTest::addColumn<QString> ("result"); |
|
102 | 102 | QTest::newRow("label0") << QString("label0") << QString("label0"); |
|
103 | 103 | QTest::newRow("label1") << QString("label1") << QString("label1"); |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | void tst_QBarSet::label() |
|
107 | 107 | { |
|
108 | 108 | QFETCH(QString, label); |
|
109 | 109 | QFETCH(QString, result); |
|
110 | 110 | |
|
111 | 111 | QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged())); |
|
112 | 112 | m_barset->setLabel(label); |
|
113 | 113 | QCOMPARE(m_barset->label(), result); |
|
114 | 114 | QVERIFY(labelSpy.count() == 1); |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | void tst_QBarSet::append_data() |
|
118 | 118 | { |
|
119 | 119 | QTest::addColumn<int> ("count"); |
|
120 | 120 | QTest::newRow("0") << 0; |
|
121 | 121 | QTest::newRow("5") << 5; |
|
122 | 122 | QTest::newRow("100") << 100; |
|
123 | 123 | QTest::newRow("1000") << 1000; |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | void tst_QBarSet::append() |
|
127 | 127 | { |
|
128 | 128 | QFETCH(int, count); |
|
129 | 129 | |
|
130 | 130 | QCOMPARE(m_barset->count(), 0); |
|
131 | 131 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
132 | 132 | |
|
133 | 133 | QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int))); |
|
134 | 134 | |
|
135 | 135 | qreal sum(0.0); |
|
136 | 136 | qreal value(0.0); |
|
137 | 137 | |
|
138 | 138 | for (int i=0; i<count; i++) { |
|
139 | 139 | m_barset->append(value); |
|
140 | 140 | QCOMPARE(m_barset->at(i), value); |
|
141 | 141 | sum += value; |
|
142 | 142 | value += 1.0; |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | QCOMPARE(m_barset->count(), count); |
|
146 | 146 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
147 | 147 | |
|
148 | 148 | QCOMPARE(valueSpy.count(), count); |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | void tst_QBarSet::appendOperator_data() |
|
152 | 152 | { |
|
153 | 153 | append_data(); |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | void tst_QBarSet::appendOperator() |
|
157 | 157 | { |
|
158 | 158 | QFETCH(int, count); |
|
159 | 159 | |
|
160 | 160 | QCOMPARE(m_barset->count(), 0); |
|
161 | 161 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
162 | 162 | |
|
163 | 163 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); |
|
164 | 164 | |
|
165 | 165 | qreal sum(0.0); |
|
166 | 166 | qreal value(0.0); |
|
167 | 167 | |
|
168 | 168 | for (int i=0; i<count; i++) { |
|
169 | 169 | *m_barset << value; |
|
170 | 170 | QCOMPARE(m_barset->at(i), value); |
|
171 | 171 | sum += value; |
|
172 | 172 | value += 1.0; |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | 175 | QCOMPARE(m_barset->count(), count); |
|
176 | 176 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
177 | 177 | QCOMPARE(valueSpy.count(), count); |
|
178 | 178 | } |
|
179 | 179 | |
|
180 | 180 | void tst_QBarSet::insert_data() |
|
181 | 181 | { |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | void tst_QBarSet::insert() |
|
185 | 185 | { |
|
186 | 186 | QCOMPARE(m_barset->count(), 0); |
|
187 | 187 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
188 | 188 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); |
|
189 | 189 | |
|
190 | 190 | m_barset->insert(0, 1.0); // 1.0 |
|
191 | 191 | QCOMPARE(m_barset->at(0), 1.0); |
|
192 | 192 | QCOMPARE(m_barset->count(), 1); |
|
193 | 193 | QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0)); |
|
194 | 194 | |
|
195 | 195 | m_barset->insert(0, 2.0); // 2.0 1.0 |
|
196 | 196 | QCOMPARE(m_barset->at(0), 2.0); |
|
197 | 197 | QCOMPARE(m_barset->at(1), 1.0); |
|
198 | 198 | QCOMPARE(m_barset->count(), 2); |
|
199 | 199 | QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0)); |
|
200 | 200 | |
|
201 | 201 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 |
|
202 | 202 | QCOMPARE(m_barset->at(1), 3.0); |
|
203 | 203 | QCOMPARE(m_barset->at(0), 2.0); |
|
204 | 204 | QCOMPARE(m_barset->at(2), 1.0); |
|
205 | 205 | QCOMPARE(m_barset->count(), 3); |
|
206 | 206 | QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0)); |
|
207 | 207 | QCOMPARE(valueSpy.count(), 3); |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | void tst_QBarSet::remove_data() |
|
211 | 211 | { |
|
212 | 212 | } |
|
213 | 213 | |
|
214 | 214 | void tst_QBarSet::remove() |
|
215 | 215 | { |
|
216 | 216 | QCOMPARE(m_barset->count(), 0); |
|
217 | 217 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
218 | 218 | |
|
219 | 219 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int))); |
|
220 | 220 | |
|
221 | 221 | m_barset->append(1.0); |
|
222 | 222 | m_barset->append(2.0); |
|
223 | 223 | m_barset->append(3.0); |
|
224 | 224 | m_barset->append(4.0); |
|
225 | 225 | |
|
226 | 226 | QCOMPARE(m_barset->count(), 4); |
|
227 | 227 | QCOMPARE(m_barset->sum(), 10.0); |
|
228 | 228 | |
|
229 | 229 | // Remove middle |
|
230 | 230 | m_barset->remove(2); // 1.0 2.0 4.0 |
|
231 | 231 | QCOMPARE(m_barset->at(0), 1.0); |
|
232 | 232 | QCOMPARE(m_barset->at(1), 2.0); |
|
233 | 233 | QCOMPARE(m_barset->at(2), 4.0); |
|
234 | 234 | QCOMPARE(m_barset->count(), 3); |
|
235 | 235 | QCOMPARE(m_barset->sum(), 7.0); |
|
236 | 236 | QCOMPARE(valueSpy.count(), 1); |
|
237 | 237 | |
|
238 | 238 | QList<QVariant> valueSpyArg = valueSpy.takeFirst(); |
|
239 | 239 | // Verify index of removed signal |
|
240 | 240 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); |
|
241 | 241 | QVERIFY(valueSpyArg.at(0).toInt() == 2); |
|
242 | 242 | // Verify count of removed signal |
|
243 | 243 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); |
|
244 | 244 | QVERIFY(valueSpyArg.at(1).toInt() == 1); |
|
245 | 245 | |
|
246 | 246 | // Remove first |
|
247 | 247 | m_barset->remove(0); // 2.0 4.0 |
|
248 | 248 | QCOMPARE(m_barset->at(0), 2.0); |
|
249 | 249 | QCOMPARE(m_barset->at(1), 4.0); |
|
250 | 250 | QCOMPARE(m_barset->count(), 2); |
|
251 | 251 | QCOMPARE(m_barset->sum(), 6.0); |
|
252 | 252 | |
|
253 | 253 | QCOMPARE(valueSpy.count(), 1); |
|
254 | 254 | valueSpyArg = valueSpy.takeFirst(); |
|
255 | 255 | // Verify index of removed signal |
|
256 | 256 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); |
|
257 | 257 | QVERIFY(valueSpyArg.at(0).toInt() == 0); |
|
258 | 258 | // Verify count of removed signal |
|
259 | 259 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); |
|
260 | 260 | QVERIFY(valueSpyArg.at(1).toInt() == 1); |
|
261 | 261 | |
|
262 | 262 | |
|
263 | 263 | // Illegal indexes |
|
264 | 264 | m_barset->remove(4); |
|
265 | 265 | QCOMPARE(m_barset->count(), 2); |
|
266 | 266 | QCOMPARE(m_barset->sum(), 6.0); |
|
267 | 267 | m_barset->remove(-1); |
|
268 | 268 | QCOMPARE(m_barset->count(), 2); |
|
269 | 269 | QCOMPARE(m_barset->sum(), 6.0); |
|
270 | 270 | |
|
271 | 271 | // nothing removed, no signals should be emitted |
|
272 | 272 | QCOMPARE(valueSpy.count(), 0); |
|
273 | 273 | |
|
274 | 274 | // Remove more items than list has |
|
275 | 275 | m_barset->remove(0,312); |
|
276 | 276 | QCOMPARE(m_barset->count(), 0); |
|
277 | 277 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
278 | 278 | |
|
279 | 279 | QCOMPARE(valueSpy.count(), 1); |
|
280 | 280 | valueSpyArg = valueSpy.takeFirst(); |
|
281 | 281 | |
|
282 | 282 | // Verify index of removed signal |
|
283 | 283 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); |
|
284 | 284 | QVERIFY(valueSpyArg.at(0).toInt() == 0); |
|
285 | 285 | // Verify count of removed signal (expect 2 values removed, because list had only 2 items) |
|
286 | 286 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); |
|
287 | 287 | QVERIFY(valueSpyArg.at(1).toInt() == 2); |
|
288 | 288 | } |
|
289 | 289 | |
|
290 | 290 | void tst_QBarSet::replace_data() |
|
291 | 291 | { |
|
292 | 292 | |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | void tst_QBarSet::replace() |
|
296 | 296 | { |
|
297 | 297 | QCOMPARE(m_barset->count(), 0); |
|
298 | 298 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
299 | 299 | QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int))); |
|
300 | 300 | |
|
301 | 301 | m_barset->append(1.0); |
|
302 | 302 | m_barset->append(2.0); |
|
303 | 303 | m_barset->append(3.0); |
|
304 | 304 | m_barset->append(4.0); |
|
305 | 305 | |
|
306 | 306 | QCOMPARE(m_barset->count(), 4); |
|
307 | 307 | QCOMPARE(m_barset->sum(), 10.0); |
|
308 | 308 | |
|
309 | 309 | // Replace first |
|
310 | 310 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 |
|
311 | 311 | QCOMPARE(m_barset->count(), 4); |
|
312 | 312 | QCOMPARE(m_barset->sum(), 14.0); |
|
313 | 313 | QCOMPARE(m_barset->at(0), 5.0); |
|
314 | 314 | |
|
315 | 315 | // Replace last |
|
316 | 316 | m_barset->replace(3, 6.0); |
|
317 | 317 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
318 | 318 | QCOMPARE(m_barset->sum(), 16.0); |
|
319 | 319 | QCOMPARE(m_barset->at(0), 5.0); |
|
320 | 320 | QCOMPARE(m_barset->at(1), 2.0); |
|
321 | 321 | QCOMPARE(m_barset->at(2), 3.0); |
|
322 | 322 | QCOMPARE(m_barset->at(3), 6.0); |
|
323 | 323 | |
|
324 | 324 | // Illegal indexes |
|
325 | 325 | m_barset->replace(4, 6.0); |
|
326 | 326 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
327 | 327 | QCOMPARE(m_barset->sum(), 16.0); |
|
328 | 328 | m_barset->replace(-1, 6.0); |
|
329 | 329 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
330 | 330 | QCOMPARE(m_barset->sum(), 16.0); |
|
331 | 331 | m_barset->replace(4, 1.0); |
|
332 | 332 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
333 | 333 | QCOMPARE(m_barset->sum(), 16.0); |
|
334 | 334 | m_barset->replace(-1, 1.0); |
|
335 | 335 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
336 | 336 | QCOMPARE(m_barset->sum(), 16.0); |
|
337 | 337 | |
|
338 | 338 | QVERIFY(valueSpy.count() == 2); |
|
339 | 339 | } |
|
340 | 340 | |
|
341 | 341 | void tst_QBarSet::at_data() |
|
342 | 342 | { |
|
343 | 343 | |
|
344 | 344 | } |
|
345 | 345 | |
|
346 | 346 | void tst_QBarSet::at() |
|
347 | 347 | { |
|
348 | 348 | QCOMPARE(m_barset->count(), 0); |
|
349 | 349 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
350 | 350 | |
|
351 | 351 | m_barset->append(1.0); |
|
352 | 352 | m_barset->append(2.0); |
|
353 | 353 | m_barset->append(3.0); |
|
354 | 354 | m_barset->append(4.0); |
|
355 | 355 | |
|
356 | 356 | QCOMPARE(m_barset->at(0), 1.0); |
|
357 | 357 | QCOMPARE(m_barset->at(1), 2.0); |
|
358 | 358 | QCOMPARE(m_barset->at(2), 3.0); |
|
359 | 359 | QCOMPARE(m_barset->at(3), 4.0); |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | void tst_QBarSet::atOperator_data() |
|
363 | 363 | { |
|
364 | 364 | |
|
365 | 365 | } |
|
366 | 366 | |
|
367 | 367 | void tst_QBarSet::atOperator() |
|
368 | 368 | { |
|
369 | 369 | QCOMPARE(m_barset->count(), 0); |
|
370 | 370 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
371 | 371 | |
|
372 | 372 | m_barset->append(1.0); |
|
373 | 373 | m_barset->append(2.0); |
|
374 | 374 | m_barset->append(3.0); |
|
375 | 375 | m_barset->append(4.0); |
|
376 | 376 | |
|
377 | 377 | QCOMPARE(m_barset->operator [](0), 1.0); |
|
378 | 378 | QCOMPARE(m_barset->operator [](1), 2.0); |
|
379 | 379 | QCOMPARE(m_barset->operator [](2), 3.0); |
|
380 | 380 | QCOMPARE(m_barset->operator [](3), 4.0); |
|
381 | 381 | } |
|
382 | 382 | |
|
383 | 383 | void tst_QBarSet::count_data() |
|
384 | 384 | { |
|
385 | 385 | |
|
386 | 386 | } |
|
387 | 387 | |
|
388 | 388 | void tst_QBarSet::count() |
|
389 | 389 | { |
|
390 | 390 | QCOMPARE(m_barset->count(), 0); |
|
391 | 391 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
392 | 392 | |
|
393 | 393 | m_barset->append(1.0); |
|
394 | 394 | QCOMPARE(m_barset->count(),1); |
|
395 | 395 | m_barset->append(2.0); |
|
396 | 396 | QCOMPARE(m_barset->count(),2); |
|
397 | 397 | m_barset->append(3.0); |
|
398 | 398 | QCOMPARE(m_barset->count(),3); |
|
399 | 399 | m_barset->append(4.0); |
|
400 | 400 | QCOMPARE(m_barset->count(),4); |
|
401 | 401 | } |
|
402 | 402 | |
|
403 | 403 | void tst_QBarSet::sum_data() |
|
404 | 404 | { |
|
405 | 405 | |
|
406 | 406 | } |
|
407 | 407 | |
|
408 | 408 | void tst_QBarSet::sum() |
|
409 | 409 | { |
|
410 | 410 | QCOMPARE(m_barset->count(), 0); |
|
411 | 411 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
412 | 412 | |
|
413 | 413 | m_barset->append(1.0); |
|
414 | 414 | QVERIFY(qFuzzyCompare(m_barset->sum(),1.0)); |
|
415 | 415 | m_barset->append(2.0); |
|
416 | 416 | QVERIFY(qFuzzyCompare(m_barset->sum(),3.0)); |
|
417 | 417 | m_barset->append(3.0); |
|
418 | 418 | QVERIFY(qFuzzyCompare(m_barset->sum(),6.0)); |
|
419 | 419 | m_barset->append(4.0); |
|
420 | 420 | QVERIFY(qFuzzyCompare(m_barset->sum(),10.0)); |
|
421 | 421 | } |
|
422 | 422 | |
|
423 | 423 | void tst_QBarSet::customize() |
|
424 | 424 | { |
|
425 | 425 | // Create sets |
|
426 | 426 | QBarSet *set1 = new QBarSet("set1"); |
|
427 | 427 | QBarSet *set2 = new QBarSet("set2"); |
|
428 | 428 | |
|
429 | 429 | // Append set1 to series |
|
430 |
Q |
|
|
430 | QBarSeries *series = new QBarSeries(); | |
|
431 | 431 | bool success = series->append(set1); |
|
432 | 432 | QVERIFY(success); |
|
433 | 433 | |
|
434 | 434 | // Add series to the chart |
|
435 | 435 | QChartView view(new QChart()); |
|
436 | 436 | view.resize(200, 200); |
|
437 | 437 | view.chart()->addSeries(series); |
|
438 | 438 | view.show(); |
|
439 | 439 | QTest::qWaitForWindowShown(&view); |
|
440 | 440 | |
|
441 | 441 | // Test adding data to the sets |
|
442 | 442 | *set1 << 1 << 2 << 1 << 3; |
|
443 | 443 | *set2 << 2 << 1 << 3 << 1; |
|
444 | 444 | |
|
445 | 445 | // Test pen |
|
446 | 446 | QVERIFY(set1->pen() != QPen()); |
|
447 | 447 | QVERIFY(set2->pen() == QPen()); |
|
448 | 448 | QPen pen(QColor(128,128,128,128)); |
|
449 | 449 | set1->setPen(pen); |
|
450 | 450 | QVERIFY(set1->pen() == pen); |
|
451 | 451 | QVERIFY(set2->pen() == QPen()); |
|
452 | 452 | |
|
453 | 453 | // Test brush |
|
454 | 454 | QVERIFY(set1->brush() != QBrush()); |
|
455 | 455 | QVERIFY(set2->brush() == QBrush()); |
|
456 | 456 | QBrush brush(QColor(128,128,128,128)); |
|
457 | 457 | set1->setBrush(brush); |
|
458 | 458 | QVERIFY(set1->brush() == brush); |
|
459 | 459 | QVERIFY(set2->brush() == QBrush()); |
|
460 | 460 | |
|
461 | 461 | // Test label brush |
|
462 | 462 | QVERIFY(set1->labelBrush() != QBrush()); |
|
463 | 463 | QVERIFY(set2->labelBrush() == QBrush()); |
|
464 | 464 | set1->setLabelBrush(brush); |
|
465 | 465 | QVERIFY(set1->labelBrush() == brush); |
|
466 | 466 | QVERIFY(set2->labelBrush() == QBrush()); |
|
467 | 467 | |
|
468 | 468 | // Test label font |
|
469 | 469 | // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the |
|
470 | 470 | // same for the set added to the series (depending on the QChart's theme configuration) |
|
471 | 471 | QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont()); |
|
472 | 472 | QVERIFY(set2->labelFont() == QFont()); |
|
473 | 473 | QFont font; |
|
474 | 474 | font.setBold(true); |
|
475 | 475 | font.setItalic(true); |
|
476 | 476 | set1->setLabelFont(font); |
|
477 | 477 | QVERIFY(set1->labelFont() == font); |
|
478 | 478 | QVERIFY(set2->labelFont() == QFont()); |
|
479 | 479 | |
|
480 | 480 | // Test adding data to the sets |
|
481 | 481 | *set1 << 1 << 2 << 1 << 3; |
|
482 | 482 | *set2 << 2 << 1 << 3 << 1; |
|
483 | 483 | } |
|
484 | 484 | |
|
485 | 485 | QTEST_MAIN(tst_QBarSet) |
|
486 | 486 | |
|
487 | 487 | #include "tst_qbarset.moc" |
|
488 | 488 |
@@ -1,615 +1,615 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | #include <qchartview.h> |
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | #include <qareaseries.h> |
|
25 | 25 | #include <qscatterseries.h> |
|
26 | 26 | #include <qsplineseries.h> |
|
27 | 27 | #include <qpieseries.h> |
|
28 | 28 | #include <qabstractbarseries.h> |
|
29 |
#include <q |
|
|
29 | #include <qbarseries.h> | |
|
30 | 30 | #include <qpercentbarseries.h> |
|
31 | 31 | #include <qstackedbarseries.h> |
|
32 | 32 | #include <qvaluesaxis.h> |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
37 | 37 | Q_DECLARE_METATYPE(QValuesAxis *) |
|
38 | 38 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
39 | 39 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
40 | 40 | Q_DECLARE_METATYPE(QBrush) |
|
41 | 41 | Q_DECLARE_METATYPE(QPen) |
|
42 | 42 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
43 | 43 | |
|
44 | 44 | class tst_QChart : public QObject |
|
45 | 45 | { |
|
46 | 46 | Q_OBJECT |
|
47 | 47 | |
|
48 | 48 | public slots: |
|
49 | 49 | void initTestCase(); |
|
50 | 50 | void cleanupTestCase(); |
|
51 | 51 | void init(); |
|
52 | 52 | void cleanup(); |
|
53 | 53 | |
|
54 | 54 | private slots: |
|
55 | 55 | void qchart_data(); |
|
56 | 56 | void qchart(); |
|
57 | 57 | |
|
58 | 58 | void addSeries_data(); |
|
59 | 59 | void addSeries(); |
|
60 | 60 | void animationOptions_data(); |
|
61 | 61 | void animationOptions(); |
|
62 | 62 | void axisX_data(); |
|
63 | 63 | void axisX(); |
|
64 | 64 | void axisY_data(); |
|
65 | 65 | void axisY(); |
|
66 | 66 | void backgroundBrush_data(); |
|
67 | 67 | void backgroundBrush(); |
|
68 | 68 | void backgroundPen_data(); |
|
69 | 69 | void backgroundPen(); |
|
70 | 70 | void isBackgroundVisible_data(); |
|
71 | 71 | void isBackgroundVisible(); |
|
72 | 72 | void legend_data(); |
|
73 | 73 | void legend(); |
|
74 | 74 | void margins_data(); |
|
75 | 75 | void margins(); |
|
76 | 76 | void removeAllSeries_data(); |
|
77 | 77 | void removeAllSeries(); |
|
78 | 78 | void removeSeries_data(); |
|
79 | 79 | void removeSeries(); |
|
80 | 80 | void scroll_data(); |
|
81 | 81 | void scroll(); |
|
82 | 82 | void theme_data(); |
|
83 | 83 | void theme(); |
|
84 | 84 | void title_data(); |
|
85 | 85 | void title(); |
|
86 | 86 | void titleBrush_data(); |
|
87 | 87 | void titleBrush(); |
|
88 | 88 | void titleFont_data(); |
|
89 | 89 | void titleFont(); |
|
90 | 90 | void zoomIn_data(); |
|
91 | 91 | void zoomIn(); |
|
92 | 92 | void zoomOut_data(); |
|
93 | 93 | void zoomOut(); |
|
94 | 94 | |
|
95 | 95 | private: |
|
96 | 96 | void createTestData(); |
|
97 | 97 | |
|
98 | 98 | private: |
|
99 | 99 | QChartView* m_view; |
|
100 | 100 | QChart* m_chart; |
|
101 | 101 | }; |
|
102 | 102 | |
|
103 | 103 | void tst_QChart::initTestCase() |
|
104 | 104 | { |
|
105 | 105 | |
|
106 | 106 | } |
|
107 | 107 | |
|
108 | 108 | void tst_QChart::cleanupTestCase() |
|
109 | 109 | { |
|
110 | 110 | |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | void tst_QChart::init() |
|
114 | 114 | { |
|
115 | 115 | m_view = new QChartView(new QChart()); |
|
116 | 116 | m_chart = m_view->chart(); |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | void tst_QChart::createTestData() |
|
120 | 120 | { |
|
121 | 121 | QLineSeries* series0 = new QLineSeries(this); |
|
122 | 122 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
123 | 123 | m_chart->addSeries(series0); |
|
124 | 124 | m_view->show(); |
|
125 | 125 | QTest::qWaitForWindowShown(m_view); |
|
126 | 126 | } |
|
127 | 127 | |
|
128 | 128 | void tst_QChart::cleanup() |
|
129 | 129 | { |
|
130 | 130 | delete m_view; |
|
131 | 131 | m_view = 0; |
|
132 | 132 | m_chart = 0; |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | void tst_QChart::qchart_data() |
|
136 | 136 | { |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 139 | void tst_QChart::qchart() |
|
140 | 140 | { |
|
141 | 141 | QVERIFY(m_chart); |
|
142 | 142 | QVERIFY(m_chart->legend()); |
|
143 | 143 | QVERIFY(m_chart->legend()->isVisible()); |
|
144 | 144 | |
|
145 | 145 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
146 | 146 | QVERIFY(m_chart->axisX()); |
|
147 | 147 | QVERIFY(m_chart->axisY()); |
|
148 | 148 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
149 | 149 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
150 | 150 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
151 | 151 | |
|
152 | 152 | QVERIFY(m_chart->margins().top()>0); |
|
153 | 153 | QVERIFY(m_chart->margins().left()>0); |
|
154 | 154 | QVERIFY(m_chart->margins().right()>0); |
|
155 | 155 | QVERIFY(m_chart->margins().bottom()>0); |
|
156 | 156 | |
|
157 | 157 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
158 | 158 | QCOMPARE(m_chart->title(), QString()); |
|
159 | 159 | |
|
160 | 160 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
161 | 161 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
162 | 162 | |
|
163 | 163 | m_chart->removeAllSeries(); |
|
164 | 164 | m_chart->scroll(0,0); |
|
165 | 165 | |
|
166 | 166 | m_chart->zoomIn(); |
|
167 | 167 | m_chart->zoomIn(QRectF()); |
|
168 | 168 | m_chart->zoomOut(); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | void tst_QChart::addSeries_data() |
|
172 | 172 | { |
|
173 | 173 | QTest::addColumn<QAbstractSeries *>("series"); |
|
174 | 174 | QTest::addColumn<QAbstractAxis *>("axis"); |
|
175 | 175 | |
|
176 | 176 | QAbstractSeries* series0 = new QLineSeries(this); |
|
177 | 177 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); |
|
178 | 178 | QAbstractSeries* series2 = new QScatterSeries(this); |
|
179 | 179 | QAbstractSeries* series3 = new QSplineSeries(this); |
|
180 | 180 | QAbstractSeries* series4 = new QPieSeries(this); |
|
181 |
QAbstractSeries* series5 = new Q |
|
|
181 | QAbstractSeries* series5 = new QBarSeries(this); | |
|
182 | 182 | QAbstractSeries* series6 = new QPercentBarSeries(this); |
|
183 | 183 | QAbstractSeries* series7 = new QStackedBarSeries(this); |
|
184 | 184 | |
|
185 | 185 | QValuesAxis* axis = new QValuesAxis(this); |
|
186 | 186 | |
|
187 | 187 | QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0; |
|
188 | 188 | QTest::newRow("axis0: lineSeries") << series0 << axis; |
|
189 | 189 | QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0; |
|
190 | 190 | QTest::newRow("axis: areaSeries") << series1 << axis; |
|
191 | 191 | QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0; |
|
192 | 192 | QTest::newRow("axis1: scatterSeries") << series2 << axis; |
|
193 | 193 | QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0; |
|
194 | 194 | QTest::newRow("axis: splineSeries") << series3 << axis; |
|
195 | 195 | QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0; |
|
196 | 196 | QTest::newRow("axis: pieSeries") << series4 << axis; |
|
197 | 197 | QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0; |
|
198 | 198 | QTest::newRow("axis: barSeries") << series5 << axis; |
|
199 | 199 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0; |
|
200 | 200 | QTest::newRow("axis: barSeries") << series6 << axis; |
|
201 | 201 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0; |
|
202 | 202 | QTest::newRow("axis: barSeries") << series7 << axis; |
|
203 | 203 | |
|
204 | 204 | } |
|
205 | 205 | |
|
206 | 206 | void tst_QChart::addSeries() |
|
207 | 207 | { |
|
208 | 208 | QFETCH(QAbstractSeries *, series); |
|
209 | 209 | QFETCH(QAbstractAxis *, axis); |
|
210 | 210 | m_view->show(); |
|
211 | 211 | QTest::qWaitForWindowShown(m_view); |
|
212 | 212 | if(!axis) axis = m_chart->axisY(); |
|
213 | 213 | QVERIFY(!series->chart()); |
|
214 | 214 | QCOMPARE(m_chart->series().count(), 0); |
|
215 | 215 | m_chart->addSeries(series); |
|
216 | 216 | m_chart->setAxisY(axis,series); |
|
217 | 217 | QCOMPARE(m_chart->series().count(), 1); |
|
218 | 218 | QCOMPARE(m_chart->series().first(), series); |
|
219 | 219 | QVERIFY(series->chart() == m_chart); |
|
220 | 220 | QCOMPARE(m_chart->axisY(series),axis); |
|
221 | 221 | m_chart->removeSeries(series); |
|
222 | 222 | QVERIFY(!series->chart()); |
|
223 | 223 | QCOMPARE(m_chart->series().count(), 0); |
|
224 | 224 | } |
|
225 | 225 | |
|
226 | 226 | void tst_QChart::animationOptions_data() |
|
227 | 227 | { |
|
228 | 228 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
229 | 229 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
230 | 230 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
231 | 231 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
232 | 232 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
233 | 233 | } |
|
234 | 234 | |
|
235 | 235 | void tst_QChart::animationOptions() |
|
236 | 236 | { |
|
237 | 237 | createTestData(); |
|
238 | 238 | QFETCH(QChart::AnimationOption, animationOptions); |
|
239 | 239 | m_chart->setAnimationOptions(animationOptions); |
|
240 | 240 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | void tst_QChart::axisX_data() |
|
244 | 244 | { |
|
245 | 245 | |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | void tst_QChart::axisX() |
|
249 | 249 | { |
|
250 | 250 | QVERIFY(m_chart->axisX()); |
|
251 | 251 | QAbstractAxis* axis = m_chart->axisX(); |
|
252 | 252 | createTestData(); |
|
253 | 253 | //it should be the same axis |
|
254 | 254 | QCOMPARE(axis,m_chart->axisX()); |
|
255 | 255 | } |
|
256 | 256 | |
|
257 | 257 | void tst_QChart::axisY_data() |
|
258 | 258 | { |
|
259 | 259 | QTest::addColumn<QAbstractAxis*>("axis0"); |
|
260 | 260 | QTest::addColumn<QAbstractAxis*>("axis1"); |
|
261 | 261 | QTest::addColumn<QAbstractAxis*>("axis2"); |
|
262 | 262 | QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis(); |
|
263 | 263 | QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis(); |
|
264 | 264 | } |
|
265 | 265 | |
|
266 | 266 | |
|
267 | 267 | void tst_QChart::axisY() |
|
268 | 268 | { |
|
269 | 269 | QFETCH(QAbstractAxis*, axis0); |
|
270 | 270 | QFETCH(QAbstractAxis*, axis1); |
|
271 | 271 | QFETCH(QAbstractAxis*, axis2); |
|
272 | 272 | |
|
273 | 273 | QAbstractAxis* defaultAxisY = m_chart->axisY(); |
|
274 | 274 | |
|
275 | 275 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
276 | 276 | |
|
277 | 277 | QLineSeries* series0 = new QLineSeries(); |
|
278 | 278 | m_chart->addSeries(series0); |
|
279 | 279 | m_chart->setAxisY(axis0,series0); |
|
280 | 280 | |
|
281 | 281 | QLineSeries* series1 = new QLineSeries(); |
|
282 | 282 | m_chart->addSeries(series1); |
|
283 | 283 | m_chart->setAxisY(axis1,series1); |
|
284 | 284 | |
|
285 | 285 | QLineSeries* series2 = new QLineSeries(); |
|
286 | 286 | m_chart->addSeries(series2); |
|
287 | 287 | m_chart->setAxisY(axis2,series2); |
|
288 | 288 | |
|
289 | 289 | if (!axis0) |
|
290 | 290 | axis0 = defaultAxisY; |
|
291 | 291 | if (!axis1) |
|
292 | 292 | axis1 = defaultAxisY; |
|
293 | 293 | if (!axis2) |
|
294 | 294 | axis2 = defaultAxisY; |
|
295 | 295 | |
|
296 | 296 | QVERIFY(m_chart->axisY(series0) == axis0); |
|
297 | 297 | QVERIFY(m_chart->axisY(series1) == axis1); |
|
298 | 298 | QVERIFY(m_chart->axisY(series2) == axis2); |
|
299 | 299 | } |
|
300 | 300 | |
|
301 | 301 | void tst_QChart::backgroundBrush_data() |
|
302 | 302 | { |
|
303 | 303 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
304 | 304 | QTest::newRow("null") << QBrush(); |
|
305 | 305 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
306 | 306 | QTest::newRow("white") << QBrush(Qt::white); |
|
307 | 307 | QTest::newRow("black") << QBrush(Qt::black); |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | void tst_QChart::backgroundBrush() |
|
311 | 311 | { |
|
312 | 312 | QFETCH(QBrush, backgroundBrush); |
|
313 | 313 | m_chart->setBackgroundBrush(backgroundBrush); |
|
314 | 314 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | void tst_QChart::backgroundPen_data() |
|
318 | 318 | { |
|
319 | 319 | QTest::addColumn<QPen>("backgroundPen"); |
|
320 | 320 | QTest::newRow("null") << QPen(); |
|
321 | 321 | QTest::newRow("blue") << QPen(Qt::blue); |
|
322 | 322 | QTest::newRow("white") << QPen(Qt::white); |
|
323 | 323 | QTest::newRow("black") << QPen(Qt::black); |
|
324 | 324 | } |
|
325 | 325 | |
|
326 | 326 | |
|
327 | 327 | void tst_QChart::backgroundPen() |
|
328 | 328 | { |
|
329 | 329 | QFETCH(QPen, backgroundPen); |
|
330 | 330 | m_chart->setBackgroundPen(backgroundPen); |
|
331 | 331 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
332 | 332 | } |
|
333 | 333 | |
|
334 | 334 | void tst_QChart::isBackgroundVisible_data() |
|
335 | 335 | { |
|
336 | 336 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
337 | 337 | QTest::newRow("true") << true; |
|
338 | 338 | QTest::newRow("false") << false; |
|
339 | 339 | } |
|
340 | 340 | |
|
341 | 341 | void tst_QChart::isBackgroundVisible() |
|
342 | 342 | { |
|
343 | 343 | QFETCH(bool, isBackgroundVisible); |
|
344 | 344 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
345 | 345 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
346 | 346 | } |
|
347 | 347 | |
|
348 | 348 | void tst_QChart::legend_data() |
|
349 | 349 | { |
|
350 | 350 | |
|
351 | 351 | } |
|
352 | 352 | |
|
353 | 353 | void tst_QChart::legend() |
|
354 | 354 | { |
|
355 | 355 | QLegend *legend = m_chart->legend(); |
|
356 | 356 | QVERIFY(legend); |
|
357 | 357 | |
|
358 | 358 | // Colors related signals |
|
359 | 359 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); |
|
360 | 360 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); |
|
361 | 361 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); |
|
362 | 362 | |
|
363 | 363 | // colorChanged |
|
364 | 364 | legend->setColor(QColor("aliceblue")); |
|
365 | 365 | QCOMPARE(colorSpy.count(), 1); |
|
366 | 366 | QBrush b = legend->brush(); |
|
367 | 367 | b.setColor(QColor("aqua")); |
|
368 | 368 | legend->setBrush(b); |
|
369 | 369 | QCOMPARE(colorSpy.count(), 2); |
|
370 | 370 | |
|
371 | 371 | // borderColorChanged |
|
372 | 372 | legend->setBorderColor(QColor("aliceblue")); |
|
373 | 373 | QCOMPARE(borderColorSpy.count(), 1); |
|
374 | 374 | QPen p = legend->pen(); |
|
375 | 375 | p.setColor(QColor("aqua")); |
|
376 | 376 | legend->setPen(p); |
|
377 | 377 | QCOMPARE(borderColorSpy.count(), 2); |
|
378 | 378 | |
|
379 | 379 | // labelColorChanged |
|
380 | 380 | legend->setLabelColor(QColor("lightsalmon")); |
|
381 | 381 | QCOMPARE(labelColorSpy.count(), 1); |
|
382 | 382 | b = legend->labelBrush(); |
|
383 | 383 | b.setColor(QColor("lightseagreen")); |
|
384 | 384 | legend->setLabelBrush(b); |
|
385 | 385 | QCOMPARE(labelColorSpy.count(), 2); |
|
386 | 386 | |
|
387 | 387 | // fontChanged |
|
388 | 388 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); |
|
389 | 389 | QFont f = legend->font(); |
|
390 | 390 | f.setBold(!f.bold()); |
|
391 | 391 | legend->setFont(f); |
|
392 | 392 | QCOMPARE(fontSpy.count(), 1); |
|
393 | 393 | } |
|
394 | 394 | |
|
395 | 395 | void tst_QChart::margins_data() |
|
396 | 396 | { |
|
397 | 397 | |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | 400 | void tst_QChart::margins() |
|
401 | 401 | { |
|
402 | 402 | createTestData(); |
|
403 | 403 | QRectF rect = m_chart->geometry(); |
|
404 | 404 | |
|
405 | 405 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); |
|
406 | 406 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | void tst_QChart::removeAllSeries_data() |
|
410 | 410 | { |
|
411 | 411 | |
|
412 | 412 | } |
|
413 | 413 | |
|
414 | 414 | void tst_QChart::removeAllSeries() |
|
415 | 415 | { |
|
416 | 416 | QLineSeries* series0 = new QLineSeries(this); |
|
417 | 417 | QLineSeries* series1 = new QLineSeries(this); |
|
418 | 418 | QLineSeries* series2 = new QLineSeries(this); |
|
419 | 419 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
420 | 420 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
421 | 421 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
422 | 422 | |
|
423 | 423 | m_chart->addSeries(series0); |
|
424 | 424 | m_chart->addSeries(series1); |
|
425 | 425 | m_chart->addSeries(series2); |
|
426 | 426 | m_view->show(); |
|
427 | 427 | QTest::qWaitForWindowShown(m_view); |
|
428 | 428 | |
|
429 | 429 | QVERIFY(m_chart->axisY(series0)!=0); |
|
430 | 430 | QVERIFY(m_chart->axisY(series1)!=0); |
|
431 | 431 | QVERIFY(m_chart->axisY(series2)!=0); |
|
432 | 432 | |
|
433 | 433 | m_chart->removeAllSeries(); |
|
434 | 434 | QVERIFY(m_chart->axisY(series0)==0); |
|
435 | 435 | QVERIFY(m_chart->axisY(series1)==0); |
|
436 | 436 | QVERIFY(m_chart->axisY(series2)==0); |
|
437 | 437 | QCOMPARE(deleteSpy1.count(), 1); |
|
438 | 438 | QCOMPARE(deleteSpy2.count(), 1); |
|
439 | 439 | QCOMPARE(deleteSpy3.count(), 1); |
|
440 | 440 | } |
|
441 | 441 | |
|
442 | 442 | void tst_QChart::removeSeries_data() |
|
443 | 443 | { |
|
444 | 444 | addSeries_data(); |
|
445 | 445 | } |
|
446 | 446 | |
|
447 | 447 | void tst_QChart::removeSeries() |
|
448 | 448 | { |
|
449 | 449 | QFETCH(QAbstractSeries *, series); |
|
450 | 450 | QFETCH(QAbstractAxis *, axis); |
|
451 | 451 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
452 | 452 | m_view->show(); |
|
453 | 453 | QTest::qWaitForWindowShown(m_view); |
|
454 | 454 | if(!axis) axis = m_chart->axisY(); |
|
455 | 455 | m_chart->addSeries(series); |
|
456 | 456 | m_chart->setAxisY(axis,series); |
|
457 | 457 | QCOMPARE(m_chart->axisY(series),axis); |
|
458 | 458 | m_chart->removeSeries(series); |
|
459 | 459 | QVERIFY(m_chart->axisY(series)==0); |
|
460 | 460 | QCOMPARE(deleteSpy.count(), 0); |
|
461 | 461 | } |
|
462 | 462 | |
|
463 | 463 | void tst_QChart::scroll_data() |
|
464 | 464 | { |
|
465 | 465 | |
|
466 | 466 | } |
|
467 | 467 | |
|
468 | 468 | void tst_QChart::scroll() |
|
469 | 469 | { |
|
470 | 470 | qFatal("implement me"); |
|
471 | 471 | createTestData(); |
|
472 | 472 | //TODO qreal min = m_chart->axisY()->min(); |
|
473 | 473 | m_chart->scroll(0,0); |
|
474 | 474 | //TODO QVERIFY(m_chart->axisY()->min()<min); |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | void tst_QChart::theme_data() |
|
478 | 478 | { |
|
479 | 479 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
480 | 480 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
481 | 481 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
482 | 482 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
483 | 483 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
484 | 484 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
485 | 485 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
486 | 486 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
487 | 487 | } |
|
488 | 488 | |
|
489 | 489 | void tst_QChart::theme() |
|
490 | 490 | { |
|
491 | 491 | QFETCH(QChart::ChartTheme, theme); |
|
492 | 492 | createTestData(); |
|
493 | 493 | m_chart->setTheme(theme); |
|
494 | 494 | QVERIFY(m_chart->theme()==theme); |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | void tst_QChart::title_data() |
|
498 | 498 | { |
|
499 | 499 | QTest::addColumn<QString>("title"); |
|
500 | 500 | QTest::newRow("null") << QString(); |
|
501 | 501 | QTest::newRow("foo") << QString("foo"); |
|
502 | 502 | } |
|
503 | 503 | |
|
504 | 504 | void tst_QChart::title() |
|
505 | 505 | { |
|
506 | 506 | QFETCH(QString, title); |
|
507 | 507 | m_chart->setTitle(title); |
|
508 | 508 | QCOMPARE(m_chart->title(), title); |
|
509 | 509 | } |
|
510 | 510 | |
|
511 | 511 | void tst_QChart::titleBrush_data() |
|
512 | 512 | { |
|
513 | 513 | QTest::addColumn<QBrush>("titleBrush"); |
|
514 | 514 | QTest::newRow("null") << QBrush(); |
|
515 | 515 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
516 | 516 | QTest::newRow("white") << QBrush(Qt::white); |
|
517 | 517 | QTest::newRow("black") << QBrush(Qt::black); |
|
518 | 518 | } |
|
519 | 519 | |
|
520 | 520 | void tst_QChart::titleBrush() |
|
521 | 521 | { |
|
522 | 522 | QFETCH(QBrush, titleBrush); |
|
523 | 523 | m_chart->setTitleBrush(titleBrush); |
|
524 | 524 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
525 | 525 | } |
|
526 | 526 | |
|
527 | 527 | void tst_QChart::titleFont_data() |
|
528 | 528 | { |
|
529 | 529 | QTest::addColumn<QFont>("titleFont"); |
|
530 | 530 | QTest::newRow("null") << QFont(); |
|
531 | 531 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
532 | 532 | } |
|
533 | 533 | |
|
534 | 534 | void tst_QChart::titleFont() |
|
535 | 535 | { |
|
536 | 536 | QFETCH(QFont, titleFont); |
|
537 | 537 | m_chart->setTitleFont(titleFont); |
|
538 | 538 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
539 | 539 | } |
|
540 | 540 | |
|
541 | 541 | void tst_QChart::zoomIn_data() |
|
542 | 542 | { |
|
543 | 543 | QTest::addColumn<QRectF>("rect"); |
|
544 | 544 | QTest::newRow("null") << QRectF(); |
|
545 | 545 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
546 | 546 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
547 | 547 | } |
|
548 | 548 | |
|
549 | 549 | |
|
550 | 550 | void tst_QChart::zoomIn() |
|
551 | 551 | { |
|
552 | 552 | qFatal("implement me"); |
|
553 | 553 | /* |
|
554 | 554 | QFETCH(QRectF, rect); |
|
555 | 555 | createTestData(); |
|
556 | 556 | QRectF marigns = m_chart->margins(); |
|
557 | 557 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
558 | 558 | qreal minX = m_chart->axisX()->min(); |
|
559 | 559 | qreal minY = m_chart->axisY()->min(); |
|
560 | 560 | qreal maxX = m_chart->axisX()->max(); |
|
561 | 561 | qreal maxY = m_chart->axisY()->max(); |
|
562 | 562 | m_chart->zoomIn(rect); |
|
563 | 563 | if(rect.isValid()){ |
|
564 | 564 | QVERIFY(minX<m_chart->axisX()->min()); |
|
565 | 565 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
566 | 566 | QVERIFY(minY<m_chart->axisY()->min()); |
|
567 | 567 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
568 | 568 | } |
|
569 | 569 | */ |
|
570 | 570 | } |
|
571 | 571 | |
|
572 | 572 | void tst_QChart::zoomOut_data() |
|
573 | 573 | { |
|
574 | 574 | |
|
575 | 575 | } |
|
576 | 576 | |
|
577 | 577 | void tst_QChart::zoomOut() |
|
578 | 578 | { |
|
579 | 579 | qFatal("implement me"); |
|
580 | 580 | createTestData(); |
|
581 | 581 | /* |
|
582 | 582 | qreal minX = m_chart->axisX()->min(); |
|
583 | 583 | qreal minY = m_chart->axisY()->min(); |
|
584 | 584 | qreal maxX = m_chart->axisX()->max(); |
|
585 | 585 | qreal maxY = m_chart->axisY()->max(); |
|
586 | 586 | |
|
587 | 587 | m_chart->zoomIn(); |
|
588 | 588 | |
|
589 | 589 | QVERIFY(minX < m_chart->axisX()->min()); |
|
590 | 590 | QVERIFY(maxX > m_chart->axisX()->max()); |
|
591 | 591 | QVERIFY(minY < m_chart->axisY()->min()); |
|
592 | 592 | QVERIFY(maxY > m_chart->axisY()->max()); |
|
593 | 593 | |
|
594 | 594 | m_chart->zoomOut(); |
|
595 | 595 | |
|
596 | 596 | // min x may be a zero value |
|
597 | 597 | if (qFuzzyIsNull(minX)) |
|
598 | 598 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); |
|
599 | 599 | else |
|
600 | 600 | QCOMPARE(minX, m_chart->axisX()->min()); |
|
601 | 601 | |
|
602 | 602 | // min y may be a zero value |
|
603 | 603 | if (qFuzzyIsNull(minY)) |
|
604 | 604 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); |
|
605 | 605 | else |
|
606 | 606 | QCOMPARE(minY, m_chart->axisY()->min()); |
|
607 | 607 | |
|
608 | 608 | QVERIFY(maxX == m_chart->axisX()->max()); |
|
609 | 609 | QVERIFY(maxY == m_chart->axisY()->max()); |
|
610 | 610 | */ |
|
611 | 611 | } |
|
612 | 612 | |
|
613 | 613 | QTEST_MAIN(tst_QChart) |
|
614 | 614 | #include "tst_qchart.moc" |
|
615 | 615 |
@@ -1,277 +1,277 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 |
#include <q |
|
|
22 | #include <qbarseries.h> | |
|
23 | 23 | #include <qbarset.h> |
|
24 | 24 | #include <qchartview.h> |
|
25 | 25 | #include <qchart.h> |
|
26 | 26 | #include <QBarModelMapper> |
|
27 | 27 | #include <QStandardItemModel> |
|
28 | 28 | #include "tst_definitions.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | Q_DECLARE_METATYPE(QBarSet*) |
|
33 | 33 | |
|
34 | 34 | class tst_QGroupedBarSeries : public QObject |
|
35 | 35 | { |
|
36 | 36 | Q_OBJECT |
|
37 | 37 | |
|
38 | 38 | public slots: |
|
39 | 39 | void initTestCase(); |
|
40 | 40 | void cleanupTestCase(); |
|
41 | 41 | void init(); |
|
42 | 42 | void cleanup(); |
|
43 | 43 | |
|
44 | 44 | private slots: |
|
45 | 45 | void qgroupedbarseries_data(); |
|
46 | 46 | void qgroupedbarseries(); |
|
47 | 47 | void type_data(); |
|
48 | 48 | void type(); |
|
49 | 49 | void mouseclicked_data(); |
|
50 | 50 | void mouseclicked(); |
|
51 | 51 | void mousehovered_data(); |
|
52 | 52 | void mousehovered(); |
|
53 | 53 | |
|
54 | 54 | private: |
|
55 |
Q |
|
|
55 | QBarSeries* m_barseries; | |
|
56 | 56 | }; |
|
57 | 57 | |
|
58 | 58 | void tst_QGroupedBarSeries::initTestCase() |
|
59 | 59 | { |
|
60 | 60 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | void tst_QGroupedBarSeries::cleanupTestCase() |
|
64 | 64 | { |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | void tst_QGroupedBarSeries::init() |
|
68 | 68 | { |
|
69 |
m_barseries = new Q |
|
|
69 | m_barseries = new QBarSeries(); | |
|
70 | 70 | } |
|
71 | 71 | |
|
72 | 72 | void tst_QGroupedBarSeries::cleanup() |
|
73 | 73 | { |
|
74 | 74 | delete m_barseries; |
|
75 | 75 | m_barseries = 0; |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | void tst_QGroupedBarSeries::qgroupedbarseries_data() |
|
79 | 79 | { |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | void tst_QGroupedBarSeries::qgroupedbarseries() |
|
83 | 83 | { |
|
84 |
Q |
|
|
84 | QBarSeries *barseries = new QBarSeries(); | |
|
85 | 85 | QVERIFY(barseries != 0); |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | void tst_QGroupedBarSeries::type_data() |
|
89 | 89 | { |
|
90 | 90 | |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | void tst_QGroupedBarSeries::type() |
|
94 | 94 | { |
|
95 | 95 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeGroupedBar); |
|
96 | 96 | } |
|
97 | 97 | |
|
98 | 98 | void tst_QGroupedBarSeries::mouseclicked_data() |
|
99 | 99 | { |
|
100 | 100 | |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | void tst_QGroupedBarSeries::mouseclicked() |
|
104 | 104 | { |
|
105 |
Q |
|
|
105 | QBarSeries* series = new QBarSeries(); | |
|
106 | 106 | |
|
107 | 107 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
108 | 108 | *set1 << 10 << 10 << 10; |
|
109 | 109 | series->append(set1); |
|
110 | 110 | |
|
111 | 111 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
112 | 112 | *set2 << 10 << 10 << 10; |
|
113 | 113 | series->append(set2); |
|
114 | 114 | |
|
115 | 115 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int, QBarSet*))); |
|
116 | 116 | |
|
117 | 117 | QChartView view(new QChart()); |
|
118 | 118 | view.resize(400,300); |
|
119 | 119 | view.chart()->addSeries(series); |
|
120 | 120 | view.show(); |
|
121 | 121 | QTest::qWaitForWindowShown(&view); |
|
122 | 122 | |
|
123 | 123 | //==================================================================================== |
|
124 | 124 | // barset 1, category test1 |
|
125 | 125 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(95,143)); |
|
126 | 126 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
127 | 127 | |
|
128 | 128 | QCOMPARE(seriesSpy.count(), 1); |
|
129 | 129 | |
|
130 | 130 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
131 | 131 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
132 | 132 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
133 | 133 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
134 | 134 | |
|
135 | 135 | //==================================================================================== |
|
136 | 136 | // barset 1, category test2 |
|
137 | 137 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(187,143)); |
|
138 | 138 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
139 | 139 | |
|
140 | 140 | QCOMPARE(seriesSpy.count(), 1); |
|
141 | 141 | |
|
142 | 142 | seriesSpyArg = seriesSpy.takeFirst(); |
|
143 | 143 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
144 | 144 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
145 | 145 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
146 | 146 | |
|
147 | 147 | //==================================================================================== |
|
148 | 148 | // barset 1, category test3 |
|
149 | 149 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(280,143)); |
|
150 | 150 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
151 | 151 | |
|
152 | 152 | QCOMPARE(seriesSpy.count(), 1); |
|
153 | 153 | |
|
154 | 154 | seriesSpyArg = seriesSpy.takeFirst(); |
|
155 | 155 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
156 | 156 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
157 | 157 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
158 | 158 | |
|
159 | 159 | //==================================================================================== |
|
160 | 160 | // barset 2, category test1 |
|
161 | 161 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(118,143)); |
|
162 | 162 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
163 | 163 | |
|
164 | 164 | QCOMPARE(seriesSpy.count(), 1); |
|
165 | 165 | |
|
166 | 166 | seriesSpyArg = seriesSpy.takeFirst(); |
|
167 | 167 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
168 | 168 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
169 | 169 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
170 | 170 | |
|
171 | 171 | //==================================================================================== |
|
172 | 172 | // barset 2, category test2 |
|
173 | 173 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(210,143)); |
|
174 | 174 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
175 | 175 | |
|
176 | 176 | QCOMPARE(seriesSpy.count(), 1); |
|
177 | 177 | |
|
178 | 178 | seriesSpyArg = seriesSpy.takeFirst(); |
|
179 | 179 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
180 | 180 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
181 | 181 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
182 | 182 | |
|
183 | 183 | //==================================================================================== |
|
184 | 184 | // barset 2, category test3 |
|
185 | 185 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(303,143)); |
|
186 | 186 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
187 | 187 | |
|
188 | 188 | QCOMPARE(seriesSpy.count(), 1); |
|
189 | 189 | |
|
190 | 190 | seriesSpyArg = seriesSpy.takeFirst(); |
|
191 | 191 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
192 | 192 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
193 | 193 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | void tst_QGroupedBarSeries::mousehovered_data() |
|
197 | 197 | { |
|
198 | 198 | |
|
199 | 199 | } |
|
200 | 200 | |
|
201 | 201 | void tst_QGroupedBarSeries::mousehovered() |
|
202 | 202 | { |
|
203 |
Q |
|
|
203 | QBarSeries* series = new QBarSeries(); | |
|
204 | 204 | |
|
205 | 205 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
206 | 206 | *set1 << 10 << 10 << 10; |
|
207 | 207 | series->append(set1); |
|
208 | 208 | |
|
209 | 209 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
210 | 210 | *set2 << 10 << 10 << 10; |
|
211 | 211 | series->append(set2); |
|
212 | 212 | |
|
213 | 213 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool, QBarSet*))); |
|
214 | 214 | |
|
215 | 215 | QChartView view(new QChart()); |
|
216 | 216 | view.resize(400,300); |
|
217 | 217 | view.chart()->addSeries(series); |
|
218 | 218 | view.show(); |
|
219 | 219 | QTest::qWaitForWindowShown(&view); |
|
220 | 220 | |
|
221 | 221 | //this is hack since view does not get events otherwise |
|
222 | 222 | view.setMouseTracking(true); |
|
223 | 223 | |
|
224 | 224 | //======================================================================= |
|
225 | 225 | // move mouse to left border |
|
226 | 226 | qDebug() << "move mouse to left border"; |
|
227 | 227 | QTest::mouseMove(view.viewport(), QPoint(0, 143)); |
|
228 | 228 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); |
|
229 | 229 | TRY_COMPARE(seriesSpy.count(), 0); |
|
230 | 230 | |
|
231 | 231 | //======================================================================= |
|
232 | 232 | // move mouse on top of set1 |
|
233 | 233 | qDebug() << "move mouse on top of set1"; |
|
234 | 234 | QTest::mouseMove(view.viewport(), QPoint(95,143)); |
|
235 | 235 | TRY_COMPARE(seriesSpy.count(), 1); |
|
236 | 236 | |
|
237 | 237 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
238 | 238 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
239 | 239 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
240 | 240 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
241 | 241 | |
|
242 | 242 | //======================================================================= |
|
243 | 243 | // move mouse from top of set1 to top of set2 |
|
244 | 244 | qDebug() << "move mouse from top of set1 to top of set2"; |
|
245 | 245 | QTest::mouseMove(view.viewport(), QPoint(118,143)); |
|
246 | 246 | TRY_COMPARE(seriesSpy.count(), 2); |
|
247 | 247 | |
|
248 | 248 | // should leave set1 |
|
249 | 249 | seriesSpyArg = seriesSpy.takeFirst(); |
|
250 | 250 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
251 | 251 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
252 | 252 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
253 | 253 | |
|
254 | 254 | // should enter set2 |
|
255 | 255 | seriesSpyArg = seriesSpy.takeFirst(); |
|
256 | 256 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
257 | 257 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
258 | 258 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
259 | 259 | |
|
260 | 260 | //======================================================================= |
|
261 | 261 | // move mouse from top of set2 to background |
|
262 | 262 | qDebug() << "move mouse from top of set2 to background"; |
|
263 | 263 | |
|
264 | 264 | QTest::mouseMove(view.viewport(), QPoint(118,0)); |
|
265 | 265 | TRY_COMPARE(seriesSpy.count(), 1); |
|
266 | 266 | |
|
267 | 267 | // should leave set2 |
|
268 | 268 | seriesSpyArg = seriesSpy.takeFirst(); |
|
269 | 269 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
270 | 270 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
271 | 271 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
272 | 272 | } |
|
273 | 273 | |
|
274 | 274 | QTEST_MAIN(tst_QGroupedBarSeries) |
|
275 | 275 | |
|
276 | 276 | #include "tst_qgroupedbarseries.moc" |
|
277 | 277 |
@@ -1,189 +1,189 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "dataseriedialog.h" |
|
22 | 22 | #include <QDialogButtonBox> |
|
23 | 23 | #include <QGridLayout> |
|
24 | 24 | #include <QCheckBox> |
|
25 | 25 | #include <QPushButton> |
|
26 | 26 | #include <QGroupBox> |
|
27 | 27 | #include <QRadioButton> |
|
28 | 28 | #include <QLabel> |
|
29 | 29 | #include <QDebug> |
|
30 | 30 | |
|
31 | 31 | DataSerieDialog::DataSerieDialog(QWidget *parent) : |
|
32 | 32 | QDialog(parent) |
|
33 | 33 | { |
|
34 | 34 | QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal); |
|
35 | 35 | QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok); |
|
36 | 36 | connect(b, SIGNAL(clicked()), this, SLOT(accept())); |
|
37 | 37 | b = addSeriesBox->addButton(QDialogButtonBox::Cancel); |
|
38 | 38 | connect(b, SIGNAL(clicked()), this, SLOT(reject())); |
|
39 | 39 | |
|
40 | 40 | QGridLayout *grid = new QGridLayout(); |
|
41 | 41 | |
|
42 | 42 | m_seriesTypeSelector = seriesTypeSelector(); |
|
43 | 43 | m_columnCountSelector = columnCountSelector(); |
|
44 | 44 | m_rowCountSelector = rowCountSelector(); |
|
45 | 45 | m_dataCharacteristicsSelector = dataCharacteristicsSelector(); |
|
46 | 46 | |
|
47 | 47 | grid->addWidget(m_seriesTypeSelector, 0, 0); |
|
48 | 48 | grid->addWidget(m_columnCountSelector, 0, 1); |
|
49 | 49 | grid->addWidget(m_rowCountSelector, 1, 1); |
|
50 | 50 | grid->addWidget(m_dataCharacteristicsSelector, 1, 0); |
|
51 | 51 | m_labelsSelector = new QCheckBox("Labels defined"); |
|
52 | 52 | m_labelsSelector->setChecked(true); |
|
53 | 53 | grid->addWidget(m_labelsSelector, 2, 0); |
|
54 | 54 | grid->addWidget(addSeriesBox, 3, 1); |
|
55 | 55 | |
|
56 | 56 | setLayout(grid); |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | QGroupBox *DataSerieDialog::seriesTypeSelector() |
|
60 | 60 | { |
|
61 | 61 | QVBoxLayout *layout = new QVBoxLayout(); |
|
62 | 62 | |
|
63 | 63 | QRadioButton *line = new QRadioButton("Line"); |
|
64 | 64 | line->setChecked(true); |
|
65 | 65 | layout->addWidget(line); |
|
66 | 66 | layout->addWidget(new QRadioButton("Area")); |
|
67 | 67 | layout->addWidget(new QRadioButton("Pie")); |
|
68 |
layout->addWidget(new QRadioButton(" |
|
|
68 | layout->addWidget(new QRadioButton("Bar")); | |
|
69 | 69 | layout->addWidget(new QRadioButton("Stacked bar")); |
|
70 | 70 | layout->addWidget(new QRadioButton("Percent bar")); |
|
71 | 71 | layout->addWidget(new QRadioButton("Scatter")); |
|
72 | 72 | layout->addWidget(new QRadioButton("Spline")); |
|
73 | 73 | |
|
74 | 74 | QGroupBox *groupBox = new QGroupBox("Series type"); |
|
75 | 75 | groupBox->setLayout(layout); |
|
76 | 76 | selectRadio(groupBox, 0); |
|
77 | 77 | |
|
78 | 78 | return groupBox; |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | QGroupBox *DataSerieDialog::columnCountSelector() |
|
82 | 82 | { |
|
83 | 83 | QVBoxLayout *layout = new QVBoxLayout(); |
|
84 | 84 | |
|
85 | 85 | QRadioButton *radio = new QRadioButton("1"); |
|
86 | 86 | radio->setChecked(true); |
|
87 | 87 | layout->addWidget(radio); |
|
88 | 88 | layout->addWidget(new QRadioButton("2")); |
|
89 | 89 | layout->addWidget(new QRadioButton("3")); |
|
90 | 90 | layout->addWidget(new QRadioButton("4")); |
|
91 | 91 | layout->addWidget(new QRadioButton("5")); |
|
92 | 92 | layout->addWidget(new QRadioButton("8")); |
|
93 | 93 | layout->addWidget(new QRadioButton("10")); |
|
94 | 94 | layout->addWidget(new QRadioButton("100")); |
|
95 | 95 | |
|
96 | 96 | QGroupBox *groupBox = new QGroupBox("Column count"); |
|
97 | 97 | groupBox->setLayout(layout); |
|
98 | 98 | selectRadio(groupBox, 0); |
|
99 | 99 | |
|
100 | 100 | return groupBox; |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | QGroupBox *DataSerieDialog::rowCountSelector() |
|
104 | 104 | { |
|
105 | 105 | QVBoxLayout *layout = new QVBoxLayout(); |
|
106 | 106 | |
|
107 | 107 | layout->addWidget(new QRadioButton("1")); |
|
108 | 108 | QRadioButton *radio = new QRadioButton("10"); |
|
109 | 109 | radio->setChecked(true); |
|
110 | 110 | layout->addWidget(radio); |
|
111 | 111 | layout->addWidget(new QRadioButton("50")); |
|
112 | 112 | layout->addWidget(new QRadioButton("100")); |
|
113 | 113 | layout->addWidget(new QRadioButton("1000")); |
|
114 | 114 | layout->addWidget(new QRadioButton("10000")); |
|
115 | 115 | layout->addWidget(new QRadioButton("100000")); |
|
116 | 116 | layout->addWidget(new QRadioButton("1000000")); |
|
117 | 117 | |
|
118 | 118 | QGroupBox *groupBox = new QGroupBox("Row count"); |
|
119 | 119 | groupBox->setLayout(layout); |
|
120 | 120 | selectRadio(groupBox, 0); |
|
121 | 121 | |
|
122 | 122 | return groupBox; |
|
123 | 123 | } |
|
124 | 124 | |
|
125 | 125 | QGroupBox *DataSerieDialog::dataCharacteristicsSelector() |
|
126 | 126 | { |
|
127 | 127 | QVBoxLayout *layout = new QVBoxLayout(); |
|
128 | 128 | |
|
129 | 129 | layout->addWidget(new QRadioButton("Linear")); |
|
130 | 130 | layout->addWidget(new QRadioButton("Constant")); |
|
131 | 131 | layout->addWidget(new QRadioButton("Random")); |
|
132 | 132 | layout->addWidget(new QRadioButton("Sin")); |
|
133 | 133 | layout->addWidget(new QRadioButton("Sin + random")); |
|
134 | 134 | |
|
135 | 135 | QGroupBox *groupBox = new QGroupBox("Data Characteristics"); |
|
136 | 136 | groupBox->setLayout(layout); |
|
137 | 137 | selectRadio(groupBox, 0); |
|
138 | 138 | |
|
139 | 139 | return groupBox; |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | void DataSerieDialog::accept() |
|
143 | 143 | { |
|
144 | 144 | accepted(radioSelection(m_seriesTypeSelector), |
|
145 | 145 | radioSelection(m_columnCountSelector).toInt(), |
|
146 | 146 | radioSelection(m_rowCountSelector).toInt(), |
|
147 | 147 | radioSelection(m_dataCharacteristicsSelector), |
|
148 | 148 | m_labelsSelector->isChecked()); |
|
149 | 149 | QDialog::accept(); |
|
150 | 150 | } |
|
151 | 151 | |
|
152 | 152 | void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection) |
|
153 | 153 | { |
|
154 | 154 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); |
|
155 | 155 | Q_ASSERT(layout); |
|
156 | 156 | Q_ASSERT(layout->count()); |
|
157 | 157 | |
|
158 | 158 | QLayoutItem *item = 0; |
|
159 | 159 | if (defaultSelection == -1) { |
|
160 | 160 | item = layout->itemAt(0); |
|
161 | 161 | } else if (layout->count() > defaultSelection) { |
|
162 | 162 | item = layout->itemAt(defaultSelection); |
|
163 | 163 | } |
|
164 | 164 | Q_ASSERT(item); |
|
165 | 165 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); |
|
166 | 166 | Q_ASSERT(radio); |
|
167 | 167 | radio->setChecked(true); |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | QString DataSerieDialog::radioSelection(QGroupBox *groupBox) |
|
171 | 171 | { |
|
172 | 172 | QString selection; |
|
173 | 173 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); |
|
174 | 174 | Q_ASSERT(layout); |
|
175 | 175 | |
|
176 | 176 | for (int i(0); i < layout->count(); i++) { |
|
177 | 177 | QLayoutItem *item = layout->itemAt(i); |
|
178 | 178 | Q_ASSERT(item); |
|
179 | 179 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); |
|
180 | 180 | Q_ASSERT(radio); |
|
181 | 181 | if (radio->isChecked()) { |
|
182 | 182 | selection = radio->text(); |
|
183 | 183 | break; |
|
184 | 184 | } |
|
185 | 185 | } |
|
186 | 186 | |
|
187 | 187 | qDebug() << "radioSelection: " << selection; |
|
188 | 188 | return selection; |
|
189 | 189 | } |
@@ -1,357 +1,357 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "mainwidget.h" |
|
22 | 22 | #include "dataseriedialog.h" |
|
23 | 23 | #include "qchartview.h" |
|
24 | 24 | #include "qpieseries.h" |
|
25 | 25 | #include "qscatterseries.h" |
|
26 | 26 | #include "qlineseries.h" |
|
27 | 27 | #include <qareaseries.h> |
|
28 | 28 | #include <qsplineseries.h> |
|
29 | 29 | #include <qbarset.h> |
|
30 |
#include <q |
|
|
30 | #include <qbarseries.h> | |
|
31 | 31 | #include <qstackedbarseries.h> |
|
32 | 32 | #include <qpercentbarseries.h> |
|
33 | 33 | #include <QPushButton> |
|
34 | 34 | #include <QComboBox> |
|
35 | 35 | #include <QSpinBox> |
|
36 | 36 | #include <QCheckBox> |
|
37 | 37 | #include <QGridLayout> |
|
38 | 38 | #include <QHBoxLayout> |
|
39 | 39 | #include <QLabel> |
|
40 | 40 | #include <QSpacerItem> |
|
41 | 41 | #include <QMessageBox> |
|
42 | 42 | #include <cmath> |
|
43 | 43 | #include <QDebug> |
|
44 | 44 | #include <QStandardItemModel> |
|
45 | 45 | #include <QCategoriesAxis> |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
49 | 49 | |
|
50 | 50 | MainWidget::MainWidget(QWidget *parent) : |
|
51 | 51 | QWidget(parent), |
|
52 | 52 | m_addSerieDialog(0), |
|
53 | 53 | m_chart(0) |
|
54 | 54 | { |
|
55 | 55 | m_chart = new QChart(); |
|
56 | 56 | |
|
57 | 57 | // Grid layout for the controls for configuring the chart widget |
|
58 | 58 | QGridLayout *grid = new QGridLayout(); |
|
59 | 59 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
60 | 60 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
61 | 61 | grid->addWidget(addSeriesButton, 0, 1); |
|
62 | 62 | initBackroundCombo(grid); |
|
63 | 63 | initScaleControls(grid); |
|
64 | 64 | initThemeCombo(grid); |
|
65 | 65 | initCheckboxes(grid); |
|
66 | 66 | |
|
67 | 67 | // add row with empty label to make all the other rows static |
|
68 | 68 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
69 | 69 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
70 | 70 | |
|
71 | 71 | // Create chart view with the chart |
|
72 | 72 | m_chartView = new QChartView(m_chart, this); |
|
73 | 73 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
74 | 74 | |
|
75 | 75 | // Another grid layout as a main layout |
|
76 | 76 | QGridLayout *mainLayout = new QGridLayout(); |
|
77 | 77 | mainLayout->addLayout(grid, 0, 0); |
|
78 | 78 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
79 | 79 | setLayout(mainLayout); |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | // Combo box for selecting the chart's background |
|
83 | 83 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
84 | 84 | { |
|
85 | 85 | QComboBox *backgroundCombo = new QComboBox(this); |
|
86 | 86 | backgroundCombo->addItem("Color"); |
|
87 | 87 | backgroundCombo->addItem("Gradient"); |
|
88 | 88 | backgroundCombo->addItem("Image"); |
|
89 | 89 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
90 | 90 | this, SLOT(backgroundChanged(int))); |
|
91 | 91 | |
|
92 | 92 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
93 | 93 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | // Scale related controls (auto-scale vs. manual min-max values) |
|
97 | 97 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
98 | 98 | { |
|
99 | 99 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
100 | 100 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
101 | 101 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
102 | 102 | m_xMinSpin = new QSpinBox(); |
|
103 | 103 | m_xMinSpin->setMinimum(INT_MIN); |
|
104 | 104 | m_xMinSpin->setMaximum(INT_MAX); |
|
105 | 105 | m_xMinSpin->setValue(0); |
|
106 | 106 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
107 | 107 | m_xMaxSpin = new QSpinBox(); |
|
108 | 108 | m_xMaxSpin->setMinimum(INT_MIN); |
|
109 | 109 | m_xMaxSpin->setMaximum(INT_MAX); |
|
110 | 110 | m_xMaxSpin->setValue(10); |
|
111 | 111 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
112 | 112 | m_yMinSpin = new QSpinBox(); |
|
113 | 113 | m_yMinSpin->setMinimum(INT_MIN); |
|
114 | 114 | m_yMinSpin->setMaximum(INT_MAX); |
|
115 | 115 | m_yMinSpin->setValue(0); |
|
116 | 116 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
117 | 117 | m_yMaxSpin = new QSpinBox(); |
|
118 | 118 | m_yMaxSpin->setMinimum(INT_MIN); |
|
119 | 119 | m_yMaxSpin->setMaximum(INT_MAX); |
|
120 | 120 | m_yMaxSpin->setValue(10); |
|
121 | 121 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
122 | 122 | |
|
123 | 123 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
124 | 124 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
125 | 125 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
126 | 126 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
127 | 127 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
128 | 128 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
129 | 129 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
130 | 130 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
131 | 131 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
132 | 132 | |
|
133 | 133 | m_autoScaleCheck->setChecked(true); |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | // Combo box for selecting theme |
|
137 | 137 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
138 | 138 | { |
|
139 | 139 | QComboBox *chartTheme = new QComboBox(); |
|
140 | 140 | chartTheme->addItem("Default"); |
|
141 | 141 | chartTheme->addItem("Light"); |
|
142 | 142 | chartTheme->addItem("Blue Cerulean"); |
|
143 | 143 | chartTheme->addItem("Dark"); |
|
144 | 144 | chartTheme->addItem("Brown Sand"); |
|
145 | 145 | chartTheme->addItem("Blue NCS"); |
|
146 | 146 | chartTheme->addItem("High Contrast"); |
|
147 | 147 | chartTheme->addItem("Blue Icy"); |
|
148 | 148 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
149 | 149 | this, SLOT(changeChartTheme(int))); |
|
150 | 150 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
151 | 151 | grid->addWidget(chartTheme, 8, 1); |
|
152 | 152 | } |
|
153 | 153 | |
|
154 | 154 | // Different check boxes for customizing chart |
|
155 | 155 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
156 | 156 | { |
|
157 | 157 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
158 | 158 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
159 | 159 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
160 | 160 | zoomCheckBox->setChecked(true); |
|
161 | 161 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
162 | 162 | |
|
163 | 163 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
164 | 164 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
165 | 165 | aliasCheckBox->setChecked(false); |
|
166 | 166 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
167 | 167 | } |
|
168 | 168 | |
|
169 | 169 | void MainWidget::antiAliasToggled(bool enabled) |
|
170 | 170 | { |
|
171 | 171 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | 174 | void MainWidget::addSeries() |
|
175 | 175 | { |
|
176 | 176 | if (!m_addSerieDialog) { |
|
177 | 177 | m_addSerieDialog = new DataSerieDialog(this); |
|
178 | 178 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), |
|
179 | 179 | this, SLOT(addSeries(QString,int,int,QString,bool))); |
|
180 | 180 | } |
|
181 | 181 | m_addSerieDialog->exec(); |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
185 | 185 | { |
|
186 | 186 | // TODO: dataCharacteristics |
|
187 | 187 | QList<RealList> testData; |
|
188 | 188 | for (int j(0); j < columnCount; j++) { |
|
189 | 189 | QList <qreal> newColumn; |
|
190 | 190 | for (int i(0); i < rowCount; i++) { |
|
191 | 191 | if (dataCharacteristics == "Sin") { |
|
192 | 192 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
193 | 193 | } else if (dataCharacteristics == "Sin + random") { |
|
194 | 194 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
195 | 195 | } else if (dataCharacteristics == "Random") { |
|
196 | 196 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
197 | 197 | } else if (dataCharacteristics == "Linear") { |
|
198 | 198 | //newColumn.append(i * (j + 1.0)); |
|
199 | 199 | // TODO: temporary hack to make pie work; prevent zero values: |
|
200 | 200 | newColumn.append(i * (j + 1.0) + 0.1); |
|
201 | 201 | } else { // "constant" |
|
202 | 202 | newColumn.append((j + 1.0)); |
|
203 | 203 | } |
|
204 | 204 | } |
|
205 | 205 | testData.append(newColumn); |
|
206 | 206 | } |
|
207 | 207 | return testData; |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | QStringList MainWidget::generateLabels(int count) |
|
211 | 211 | { |
|
212 | 212 | QStringList result; |
|
213 | 213 | for (int i(0); i < count; i++) |
|
214 | 214 | result.append("label" + QString::number(i)); |
|
215 | 215 | return result; |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
219 | 219 | { |
|
220 | 220 | qDebug() << "addSeries: " << seriesName |
|
221 | 221 | << " columnCount: " << columnCount |
|
222 | 222 | << " rowCount: " << rowCount |
|
223 | 223 | << " dataCharacteristics: " << dataCharacteristics |
|
224 | 224 | << " labels enabled: " << labelsEnabled; |
|
225 | 225 | m_defaultSeriesName = seriesName; |
|
226 | 226 | |
|
227 | 227 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
228 | 228 | |
|
229 | 229 | // Line series and scatter series use similar data |
|
230 | 230 | if (seriesName == "Line") { |
|
231 | 231 | for (int j(0); j < data.count(); j ++) { |
|
232 | 232 | QList<qreal> column = data.at(j); |
|
233 | 233 | QLineSeries *series = new QLineSeries(); |
|
234 | 234 | series->setName("line" + QString::number(j)); |
|
235 | 235 | for (int i(0); i < column.count(); i++) |
|
236 | 236 | series->append(i, column.at(i)); |
|
237 | 237 | m_chart->addSeries(series); |
|
238 | 238 | } |
|
239 | 239 | } else if (seriesName == "Area") { |
|
240 | 240 | // TODO: lower series for the area? |
|
241 | 241 | for (int j(0); j < data.count(); j ++) { |
|
242 | 242 | QList<qreal> column = data.at(j); |
|
243 | 243 | QLineSeries *lineSeries = new QLineSeries(); |
|
244 | 244 | for (int i(0); i < column.count(); i++) |
|
245 | 245 | lineSeries->append(i, column.at(i)); |
|
246 | 246 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
247 | 247 | areaSeries->setName("area" + QString::number(j)); |
|
248 | 248 | m_chart->addSeries(areaSeries); |
|
249 | 249 | } |
|
250 | 250 | } else if (seriesName == "Scatter") { |
|
251 | 251 | for (int j(0); j < data.count(); j++) { |
|
252 | 252 | QList<qreal> column = data.at(j); |
|
253 | 253 | QScatterSeries *series = new QScatterSeries(); |
|
254 | 254 | series->setName("scatter" + QString::number(j)); |
|
255 | 255 | for (int i(0); i < column.count(); i++) |
|
256 | 256 | series->append(i, column.at(i)); |
|
257 | 257 | m_chart->addSeries(series); |
|
258 | 258 | } |
|
259 | 259 | } else if (seriesName == "Pie") { |
|
260 | 260 | QStringList labels = generateLabels(rowCount); |
|
261 | 261 | for (int j(0); j < data.count(); j++) { |
|
262 | 262 | QPieSeries *series = new QPieSeries(); |
|
263 | 263 | QList<qreal> column = data.at(j); |
|
264 | 264 | for (int i(0); i < column.count(); i++) |
|
265 | 265 | series->append(labels.at(i), column.at(i)); |
|
266 | 266 | m_chart->addSeries(series); |
|
267 | 267 | } |
|
268 |
} else if (seriesName == " |
|
|
268 | } else if (seriesName == "Bar" | |
|
269 | 269 | || seriesName == "Stacked bar" |
|
270 | 270 | || seriesName == "Percent bar") { |
|
271 | 271 | QStringList category; |
|
272 | 272 | QStringList labels = generateLabels(rowCount); |
|
273 | 273 | foreach(QString label, labels) |
|
274 | 274 | category << label; |
|
275 | 275 | QAbstractBarSeries* series = 0; |
|
276 |
if (seriesName == " |
|
|
277 |
series = new Q |
|
|
276 | if (seriesName == "Bar") { | |
|
277 | series = new QBarSeries(this); | |
|
278 | 278 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
279 | 279 | axis->append(category); |
|
280 | 280 | m_chart->setAxisX(axis,series); |
|
281 | 281 | } else if (seriesName == "Stacked bar") { |
|
282 | 282 | series = new QStackedBarSeries(this); |
|
283 | 283 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
284 | 284 | axis->append(category); |
|
285 | 285 | m_chart->setAxisX(axis,series); |
|
286 | 286 | } else { |
|
287 | 287 | series = new QPercentBarSeries(this); |
|
288 | 288 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
289 | 289 | axis->append(category); |
|
290 | 290 | m_chart->setAxisX(axis,series); |
|
291 | 291 | } |
|
292 | 292 | |
|
293 | 293 | for (int j(0); j < data.count(); j++) { |
|
294 | 294 | QList<qreal> column = data.at(j); |
|
295 | 295 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
296 | 296 | for (int i(0); i < column.count(); i++) |
|
297 | 297 | *set << column.at(i); |
|
298 | 298 | series->append(set); |
|
299 | 299 | } |
|
300 | 300 | |
|
301 | 301 | m_chart->addSeries(series); |
|
302 | 302 | } else if (seriesName == "Spline") { |
|
303 | 303 | for (int j(0); j < data.count(); j ++) { |
|
304 | 304 | QList<qreal> column = data.at(j); |
|
305 | 305 | QSplineSeries *series = new QSplineSeries(); |
|
306 | 306 | for (int i(0); i < column.count(); i++) |
|
307 | 307 | series->append(i, column.at(i)); |
|
308 | 308 | m_chart->addSeries(series); |
|
309 | 309 | } |
|
310 | 310 | } |
|
311 | 311 | m_chart->createDefaultAxes(); |
|
312 | 312 | } |
|
313 | 313 | |
|
314 | 314 | void MainWidget::backgroundChanged(int itemIndex) |
|
315 | 315 | { |
|
316 | 316 | qDebug() << "backgroundChanged: " << itemIndex; |
|
317 | 317 | } |
|
318 | 318 | |
|
319 | 319 | void MainWidget::autoScaleChanged(int value) |
|
320 | 320 | { |
|
321 | 321 | if (value) { |
|
322 | 322 | // TODO: enable auto scaling |
|
323 | 323 | } else { |
|
324 | 324 | // TODO: set scaling manually (and disable auto scaling) |
|
325 | 325 | } |
|
326 | 326 | |
|
327 | 327 | m_xMinSpin->setEnabled(!value); |
|
328 | 328 | m_xMaxSpin->setEnabled(!value); |
|
329 | 329 | m_yMinSpin->setEnabled(!value); |
|
330 | 330 | m_yMaxSpin->setEnabled(!value); |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | void MainWidget::xMinChanged(int value) |
|
334 | 334 | { |
|
335 | 335 | qDebug() << "xMinChanged: " << value; |
|
336 | 336 | } |
|
337 | 337 | |
|
338 | 338 | void MainWidget::xMaxChanged(int value) |
|
339 | 339 | { |
|
340 | 340 | qDebug() << "xMaxChanged: " << value; |
|
341 | 341 | } |
|
342 | 342 | |
|
343 | 343 | void MainWidget::yMinChanged(int value) |
|
344 | 344 | { |
|
345 | 345 | qDebug() << "yMinChanged: " << value; |
|
346 | 346 | } |
|
347 | 347 | |
|
348 | 348 | void MainWidget::yMaxChanged(int value) |
|
349 | 349 | { |
|
350 | 350 | qDebug() << "yMaxChanged: " << value; |
|
351 | 351 | } |
|
352 | 352 | |
|
353 | 353 | void MainWidget::changeChartTheme(int themeIndex) |
|
354 | 354 | { |
|
355 | 355 | qDebug() << "changeChartTheme: " << themeIndex; |
|
356 | 356 | m_chart->setTheme((QChart::ChartTheme) themeIndex); |
|
357 | 357 | } |
General Comments 0
You need to be logged in to leave comments.
Login now