##// 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 13 m_labels.append("Lemons");
14 14 m_points.append(QPointF(200, 150));
15 15 m_labels.append("Plums");
16 m_points.append(QPointF(225, 75));
17 m_labels.append("Pearls");
16 18 }
17 19
18 20 int CustomTableModel::rowCount(const QModelIndex & parent) const
@@ -22,7 +24,7 int CustomTableModel::rowCount(const QModelIndex & parent) const
22 24
23 25 int CustomTableModel::columnCount(const QModelIndex & parent) const
24 26 {
25 return 3;
27 return 2;
26 28 }
27 29
28 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 42 return "y";
41 43 case 2:
42 44 return "Fruit";
43 default: "What?";
45 default:
46 return "What?";
44 47 }
45 48 }
46 49 else
@@ -105,8 +108,8 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & val
105 108
106 109 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
107 110 {
108 if (!index.isValid())
109 return Qt::ItemIsEnabled;
111 // if (!index.isValid())
112 // return Qt::ItemIsEnabled;
110 113 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
111 114 }
112 115
@@ -26,8 +26,8 TableWidget::TableWidget(QWidget *parent)
26 26 // QLineSeries* series = new QLineSeries;
27 27 QSplineSeries* series = new QSplineSeries;
28 28 series->setModel(model);
29 series->setModelMappingX(0);
30 series->setModelMappingY(1);
29 series->setModelMapping(0,1, Qt::Vertical);
30 // series->setModelMappingY(1);
31 31
32 32 // series->add(QPointF(150, 100));
33 33 // series->add(QPointF(200, 130));
@@ -68,6 +68,9 void QBarSeries::removeBarSet(QBarSet *set)
68 68 */
69 69 int QBarSeries::barsetCount()
70 70 {
71 if(m_model)
72 return m_mapBarTop - m_mapBarBottom;
73 else
71 74 return mModel->barsetCount();
72 75 }
73 76
@@ -222,6 +225,21 bool QBarSeries::separatorsVisible()
222 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 243 #include "moc_qbarseries.cpp"
226 244
227 245 QTCOMMERCIALCHART_END_NAMESPACE
@@ -26,6 +26,11 public:
26 26 QList<QBarSet*> barSets();
27 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 34 public:
30 35 // TODO: Functions below this are not part of api and will be moved
31 36 // to private implementation, when we start using it
@@ -65,6 +70,11 public Q_SLOTS:
65 70 protected:
66 71 BarChartModel* mModel;
67 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 80 QTCOMMERCIALCHART_END_NAMESPACE
@@ -140,6 +140,12 void QSplineSeries::updateControlPoints()
140 140 bool QSplineSeries::setModel(QAbstractItemModel* model)
141 141 {
142 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 149 calculateControlPoints();
144 150 }
145 151
@@ -21,6 +21,8 public:
21 21 QPointF controlPoint(int index) const {return m_controlPoints[index];}
22 22 bool setModel(QAbstractItemModel* model);
23 23
24 void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
25
24 26 // TODO: allow the user to set custom control points
25 27 // void setCustomControlPoints(QList<QPointsF> controlPoints);
26 28 // bool calculateControlPointsAutomatically();
@@ -45,9 +45,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
45 45 */
46 46 QXYSeries::QXYSeries(QObject* parent):QSeries(parent)
47 47 {
48 m_model = 0;
49 m_mapX = 0;
50 m_mapY = 1;
48 m_model = NULL;
49 m_mapX = -1;
50 m_mapY = -1;
51 m_mapOrientation = Qt::Vertical;
52 // m_mapYOrientation = Qt::Vertical;
51 53 }
52 54 /*!
53 55 Destroys the object. Series added to QChartView or QChart instances are owned by those,
@@ -142,8 +144,14 void QXYSeries::removeAll()
142 144 qreal QXYSeries::x(int pos) const
143 145 {
144 146 if (m_model)
147 if (m_mapOrientation == Qt::Vertical)
148 // consecutive data is read from model's column
145 149 return m_model->data(m_model->index(pos, m_mapX), Qt::DisplayRole).toDouble();
146 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 155 return m_x.at(pos);
148 156 }
149 157
@@ -153,8 +161,14 qreal QXYSeries::x(int pos) const
153 161 qreal QXYSeries::y(int pos) const
154 162 {
155 163 if (m_model)
164 if (m_mapOrientation == Qt::Vertical)
165 // consecutive data is read from model's column
156 166 return m_model->data(m_model->index(pos, m_mapY), Qt::DisplayRole).toDouble();
157 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 172 return m_y.at(pos);
159 173 }
160 174
@@ -165,10 +179,15 int QXYSeries::count() const
165 179 {
166 180 Q_ASSERT(m_x.size() == m_y.size());
167 181
168 // int k = m_model->rowCount();
169 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 185 return m_model->rowCount();
171 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 191 return m_x.size();
173 192 }
174 193
@@ -243,12 +262,25 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
243 262
244 263 bool QXYSeries::setModel(QAbstractItemModel* model) {
245 264 m_model = model;
246 for (int i = 0; i < m_model->rowCount(); i++)
247 emit pointAdded(i);
265 // for (int i = 0; i < m_model->rowCount(); i++)
266 // emit pointAdded(i);
248 267 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
249 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 284 #include "moc_qxyseries.cpp"
253 285
254 286 QTCOMMERCIALCHART_END_NAMESPACE
@@ -42,8 +42,8 public:
42 42 bool setModel(QAbstractItemModel* model);
43 43 QAbstractItemModel* model() {return m_model;}
44 44
45 void setModelMappingX(int modelColumn) {m_mapX = modelColumn;}
46 void setModelMappingY(int modelColumn) {m_mapY = modelColumn;}
45 void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
46 // void setModelMappingY(int modelLineIndex, Qt::Orientation orientation = Qt::Vertical);
47 47
48 48 private slots:
49 49 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
@@ -63,7 +63,9 protected:
63 63
64 64 QAbstractItemModel* m_model;
65 65 int m_mapX;
66 Qt::Orientation m_mapOrientation;
66 67 int m_mapY;
68 // Qt::Orientation m_mapYOrientation;
67 69 };
68 70
69 71 QTCOMMERCIALCHART_END_NAMESPACE
@@ -100,8 +100,8 void XYChartItem::handlePointReplaced(int index)
100 100 Q_ASSERT(index>=0);
101 101 QPointF point = calculateGeometryPoint(index);
102 102 QVector<QPointF> points = m_points;
103 m_points.replace(index,point);
104 updatePoint(m_points);
103 points.replace(index,point);
104 updatePoint(points);
105 105 update();
106 106 }
107 107
General Comments 0
You need to be logged in to leave comments. Login now