##// END OF EJS Templates
Refactored model related methods in XYSeries
Marek Rosa -
r1065:f025a5fd5ba2
parent child
Show More
@@ -136,7 +136,7 void XYChartItem::handlePointsAdded(int start, int end)
136 if (m_series->mapCount() != -1 && addedCount > m_series->mapCount())
136 if (m_series->mapCount() != -1 && addedCount > m_series->mapCount())
137 addedCount = m_series->mapCount();
137 addedCount = m_series->mapCount();
138 int first = qMax(start, m_series->mapFirst());
138 int first = qMax(start, m_series->mapFirst());
139 int last = qMin(first + addedCount - 1, m_series->mapOrientation() == Qt::Vertical ? m_series->model()->rowCount() - 1 : m_series->model()->columnCount() - 1);
139 int last = qMin(first + addedCount - 1, m_series->count() + m_series->mapFirst() - 1);
140 for (int i = first; i <= last; i++) {
140 for (int i = first; i <= last; i++) {
141 handlePointAdded(i - m_series->mapFirst());
141 handlePointAdded(i - m_series->mapFirst());
142 }
142 }
@@ -144,53 +144,6 void XYChartItem::handlePointsAdded(int start, int end)
144 for (int i = m_points.size() - 1; i >= m_series->mapCount(); i--)
144 for (int i = m_points.size() - 1; i >= m_series->mapCount(); i--)
145 handlePointRemoved(i);
145 handlePointRemoved(i);
146 }
146 }
147
148 // else {
149 // // series uses model as a data source
150 // int first = m_series->mapFirst();
151 // int count = m_series->mapCount();
152 // int addedCount = end - start + 1;
153 // if (count != -1 && start >= first + count) {
154 // return;
155 // }
156
157 // // adding items to unlimited map
158 // else if (count == -1 && start >= first) {
159 // for (int i = start; i <= end; i++)
160 // handlePointAdded(i - first);
161 // } else if (count == - 1 && start < first) {
162 // // not all newly added items
163 // for (int i = first; i < first + addedCount; i++)
164 // handlePointAdded(i - first);
165 // }
166 // // commented out code below does the same thing, but its more confusing.
167 // // } else if (count == -1) {
168 // // int begin = qMax(start, first);
169 // // for (int i = begin; i < begin + (end - start + 1); i++)
170 // // handlePointAdded(i - first);
171 // // }
172
173 // // adding items to limited map
174 // else if (start >= first) {
175 // // remove the items that will no longer fit into the map
176 // // int toRemove = addedCount - (count - points().size());
177 // for (int i = start; i <= end; i++) {
178 // handlePointAdded(i - first);
179 // }
180 // if (m_points.size() > count)
181 // for (int i = m_points.size() - 1; i >= count; i--)
182 // handlePointRemoved(i);
183 // // update();
184 // } else {
185 // //
186 // for (int i = first; i < first + addedCount; i++) {
187 // handlePointAdded(i - first);
188 // }
189 // if (m_points.size() > count)
190 // for (int i = m_points.size() - 1; i >= count; i--)
191 // handlePointRemoved(i);
192 // }
193 // }
194 }
147 }
195
148
196 void XYChartItem::handlePointRemoved(int index)
149 void XYChartItem::handlePointRemoved(int index)
@@ -214,60 +167,31 void XYChartItem::handlePointsRemoved(int start, int end)
214 handlePointRemoved(i);
167 handlePointRemoved(i);
215 } else {
168 } else {
216 // series uses model as a data source
169 // series uses model as a data source
217 int first = m_series->mapFirst();
170 int mapFirst = m_series->mapFirst();
218 int count = m_series->mapCount();
171 int mapCount = m_series->mapCount();
219 int removedCount = end - start + 1;
172 int removedCount = end - start + 1;
220 if (count != -1 && start >= first + count) {
173 if (mapCount != -1 && start >= mapFirst + mapCount) {
221 return;
174 return;
222 }
223
224 // removing items from unlimited map
225 else if (count == -1 && start >= first) {
226 for (int i = end; i >= start; i--)
227 handlePointRemoved(i - first);
228 } else if (count == - 1 && start < first) {
229 // not all removed items
230 int lastExisting = qMin(first + m_points.size() - 1, first + removedCount - 1);
231 for (int i = lastExisting; i >= first; i--)
232 handlePointRemoved(i - first);
233 }
234
235 // removing items from limited map
236 else if (start >= first) {
237 //
238 int lastExisting = qMin(first + m_points.size() - 1, end);
239 for (int i = lastExisting; i >= start; i--) {
240 handlePointRemoved(i - first);
241 }
242
243 // the map is limited, so after removing the items some new items may have fall within the mapped area
244 int itemsAvailable;
245 if (m_series->mapOrientation() == Qt::Vertical)
246 itemsAvailable = m_series->model()->rowCount() - first - m_points.size();
247 else
248 itemsAvailable = m_series->model()->columnCount() - first - m_points.size();
249 int toBeAdded = qMin(itemsAvailable, count - m_points.size());
250 int currentSize = m_points.size();
251 if (itemsAvailable > 0)
252 for (int i = m_points.size(); i < currentSize + toBeAdded; i++)
253 handlePointAdded(i);
254 } else {
175 } else {
255 // first removed item lays before the mapped area
176 int toRemove = qMin(m_points.size(), removedCount); // first find how many items can actually be removed
256 int toRemove = qMin(m_points.size() - 1, removedCount);
177 int first = qMax(start, mapFirst); // get the index of the first item that will be removed.
257 for (int i = first; i < first + toRemove; i++)
178 int last = qMin(first + toRemove - 1, m_points.size() + mapFirst - 1); // get the index of the last item that will be removed.
258 handlePointRemoved(0);
179 for (int i = last; i >= first; i--)
259
180 handlePointRemoved(i - mapFirst);
260 // the map is limited, so after removing the items some new items may have fall into the map
181
261 int itemsAvailable;
182 if (mapCount != -1) {
262 if (m_series->mapOrientation() == Qt::Vertical)
183 int itemsAvailable; // check how many are available to be added
263 itemsAvailable = m_series->model()->rowCount() - first - m_points.size();
184 if (m_series->mapOrientation() == Qt::Vertical)
264 else
185 itemsAvailable = m_series->model()->rowCount() - mapFirst - m_points.size();
265 itemsAvailable = m_series->model()->columnCount() - first - m_points.size();
186 else
266 int toBeAdded = qMin(itemsAvailable, count - m_points.size());
187 itemsAvailable = m_series->model()->columnCount() - mapFirst - m_points.size();
267 int currentSize = m_points.size();
188 int toBeAdded = qMin(itemsAvailable, mapCount - m_points.size()); // add not more items than there is space left to be filled.
268 if (itemsAvailable > 0)
189 int currentSize = m_points.size();
269 for (int i = m_points.size(); i < currentSize + toBeAdded; i++)
190 if (toBeAdded > 0)
270 handlePointAdded(i);
191 for (int i = m_points.size(); i < currentSize + toBeAdded; i++) {
192 handlePointAdded(i);
193 }
194 }
271 }
195 }
272 }
196 }
273
197
@@ -54,7 +54,7 TableWidget::TableWidget(QWidget *parent)
54 // tableView->setItemDelegate(new QStyledItemDelegate);
54 // tableView->setItemDelegate(new QStyledItemDelegate);
55 m_chart = new QChart;
55 m_chart = new QChart;
56 m_chart->legend()->setVisible(true);
56 m_chart->legend()->setVisible(true);
57 m_chart->setAnimationOptions(QChart::SeriesAnimations);
57 // m_chart->setAnimationOptions(QChart::SeriesAnimations);
58 m_chartView = new QChartView(m_chart);
58 m_chartView = new QChartView(m_chart);
59 m_chartView->setRenderHint(QPainter::Antialiasing);
59 m_chartView->setRenderHint(QPainter::Antialiasing);
60 m_chartView->setMinimumSize(640, 480);
60 m_chartView->setMinimumSize(640, 480);
General Comments 0
You need to be logged in to leave comments. Login now