##// END OF EJS Templates
QXYSeries: model data orientation added. QBarSeries: some model data function placeholders
Marek Rosa -
r527:b700a12da54b
parent child
Show More
@@ -13,6 +13,8 CustomTableModel::CustomTableModel(QObject *parent) :
13 m_labels.append("Lemons");
13 m_labels.append("Lemons");
14 m_points.append(QPointF(200, 150));
14 m_points.append(QPointF(200, 150));
15 m_labels.append("Plums");
15 m_labels.append("Plums");
16 m_points.append(QPointF(225, 75));
17 m_labels.append("Pearls");
16 }
18 }
17
19
18 int CustomTableModel::rowCount(const QModelIndex & parent) const
20 int CustomTableModel::rowCount(const QModelIndex & parent) const
@@ -22,7 +24,7 int CustomTableModel::rowCount(const QModelIndex & parent) const
22
24
23 int CustomTableModel::columnCount(const QModelIndex & parent) const
25 int CustomTableModel::columnCount(const QModelIndex & parent) const
24 {
26 {
25 return 3;
27 return 2;
26 }
28 }
27
29
28 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
30 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
@@ -40,7 +42,8 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation,
40 return "y";
42 return "y";
41 case 2:
43 case 2:
42 return "Fruit";
44 return "Fruit";
43 default: "What?";
45 default:
46 return "What?";
44 }
47 }
45 }
48 }
46 else
49 else
@@ -105,8 +108,8 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & val
105
108
106 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
109 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
107 {
110 {
108 if (!index.isValid())
111 // if (!index.isValid())
109 return Qt::ItemIsEnabled;
112 // return Qt::ItemIsEnabled;
110 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
113 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
111 }
114 }
112
115
@@ -26,8 +26,8 TableWidget::TableWidget(QWidget *parent)
26 // QLineSeries* series = new QLineSeries;
26 // QLineSeries* series = new QLineSeries;
27 QSplineSeries* series = new QSplineSeries;
27 QSplineSeries* series = new QSplineSeries;
28 series->setModel(model);
28 series->setModel(model);
29 series->setModelMappingX(0);
29 series->setModelMapping(0,1, Qt::Vertical);
30 series->setModelMappingY(1);
30 // series->setModelMappingY(1);
31
31
32 // series->add(QPointF(150, 100));
32 // series->add(QPointF(150, 100));
33 // series->add(QPointF(200, 130));
33 // series->add(QPointF(200, 130));
@@ -68,6 +68,9 void QBarSeries::removeBarSet(QBarSet *set)
68 */
68 */
69 int QBarSeries::barsetCount()
69 int QBarSeries::barsetCount()
70 {
70 {
71 if(m_model)
72 return m_mapBarTop - m_mapBarBottom;
73 else
71 return mModel->barsetCount();
74 return mModel->barsetCount();
72 }
75 }
73
76
@@ -222,6 +225,21 bool QBarSeries::separatorsVisible()
222 return mSeparatorsVisible;
225 return mSeparatorsVisible;
223 }
226 }
224
227
228 bool QBarSeries::setModel(QAbstractItemModel* model)
229 {
230 m_model = model;
231 }
232
233 void QBarSeries::setModelMappingCategories(int modelColumn)
234 {
235 //
236 }
237
238 void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry)
239 {
240 //
241 }
242
225 #include "moc_qbarseries.cpp"
243 #include "moc_qbarseries.cpp"
226
244
227 QTCOMMERCIALCHART_END_NAMESPACE
245 QTCOMMERCIALCHART_END_NAMESPACE
@@ -26,6 +26,11 public:
26 QList<QBarSet*> barSets();
26 QList<QBarSet*> barSets();
27 QList<QSeries::LegendEntry> legendEntries();
27 QList<QSeries::LegendEntry> legendEntries();
28
28
29 bool setModel(QAbstractItemModel* model);
30 QAbstractItemModel* modelExt() {return m_model;}
31 void setModelMappingCategories(int modelColumn);
32 void setModelMappingBarRange(int bottomBoundry, int topBoundry);
33
29 public:
34 public:
30 // TODO: Functions below this are not part of api and will be moved
35 // TODO: Functions below this are not part of api and will be moved
31 // to private implementation, when we start using it
36 // to private implementation, when we start using it
@@ -65,6 +70,11 public Q_SLOTS:
65 protected:
70 protected:
66 BarChartModel* mModel;
71 BarChartModel* mModel;
67 bool mSeparatorsVisible;
72 bool mSeparatorsVisible;
73
74 QAbstractItemModel* m_model;
75 int m_mapCategories;
76 int m_mapBarBottom;
77 int m_mapBarTop;
68 };
78 };
69
79
70 QTCOMMERCIALCHART_END_NAMESPACE
80 QTCOMMERCIALCHART_END_NAMESPACE
@@ -140,6 +140,12 void QSplineSeries::updateControlPoints()
140 bool QSplineSeries::setModel(QAbstractItemModel* model)
140 bool QSplineSeries::setModel(QAbstractItemModel* model)
141 {
141 {
142 QXYSeries::setModel(model);
142 QXYSeries::setModel(model);
143 // calculateControlPoints();
144 }
145
146 void QSplineSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
147 {
148 QLineSeries::setModelMapping(modelX, modelY, orientation);
143 calculateControlPoints();
149 calculateControlPoints();
144 }
150 }
145
151
@@ -21,6 +21,8 public:
21 QPointF controlPoint(int index) const {return m_controlPoints[index];}
21 QPointF controlPoint(int index) const {return m_controlPoints[index];}
22 bool setModel(QAbstractItemModel* model);
22 bool setModel(QAbstractItemModel* model);
23
23
24 void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
25
24 // TODO: allow the user to set custom control points
26 // TODO: allow the user to set custom control points
25 // void setCustomControlPoints(QList<QPointsF> controlPoints);
27 // void setCustomControlPoints(QList<QPointsF> controlPoints);
26 // bool calculateControlPointsAutomatically();
28 // bool calculateControlPointsAutomatically();
@@ -45,9 +45,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
45 */
45 */
46 QXYSeries::QXYSeries(QObject* parent):QSeries(parent)
46 QXYSeries::QXYSeries(QObject* parent):QSeries(parent)
47 {
47 {
48 m_model = 0;
48 m_model = NULL;
49 m_mapX = 0;
49 m_mapX = -1;
50 m_mapY = 1;
50 m_mapY = -1;
51 m_mapOrientation = Qt::Vertical;
52 // m_mapYOrientation = Qt::Vertical;
51 }
53 }
52 /*!
54 /*!
53 Destroys the object. Series added to QChartView or QChart instances are owned by those,
55 Destroys the object. Series added to QChartView or QChart instances are owned by those,
@@ -142,8 +144,14 void QXYSeries::removeAll()
142 qreal QXYSeries::x(int pos) const
144 qreal QXYSeries::x(int pos) const
143 {
145 {
144 if (m_model)
146 if (m_model)
147 if (m_mapOrientation == Qt::Vertical)
148 // consecutive data is read from model's column
145 return m_model->data(m_model->index(pos, m_mapX), Qt::DisplayRole).toDouble();
149 return m_model->data(m_model->index(pos, m_mapX), Qt::DisplayRole).toDouble();
146 else
150 else
151 // consecutive data is read from model's row
152 return m_model->data(m_model->index(m_mapX, pos), Qt::DisplayRole).toDouble();
153 else
154 // model is not specified, return the data from series' internal data store
147 return m_x.at(pos);
155 return m_x.at(pos);
148 }
156 }
149
157
@@ -153,8 +161,14 qreal QXYSeries::x(int pos) const
153 qreal QXYSeries::y(int pos) const
161 qreal QXYSeries::y(int pos) const
154 {
162 {
155 if (m_model)
163 if (m_model)
164 if (m_mapOrientation == Qt::Vertical)
165 // consecutive data is read from model's column
156 return m_model->data(m_model->index(pos, m_mapY), Qt::DisplayRole).toDouble();
166 return m_model->data(m_model->index(pos, m_mapY), Qt::DisplayRole).toDouble();
157 else
167 else
168 // consecutive data is read from model's row
169 return m_model->data(m_model->index(m_mapY, pos), Qt::DisplayRole).toDouble();
170 else
171 // model is not specified, return the data from series' internal data store
158 return m_y.at(pos);
172 return m_y.at(pos);
159 }
173 }
160
174
@@ -165,10 +179,15 int QXYSeries::count() const
165 {
179 {
166 Q_ASSERT(m_x.size() == m_y.size());
180 Q_ASSERT(m_x.size() == m_y.size());
167
181
168 // int k = m_model->rowCount();
169 if (m_model)
182 if (m_model)
183 if (m_mapOrientation == Qt::Vertical)
184 // data is in a column, so return the number of items in single column
170 return m_model->rowCount();
185 return m_model->rowCount();
171 else
186 else
187 // data is in a row, so return the number of items in single row
188 m_model->columnCount();
189 else
190 // model is not specified, return the number of points in the series internal data store
172 return m_x.size();
191 return m_x.size();
173 }
192 }
174
193
@@ -243,12 +262,25 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
243
262
244 bool QXYSeries::setModel(QAbstractItemModel* model) {
263 bool QXYSeries::setModel(QAbstractItemModel* model) {
245 m_model = model;
264 m_model = model;
246 for (int i = 0; i < m_model->rowCount(); i++)
265 // for (int i = 0; i < m_model->rowCount(); i++)
247 emit pointAdded(i);
266 // emit pointAdded(i);
248 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
267 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
249 // connect(m_model,SIGNAL(), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
268 // connect(m_model,SIGNAL(), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
250 }
269 }
251
270
271 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
272 {
273 m_mapX = modelX;
274 m_mapY = modelY;
275 m_mapOrientation = orientation;
276 }
277
278 //void QXYSeries::setModelMappingY(int modelLineIndex, Qt::Orientation orientation)
279 //{
280 // m_mapY = modelLineIndex;
281 // m_mapYOrientation = orientation;
282 //}
283
252 #include "moc_qxyseries.cpp"
284 #include "moc_qxyseries.cpp"
253
285
254 QTCOMMERCIALCHART_END_NAMESPACE
286 QTCOMMERCIALCHART_END_NAMESPACE
@@ -42,8 +42,8 public:
42 bool setModel(QAbstractItemModel* model);
42 bool setModel(QAbstractItemModel* model);
43 QAbstractItemModel* model() {return m_model;}
43 QAbstractItemModel* model() {return m_model;}
44
44
45 void setModelMappingX(int modelColumn) {m_mapX = modelColumn;}
45 void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
46 void setModelMappingY(int modelColumn) {m_mapY = modelColumn;}
46 // void setModelMappingY(int modelLineIndex, Qt::Orientation orientation = Qt::Vertical);
47
47
48 private slots:
48 private slots:
49 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
49 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
@@ -63,7 +63,9 protected:
63
63
64 QAbstractItemModel* m_model;
64 QAbstractItemModel* m_model;
65 int m_mapX;
65 int m_mapX;
66 Qt::Orientation m_mapOrientation;
66 int m_mapY;
67 int m_mapY;
68 // Qt::Orientation m_mapYOrientation;
67 };
69 };
68
70
69 QTCOMMERCIALCHART_END_NAMESPACE
71 QTCOMMERCIALCHART_END_NAMESPACE
@@ -100,8 +100,8 void XYChartItem::handlePointReplaced(int index)
100 Q_ASSERT(index>=0);
100 Q_ASSERT(index>=0);
101 QPointF point = calculateGeometryPoint(index);
101 QPointF point = calculateGeometryPoint(index);
102 QVector<QPointF> points = m_points;
102 QVector<QPointF> points = m_points;
103 m_points.replace(index,point);
103 points.replace(index,point);
104 updatePoint(m_points);
104 updatePoint(points);
105 update();
105 update();
106 }
106 }
107
107
General Comments 0
You need to be logged in to leave comments. Login now