@@ -54,7 +54,7 qreal Chart::distance(const QPointF &p1, const QPointF &p2) | |||||
54 |
|
54 | |||
55 | void Chart::setPointClicked(bool clicked) |
|
55 | void Chart::setPointClicked(bool clicked) | |
56 | { |
|
56 | { | |
57 | m_clicked = clicked; |
|
57 | m_clicked = clicked; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void Chart::handlePointMove(const QPoint &point) |
|
60 | void Chart::handlePointMove(const QPoint &point) | |
@@ -63,30 +63,30 void Chart::handlePointMove(const QPoint &point) | |||||
63 | //Map the point clicked from the ChartView |
|
63 | //Map the point clicked from the ChartView | |
64 | //to the area occupied by the chart. |
|
64 | //to the area occupied by the chart. | |
65 | QPoint mappedPoint = point; |
|
65 | QPoint mappedPoint = point; | |
66 | mappedPoint.setX(point.x()-this->plotArea().x()); |
|
66 | mappedPoint.setX(point.x() - this->plotArea().x()); | |
67 | mappedPoint.setY(point.y()-this->plotArea().y()); |
|
67 | mappedPoint.setY(point.y() - this->plotArea().y()); | |
68 |
|
68 | |||
69 | //Get the x- and y axis to be able to convert the mapped |
|
69 | //Get the x- and y axis to be able to convert the mapped | |
70 | //coordinate point to the charts scale. |
|
70 | //coordinate point to the charts scale. | |
71 |
QAbstractAxis * |
|
71 | QAbstractAxis *axisx = this->axisX(); | |
72 |
QValueAxis* |
|
72 | QValueAxis *haxis = 0; | |
73 | if (axisx->type() == QAbstractAxis::AxisTypeValue) |
|
73 | if (axisx->type() == QAbstractAxis::AxisTypeValue) | |
74 | haxis = qobject_cast<QValueAxis*>(axisx); |
|
74 | haxis = qobject_cast<QValueAxis *>(axisx); | |
75 |
|
75 | |||
76 |
QAbstractAxis * |
|
76 | QAbstractAxis *axisy = this->axisY(); | |
77 |
QValueAxis* |
|
77 | QValueAxis *vaxis = 0; | |
78 | if (axisy->type() == QAbstractAxis::AxisTypeValue) |
|
78 | if (axisy->type() == QAbstractAxis::AxisTypeValue) | |
79 | vaxis = qobject_cast<QValueAxis*>(axisy); |
|
79 | vaxis = qobject_cast<QValueAxis *>(axisy); | |
80 |
|
80 | |||
81 | if (haxis && vaxis) { |
|
81 | if (haxis && vaxis) { | |
82 | //Calculate the "unit" between points on the x |
|
82 | //Calculate the "unit" between points on the x | |
83 | //y axis. |
|
83 | //y axis. | |
84 | double xUnit = this->plotArea().width()/haxis->max(); |
|
84 | double xUnit = this->plotArea().width() / haxis->max(); | |
85 | double yUnit = this->plotArea().height()/vaxis->max(); |
|
85 | double yUnit = this->plotArea().height() / vaxis->max(); | |
86 |
|
86 | |||
87 | //Convert the mappedPoint to the actual chart scale. |
|
87 | //Convert the mappedPoint to the actual chart scale. | |
88 | double x = mappedPoint.x()/xUnit; |
|
88 | double x = mappedPoint.x() / xUnit; | |
89 | double y = vaxis->max() - mappedPoint.y()/yUnit; |
|
89 | double y = vaxis->max() - mappedPoint.y() / yUnit; | |
90 |
|
90 | |||
91 | //Replace the old point with the new one. |
|
91 | //Replace the old point with the new one. | |
92 | m_series->replace(m_movingPoint, QPointF(x, y)); |
|
92 | m_series->replace(m_movingPoint, QPointF(x, y)); |
@@ -33,7 +33,7 int main(int argc, char *argv[]) | |||||
33 | { |
|
33 | { | |
34 | QApplication a(argc, argv); |
|
34 | QApplication a(argc, argv); | |
35 |
|
35 | |||
36 |
QLineSeries* |
|
36 | QLineSeries *series = new QLineSeries(); | |
37 |
|
37 | |||
38 | series->append(0, 6); |
|
38 | series->append(0, 6); | |
39 | series->append(1, 3); |
|
39 | series->append(1, 3); | |
@@ -43,7 +43,7 int main(int argc, char *argv[]) | |||||
43 | series->append(10, 5); |
|
43 | series->append(10, 5); | |
44 | *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); |
|
44 | *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); | |
45 |
|
45 | |||
46 |
Chart* |
|
46 | Chart *chart = new Chart(0, 0, series); | |
47 | chart->legend()->hide(); |
|
47 | chart->legend()->hide(); | |
48 | chart->addSeries(series); |
|
48 | chart->addSeries(series); | |
49 | QPen p = series->pen(); |
|
49 | QPen p = series->pen(); | |
@@ -62,7 +62,7 int main(int argc, char *argv[]) | |||||
62 |
|
62 | |||
63 | QObject::connect(series, SIGNAL(clicked(QPointF)), chart, SLOT(clickPoint(QPointF))); |
|
63 | QObject::connect(series, SIGNAL(clicked(QPointF)), chart, SLOT(clickPoint(QPointF))); | |
64 |
|
64 | |||
65 |
ChartView* |
|
65 | ChartView *chartView = new ChartView(chart); | |
66 | chartView->setRenderHint(QPainter::Antialiasing); |
|
66 | chartView->setRenderHint(QPainter::Antialiasing); | |
67 |
|
67 | |||
68 | QMainWindow window; |
|
68 | QMainWindow window; |
@@ -26,7 +26,7 int main(int argc, char *argv[]) | |||||
26 | { |
|
26 | { | |
27 | QApplication a(argc, argv); |
|
27 | QApplication a(argc, argv); | |
28 | QMainWindow window; |
|
28 | QMainWindow window; | |
29 |
ThemeWidget* |
|
29 | ThemeWidget *widget = new ThemeWidget(); | |
30 | window.setCentralWidget(widget); |
|
30 | window.setCentralWidget(widget); | |
31 | window.resize(900, 600); |
|
31 | window.resize(900, 600); | |
32 | window.show(); |
|
32 | window.show(); |
@@ -43,12 +43,12 | |||||
43 | #include <QTime> |
|
43 | #include <QTime> | |
44 | #include <QBarCategoryAxis> |
|
44 | #include <QBarCategoryAxis> | |
45 |
|
45 | |||
46 |
ThemeWidget::ThemeWidget(QWidget* |
|
46 | ThemeWidget::ThemeWidget(QWidget *parent) : | |
47 | QWidget(parent), |
|
47 | QWidget(parent), | |
48 | m_listCount(3), |
|
48 | m_listCount(3), | |
49 | m_valueMax(10), |
|
49 | m_valueMax(10), | |
50 | m_valueCount(7), |
|
50 | m_valueCount(7), | |
51 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
51 | m_dataTable(generateRandomData(m_listCount, m_valueMax, m_valueCount)), | |
52 | m_themeComboBox(createThemeBox()), |
|
52 | m_themeComboBox(createThemeBox()), | |
53 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), |
|
53 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), | |
54 | m_animatedComboBox(createAnimationBox()), |
|
54 | m_animatedComboBox(createAnimationBox()), | |
@@ -56,7 +56,7 ThemeWidget::ThemeWidget(QWidget* parent) : | |||||
56 | { |
|
56 | { | |
57 | connectSignals(); |
|
57 | connectSignals(); | |
58 | // create layout |
|
58 | // create layout | |
59 |
QGridLayout* |
|
59 | QGridLayout *baseLayout = new QGridLayout(); | |
60 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
60 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
61 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
61 | settingsLayout->addWidget(new QLabel("Theme:")); | |
62 | settingsLayout->addWidget(m_themeComboBox); |
|
62 | settingsLayout->addWidget(m_themeComboBox); | |
@@ -116,7 +116,7 void ThemeWidget::connectSignals() | |||||
116 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
116 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
119 | DataTable ThemeWidget::generateRandomData(int listCount, int valueMax, int valueCount) const | |
120 | { |
|
120 | { | |
121 | DataTable dataTable; |
|
121 | DataTable dataTable; | |
122 |
|
122 | |||
@@ -128,7 +128,7 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCo | |||||
128 | DataList dataList; |
|
128 | DataList dataList; | |
129 | qreal yValue(0); |
|
129 | qreal yValue(0); | |
130 | for (int j(0); j < valueCount; j++) { |
|
130 | for (int j(0); j < valueCount; j++) { | |
131 |
yValue = yValue + (qreal) |
|
131 | yValue = yValue + (qreal)(qrand() % valueMax) / (qreal) valueCount; | |
132 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), |
|
132 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), | |
133 | yValue); |
|
133 | yValue); | |
134 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); |
|
134 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); | |
@@ -140,10 +140,10 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCo | |||||
140 | return dataTable; |
|
140 | return dataTable; | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 |
QComboBox* |
|
143 | QComboBox *ThemeWidget::createThemeBox() const | |
144 | { |
|
144 | { | |
145 | // settings layout |
|
145 | // settings layout | |
146 |
QComboBox* |
|
146 | QComboBox *themeComboBox = new QComboBox(); | |
147 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
147 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
148 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
148 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
149 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
149 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
@@ -154,10 +154,10 QComboBox* ThemeWidget::createThemeBox() const | |||||
154 | return themeComboBox; |
|
154 | return themeComboBox; | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 |
QComboBox* |
|
157 | QComboBox *ThemeWidget::createAnimationBox() const | |
158 | { |
|
158 | { | |
159 | // settings layout |
|
159 | // settings layout | |
160 |
QComboBox* |
|
160 | QComboBox *animationComboBox = new QComboBox(); | |
161 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
161 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
162 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
162 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
163 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
163 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
@@ -165,9 +165,9 QComboBox* ThemeWidget::createAnimationBox() const | |||||
165 | return animationComboBox; |
|
165 | return animationComboBox; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 |
QComboBox* |
|
168 | QComboBox *ThemeWidget::createLegendBox() const | |
169 | { |
|
169 | { | |
170 |
QComboBox* |
|
170 | QComboBox *legendComboBox = new QComboBox(); | |
171 | legendComboBox->addItem("No Legend ", 0); |
|
171 | legendComboBox->addItem("No Legend ", 0); | |
172 | legendComboBox->addItem("Legend Top", Qt::AlignTop); |
|
172 | legendComboBox->addItem("Legend Top", Qt::AlignTop); | |
173 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); |
|
173 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); | |
@@ -176,7 +176,7 QComboBox* ThemeWidget::createLegendBox() const | |||||
176 | return legendComboBox; |
|
176 | return legendComboBox; | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 |
QChart* |
|
179 | QChart *ThemeWidget::createAreaChart() const | |
180 | { |
|
180 | { | |
181 | QChart *chart = new QChart(); |
|
181 | QChart *chart = new QChart(); | |
182 | // chart->axisX()->setNiceNumbersEnabled(true); |
|
182 | // chart->axisX()->setNiceNumbersEnabled(true); | |
@@ -191,11 +191,12 QChart* ThemeWidget::createAreaChart() const | |||||
191 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
191 | QLineSeries *upperSeries = new QLineSeries(chart); | |
192 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
192 | for (int j(0); j < m_dataTable[i].count(); j++) { | |
193 | Data data = m_dataTable[i].at(j); |
|
193 | Data data = m_dataTable[i].at(j); | |
194 | if (lowerSeries){ |
|
194 | if (lowerSeries) { | |
195 | const QList<QPointF>& points = lowerSeries->points(); |
|
195 | const QList<QPointF>& points = lowerSeries->points(); | |
196 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); |
|
196 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); | |
197 | }else |
|
197 | } else { | |
198 | upperSeries->append(QPointF(j, data.first.y())); |
|
198 | upperSeries->append(QPointF(j, data.first.y())); | |
|
199 | } | |||
199 | } |
|
200 | } | |
200 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
201 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); | |
201 | area->setName(name + QString::number(nameIndex)); |
|
202 | area->setName(name + QString::number(nameIndex)); | |
@@ -208,13 +209,13 QChart* ThemeWidget::createAreaChart() const | |||||
208 | return chart; |
|
209 | return chart; | |
209 | } |
|
210 | } | |
210 |
|
211 | |||
211 |
QChart* |
|
212 | QChart *ThemeWidget::createBarChart(int valueCount) const | |
212 | { |
|
213 | { | |
213 | Q_UNUSED(valueCount); |
|
214 | Q_UNUSED(valueCount); | |
214 |
QChart* |
|
215 | QChart *chart = new QChart(); | |
215 | chart->setTitle("Bar chart"); |
|
216 | chart->setTitle("Bar chart"); | |
216 |
|
217 | |||
217 |
QStackedBarSeries* |
|
218 | QStackedBarSeries *series = new QStackedBarSeries(chart); | |
218 | for (int i(0); i < m_dataTable.count(); i++) { |
|
219 | for (int i(0); i < m_dataTable.count(); i++) { | |
219 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
220 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
220 | foreach (Data data, m_dataTable[i]) |
|
221 | foreach (Data data, m_dataTable[i]) | |
@@ -227,9 +228,9 QChart* ThemeWidget::createBarChart(int valueCount) const | |||||
227 | return chart; |
|
228 | return chart; | |
228 | } |
|
229 | } | |
229 |
|
230 | |||
230 |
QChart* |
|
231 | QChart *ThemeWidget::createLineChart() const | |
231 | { |
|
232 | { | |
232 |
QChart* |
|
233 | QChart *chart = new QChart(); | |
233 | chart->setTitle("Line chart"); |
|
234 | chart->setTitle("Line chart"); | |
234 |
|
235 | |||
235 | QString name("Series "); |
|
236 | QString name("Series "); | |
@@ -247,9 +248,9 QChart* ThemeWidget::createLineChart() const | |||||
247 | return chart; |
|
248 | return chart; | |
248 | } |
|
249 | } | |
249 |
|
250 | |||
250 |
QChart* |
|
251 | QChart *ThemeWidget::createPieChart() const | |
251 | { |
|
252 | { | |
252 |
QChart* |
|
253 | QChart *chart = new QChart(); | |
253 | chart->setTitle("Pie chart"); |
|
254 | chart->setTitle("Pie chart"); | |
254 |
|
255 | |||
255 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
256 | qreal pieSize = 1.0 / m_dataTable.count(); | |
@@ -272,9 +273,10 QChart* ThemeWidget::createPieChart() const | |||||
272 | return chart; |
|
273 | return chart; | |
273 | } |
|
274 | } | |
274 |
|
275 | |||
275 |
QChart* |
|
276 | QChart *ThemeWidget::createSplineChart() const | |
276 | { // spine chart |
|
277 | { | |
277 | QChart* chart = new QChart(); |
|
278 | // spine chart | |
|
279 | QChart *chart = new QChart(); | |||
278 | chart->setTitle("Spline chart"); |
|
280 | chart->setTitle("Spline chart"); | |
279 | QString name("Series "); |
|
281 | QString name("Series "); | |
280 | int nameIndex = 0; |
|
282 | int nameIndex = 0; | |
@@ -290,9 +292,10 QChart* ThemeWidget::createSplineChart() const | |||||
290 | return chart; |
|
292 | return chart; | |
291 | } |
|
293 | } | |
292 |
|
294 | |||
293 |
QChart* |
|
295 | QChart *ThemeWidget::createScatterChart() const | |
294 | { // scatter chart |
|
296 | { | |
295 | QChart* chart = new QChart(); |
|
297 | // scatter chart | |
|
298 | QChart *chart = new QChart(); | |||
296 | chart->setTitle("Scatter chart"); |
|
299 | chart->setTitle("Scatter chart"); | |
297 | QString name("Series "); |
|
300 | QString name("Series "); | |
298 | int nameIndex = 0; |
|
301 | int nameIndex = 0; | |
@@ -358,9 +361,8 void ThemeWidget::updateUI() | |||||
358 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
361 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
359 |
|
362 | |||
360 | if (!alignment) { |
|
363 | if (!alignment) { | |
361 |
foreach (QChartView *chartView, m_charts) |
|
364 | foreach (QChartView *chartView, m_charts) | |
362 | chartView->chart()->legend()->hide(); |
|
365 | chartView->chart()->legend()->hide(); | |
363 | } |
|
|||
364 | } else { |
|
366 | } else { | |
365 | foreach (QChartView *chartView, m_charts) { |
|
367 | foreach (QChartView *chartView, m_charts) { | |
366 | chartView->chart()->legend()->setAlignment(alignment); |
|
368 | chartView->chart()->legend()->setAlignment(alignment); |
@@ -49,23 +49,23 private Q_SLOTS: | |||||
49 | void updateUI(); |
|
49 | void updateUI(); | |
50 |
|
50 | |||
51 | private: |
|
51 | private: | |
52 | DataTable generateRandomData(int listCount,int valueMax,int valueCount) const; |
|
52 | DataTable generateRandomData(int listCount, int valueMax, int valueCount) const; | |
53 |
QComboBox* |
|
53 | QComboBox *createThemeBox() const; | |
54 |
QComboBox* |
|
54 | QComboBox *createAnimationBox() const; | |
55 |
QComboBox* |
|
55 | QComboBox *createLegendBox() const; | |
56 | void connectSignals(); |
|
56 | void connectSignals(); | |
57 |
QChart* |
|
57 | QChart *createAreaChart() const; | |
58 |
QChart* |
|
58 | QChart *createBarChart(int valueCount) const; | |
59 |
QChart* |
|
59 | QChart *createPieChart() const; | |
60 |
QChart* |
|
60 | QChart *createLineChart() const; | |
61 |
QChart* |
|
61 | QChart *createSplineChart() const; | |
62 |
QChart* |
|
62 | QChart *createScatterChart() const; | |
63 |
|
63 | |||
64 | private: |
|
64 | private: | |
65 | int m_listCount; |
|
65 | int m_listCount; | |
66 | int m_valueMax; |
|
66 | int m_valueMax; | |
67 | int m_valueCount; |
|
67 | int m_valueCount; | |
68 | QList<QChartView*> m_charts; |
|
68 | QList<QChartView *> m_charts; | |
69 | DataTable m_dataTable; |
|
69 | DataTable m_dataTable; | |
70 |
|
70 | |||
71 | QComboBox *m_themeComboBox; |
|
71 | QComboBox *m_themeComboBox; |
@@ -35,8 +35,8 QTCOMMERCIALCHART_USE_NAMESPACE | |||||
35 | class Chart |
|
35 | class Chart | |
36 | { |
|
36 | { | |
37 | public: |
|
37 | public: | |
38 | virtual ~Chart(){}; |
|
38 | virtual ~Chart() {}; | |
39 |
virtual QChart* |
|
39 | virtual QChart *createChart(const DataTable &table) = 0; | |
40 | virtual QString name() = 0; |
|
40 | virtual QString name() = 0; | |
41 | virtual QString category() = 0; |
|
41 | virtual QString category() = 0; | |
42 | virtual QString subCategory() = 0; |
|
42 | virtual QString subCategory() = 0; | |
@@ -46,46 +46,41 public: | |||||
46 | namespace Charts |
|
46 | namespace Charts | |
47 | { |
|
47 | { | |
48 |
|
48 | |||
49 | typedef QList<Chart*> ChartList; |
|
49 | typedef QList<Chart *> ChartList; | |
50 |
|
50 | |||
51 |
inline ChartList& |
|
51 | inline ChartList &chartList() | |
52 | { |
|
52 | { | |
53 | static ChartList list; |
|
53 | static ChartList list; | |
54 | return list; |
|
54 | return list; | |
55 | } |
|
|||
56 |
|
||||
57 | inline bool findChart(Chart* chart) |
|
|||
58 | { |
|
|||
59 | ChartList& list = chartList(); |
|
|||
60 | if (list.contains(chart)) { |
|
|||
61 | return true; |
|
|||
62 | } |
|
55 | } | |
63 | foreach (Chart* item, list) { |
|
56 | ||
64 | if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) { |
|
57 | inline bool findChart(Chart *chart) | |
|
58 | { | |||
|
59 | ChartList &list = chartList(); | |||
|
60 | if (list.contains(chart)) | |||
65 | return true; |
|
61 | return true; | |
|
62 | ||||
|
63 | foreach (Chart *item, list) { | |||
|
64 | if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) | |||
|
65 | return true; | |||
66 | } |
|
66 | } | |
|
67 | return false; | |||
67 | } |
|
68 | } | |
68 | return false; |
|
|||
69 | } |
|
|||
70 |
|
69 | |||
71 |
inline void addChart(Chart* |
|
70 | inline void addChart(Chart *chart) | |
72 | { |
|
71 | { | |
73 |
ChartList& |
|
72 | ChartList &list = chartList(); | |
74 |
if (!findChart(chart)) |
|
73 | if (!findChart(chart)) | |
75 | list.append(chart); |
|
74 | list.append(chart); | |
76 | } |
|
75 | } | |
77 | } |
|
76 | } | |
78 | } |
|
|||
79 |
|
77 | |||
80 | template <class T> |
|
78 | template <class T> | |
81 | class ChartWrapper |
|
79 | class ChartWrapper | |
82 | { |
|
80 | { | |
83 | public: |
|
81 | public: | |
84 | QSharedPointer<T> chart; |
|
82 | QSharedPointer<T> chart; | |
85 | ChartWrapper() : chart(new T) |
|
83 | ChartWrapper() : chart(new T) { Charts::addChart(chart.data()); } | |
86 | { |
|
|||
87 | Charts::addChart(chart.data()); |
|
|||
88 | } |
|
|||
89 | }; |
|
84 | }; | |
90 |
|
85 | |||
91 | #define DECLARE_CHART(chartType) static ChartWrapper<chartType> chartType; |
|
86 | #define DECLARE_CHART(chartType) static ChartWrapper<chartType> chartType; |
@@ -30,39 +30,38 public: | |||||
30 | QString category() { return QObject::tr("Axis"); } |
|
30 | QString category() { return QObject::tr("Axis"); } | |
31 | QString subCategory() { return QString::null; } |
|
31 | QString subCategory() { return QString::null; } | |
32 |
|
32 | |||
33 |
QChart* |
|
33 | QChart *createChart(const DataTable &table) | |
|
34 | { | |||
|
35 | QChart *chart = new QChart(); | |||
|
36 | chart->setTitle("Category X , Category Y "); | |||
34 |
|
37 | |||
35 | QChart* chart = new QChart(); |
|
38 | QString name("Series "); | |
36 | chart->setTitle("Category X , Category Y "); |
|
39 | int nameIndex = 0; | |
|
40 | foreach (DataList list, table) { | |||
|
41 | QLineSeries *series = new QLineSeries(chart); | |||
|
42 | foreach(Data data, list) | |||
|
43 | series->append(data.first); | |||
|
44 | series->setName(name + QString::number(nameIndex)); | |||
|
45 | nameIndex++; | |||
|
46 | chart->addSeries(series); | |||
|
47 | } | |||
37 |
|
48 | |||
38 | QString name("Series "); |
|
49 | QCategoryAxis *axisX = new QCategoryAxis; | |
39 | int nameIndex = 0; |
|
50 | axisX->append("low", 5); | |
40 | foreach (DataList list, table) { |
|
51 | axisX->append("avg.", 12); | |
41 | QLineSeries *series = new QLineSeries(chart); |
|
52 | axisX->append("high", 19); | |
42 | foreach (Data data, list) |
|
53 | axisX->setRange(0, 20); | |
43 | series->append(data.first); |
|
54 | chart->setAxisX(axisX, chart->series().at(0)); | |
44 | series->setName(name + QString::number(nameIndex)); |
|
|||
45 | nameIndex++; |
|
|||
46 | chart->addSeries(series); |
|
|||
47 | } |
|
|||
48 |
|
55 | |||
49 |
|
|
56 | QCategoryAxis *axisY = new QCategoryAxis; | |
50 |
|
|
57 | axisY->append("cheap", 5); | |
51 |
|
|
58 | axisY->append("fair", 12); | |
52 |
|
|
59 | axisY->append("pricy", 20); | |
53 |
|
|
60 | axisY->setRange(0, 20); | |
54 |
|
|
61 | chart->setAxisY(axisY, chart->series().at(0)); | |
55 |
|
62 | |||
56 | QCategoryAxis *axisY = new QCategoryAxis; |
|
63 | return chart; | |
57 | axisY->append("cheap", 5); |
|
|||
58 | axisY->append("fair", 12); |
|
|||
59 | axisY->append("pricy", 20); |
|
|||
60 | axisY->setRange(0, 20); |
|
|||
61 | chart->setAxisY(axisY, chart->series().at(0)); |
|
|||
62 |
|
||||
63 | return chart; |
|
|||
64 | } |
|
64 | } | |
65 |
|
||||
66 | }; |
|
65 | }; | |
67 |
|
66 | |||
68 | DECLARE_CHART(CategoryLineChart) |
|
67 | DECLARE_CHART(CategoryLineChart) |
@@ -31,30 +31,29 public: | |||||
31 | QString category() { return QObject::tr("Axis"); } |
|
31 | QString category() { return QObject::tr("Axis"); } | |
32 | QString subCategory() { return QString::null; } |
|
32 | QString subCategory() { return QString::null; } | |
33 |
|
33 | |||
34 |
QChart* |
|
34 | QChart *createChart(const DataTable &table) | |
35 |
|
35 | { | ||
36 |
|
|
36 | QChart *chart = new QChart(); | |
37 |
|
|
37 | chart->setTitle("Value X , Value Y"); | |
38 |
|
38 | |||
39 |
|
|
39 | QString name("Series "); | |
40 |
|
|
40 | int nameIndex = 0; | |
41 |
|
|
41 | foreach (DataList list, table) { | |
42 |
|
|
42 | QLineSeries *series = new QLineSeries(chart); | |
43 |
|
|
43 | foreach (Data data, list) | |
44 |
|
|
44 | series->append(data.first); | |
45 |
|
|
45 | series->setName(name + QString::number(nameIndex)); | |
46 |
|
|
46 | nameIndex++; | |
47 |
|
|
47 | chart->addSeries(series); | |
48 |
|
|
48 | } | |
49 |
|
49 | |||
50 |
|
|
50 | chart->createDefaultAxes(); | |
51 |
|
|
51 | QValueAxis *axis = new QValueAxis(); | |
52 |
|
|
52 | foreach (QAbstractSeries *series, chart->series()) | |
53 |
|
|
53 | chart->setAxisX(axis, series); | |
54 |
|
54 | |||
55 |
|
|
55 | return chart; | |
56 | } |
|
56 | } | |
57 |
|
||||
58 | }; |
|
57 | }; | |
59 |
|
58 | |||
60 | DECLARE_CHART(ValueAxis); |
|
59 | DECLARE_CHART(ValueAxis); |
@@ -30,14 +30,11 public: | |||||
30 | QString category() { return QObject::tr("BarSeries"); } |
|
30 | QString category() { return QObject::tr("BarSeries"); } | |
31 | QString subCategory() { return QObject::tr("Horizontal"); } |
|
31 | QString subCategory() { return QObject::tr("Horizontal"); } | |
32 |
|
32 | |||
33 |
QChart* |
|
33 | QChart *createChart(const DataTable &table) | |
34 | { |
|
34 | { | |
35 |
|
35 | QChart *chart = new QChart(); | ||
36 | QChart* chart = new QChart(); |
|
|||
37 |
|
||||
38 | chart->setTitle("Horizontal bar chart"); |
|
36 | chart->setTitle("Horizontal bar chart"); | |
39 |
|
37 | QHorizontalBarSeries *series = new QHorizontalBarSeries(chart); | ||
40 | QHorizontalBarSeries* series = new QHorizontalBarSeries(chart); |
|
|||
41 | for (int i(0); i < table.count(); i++) { |
|
38 | for (int i(0); i < table.count(); i++) { | |
42 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
39 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
43 | foreach (Data data, table[i]) |
|
40 | foreach (Data data, table[i]) | |
@@ -48,7 +45,6 public: | |||||
48 | chart->createDefaultAxes(); |
|
45 | chart->createDefaultAxes(); | |
49 | return chart; |
|
46 | return chart; | |
50 | } |
|
47 | } | |
51 |
|
||||
52 | }; |
|
48 | }; | |
53 |
|
49 | |||
54 | DECLARE_CHART(HorizontalBarChart) |
|
50 | DECLARE_CHART(HorizontalBarChart) |
@@ -30,14 +30,11 public: | |||||
30 | QString category() { return QObject::tr("BarSeries"); } |
|
30 | QString category() { return QObject::tr("BarSeries"); } | |
31 | QString subCategory() { return QObject::tr("Horizontal"); } |
|
31 | QString subCategory() { return QObject::tr("Horizontal"); } | |
32 |
|
32 | |||
33 |
QChart* |
|
33 | QChart *createChart(const DataTable &table) | |
34 | { |
|
34 | { | |
35 |
|
35 | QChart *chart = new QChart(); | ||
36 | QChart* chart = new QChart(); |
|
|||
37 |
|
||||
38 | chart->setTitle("Horizontal percent chart"); |
|
36 | chart->setTitle("Horizontal percent chart"); | |
39 |
|
37 | QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries(chart); | ||
40 | QHorizontalPercentBarSeries* series = new QHorizontalPercentBarSeries(chart); |
|
|||
41 | for (int i(0); i < table.count(); i++) { |
|
38 | for (int i(0); i < table.count(); i++) { | |
42 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
39 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
43 | foreach (Data data, table[i]) |
|
40 | foreach (Data data, table[i]) | |
@@ -48,7 +45,6 public: | |||||
48 | chart->createDefaultAxes(); |
|
45 | chart->createDefaultAxes(); | |
49 | return chart; |
|
46 | return chart; | |
50 | } |
|
47 | } | |
51 |
|
||||
52 | }; |
|
48 | }; | |
53 |
|
49 | |||
54 | DECLARE_CHART(HorizontalPercentBarChart) |
|
50 | DECLARE_CHART(HorizontalPercentBarChart) |
@@ -30,14 +30,11 public: | |||||
30 | QString category() { return QObject::tr("BarSeries"); } |
|
30 | QString category() { return QObject::tr("BarSeries"); } | |
31 | QString subCategory() { return QObject::tr("Horizontal"); } |
|
31 | QString subCategory() { return QObject::tr("Horizontal"); } | |
32 |
|
32 | |||
33 |
QChart* |
|
33 | QChart *createChart(const DataTable &table) | |
34 | { |
|
34 | { | |
35 |
|
35 | QChart *chart = new QChart(); | ||
36 | QChart* chart = new QChart(); |
|
|||
37 |
|
||||
38 | chart->setTitle("Horizontal stacked chart"); |
|
36 | chart->setTitle("Horizontal stacked chart"); | |
39 |
|
37 | QHorizontalStackedBarSeries *series = new QHorizontalStackedBarSeries(chart); | ||
40 | QHorizontalStackedBarSeries* series = new QHorizontalStackedBarSeries(chart); |
|
|||
41 | for (int i(0); i < table.count(); i++) { |
|
38 | for (int i(0); i < table.count(); i++) { | |
42 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
39 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
43 | foreach (Data data, table[i]) |
|
40 | foreach (Data data, table[i]) | |
@@ -48,7 +45,6 public: | |||||
48 | chart->createDefaultAxes(); |
|
45 | chart->createDefaultAxes(); | |
49 | return chart; |
|
46 | return chart; | |
50 | } |
|
47 | } | |
51 |
|
||||
52 | }; |
|
48 | }; | |
53 |
|
49 | |||
54 | DECLARE_CHART(HorizontalStackedBarChart) |
|
50 | DECLARE_CHART(HorizontalStackedBarChart) |
@@ -30,14 +30,11 public: | |||||
30 | QString category() { return QObject::tr("BarSeries"); } |
|
30 | QString category() { return QObject::tr("BarSeries"); } | |
31 | QString subCategory() { return QObject::tr("Vertical"); } |
|
31 | QString subCategory() { return QObject::tr("Vertical"); } | |
32 |
|
32 | |||
33 |
QChart* |
|
33 | QChart *createChart(const DataTable &table) | |
34 | { |
|
34 | { | |
35 |
|
35 | QChart *chart = new QChart(); | ||
36 | QChart* chart = new QChart(); |
|
|||
37 |
|
||||
38 | chart->setTitle("Vertical bar chart"); |
|
36 | chart->setTitle("Vertical bar chart"); | |
39 |
|
37 | QBarSeries *series = new QBarSeries(chart); | ||
40 | QBarSeries* series = new QBarSeries(chart); |
|
|||
41 | for (int i(0); i < table.count(); i++) { |
|
38 | for (int i(0); i < table.count(); i++) { | |
42 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
39 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
43 | foreach (Data data, table[i]) |
|
40 | foreach (Data data, table[i]) | |
@@ -48,7 +45,6 public: | |||||
48 | chart->createDefaultAxes(); |
|
45 | chart->createDefaultAxes(); | |
49 | return chart; |
|
46 | return chart; | |
50 | } |
|
47 | } | |
51 |
|
||||
52 | }; |
|
48 | }; | |
53 |
|
49 | |||
54 | DECLARE_CHART(VerticalBarChart) |
|
50 | DECLARE_CHART(VerticalBarChart) |
@@ -30,14 +30,11 public: | |||||
30 | QString category() { return QObject::tr("BarSeries"); } |
|
30 | QString category() { return QObject::tr("BarSeries"); } | |
31 | QString subCategory() { return QObject::tr("Vertical"); } |
|
31 | QString subCategory() { return QObject::tr("Vertical"); } | |
32 |
|
32 | |||
33 |
QChart* |
|
33 | QChart *createChart(const DataTable &table) | |
34 | { |
|
34 | { | |
35 |
|
35 | QChart *chart = new QChart(); | ||
36 | QChart* chart = new QChart(); |
|
|||
37 |
|
||||
38 | chart->setTitle("Stacked bar chart"); |
|
36 | chart->setTitle("Stacked bar chart"); | |
39 |
|
37 | QPercentBarSeries *series = new QPercentBarSeries(chart); | ||
40 | QPercentBarSeries* series = new QPercentBarSeries(chart); |
|
|||
41 | for (int i(0); i < table.count(); i++) { |
|
38 | for (int i(0); i < table.count(); i++) { | |
42 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
39 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
43 | foreach (Data data, table[i]) |
|
40 | foreach (Data data, table[i]) | |
@@ -48,7 +45,6 public: | |||||
48 | chart->createDefaultAxes(); |
|
45 | chart->createDefaultAxes(); | |
49 | return chart; |
|
46 | return chart; | |
50 | } |
|
47 | } | |
51 |
|
||||
52 | }; |
|
48 | }; | |
53 |
|
49 | |||
54 | DECLARE_CHART(VerticalPercentBarChart) |
|
50 | DECLARE_CHART(VerticalPercentBarChart) |
@@ -30,14 +30,11 public: | |||||
30 | QString category() { return QObject::tr("BarSeries"); } |
|
30 | QString category() { return QObject::tr("BarSeries"); } | |
31 | QString subCategory() { return QObject::tr("Vertical"); } |
|
31 | QString subCategory() { return QObject::tr("Vertical"); } | |
32 |
|
32 | |||
33 |
QChart* |
|
33 | QChart *createChart(const DataTable &table) | |
34 | { |
|
34 | { | |
35 |
|
35 | QChart *chart = new QChart(); | ||
36 | QChart* chart = new QChart(); |
|
|||
37 |
|
||||
38 | chart->setTitle("Stacked bar chart"); |
|
36 | chart->setTitle("Stacked bar chart"); | |
39 |
|
37 | QStackedBarSeries *series = new QStackedBarSeries(chart); | ||
40 | QStackedBarSeries* series = new QStackedBarSeries(chart); |
|
|||
41 | for (int i(0); i < table.count(); i++) { |
|
38 | for (int i(0); i < table.count(); i++) { | |
42 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
39 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
43 | foreach (Data data, table[i]) |
|
40 | foreach (Data data, table[i]) | |
@@ -48,7 +45,6 public: | |||||
48 | chart->createDefaultAxes(); |
|
45 | chart->createDefaultAxes(); | |
49 | return chart; |
|
46 | return chart; | |
50 | } |
|
47 | } | |
51 |
|
||||
52 | }; |
|
48 | }; | |
53 |
|
49 | |||
54 | DECLARE_CHART(VerticalStackedBarChart) |
|
50 | DECLARE_CHART(VerticalStackedBarChart) |
@@ -25,86 +25,90 | |||||
25 | class FontChart: public Chart |
|
25 | class FontChart: public Chart | |
26 | { |
|
26 | { | |
27 | public: |
|
27 | public: | |
28 | FontChart(int fontSize):m_fontSize(fontSize){}; |
|
28 | FontChart(int fontSize): m_fontSize(fontSize) {}; | |
29 | QString name() { return QObject::tr("Font") + " " + QString::number(m_fontSize); } |
|
29 | QString name() { return QObject::tr("Font") + " " + QString::number(m_fontSize); } | |
30 | QString category() { return QObject::tr("Font"); } |
|
30 | QString category() { return QObject::tr("Font"); } | |
31 | QString subCategory() { return QString::null; } |
|
31 | QString subCategory() { return QString::null; } | |
32 |
|
32 | |||
33 |
QChart* |
|
33 | QChart *createChart(const DataTable &table) | |
34 |
|
34 | { | ||
35 |
|
|
35 | QChart *chart = new QChart(); | |
36 |
|
|
36 | chart->setTitle("Font size " + QString::number(m_fontSize)); | |
37 |
|
37 | QString name("Series "); | ||
38 | QString name("Series "); |
|
38 | int nameIndex = 0; | |
39 | int nameIndex = 0; |
|
39 | foreach (DataList list, table) { | |
40 | foreach (DataList list, table) { |
|
40 | QLineSeries *series = new QLineSeries(chart); | |
41 | QLineSeries *series = new QLineSeries(chart); |
|
41 | foreach (Data data, list) | |
42 |
|
|
42 | series->append(data.first); | |
43 | series->append(data.first); |
|
43 | series->setName(name + QString::number(nameIndex)); | |
44 | series->setName(name + QString::number(nameIndex)); |
|
44 | nameIndex++; | |
45 | nameIndex++; |
|
45 | chart->addSeries(series); | |
46 | chart->addSeries(series); |
|
46 | } | |
47 | } |
|
47 | chart->createDefaultAxes(); | |
48 |
|
48 | QFont font; | ||
49 | chart->createDefaultAxes(); |
|
49 | font.setPixelSize(m_fontSize); | |
50 |
|
|
50 | chart->setTitleFont(font); | |
51 | font.setPixelSize(m_fontSize); |
|
51 | chart->axisX()->setLabelsFont(font); | |
52 |
|
|
52 | chart->axisY()->setLabelsFont(font); | |
53 | chart->axisX()->setLabelsFont(font); |
|
53 | return chart; | |
54 | chart->axisY()->setLabelsFont(font); |
|
|||
55 |
|
||||
56 | return chart; |
|
|||
57 | } |
|
54 | } | |
58 |
|
55 | |||
59 | private: |
|
56 | private: | |
60 | int m_fontSize; |
|
57 | int m_fontSize; | |
61 |
|
||||
62 | }; |
|
58 | }; | |
63 |
|
59 | |||
64 |
class FontChart6:public FontChart |
|
60 | class FontChart6: public FontChart | |
|
61 | { | |||
65 | public: |
|
62 | public: | |
66 | FontChart6():FontChart(6){}; |
|
63 | FontChart6(): FontChart(6) {}; | |
67 | }; |
|
64 | }; | |
68 |
|
65 | |||
69 |
class FontChart8:public FontChart |
|
66 | class FontChart8: public FontChart | |
|
67 | { | |||
70 | public: |
|
68 | public: | |
71 | FontChart8():FontChart(8){}; |
|
69 | FontChart8(): FontChart(8) {}; | |
72 | }; |
|
70 | }; | |
73 |
|
71 | |||
74 |
class FontChart10:public FontChart |
|
72 | class FontChart10: public FontChart | |
|
73 | { | |||
75 | public: |
|
74 | public: | |
76 | FontChart10():FontChart(10){}; |
|
75 | FontChart10(): FontChart(10) {}; | |
77 | }; |
|
76 | }; | |
78 |
|
77 | |||
79 |
class FontChart14:public FontChart |
|
78 | class FontChart14: public FontChart | |
|
79 | { | |||
80 | public: |
|
80 | public: | |
81 | FontChart14():FontChart(14){}; |
|
81 | FontChart14(): FontChart(14) {}; | |
82 | }; |
|
82 | }; | |
83 |
|
83 | |||
84 |
|
84 | class FontChart18: public FontChart | ||
85 | class FontChart18:public FontChart{ |
|
85 | { | |
86 | public: |
|
86 | public: | |
87 | FontChart18():FontChart(18){}; |
|
87 | FontChart18(): FontChart(18) {}; | |
88 | }; |
|
88 | }; | |
89 |
|
89 | |||
90 |
class FontChart20:public FontChart |
|
90 | class FontChart20: public FontChart | |
|
91 | { | |||
91 | public: |
|
92 | public: | |
92 | FontChart20():FontChart(20){}; |
|
93 | FontChart20(): FontChart(20) {}; | |
93 | }; |
|
94 | }; | |
94 |
|
95 | |||
95 |
class FontChart24:public FontChart |
|
96 | class FontChart24: public FontChart | |
|
97 | { | |||
96 | public: |
|
98 | public: | |
97 | FontChart24():FontChart(24){}; |
|
99 | FontChart24(): FontChart(24) {}; | |
98 | }; |
|
100 | }; | |
99 |
|
101 | |||
100 |
class FontChart28:public FontChart |
|
102 | class FontChart28: public FontChart | |
|
103 | { | |||
101 | public: |
|
104 | public: | |
102 | FontChart28():FontChart(28){}; |
|
105 | FontChart28(): FontChart(28) {}; | |
103 | }; |
|
106 | }; | |
104 |
|
107 | |||
105 |
class FontChart32:public FontChart |
|
108 | class FontChart32: public FontChart | |
|
109 | { | |||
106 | public: |
|
110 | public: | |
107 | FontChart32():FontChart(32){}; |
|
111 | FontChart32(): FontChart(32) {}; | |
108 | }; |
|
112 | }; | |
109 |
|
113 | |||
110 | DECLARE_CHART(FontChart6); |
|
114 | DECLARE_CHART(FontChart6); |
@@ -29,28 +29,26 public: | |||||
29 | QString category() { return QObject::tr("PieSeries"); } |
|
29 | QString category() { return QObject::tr("PieSeries"); } | |
30 | QString subCategory() { return QString::null; } |
|
30 | QString subCategory() { return QString::null; } | |
31 |
|
31 | |||
32 |
QChart* |
|
32 | QChart *createChart(const DataTable &table) | |
33 | { |
|
33 | { | |
34 |
QChart* |
|
34 | QChart *chart = new QChart(); | |
35 | chart->setTitle("Donut chart"); |
|
35 | chart->setTitle("Donut chart"); | |
36 |
|
36 | for (int i = 0, j = table.count(); i < table.count(); i++, j--) { | ||
37 | for (int i = 0, j = table.count(); i < table.count(); i++,j--) { |
|
|||
38 | QPieSeries *series = new QPieSeries(chart); |
|
37 | QPieSeries *series = new QPieSeries(chart); | |
39 | foreach (Data data, table[i]) { |
|
38 | foreach (Data data, table[i]) { | |
40 | QPieSlice *slice = series->append(data.second, data.first.y()); |
|
39 | QPieSlice *slice = series->append(data.second, data.first.y()); | |
41 |
if (data == table[i].first()) |
|
40 | if (data == table[i].first()) | |
42 | slice->setLabelVisible(); |
|
41 | slice->setLabelVisible(); | |
43 | } |
|
|||
44 | } |
|
42 | } | |
45 |
series->setPieSize( |
|
43 | series->setPieSize(j / (qreal) table.count()); | |
46 | if(j>1) series->setHoleSize( (j-1)/ (qreal) table.count()+0.1); |
|
44 | if (j > 1) | |
|
45 | series->setHoleSize((j - 1) / (qreal) table.count() + 0.1); | |||
47 | series->setHorizontalPosition(0.5); |
|
46 | series->setHorizontalPosition(0.5); | |
48 | series->setVerticalPosition(0.5); |
|
47 | series->setVerticalPosition(0.5); | |
49 | chart->addSeries(series); |
|
48 | chart->addSeries(series); | |
50 | } |
|
49 | } | |
51 | return chart; |
|
50 | return chart; | |
52 | } |
|
51 | } | |
53 |
|
||||
54 | }; |
|
52 | }; | |
55 |
|
53 | |||
56 | DECLARE_CHART(DonutChart) |
|
54 | DECLARE_CHART(DonutChart) |
@@ -29,11 +29,10 public: | |||||
29 | QString category() { return QObject::tr("PieSeries"); } |
|
29 | QString category() { return QObject::tr("PieSeries"); } | |
30 | QString subCategory() { return QString::null; } |
|
30 | QString subCategory() { return QString::null; } | |
31 |
|
31 | |||
32 |
QChart* |
|
32 | QChart *createChart(const DataTable &table) | |
33 | { |
|
33 | { | |
34 |
QChart* |
|
34 | QChart *chart = new QChart(); | |
35 | chart->setTitle("Pie chart"); |
|
35 | chart->setTitle("Pie chart"); | |
36 |
|
||||
37 | qreal pieSize = 1.0 / table.count(); |
|
36 | qreal pieSize = 1.0 / table.count(); | |
38 | for (int i = 0; i < table.count(); i++) { |
|
37 | for (int i = 0; i < table.count(); i++) { | |
39 | QPieSeries *series = new QPieSeries(chart); |
|
38 | QPieSeries *series = new QPieSeries(chart); | |
@@ -52,7 +51,6 public: | |||||
52 | } |
|
51 | } | |
53 | return chart; |
|
52 | return chart; | |
54 | } |
|
53 | } | |
55 |
|
||||
56 | }; |
|
54 | }; | |
57 |
|
55 | |||
58 | DECLARE_CHART(PieChart) |
|
56 | DECLARE_CHART(PieChart) |
@@ -30,9 +30,8 public: | |||||
30 | QString category() { return QObject::tr("XYSeries"); } |
|
30 | QString category() { return QObject::tr("XYSeries"); } | |
31 | QString subCategory() { return QString::null; } |
|
31 | QString subCategory() { return QString::null; } | |
32 |
|
32 | |||
33 |
QChart* |
|
33 | QChart *createChart(const DataTable &table) | |
34 | { |
|
34 | { | |
35 |
|
||||
36 | QChart *chart = new QChart(); |
|
35 | QChart *chart = new QChart(); | |
37 | chart->setTitle("Area chart"); |
|
36 | chart->setTitle("Area chart"); | |
38 |
|
37 | |||
@@ -47,9 +46,9 public: | |||||
47 | if (lowerSeries) { |
|
46 | if (lowerSeries) { | |
48 | const QList<QPointF>& points = lowerSeries->points(); |
|
47 | const QList<QPointF>& points = lowerSeries->points(); | |
49 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); |
|
48 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); | |
50 | } |
|
49 | } else { | |
51 | else |
|
|||
52 | upperSeries->append(QPointF(j, data.first.y())); |
|
50 | upperSeries->append(QPointF(j, data.first.y())); | |
|
51 | } | |||
53 | } |
|
52 | } | |
54 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
53 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); | |
55 | area->setName(name + QString::number(nameIndex)); |
|
54 | area->setName(name + QString::number(nameIndex)); | |
@@ -58,11 +57,8 public: | |||||
58 | chart->createDefaultAxes(); |
|
57 | chart->createDefaultAxes(); | |
59 | lowerSeries = upperSeries; |
|
58 | lowerSeries = upperSeries; | |
60 | } |
|
59 | } | |
61 |
|
||||
62 | return chart; |
|
60 | return chart; | |
63 |
|
||||
64 | } |
|
61 | } | |
65 |
|
||||
66 | }; |
|
62 | }; | |
67 |
|
63 | |||
68 | DECLARE_CHART(AreaChart) |
|
64 | DECLARE_CHART(AreaChart) |
@@ -29,27 +29,23 public: | |||||
29 | QString category() { return QObject::tr("XYSeries"); } |
|
29 | QString category() { return QObject::tr("XYSeries"); } | |
30 | QString subCategory() { return QString::null; } |
|
30 | QString subCategory() { return QString::null; } | |
31 |
|
31 | |||
32 |
QChart* |
|
32 | QChart *createChart(const DataTable &table) | |
33 |
|
33 | { | ||
34 |
|
|
34 | QChart *chart = new QChart(); | |
35 |
|
|
35 | chart->setTitle("Line chart"); | |
36 |
|
36 | QString name("Series "); | ||
37 | QString name("Series "); |
|
37 | int nameIndex = 0; | |
38 | int nameIndex = 0; |
|
38 | foreach (DataList list, table) { | |
39 | foreach (DataList list, table) { |
|
39 | QLineSeries *series = new QLineSeries(chart); | |
40 | QLineSeries *series = new QLineSeries(chart); |
|
40 | foreach (Data data, list) | |
41 |
|
|
41 | series->append(data.first); | |
42 | series->append(data.first); |
|
42 | series->setName(name + QString::number(nameIndex)); | |
43 | series->setName(name + QString::number(nameIndex)); |
|
43 | nameIndex++; | |
44 | nameIndex++; |
|
44 | chart->addSeries(series); | |
45 | chart->addSeries(series); |
|
45 | } | |
46 | } |
|
46 | chart->createDefaultAxes(); | |
47 |
|
47 | return chart; | ||
48 | chart->createDefaultAxes(); |
|
|||
49 |
|
||||
50 | return chart; |
|
|||
51 | } |
|
48 | } | |
52 |
|
||||
53 | }; |
|
49 | }; | |
54 |
|
50 | |||
55 | DECLARE_CHART(LineChart) |
|
51 | DECLARE_CHART(LineChart) |
@@ -29,10 +29,9 public: | |||||
29 | QString category() { return QObject::tr("XYSeries"); } |
|
29 | QString category() { return QObject::tr("XYSeries"); } | |
30 | QString subCategory() { return QString::null; } |
|
30 | QString subCategory() { return QString::null; } | |
31 |
|
31 | |||
32 |
QChart* |
|
32 | QChart *createChart(const DataTable &table) | |
33 | { |
|
33 | { | |
34 |
|
34 | QChart *chart = new QChart(); | ||
35 | QChart* chart = new QChart(); |
|
|||
36 | chart->setTitle("Scatter chart"); |
|
35 | chart->setTitle("Scatter chart"); | |
37 | QString name("Series "); |
|
36 | QString name("Series "); | |
38 | int nameIndex = 0; |
|
37 | int nameIndex = 0; | |
@@ -45,10 +44,8 public: | |||||
45 | chart->addSeries(series); |
|
44 | chart->addSeries(series); | |
46 | } |
|
45 | } | |
47 | chart->createDefaultAxes(); |
|
46 | chart->createDefaultAxes(); | |
48 |
|
||||
49 | return chart; |
|
47 | return chart; | |
50 | } |
|
48 | } | |
51 |
|
||||
52 | }; |
|
49 | }; | |
53 |
|
50 | |||
54 | DECLARE_CHART(ScatterChart) |
|
51 | DECLARE_CHART(ScatterChart) |
@@ -29,11 +29,9 public: | |||||
29 | QString category() { return QObject::tr("XYSeries"); } |
|
29 | QString category() { return QObject::tr("XYSeries"); } | |
30 | QString subCategory() { return QString::null; } |
|
30 | QString subCategory() { return QString::null; } | |
31 |
|
31 | |||
32 |
QChart* |
|
32 | QChart *createChart(const DataTable &table) | |
33 | { |
|
33 | { | |
34 |
|
34 | QChart *chart = new QChart(); | ||
35 | QChart* chart = new QChart(); |
|
|||
36 |
|
||||
37 | chart->setTitle("Spline chart"); |
|
35 | chart->setTitle("Spline chart"); | |
38 | QString name("Series "); |
|
36 | QString name("Series "); | |
39 | int nameIndex = 0; |
|
37 | int nameIndex = 0; | |
@@ -48,7 +46,6 public: | |||||
48 | chart->createDefaultAxes(); |
|
46 | chart->createDefaultAxes(); | |
49 | return chart; |
|
47 | return chart; | |
50 | } |
|
48 | } | |
51 |
|
||||
52 | }; |
|
49 | }; | |
53 |
|
50 | |||
54 | DECLARE_CHART(SplineChart) |
|
51 | DECLARE_CHART(SplineChart) |
@@ -35,7 +35,7 typedef QList<DataList> DataTable; | |||||
35 | class Model |
|
35 | class Model | |
36 | { |
|
36 | { | |
37 | private: |
|
37 | private: | |
38 | Model(){} |
|
38 | Model() {} | |
39 |
|
39 | |||
40 | public: |
|
40 | public: | |
41 | static DataTable generateRandomData(int listCount, int valueMax, int valueCount) |
|
41 | static DataTable generateRandomData(int listCount, int valueMax, int valueCount) | |
@@ -50,19 +50,17 public: | |||||
50 | DataList dataList; |
|
50 | DataList dataList; | |
51 | qreal yValue(0); |
|
51 | qreal yValue(0); | |
52 | for (int j(0); j < valueCount; j++) { |
|
52 | for (int j(0); j < valueCount; j++) { | |
53 |
yValue = yValue + (qreal) |
|
53 | yValue = yValue + (qreal)(qrand() % valueMax) / (qreal) valueCount; | |
54 | QPointF value( |
|
54 | QPointF value( | |
55 | (j + (qreal) qrand() / (qreal) RAND_MAX) |
|
55 | (j + (qreal) qrand() / (qreal) RAND_MAX) | |
56 |
|
|
56 | * ((qreal) valueMax / (qreal) valueCount), yValue); | |
57 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); |
|
57 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); | |
58 | dataList << Data(value, label); |
|
58 | dataList << Data(value, label); | |
59 | } |
|
59 | } | |
60 | dataTable << dataList; |
|
60 | dataTable << dataList; | |
61 | } |
|
61 | } | |
62 |
|
||||
63 | return dataTable; |
|
62 | return dataTable; | |
64 | } |
|
63 | } | |
65 |
|
||||
66 | }; |
|
64 | }; | |
67 |
|
65 | |||
68 | #endif |
|
66 | #endif |
@@ -23,8 +23,9 | |||||
23 | #include <QResizeEvent> |
|
23 | #include <QResizeEvent> | |
24 | #include <QDebug> |
|
24 | #include <QDebug> | |
25 |
|
25 | |||
26 |
View::View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent) |
|
26 | View::View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent) | |
27 | m_form(form) |
|
27 | : QGraphicsView(scene, parent), | |
|
28 | m_form(form) | |||
28 | { |
|
29 | { | |
29 | setDragMode(QGraphicsView::NoDrag); |
|
30 | setDragMode(QGraphicsView::NoDrag); | |
30 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
31 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
@@ -49,8 +50,7 void View::mouseMoveEvent(QMouseEvent *event) | |||||
49 |
|
50 | |||
50 | void View::mouseReleaseEvent(QMouseEvent *event) |
|
51 | void View::mouseReleaseEvent(QMouseEvent *event) | |
51 | { |
|
52 | { | |
52 |
|
||||
53 | QGraphicsView::mouseReleaseEvent(event); |
|
53 | QGraphicsView::mouseReleaseEvent(event); | |
54 | //BugFix somehow view always eats the mouse release event; |
|
54 | //BugFix somehow view always eats the mouse release event; | |
55 | event->setAccepted(false); |
|
55 | event->setAccepted(false); | |
56 | } |
|
56 | } |
@@ -40,7 +40,7 | |||||
40 | #include <QDebug> |
|
40 | #include <QDebug> | |
41 | #include <QMenu> |
|
41 | #include <QMenu> | |
42 |
|
42 | |||
43 |
Window::Window(QWidget* |
|
43 | Window::Window(QWidget *parent) : | |
44 | QMainWindow(parent), |
|
44 | QMainWindow(parent), | |
45 | m_listCount(3), |
|
45 | m_listCount(3), | |
46 | m_valueMax(10), |
|
46 | m_valueMax(10), | |
@@ -88,12 +88,12 Window::Window(QWidget* parent) : | |||||
88 | Charts::ChartList list = Charts::chartList(); |
|
88 | Charts::ChartList list = Charts::chartList(); | |
89 |
|
89 | |||
90 | for (int i = 0; i < 9; ++i) { |
|
90 | for (int i = 0; i < 9; ++i) { | |
91 |
QChart* |
|
91 | QChart *chart = 0; | |
92 | if(i<list.size()){ |
|
92 | if (i < list.size()) { | |
93 | chart = list.at(i)->createChart(m_dataTable); |
|
93 | chart = list.at(i)->createChart(m_dataTable); | |
94 | }else{ |
|
94 | } else { | |
95 | chart = new QChart(); |
|
95 | chart = new QChart(); | |
96 | chart->setTitle(tr("Empty")); |
|
96 | chart->setTitle(tr("Empty")); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | m_baseLayout->addItem(chart, i / 3, i % 3); |
|
99 | m_baseLayout->addItem(chart, i / 3, i % 3); | |
@@ -123,7 +123,7 Window::~Window() | |||||
123 |
|
123 | |||
124 | void Window::connectSignals() |
|
124 | void Window::connectSignals() | |
125 | { |
|
125 | { | |
126 | QObject::connect(m_form, SIGNAL(geometryChanged()),this ,SLOT(handleGeometryChanged())); |
|
126 | QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged())); | |
127 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
127 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
128 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
128 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
129 | QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
129 | QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
@@ -143,7 +143,7 void Window::createProxyWidgets() | |||||
143 | m_openGLCheckBox = new QCheckBox(tr("OpenGL")); |
|
143 | m_openGLCheckBox = new QCheckBox(tr("OpenGL")); | |
144 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); |
|
144 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); | |
145 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); |
|
145 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); | |
146 | m_templateComboBox= createTempleteBox(); |
|
146 | m_templateComboBox = createTempleteBox(); | |
147 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); |
|
147 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); | |
148 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); |
|
148 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); | |
149 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); |
|
149 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); | |
@@ -159,9 +159,9 void Window::createProxyWidgets() | |||||
159 |
|
159 | |||
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 |
QComboBox* |
|
162 | QComboBox *Window::createThemeBox() | |
163 | { |
|
163 | { | |
164 |
QComboBox* |
|
164 | QComboBox *themeComboBox = new ComboBox(this); | |
165 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
165 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
166 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
166 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
167 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
167 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
@@ -172,9 +172,9 QComboBox* Window::createThemeBox() | |||||
172 | return themeComboBox; |
|
172 | return themeComboBox; | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 |
QComboBox* |
|
175 | QComboBox *Window::createAnimationBox() | |
176 | { |
|
176 | { | |
177 |
QComboBox* |
|
177 | QComboBox *animationComboBox = new ComboBox(this); | |
178 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
178 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
179 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
179 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
180 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
180 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
@@ -182,9 +182,9 QComboBox* Window::createAnimationBox() | |||||
182 | return animationComboBox; |
|
182 | return animationComboBox; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 |
QComboBox* |
|
185 | QComboBox *Window::createLegendBox() | |
186 | { |
|
186 | { | |
187 |
QComboBox* |
|
187 | QComboBox *legendComboBox = new ComboBox(this); | |
188 | legendComboBox->addItem("No Legend ", 0); |
|
188 | legendComboBox->addItem("No Legend ", 0); | |
189 | legendComboBox->addItem("Legend Top", Qt::AlignTop); |
|
189 | legendComboBox->addItem("Legend Top", Qt::AlignTop); | |
190 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); |
|
190 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); | |
@@ -193,20 +193,20 QComboBox* Window::createLegendBox() | |||||
193 | return legendComboBox; |
|
193 | return legendComboBox; | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 |
QComboBox* |
|
196 | QComboBox *Window::createTempleteBox() | |
197 | { |
|
197 | { | |
198 |
QComboBox* |
|
198 | QComboBox *templateComboBox = new ComboBox(this); | |
199 | templateComboBox->addItem("No Template", 0); |
|
199 | templateComboBox->addItem("No Template", 0); | |
200 |
|
200 | |||
201 | Charts::ChartList list = Charts::chartList(); |
|
201 | Charts::ChartList list = Charts::chartList(); | |
202 | QMultiMap<QString, Chart*> categoryMap; |
|
202 | QMultiMap<QString, Chart *> categoryMap; | |
203 |
|
203 | |||
204 |
foreach(Chart* |
|
204 | foreach (Chart *chart, list) | |
205 |
|
|
205 | categoryMap.insertMulti(chart->category(), chart); | |
206 | } |
|
206 | ||
207 |
foreach(const QString& |
|
207 | foreach (const QString &category, categoryMap.uniqueKeys()) | |
208 | templateComboBox->addItem(category, category); |
|
208 | templateComboBox->addItem(category, category); | |
209 | } |
|
209 | ||
210 | return templateComboBox; |
|
210 | return templateComboBox; | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
@@ -226,11 +226,9 void Window::checkLegend() | |||||
226 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
226 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
227 |
|
227 | |||
228 | if (!alignment) { |
|
228 | if (!alignment) { | |
229 |
foreach (QChart *chart, m_chartHash.keys()) |
|
229 | foreach (QChart *chart, m_chartHash.keys()) | |
230 | chart->legend()->hide(); |
|
230 | chart->legend()->hide(); | |
231 | } |
|
231 | } else { | |
232 | } |
|
|||
233 | else { |
|
|||
234 | foreach (QChart *chart, m_chartHash.keys()) { |
|
232 | foreach (QChart *chart, m_chartHash.keys()) { | |
235 | chart->legend()->setAlignment(alignment); |
|
233 | chart->legend()->setAlignment(alignment); | |
236 | chart->legend()->show(); |
|
234 | chart->legend()->show(); | |
@@ -241,7 +239,7 void Window::checkLegend() | |||||
241 | void Window::checkOpenGL() |
|
239 | void Window::checkOpenGL() | |
242 | { |
|
240 | { | |
243 | bool opengl = m_openGLCheckBox->isChecked(); |
|
241 | bool opengl = m_openGLCheckBox->isChecked(); | |
244 | bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport()); |
|
242 | bool isOpengl = qobject_cast<QGLWidget *>(m_view->viewport()); | |
245 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { |
|
243 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { | |
246 | m_view->deleteLater(); |
|
244 | m_view->deleteLater(); | |
247 | m_view = new View(m_scene, m_form); |
|
245 | m_view = new View(m_scene, m_form); | |
@@ -251,20 +249,21 void Window::checkOpenGL() | |||||
251 |
|
249 | |||
252 | bool antialias = m_antialiasCheckBox->isChecked(); |
|
250 | bool antialias = m_antialiasCheckBox->isChecked(); | |
253 |
|
251 | |||
254 |
|
|
252 | if (opengl) | |
255 |
|
|
253 | m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); | |
256 |
|
|
254 | else | |
257 |
|
|
255 | m_view->setRenderHint(QPainter::Antialiasing, antialias); | |
258 | } |
|
256 | } | |
259 |
|
257 | |||
260 | void Window::checkAnimationOptions() |
|
258 | void Window::checkAnimationOptions() | |
261 | { |
|
259 | { | |
262 | QChart::AnimationOptions options( |
|
260 | QChart::AnimationOptions options( | |
263 |
|
|
261 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
264 | if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) { |
|
262 | ||
265 | foreach (QChart *chart, m_chartHash.keys()) |
|
263 | if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) { | |
266 | chart->setAnimationOptions(options); |
|
264 | foreach (QChart *chart, m_chartHash.keys()) | |
267 | } |
|
265 | chart->setAnimationOptions(options); | |
|
266 | } | |||
268 | } |
|
267 | } | |
269 |
|
268 | |||
270 | void Window::checkState() |
|
269 | void Window::checkState() | |
@@ -274,8 +273,7 void Window::checkState() | |||||
274 | if (m_state != ScrollState && scroll) { |
|
273 | if (m_state != ScrollState && scroll) { | |
275 | m_state = ScrollState; |
|
274 | m_state = ScrollState; | |
276 | m_zoomCheckBox->setChecked(false); |
|
275 | m_zoomCheckBox->setChecked(false); | |
277 | } |
|
276 | } else if (!scroll && m_state == ScrollState) { | |
278 | else if (!scroll && m_state == ScrollState) { |
|
|||
279 | m_state = NoState; |
|
277 | m_state = NoState; | |
280 | } |
|
278 | } | |
281 |
|
279 | |||
@@ -284,8 +282,7 void Window::checkState() | |||||
284 | if (m_state != ZoomState && zoom) { |
|
282 | if (m_state != ZoomState && zoom) { | |
285 | m_state = ZoomState; |
|
283 | m_state = ZoomState; | |
286 | m_scrollCheckBox->setChecked(false); |
|
284 | m_scrollCheckBox->setChecked(false); | |
287 | } |
|
285 | } else if (!zoom && m_state == ZoomState) { | |
288 | else if (!zoom && m_state == ZoomState) { |
|
|||
289 | m_state = NoState; |
|
286 | m_state = NoState; | |
290 | } |
|
287 | } | |
291 | } |
|
288 | } | |
@@ -302,26 +299,25 void Window::checkTemplate() | |||||
302 | QString category = m_templateComboBox->itemData(index).toString(); |
|
299 | QString category = m_templateComboBox->itemData(index).toString(); | |
303 | Charts::ChartList list = Charts::chartList(); |
|
300 | Charts::ChartList list = Charts::chartList(); | |
304 |
|
301 | |||
305 | QList<QChart*> qchartList = m_chartHash.keys(); |
|
302 | QList<QChart *> qchartList = m_chartHash.keys(); | |
306 |
|
303 | |||
307 |
foreach(QChart* |
|
304 | foreach (QChart *qchart, qchartList) { | |
308 | for(int i = 0 ; i < m_baseLayout->count();++i) |
|
305 | for (int i = 0 ; i < m_baseLayout->count(); ++i) { | |
309 | { |
|
306 | if (m_baseLayout->itemAt(i) == qchart) { | |
310 |
|
|
307 | m_baseLayout->removeAt(i); | |
311 | m_baseLayout->removeAt(i); |
|
308 | break; | |
312 |
|
|
309 | } | |
313 |
|
|
310 | } | |
314 | } |
|
|||
315 | } |
|
311 | } | |
316 |
|
312 | |||
317 | m_chartHash.clear(); |
|
313 | m_chartHash.clear(); | |
318 | qDeleteAll(qchartList); |
|
314 | qDeleteAll(qchartList); | |
319 |
|
315 | |||
320 |
QChart* |
|
316 | QChart *qchart(0); | |
321 |
|
317 | |||
322 | int j=0; |
|
318 | int j = 0; | |
323 | for (int i = 0; i < list.size(); ++i) { |
|
319 | for (int i = 0; i < list.size(); ++i) { | |
324 |
Chart* |
|
320 | Chart *chart = list.at(i); | |
325 | if (chart->category() == category && j < 9) { |
|
321 | if (chart->category() == category && j < 9) { | |
326 | qchart = list.at(i)->createChart(m_dataTable); |
|
322 | qchart = list.at(i)->createChart(m_dataTable); | |
327 | m_baseLayout->addItem(qchart, j / 3, j % 3); |
|
323 | m_baseLayout->addItem(qchart, j / 3, j % 3); | |
@@ -341,7 +337,7 void Window::checkTemplate() | |||||
341 | void Window::checkTheme() |
|
337 | void Window::checkTheme() | |
342 | { |
|
338 | { | |
343 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( |
|
339 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( | |
344 | m_themeComboBox->currentIndex()).toInt(); |
|
340 | m_themeComboBox->currentIndex()).toInt(); | |
345 |
|
341 | |||
346 | foreach (QChart *chart, m_chartHash.keys()) |
|
342 | foreach (QChart *chart, m_chartHash.keys()) | |
347 | chart->setTheme(theme); |
|
343 | chart->setTheme(theme); | |
@@ -350,38 +346,30 void Window::checkTheme() | |||||
350 | if (theme == QChart::ChartThemeLight) { |
|
346 | if (theme == QChart::ChartThemeLight) { | |
351 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
347 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
352 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
348 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
353 | } |
|
349 | } else if (theme == QChart::ChartThemeDark) { | |
354 | else if (theme == QChart::ChartThemeDark) { |
|
|||
355 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
350 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
356 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
351 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
357 | } |
|
352 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
358 | else if (theme == QChart::ChartThemeBlueCerulean) { |
|
|||
359 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
353 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
360 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
354 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
361 | } |
|
355 | } else if (theme == QChart::ChartThemeBrownSand) { | |
362 | else if (theme == QChart::ChartThemeBrownSand) { |
|
|||
363 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
356 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
364 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
357 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
365 | } |
|
358 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
366 | else if (theme == QChart::ChartThemeBlueNcs) { |
|
|||
367 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
359 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
368 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
360 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
369 | } |
|
361 | } else if (theme == QChart::ChartThemeHighContrast) { | |
370 | else if (theme == QChart::ChartThemeHighContrast) { |
|
|||
371 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
362 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
372 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
363 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
373 | } |
|
364 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
374 | else if (theme == QChart::ChartThemeBlueIcy) { |
|
|||
375 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
365 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
376 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
366 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
377 | } |
|
367 | } else { | |
378 | else { |
|
|||
379 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
368 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
380 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
369 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
381 | } |
|
370 | } | |
382 |
foreach(QGraphicsProxyWidget* |
|
371 | foreach (QGraphicsProxyWidget *widget, m_widgetHash) | |
383 | widget->setPalette(pal); |
|
372 | widget->setPalette(pal); | |
384 | } |
|
|||
385 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); |
|
373 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); | |
386 | m_rubberBand->setPen(pal.color((QPalette::WindowText))); |
|
374 | m_rubberBand->setPen(pal.color((QPalette::WindowText))); | |
387 | } |
|
375 | } | |
@@ -400,10 +388,8 void Window::mousePressEvent(QMouseEvent *event) | |||||
400 | plotArea.translate(geometryRect.topLeft()); |
|
388 | plotArea.translate(geometryRect.topLeft()); | |
401 | if (plotArea.contains(m_origin)) { |
|
389 | if (plotArea.contains(m_origin)) { | |
402 | m_currentState = m_state; |
|
390 | m_currentState = m_state; | |
403 |
|
391 | if (m_currentState == NoState && m_templateComboBox->currentIndex() == 0) | ||
404 | if (m_currentState == NoState && m_templateComboBox->currentIndex()==0) { |
|
|||
405 | handleMenu(chart); |
|
392 | handleMenu(chart); | |
406 | } |
|
|||
407 | break; |
|
393 | break; | |
408 | } |
|
394 | } | |
409 | } |
|
395 | } | |
@@ -424,7 +410,7 void Window::mousePressEvent(QMouseEvent *event) | |||||
424 |
|
410 | |||
425 | void Window::mouseMoveEvent(QMouseEvent *event) |
|
411 | void Window::mouseMoveEvent(QMouseEvent *event) | |
426 | { |
|
412 | { | |
427 |
if ( |
|
413 | if (m_currentState != NoState) { | |
428 |
|
414 | |||
429 | foreach (QChart *chart, m_chartHash.keys()) { |
|
415 | foreach (QChart *chart, m_chartHash.keys()) { | |
430 |
|
416 | |||
@@ -437,13 +423,13 void Window::mouseMoveEvent(QMouseEvent *event) | |||||
437 | QPointF delta = m_origin - event->pos(); |
|
423 | QPointF delta = m_origin - event->pos(); | |
438 | chart->scroll(delta.x(), -delta.y()); |
|
424 | chart->scroll(delta.x(), -delta.y()); | |
439 | } |
|
425 | } | |
440 |
if (m_currentState == ZoomState && plotArea.contains(event->pos())) |
|
426 | if (m_currentState == ZoomState && plotArea.contains(event->pos())) | |
441 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); |
|
427 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); | |
442 | } |
|
|||
443 | break; |
|
428 | break; | |
444 | } |
|
429 | } | |
445 | } |
|
430 | } | |
446 |
if(m_currentState == ScrollState) |
|
431 | if (m_currentState == ScrollState) | |
|
432 | m_origin = event->pos(); | |||
447 | event->accept(); |
|
433 | event->accept(); | |
448 | } |
|
434 | } | |
449 | } |
|
435 | } | |
@@ -493,32 +479,31 void Window::mouseReleaseEvent(QMouseEvent *event) | |||||
493 |
|
479 | |||
494 | void Window::comboBoxFocused(QComboBox *combobox) |
|
480 | void Window::comboBoxFocused(QComboBox *combobox) | |
495 | { |
|
481 | { | |
496 |
foreach(QGraphicsProxyWidget* |
|
482 | foreach (QGraphicsProxyWidget *widget , m_widgetHash) { | |
497 | if(widget->widget()==combobox) |
|
483 | if (widget->widget() == combobox) | |
498 | widget->setZValue(2.0); |
|
484 | widget->setZValue(2.0); | |
499 | else |
|
485 | else | |
500 | widget->setZValue(0.0); |
|
486 | widget->setZValue(0.0); | |
501 | } |
|
487 | } | |
502 | } |
|
488 | } | |
503 |
|
489 | |||
504 |
void Window::handleMenu(QChart* |
|
490 | void Window::handleMenu(QChart *qchart) | |
505 | { |
|
491 | { | |
506 | QAction *chosen = m_menu->exec(QCursor::pos()); |
|
492 | QAction *chosen = m_menu->exec(QCursor::pos()); | |
507 |
|
493 | |||
508 | if (chosen) { |
|
494 | if (chosen) { | |
509 |
Chart* |
|
495 | Chart *chart = (Chart *) chosen->data().value<void *>(); | |
510 | int index = m_chartHash[qchart]; |
|
496 | int index = m_chartHash[qchart]; | |
511 | //not in 4.7.2 m_baseLayout->removeItem(qchart); |
|
497 | //not in 4.7.2 m_baseLayout->removeItem(qchart); | |
512 | for(int i = 0 ; i < m_baseLayout->count();++i) |
|
498 | for (int i = 0 ; i < m_baseLayout->count(); ++i) { | |
513 | { |
|
499 | if (m_baseLayout->itemAt(i) == qchart) { | |
514 | if(m_baseLayout->itemAt(i)==qchart){ |
|
|||
515 | m_baseLayout->removeAt(i); |
|
500 | m_baseLayout->removeAt(i); | |
516 | break; |
|
501 | break; | |
517 | } |
|
502 | } | |
518 | } |
|
503 | } | |
519 |
|
504 | |||
520 | m_chartHash.remove(qchart); |
|
505 | m_chartHash.remove(qchart); | |
521 |
QChart* |
|
506 | QChart *newChart = chart->createChart(m_dataTable); | |
522 | m_baseLayout->addItem(newChart, index / 3, index % 3); |
|
507 | m_baseLayout->addItem(newChart, index / 3, index % 3); | |
523 | m_chartHash[newChart] = index; |
|
508 | m_chartHash[newChart] = index; | |
524 | delete qchart; |
|
509 | delete qchart; | |
@@ -527,46 +512,41 void Window::handleMenu(QChart* qchart) | |||||
527 |
|
512 | |||
528 | } |
|
513 | } | |
529 |
|
514 | |||
530 |
QMenu* |
|
515 | QMenu *Window::createMenu() | |
531 | { |
|
516 | { | |
532 | Charts::ChartList list = Charts::chartList(); |
|
517 | Charts::ChartList list = Charts::chartList(); | |
533 | QMultiMap<QString, Chart*> categoryMap; |
|
518 | QMultiMap<QString, Chart *> categoryMap; | |
534 |
|
519 | |||
535 |
QMenu* |
|
520 | QMenu *result = new QMenu(this); | |
536 |
|
521 | |||
537 |
foreach(Chart* |
|
522 | foreach (Chart *chart, list) | |
538 | categoryMap.insertMulti(chart->category(), chart); |
|
523 | categoryMap.insertMulti(chart->category(), chart); | |
539 | } |
|
|||
540 |
|
524 | |||
541 |
foreach(const QString& |
|
525 | foreach (const QString &category, categoryMap.uniqueKeys()) { | |
542 |
QMenu* |
|
526 | QMenu *menu(0); | |
543 | QMultiMap<QString, Chart*> subCategoryMap; |
|
527 | QMultiMap<QString, Chart *> subCategoryMap; | |
544 | if (category.isEmpty()) { |
|
528 | if (category.isEmpty()) { | |
545 | menu = result; |
|
529 | menu = result; | |
546 | } |
|
530 | } else { | |
547 | else { |
|
|||
548 | menu = new QMenu(category, this); |
|
531 | menu = new QMenu(category, this); | |
549 | result->addMenu(menu); |
|
532 | result->addMenu(menu); | |
550 | } |
|
533 | } | |
551 |
|
534 | |||
552 |
foreach(Chart* |
|
535 | foreach (Chart *chart, categoryMap.values(category)) | |
553 | subCategoryMap.insert(chart->subCategory(), chart); |
|
536 | subCategoryMap.insert(chart->subCategory(), chart); | |
554 | } |
|
|||
555 |
|
537 | |||
556 |
foreach(const QString& |
|
538 | foreach (const QString &subCategory, subCategoryMap.uniqueKeys()) { | |
557 |
QMenu* |
|
539 | QMenu *subMenu(0); | |
558 | if (subCategory.isEmpty()) { |
|
540 | if (subCategory.isEmpty()) { | |
559 | subMenu = menu; |
|
541 | subMenu = menu; | |
560 | } |
|
542 | } else { | |
561 | else { |
|
|||
562 | subMenu = new QMenu(subCategory, this); |
|
543 | subMenu = new QMenu(subCategory, this); | |
563 | menu->addMenu(subMenu); |
|
544 | menu->addMenu(subMenu); | |
564 | } |
|
545 | } | |
565 |
|
546 | |||
566 |
foreach(Chart* |
|
547 | foreach(Chart *chart, subCategoryMap.values(subCategory)) { | |
567 |
|
||||
568 | createMenuAction(subMenu, QIcon(), chart->name(), |
|
548 | createMenuAction(subMenu, QIcon(), chart->name(), | |
569 | qVariantFromValue((void *) chart)); |
|
549 | qVariantFromValue((void *) chart)); | |
570 | } |
|
550 | } | |
571 | } |
|
551 | } | |
572 | } |
|
552 | } | |
@@ -574,8 +554,8 QMenu* Window::createMenu() | |||||
574 | return result; |
|
554 | return result; | |
575 | } |
|
555 | } | |
576 |
|
556 | |||
577 |
QAction* |
|
557 | QAction *Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, | |
578 | const QVariant &data) |
|
558 | const QVariant &data) | |
579 | { |
|
559 | { | |
580 | QAction *action = menu->addAction(icon, text); |
|
560 | QAction *action = menu->addAction(icon, text); | |
581 | action->setCheckable(false); |
|
561 | action->setCheckable(false); | |
@@ -585,7 +565,7 QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString | |||||
585 |
|
565 | |||
586 | void Window::handleGeometryChanged() |
|
566 | void Window::handleGeometryChanged() | |
587 | { |
|
567 | { | |
588 | QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize); |
|
568 | QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize); | |
589 | m_view->scene()->setSceneRect(0, 0, this->width(), this->height()); |
|
569 | m_view->scene()->setSceneRect(0, 0, this->width(), this->height()); | |
590 | m_view->setMinimumSize(size.toSize()); |
|
570 | m_view->setMinimumSize(size.toSize()); | |
591 | } |
|
571 | } |
@@ -44,7 +44,7 QTCOMMERCIALCHART_USE_NAMESPACE | |||||
44 | class Window: public QMainWindow |
|
44 | class Window: public QMainWindow | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | enum State{ NoState = 0, ZoomState, ScrollState}; |
|
47 | enum State { NoState = 0, ZoomState, ScrollState}; | |
48 | public: |
|
48 | public: | |
49 | explicit Window(QWidget *parent = 0); |
|
49 | explicit Window(QWidget *parent = 0); | |
50 | ~Window(); |
|
50 | ~Window(); | |
@@ -53,10 +53,10 private Q_SLOTS: | |||||
53 | void updateUI(); |
|
53 | void updateUI(); | |
54 | void handleGeometryChanged(); |
|
54 | void handleGeometryChanged(); | |
55 | private: |
|
55 | private: | |
56 |
QComboBox* |
|
56 | QComboBox *createThemeBox(); | |
57 |
QComboBox* |
|
57 | QComboBox *createAnimationBox(); | |
58 |
QComboBox* |
|
58 | QComboBox *createLegendBox(); | |
59 |
QComboBox* |
|
59 | QComboBox *createTempleteBox(); | |
60 | void connectSignals(); |
|
60 | void connectSignals(); | |
61 | void createProxyWidgets(); |
|
61 | void createProxyWidgets(); | |
62 | void comboBoxFocused(QComboBox *combox); |
|
62 | void comboBoxFocused(QComboBox *combox); | |
@@ -66,9 +66,9 private: | |||||
66 | inline void checkTheme(); |
|
66 | inline void checkTheme(); | |
67 | inline void checkState(); |
|
67 | inline void checkState(); | |
68 | inline void checkTemplate(); |
|
68 | inline void checkTemplate(); | |
69 |
QMenu* |
|
69 | QMenu *createMenu(); | |
70 |
void handleMenu(QChart * |
|
70 | void handleMenu(QChart *chart); | |
71 |
QAction* |
|
71 | QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data); | |
72 |
|
72 | |||
73 | protected: |
|
73 | protected: | |
74 | void mousePressEvent(QMouseEvent *event); |
|
74 | void mousePressEvent(QMouseEvent *event); | |
@@ -79,10 +79,10 private: | |||||
79 | int m_listCount; |
|
79 | int m_listCount; | |
80 | int m_valueMax; |
|
80 | int m_valueMax; | |
81 | int m_valueCount; |
|
81 | int m_valueCount; | |
82 |
QGraphicsScene* |
|
82 | QGraphicsScene *m_scene; | |
83 |
View* |
|
83 | View *m_view; | |
84 | QHash<QString, QGraphicsProxyWidget*> m_widgetHash; |
|
84 | QHash<QString, QGraphicsProxyWidget *> m_widgetHash; | |
85 | QHash<QChart*, int> m_chartHash; |
|
85 | QHash<QChart *, int> m_chartHash; | |
86 | DataTable m_dataTable; |
|
86 | DataTable m_dataTable; | |
87 |
|
87 | |||
88 | QGraphicsWidget *m_form; |
|
88 | QGraphicsWidget *m_form; | |
@@ -95,9 +95,9 private: | |||||
95 | QCheckBox *m_zoomCheckBox; |
|
95 | QCheckBox *m_zoomCheckBox; | |
96 | QCheckBox *m_scrollCheckBox; |
|
96 | QCheckBox *m_scrollCheckBox; | |
97 | QPoint m_origin; |
|
97 | QPoint m_origin; | |
98 |
QGraphicsRectItem* |
|
98 | QGraphicsRectItem *m_rubberBand; | |
99 |
QGraphicsGridLayout* |
|
99 | QGraphicsGridLayout *m_baseLayout; | |
100 |
QMenu* |
|
100 | QMenu *m_menu; | |
101 | State m_state; |
|
101 | State m_state; | |
102 | State m_currentState; |
|
102 | State m_currentState; | |
103 | int m_template; |
|
103 | int m_template; | |
@@ -108,17 +108,16 private: | |||||
108 | class ComboBox: public QComboBox |
|
108 | class ComboBox: public QComboBox | |
109 | { |
|
109 | { | |
110 | public: |
|
110 | public: | |
111 |
ComboBox(Window* |
|
111 | ComboBox(Window *window, QWidget *parent = 0): QComboBox(parent), m_window(window) | |
112 | {} |
|
112 | {} | |
113 |
|
113 | |||
114 | protected: |
|
114 | protected: | |
115 | void focusInEvent(QFocusEvent *e) |
|
115 | void focusInEvent(QFocusEvent *e) { | |
116 | { |
|
|||
117 | QComboBox::focusInEvent(e); |
|
116 | QComboBox::focusInEvent(e); | |
118 | m_window->comboBoxFocused(this); |
|
117 | m_window->comboBoxFocused(this); | |
119 | } |
|
118 | } | |
120 | private: |
|
119 | private: | |
121 |
Window* |
|
120 | Window *m_window; | |
122 | }; |
|
121 | }; | |
123 |
|
122 | |||
124 | #endif |
|
123 | #endif |
@@ -46,7 +46,7 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags): | |||||
46 |
|
46 | |||
47 | addSeries(m_series); |
|
47 | addSeries(m_series); | |
48 | createDefaultAxes(); |
|
48 | createDefaultAxes(); | |
49 | setAxisX(m_axis,m_series); |
|
49 | setAxisX(m_axis, m_series); | |
50 | m_axis->setTickCount(5); |
|
50 | m_axis->setTickCount(5); | |
51 | axisX()->setRange(0, 10); |
|
51 | axisX()->setRange(0, 10); | |
52 | axisY()->setRange(-5, 10); |
|
52 | axisY()->setRange(-5, 10); | |
@@ -61,11 +61,12 Chart::~Chart() | |||||
61 |
|
61 | |||
62 | void Chart::handleTimeout() |
|
62 | void Chart::handleTimeout() | |
63 | { |
|
63 | { | |
64 | qreal x = plotArea().width()/m_axis->tickCount(); |
|
64 | qreal x = plotArea().width() / m_axis->tickCount(); | |
65 | qreal y =(m_axis->max() - m_axis->min())/m_axis->tickCount(); |
|
65 | qreal y = (m_axis->max() - m_axis->min()) / m_axis->tickCount(); | |
66 | m_x += y; |
|
66 | m_x += y; | |
67 | m_y = qrand() % 5 - 2.5; |
|
67 | m_y = qrand() % 5 - 2.5; | |
68 | m_series->append(m_x, m_y); |
|
68 | m_series->append(m_x, m_y); | |
69 | scroll(x,0); |
|
69 | scroll(x, 0); | |
70 |
if(m_x==100) |
|
70 | if (m_x == 100) | |
|
71 | m_timer.stop(); | |||
71 | } |
|
72 | } |
@@ -44,9 +44,9 public slots: | |||||
44 |
|
44 | |||
45 | private: |
|
45 | private: | |
46 | QTimer m_timer; |
|
46 | QTimer m_timer; | |
47 |
QSplineSeries* |
|
47 | QSplineSeries *m_series; | |
48 | QStringList m_titles; |
|
48 | QStringList m_titles; | |
49 |
QValueAxis* |
|
49 | QValueAxis *m_axis; | |
50 | qreal m_step; |
|
50 | qreal m_step; | |
51 | qreal m_x; |
|
51 | qreal m_x; | |
52 | qreal m_y; |
|
52 | qreal m_y; |
@@ -25,6 +25,5 int main(int argc, char *argv[]) | |||||
25 | QApplication a(argc, argv); |
|
25 | QApplication a(argc, argv); | |
26 | Widget w; |
|
26 | Widget w; | |
27 | w.show(); |
|
27 | w.show(); | |
28 |
|
||||
29 | return a.exec(); |
|
28 | return a.exec(); | |
30 | } |
|
29 | } |
@@ -31,14 +31,14 QTCOMMERCIALCHART_USE_NAMESPACE | |||||
31 |
|
31 | |||
32 | Widget::Widget(QWidget *parent) |
|
32 | Widget::Widget(QWidget *parent) | |
33 | : QWidget(parent) |
|
33 | : QWidget(parent) | |
34 | { |
|
34 | { | |
35 | setMinimumSize(800, 600); |
|
35 | setMinimumSize(800, 600); | |
36 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
36 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
37 |
|
37 | |||
38 | //! [1] |
|
38 | //! [1] | |
39 | QChartView *chartView = new QChartView; |
|
39 | QChartView *chartView = new QChartView; | |
40 | chartView->setRenderHint(QPainter::Antialiasing); |
|
40 | chartView->setRenderHint(QPainter::Antialiasing); | |
41 |
QChart *chart = chartView->chart(); |
|
41 | QChart *chart = chartView->chart(); | |
42 | chart->legend()->setVisible(false); |
|
42 | chart->legend()->setVisible(false); | |
43 | chart->setTitle("Nested donuts demo"); |
|
43 | chart->setTitle("Nested donuts demo"); | |
44 | chart->setAnimationOptions(QChart::AllAnimations); |
|
44 | chart->setAnimationOptions(QChart::AllAnimations); | |
@@ -72,7 +72,7 Widget::Widget(QWidget *parent) | |||||
72 |
|
72 | |||
73 | // create main layout |
|
73 | // create main layout | |
74 | //! [4] |
|
74 | //! [4] | |
75 |
QGridLayout* |
|
75 | QGridLayout *mainLayout = new QGridLayout; | |
76 | mainLayout->addWidget(chartView, 1, 1); |
|
76 | mainLayout->addWidget(chartView, 1, 1); | |
77 | setLayout(mainLayout); |
|
77 | setLayout(mainLayout); | |
78 | //! [4] |
|
78 | //! [4] | |
@@ -86,10 +86,10 Widget::Widget(QWidget *parent) | |||||
86 |
|
86 | |||
87 | Widget::~Widget() |
|
87 | Widget::~Widget() | |
88 | { |
|
88 | { | |
89 |
|
89 | |||
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 |
|
|
92 | //! [6] | |
93 | void Widget::updateRotation() |
|
93 | void Widget::updateRotation() | |
94 | { |
|
94 | { | |
95 | for (int i = 0; i < m_donuts.count(); i++) { |
|
95 | for (int i = 0; i < m_donuts.count(); i++) { | |
@@ -99,9 +99,9 void Widget::updateRotation() | |||||
99 | donut->setPieEndAngle(donut->pieEndAngle() + phaseShift); |
|
99 | donut->setPieEndAngle(donut->pieEndAngle() + phaseShift); | |
100 | } |
|
100 | } | |
101 | } |
|
101 | } | |
102 |
|
|
102 | //! [6] | |
103 |
|
103 | |||
104 |
|
|
104 | //! [7] | |
105 | void Widget::explodeSlice(bool exploded) |
|
105 | void Widget::explodeSlice(bool exploded) | |
106 | { |
|
106 | { | |
107 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
107 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); | |
@@ -125,4 +125,4 void Widget::explodeSlice(bool exploded) | |||||
125 | } |
|
125 | } | |
126 | slice->setExploded(exploded); |
|
126 | slice->setExploded(exploded); | |
127 | } |
|
127 | } | |
128 |
|
|
128 | //! [7] |
@@ -30,7 +30,7 QTCOMMERCIALCHART_USE_NAMESPACE | |||||
30 | class Widget : public QWidget |
|
30 | class Widget : public QWidget | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | Widget(QWidget *parent = 0); |
|
35 | Widget(QWidget *parent = 0); | |
36 | ~Widget(); |
|
36 | ~Widget(); |
@@ -24,7 +24,7 | |||||
24 | #include <QColorDialog> |
|
24 | #include <QColorDialog> | |
25 |
|
25 | |||
26 | BrushTool::BrushTool(QString title, QWidget *parent) |
|
26 | BrushTool::BrushTool(QString title, QWidget *parent) | |
27 | :QWidget(parent) |
|
27 | : QWidget(parent) | |
28 | { |
|
28 | { | |
29 | setWindowTitle(title); |
|
29 | setWindowTitle(title); | |
30 | setWindowFlags(Qt::Tool); |
|
30 | setWindowFlags(Qt::Tool); |
@@ -23,7 +23,7 | |||||
23 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
23 | QTCOMMERCIALCHART_USE_NAMESPACE | |
24 |
|
24 | |||
25 | CustomSlice::CustomSlice(QString label, qreal value) |
|
25 | CustomSlice::CustomSlice(QString label, qreal value) | |
26 | :QPieSlice(label, value) |
|
26 | : QPieSlice(label, value) | |
27 | { |
|
27 | { | |
28 | connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool))); |
|
28 | connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool))); | |
29 | } |
|
29 | } |
@@ -34,8 +34,8 | |||||
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
35 | QTCOMMERCIALCHART_USE_NAMESPACE | |
36 |
|
36 | |||
37 |
MainWidget::MainWidget(QWidget* |
|
37 | MainWidget::MainWidget(QWidget *parent) | |
38 | :QWidget(parent), |
|
38 | : QWidget(parent), | |
39 | m_slice(0) |
|
39 | m_slice(0) | |
40 | { |
|
40 | { | |
41 | // create chart |
|
41 | // create chart | |
@@ -71,18 +71,18 MainWidget::MainWidget(QWidget* parent) | |||||
71 |
|
71 | |||
72 | m_legendCheckBox = new QCheckBox(); |
|
72 | m_legendCheckBox = new QCheckBox(); | |
73 |
|
73 | |||
74 |
QFormLayout* |
|
74 | QFormLayout *chartSettingsLayout = new QFormLayout(); | |
75 | chartSettingsLayout->addRow("Theme", m_themeComboBox); |
|
75 | chartSettingsLayout->addRow("Theme", m_themeComboBox); | |
76 | chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); |
|
76 | chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); | |
77 | chartSettingsLayout->addRow("Animations", m_animationsCheckBox); |
|
77 | chartSettingsLayout->addRow("Animations", m_animationsCheckBox); | |
78 | chartSettingsLayout->addRow("Legend", m_legendCheckBox); |
|
78 | chartSettingsLayout->addRow("Legend", m_legendCheckBox); | |
79 |
QGroupBox* |
|
79 | QGroupBox *chartSettings = new QGroupBox("Chart"); | |
80 | chartSettings->setLayout(chartSettingsLayout); |
|
80 | chartSettings->setLayout(chartSettingsLayout); | |
81 |
|
81 | |||
82 |
connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this |
|
82 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateChartSettings())); | |
83 |
connect(m_aaCheckBox, SIGNAL(toggled(bool)), this |
|
83 | connect(m_aaCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateChartSettings())); | |
84 |
connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this |
|
84 | connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateChartSettings())); | |
85 |
connect(m_legendCheckBox, SIGNAL(toggled(bool)), this |
|
85 | connect(m_legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateChartSettings())); | |
86 |
|
86 | |||
87 | // series settings |
|
87 | // series settings | |
88 | m_hPosition = new QDoubleSpinBox(); |
|
88 | m_hPosition = new QDoubleSpinBox(); | |
@@ -125,7 +125,7 MainWidget::MainWidget(QWidget* parent) | |||||
125 | QPushButton *insertSlice = new QPushButton("Insert slice"); |
|
125 | QPushButton *insertSlice = new QPushButton("Insert slice"); | |
126 | QPushButton *removeSlice = new QPushButton("Remove selected slice"); |
|
126 | QPushButton *removeSlice = new QPushButton("Remove selected slice"); | |
127 |
|
127 | |||
128 |
QFormLayout* |
|
128 | QFormLayout *seriesSettingsLayout = new QFormLayout(); | |
129 | seriesSettingsLayout->addRow("Horizontal position", m_hPosition); |
|
129 | seriesSettingsLayout->addRow("Horizontal position", m_hPosition); | |
130 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); |
|
130 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); | |
131 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); |
|
131 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); | |
@@ -135,7 +135,7 MainWidget::MainWidget(QWidget* parent) | |||||
135 | seriesSettingsLayout->addRow(appendSlice); |
|
135 | seriesSettingsLayout->addRow(appendSlice); | |
136 | seriesSettingsLayout->addRow(insertSlice); |
|
136 | seriesSettingsLayout->addRow(insertSlice); | |
137 | seriesSettingsLayout->addRow(removeSlice); |
|
137 | seriesSettingsLayout->addRow(removeSlice); | |
138 |
QGroupBox* |
|
138 | QGroupBox *seriesSettings = new QGroupBox("Series"); | |
139 | seriesSettings->setLayout(seriesSettingsLayout); |
|
139 | seriesSettings->setLayout(seriesSettingsLayout); | |
140 |
|
140 | |||
141 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
141 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
@@ -172,7 +172,7 MainWidget::MainWidget(QWidget* parent) | |||||
172 | m_labelPosition->addItem("Inside tangential", QPieSlice::LabelInsideTangential); |
|
172 | m_labelPosition->addItem("Inside tangential", QPieSlice::LabelInsideTangential); | |
173 | m_labelPosition->addItem("Inside normal", QPieSlice::LabelInsideNormal); |
|
173 | m_labelPosition->addItem("Inside normal", QPieSlice::LabelInsideNormal); | |
174 |
|
174 | |||
175 |
QFormLayout* |
|
175 | QFormLayout *sliceSettingsLayout = new QFormLayout(); | |
176 | sliceSettingsLayout->addRow("Label", m_sliceName); |
|
176 | sliceSettingsLayout->addRow("Label", m_sliceName); | |
177 | sliceSettingsLayout->addRow("Value", m_sliceValue); |
|
177 | sliceSettingsLayout->addRow("Value", m_sliceValue); | |
178 | sliceSettingsLayout->addRow("Pen", m_pen); |
|
178 | sliceSettingsLayout->addRow("Pen", m_pen); | |
@@ -184,7 +184,7 MainWidget::MainWidget(QWidget* parent) | |||||
184 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); |
|
184 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); | |
185 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); |
|
185 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); | |
186 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); |
|
186 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); | |
187 |
QGroupBox* |
|
187 | QGroupBox *sliceSettings = new QGroupBox("Selected slice"); | |
188 | sliceSettings->setLayout(sliceSettingsLayout); |
|
188 | sliceSettings->setLayout(sliceSettingsLayout); | |
189 |
|
189 | |||
190 | connect(m_sliceName, SIGNAL(textChanged(QString)), this, SLOT(updateSliceSettings())); |
|
190 | connect(m_sliceName, SIGNAL(textChanged(QString)), this, SLOT(updateSliceSettings())); | |
@@ -213,7 +213,7 MainWidget::MainWidget(QWidget* parent) | |||||
213 | settingsLayout->addWidget(sliceSettings); |
|
213 | settingsLayout->addWidget(sliceSettings); | |
214 | settingsLayout->addStretch(); |
|
214 | settingsLayout->addStretch(); | |
215 |
|
215 | |||
216 |
QGridLayout* |
|
216 | QGridLayout *baseLayout = new QGridLayout(); | |
217 | baseLayout->addLayout(settingsLayout, 0, 0); |
|
217 | baseLayout->addLayout(settingsLayout, 0, 0); | |
218 | baseLayout->addWidget(m_chartView, 0, 1); |
|
218 | baseLayout->addWidget(m_chartView, 0, 1); | |
219 | setLayout(baseLayout); |
|
219 | setLayout(baseLayout); | |
@@ -272,9 +272,9 void MainWidget::updateSliceSettings() | |||||
272 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); |
|
272 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 |
void MainWidget::handleSliceClicked(QPieSlice* |
|
275 | void MainWidget::handleSliceClicked(QPieSlice *slice) | |
276 | { |
|
276 | { | |
277 | m_slice = static_cast<CustomSlice*>(slice); |
|
277 | m_slice = static_cast<CustomSlice *>(slice); | |
278 |
|
278 | |||
279 | // name |
|
279 | // name | |
280 | m_sliceName->blockSignals(true); |
|
280 | m_sliceName->blockSignals(true); | |
@@ -332,7 +332,7 void MainWidget::showFontDialog() | |||||
332 |
|
332 | |||
333 | void MainWidget::appendSlice() |
|
333 | void MainWidget::appendSlice() | |
334 | { |
|
334 | { | |
335 | *m_series << new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0); |
|
335 | *m_series << new CustomSlice("Slice " + QString::number(m_series->count() + 1), 10.0); | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | void MainWidget::insertSlice() |
|
338 | void MainWidget::insertSlice() | |
@@ -342,7 +342,7 void MainWidget::insertSlice() | |||||
342 |
|
342 | |||
343 | int i = m_series->slices().indexOf(m_slice); |
|
343 | int i = m_series->slices().indexOf(m_slice); | |
344 |
|
344 | |||
345 | m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0)); |
|
345 | m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count() + 1), 10.0)); | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | void MainWidget::removeSlice() |
|
348 | void MainWidget::removeSlice() |
@@ -45,13 +45,13 class MainWidget : public QWidget | |||||
45 | Q_OBJECT |
|
45 | Q_OBJECT | |
46 |
|
46 | |||
47 | public: |
|
47 | public: | |
48 |
explicit MainWidget(QWidget* |
|
48 | explicit MainWidget(QWidget *parent = 0); | |
49 |
|
49 | |||
50 | public Q_SLOTS: |
|
50 | public Q_SLOTS: | |
51 | void updateChartSettings(); |
|
51 | void updateChartSettings(); | |
52 | void updateSerieSettings(); |
|
52 | void updateSerieSettings(); | |
53 | void updateSliceSettings(); |
|
53 | void updateSliceSettings(); | |
54 |
void handleSliceClicked(QPieSlice* |
|
54 | void handleSliceClicked(QPieSlice *slice); | |
55 | void showFontDialog(); |
|
55 | void showFontDialog(); | |
56 | void appendSlice(); |
|
56 | void appendSlice(); | |
57 | void insertSlice(); |
|
57 | void insertSlice(); | |
@@ -63,23 +63,23 private: | |||||
63 | QCheckBox *m_animationsCheckBox; |
|
63 | QCheckBox *m_animationsCheckBox; | |
64 | QCheckBox *m_legendCheckBox; |
|
64 | QCheckBox *m_legendCheckBox; | |
65 |
|
65 | |||
66 |
QChartView* |
|
66 | QChartView *m_chartView; | |
67 |
QPieSeries* |
|
67 | QPieSeries *m_series; | |
68 |
CustomSlice* |
|
68 | CustomSlice *m_slice; | |
69 |
|
69 | |||
70 |
QDoubleSpinBox* |
|
70 | QDoubleSpinBox *m_hPosition; | |
71 |
QDoubleSpinBox* |
|
71 | QDoubleSpinBox *m_vPosition; | |
72 |
QDoubleSpinBox* |
|
72 | QDoubleSpinBox *m_sizeFactor; | |
73 |
QDoubleSpinBox* |
|
73 | QDoubleSpinBox *m_startAngle; | |
74 |
QDoubleSpinBox* |
|
74 | QDoubleSpinBox *m_endAngle; | |
75 |
QDoubleSpinBox* |
|
75 | QDoubleSpinBox *m_holeSize; | |
76 |
|
76 | |||
77 |
QLineEdit* |
|
77 | QLineEdit *m_sliceName; | |
78 |
QDoubleSpinBox* |
|
78 | QDoubleSpinBox *m_sliceValue; | |
79 |
QCheckBox* |
|
79 | QCheckBox *m_sliceLabelVisible; | |
80 |
QDoubleSpinBox* |
|
80 | QDoubleSpinBox *m_sliceLabelArmFactor; | |
81 |
QCheckBox* |
|
81 | QCheckBox *m_sliceExploded; | |
82 |
QDoubleSpinBox* |
|
82 | QDoubleSpinBox *m_sliceExplodedFactor; | |
83 | QPushButton *m_brush; |
|
83 | QPushButton *m_brush; | |
84 | BrushTool *m_brushTool; |
|
84 | BrushTool *m_brushTool; | |
85 | QPushButton *m_pen; |
|
85 | QPushButton *m_pen; |
@@ -26,7 +26,7 | |||||
26 | #include <QColorDialog> |
|
26 | #include <QColorDialog> | |
27 |
|
27 | |||
28 | PenTool::PenTool(QString title, QWidget *parent) |
|
28 | PenTool::PenTool(QString title, QWidget *parent) | |
29 | :QWidget(parent) |
|
29 | : QWidget(parent) | |
30 | { |
|
30 | { | |
31 | setWindowTitle(title); |
|
31 | setWindowTitle(title); | |
32 | setWindowFlags(Qt::Tool); |
|
32 | setWindowFlags(Qt::Tool); |
@@ -1,40 +1,40 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #ifdef QT5_QUICK_1 |
|
22 | #ifdef QT5_QUICK_1 | |
23 | #include <QtQuick1/QDeclarativeEngine> |
|
23 | #include <QtQuick1/QDeclarativeEngine> | |
24 | #else |
|
24 | #else | |
25 | #include <QtDeclarative/QDeclarativeEngine> |
|
25 | #include <QtDeclarative/QDeclarativeEngine> | |
26 | #endif |
|
26 | #endif | |
27 | #include "qmlapplicationviewer.h" |
|
27 | #include "qmlapplicationviewer.h" | |
28 |
|
28 | |||
29 | Q_DECL_EXPORT int main(int argc, char *argv[]) |
|
29 | Q_DECL_EXPORT int main(int argc, char *argv[]) | |
30 | { |
|
30 | { | |
31 | QScopedPointer<QApplication> app(createApplication(argc, argv)); |
|
31 | QScopedPointer<QApplication> app(createApplication(argc, argv)); | |
32 | QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create()); |
|
32 | QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create()); | |
33 |
|
33 | |||
34 | //viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); |
|
34 | //viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); | |
35 | viewer->setSource(QUrl("qrc:/qml/qmlcustomlegend/loader.qml")); |
|
35 | viewer->setSource(QUrl("qrc:/qml/qmlcustomlegend/loader.qml")); | |
36 | viewer->setRenderHint(QPainter::Antialiasing, true); |
|
36 | viewer->setRenderHint(QPainter::Antialiasing, true); | |
37 | viewer->showExpanded(); |
|
37 | viewer->showExpanded(); | |
38 |
|
38 | |||
39 | return app->exec(); |
|
39 | return app->exec(); | |
40 | } |
|
40 | } |
1 | NO CONTENT: modified file chmod 100755 => 100644 |
|
NO CONTENT: modified file chmod 100755 => 100644 |
1 | NO CONTENT: modified file chmod 100755 => 100644 |
|
NO CONTENT: modified file chmod 100755 => 100644 |
@@ -31,13 +31,13 CustomTableModel::CustomTableModel(QObject *parent) : | |||||
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 |
int CustomTableModel::rowCount(const QModelIndex & |
|
34 | int CustomTableModel::rowCount(const QModelIndex &parent) const | |
35 | { |
|
35 | { | |
36 | Q_UNUSED(parent) |
|
36 | Q_UNUSED(parent) | |
37 | return m_data.count(); |
|
37 | return m_data.count(); | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 |
int CustomTableModel::columnCount(const QModelIndex & |
|
40 | int CustomTableModel::columnCount(const QModelIndex &parent) const | |
41 | { |
|
41 | { | |
42 | Q_UNUSED(parent) |
|
42 | Q_UNUSED(parent) | |
43 | return m_columnCount; |
|
43 | return m_columnCount; | |
@@ -128,7 +128,7 bool CustomTableModel::removeRows(int row, int count, const QModelIndex &parent) | |||||
128 | return removed; |
|
128 | return removed; | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 |
Qt::ItemFlags CustomTableModel::flags |
|
131 | Qt::ItemFlags CustomTableModel::flags(const QModelIndex &index) const | |
132 | { |
|
132 | { | |
133 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; |
|
133 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; | |
134 | } |
|
134 | } |
@@ -33,17 +33,17 class CustomTableModel : public QAbstractTableModel | |||||
33 | public: |
|
33 | public: | |
34 | explicit CustomTableModel(QObject *parent = 0); |
|
34 | explicit CustomTableModel(QObject *parent = 0); | |
35 |
|
35 | |||
36 |
int rowCount |
|
36 | int rowCount(const QModelIndex &parent = QModelIndex()) const; | |
37 |
int columnCount |
|
37 | int columnCount(const QModelIndex &parent = QModelIndex()) const; | |
38 |
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole |
|
38 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; | |
39 | bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole); |
|
39 | bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole); | |
40 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
40 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | |
41 |
bool setData |
|
41 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); | |
42 |
Qt::ItemFlags flags |
|
42 | Qt::ItemFlags flags(const QModelIndex &index) const; | |
43 | void insertColumn(int column, const QModelIndex &parent = QModelIndex()); |
|
43 | void insertColumn(int column, const QModelIndex &parent = QModelIndex()); | |
44 | void insertRow(int row, const QModelIndex &parent = QModelIndex()); |
|
44 | void insertRow(int row, const QModelIndex &parent = QModelIndex()); | |
45 |
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex & |
|
45 | Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); | |
46 |
Q_INVOKABLE bool removeRow |
|
46 | Q_INVOKABLE bool removeRow(int row, const QModelIndex &parent = QModelIndex()); | |
47 | Q_INVOKABLE QVariant at(int row, int column); |
|
47 | Q_INVOKABLE QVariant at(int row, int column); | |
48 |
|
48 | |||
49 | private: |
|
49 | private: |
@@ -33,9 +33,9 class DataSource : public QObject | |||||
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | public: |
|
34 | public: | |
35 | explicit DataSource(QDeclarativeView *appViewer, QObject *parent = 0); |
|
35 | explicit DataSource(QDeclarativeView *appViewer, QObject *parent = 0); | |
36 |
|
36 | |||
37 | signals: |
|
37 | signals: | |
38 |
|
38 | |||
39 | public slots: |
|
39 | public slots: | |
40 | void generateData(int type, int rowCount, int colCount); |
|
40 | void generateData(int type, int rowCount, int colCount); | |
41 | void update(QAbstractSeries *series); |
|
41 | void update(QAbstractSeries *series); |
General Comments 0
You need to be logged in to leave comments.
Login now