@@ -20,4 +20,4 SUBDIRS += linechart \ | |||
|
20 | 20 | stackedbarchartdrilldown \ |
|
21 | 21 | customcolors \ |
|
22 | 22 | tablemodelchart \ |
|
23 | ekgchart | |
|
23 | #ekgchart |
@@ -5,6 +5,7 | |||
|
5 | 5 | #include <QPushButton> |
|
6 | 6 | #include "qchartaxis.h" |
|
7 | 7 | #include <qmath.h> |
|
8 | #include <QTime> | |
|
8 | 9 | |
|
9 | 10 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
10 | 11 | |
@@ -12,6 +13,7 SplineWidget::SplineWidget(QWidget *parent) | |||
|
12 | 13 | : QWidget(parent) |
|
13 | 14 | { |
|
14 | 15 | // qsrand(time(NULL)); |
|
16 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
|
15 | 17 | //! [1] |
|
16 | 18 | //create QSplineSeries |
|
17 | 19 | series = new QSplineSeries(this); |
@@ -1,32 +1,48 | |||
|
1 | 1 | #include "customtablemodel.h" |
|
2 | #include <QVector> | |
|
2 | 3 | |
|
3 | 4 | CustomTableModel::CustomTableModel(QObject *parent) : |
|
4 | 5 | QAbstractTableModel(parent) |
|
5 | 6 | { |
|
6 | m_points.append(QPointF(10, 50)); | |
|
7 | m_labels.append("Apples"); | |
|
8 | m_points.append(QPointF(60, 70)); | |
|
9 | m_labels.append("Oranges"); | |
|
10 | m_points.append(QPointF(110, 50)); | |
|
11 | m_labels.append("Bananas"); | |
|
12 | m_points.append(QPointF(140, 40)); | |
|
13 | m_labels.append("Lemons"); | |
|
14 | m_points.append(QPointF(200, 150)); | |
|
15 | m_labels.append("Plums"); | |
|
16 | m_points.append(QPointF(225, 75)); | |
|
17 | m_labels.append("Pearls"); | |
|
7 | // m_points.append(QPointF(10, 50)); | |
|
8 | // m_labels.append("Apples"); | |
|
9 | // m_points.append(QPointF(60, 70)); | |
|
10 | // m_labels.append("Oranges"); | |
|
11 | // m_points.append(QPointF(110, 50)); | |
|
12 | // m_labels.append("Bananas"); | |
|
13 | // m_points.append(QPointF(140, 40)); | |
|
14 | // m_labels.append("Lemons"); | |
|
15 | // m_points.append(QPointF(200, 150)); | |
|
16 | // m_labels.append("Plums"); | |
|
17 | // m_points.append(QPointF(225, 75)); | |
|
18 | // m_labels.append("Pearls"); | |
|
19 | ||
|
20 | // m_data | |
|
21 | for (int i = 0; i < 6; i++) | |
|
22 | { | |
|
23 | QVector<qreal>* dataVec = new QVector<qreal>(6); | |
|
24 | for (int k = 0; k < dataVec->size(); k++) | |
|
25 | if (k%2 == 0) | |
|
26 | dataVec->replace(k, i * 50 + qrand()%20); | |
|
27 | else | |
|
28 | dataVec->replace(k, qrand()%100); | |
|
29 | m_data.append(dataVec); | |
|
30 | m_labels.append(QString("Row: %1").arg((i + 1))); | |
|
31 | } | |
|
18 | 32 | } |
|
19 | 33 | |
|
20 | 34 | int CustomTableModel::rowCount(const QModelIndex & parent) const |
|
21 | 35 | { |
|
22 | 36 | Q_UNUSED(parent) |
|
23 | return m_points.count(); | |
|
37 | // return m_points.count(); | |
|
38 | return m_data.count(); | |
|
24 | 39 | } |
|
25 | 40 | |
|
26 | 41 | int CustomTableModel::columnCount(const QModelIndex & parent) const |
|
27 | 42 | { |
|
28 | 43 | Q_UNUSED(parent) |
|
29 | return 3; | |
|
44 | // return 3; | |
|
45 | return 6; | |
|
30 | 46 | } |
|
31 | 47 | |
|
32 | 48 | QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const |
@@ -38,14 +54,19 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, | |||
|
38 | 54 | { |
|
39 | 55 | switch(section) |
|
40 | 56 | { |
|
41 | case 0: | |
|
42 | return "x"; | |
|
43 | case 1: | |
|
44 | return "y"; | |
|
45 | case 2: | |
|
57 | // case 0: | |
|
58 | // return "x"; | |
|
59 | // case 1: | |
|
60 | // return "y"; | |
|
61 | // case 2: | |
|
62 | case 6: | |
|
46 | 63 | return "Fruit"; |
|
47 | 64 | default: |
|
48 | return "What?"; | |
|
65 | if (section%2 == 0) | |
|
66 | return "x"; | |
|
67 | else | |
|
68 | return "y"; | |
|
69 | // return "What?"; | |
|
49 | 70 | } |
|
50 | 71 | } |
|
51 | 72 | else |
@@ -58,13 +79,15 QVariant CustomTableModel::data(const QModelIndex & index, int role) const | |||
|
58 | 79 | { |
|
59 | 80 | switch(index.column()) |
|
60 | 81 | { |
|
61 | case 0: | |
|
62 | return m_points[index.row()].x(); | |
|
63 | case 1: | |
|
64 | return m_points[index.row()].y(); | |
|
65 | case 2: | |
|
82 | // case 0: | |
|
83 | // return m_points[index.row()].x(); | |
|
84 | // case 1: | |
|
85 | // return m_points[index.row()].y(); | |
|
86 | // case 2: | |
|
87 | case 6: | |
|
66 | 88 | return m_labels[index.row()]; |
|
67 | 89 | default: |
|
90 | return m_data[index.row()]->at(index.column()); | |
|
68 | 91 | break; |
|
69 | 92 | } |
|
70 | 93 | } |
@@ -72,13 +95,15 QVariant CustomTableModel::data(const QModelIndex & index, int role) const | |||
|
72 | 95 | { |
|
73 | 96 | switch(index.column()) |
|
74 | 97 | { |
|
75 | case 0: | |
|
76 | return m_points[index.row()].x(); | |
|
77 | case 1: | |
|
78 | return m_points[index.row()].y(); | |
|
79 | case 2: | |
|
98 | // case 0: | |
|
99 | // return m_points[index.row()].x(); | |
|
100 | // case 1: | |
|
101 | // return m_points[index.row()].y(); | |
|
102 | // case 2: | |
|
103 | case 6: | |
|
80 | 104 | return m_labels[index.row()]; |
|
81 | 105 | default: |
|
106 | return m_data[index.row()]->at(index.column()); | |
|
82 | 107 | break; |
|
83 | 108 | } |
|
84 | 109 | } |
@@ -91,17 +116,20 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & val | |||
|
91 | 116 | { |
|
92 | 117 | switch(index.column()) |
|
93 | 118 | { |
|
94 | case 0: | |
|
95 | m_points[index.row()].setX(value.toDouble()); | |
|
96 | break; | |
|
97 | case 1: | |
|
98 | m_points[index.row()].setY(value.toDouble()); | |
|
99 | break; | |
|
100 | case 2: | |
|
119 | // case 0: | |
|
120 | // m_points[index.row()].setX(value.toDouble()); | |
|
121 | // break; | |
|
122 | // case 1: | |
|
123 | // m_points[index.row()].setY(value.toDouble()); | |
|
124 | // break; | |
|
125 | // case 2: | |
|
126 | case 6: | |
|
101 | 127 | m_labels.replace(index.row(), value.toString()); |
|
102 | 128 | break; |
|
103 | 129 | default: |
|
104 | return false; | |
|
130 | m_data[index.row()]->replace(index.column(), value.toDouble()); | |
|
131 | break; | |
|
132 | // return false; | |
|
105 | 133 | } |
|
106 | 134 | emit dataChanged(index, index); |
|
107 | 135 | return true; |
@@ -125,8 +153,30 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & pare | |||
|
125 | 153 | beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1); |
|
126 | 154 | for (int i = row; i < row + count; i++) |
|
127 | 155 | { |
|
128 | m_points.insert(row, QPointF(10,20)); | |
|
129 | m_labels.insert(row,("a")); | |
|
156 | // m_points.insert(row, QPointF(10,20)); | |
|
157 | QVector<qreal>* dataVec = new QVector<qreal>(6); | |
|
158 | for (int k = 0; k < dataVec->size(); k++) | |
|
159 | if (k%2 == 0) | |
|
160 | // dataVec->replace(k, i * 50 + qrand()%20); | |
|
161 | { | |
|
162 | int difference = 0; | |
|
163 | if (row < m_data.size()) | |
|
164 | { | |
|
165 | if (row - 1 >= 0) | |
|
166 | { | |
|
167 | difference = (int)(qAbs(m_data[row]->at(k) - m_data[row - 1]->at(k))); | |
|
168 | dataVec->replace(k, m_data[row - 1]->at(k) + qrand()%qMax(1, difference)); | |
|
169 | } | |
|
170 | else | |
|
171 | dataVec->replace(k, qrand()%20); | |
|
172 | } | |
|
173 | else | |
|
174 | dataVec->replace(k, m_data[row - 1]->at(k) + qrand()%20); | |
|
175 | } | |
|
176 | else | |
|
177 | dataVec->replace(k, qrand()%100); | |
|
178 | m_data.insert(row, dataVec); | |
|
179 | m_labels.insert(row,(QString("Row: %1").arg(row + 1))); | |
|
130 | 180 | } |
|
131 | 181 | endInsertRows(); |
|
132 | 182 | return true; |
@@ -143,7 +193,10 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & pare | |||
|
143 | 193 | beginRemoveRows(parent, row, row + count - 1); |
|
144 | 194 | for (int i = row; i < row + count; i++) |
|
145 | 195 | { |
|
146 | m_points.removeAt(row); | |
|
196 | // m_points.removeAt(row); | |
|
197 | QVector<qreal>* item = m_data.at(row); | |
|
198 | m_data.removeAt(row); | |
|
199 | delete item; | |
|
147 | 200 | m_labels.removeAt(row); |
|
148 | 201 | } |
|
149 | 202 | endRemoveRows(); |
@@ -24,6 +24,7 public: | |||
|
24 | 24 | |
|
25 | 25 | //public slots: |
|
26 | 26 | private: |
|
27 | QList<QVector<qreal>* > m_data; | |
|
27 | 28 | QList<QPointF> m_points; |
|
28 | 29 | QStringList m_labels; |
|
29 | 30 |
@@ -7,21 +7,27 | |||
|
7 | 7 | #include "qscatterseries.h" |
|
8 | 8 | #include "customtablemodel.h" |
|
9 | 9 | #include "qpieseries.h" |
|
10 | #include "qareaseries.h" | |
|
11 | #include "qbarseries.h" | |
|
10 | 12 | #include <QPushButton> |
|
11 | 13 | #include <QRadioButton> |
|
14 | #include <QTime> | |
|
12 | 15 | |
|
13 | 16 | TableWidget::TableWidget(QWidget *parent) |
|
14 | 17 | : QWidget(parent) |
|
15 | 18 | { |
|
16 | 19 | setGeometry(100, 100, 1000, 600); |
|
20 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
|
17 | 21 | // create simple model for storing data |
|
18 | 22 | // user's table data model |
|
19 | 23 | m_model = new CustomTableModel; |
|
20 | 24 | tableView = new QTableView; |
|
21 | 25 | tableView->setModel(m_model); |
|
22 |
tableView->setMinimum |
|
|
26 | tableView->setMinimumHeight(240); | |
|
27 | // tableView->setMinimumSize(340, 480); | |
|
23 | 28 | // tableView->setItemDelegate(new QStyledItemDelegate); |
|
24 | 29 | chartView = new QChartView(this); |
|
30 | chartView->setRenderHint(QPainter::Antialiasing); | |
|
25 | 31 | chartView->setMinimumSize(640, 480); |
|
26 | 32 | |
|
27 | 33 | // create |
@@ -59,27 +65,35 TableWidget::TableWidget(QWidget *parent) | |||
|
59 | 65 | splineRadioButton = new QRadioButton("Spline"); |
|
60 | 66 | scatterRadioButton = new QRadioButton("Scatter"); |
|
61 | 67 | pieRadioButton = new QRadioButton("Pie"); |
|
68 | areaRadioButton = new QRadioButton("Area"); | |
|
69 | barRadioButton = new QRadioButton("Bar"); | |
|
62 | 70 | |
|
63 | 71 | connect(lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
64 | 72 | connect(splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
65 | 73 | connect(scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
66 | 74 | connect(pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
75 | connect(areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
|
76 | connect(barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
|
67 | 77 | lineRadioButton->setChecked(true); |
|
68 | 78 | |
|
69 | 79 | // radio buttons layout |
|
70 |
Q |
|
|
80 | QVBoxLayout* radioLayout = new QVBoxLayout; | |
|
71 | 81 | radioLayout->addWidget(lineRadioButton); |
|
72 | 82 | radioLayout->addWidget(splineRadioButton); |
|
73 | 83 | radioLayout->addWidget(scatterRadioButton); |
|
74 | 84 | radioLayout->addWidget(pieRadioButton); |
|
85 | radioLayout->addWidget(areaRadioButton); | |
|
86 | radioLayout->addWidget(barRadioButton); | |
|
87 | radioLayout->addStretch(); | |
|
75 | 88 | |
|
76 | 89 | // create main layout |
|
77 | 90 | QGridLayout* mainLayout = new QGridLayout; |
|
78 |
mainLayout->addLayout(buttonsLayout, |
|
|
79 |
mainLayout->addLayout(radioLayout, |
|
|
91 | mainLayout->addLayout(buttonsLayout, 1, 0); | |
|
92 | mainLayout->addLayout(radioLayout, 2, 0); | |
|
80 | 93 | mainLayout->addWidget(tableView, 1, 1); |
|
81 |
mainLayout->addWidget(chartView, |
|
|
94 | mainLayout->addWidget(chartView, 2, 1); | |
|
82 | 95 | setLayout(mainLayout); |
|
96 | lineRadioButton->setFocus(); | |
|
83 | 97 | } |
|
84 | 98 | |
|
85 | 99 | void TableWidget::addRowAbove() |
@@ -107,24 +121,126 void TableWidget::updateChartType() | |||
|
107 | 121 | chartView->removeAllSeries(); |
|
108 | 122 | |
|
109 | 123 | if (lineRadioButton->isChecked()) |
|
124 | { | |
|
125 | // series 1 | |
|
126 | series = new QLineSeries; | |
|
127 | series->setModel(m_model); | |
|
128 | series->setModelMapping(0,1, Qt::Vertical); | |
|
129 | // series->setModelMapping(0,1, Qt::Horizontal); | |
|
130 | chartView->addSeries(series); | |
|
131 | ||
|
132 | // series 2 | |
|
110 | 133 | series = new QLineSeries; |
|
134 | series->setModel(m_model); | |
|
135 | series->setModelMapping(2,3, Qt::Vertical); | |
|
136 | // series->setModelMapping(2,3, Qt::Horizontal); | |
|
137 | chartView->addSeries(series); | |
|
138 | ||
|
139 | // series 3 | |
|
140 | series = new QLineSeries; | |
|
141 | series->setModel(m_model); | |
|
142 | series->setModelMapping(4,5, Qt::Vertical); | |
|
143 | // series->setModelMapping(4,5, Qt::Horizontal); | |
|
144 | chartView->addSeries(series); | |
|
145 | } | |
|
111 | 146 | else if (splineRadioButton->isChecked()) |
|
147 | { | |
|
148 | // series 1 | |
|
112 | 149 | series = new QSplineSeries; |
|
150 | series->setModel(m_model); | |
|
151 | series->setModelMapping(0,1, Qt::Vertical); | |
|
152 | // series->setModelMapping(0,1, Qt::Horizontal); | |
|
153 | chartView->addSeries(series); | |
|
154 | ||
|
155 | // series 2 | |
|
156 | series = new QSplineSeries; | |
|
157 | series->setModel(m_model); | |
|
158 | series->setModelMapping(2,3, Qt::Vertical); | |
|
159 | // series->setModelMapping(2,3, Qt::Horizontal); | |
|
160 | chartView->addSeries(series); | |
|
161 | ||
|
162 | // series 3 | |
|
163 | series = new QSplineSeries; | |
|
164 | series->setModel(m_model); | |
|
165 | series->setModelMapping(4,5, Qt::Vertical); | |
|
166 | // series->setModelMapping(4,5, Qt::Horizontal); | |
|
167 | chartView->addSeries(series); | |
|
168 | } | |
|
113 | 169 | else if (scatterRadioButton->isChecked()) |
|
170 | { | |
|
171 | // series 1 | |
|
114 | 172 | series = new QScatterSeries; |
|
173 | series->setModel(m_model); | |
|
174 | series->setModelMapping(0,1, Qt::Vertical); | |
|
175 | // series->setModelMapping(0,1, Qt::Horizontal); | |
|
176 | chartView->addSeries(series); | |
|
177 | ||
|
178 | // series 2 | |
|
179 | series = new QScatterSeries; | |
|
180 | series->setModel(m_model); | |
|
181 | series->setModelMapping(2,3, Qt::Vertical); | |
|
182 | // series->setModelMapping(2,3, Qt::Horizontal); | |
|
183 | chartView->addSeries(series); | |
|
184 | ||
|
185 | // series 3 | |
|
186 | series = new QScatterSeries; | |
|
187 | series->setModel(m_model); | |
|
188 | series->setModelMapping(4,5, Qt::Vertical); | |
|
189 | // series->setModelMapping(4,5, Qt::Horizontal); | |
|
190 | chartView->addSeries(series); | |
|
191 | } | |
|
115 | 192 | else if (pieRadioButton->isChecked()) |
|
116 | 193 | { |
|
194 | // pie 1 | |
|
117 | 195 | QPieSeries* pieSeries = new QPieSeries; |
|
118 | 196 | pieSeries->setModel(m_model); |
|
119 |
pieSeries->setModelMapping(0, |
|
|
197 | pieSeries->setModelMapping(0,0, Qt::Horizontal); | |
|
198 | pieSeries->setLabelsVisible(true); | |
|
199 | pieSeries->setPieSize(0.4); | |
|
200 | pieSeries->setPiePosition(0.2, 0.35); | |
|
201 | chartView->addSeries(pieSeries); | |
|
202 | ||
|
203 | // pie 2 | |
|
204 | pieSeries = new QPieSeries; | |
|
205 | pieSeries->setModel(m_model); | |
|
206 | pieSeries->setModelMapping(1,1, Qt::Horizontal); | |
|
120 | 207 | pieSeries->setLabelsVisible(true); |
|
208 | pieSeries->setPieSize(0.4); | |
|
209 | pieSeries->setPiePosition(0.8, 0.35); | |
|
121 | 210 | chartView->addSeries(pieSeries); |
|
122 | return; | |
|
211 | ||
|
212 | // pie 3 | |
|
213 | pieSeries = new QPieSeries; | |
|
214 | pieSeries->setModel(m_model); | |
|
215 | pieSeries->setModelMapping(2,2, Qt::Horizontal); | |
|
216 | pieSeries->setLabelsVisible(true); | |
|
217 | pieSeries->setPieSize(0.4); | |
|
218 | pieSeries->setPiePosition(0.5, 0.65); | |
|
219 | chartView->addSeries(pieSeries); | |
|
220 | } | |
|
221 | else if (areaRadioButton->isChecked()) | |
|
222 | { | |
|
223 | QLineSeries* upperLineSeries = new QLineSeries; | |
|
224 | upperLineSeries->setModel(m_model); | |
|
225 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
|
226 | QLineSeries* lowerLineSeries = new QLineSeries; | |
|
227 | lowerLineSeries->setModel(m_model); | |
|
228 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | |
|
229 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
|
230 | chartView->addSeries(areaSeries); | |
|
231 | } | |
|
232 | else if (barRadioButton->isChecked()) | |
|
233 | { | |
|
234 | QBarSeries* barSeries = new QBarSeries(QStringList()); | |
|
235 | barSeries->setModel(m_model); | |
|
236 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
|
237 | barSeries->setToolTipEnabled(true); | |
|
238 | chartView->addSeries(barSeries); | |
|
123 | 239 | } |
|
124 | 240 | |
|
125 | series->setModel(m_model); | |
|
126 | series->setModelMapping(0,1, Qt::Vertical); | |
|
127 | chartView->addSeries(series); | |
|
241 | // series->setModel(m_model); | |
|
242 | // series->setModelMapping(0,1, Qt::Vertical); | |
|
243 | // chartView->addSeries(series); | |
|
128 | 244 | } |
|
129 | 245 | |
|
130 | 246 | TableWidget::~TableWidget() |
@@ -36,6 +36,8 public: | |||
|
36 | 36 | QRadioButton* splineRadioButton; |
|
37 | 37 | QRadioButton* scatterRadioButton; |
|
38 | 38 | QRadioButton* pieRadioButton; |
|
39 | QRadioButton* areaRadioButton; | |
|
40 | QRadioButton* barRadioButton; | |
|
39 | 41 | }; |
|
40 | 42 | |
|
41 | 43 | #endif // TABLEWIDGET_H |
@@ -124,6 +124,25 void QAreaSeries::setPointsVisible(bool visible) | |||
|
124 | 124 | } |
|
125 | 125 | } |
|
126 | 126 | |
|
127 | //bool QAreaSeries::setModel(QAbstractItemModel* model) | |
|
128 | //{ | |
|
129 | // m_upperSeries->setModel(model); | |
|
130 | // if (m_lowerSeries) | |
|
131 | // m_lowerSeries->setModel(model); | |
|
132 | // return true; | |
|
133 | //} | |
|
134 | ||
|
135 | //void QAreaSeries::setModelMappingUpper(int modelX, int modelY, Qt::Orientation orientation) | |
|
136 | //{ | |
|
137 | // m_upperSeries->setModelMapping(modelX, modelY, orientation); | |
|
138 | //} | |
|
139 | ||
|
140 | //void QAreaSeries::setModelMappingLower(int modelX, int modelY, Qt::Orientation orientation) | |
|
141 | //{ | |
|
142 | // if (m_lowerSeries) | |
|
143 | // m_lowerSeries->setModelMapping(modelX, modelY, orientation); | |
|
144 | //} | |
|
145 | ||
|
127 | 146 | #include "moc_qareaseries.cpp" |
|
128 | 147 | |
|
129 | 148 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -32,6 +32,10 public: // from QChartSeries | |||
|
32 | 32 | void setPointsVisible(bool visible); |
|
33 | 33 | bool pointsVisible() const {return m_pointsVisible;} |
|
34 | 34 | |
|
35 | // bool setModel(QAbstractItemModel* model); | |
|
36 | // void setModelMappingUpper(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); | |
|
37 | // void setModelMappingLower(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); | |
|
38 | ||
|
35 | 39 | signals: |
|
36 | 40 | void updated(); |
|
37 | 41 | void clicked(const QPointF& point); |
@@ -41,6 +41,7 QBarSeries::QBarSeries(QStringList categories, QObject *parent) | |||
|
41 | 41 | m_mapCategories = -1; |
|
42 | 42 | m_mapBarBottom = -1; |
|
43 | 43 | m_mapBarTop = -1; |
|
44 | m_mapOrientation = Qt::Vertical; | |
|
44 | 45 | } |
|
45 | 46 | |
|
46 | 47 | /*! |
@@ -53,6 +54,7 void QBarSeries::addBarSet(QBarSet *set) | |||
|
53 | 54 | mModel->addBarSet(set); |
|
54 | 55 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
55 | 56 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
57 | connect(set, SIGNAL(changed()), this, SLOT(barsetChanged())); | |
|
56 | 58 | } |
|
57 | 59 | |
|
58 | 60 | /*! |
@@ -72,9 +74,9 void QBarSeries::removeBarSet(QBarSet *set) | |||
|
72 | 74 | */ |
|
73 | 75 | int QBarSeries::barsetCount() |
|
74 | 76 | { |
|
75 | if(m_model) | |
|
76 | return m_mapBarTop - m_mapBarBottom; | |
|
77 | else | |
|
77 | // if(m_model) | |
|
78 | // return m_mapBarTop - m_mapBarBottom; | |
|
79 | // else | |
|
78 | 80 | return mModel->barsetCount(); |
|
79 | 81 | } |
|
80 | 82 | |
@@ -223,18 +225,121 bool QBarSeries::separatorsVisible() | |||
|
223 | 225 | |
|
224 | 226 | bool QBarSeries::setModel(QAbstractItemModel* model) |
|
225 | 227 | { |
|
228 | // disconnect signals from old model | |
|
229 | if(m_model) | |
|
230 | { | |
|
231 | disconnect(m_model, 0, this, 0); | |
|
232 | m_mapCategories = -1; | |
|
233 | m_mapBarBottom = -1; | |
|
234 | m_mapBarTop = -1; | |
|
235 | m_mapOrientation = Qt::Vertical; | |
|
236 | } | |
|
237 | ||
|
238 | // set new model | |
|
239 | if(model) | |
|
240 | { | |
|
226 | 241 | m_model = model; |
|
227 | 242 | return true; |
|
228 | 243 | } |
|
244 | else | |
|
245 | { | |
|
246 | m_model = NULL; | |
|
247 | return false; | |
|
248 | } | |
|
249 | } | |
|
229 | 250 | |
|
230 | 251 | // TODO |
|
231 | void QBarSeries::setModelMappingCategories(int /*modelColumn*/) | |
|
252 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
|
253 | { | |
|
254 | if (m_model == NULL) | |
|
255 | return; | |
|
256 | m_mapCategories = categories; | |
|
257 | m_mapBarBottom = bottomBoundry; | |
|
258 | m_mapBarTop = topBoundry; | |
|
259 | m_mapOrientation = orientation; | |
|
260 | ||
|
261 | // connect the signals | |
|
262 | if (m_mapOrientation == Qt::Vertical) | |
|
263 | { | |
|
264 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
265 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
266 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
267 | } | |
|
268 | else | |
|
232 | 269 | { |
|
270 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
271 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
272 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
233 | 273 | } |
|
234 | 274 | |
|
235 | // TODO | |
|
236 | void QBarSeries::setModelMappingBarRange(int /*bottomBoundry*/, int /*topBoundry*/) | |
|
275 | ||
|
276 | // create the initial bars | |
|
277 | delete mModel; | |
|
278 | if (m_mapOrientation == Qt::Vertical) | |
|
279 | { | |
|
280 | QStringList categories; | |
|
281 | for (int k = 0; k < m_model->columnCount(); k++) | |
|
282 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
|
283 | mModel = new BarChartModel(categories, this); | |
|
284 | ||
|
285 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) | |
|
286 | { | |
|
287 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
|
288 | for(int m = 0; m < m_model->columnCount(); m++) | |
|
289 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
|
290 | addBarSet(barSet); | |
|
291 | } | |
|
292 | } | |
|
293 | else | |
|
294 | { | |
|
295 | QStringList categories; | |
|
296 | for (int k = 0; k < m_model->rowCount(); k++) | |
|
297 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
|
298 | mModel = new BarChartModel(categories, this); | |
|
299 | ||
|
300 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) | |
|
301 | { | |
|
302 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
|
303 | for(int m = 0; m < m_model->rowCount(); m++) | |
|
304 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
|
305 | addBarSet(barSet); | |
|
306 | } | |
|
307 | } | |
|
308 | } | |
|
309 | ||
|
310 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
|
311 | { | |
|
312 | Q_UNUSED(bottomRight) | |
|
313 | ||
|
314 | if (m_mapOrientation == Qt::Vertical) | |
|
315 | { | |
|
316 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) | |
|
317 | barsetAt(topLeft.row())->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
318 | // else if (topLeft.column() == m_mapCategories) | |
|
319 | // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
320 | } | |
|
321 | else | |
|
322 | { | |
|
323 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) | |
|
324 | barsetAt(topLeft.column())->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
325 | // else if (topLeft.row() == m_mapCategories) | |
|
326 | // slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
327 | } | |
|
328 | } | |
|
329 | ||
|
330 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int /*start*/, int /*end*/) | |
|
331 | { | |
|
332 | // | |
|
333 | } | |
|
334 | ||
|
335 | void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int /*start*/, int /*end*/) | |
|
336 | { | |
|
337 | // | |
|
338 | } | |
|
339 | ||
|
340 | void QBarSeries::barsetChanged() | |
|
237 | 341 | { |
|
342 | // mModel-> | |
|
238 | 343 | } |
|
239 | 344 | |
|
240 | 345 | #include "moc_qbarseries.cpp" |
@@ -27,8 +27,7 public: | |||
|
27 | 27 | |
|
28 | 28 | bool setModel(QAbstractItemModel* model); |
|
29 | 29 | QAbstractItemModel* modelExt() {return m_model;} |
|
30 | void setModelMappingCategories(int modelColumn); | |
|
31 | void setModelMappingBarRange(int bottomBoundry, int topBoundry); | |
|
30 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
|
32 | 31 | |
|
33 | 32 | public: |
|
34 | 33 | // TODO: Functions below this are not part of api and will be moved |
@@ -66,6 +65,13 public Q_SLOTS: | |||
|
66 | 65 | void barsetRightClicked(QString category); |
|
67 | 66 | // <--- TO PIMPL |
|
68 | 67 | |
|
68 | private Q_SLOTS: | |
|
69 | // slots for updating bars when data in model changes | |
|
70 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
|
71 | void modelDataAdded(QModelIndex parent, int start, int end); | |
|
72 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
|
73 | void barsetChanged(); | |
|
74 | ||
|
69 | 75 | protected: |
|
70 | 76 | BarChartModel* mModel; |
|
71 | 77 | bool mSeparatorsVisible; |
@@ -74,6 +80,7 protected: | |||
|
74 | 80 | int m_mapCategories; |
|
75 | 81 | int m_mapBarBottom; |
|
76 | 82 | int m_mapBarTop; |
|
83 | Qt::Orientation m_mapOrientation; | |
|
77 | 84 | }; |
|
78 | 85 | |
|
79 | 86 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -107,6 +107,7 qreal QBarSet::valueAt(int index) | |||
|
107 | 107 | void QBarSet::setValue(int index, qreal value) |
|
108 | 108 | { |
|
109 | 109 | mValues.replace(index,value); |
|
110 | emit changed(); | |
|
110 | 111 | } |
|
111 | 112 | |
|
112 | 113 | /*! |
@@ -481,32 +481,48 bool QPieSeries::setModel(QAbstractItemModel* model) | |||
|
481 | 481 | // disconnect signals from old model |
|
482 | 482 | if(m_model) |
|
483 | 483 | { |
|
484 | disconnect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), 0, 0); | |
|
485 | disconnect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), 0, 0); | |
|
486 | disconnect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), 0, 0); | |
|
484 | disconnect(m_model, 0, this, 0); | |
|
485 | m_mapValues = -1; | |
|
486 | m_mapLabels = -1; | |
|
487 | m_mapOrientation = Qt::Vertical; | |
|
487 | 488 | } |
|
488 | 489 | |
|
489 | // set new model if not NULL and connect necessary signals from it | |
|
490 | // set new model | |
|
490 | 491 | if(model) |
|
491 | 492 | { |
|
492 | 493 | m_model = model; |
|
493 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
494 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
495 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
496 | } | |
|
497 | ||
|
498 | 494 | return true; |
|
499 | 495 | } |
|
496 | else | |
|
497 | { | |
|
498 | m_model = NULL; | |
|
499 | return false; | |
|
500 | } | |
|
501 | } | |
|
500 | 502 | |
|
501 | 503 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
502 | 504 | { |
|
505 | if (m_model == NULL) | |
|
506 | return; | |
|
503 | 507 | m_mapValues = modelValuesLine; |
|
504 | 508 | m_mapLabels = modelLabelsLine; |
|
505 | 509 | m_mapOrientation = orientation; |
|
506 | 510 | |
|
507 | if (m_model == NULL) | |
|
508 | return; | |
|
511 | // connect the signals | |
|
512 | if (m_mapOrientation == Qt::Vertical) | |
|
513 | { | |
|
514 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
515 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
516 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
517 | } | |
|
518 | else | |
|
519 | { | |
|
520 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
521 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
522 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
523 | } | |
|
509 | 524 | |
|
525 | // create the initial slices set | |
|
510 | 526 | if (m_mapOrientation == Qt::Vertical) |
|
511 | 527 | for (int i = 0; i < m_model->rowCount(); i++) |
|
512 | 528 | add(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString()); |
@@ -532,9 +548,9 void QPieSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |||
|
532 | 548 | else |
|
533 | 549 | { |
|
534 | 550 | // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble()); |
|
535 |
if (topLeft. |
|
|
551 | if (topLeft.row() == m_mapValues) | |
|
536 | 552 | slices().at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
537 |
else if (topLeft. |
|
|
553 | else if (topLeft.row() == m_mapLabels) | |
|
538 | 554 | slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
539 | 555 | } |
|
540 | 556 | } |
@@ -306,20 +306,48 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |||
|
306 | 306 | } |
|
307 | 307 | |
|
308 | 308 | bool QXYSeries::setModel(QAbstractItemModel* model) { |
|
309 | ||
|
310 | // disconnect signals from old model | |
|
311 | if(m_model) | |
|
312 | { | |
|
313 | disconnect(m_model, 0, this, 0); | |
|
314 | m_mapX = -1; | |
|
315 | m_mapY = -1; | |
|
316 | m_mapOrientation = Qt::Vertical; | |
|
317 | } | |
|
318 | ||
|
319 | // set new model | |
|
320 | if(model) | |
|
321 | { | |
|
309 | 322 | m_model = model; |
|
310 | // for (int i = 0; i < m_model->rowCount(); i++) | |
|
311 | // emit pointAdded(i); | |
|
312 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
313 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
314 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
315 | 323 | return true; |
|
316 | 324 | } |
|
325 | else | |
|
326 | { | |
|
327 | m_model = NULL; | |
|
328 | return false; | |
|
329 | } | |
|
330 | } | |
|
317 | 331 | |
|
318 | 332 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) |
|
319 | 333 | { |
|
334 | if (m_model == NULL) | |
|
335 | return; | |
|
320 | 336 | m_mapX = modelX; |
|
321 | 337 | m_mapY = modelY; |
|
322 | 338 | m_mapOrientation = orientation; |
|
339 | if (m_mapOrientation == Qt::Vertical) | |
|
340 | { | |
|
341 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
342 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
343 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
344 | } | |
|
345 | else | |
|
346 | { | |
|
347 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
348 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
349 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
350 | } | |
|
323 | 351 | } |
|
324 | 352 | |
|
325 | 353 | //void QXYSeries::setModelMappingY(int modelLineIndex, Qt::Orientation orientation) |
General Comments 0
You need to be logged in to leave comments.
Login now