##// END OF EJS Templates
Rework zone selection with graph & time mode as a poppup menu
trabillard -
r1376:f86313d53b19
parent child
Show More
@@ -17,10 +17,12
17 17 #include <Visualization/VisualizationWidget.h>
18 18 #include <Visualization/VisualizationZoneWidget.h>
19 19
20 #include <QActionGroup>
20 21 #include <QDialog>
21 22 #include <QDialogButtonBox>
22 23 #include <QKeyEvent>
23 24 #include <QListWidget>
25 #include <QMenu>
24 26 #include <QMessageBox>
25 27
26 28 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
@@ -87,65 +89,33 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
87 89 return QStringList{};
88 90 }
89 91
90 QDialog d(parent, Qt::Tool);
91 d.setWindowTitle("Choose a zone");
92 auto layout = new QVBoxLayout{&d};
93 layout->setContentsMargins(0, 0, 0, 0);
94 auto listWidget = new QListWidget{&d};
95 layout->addWidget(listWidget);
92 QActionGroup actionGroup{parent};
93 actionGroup.setExclusive(!allowMultiSelection);
96 94
97 QSet<QListWidgetItem *> checkedItems;
95 QMenu selectionMenu{parent};
96 selectionMenu.addSeparator();
97 QVector<QAction *> zoneActions;
98 98 for (auto zone : availableZones) {
99 auto item = new QListWidgetItem{zone};
100 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
101 if (selectedZones.contains(zone)) {
102 item->setCheckState(Qt::Checked);
103 checkedItems << item;
104 }
105 else {
106 item->setCheckState(Qt::Unchecked);
107 }
108
109 listWidget->addItem(item);
99 auto zoneAction = selectionMenu.addAction(zone);
100 zoneAction->setCheckable(true);
101 zoneAction->setChecked(selectedZones.contains(zone));
102 actionGroup.addAction(zoneAction);
103 zoneActions << zoneAction;
110 104 }
111 105
112 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
113 layout->addWidget(buttonBox);
114
115 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
116 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
117
118 QObject::connect(listWidget, &QListWidget::itemChanged,
119 [&checkedItems, allowMultiSelection, listWidget](auto item) {
120 if (item->checkState() == Qt::Checked) {
121 if (!allowMultiSelection) {
122 for (auto checkedItem : checkedItems) {
123 listWidget->blockSignals(true);
124 checkedItem->setCheckState(Qt::Unchecked);
125 listWidget->blockSignals(false);
126 }
127
128 checkedItems.clear();
129 }
130 checkedItems << item;
131 }
132 else {
133 checkedItems.remove(item);
134 }
135 });
106 auto action = selectionMenu.exec(QCursor::pos());
136 107
137 108 QStringList result;
138 109
139 d.setMinimumWidth(120);
140 d.resize(d.minimumSizeHint());
141 d.move(location);
142 if (d.exec() == QDialog::Accepted) {
143 for (auto item : checkedItems) {
144 result += item->text();
145 }
110 if (action == nullptr) {
111 result = selectedZones;
146 112 }
147 113 else {
148 result = selectedZones;
114 for (auto zoneAction : zoneActions) {
115 if (zoneAction->isChecked()) {
116 result << zoneAction->text();
117 }
118 }
149 119 }
150 120
151 121 return result;
General Comments 0
You need to be logged in to leave comments. Login now