##// 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 #include <Visualization/VisualizationWidget.h>
17 #include <Visualization/VisualizationWidget.h>
18 #include <Visualization/VisualizationZoneWidget.h>
18 #include <Visualization/VisualizationZoneWidget.h>
19
19
20 #include <QActionGroup>
20 #include <QDialog>
21 #include <QDialog>
21 #include <QDialogButtonBox>
22 #include <QDialogButtonBox>
22 #include <QKeyEvent>
23 #include <QKeyEvent>
23 #include <QListWidget>
24 #include <QListWidget>
25 #include <QMenu>
24 #include <QMessageBox>
26 #include <QMessageBox>
25
27
26 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
28 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
@@ -87,65 +89,33 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
87 return QStringList{};
89 return QStringList{};
88 }
90 }
89
91
90 QDialog d(parent, Qt::Tool);
92 QActionGroup actionGroup{parent};
91 d.setWindowTitle("Choose a zone");
93 actionGroup.setExclusive(!allowMultiSelection);
92 auto layout = new QVBoxLayout{&d};
93 layout->setContentsMargins(0, 0, 0, 0);
94 auto listWidget = new QListWidget{&d};
95 layout->addWidget(listWidget);
96
94
97 QSet<QListWidgetItem *> checkedItems;
95 QMenu selectionMenu{parent};
96 selectionMenu.addSeparator();
97 QVector<QAction *> zoneActions;
98 for (auto zone : availableZones) {
98 for (auto zone : availableZones) {
99 auto item = new QListWidgetItem{zone};
99 auto zoneAction = selectionMenu.addAction(zone);
100 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
100 zoneAction->setCheckable(true);
101 if (selectedZones.contains(zone)) {
101 zoneAction->setChecked(selectedZones.contains(zone));
102 item->setCheckState(Qt::Checked);
102 actionGroup.addAction(zoneAction);
103 checkedItems << item;
103 zoneActions << zoneAction;
104 }
105 else {
106 item->setCheckState(Qt::Unchecked);
107 }
108
109 listWidget->addItem(item);
110 }
104 }
111
105
112 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
106 auto action = selectionMenu.exec(QCursor::pos());
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 });
136
107
137 QStringList result;
108 QStringList result;
138
109
139 d.setMinimumWidth(120);
110 if (action == nullptr) {
140 d.resize(d.minimumSizeHint());
111 result = selectedZones;
141 d.move(location);
142 if (d.exec() == QDialog::Accepted) {
143 for (auto item : checkedItems) {
144 result += item->text();
145 }
146 }
112 }
147 else {
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 return result;
121 return result;
General Comments 0
You need to be logged in to leave comments. Login now