@@ -20,4 +20,4 SUBDIRS += linechart \ | |||||
20 | stackedbarchartdrilldown \ |
|
20 | stackedbarchartdrilldown \ | |
21 | customcolors \ |
|
21 | customcolors \ | |
22 | tablemodelchart \ |
|
22 | tablemodelchart \ | |
23 | ekgchart |
|
23 | #ekgchart |
@@ -5,6 +5,7 | |||||
5 | #include <QPushButton> |
|
5 | #include <QPushButton> | |
6 | #include "qchartaxis.h" |
|
6 | #include "qchartaxis.h" | |
7 | #include <qmath.h> |
|
7 | #include <qmath.h> | |
|
8 | #include <QTime> | |||
8 |
|
9 | |||
9 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
10 | QTCOMMERCIALCHART_USE_NAMESPACE | |
10 |
|
11 | |||
@@ -12,6 +13,7 SplineWidget::SplineWidget(QWidget *parent) | |||||
12 | : QWidget(parent) |
|
13 | : QWidget(parent) | |
13 | { |
|
14 | { | |
14 | // qsrand(time(NULL)); |
|
15 | // qsrand(time(NULL)); | |
|
16 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |||
15 | //! [1] |
|
17 | //! [1] | |
16 | //create QSplineSeries |
|
18 | //create QSplineSeries | |
17 | series = new QSplineSeries(this); |
|
19 | series = new QSplineSeries(this); |
@@ -1,32 +1,48 | |||||
1 | #include "customtablemodel.h" |
|
1 | #include "customtablemodel.h" | |
|
2 | #include <QVector> | |||
2 |
|
3 | |||
3 | CustomTableModel::CustomTableModel(QObject *parent) : |
|
4 | CustomTableModel::CustomTableModel(QObject *parent) : | |
4 | QAbstractTableModel(parent) |
|
5 | QAbstractTableModel(parent) | |
5 | { |
|
6 | { | |
6 | m_points.append(QPointF(10, 50)); |
|
7 | // m_points.append(QPointF(10, 50)); | |
7 | m_labels.append("Apples"); |
|
8 | // m_labels.append("Apples"); | |
8 | m_points.append(QPointF(60, 70)); |
|
9 | // m_points.append(QPointF(60, 70)); | |
9 | m_labels.append("Oranges"); |
|
10 | // m_labels.append("Oranges"); | |
10 | m_points.append(QPointF(110, 50)); |
|
11 | // m_points.append(QPointF(110, 50)); | |
11 | m_labels.append("Bananas"); |
|
12 | // m_labels.append("Bananas"); | |
12 | m_points.append(QPointF(140, 40)); |
|
13 | // m_points.append(QPointF(140, 40)); | |
13 | m_labels.append("Lemons"); |
|
14 | // m_labels.append("Lemons"); | |
14 | m_points.append(QPointF(200, 150)); |
|
15 | // m_points.append(QPointF(200, 150)); | |
15 | m_labels.append("Plums"); |
|
16 | // m_labels.append("Plums"); | |
16 | m_points.append(QPointF(225, 75)); |
|
17 | // m_points.append(QPointF(225, 75)); | |
17 | m_labels.append("Pearls"); |
|
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 | int CustomTableModel::rowCount(const QModelIndex & parent) const |
|
34 | int CustomTableModel::rowCount(const QModelIndex & parent) const | |
21 | { |
|
35 | { | |
22 | Q_UNUSED(parent) |
|
36 | Q_UNUSED(parent) | |
23 | return m_points.count(); |
|
37 | // return m_points.count(); | |
|
38 | return m_data.count(); | |||
24 | } |
|
39 | } | |
25 |
|
40 | |||
26 | int CustomTableModel::columnCount(const QModelIndex & parent) const |
|
41 | int CustomTableModel::columnCount(const QModelIndex & parent) const | |
27 | { |
|
42 | { | |
28 | Q_UNUSED(parent) |
|
43 | Q_UNUSED(parent) | |
29 | return 3; |
|
44 | // return 3; | |
|
45 | return 6; | |||
30 | } |
|
46 | } | |
31 |
|
47 | |||
32 | QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const |
|
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 | switch(section) |
|
55 | switch(section) | |
40 | { |
|
56 | { | |
41 | case 0: |
|
57 | // case 0: | |
42 | return "x"; |
|
58 | // return "x"; | |
43 | case 1: |
|
59 | // case 1: | |
44 | return "y"; |
|
60 | // return "y"; | |
45 | case 2: |
|
61 | // case 2: | |
|
62 | case 6: | |||
46 | return "Fruit"; |
|
63 | return "Fruit"; | |
47 | default: |
|
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 | else |
|
72 | else | |
@@ -58,13 +79,15 QVariant CustomTableModel::data(const QModelIndex & index, int role) const | |||||
58 | { |
|
79 | { | |
59 | switch(index.column()) |
|
80 | switch(index.column()) | |
60 | { |
|
81 | { | |
61 | case 0: |
|
82 | // case 0: | |
62 | return m_points[index.row()].x(); |
|
83 | // return m_points[index.row()].x(); | |
63 | case 1: |
|
84 | // case 1: | |
64 | return m_points[index.row()].y(); |
|
85 | // return m_points[index.row()].y(); | |
65 | case 2: |
|
86 | // case 2: | |
|
87 | case 6: | |||
66 | return m_labels[index.row()]; |
|
88 | return m_labels[index.row()]; | |
67 | default: |
|
89 | default: | |
|
90 | return m_data[index.row()]->at(index.column()); | |||
68 | break; |
|
91 | break; | |
69 | } |
|
92 | } | |
70 | } |
|
93 | } | |
@@ -72,13 +95,15 QVariant CustomTableModel::data(const QModelIndex & index, int role) const | |||||
72 | { |
|
95 | { | |
73 | switch(index.column()) |
|
96 | switch(index.column()) | |
74 | { |
|
97 | { | |
75 | case 0: |
|
98 | // case 0: | |
76 | return m_points[index.row()].x(); |
|
99 | // return m_points[index.row()].x(); | |
77 | case 1: |
|
100 | // case 1: | |
78 | return m_points[index.row()].y(); |
|
101 | // return m_points[index.row()].y(); | |
79 | case 2: |
|
102 | // case 2: | |
|
103 | case 6: | |||
80 | return m_labels[index.row()]; |
|
104 | return m_labels[index.row()]; | |
81 | default: |
|
105 | default: | |
|
106 | return m_data[index.row()]->at(index.column()); | |||
82 | break; |
|
107 | break; | |
83 | } |
|
108 | } | |
84 | } |
|
109 | } | |
@@ -91,17 +116,20 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & val | |||||
91 | { |
|
116 | { | |
92 | switch(index.column()) |
|
117 | switch(index.column()) | |
93 | { |
|
118 | { | |
94 | case 0: |
|
119 | // case 0: | |
95 | m_points[index.row()].setX(value.toDouble()); |
|
120 | // m_points[index.row()].setX(value.toDouble()); | |
96 | break; |
|
121 | // break; | |
97 | case 1: |
|
122 | // case 1: | |
98 | m_points[index.row()].setY(value.toDouble()); |
|
123 | // m_points[index.row()].setY(value.toDouble()); | |
99 | break; |
|
124 | // break; | |
100 | case 2: |
|
125 | // case 2: | |
|
126 | case 6: | |||
101 | m_labels.replace(index.row(), value.toString()); |
|
127 | m_labels.replace(index.row(), value.toString()); | |
102 | break; |
|
128 | break; | |
103 | default: |
|
129 | default: | |
104 | return false; |
|
130 | m_data[index.row()]->replace(index.column(), value.toDouble()); | |
|
131 | break; | |||
|
132 | // return false; | |||
105 | } |
|
133 | } | |
106 | emit dataChanged(index, index); |
|
134 | emit dataChanged(index, index); | |
107 | return true; |
|
135 | return true; | |
@@ -111,9 +139,9 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & val | |||||
111 |
|
139 | |||
112 | Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const |
|
140 | Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const | |
113 | { |
|
141 | { | |
114 | // if (!index.isValid()) |
|
142 | // if (!index.isValid()) | |
115 | // return Qt::ItemIsEnabled; |
|
143 | // return Qt::ItemIsEnabled; | |
116 |
|
|
144 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; | |
117 | } |
|
145 | } | |
118 |
|
146 | |||
119 | bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent) |
|
147 | bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent) | |
@@ -125,8 +153,30 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & pare | |||||
125 | beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1); |
|
153 | beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1); | |
126 | for (int i = row; i < row + count; i++) |
|
154 | for (int i = row; i < row + count; i++) | |
127 | { |
|
155 | { | |
128 | m_points.insert(row, QPointF(10,20)); |
|
156 | // m_points.insert(row, QPointF(10,20)); | |
129 | m_labels.insert(row,("a")); |
|
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 | endInsertRows(); |
|
181 | endInsertRows(); | |
132 | return true; |
|
182 | return true; | |
@@ -143,7 +193,10 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & pare | |||||
143 | beginRemoveRows(parent, row, row + count - 1); |
|
193 | beginRemoveRows(parent, row, row + count - 1); | |
144 | for (int i = row; i < row + count; i++) |
|
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 | m_labels.removeAt(row); |
|
200 | m_labels.removeAt(row); | |
148 | } |
|
201 | } | |
149 | endRemoveRows(); |
|
202 | endRemoveRows(); |
@@ -24,6 +24,7 public: | |||||
24 |
|
24 | |||
25 | //public slots: |
|
25 | //public slots: | |
26 | private: |
|
26 | private: | |
|
27 | QList<QVector<qreal>* > m_data; | |||
27 | QList<QPointF> m_points; |
|
28 | QList<QPointF> m_points; | |
28 | QStringList m_labels; |
|
29 | QStringList m_labels; | |
29 |
|
30 |
@@ -7,21 +7,27 | |||||
7 | #include "qscatterseries.h" |
|
7 | #include "qscatterseries.h" | |
8 | #include "customtablemodel.h" |
|
8 | #include "customtablemodel.h" | |
9 | #include "qpieseries.h" |
|
9 | #include "qpieseries.h" | |
|
10 | #include "qareaseries.h" | |||
|
11 | #include "qbarseries.h" | |||
10 | #include <QPushButton> |
|
12 | #include <QPushButton> | |
11 | #include <QRadioButton> |
|
13 | #include <QRadioButton> | |
|
14 | #include <QTime> | |||
12 |
|
15 | |||
13 | TableWidget::TableWidget(QWidget *parent) |
|
16 | TableWidget::TableWidget(QWidget *parent) | |
14 | : QWidget(parent) |
|
17 | : QWidget(parent) | |
15 | { |
|
18 | { | |
16 | setGeometry(100, 100, 1000, 600); |
|
19 | setGeometry(100, 100, 1000, 600); | |
|
20 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |||
17 | // create simple model for storing data |
|
21 | // create simple model for storing data | |
18 | // user's table data model |
|
22 | // user's table data model | |
19 | m_model = new CustomTableModel; |
|
23 | m_model = new CustomTableModel; | |
20 | tableView = new QTableView; |
|
24 | tableView = new QTableView; | |
21 | tableView->setModel(m_model); |
|
25 | tableView->setModel(m_model); | |
22 |
tableView->setMinimum |
|
26 | tableView->setMinimumHeight(240); | |
|
27 | // tableView->setMinimumSize(340, 480); | |||
23 | // tableView->setItemDelegate(new QStyledItemDelegate); |
|
28 | // tableView->setItemDelegate(new QStyledItemDelegate); | |
24 | chartView = new QChartView(this); |
|
29 | chartView = new QChartView(this); | |
|
30 | chartView->setRenderHint(QPainter::Antialiasing); | |||
25 | chartView->setMinimumSize(640, 480); |
|
31 | chartView->setMinimumSize(640, 480); | |
26 |
|
32 | |||
27 | // create |
|
33 | // create | |
@@ -59,27 +65,35 TableWidget::TableWidget(QWidget *parent) | |||||
59 | splineRadioButton = new QRadioButton("Spline"); |
|
65 | splineRadioButton = new QRadioButton("Spline"); | |
60 | scatterRadioButton = new QRadioButton("Scatter"); |
|
66 | scatterRadioButton = new QRadioButton("Scatter"); | |
61 | pieRadioButton = new QRadioButton("Pie"); |
|
67 | pieRadioButton = new QRadioButton("Pie"); | |
|
68 | areaRadioButton = new QRadioButton("Area"); | |||
|
69 | barRadioButton = new QRadioButton("Bar"); | |||
62 |
|
70 | |||
63 | connect(lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
71 | connect(lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
64 | connect(splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
72 | connect(splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
65 | connect(scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
73 | connect(scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
66 | connect(pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
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 | lineRadioButton->setChecked(true); |
|
77 | lineRadioButton->setChecked(true); | |
68 |
|
78 | |||
69 | // radio buttons layout |
|
79 | // radio buttons layout | |
70 |
Q |
|
80 | QVBoxLayout* radioLayout = new QVBoxLayout; | |
71 | radioLayout->addWidget(lineRadioButton); |
|
81 | radioLayout->addWidget(lineRadioButton); | |
72 | radioLayout->addWidget(splineRadioButton); |
|
82 | radioLayout->addWidget(splineRadioButton); | |
73 | radioLayout->addWidget(scatterRadioButton); |
|
83 | radioLayout->addWidget(scatterRadioButton); | |
74 | radioLayout->addWidget(pieRadioButton); |
|
84 | radioLayout->addWidget(pieRadioButton); | |
|
85 | radioLayout->addWidget(areaRadioButton); | |||
|
86 | radioLayout->addWidget(barRadioButton); | |||
|
87 | radioLayout->addStretch(); | |||
75 |
|
88 | |||
76 | // create main layout |
|
89 | // create main layout | |
77 | QGridLayout* mainLayout = new QGridLayout; |
|
90 | QGridLayout* mainLayout = new QGridLayout; | |
78 |
mainLayout->addLayout(buttonsLayout, |
|
91 | mainLayout->addLayout(buttonsLayout, 1, 0); | |
79 |
mainLayout->addLayout(radioLayout, |
|
92 | mainLayout->addLayout(radioLayout, 2, 0); | |
80 | mainLayout->addWidget(tableView, 1, 1); |
|
93 | mainLayout->addWidget(tableView, 1, 1); | |
81 |
mainLayout->addWidget(chartView, |
|
94 | mainLayout->addWidget(chartView, 2, 1); | |
82 | setLayout(mainLayout); |
|
95 | setLayout(mainLayout); | |
|
96 | lineRadioButton->setFocus(); | |||
83 | } |
|
97 | } | |
84 |
|
98 | |||
85 | void TableWidget::addRowAbove() |
|
99 | void TableWidget::addRowAbove() | |
@@ -107,24 +121,126 void TableWidget::updateChartType() | |||||
107 | chartView->removeAllSeries(); |
|
121 | chartView->removeAllSeries(); | |
108 |
|
122 | |||
109 | if (lineRadioButton->isChecked()) |
|
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 | |||
|
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 | |||
110 | series = new QLineSeries; |
|
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 | else if (splineRadioButton->isChecked()) |
|
146 | else if (splineRadioButton->isChecked()) | |
|
147 | { | |||
|
148 | // series 1 | |||
|
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 | |||
112 | series = new QSplineSeries; |
|
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 | else if (scatterRadioButton->isChecked()) |
|
169 | else if (scatterRadioButton->isChecked()) | |
|
170 | { | |||
|
171 | // series 1 | |||
|
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 | |||
114 | series = new QScatterSeries; |
|
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 | else if (pieRadioButton->isChecked()) |
|
192 | else if (pieRadioButton->isChecked()) | |
116 | { |
|
193 | { | |
|
194 | // pie 1 | |||
117 | QPieSeries* pieSeries = new QPieSeries; |
|
195 | QPieSeries* pieSeries = new QPieSeries; | |
118 | pieSeries->setModel(m_model); |
|
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); | |||
|
207 | pieSeries->setLabelsVisible(true); | |||
|
208 | pieSeries->setPieSize(0.4); | |||
|
209 | pieSeries->setPiePosition(0.8, 0.35); | |||
|
210 | chartView->addSeries(pieSeries); | |||
|
211 | ||||
|
212 | // pie 3 | |||
|
213 | pieSeries = new QPieSeries; | |||
|
214 | pieSeries->setModel(m_model); | |||
|
215 | pieSeries->setModelMapping(2,2, Qt::Horizontal); | |||
120 | pieSeries->setLabelsVisible(true); |
|
216 | pieSeries->setLabelsVisible(true); | |
|
217 | pieSeries->setPieSize(0.4); | |||
|
218 | pieSeries->setPiePosition(0.5, 0.65); | |||
121 | chartView->addSeries(pieSeries); |
|
219 | chartView->addSeries(pieSeries); | |
122 | return; |
|
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); |
|
241 | // series->setModel(m_model); | |
126 | series->setModelMapping(0,1, Qt::Vertical); |
|
242 | // series->setModelMapping(0,1, Qt::Vertical); | |
127 | chartView->addSeries(series); |
|
243 | // chartView->addSeries(series); | |
128 | } |
|
244 | } | |
129 |
|
245 | |||
130 | TableWidget::~TableWidget() |
|
246 | TableWidget::~TableWidget() |
@@ -36,6 +36,8 public: | |||||
36 | QRadioButton* splineRadioButton; |
|
36 | QRadioButton* splineRadioButton; | |
37 | QRadioButton* scatterRadioButton; |
|
37 | QRadioButton* scatterRadioButton; | |
38 | QRadioButton* pieRadioButton; |
|
38 | QRadioButton* pieRadioButton; | |
|
39 | QRadioButton* areaRadioButton; | |||
|
40 | QRadioButton* barRadioButton; | |||
39 | }; |
|
41 | }; | |
40 |
|
42 | |||
41 | #endif // TABLEWIDGET_H |
|
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 | #include "moc_qareaseries.cpp" |
|
146 | #include "moc_qareaseries.cpp" | |
128 |
|
147 | |||
129 | QTCOMMERCIALCHART_END_NAMESPACE |
|
148 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -32,6 +32,10 public: // from QChartSeries | |||||
32 | void setPointsVisible(bool visible); |
|
32 | void setPointsVisible(bool visible); | |
33 | bool pointsVisible() const {return m_pointsVisible;} |
|
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 | signals: |
|
39 | signals: | |
36 | void updated(); |
|
40 | void updated(); | |
37 | void clicked(const QPointF& point); |
|
41 | void clicked(const QPointF& point); |
@@ -41,6 +41,7 QBarSeries::QBarSeries(QStringList categories, QObject *parent) | |||||
41 | m_mapCategories = -1; |
|
41 | m_mapCategories = -1; | |
42 | m_mapBarBottom = -1; |
|
42 | m_mapBarBottom = -1; | |
43 | m_mapBarTop = -1; |
|
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 | mModel->addBarSet(set); |
|
54 | mModel->addBarSet(set); | |
54 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
55 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
55 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
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 | int QBarSeries::barsetCount() |
|
75 | int QBarSeries::barsetCount() | |
74 | { |
|
76 | { | |
75 | if(m_model) |
|
77 | // if(m_model) | |
76 | return m_mapBarTop - m_mapBarBottom; |
|
78 | // return m_mapBarTop - m_mapBarBottom; | |
77 | else |
|
79 | // else | |
78 | return mModel->barsetCount(); |
|
80 | return mModel->barsetCount(); | |
79 | } |
|
81 | } | |
80 |
|
82 | |||
@@ -223,18 +225,121 bool QBarSeries::separatorsVisible() | |||||
223 |
|
225 | |||
224 | bool QBarSeries::setModel(QAbstractItemModel* model) |
|
226 | bool QBarSeries::setModel(QAbstractItemModel* model) | |
225 | { |
|
227 | { | |
226 | m_model = model; |
|
228 | // disconnect signals from old model | |
227 | return true; |
|
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 | { | |||
|
241 | m_model = model; | |||
|
242 | return true; | |||
|
243 | } | |||
|
244 | else | |||
|
245 | { | |||
|
246 | m_model = NULL; | |||
|
247 | return false; | |||
|
248 | } | |||
228 | } |
|
249 | } | |
229 |
|
250 | |||
230 | // TODO |
|
251 | // TODO | |
231 | void QBarSeries::setModelMappingCategories(int /*modelColumn*/) |
|
252 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
232 | { |
|
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 | |||
|
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))); | |||
|
273 | } | |||
|
274 | ||||
|
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 | } | |||
233 | } |
|
308 | } | |
234 |
|
309 | |||
235 | // TODO |
|
310 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
236 | void QBarSeries::setModelMappingBarRange(int /*bottomBoundry*/, int /*topBoundry*/) |
|
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 | #include "moc_qbarseries.cpp" |
|
345 | #include "moc_qbarseries.cpp" |
@@ -27,8 +27,7 public: | |||||
27 |
|
27 | |||
28 | bool setModel(QAbstractItemModel* model); |
|
28 | bool setModel(QAbstractItemModel* model); | |
29 | QAbstractItemModel* modelExt() {return m_model;} |
|
29 | QAbstractItemModel* modelExt() {return m_model;} | |
30 | void setModelMappingCategories(int modelColumn); |
|
30 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
31 | void setModelMappingBarRange(int bottomBoundry, int topBoundry); |
|
|||
32 |
|
31 | |||
33 | public: |
|
32 | public: | |
34 | // TODO: Functions below this are not part of api and will be moved |
|
33 | // TODO: Functions below this are not part of api and will be moved | |
@@ -66,6 +65,13 public Q_SLOTS: | |||||
66 | void barsetRightClicked(QString category); |
|
65 | void barsetRightClicked(QString category); | |
67 | // <--- TO PIMPL |
|
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 | protected: |
|
75 | protected: | |
70 | BarChartModel* mModel; |
|
76 | BarChartModel* mModel; | |
71 | bool mSeparatorsVisible; |
|
77 | bool mSeparatorsVisible; | |
@@ -74,6 +80,7 protected: | |||||
74 | int m_mapCategories; |
|
80 | int m_mapCategories; | |
75 | int m_mapBarBottom; |
|
81 | int m_mapBarBottom; | |
76 | int m_mapBarTop; |
|
82 | int m_mapBarTop; | |
|
83 | Qt::Orientation m_mapOrientation; | |||
77 | }; |
|
84 | }; | |
78 |
|
85 | |||
79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -107,6 +107,7 qreal QBarSet::valueAt(int index) | |||||
107 | void QBarSet::setValue(int index, qreal value) |
|
107 | void QBarSet::setValue(int index, qreal value) | |
108 | { |
|
108 | { | |
109 | mValues.replace(index,value); |
|
109 | mValues.replace(index,value); | |
|
110 | emit changed(); | |||
110 | } |
|
111 | } | |
111 |
|
112 | |||
112 | /*! |
|
113 | /*! |
@@ -481,32 +481,48 bool QPieSeries::setModel(QAbstractItemModel* model) | |||||
481 | // disconnect signals from old model |
|
481 | // disconnect signals from old model | |
482 | if(m_model) |
|
482 | if(m_model) | |
483 | { |
|
483 | { | |
484 | disconnect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), 0, 0); |
|
484 | disconnect(m_model, 0, this, 0); | |
485 | disconnect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), 0, 0); |
|
485 | m_mapValues = -1; | |
486 | disconnect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), 0, 0); |
|
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 | if(model) |
|
491 | if(model) | |
491 | { |
|
492 | { | |
492 | m_model = model; |
|
493 | m_model = model; | |
493 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
494 | return true; | |
494 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
495 | } | |
495 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
496 | else | |
|
497 | { | |||
|
498 | m_model = NULL; | |||
|
499 | return false; | |||
496 | } |
|
500 | } | |
497 |
|
||||
498 | return true; |
|
|||
499 | } |
|
501 | } | |
500 |
|
502 | |||
501 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
503 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
502 | { |
|
504 | { | |
|
505 | if (m_model == NULL) | |||
|
506 | return; | |||
503 | m_mapValues = modelValuesLine; |
|
507 | m_mapValues = modelValuesLine; | |
504 | m_mapLabels = modelLabelsLine; |
|
508 | m_mapLabels = modelLabelsLine; | |
505 | m_mapOrientation = orientation; |
|
509 | m_mapOrientation = orientation; | |
506 |
|
510 | |||
507 | if (m_model == NULL) |
|
511 | // connect the signals | |
508 | return; |
|
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 | if (m_mapOrientation == Qt::Vertical) |
|
526 | if (m_mapOrientation == Qt::Vertical) | |
511 | for (int i = 0; i < m_model->rowCount(); i++) |
|
527 | for (int i = 0; i < m_model->rowCount(); i++) | |
512 | 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()); |
|
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 | else |
|
548 | else | |
533 | { |
|
549 | { | |
534 | // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble()); |
|
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 | slices().at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
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 | slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
554 | slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
539 | } |
|
555 | } | |
540 | } |
|
556 | } |
@@ -53,7 +53,7 QXYSeries::QXYSeries(QObject* parent):QSeries(parent) | |||||
53 | m_mapX = -1; |
|
53 | m_mapX = -1; | |
54 | m_mapY = -1; |
|
54 | m_mapY = -1; | |
55 | m_mapOrientation = Qt::Vertical; |
|
55 | m_mapOrientation = Qt::Vertical; | |
56 | // m_mapYOrientation = Qt::Vertical; |
|
56 | // m_mapYOrientation = Qt::Vertical; | |
57 | } |
|
57 | } | |
58 | /*! |
|
58 | /*! | |
59 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
59 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
@@ -306,20 +306,48 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |||||
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | bool QXYSeries::setModel(QAbstractItemModel* model) { |
|
308 | bool QXYSeries::setModel(QAbstractItemModel* model) { | |
309 | m_model = model; |
|
309 | ||
310 | // for (int i = 0; i < m_model->rowCount(); i++) |
|
310 | // disconnect signals from old model | |
311 | // emit pointAdded(i); |
|
311 | if(m_model) | |
312 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
312 | { | |
313 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
313 | disconnect(m_model, 0, this, 0); | |
314 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
314 | m_mapX = -1; | |
315 | return true; |
|
315 | m_mapY = -1; | |
|
316 | m_mapOrientation = Qt::Vertical; | |||
|
317 | } | |||
|
318 | ||||
|
319 | // set new model | |||
|
320 | if(model) | |||
|
321 | { | |||
|
322 | m_model = model; | |||
|
323 | return true; | |||
|
324 | } | |||
|
325 | else | |||
|
326 | { | |||
|
327 | m_model = NULL; | |||
|
328 | return false; | |||
|
329 | } | |||
316 | } |
|
330 | } | |
317 |
|
331 | |||
318 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) |
|
332 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) | |
319 | { |
|
333 | { | |
|
334 | if (m_model == NULL) | |||
|
335 | return; | |||
320 | m_mapX = modelX; |
|
336 | m_mapX = modelX; | |
321 | m_mapY = modelY; |
|
337 | m_mapY = modelY; | |
322 | m_mapOrientation = orientation; |
|
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 | //void QXYSeries::setModelMappingY(int modelLineIndex, Qt::Orientation orientation) |
|
353 | //void QXYSeries::setModelMappingY(int modelLineIndex, Qt::Orientation orientation) |
General Comments 0
You need to be logged in to leave comments.
Login now