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