##// END OF EJS Templates
QXYSeries: support for removing data from model when using custom mapping
Marek Rosa -
r1055:ab3fbe16ea33
parent child
Show More
@@ -226,8 +226,7 QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) :
226 m_categories(categories),
226 m_categories(categories),
227 m_mapCategories(-1),
227 m_mapCategories(-1),
228 m_mapBarBottom(-1),
228 m_mapBarBottom(-1),
229 m_mapBarTop(-1),
229 m_mapBarTop(-1)
230 m_mapOrientation(Qt::Vertical)
231 {
230 {
232 }
231 }
233
232
@@ -51,7 +51,6 protected:
51 int m_mapCategories;
51 int m_mapCategories;
52 int m_mapBarBottom;
52 int m_mapBarBottom;
53 int m_mapBarTop;
53 int m_mapBarTop;
54 Qt::Orientation m_mapOrientation;
55 private:
54 private:
56 Q_DECLARE_PUBLIC(QBarSeries)
55 Q_DECLARE_PUBLIC(QBarSeries)
57 };
56 };
@@ -475,8 +475,7 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
475 m_pieEndAngle(360),
475 m_pieEndAngle(360),
476 m_sum(0),
476 m_sum(0),
477 m_mapValues(0),
477 m_mapValues(0),
478 m_mapLabels(0),
478 m_mapLabels(0)
479 m_mapOrientation(Qt::Vertical)
480 {
479 {
481
480
482 }
481 }
@@ -70,7 +70,6 public:
70 // model map
70 // model map
71 int m_mapValues;
71 int m_mapValues;
72 int m_mapLabels;
72 int m_mapLabels;
73 Qt::Orientation m_mapOrientation;
74
73
75 private:
74 private:
76 friend class QLegendPrivate;
75 friend class QLegendPrivate;
@@ -105,11 +105,17 int QAbstractSeries::mapFirst() const
105 {
105 {
106 return d_ptr->m_mapFirst;
106 return d_ptr->m_mapFirst;
107 }
107 }
108
108 int QAbstractSeries::mapCount() const
109 int QAbstractSeries::mapCount() const
109 {
110 {
110 return d_ptr->m_mapCount;
111 return d_ptr->m_mapCount;
111 }
112 }
112
113
114 int QAbstractSeries::mapOrientation() const
115 {
116 return d_ptr->m_mapOrientation;
117 }
118
113 void QAbstractSeries::setName(const QString& name)
119 void QAbstractSeries::setName(const QString& name)
114 {
120 {
115 d_ptr->m_name = name;
121 d_ptr->m_name = name;
@@ -130,7 +136,8 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
130 q_ptr(q),
136 q_ptr(q),
131 m_model(0),
137 m_model(0),
132 m_mapFirst(0),
138 m_mapFirst(0),
133 m_mapCount(-1)
139 m_mapCount(-1),
140 m_mapOrientation(Qt::Vertical)
134 {
141 {
135 }
142 }
136
143
@@ -59,6 +59,7 public:
59 QAbstractItemModel* model() const;
59 QAbstractItemModel* model() const;
60 int mapFirst() const;
60 int mapFirst() const;
61 int mapCount() const;
61 int mapCount() const;
62 int mapOrientation() const;
62 void setName(const QString& name);
63 void setName(const QString& name);
63 QString name() const;
64 QString name() const;
64
65
@@ -58,6 +58,7 protected:
58 QAbstractItemModel *m_model;
58 QAbstractItemModel *m_model;
59 int m_mapFirst;
59 int m_mapFirst;
60 int m_mapCount;
60 int m_mapCount;
61 Qt::Orientation m_mapOrientation;
61 QString m_name;
62 QString m_name;
62
63
63 friend class QAbstractSeries;
64 friend class QAbstractSeries;
@@ -430,7 +430,6 void QXYSeries::setModelMappingRange(int first, int count)
430 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : QAbstractSeriesPrivate(q),
430 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : QAbstractSeriesPrivate(q),
431 m_mapX(-1),
431 m_mapX(-1),
432 m_mapY(-1),
432 m_mapY(-1),
433 m_mapOrientation( Qt::Vertical),
434 m_pointsVisible(false)
433 m_pointsVisible(false)
435 {
434 {
436 }
435 }
@@ -70,7 +70,6 protected:
70
70
71 int m_mapX;
71 int m_mapX;
72 int m_mapY;
72 int m_mapY;
73 Qt::Orientation m_mapOrientation;
74 bool m_pointsVisible;
73 bool m_pointsVisible;
75
74
76 private:
75 private:
@@ -25,6 +25,7
25 #include "chartanimator_p.h"
25 #include "chartanimator_p.h"
26 #include <QPainter>
26 #include <QPainter>
27 #include <QGraphicsSceneMouseEvent>
27 #include <QGraphicsSceneMouseEvent>
28 #include <QAbstractItemModel>
28
29
29
30
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -189,6 +190,67 void XYChartItem::handlePointsRemoved(int start, int end)
189 {
190 {
190 Q_UNUSED(start)
191 Q_UNUSED(start)
191 Q_UNUSED(end)
192 Q_UNUSED(end)
193 if (m_series->model() == 0) {
194 for (int i = end; i >= start; i--)
195 handlePointRemoved(i);
196 } else {
197 // series uses model as a data source
198 int first = m_series->mapFirst();
199 int count = m_series->mapCount();
200 int removedCount = end - start + 1;
201 if (count != -1 && start >= first + count) {
202 return;
203 }
204
205 // removing items from unlimited map
206 else if (count == -1 && start >= first) {
207 for (int i = end; i >= start; i--)
208 handlePointRemoved(i - first);
209 } else if (count == - 1 && start < first) {
210 // not all removed items
211 for (int i = first + removedCount - 1; i >= first; i--)
212 handlePointRemoved(i - first);
213 }
214
215 // removing items from limited map
216 else if (start >= first) {
217 //
218 int lastExisting = qMin(first + m_points.size() - 1, end);
219 for (int i = lastExisting; i >= start; i--) {
220 handlePointRemoved(i - first);
221 }
222
223 // the map is limited, so after removing the items some new items may have fall into the map
224 int itemsAvailable;
225 if (m_series->mapOrientation() == Qt::Vertical)
226 itemsAvailable = m_series->model()->rowCount() - first - m_points.size();
227 else
228 itemsAvailable = m_series->model()->columnCount() - first - m_points.size();
229 int toBeAdded = qMin(itemsAvailable, count - m_points.size());
230 int currentSize = m_points.size();
231 if (itemsAvailable > 0)
232 for (int i = m_points.size(); i < currentSize + toBeAdded; i++)
233 handlePointAdded(i);
234 } else {
235 // TODO:
236 int toRemove = qMin(m_points.size() - 1, removedCount);
237 for (int i = first; i < first + toRemove; i++)
238 handlePointRemoved(0);
239
240 // the map is limited, so after removing the items some new items may have fall into the map
241 int itemsAvailable;
242 if (m_series->mapOrientation() == Qt::Vertical)
243 itemsAvailable = m_series->model()->rowCount() - first - m_points.size();
244 else
245 itemsAvailable = m_series->model()->columnCount() - first - m_points.size();
246 int toBeAdded = qMin(itemsAvailable, count - m_points.size());
247 int currentSize = m_points.size();
248 if (itemsAvailable > 0)
249 for (int i = m_points.size(); i < currentSize + toBeAdded; i++)
250 handlePointAdded(i);
251 }
252 }
253
192 }
254 }
193
255
194 void XYChartItem::handlePointReplaced(int index)
256 void XYChartItem::handlePointReplaced(int index)
General Comments 0
You need to be logged in to leave comments. Login now