##// END OF EJS Templates
Fix bug with null parent of selectedItem
perrinel -
r1375:8614c945da0f
parent child
Show More
@@ -1,51 +1,54
1 1 #include "Visualization/VisualizationSelectionZoneManager.h"
2 2 #include "Visualization/VisualizationSelectionZoneItem.h"
3 3
4 4 struct VisualizationSelectionZoneManager::VisualizationSelectionZoneManagerPrivate {
5 5 QVector<VisualizationSelectionZoneItem *> m_SelectedItems;
6 6 };
7 7
8 8 VisualizationSelectionZoneManager::VisualizationSelectionZoneManager()
9 9 : impl{spimpl::make_unique_impl<VisualizationSelectionZoneManagerPrivate>()}
10 10 {
11 11 }
12 12
13 13 void VisualizationSelectionZoneManager::select(
14 14 const QVector<VisualizationSelectionZoneItem *> &items)
15 15 {
16 16 clearSelection();
17 17 for (auto item : items) {
18 18 setSelected(item, true);
19 19 }
20 20 }
21 21
22 22 void VisualizationSelectionZoneManager::setSelected(VisualizationSelectionZoneItem *item,
23 23 bool value)
24 24 {
25 25 if (value != item->selected()) {
26 26 item->setSelected(value);
27 27 item->parentPlot()->replot(QCustomPlot::rpQueuedReplot);
28 28 }
29 29
30 30 if (!value && impl->m_SelectedItems.contains(item)) {
31 31 impl->m_SelectedItems.removeAll(item);
32 32 }
33 33 else if (value) {
34 34 impl->m_SelectedItems << item;
35 35 }
36 36 }
37 37
38 38 void VisualizationSelectionZoneManager::clearSelection()
39 39 {
40 40 for (auto item : impl->m_SelectedItems) {
41 41 item->setSelected(false);
42 item->parentPlot()->replot(QCustomPlot::rpQueuedReplot);
42 auto parentPlot = item->parentPlot();
43 if (parentPlot) {
44 parentPlot->replot(QCustomPlot::rpQueuedReplot);
45 }
43 46 }
44 47
45 48 impl->m_SelectedItems.clear();
46 49 }
47 50
48 51 QVector<VisualizationSelectionZoneItem *> VisualizationSelectionZoneManager::selectedItems() const
49 52 {
50 53 return impl->m_SelectedItems;
51 54 }
General Comments 0
You need to be logged in to leave comments. Login now