@@ -0,0 +1,33 | |||
|
1 | #include "qhpiemodelmapper.h" | |
|
2 | ||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
4 | ||
|
5 | QHPieModelMapper::QHPieModelMapper(QObject *parent) : | |
|
6 | QPieModelMapper(parent) | |
|
7 | { | |
|
8 | QPieModelMapper::setOrientation(Qt::Horizontal); | |
|
9 | } | |
|
10 | ||
|
11 | int QHPieModelMapper::valuesRow() const | |
|
12 | { | |
|
13 | return QPieModelMapper::valuesIndex(); | |
|
14 | } | |
|
15 | ||
|
16 | void QHPieModelMapper::setValuesRow(int valuesRow) | |
|
17 | { | |
|
18 | QPieModelMapper::setValuesIndex(valuesRow); | |
|
19 | } | |
|
20 | ||
|
21 | int QHPieModelMapper::labelsRow() const | |
|
22 | { | |
|
23 | return QPieModelMapper::labelsIndex(); | |
|
24 | } | |
|
25 | ||
|
26 | void QHPieModelMapper::setLabelsRow(int labelsRow) | |
|
27 | { | |
|
28 | QPieModelMapper::setLabelsIndex(labelsRow); | |
|
29 | } | |
|
30 | ||
|
31 | #include "moc_qhpiemodelmapper.cpp" | |
|
32 | ||
|
33 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,27 | |||
|
1 | #ifndef QHPIEMODELMAPPER_H | |
|
2 | #define QHPIEMODELMAPPER_H | |
|
3 | ||
|
4 | #include "qpiemodelmapper.h" | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
7 | ||
|
8 | class QTCOMMERCIALCHART_EXPORT QHPieModelMapper : public QPieModelMapper | |
|
9 | { | |
|
10 | Q_OBJECT | |
|
11 | Q_PROPERTY(int valuesRow READ valuesRow WRITE setValuesRow) | |
|
12 | Q_PROPERTY(int labelsRow READ labelsRow WRITE setLabelsRow) | |
|
13 | ||
|
14 | public: | |
|
15 | QHPieModelMapper(QObject *parent = 0); | |
|
16 | ||
|
17 | int valuesRow() const; | |
|
18 | void setValuesRow(int valuesRow); | |
|
19 | ||
|
20 | int labelsRow() const; | |
|
21 | void setLabelsRow(int labelsRow); | |
|
22 | ||
|
23 | }; | |
|
24 | ||
|
25 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
26 | ||
|
27 | #endif // QHPIEMODELMAPPER_H |
@@ -0,0 +1,34 | |||
|
1 | #include "qpiemodelmapper_p.h" | |
|
2 | #include "qvpiemodelmapper.h" | |
|
3 | ||
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
5 | ||
|
6 | QVPieModelMapper::QVPieModelMapper(QObject *parent) : | |
|
7 | QPieModelMapper(parent) | |
|
8 | { | |
|
9 | QPieModelMapper::setOrientation(Qt::Vertical); | |
|
10 | } | |
|
11 | ||
|
12 | int QVPieModelMapper::valuesColumn() const | |
|
13 | { | |
|
14 | return QPieModelMapper::valuesIndex(); | |
|
15 | } | |
|
16 | ||
|
17 | void QVPieModelMapper::setValuesColumn(int valuesColumn) | |
|
18 | { | |
|
19 | QPieModelMapper::setValuesIndex(valuesColumn); | |
|
20 | } | |
|
21 | ||
|
22 | int QVPieModelMapper::labelsColumn() const | |
|
23 | { | |
|
24 | return QPieModelMapper::labelsIndex(); | |
|
25 | } | |
|
26 | ||
|
27 | void QVPieModelMapper::setLabelsColumn(int labelsColumn) | |
|
28 | { | |
|
29 | QPieModelMapper::setLabelsIndex(labelsColumn); | |
|
30 | } | |
|
31 | ||
|
32 | #include "moc_qvpiemodelmapper.cpp" | |
|
33 | ||
|
34 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,26 | |||
|
1 | #ifndef QVPIEMODELMAPPER_H | |
|
2 | #define QVPIEMODELMAPPER_H | |
|
3 | ||
|
4 | #include "qpiemodelmapper.h" | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
7 | ||
|
8 | class QTCOMMERCIALCHART_EXPORT QVPieModelMapper : public QPieModelMapper | |
|
9 | { | |
|
10 | Q_OBJECT | |
|
11 | Q_PROPERTY(int valuesColumn READ valuesColumn WRITE setValuesColumn) | |
|
12 | Q_PROPERTY(int labelsColumn READ labelsColumn WRITE setLabelsColumn) | |
|
13 | ||
|
14 | public: | |
|
15 | explicit QVPieModelMapper(QObject *parent = 0); | |
|
16 | ||
|
17 | int valuesColumn() const; | |
|
18 | void setValuesColumn(int valuesColumn); | |
|
19 | ||
|
20 | int labelsColumn() const; | |
|
21 | void setLabelsColumn(int labelsColumn); | |
|
22 | }; | |
|
23 | ||
|
24 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
25 | ||
|
26 | #endif // QVPIEMODELMAPPER_H |
@@ -1,21 +1,25 | |||
|
1 | 1 | INCLUDEPATH += $$PWD |
|
2 | 2 | DEPENDPATH += $$PWD |
|
3 | 3 | |
|
4 | 4 | SOURCES += \ |
|
5 | 5 | $$PWD/qpieseries.cpp \ |
|
6 | 6 | $$PWD/piesliceitem.cpp \ |
|
7 | 7 | $$PWD/piechartitem.cpp \ |
|
8 | 8 | $$PWD/qpieslice.cpp \ |
|
9 | $$PWD/qpiemodelmapper.cpp | |
|
9 | $$PWD/qpiemodelmapper.cpp \ | |
|
10 | $$PWD/qvpiemodelmapper.cpp \ | |
|
11 | $$PWD/qhpiemodelmapper.cpp | |
|
10 | 12 | |
|
11 | 13 | PRIVATE_HEADERS += \ |
|
12 | 14 | $$PWD/pieslicedata_p.h \ |
|
13 | 15 | $$PWD/piechartitem_p.h \ |
|
14 | 16 | $$PWD/piesliceitem_p.h \ |
|
15 | 17 | $$PWD/qpieseries_p.h \ |
|
16 | 18 | $$PWD/qpiemodelmapper_p.h |
|
17 | 19 | |
|
18 | 20 | PUBLIC_HEADERS += \ |
|
19 | 21 | $$PWD/qpieseries.h \ |
|
20 | 22 | $$PWD/qpieslice.h \ |
|
21 | $$PWD/qpiemodelmapper.h | |
|
23 | $$PWD/qpiemodelmapper.h \ | |
|
24 | $$PWD/qvpiemodelmapper.h \ | |
|
25 | $$PWD/qhpiemodelmapper.h |
@@ -1,57 +1,76 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
1 | 21 | #ifndef QPIEMODELMAPPER_H |
|
2 | 22 | #define QPIEMODELMAPPER_H |
|
3 | 23 | |
|
4 | 24 | #include "qchartglobal.h" |
|
5 | 25 | #include <QObject> |
|
6 | 26 | |
|
7 | 27 | class QAbstractItemModel; |
|
8 | 28 | |
|
9 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 30 | |
|
11 | 31 | class QPieModelMapperPrivate; |
|
12 | 32 | class QPieSeries; |
|
13 | 33 | |
|
14 | 34 | class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject |
|
15 | 35 | { |
|
16 | 36 | Q_OBJECT |
|
17 | Q_PROPERTY(int valuesIndex READ valuesIndex WRITE setValuesIndex) | |
|
18 | Q_PROPERTY(int labelsIndex READ labelsIndex WRITE setLabelsIndex) | |
|
19 | 37 | Q_PROPERTY(int first READ first WRITE setFirst) |
|
20 | 38 | Q_PROPERTY(int count READ count WRITE setCount) |
|
21 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) | |
|
22 | 39 | Q_ENUMS(Qt::Orientation) |
|
23 | 40 | |
|
24 | public: | |
|
41 | protected: | |
|
25 | 42 | QPieModelMapper(QObject *parent = 0); |
|
26 | 43 | |
|
44 | public: | |
|
27 | 45 | QAbstractItemModel* model() const; |
|
28 | 46 | void setModel(QAbstractItemModel *model); |
|
29 | 47 | |
|
30 | 48 | QPieSeries* series() const; |
|
31 | 49 | void setSeries(QPieSeries *series); |
|
32 | 50 | |
|
33 | 51 | int first() const; |
|
34 | 52 | void setFirst(int first); |
|
35 | 53 | |
|
36 | 54 | int count() const; |
|
37 | 55 | void setCount(int count); |
|
38 | 56 | |
|
39 | Qt::Orientation orientation() const; | |
|
40 | void setOrientation(Qt::Orientation orientation); | |
|
57 | void reset(); | |
|
41 | 58 | |
|
59 | protected: | |
|
42 | 60 | int valuesIndex() const; |
|
43 | 61 | void setValuesIndex(int valuesIndex); |
|
44 | 62 | |
|
45 | 63 | int labelsIndex() const; |
|
46 | 64 | void setLabelsIndex(int labelsIndex); |
|
47 | 65 | |
|
48 | void reset(); | |
|
66 | Qt::Orientation orientation() const; | |
|
67 | void setOrientation(Qt::Orientation orientation); | |
|
49 | 68 | |
|
50 | 69 | protected: |
|
51 | 70 | QPieModelMapperPrivate * const d_ptr; |
|
52 | 71 | Q_DECLARE_PRIVATE(QPieModelMapper) |
|
53 | 72 | }; |
|
54 | 73 | |
|
55 | 74 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | 75 | |
|
57 | 76 | #endif // QPIEMODELMAPPER_H |
@@ -1,519 +1,519 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "tablewidget.h" |
|
22 | 22 | #include <QGridLayout> |
|
23 | 23 | #include <QTableView> |
|
24 | 24 | #include <QChart> |
|
25 | 25 | #include <QStyledItemDelegate> |
|
26 | 26 | #include <QLineSeries> |
|
27 | 27 | #include <QSplineSeries> |
|
28 | 28 | #include <QScatterSeries> |
|
29 | 29 | #include <QXYModelMapper> |
|
30 | 30 | #include "customtablemodel.h" |
|
31 | 31 | #include <QPieSeries> |
|
32 | #include <QPieModelMapper> | |
|
32 | #include <QVPieModelMapper> | |
|
33 | 33 | #include <QPieSlice> |
|
34 | 34 | #include <QAreaSeries> |
|
35 | 35 | #include <QBarSeries> |
|
36 | 36 | #include <QGroupedBarSeries> |
|
37 | 37 | #include <QBarSet> |
|
38 | 38 | #include <QBarModelMapper> |
|
39 | 39 | #include <QPushButton> |
|
40 | 40 | #include <QRadioButton> |
|
41 | 41 | #include <QLabel> |
|
42 | 42 | #include <QSpinBox> |
|
43 | 43 | #include <QTime> |
|
44 | 44 | #include <QHeaderView> |
|
45 | 45 | |
|
46 | 46 | TableWidget::TableWidget(QWidget *parent) |
|
47 | 47 | : QWidget(parent) |
|
48 | 48 | // specialPie(0) |
|
49 | 49 | { |
|
50 | 50 | setGeometry(1900, 100, 1000, 600); |
|
51 | 51 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
52 | 52 | // create simple model for storing data |
|
53 | 53 | // user's table data model |
|
54 | 54 | m_model = new CustomTableModel; |
|
55 | 55 | m_tableView = new QTableView; |
|
56 | 56 | m_tableView->setModel(m_model); |
|
57 | 57 | // m_tableView->setMinimumHeight(300); |
|
58 | 58 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
59 | 59 | m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
60 | 60 | |
|
61 | 61 | m_chart = new QChart; |
|
62 | 62 | m_chart->legend()->setVisible(true); |
|
63 | 63 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
64 | 64 | m_chartView = new QChartView(m_chart); |
|
65 | 65 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
66 | 66 | m_chartView->setMinimumSize(640, 480); |
|
67 | 67 | |
|
68 | 68 | // add, remove data buttons |
|
69 | 69 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
70 | 70 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
71 | 71 | |
|
72 | 72 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
73 | 73 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
74 | 74 | |
|
75 | 75 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
76 | 76 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
77 | 77 | |
|
78 | 78 | QPushButton* addColumnRightButton = new QPushButton("Add column to the right"); |
|
79 | 79 | connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight())); |
|
80 | 80 | |
|
81 | 81 | QPushButton* removeColumnButton = new QPushButton("Remove column"); |
|
82 | 82 | connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn())); |
|
83 | 83 | |
|
84 | 84 | QPushButton* specialPieButton = new QPushButton("Add slices from series"); |
|
85 | 85 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); |
|
86 | 86 | |
|
87 | 87 | QPushButton* specialPieButton2 = new QPushButton("Remove slices from series"); |
|
88 | 88 | connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2())); |
|
89 | 89 | |
|
90 | 90 | QPushButton* specialPieButton3 = new QPushButton("Remove slices from series"); |
|
91 | 91 | connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3())); |
|
92 | 92 | |
|
93 | 93 | |
|
94 | 94 | // QLabel *spinBoxLabel = new QLabel("Rows affected:"); |
|
95 | 95 | |
|
96 | 96 | // spin box for setting number of affected items (add, remove) |
|
97 | 97 | m_linesCountSpinBox = new QSpinBox; |
|
98 | 98 | m_linesCountSpinBox->setRange(1, 10); |
|
99 | 99 | m_linesCountSpinBox->setValue(1); |
|
100 | 100 | |
|
101 | 101 | // buttons layout |
|
102 | 102 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
103 | 103 | // buttonsLayout->addWidget(spinBoxLabel); |
|
104 | 104 | // buttonsLayout->addWidget(m_linesCountSpinBox); |
|
105 | 105 | // buttonsLayout->addWidget(addRowAboveButton); |
|
106 | 106 | buttonsLayout->addWidget(addRowBelowButton); |
|
107 | 107 | buttonsLayout->addWidget(removeRowButton); |
|
108 | 108 | // buttonsLayout->addWidget(addColumnRightButton); |
|
109 | 109 | // buttonsLayout->addWidget(removeColumnButton); |
|
110 | 110 | buttonsLayout->addWidget(specialPieButton); |
|
111 | 111 | buttonsLayout->addWidget(specialPieButton2); |
|
112 | 112 | buttonsLayout->addWidget(specialPieButton3); |
|
113 | 113 | buttonsLayout->addStretch(); |
|
114 | 114 | |
|
115 | 115 | // chart type radio buttons |
|
116 | 116 | m_lineRadioButton = new QRadioButton("Line"); |
|
117 | 117 | m_splineRadioButton = new QRadioButton("Spline"); |
|
118 | 118 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
119 | 119 | m_pieRadioButton = new QRadioButton("Pie"); |
|
120 | 120 | m_areaRadioButton = new QRadioButton("Area"); |
|
121 | 121 | m_barRadioButton = new QRadioButton("Bar"); |
|
122 | 122 | |
|
123 | 123 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
124 | 124 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
125 | 125 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
126 | 126 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
127 | 127 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
128 | 128 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
129 | 129 | m_lineRadioButton->setChecked(true); |
|
130 | 130 | |
|
131 | 131 | // radio buttons layout |
|
132 | 132 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
133 | 133 | radioLayout->addWidget(m_lineRadioButton); |
|
134 | 134 | radioLayout->addWidget(m_splineRadioButton); |
|
135 | 135 | // radioLayout->addWidget(m_scatterRadioButton); |
|
136 | 136 | radioLayout->addWidget(m_pieRadioButton); |
|
137 | 137 | // radioLayout->addWidget(m_areaRadioButton); |
|
138 | 138 | radioLayout->addWidget(m_barRadioButton); |
|
139 | 139 | radioLayout->addStretch(); |
|
140 | 140 | |
|
141 | 141 | // create main layout |
|
142 | 142 | QGridLayout* mainLayout = new QGridLayout; |
|
143 | 143 | mainLayout->addLayout(buttonsLayout, 2, 0); |
|
144 | 144 | mainLayout->addLayout(radioLayout, 3, 0); |
|
145 | 145 | mainLayout->addWidget(m_tableView, 1, 0); |
|
146 | 146 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); |
|
147 | 147 | setLayout(mainLayout); |
|
148 | 148 | m_lineRadioButton->setFocus(); |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | void TableWidget::addRowAbove() |
|
152 | 152 | { |
|
153 | 153 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
154 | 154 | |
|
155 | 155 | } |
|
156 | 156 | |
|
157 | 157 | void TableWidget::addRowBelow() |
|
158 | 158 | { |
|
159 | 159 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
160 | 160 | |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | 163 | void TableWidget::removeRow() |
|
164 | 164 | { |
|
165 | 165 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | void TableWidget::addColumnRight() |
|
169 | 169 | { |
|
170 | 170 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | void TableWidget::removeColumn() |
|
174 | 174 | { |
|
175 | 175 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | void TableWidget::updateChartType(bool toggle) |
|
179 | 179 | { |
|
180 | 180 | // this if is needed, so that the function is only called once. |
|
181 | 181 | // For the radioButton that was enabled. |
|
182 | 182 | if (toggle) { |
|
183 | 183 | // specialPie = 0; |
|
184 | 184 | m_chart->removeAllSeries(); |
|
185 | 185 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
186 | 186 | // m_chart->axisY()->setNiceNumbersEnabled(false); |
|
187 | 187 | |
|
188 | 188 | // // renable axes of the chart (pie hides them) |
|
189 | 189 | // // x axis |
|
190 | 190 | // QAxis *axis = m_chart->axisX(); |
|
191 | 191 | // axis->setAxisVisible(true); |
|
192 | 192 | // axis->setGridLineVisible(true); |
|
193 | 193 | // axis->setLabelsVisible(true); |
|
194 | 194 | |
|
195 | 195 | // // y axis |
|
196 | 196 | // axis = m_chart->axisY(); |
|
197 | 197 | // axis->setAxisVisible(true); |
|
198 | 198 | // axis->setGridLineVisible(true); |
|
199 | 199 | // axis->setLabelsVisible(true); |
|
200 | 200 | |
|
201 | 201 | // m_model->clearMapping(); |
|
202 | 202 | |
|
203 | 203 | QString seriesColorHex = "#000000"; |
|
204 | 204 | // QPen pen; |
|
205 | 205 | // pen.setWidth(2); |
|
206 | 206 | |
|
207 | 207 | if (m_lineRadioButton->isChecked()) |
|
208 | 208 | { |
|
209 | 209 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
210 | 210 | |
|
211 | 211 | // // series 1 |
|
212 | 212 | // m_series = new QLineSeries; |
|
213 | 213 | // m_series->setModel(m_model); |
|
214 | 214 | |
|
215 | 215 | // QXYModelMapper *mapper = new QXYModelMapper; |
|
216 | 216 | // mapper->setMapX(0); |
|
217 | 217 | // mapper->setMapY(1); |
|
218 | 218 | // mapper->setFirst(3); |
|
219 | 219 | // mapper->setCount(4); |
|
220 | 220 | // m_series->setModelMapper(mapper); |
|
221 | 221 | // // m_series->setModelMapping(0,1, Qt::Vertical); |
|
222 | 222 | // // m_series->setModelMappingRange(3, 4); |
|
223 | 223 | // m_chart->addSeries(m_series); |
|
224 | 224 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
225 | 225 | // m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); |
|
226 | 226 | |
|
227 | 227 | // // series 2 |
|
228 | 228 | // m_series = new QLineSeries; |
|
229 | 229 | // m_series->setModel(m_model); |
|
230 | 230 | |
|
231 | 231 | // mapper = new QXYModelMapper; |
|
232 | 232 | // mapper->setMapX(3); |
|
233 | 233 | // mapper->setMapY(4); |
|
234 | 234 | // // mapper->setFirst(3); |
|
235 | 235 | // // mapper->setCount(4); |
|
236 | 236 | // m_series->setModelMapper(mapper); |
|
237 | 237 | // // m_series->setModelMapping(2,3, Qt::Vertical); |
|
238 | 238 | // m_chart->addSeries(m_series); |
|
239 | 239 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
240 | 240 | // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); |
|
241 | 241 | |
|
242 | 242 | // // series 3 |
|
243 | 243 | // m_series = new QLineSeries; |
|
244 | 244 | // m_series->setModel(m_model); |
|
245 | 245 | |
|
246 | 246 | // mapper = new QXYModelMapper; |
|
247 | 247 | // mapper->setMapX(5); |
|
248 | 248 | // mapper->setMapY(6); |
|
249 | 249 | // mapper->setFirst(2); |
|
250 | 250 | // mapper->setCount(-1); |
|
251 | 251 | // m_series->setModelMapper(mapper); |
|
252 | 252 | // // m_series->setModelMapping(4,5, Qt::Vertical); |
|
253 | 253 | // // m_series->setModelMappingRange(2, -1); |
|
254 | 254 | // m_chart->addSeries(m_series); |
|
255 | 255 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
256 | 256 | // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); |
|
257 | 257 | } |
|
258 | 258 | else if (m_splineRadioButton->isChecked()) |
|
259 | 259 | { |
|
260 | 260 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
261 | 261 | |
|
262 | 262 | // // series 1 |
|
263 | 263 | // m_series = new QSplineSeries; |
|
264 | 264 | // m_series->setModel(m_model); |
|
265 | 265 | |
|
266 | 266 | // QXYModelMapper *mapper = new QXYModelMapper; |
|
267 | 267 | // mapper->setMapX(0); |
|
268 | 268 | // mapper->setMapY(1); |
|
269 | 269 | // mapper->setFirst(0); |
|
270 | 270 | // mapper->setCount(-1); |
|
271 | 271 | |
|
272 | 272 | // m_series->setModelMapper(mapper); |
|
273 | 273 | |
|
274 | 274 | // m_chart->addSeries(m_series); |
|
275 | 275 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
276 | 276 | // m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); |
|
277 | 277 | |
|
278 | 278 | // // series 2 |
|
279 | 279 | // m_series = new QSplineSeries; |
|
280 | 280 | // m_series->setModel(m_model); |
|
281 | 281 | |
|
282 | 282 | // mapper = new QXYModelMapper; |
|
283 | 283 | // mapper->setMapX(2); |
|
284 | 284 | // mapper->setMapY(3); |
|
285 | 285 | // mapper->setFirst(2); |
|
286 | 286 | // mapper->setCount(4); |
|
287 | 287 | |
|
288 | 288 | // m_series->setModelMapper(mapper); |
|
289 | 289 | |
|
290 | 290 | // m_chart->addSeries(m_series); |
|
291 | 291 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
292 | 292 | // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); |
|
293 | 293 | |
|
294 | 294 | // // series 3 |
|
295 | 295 | // m_series = new QSplineSeries; |
|
296 | 296 | // m_series->setModel(m_model); |
|
297 | 297 | |
|
298 | 298 | // mapper = new QXYModelMapper; |
|
299 | 299 | // mapper->setMapX(4); |
|
300 | 300 | // mapper->setMapY(5); |
|
301 | 301 | // mapper->setFirst(2); |
|
302 | 302 | // mapper->setCount(-1); |
|
303 | 303 | |
|
304 | 304 | // m_series->setModelMapper(mapper); |
|
305 | 305 | |
|
306 | 306 | // m_chart->addSeries(m_series); |
|
307 | 307 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
308 | 308 | // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
309 | 309 | } |
|
310 | 310 | // else if (m_scatterRadioButton->isChecked()) |
|
311 | 311 | // { |
|
312 | 312 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
313 | 313 | |
|
314 | 314 | // // series 1 |
|
315 | 315 | // m_series = new QScatterSeries; |
|
316 | 316 | // m_series->setModel(m_model); |
|
317 | 317 | // m_series->setModelMapping(0,1, Qt::Vertical); |
|
318 | 318 | // // m_series->setModelMappingRange(2, 0); |
|
319 | 319 | // // series->setModelMapping(0,1, Qt::Horizontal); |
|
320 | 320 | // m_chart->addSeries(m_series); |
|
321 | 321 | |
|
322 | 322 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
323 | 323 | // m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
324 | 324 | |
|
325 | 325 | // // series 2 |
|
326 | 326 | // m_series = new QScatterSeries; |
|
327 | 327 | // m_series->setModel(m_model); |
|
328 | 328 | // m_series->setModelMapping(2,3, Qt::Vertical); |
|
329 | 329 | // // m_series->setModelMappingRange(1, 6); |
|
330 | 330 | // // series->setModelMapping(2,3, Qt::Horizontal); |
|
331 | 331 | // m_chart->addSeries(m_series); |
|
332 | 332 | |
|
333 | 333 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
334 | 334 | // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
335 | 335 | |
|
336 | 336 | // // series 3 |
|
337 | 337 | // m_series = new QScatterSeries; |
|
338 | 338 | // m_series->setModel(m_model); |
|
339 | 339 | // m_series->setModelMapping(4,5, Qt::Vertical); |
|
340 | 340 | // // series->setModelMapping(4,5, Qt::Horizontal); |
|
341 | 341 | // m_chart->addSeries(m_series); |
|
342 | 342 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
343 | 343 | // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
344 | 344 | // } |
|
345 | 345 | else if (m_pieRadioButton->isChecked()) |
|
346 | 346 | { |
|
347 | 347 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
348 | 348 | |
|
349 | 349 | // pie 1 |
|
350 | 350 | m_pieSeries = new QPieSeries; |
|
351 | 351 | |
|
352 | m_pieMapper = new QPieModelMapper; | |
|
353 |
m_pieMapper->setValues |
|
|
354 |
m_pieMapper->setLabels |
|
|
352 | m_pieMapper = new QVPieModelMapper; | |
|
353 | m_pieMapper->setValuesColumn(1); | |
|
354 | m_pieMapper->setLabelsColumn(7); | |
|
355 | 355 | m_pieMapper->setSeries(m_pieSeries); |
|
356 | 356 | m_pieMapper->setModel(m_model); |
|
357 | 357 | m_pieMapper->setFirst(2); |
|
358 | 358 | m_pieMapper->setCount(5); |
|
359 | 359 | // pieSeries->setModelMapper(mapper); |
|
360 | 360 | |
|
361 | 361 | m_pieSeries->setLabelsVisible(true); |
|
362 | 362 | m_pieSeries->setPieSize(0.75); |
|
363 | 363 | // pieSeries->setHorizontalPosition(0.2); |
|
364 | 364 | // pieSeries->setVerticalPosition(0.3); |
|
365 | 365 | |
|
366 | 366 | m_chart->addSeries(m_pieSeries); |
|
367 | 367 | seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
368 | 368 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5)); |
|
369 | 369 | |
|
370 | 370 | |
|
371 | 371 | // pieSeries->slices().at(0)->setValue(400); |
|
372 | 372 | // pieSeries->slices().at(0)->setLabel(QString("36")); |
|
373 | 373 | |
|
374 | 374 | // // pie 2 |
|
375 | 375 | // pieSeries = new QPieSeries; |
|
376 | 376 | // pieSeries->setModel(m_model); |
|
377 | 377 | |
|
378 | 378 | // pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
379 | 379 | // pieSeries->setModelMappingRange(2, -1); |
|
380 | 380 | // pieSeries->setLabelsVisible(true); |
|
381 | 381 | // pieSeries->setPieSize(0.35); |
|
382 | 382 | // pieSeries->setHorizontalPosition(0.8); |
|
383 | 383 | // pieSeries->setVerticalPosition(0.3); |
|
384 | 384 | // m_chart->addSeries(pieSeries); |
|
385 | 385 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
386 | 386 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); |
|
387 | 387 | |
|
388 | 388 | // // pie 3 |
|
389 | 389 | // pieSeries = new QPieSeries; |
|
390 | 390 | // pieSeries->setModel(m_model); |
|
391 | 391 | // pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
392 | 392 | // pieSeries->setLabelsVisible(true); |
|
393 | 393 | // pieSeries->setPieSize(0.35); |
|
394 | 394 | // pieSeries->setHorizontalPosition(0.5); |
|
395 | 395 | // pieSeries->setVerticalPosition(0.75); |
|
396 | 396 | // m_chart->addSeries(pieSeries); |
|
397 | 397 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
398 | 398 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
399 | 399 | |
|
400 | 400 | // // special pie |
|
401 | 401 | // specialPie = new QPieSeries; |
|
402 | 402 | // specialPie->append(17, "1"); |
|
403 | 403 | // specialPie->append(45, "2"); |
|
404 | 404 | // specialPie->append(77, "3"); |
|
405 | 405 | // specialPie->append(37, "4"); |
|
406 | 406 | // specialPie->append(27, "5"); |
|
407 | 407 | // specialPie->append(47, "6"); |
|
408 | 408 | // specialPie->setPieSize(0.35); |
|
409 | 409 | // specialPie->setHorizontalPosition(0.8); |
|
410 | 410 | // specialPie->setVerticalPosition(0.75); |
|
411 | 411 | // specialPie->setLabelsVisible(true); |
|
412 | 412 | // m_chart->addSeries(specialPie); |
|
413 | 413 | } |
|
414 | 414 | // else if (m_areaRadioButton->isChecked()) |
|
415 | 415 | // { |
|
416 | 416 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
417 | 417 | |
|
418 | 418 | // QLineSeries* upperLineSeries = new QLineSeries; |
|
419 | 419 | // upperLineSeries->setModel(m_model); |
|
420 | 420 | // upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
421 | 421 | // // upperLineSeries->setModelMappingRange(1, 5); |
|
422 | 422 | // QLineSeries* lowerLineSeries = new QLineSeries; |
|
423 | 423 | // lowerLineSeries->setModel(m_model); |
|
424 | 424 | // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
425 | 425 | // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
426 | 426 | // m_chart->addSeries(areaSeries); |
|
427 | 427 | // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
428 | 428 | // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
429 | 429 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
430 | 430 | // } |
|
431 | 431 | else if (m_barRadioButton->isChecked()) |
|
432 | 432 | { |
|
433 | 433 | // m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
434 | 434 | |
|
435 | 435 | // QGroupedBarSeries* barSeries = new QGroupedBarSeries(); |
|
436 | 436 | // barSeries->setCategories(QStringList()); |
|
437 | 437 | // barSeries->setModel(m_model); |
|
438 | 438 | // // barSeries->setModelMappingRange(2, 5); |
|
439 | 439 | //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
440 | 440 | |
|
441 | 441 | // QBarModelMapper *mapper = new QBarModelMapper; |
|
442 | 442 | // mapper->setMapCategories(5); |
|
443 | 443 | // mapper->setMapBarBottom(2); |
|
444 | 444 | // mapper->setMapBarTop(4); |
|
445 | 445 | // barSeries->setModelMapper(mapper); |
|
446 | 446 | // m_chart->addSeries(barSeries); |
|
447 | 447 | // QList<QBarSet*> barsets = barSeries->barSets(); |
|
448 | 448 | // for (int i = 0; i < barsets.count(); i++) { |
|
449 | 449 | // seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
450 | 450 | // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
451 | 451 | // } |
|
452 | 452 | } |
|
453 | 453 | |
|
454 | 454 | |
|
455 | 455 | if (!m_barRadioButton->isChecked()) { |
|
456 | 456 | m_chart->axisX()->setRange(0, 500); |
|
457 | 457 | m_chart->axisY()->setRange(0, 220); |
|
458 | 458 | } |
|
459 | 459 | m_chart->legend()->setVisible(true); |
|
460 | 460 | |
|
461 | 461 | // repaint table view colors |
|
462 | 462 | m_tableView->repaint(); |
|
463 | 463 | m_tableView->setFocus(); |
|
464 | 464 | } |
|
465 | 465 | } |
|
466 | 466 | |
|
467 | 467 | void TableWidget::testPie() |
|
468 | 468 | { |
|
469 | 469 | // m_pieMapper->setCount(-1); |
|
470 | 470 | QPieSlice *slice = new QPieSlice("Hehe", 145); |
|
471 | 471 | slice->setLabelVisible(); |
|
472 | 472 | m_pieSeries->append(slice); |
|
473 | 473 | |
|
474 | 474 | slice = new QPieSlice("Hoho", 34); |
|
475 | 475 | slice->setLabelVisible(); |
|
476 | 476 | m_pieSeries->append(slice); |
|
477 | 477 | // m_series->modelMapper()->setMapX(4); |
|
478 | 478 | // m_tableView->setColumnWidth(10, 250); |
|
479 | 479 | // if (specialPie) { |
|
480 | 480 | // specialPie->remove(specialPie->slices().at(2)); |
|
481 | 481 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); |
|
482 | 482 | // specialPie->append(4, "heloo"); |
|
483 | 483 | // } |
|
484 | 484 | } |
|
485 | 485 | |
|
486 | 486 | void TableWidget::testPie2() |
|
487 | 487 | { |
|
488 | 488 | QPieSlice *slice; |
|
489 | 489 | if (m_pieSeries->count() > 0) { |
|
490 | 490 | slice = m_pieSeries->slices().last(); |
|
491 | 491 | m_pieSeries->remove(slice); |
|
492 | 492 | } |
|
493 | 493 | |
|
494 | 494 | if (m_pieSeries->count() > 0) { |
|
495 | 495 | slice = m_pieSeries->slices().first(); |
|
496 | 496 | m_pieSeries->remove(slice); |
|
497 | 497 | } |
|
498 | 498 | } |
|
499 | 499 | |
|
500 | 500 | void TableWidget::testPie3() |
|
501 | 501 | { |
|
502 | 502 | QPieSlice *slice; |
|
503 | 503 | if (m_pieSeries->count() > 0) { |
|
504 | 504 | slice = m_pieSeries->slices().last(); |
|
505 | 505 | slice->setLabel("Dalej"); |
|
506 | 506 | slice->setValue(222); |
|
507 | 507 | } |
|
508 | 508 | |
|
509 | 509 | if (m_pieSeries->count() > 0) { |
|
510 | 510 | slice = m_pieSeries->slices().first(); |
|
511 | 511 | slice->setLabel("Prawie"); |
|
512 | 512 | slice->setValue(111); |
|
513 | 513 | } |
|
514 | 514 | } |
|
515 | 515 | |
|
516 | 516 | TableWidget::~TableWidget() |
|
517 | 517 | { |
|
518 | 518 | |
|
519 | 519 | } |
@@ -1,76 +1,76 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef TABLEWIDGET_H |
|
22 | 22 | #define TABLEWIDGET_H |
|
23 | 23 | |
|
24 | 24 | #include <QtGui/QWidget> |
|
25 | 25 | //#include <QChartGlobal> |
|
26 | 26 | #include "qchartview.h" |
|
27 | 27 | //#include "qxyseries.h" |
|
28 | 28 | #include <QPieSeries> |
|
29 | #include <QPieModelMapper> | |
|
29 | #include <QVPieModelMapper> | |
|
30 | 30 | |
|
31 | 31 | class CustomTableModel; |
|
32 | 32 | class QTableView; |
|
33 | 33 | class QRadioButton; |
|
34 | 34 | class QSpinBox; |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | class TableWidget : public QWidget |
|
39 | 39 | { |
|
40 | 40 | Q_OBJECT |
|
41 | 41 | |
|
42 | 42 | public: |
|
43 | 43 | TableWidget(QWidget *parent = 0); |
|
44 | 44 | ~TableWidget(); |
|
45 | 45 | |
|
46 | 46 | |
|
47 | 47 | public slots: |
|
48 | 48 | void addRowAbove(); |
|
49 | 49 | void addRowBelow(); |
|
50 | 50 | void removeRow(); |
|
51 | 51 | void addColumnRight(); |
|
52 | 52 | void removeColumn(); |
|
53 | 53 | void updateChartType(bool toggle); |
|
54 | 54 | void testPie(); |
|
55 | 55 | void testPie2(); |
|
56 | 56 | void testPie3(); |
|
57 | 57 | |
|
58 | 58 | private: |
|
59 | 59 | QChartView* m_chartView; |
|
60 | 60 | QChart* m_chart; |
|
61 | 61 | QXYSeries* m_series; |
|
62 | 62 | CustomTableModel* m_model; |
|
63 | 63 | QTableView* m_tableView; |
|
64 | 64 | QRadioButton* m_lineRadioButton; |
|
65 | 65 | QRadioButton* m_splineRadioButton; |
|
66 | 66 | QRadioButton* m_scatterRadioButton; |
|
67 | 67 | QRadioButton* m_pieRadioButton; |
|
68 | 68 | QRadioButton* m_areaRadioButton; |
|
69 | 69 | QRadioButton* m_barRadioButton; |
|
70 | 70 | QSpinBox* m_linesCountSpinBox; |
|
71 | QPieModelMapper *m_pieMapper; | |
|
71 | QVPieModelMapper *m_pieMapper; | |
|
72 | 72 | QPieSeries* m_pieSeries; |
|
73 | 73 | // QPieSeries* specialPie; |
|
74 | 74 | }; |
|
75 | 75 | |
|
76 | 76 | #endif // TABLEWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now