@@ -136,7 +136,7 void XYChartItem::handlePointsAdded(int start, int end) | |||
|
136 | 136 | if (m_series->mapCount() != -1 && addedCount > m_series->mapCount()) |
|
137 | 137 | addedCount = m_series->mapCount(); |
|
138 | 138 | int first = qMax(start, m_series->mapFirst()); |
|
139 |
int last = qMin(first + addedCount - 1, m_series-> |
|
|
139 | int last = qMin(first + addedCount - 1, m_series->count() + m_series->mapFirst() - 1); | |
|
140 | 140 | for (int i = first; i <= last; i++) { |
|
141 | 141 | handlePointAdded(i - m_series->mapFirst()); |
|
142 | 142 | } |
@@ -144,53 +144,6 void XYChartItem::handlePointsAdded(int start, int end) | |||
|
144 | 144 | for (int i = m_points.size() - 1; i >= m_series->mapCount(); i--) |
|
145 | 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 | 149 | void XYChartItem::handlePointRemoved(int index) |
@@ -214,60 +167,31 void XYChartItem::handlePointsRemoved(int start, int end) | |||
|
214 | 167 | handlePointRemoved(i); |
|
215 | 168 | } else { |
|
216 | 169 | // series uses model as a data source |
|
217 |
int |
|
|
218 |
int |
|
|
170 | int mapFirst = m_series->mapFirst(); | |
|
171 | int mapCount = m_series->mapCount(); | |
|
219 | 172 | int removedCount = end - start + 1; |
|
220 |
if ( |
|
|
173 | if (mapCount != -1 && start >= mapFirst + mapCount) { | |
|
221 | 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 | 175 | } else { |
|
255 | // first removed item lays before the mapped area | |
|
256 | int toRemove = qMin(m_points.size() - 1, removedCount); | |
|
257 | for (int i = first; i < first + toRemove; i++) | |
|
258 | handlePointRemoved(0); | |
|
259 | ||
|
260 | // the map is limited, so after removing the items some new items may have fall into the map | |
|
261 | int itemsAvailable; | |
|
262 | if (m_series->mapOrientation() == Qt::Vertical) | |
|
263 | itemsAvailable = m_series->model()->rowCount() - first - m_points.size(); | |
|
264 | else | |
|
265 | itemsAvailable = m_series->model()->columnCount() - first - m_points.size(); | |
|
266 |
|
|
|
267 | int currentSize = m_points.size(); | |
|
268 | if (itemsAvailable > 0) | |
|
269 | for (int i = m_points.size(); i < currentSize + toBeAdded; i++) | |
|
270 | handlePointAdded(i); | |
|
176 | int toRemove = qMin(m_points.size(), removedCount); // first find how many items can actually be removed | |
|
177 | int first = qMax(start, mapFirst); // get the index of the first item that will be removed. | |
|
178 | int last = qMin(first + toRemove - 1, m_points.size() + mapFirst - 1); // get the index of the last item that will be removed. | |
|
179 | for (int i = last; i >= first; i--) | |
|
180 | handlePointRemoved(i - mapFirst); | |
|
181 | ||
|
182 | if (mapCount != -1) { | |
|
183 | int itemsAvailable; // check how many are available to be added | |
|
184 | if (m_series->mapOrientation() == Qt::Vertical) | |
|
185 | itemsAvailable = m_series->model()->rowCount() - mapFirst - m_points.size(); | |
|
186 | else | |
|
187 | itemsAvailable = m_series->model()->columnCount() - mapFirst - m_points.size(); | |
|
188 | int toBeAdded = qMin(itemsAvailable, mapCount - m_points.size()); // add not more items than there is space left to be filled. | |
|
189 | int currentSize = m_points.size(); | |
|
190 | if (toBeAdded > 0) | |
|
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 | 54 | // tableView->setItemDelegate(new QStyledItemDelegate); |
|
55 | 55 | m_chart = new QChart; |
|
56 | 56 | m_chart->legend()->setVisible(true); |
|
57 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
|
57 | // m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
|
58 | 58 | m_chartView = new QChartView(m_chart); |
|
59 | 59 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
60 | 60 | m_chartView->setMinimumSize(640, 480); |
General Comments 0
You need to be logged in to leave comments.
Login now