##// END OF EJS Templates
New tool dialog to select a zone on time and chart modes
trabillard -
r1168:0d09b45e277b
parent child
Show More
@@ -7,6 +7,10
7 7 #include <DBCatalogue.h>
8 8 #include <SqpApplication.h>
9 9
10 #include <QDialog>
11 #include <QDialogButtonBox>
12 #include <QListWidget>
13
10 14
11 15 /// Format of the dates appearing in the label of a cursor
12 16 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss");
@@ -14,6 +18,8 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss");
14 18 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
15 19
16 20 CatalogueEventsTableModel *m_Model = nullptr;
21 QString m_ZoneForTimeMode;
22 QString m_ZoneForGraphMode;
17 23
18 24 void setEvents(const QVector<DBEvent> &events, QTableView *tableView)
19 25 {
@@ -35,8 +41,72 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
35 41 m_Model->removeEvent(event);
36 42 tableView->setSortingEnabled(true);
37 43 }
38 };
39 44
45 QStringList selectZone(QWidget *parent, const QStringList &availableZones,
46 const QStringList &selectedZones, bool allowMultiSelection,
47 const QPoint &location)
48 {
49 QDialog d(parent, Qt::Tool);
50 d.setWindowTitle("Choose a zone");
51 auto layout = new QVBoxLayout{&d};
52 layout->setContentsMargins(0, 0, 0, 0);
53 auto listWidget = new QListWidget{&d};
54 layout->addWidget(listWidget);
55
56 QSet<QListWidgetItem *> checkedItems;
57 for (auto zone : availableZones) {
58 auto item = new QListWidgetItem{zone};
59 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
60 if (selectedZones.contains(zone)) {
61 item->setCheckState(Qt::Checked);
62 checkedItems << item;
63 }
64 else {
65 item->setCheckState(Qt::Unchecked);
66 }
67
68 listWidget->addItem(item);
69 }
70
71 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
72 layout->addWidget(buttonBox);
73
74 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
75 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
76
77 QObject::connect(listWidget, &QListWidget::itemChanged,
78 [&checkedItems, allowMultiSelection, listWidget](auto item) {
79 if (item->checkState() == Qt::Checked) {
80 if (!allowMultiSelection) {
81 for (auto checkedItem : checkedItems) {
82 listWidget->blockSignals(true);
83 checkedItem->setCheckState(Qt::Unchecked);
84 listWidget->blockSignals(false);
85 }
86
87 checkedItems.clear();
88 }
89 checkedItems << item;
90 }
91 else {
92 checkedItems.remove(item);
93 }
94 });
95
96 QStringList result;
97
98 d.setMinimumWidth(120);
99 d.resize(d.minimumSizeHint());
100 d.move(location);
101 if (d.exec() == QDialog::Accepted) {
102 for (auto item : checkedItems) {
103 result += item->text();
104 }
105 }
106
107 return result;
108 }
109 };
40 110
41 111 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
42 112 : QWidget(parent),
@@ -55,12 +125,22 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
55 125 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
56 126 if (checked) {
57 127 ui->btnChart->setChecked(false);
128 impl->m_ZoneForTimeMode
129 = impl->selectZone(this, {"Zone 1", "Zone 2", "Zone 3", "Zone 4"},
130 {impl->m_ZoneForTimeMode}, false,
131 this->mapToGlobal(ui->btnTime->frameGeometry().center()))
132 .value(0);
58 133 }
59 134 });
60 135
61 136 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
62 137 if (checked) {
63 138 ui->btnTime->setChecked(false);
139 impl->m_ZoneForGraphMode
140 = impl->selectZone(this, {"Zone 1", "Zone 2", "Zone 3", "Zone 4"},
141 {impl->m_ZoneForGraphMode}, false,
142 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
143 .value(0);
64 144 }
65 145 });
66 146
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved

Status change > Approved

You need to be logged in to leave comments. Login now