Auto status change to "Under Review"
@@ -1,172 +1,181 | |||
|
1 | 1 | #include "Catalogue/CatalogueInspectorWidget.h" |
|
2 | 2 | #include "ui_CatalogueInspectorWidget.h" |
|
3 | 3 | |
|
4 | 4 | #include <Common/DateUtils.h> |
|
5 | 5 | #include <DBCatalogue.h> |
|
6 | 6 | #include <DBEvent.h> |
|
7 | 7 | #include <DBEventProduct.h> |
|
8 | 8 | #include <DBTag.h> |
|
9 | 9 | |
|
10 | 10 | struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate { |
|
11 | 11 | std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr; |
|
12 | 12 | std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr; |
|
13 | 13 | std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr; |
|
14 | 14 | |
|
15 | 15 | void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector, |
|
16 | 16 | Ui::CatalogueInspectorWidget *ui); |
|
17 | 17 | void connectEventUpdateSignals(CatalogueInspectorWidget *inspector, |
|
18 | 18 | Ui::CatalogueInspectorWidget *ui); |
|
19 | 19 | }; |
|
20 | 20 | |
|
21 | 21 | CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent) |
|
22 | 22 | : QWidget(parent), |
|
23 | 23 | ui(new Ui::CatalogueInspectorWidget), |
|
24 | 24 | impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()} |
|
25 | 25 | { |
|
26 | 26 | ui->setupUi(this); |
|
27 | 27 | showPage(Page::Empty); |
|
28 | 28 | |
|
29 | 29 | impl->connectCatalogueUpdateSignals(this, ui); |
|
30 | 30 | impl->connectEventUpdateSignals(this, ui); |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | 33 | CatalogueInspectorWidget::~CatalogueInspectorWidget() |
|
34 | 34 | { |
|
35 | 35 | delete ui; |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals( |
|
39 | 39 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) |
|
40 | 40 | { |
|
41 | 41 | connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
42 | 42 | if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) { |
|
43 | 43 | m_DisplayedCatalogue->setName(ui->leCatalogueName->text()); |
|
44 | 44 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); |
|
45 | 45 | } |
|
46 | 46 | }); |
|
47 | 47 | |
|
48 | 48 | connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
49 | 49 | if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) { |
|
50 | 50 | m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text()); |
|
51 | 51 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); |
|
52 | 52 | } |
|
53 | 53 | }); |
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals( |
|
57 | 57 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) |
|
58 | 58 | { |
|
59 | 59 | connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
60 | 60 | if (ui->leEventName->text() != m_DisplayedEvent->getName()) { |
|
61 | 61 | m_DisplayedEvent->setName(ui->leEventName->text()); |
|
62 | 62 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
63 | 63 | } |
|
64 | 64 | }); |
|
65 | 65 | |
|
66 | connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
|
67 | auto tags = ui->leEventTags->text().split(QRegExp("\\s+")); | |
|
68 | std::list<QString> tagNames; | |
|
69 | for (auto tag : tags) { | |
|
70 | tagNames.push_back(tag); | |
|
71 | } | |
|
72 | ||
|
73 | if (m_DisplayedEvent->getTagsNames() != tagNames) { | |
|
74 | m_DisplayedEvent->setTagsNames(tagNames); | |
|
75 | emit inspector->eventUpdated(m_DisplayedEvent); | |
|
76 | } | |
|
77 | }); | |
|
78 | ||
|
66 | 79 | connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
67 | 80 | if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) { |
|
68 | 81 | m_DisplayedEventProduct->setProductId(ui->leEventProduct->text()); |
|
69 | 82 | emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct); |
|
70 | 83 | } |
|
71 | 84 | }); |
|
72 | 85 | |
|
73 | connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
|
74 | // TODO | |
|
75 | }); | |
|
76 | ||
|
77 | 86 | connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { |
|
78 | 87 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime()); |
|
79 | 88 | if (time != m_DisplayedEventProduct->getTStart()) { |
|
80 | 89 | m_DisplayedEventProduct->setTStart(time); |
|
81 | 90 | emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct); |
|
82 | 91 | } |
|
83 | 92 | }); |
|
84 | 93 | |
|
85 | 94 | connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { |
|
86 | 95 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime()); |
|
87 | 96 | if (time != m_DisplayedEventProduct->getTEnd()) { |
|
88 | 97 | m_DisplayedEventProduct->setTEnd(time); |
|
89 | 98 | emit inspector->eventProductUpdated(m_DisplayedEvent, m_DisplayedEventProduct); |
|
90 | 99 | } |
|
91 | 100 | }); |
|
92 | 101 | } |
|
93 | 102 | |
|
94 | 103 | void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page) |
|
95 | 104 | { |
|
96 | 105 | ui->stackedWidget->setCurrentIndex(static_cast<int>(page)); |
|
97 | 106 | } |
|
98 | 107 | |
|
99 | 108 | CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const |
|
100 | 109 | { |
|
101 | 110 | return static_cast<Page>(ui->stackedWidget->currentIndex()); |
|
102 | 111 | } |
|
103 | 112 | |
|
104 | 113 | void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event) |
|
105 | 114 | { |
|
106 | 115 | impl->m_DisplayedEvent = event; |
|
107 | 116 | |
|
108 | 117 | blockSignals(true); |
|
109 | 118 | |
|
110 | 119 | showPage(Page::EventProperties); |
|
111 | 120 | ui->leEventName->setEnabled(true); |
|
112 | 121 | ui->leEventName->setText(event->getName()); |
|
113 | 122 | ui->leEventProduct->setEnabled(false); |
|
114 | 123 | ui->leEventProduct->setText( |
|
115 | 124 | QString::number(event->getEventProducts().size()).append(" product(s)")); |
|
116 | 125 | |
|
117 | 126 | QString tagList; |
|
118 | auto tags = event->getTags(); | |
|
127 | auto tags = event->getTagsNames(); | |
|
119 | 128 | for (auto tag : tags) { |
|
120 |
tagList += tag |
|
|
129 | tagList += tag; | |
|
121 | 130 | tagList += ' '; |
|
122 | 131 | } |
|
123 | 132 | |
|
124 | 133 | ui->leEventTags->setEnabled(true); |
|
125 | 134 | ui->leEventTags->setText(tagList); |
|
126 | 135 | |
|
127 | 136 | ui->dateTimeEventTStart->setEnabled(false); |
|
128 | 137 | ui->dateTimeEventTEnd->setEnabled(false); |
|
129 | 138 | |
|
130 | 139 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart())); |
|
131 | 140 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd())); |
|
132 | 141 | |
|
133 | 142 | blockSignals(false); |
|
134 | 143 | } |
|
135 | 144 | |
|
136 | 145 | void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event, |
|
137 | 146 | const std::shared_ptr<DBEventProduct> &eventProduct) |
|
138 | 147 | { |
|
139 | 148 | impl->m_DisplayedEventProduct = eventProduct; |
|
140 | 149 | |
|
141 | 150 | blockSignals(true); |
|
142 | 151 | |
|
143 | 152 | showPage(Page::EventProperties); |
|
144 | 153 | ui->leEventName->setEnabled(false); |
|
145 | 154 | ui->leEventName->setText(event->getName()); |
|
146 | 155 | ui->leEventProduct->setEnabled(true); |
|
147 | 156 | ui->leEventProduct->setText(eventProduct->getProductId()); |
|
148 | 157 | |
|
149 | 158 | ui->leEventTags->setEnabled(false); |
|
150 | 159 | ui->leEventTags->clear(); |
|
151 | 160 | |
|
152 | 161 | ui->dateTimeEventTStart->setEnabled(true); |
|
153 | 162 | ui->dateTimeEventTEnd->setEnabled(true); |
|
154 | 163 | |
|
155 | 164 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart())); |
|
156 | 165 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd())); |
|
157 | 166 | |
|
158 | 167 | blockSignals(false); |
|
159 | 168 | } |
|
160 | 169 | |
|
161 | 170 | void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue) |
|
162 | 171 | { |
|
163 | 172 | impl->m_DisplayedCatalogue = catalogue; |
|
164 | 173 | |
|
165 | 174 | blockSignals(true); |
|
166 | 175 | |
|
167 | 176 | showPage(Page::CatalogueProperties); |
|
168 | 177 | ui->leCatalogueName->setText(catalogue->getName()); |
|
169 | 178 | ui->leCatalogueAuthor->setText(catalogue->getAuthor()); |
|
170 | 179 | |
|
171 | 180 | blockSignals(false); |
|
172 | 181 | } |
General Comments 3
Status change > Approved
You need to be logged in to leave comments.
Login now