@@ -0,0 +1,27 | |||||
|
1 | #ifndef BROWSER_H | |||
|
2 | #define BROWSER_H | |||
|
3 | ||||
|
4 | #include <QWidget> | |||
|
5 | #include <Catalogue/CatalogueController.h> | |||
|
6 | ||||
|
7 | namespace Ui { | |||
|
8 | class Browser; | |||
|
9 | } | |||
|
10 | ||||
|
11 | class Browser : public QWidget | |||
|
12 | { | |||
|
13 | Q_OBJECT | |||
|
14 | ||||
|
15 | public: | |||
|
16 | explicit Browser(QWidget *parent = nullptr); | |||
|
17 | ~Browser(); | |||
|
18 | private slots: | |||
|
19 | void repositorySelected(const QString& repo); | |||
|
20 | void catalogueSelected(const CatalogueController::Catalogue_ptr& catalogue); | |||
|
21 | void eventSelected(const CatalogueController::Event_ptr& event); | |||
|
22 | void productSelected(const CatalogueController::Product_t& product, const CatalogueController::Event_ptr& event); | |||
|
23 | private: | |||
|
24 | Ui::Browser *ui; | |||
|
25 | }; | |||
|
26 | ||||
|
27 | #endif // BROWSER_H |
@@ -0,0 +1,37 | |||||
|
1 | #ifndef EVENTEDITOR_H | |||
|
2 | #define EVENTEDITOR_H | |||
|
3 | ||||
|
4 | #include <QWidget> | |||
|
5 | #include <Catalogue/CatalogueController.h> | |||
|
6 | ||||
|
7 | namespace Ui { | |||
|
8 | class EventEditor; | |||
|
9 | } | |||
|
10 | ||||
|
11 | class EventEditor : public QWidget | |||
|
12 | { | |||
|
13 | Q_OBJECT | |||
|
14 | enum class mode{ | |||
|
15 | editable = true, | |||
|
16 | readonly = false | |||
|
17 | }; | |||
|
18 | ||||
|
19 | public: | |||
|
20 | explicit EventEditor(QWidget *parent = nullptr); | |||
|
21 | ~EventEditor(); | |||
|
22 | ||||
|
23 | public slots: | |||
|
24 | void setEvent(const CatalogueController::Event_ptr& event); | |||
|
25 | void setProduct(const CatalogueController::Product_t& product, const CatalogueController::Event_ptr& event); | |||
|
26 | ||||
|
27 | private: | |||
|
28 | void _setEventName(const CatalogueController::Event_ptr& event, mode is_editable=mode::editable); | |||
|
29 | void _setTags(const CatalogueController::Event_ptr& event,mode is_editable=mode::editable); | |||
|
30 | void _setProducts(const CatalogueController::Event_ptr& event,mode is_editable=mode::editable); | |||
|
31 | void _setProducts(const CatalogueController::Product_t& product,mode is_editable=mode::editable); | |||
|
32 | void _setDates(double startDate, double stopDate, mode is_editable=mode::editable); | |||
|
33 | void _setDates(std::optional<double> startDate, std::optional<double> stopDate, mode is_editable=mode::editable); | |||
|
34 | Ui::EventEditor *ui; | |||
|
35 | }; | |||
|
36 | ||||
|
37 | #endif // EVENTEDITOR_H |
@@ -0,0 +1,50 | |||||
|
1 | #include "Catalogue2/browser.h" | |||
|
2 | #include "ui_browser.h" | |||
|
3 | #include <SqpApplication.h> | |||
|
4 | ||||
|
5 | Browser::Browser(QWidget* parent) : QWidget(parent), ui(new Ui::Browser) | |||
|
6 | { | |||
|
7 | ui->setupUi(this); | |||
|
8 | connect(ui->repositories, &RepositoriesTreeView::repositorySelected, this, | |||
|
9 | &Browser::repositorySelected); | |||
|
10 | connect(ui->repositories, &RepositoriesTreeView::catalogueSelected, this, | |||
|
11 | &Browser::catalogueSelected); | |||
|
12 | connect(ui->events, &EventsTreeView::eventSelected, this, &Browser::eventSelected); | |||
|
13 | connect(ui->events, &EventsTreeView::productSelected, this, &Browser::productSelected); | |||
|
14 | } | |||
|
15 | ||||
|
16 | Browser::~Browser() | |||
|
17 | { | |||
|
18 | delete ui; | |||
|
19 | } | |||
|
20 | ||||
|
21 | void Browser::repositorySelected(const QString& repo) | |||
|
22 | { | |||
|
23 | this->ui->Infos->setCurrentIndex(0); | |||
|
24 | this->ui->events->setEvents(sqpApp->catalogueController().events(repo)); | |||
|
25 | // TODO add a statistic API | |||
|
26 | this->ui->catalogues_count->setText( | |||
|
27 | QString::number(sqpApp->catalogueController().catalogues(repo).size())); | |||
|
28 | this->ui->rep_events_count->setText( | |||
|
29 | QString::number(sqpApp->catalogueController().events(repo).size())); | |||
|
30 | } | |||
|
31 | ||||
|
32 | void Browser::catalogueSelected(const CatalogueController::Catalogue_ptr& catalogue) | |||
|
33 | { | |||
|
34 | this->ui->Infos->setCurrentIndex(1); | |||
|
35 | this->ui->events->setEvents(sqpApp->catalogueController().events(catalogue)); | |||
|
36 | this->ui->cat_events_count->setText( | |||
|
37 | QString::number(sqpApp->catalogueController().events(catalogue).size())); | |||
|
38 | } | |||
|
39 | ||||
|
40 | void Browser::eventSelected(const CatalogueController::Event_ptr& event) | |||
|
41 | { | |||
|
42 | this->ui->Infos->setCurrentIndex(2); | |||
|
43 | this->ui->Event->setEvent(event); | |||
|
44 | } | |||
|
45 | ||||
|
46 | void Browser::productSelected(const CatalogueController::Product_t& product, const CatalogueController::Event_ptr& event) | |||
|
47 | { | |||
|
48 | this->ui->Infos->setCurrentIndex(2); | |||
|
49 | this->ui->Event->setProduct(product,event); | |||
|
50 | } |
@@ -0,0 +1,74 | |||||
|
1 | #include "Catalogue2/eventeditor.h" | |||
|
2 | #include "ui_eventeditor.h" | |||
|
3 | #include <Common/DateUtils.h> | |||
|
4 | #include <Common/StringUtils.h> | |||
|
5 | ||||
|
6 | EventEditor::EventEditor(QWidget* parent) : QWidget(parent), ui(new Ui::EventEditor) | |||
|
7 | { | |||
|
8 | ui->setupUi(this); | |||
|
9 | } | |||
|
10 | ||||
|
11 | EventEditor::~EventEditor() | |||
|
12 | { | |||
|
13 | delete ui; | |||
|
14 | } | |||
|
15 | ||||
|
16 | void EventEditor::setEvent(const CatalogueController::Event_ptr& event) | |||
|
17 | { | |||
|
18 | _setEventName(event, mode::editable); | |||
|
19 | _setTags(event, mode::readonly); | |||
|
20 | _setProducts(event, mode::readonly); | |||
|
21 | _setDates(event->startTime(), event->stopTime(), mode::readonly); | |||
|
22 | } | |||
|
23 | ||||
|
24 | void EventEditor::setProduct( | |||
|
25 | const CatalogueController::Product_t& product, const CatalogueController::Event_ptr& event) | |||
|
26 | { | |||
|
27 | _setEventName(event, mode::readonly); | |||
|
28 | _setTags(event, mode::readonly); | |||
|
29 | _setDates(product.startTime, product.stopTime, mode::editable); | |||
|
30 | _setProducts(product, mode::readonly); | |||
|
31 | } | |||
|
32 | ||||
|
33 | void EventEditor::_setEventName(const CatalogueController::Event_ptr& event, mode is_editable) | |||
|
34 | { | |||
|
35 | this->ui->EventName->setText(QString::fromStdString(event->name)); | |||
|
36 | this->ui->EventName->setEnabled(bool(is_editable)); | |||
|
37 | } | |||
|
38 | ||||
|
39 | void EventEditor::_setTags(const CatalogueController::Event_ptr& event, mode is_editable) | |||
|
40 | { | |||
|
41 | this->ui->Tags->setText(StringUtils::join(event->tags, ", ")); | |||
|
42 | this->ui->Tags->setEnabled(bool(is_editable)); | |||
|
43 | } | |||
|
44 | ||||
|
45 | void EventEditor::_setProducts(const CatalogueController::Event_ptr& event, mode is_editable) | |||
|
46 | { | |||
|
47 | QStringList products; | |||
|
48 | this->ui->Products->setText(StringUtils::join(event->products, ", ", | |||
|
49 | [](const auto& product) { return QString::fromStdString(product.name); })); | |||
|
50 | this->ui->Products->setEnabled(bool(is_editable)); | |||
|
51 | } | |||
|
52 | ||||
|
53 | void EventEditor::_setProducts(const CatalogueController::Product_t& product, mode is_editable) | |||
|
54 | { | |||
|
55 | this->ui->Products->setText(QString::fromStdString(product.name)); | |||
|
56 | this->ui->Products->setEnabled(bool(is_editable)); | |||
|
57 | } | |||
|
58 | ||||
|
59 | void EventEditor::_setDates(double startDate, double stopDate, mode is_editable) | |||
|
60 | { | |||
|
61 | this->ui->StartTime->setDateTime(DateUtils::dateTime(startDate)); | |||
|
62 | this->ui->StopTime->setDateTime(DateUtils::dateTime(stopDate)); | |||
|
63 | this->ui->StartTime->setEnabled(bool(is_editable)); | |||
|
64 | this->ui->StopTime->setEnabled(bool(is_editable)); | |||
|
65 | } | |||
|
66 | ||||
|
67 | void EventEditor::_setDates( | |||
|
68 | std::optional<double> startDate, std::optional<double> stopDate, mode is_editable) | |||
|
69 | { | |||
|
70 | if (startDate && stopDate) | |||
|
71 | _setDates(*startDate, *stopDate, is_editable); | |||
|
72 | else | |||
|
73 | _setDates(0., 0., is_editable); | |||
|
74 | } |
@@ -0,0 +1,70 | |||||
|
1 | #include <QMainWindow> | |||
|
2 | #include <QObject> | |||
|
3 | #include <QScreen> | |||
|
4 | #include <QString> | |||
|
5 | #include <QWheelEvent> | |||
|
6 | #include <QtTest> | |||
|
7 | ||||
|
8 | ||||
|
9 | #include <Common/cpp_utils.h> | |||
|
10 | #include <SqpApplication.h> | |||
|
11 | ||||
|
12 | #include <GUITestUtils.h> | |||
|
13 | #include <TestProviders.h> | |||
|
14 | ||||
|
15 | #include <Catalogue/CatalogueController.h> | |||
|
16 | #include <Catalogue2/browser.h> | |||
|
17 | ||||
|
18 | ||||
|
19 | class A_CatalogueBrowser : public QObject | |||
|
20 | { | |||
|
21 | Q_OBJECT | |||
|
22 | public: | |||
|
23 | explicit A_CatalogueBrowser(QObject* parent = Q_NULLPTR) : QObject(parent) {} | |||
|
24 | ||||
|
25 | private slots: | |||
|
26 | }; | |||
|
27 | ||||
|
28 | // QT_BEGIN_NAMESPACE | |||
|
29 | // QTEST_ADD_GPU_BLACKLIST_SUPPORT_DEFS | |||
|
30 | // QT_END_NAMESPACE | |||
|
31 | // int main(int argc, char* argv[]) | |||
|
32 | //{ | |||
|
33 | // SqpApplication app { argc, argv }; | |||
|
34 | // app.setAttribute(Qt::AA_Use96Dpi, true); | |||
|
35 | // QTEST_DISABLE_KEYPAD_NAVIGATION; | |||
|
36 | // QTEST_ADD_GPU_BLACKLIST_SUPPORT; | |||
|
37 | // An_EventList tc; | |||
|
38 | // QTEST_SET_MAIN_SOURCE_PATH; | |||
|
39 | // return QTest::qExec(&tc, argc, argv); | |||
|
40 | //} | |||
|
41 | ||||
|
42 | #include "main.moc" | |||
|
43 | ||||
|
44 | ||||
|
45 | int main(int argc, char* argv[]) | |||
|
46 | { | |||
|
47 | Q_INIT_RESOURCE(sqpguiresources); | |||
|
48 | QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | |||
|
49 | ||||
|
50 | SqpApplication a { argc, argv }; | |||
|
51 | Browser w; | |||
|
52 | sqpApp->catalogueController().add("test"); | |||
|
53 | sqpApp->catalogueController().add("stuff"); | |||
|
54 | sqpApp->catalogueController().add("default"); | |||
|
55 | sqpApp->catalogueController().add("new catalogue", "default"); | |||
|
56 | auto catalogue = sqpApp->catalogueController().add("new catalogue2", "default"); | |||
|
57 | for (auto _ : std::array<char, 1000>()) | |||
|
58 | { | |||
|
59 | static int i = 0; | |||
|
60 | auto event = CatalogueController::make_event_ptr(); | |||
|
61 | event->name = std::string("Event ") + std::to_string(i++); | |||
|
62 | event->tags = {"tag1", "tag2"}; | |||
|
63 | event->products = { CatalogueController::Event_t::Product_t { "Product1", 10., 11. }, | |||
|
64 | CatalogueController::Event_t::Product_t { "Product2", 11., 12. }, | |||
|
65 | CatalogueController::Event_t::Product_t { "Product3", 10.2, 11. } }; | |||
|
66 | catalogue->add(event); | |||
|
67 | } | |||
|
68 | w.show(); | |||
|
69 | return a.exec(); | |||
|
70 | } |
@@ -0,0 +1,218 | |||||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |||
|
2 | <ui version="4.0"> | |||
|
3 | <class>Browser</class> | |||
|
4 | <widget class="QWidget" name="Browser"> | |||
|
5 | <property name="geometry"> | |||
|
6 | <rect> | |||
|
7 | <x>0</x> | |||
|
8 | <y>0</y> | |||
|
9 | <width>708</width> | |||
|
10 | <height>461</height> | |||
|
11 | </rect> | |||
|
12 | </property> | |||
|
13 | <property name="windowTitle"> | |||
|
14 | <string>Catalogues Browser</string> | |||
|
15 | </property> | |||
|
16 | <layout class="QVBoxLayout" name="verticalLayout_4"> | |||
|
17 | <item> | |||
|
18 | <widget class="QSplitter" name="splitter"> | |||
|
19 | <property name="orientation"> | |||
|
20 | <enum>Qt::Horizontal</enum> | |||
|
21 | </property> | |||
|
22 | <widget class="RepositoriesTreeView" name="repositories"> | |||
|
23 | <property name="sizePolicy"> | |||
|
24 | <sizepolicy hsizetype="Maximum" vsizetype="Expanding"> | |||
|
25 | <horstretch>1</horstretch> | |||
|
26 | <verstretch>0</verstretch> | |||
|
27 | </sizepolicy> | |||
|
28 | </property> | |||
|
29 | <property name="rootIsDecorated"> | |||
|
30 | <bool>true</bool> | |||
|
31 | </property> | |||
|
32 | <property name="animated"> | |||
|
33 | <bool>true</bool> | |||
|
34 | </property> | |||
|
35 | <property name="headerHidden"> | |||
|
36 | <bool>true</bool> | |||
|
37 | </property> | |||
|
38 | <attribute name="headerStretchLastSection"> | |||
|
39 | <bool>false</bool> | |||
|
40 | </attribute> | |||
|
41 | </widget> | |||
|
42 | <widget class="QWidget" name="rightPane" native="true"> | |||
|
43 | <property name="sizePolicy"> | |||
|
44 | <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> | |||
|
45 | <horstretch>3</horstretch> | |||
|
46 | <verstretch>0</verstretch> | |||
|
47 | </sizepolicy> | |||
|
48 | </property> | |||
|
49 | <layout class="QVBoxLayout" name="verticalLayout"> | |||
|
50 | <item> | |||
|
51 | <widget class="EventsTreeView" name="events"> | |||
|
52 | <property name="sizePolicy"> | |||
|
53 | <sizepolicy hsizetype="Expanding" vsizetype="Minimum"> | |||
|
54 | <horstretch>0</horstretch> | |||
|
55 | <verstretch>0</verstretch> | |||
|
56 | </sizepolicy> | |||
|
57 | </property> | |||
|
58 | </widget> | |||
|
59 | </item> | |||
|
60 | <item> | |||
|
61 | <widget class="QStackedWidget" name="Infos"> | |||
|
62 | <property name="sizePolicy"> | |||
|
63 | <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> | |||
|
64 | <horstretch>0</horstretch> | |||
|
65 | <verstretch>0</verstretch> | |||
|
66 | </sizepolicy> | |||
|
67 | </property> | |||
|
68 | <property name="currentIndex"> | |||
|
69 | <number>2</number> | |||
|
70 | </property> | |||
|
71 | <widget class="QWidget" name="Repository"> | |||
|
72 | <property name="sizePolicy"> | |||
|
73 | <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> | |||
|
74 | <horstretch>0</horstretch> | |||
|
75 | <verstretch>0</verstretch> | |||
|
76 | </sizepolicy> | |||
|
77 | </property> | |||
|
78 | <layout class="QVBoxLayout" name="verticalLayout_2"> | |||
|
79 | <item> | |||
|
80 | <widget class="QGroupBox" name="groupBox"> | |||
|
81 | <property name="sizePolicy"> | |||
|
82 | <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> | |||
|
83 | <horstretch>0</horstretch> | |||
|
84 | <verstretch>0</verstretch> | |||
|
85 | </sizepolicy> | |||
|
86 | </property> | |||
|
87 | <property name="title"> | |||
|
88 | <string>Repository information</string> | |||
|
89 | </property> | |||
|
90 | <layout class="QGridLayout" name="gridLayout"> | |||
|
91 | <item row="0" column="1"> | |||
|
92 | <layout class="QFormLayout" name="formLayout"> | |||
|
93 | <item row="0" column="0"> | |||
|
94 | <widget class="QLabel" name="label"> | |||
|
95 | <property name="text"> | |||
|
96 | <string>Catalogues</string> | |||
|
97 | </property> | |||
|
98 | </widget> | |||
|
99 | </item> | |||
|
100 | <item row="0" column="1"> | |||
|
101 | <widget class="QLabel" name="catalogues_count"> | |||
|
102 | <property name="text"> | |||
|
103 | <string/> | |||
|
104 | </property> | |||
|
105 | </widget> | |||
|
106 | </item> | |||
|
107 | <item row="1" column="0"> | |||
|
108 | <widget class="QLabel" name="label_3"> | |||
|
109 | <property name="text"> | |||
|
110 | <string>Events</string> | |||
|
111 | </property> | |||
|
112 | </widget> | |||
|
113 | </item> | |||
|
114 | <item row="1" column="1"> | |||
|
115 | <widget class="QLabel" name="rep_events_count"> | |||
|
116 | <property name="text"> | |||
|
117 | <string/> | |||
|
118 | </property> | |||
|
119 | </widget> | |||
|
120 | </item> | |||
|
121 | </layout> | |||
|
122 | </item> | |||
|
123 | </layout> | |||
|
124 | </widget> | |||
|
125 | </item> | |||
|
126 | </layout> | |||
|
127 | </widget> | |||
|
128 | <widget class="QWidget" name="Catalogue"> | |||
|
129 | <property name="sizePolicy"> | |||
|
130 | <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> | |||
|
131 | <horstretch>0</horstretch> | |||
|
132 | <verstretch>0</verstretch> | |||
|
133 | </sizepolicy> | |||
|
134 | </property> | |||
|
135 | <layout class="QGridLayout" name="gridLayout_2"> | |||
|
136 | <item row="0" column="0"> | |||
|
137 | <widget class="QGroupBox" name="groupBox_2"> | |||
|
138 | <property name="sizePolicy"> | |||
|
139 | <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> | |||
|
140 | <horstretch>0</horstretch> | |||
|
141 | <verstretch>0</verstretch> | |||
|
142 | </sizepolicy> | |||
|
143 | </property> | |||
|
144 | <property name="title"> | |||
|
145 | <string>Catalogue</string> | |||
|
146 | </property> | |||
|
147 | <layout class="QGridLayout" name="gridLayout_3"> | |||
|
148 | <item row="0" column="0"> | |||
|
149 | <layout class="QFormLayout" name="formLayout_2"> | |||
|
150 | <item row="0" column="0"> | |||
|
151 | <widget class="QLabel" name="label_2"> | |||
|
152 | <property name="text"> | |||
|
153 | <string>Name</string> | |||
|
154 | </property> | |||
|
155 | </widget> | |||
|
156 | </item> | |||
|
157 | <item row="0" column="1"> | |||
|
158 | <widget class="QLineEdit" name="lineEdit"/> | |||
|
159 | </item> | |||
|
160 | <item row="1" column="0"> | |||
|
161 | <widget class="QLabel" name="label_4"> | |||
|
162 | <property name="text"> | |||
|
163 | <string>Events</string> | |||
|
164 | </property> | |||
|
165 | </widget> | |||
|
166 | </item> | |||
|
167 | <item row="1" column="1"> | |||
|
168 | <widget class="QLabel" name="cat_events_count"> | |||
|
169 | <property name="text"> | |||
|
170 | <string/> | |||
|
171 | </property> | |||
|
172 | </widget> | |||
|
173 | </item> | |||
|
174 | </layout> | |||
|
175 | </item> | |||
|
176 | </layout> | |||
|
177 | </widget> | |||
|
178 | </item> | |||
|
179 | </layout> | |||
|
180 | </widget> | |||
|
181 | <widget class="EventEditor" name="Event"> | |||
|
182 | <property name="sizePolicy"> | |||
|
183 | <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> | |||
|
184 | <horstretch>0</horstretch> | |||
|
185 | <verstretch>0</verstretch> | |||
|
186 | </sizepolicy> | |||
|
187 | </property> | |||
|
188 | <layout class="QGridLayout" name="gridLayout_4"/> | |||
|
189 | </widget> | |||
|
190 | </widget> | |||
|
191 | </item> | |||
|
192 | </layout> | |||
|
193 | </widget> | |||
|
194 | </widget> | |||
|
195 | </item> | |||
|
196 | </layout> | |||
|
197 | </widget> | |||
|
198 | <customwidgets> | |||
|
199 | <customwidget> | |||
|
200 | <class>RepositoriesTreeView</class> | |||
|
201 | <extends>QTreeView</extends> | |||
|
202 | <header location="global">Catalogue2/repositoriestreeview.h</header> | |||
|
203 | </customwidget> | |||
|
204 | <customwidget> | |||
|
205 | <class>EventsTreeView</class> | |||
|
206 | <extends>QTreeView</extends> | |||
|
207 | <header location="global">Catalogue2/eventstreeview.h</header> | |||
|
208 | </customwidget> | |||
|
209 | <customwidget> | |||
|
210 | <class>EventEditor</class> | |||
|
211 | <extends>QWidget</extends> | |||
|
212 | <header location="global">Catalogue2/eventeditor.h</header> | |||
|
213 | <container>1</container> | |||
|
214 | </customwidget> | |||
|
215 | </customwidgets> | |||
|
216 | <resources/> | |||
|
217 | <connections/> | |||
|
218 | </ui> |
@@ -0,0 +1,96 | |||||
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |||
|
2 | <ui version="4.0"> | |||
|
3 | <class>EventEditor</class> | |||
|
4 | <widget class="QWidget" name="EventEditor"> | |||
|
5 | <property name="geometry"> | |||
|
6 | <rect> | |||
|
7 | <x>0</x> | |||
|
8 | <y>0</y> | |||
|
9 | <width>465</width> | |||
|
10 | <height>227</height> | |||
|
11 | </rect> | |||
|
12 | </property> | |||
|
13 | <property name="sizePolicy"> | |||
|
14 | <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> | |||
|
15 | <horstretch>0</horstretch> | |||
|
16 | <verstretch>0</verstretch> | |||
|
17 | </sizepolicy> | |||
|
18 | </property> | |||
|
19 | <property name="windowTitle"> | |||
|
20 | <string>Form</string> | |||
|
21 | </property> | |||
|
22 | <layout class="QVBoxLayout" name="verticalLayout"> | |||
|
23 | <item> | |||
|
24 | <widget class="QGroupBox" name="groupBox_3"> | |||
|
25 | <property name="sizePolicy"> | |||
|
26 | <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> | |||
|
27 | <horstretch>0</horstretch> | |||
|
28 | <verstretch>0</verstretch> | |||
|
29 | </sizepolicy> | |||
|
30 | </property> | |||
|
31 | <property name="title"> | |||
|
32 | <string>Event</string> | |||
|
33 | </property> | |||
|
34 | <layout class="QVBoxLayout" name="verticalLayout_3"> | |||
|
35 | <item> | |||
|
36 | <layout class="QFormLayout" name="formLayout_3"> | |||
|
37 | <item row="0" column="0"> | |||
|
38 | <widget class="QLabel" name="label_5"> | |||
|
39 | <property name="text"> | |||
|
40 | <string>Name</string> | |||
|
41 | </property> | |||
|
42 | </widget> | |||
|
43 | </item> | |||
|
44 | <item row="1" column="0"> | |||
|
45 | <widget class="QLabel" name="label_6"> | |||
|
46 | <property name="text"> | |||
|
47 | <string>Tags</string> | |||
|
48 | </property> | |||
|
49 | </widget> | |||
|
50 | </item> | |||
|
51 | <item row="2" column="0"> | |||
|
52 | <widget class="QLabel" name="label_7"> | |||
|
53 | <property name="text"> | |||
|
54 | <string>Product(s)</string> | |||
|
55 | </property> | |||
|
56 | </widget> | |||
|
57 | </item> | |||
|
58 | <item row="3" column="0"> | |||
|
59 | <widget class="QLabel" name="label_8"> | |||
|
60 | <property name="text"> | |||
|
61 | <string>Start time</string> | |||
|
62 | </property> | |||
|
63 | </widget> | |||
|
64 | </item> | |||
|
65 | <item row="4" column="0"> | |||
|
66 | <widget class="QLabel" name="label_9"> | |||
|
67 | <property name="text"> | |||
|
68 | <string>Stop time</string> | |||
|
69 | </property> | |||
|
70 | </widget> | |||
|
71 | </item> | |||
|
72 | <item row="3" column="1"> | |||
|
73 | <widget class="QDateTimeEdit" name="StartTime"/> | |||
|
74 | </item> | |||
|
75 | <item row="4" column="1"> | |||
|
76 | <widget class="QDateTimeEdit" name="StopTime"/> | |||
|
77 | </item> | |||
|
78 | <item row="0" column="1"> | |||
|
79 | <widget class="QLineEdit" name="EventName"/> | |||
|
80 | </item> | |||
|
81 | <item row="1" column="1"> | |||
|
82 | <widget class="QLineEdit" name="Tags"/> | |||
|
83 | </item> | |||
|
84 | <item row="2" column="1"> | |||
|
85 | <widget class="QLineEdit" name="Products"/> | |||
|
86 | </item> | |||
|
87 | </layout> | |||
|
88 | </item> | |||
|
89 | </layout> | |||
|
90 | </widget> | |||
|
91 | </item> | |||
|
92 | </layout> | |||
|
93 | </widget> | |||
|
94 | <resources/> | |||
|
95 | <connections/> | |||
|
96 | </ui> |
@@ -1,1 +1,1 | |||||
1 | Subproject commit 548ec6a0c922e626003babc8b21a3953b777eae2 |
|
1 | Subproject commit 6b6bb3a15bf899d16716aa0f6d20f1122d67a0a5 |
@@ -12,6 +12,8 | |||||
12 | include/Catalogue2/eventstreeview.h |
|
12 | include/Catalogue2/eventstreeview.h | |
13 | include/Catalogue2/repositoriestreeview.h |
|
13 | include/Catalogue2/repositoriestreeview.h | |
14 | include/Catalogue2/repositoriesmodel.h |
|
14 | include/Catalogue2/repositoriesmodel.h | |
|
15 | include/Catalogue2/browser.h | |||
|
16 | include/Catalogue2/eventeditor.h | |||
15 | # include/Catalogue/CatalogueActionManager.h |
|
17 | # include/Catalogue/CatalogueActionManager.h | |
16 | # include/Catalogue/CatalogueTreeModel.h |
|
18 | # include/Catalogue/CatalogueTreeModel.h | |
17 | # include/Catalogue/CatalogueExplorer.h |
|
19 | # include/Catalogue/CatalogueExplorer.h | |
@@ -82,6 +84,8 | |||||
82 | src/Catalogue2/eventstreeview.cpp |
|
84 | src/Catalogue2/eventstreeview.cpp | |
83 | src/Catalogue2/repositoriestreeview.cpp |
|
85 | src/Catalogue2/repositoriestreeview.cpp | |
84 | src/Catalogue2/repositoriesmodel.cpp |
|
86 | src/Catalogue2/repositoriesmodel.cpp | |
|
87 | src/Catalogue2/browser.cpp | |||
|
88 | src/Catalogue2/eventeditor.cpp | |||
85 | #src/Catalogue/CatalogueEventsWidget.cpp |
|
89 | #src/Catalogue/CatalogueEventsWidget.cpp | |
86 | #src/Catalogue/CatalogueSideBarWidget.cpp |
|
90 | #src/Catalogue/CatalogueSideBarWidget.cpp | |
87 | #src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp |
|
91 | #src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp | |
@@ -154,6 +158,8 QT5_WRAP_UI( | |||||
154 | ui/Visualization/VisualizationWidget.ui |
|
158 | ui/Visualization/VisualizationWidget.ui | |
155 | ui/Visualization/VisualizationZoneWidget.ui |
|
159 | ui/Visualization/VisualizationZoneWidget.ui | |
156 | ui/Visualization/VisualizationMultiZoneSelectionDialog.ui |
|
160 | ui/Visualization/VisualizationMultiZoneSelectionDialog.ui | |
|
161 | ui/Catalogue2/browser.ui | |||
|
162 | ui/Catalogue2/eventeditor.ui | |||
157 | #ui/Catalogue/CatalogueEventsWidget.ui |
|
163 | #ui/Catalogue/CatalogueEventsWidget.ui | |
158 | #ui/Catalogue/CatalogueExplorer.ui |
|
164 | #ui/Catalogue/CatalogueExplorer.ui | |
159 | #ui/Catalogue/CatalogueInspectorWidget.ui |
|
165 | #ui/Catalogue/CatalogueInspectorWidget.ui |
@@ -18,19 +18,12 | |||||
18 | #define EVENTSMODEL_H |
|
18 | #define EVENTSMODEL_H | |
19 | #include <Catalogue/CatalogueController.h> |
|
19 | #include <Catalogue/CatalogueController.h> | |
20 | #include <QAbstractItemModel> |
|
20 | #include <QAbstractItemModel> | |
|
21 | #include <QIcon> | |||
21 | #include <array> |
|
22 | #include <array> | |
22 |
|
23 | |||
23 | class EventsModel : public QAbstractItemModel |
|
24 | class EventsModel : public QAbstractItemModel | |
24 | { |
|
25 | { | |
25 | Q_OBJECT |
|
26 | Q_OBJECT | |
26 | std::vector<CatalogueController::Event_ptr> _events; |
|
|||
27 |
|
||||
28 | enum class ItemType |
|
|||
29 | { |
|
|||
30 | None, |
|
|||
31 | Event, |
|
|||
32 | Product |
|
|||
33 | }; |
|
|||
34 |
|
27 | |||
35 | enum class Columns |
|
28 | enum class Columns | |
36 | { |
|
29 | { | |
@@ -48,8 +41,131 class EventsModel : public QAbstractItemModel | |||||
48 |
|
41 | |||
49 |
|
42 | |||
50 | public: |
|
43 | public: | |
|
44 | enum class ItemType | |||
|
45 | { | |||
|
46 | None, | |||
|
47 | Event, | |||
|
48 | Product | |||
|
49 | }; | |||
|
50 | ||||
|
51 | struct EventsModelItem | |||
|
52 | { | |||
|
53 | ItemType type; | |||
|
54 | std::variant<CatalogueController::Event_ptr, CatalogueController::Product_t> item; | |||
|
55 | EventsModelItem() : type { ItemType::None } {} | |||
|
56 | EventsModelItem(const CatalogueController::Event_ptr& event) | |||
|
57 | : type { ItemType::Event }, item { event }, parent { nullptr }, icon {} | |||
|
58 | { | |||
|
59 | std::transform(std::cbegin(event->products), std::cend(event->products), | |||
|
60 | std::back_inserter(children), | |||
|
61 | [this](auto& product) { return std::make_unique<EventsModelItem>(product, this); }); | |||
|
62 | } | |||
|
63 | ||||
|
64 | EventsModelItem(const CatalogueController::Product_t& product, EventsModelItem* parent) | |||
|
65 | : type { ItemType::Product }, item { product }, parent { parent }, icon {} | |||
|
66 | { | |||
|
67 | } | |||
|
68 | CatalogueController::Event_ptr event() const | |||
|
69 | { | |||
|
70 | return std::get<CatalogueController::Event_ptr>(item); | |||
|
71 | } | |||
|
72 | CatalogueController::Product_t product() const | |||
|
73 | { | |||
|
74 | return std::get<CatalogueController::Product_t>(item); | |||
|
75 | } | |||
|
76 | QVariant data(int col, int role) const | |||
|
77 | { | |||
|
78 | if(role==Qt::DisplayRole) | |||
|
79 | { | |||
|
80 | switch (type) | |||
|
81 | { | |||
|
82 | case ItemType::Product : | |||
|
83 | return data(product(),col); | |||
|
84 | case ItemType::Event: | |||
|
85 | return data(event(),col); | |||
|
86 | default: | |||
|
87 | break; | |||
|
88 | } | |||
|
89 | } | |||
|
90 | return QVariant{}; | |||
|
91 | } | |||
|
92 | QVariant data(const CatalogueController::Event_ptr& event, int col) const | |||
|
93 | { | |||
|
94 | switch (static_cast<Columns>(col)) | |||
|
95 | { | |||
|
96 | case EventsModel::Columns::Name: | |||
|
97 | return QString::fromStdString(event->name); | |||
|
98 | case EventsModel::Columns::TStart: | |||
|
99 | if (auto start = event->startTime()) | |||
|
100 | return DateUtils::dateTime(*start).toString(DATETIME_FORMAT_ONE_LINE); | |||
|
101 | else | |||
|
102 | return QVariant {}; | |||
|
103 | case EventsModel::Columns::TEnd: | |||
|
104 | if (auto stop = event->stopTime()) | |||
|
105 | return DateUtils::dateTime(*stop).toString(DATETIME_FORMAT_ONE_LINE); | |||
|
106 | else | |||
|
107 | return QVariant {}; | |||
|
108 | case EventsModel::Columns::Product: | |||
|
109 | { | |||
|
110 | QStringList eventProductList; | |||
|
111 | for (const auto& evtProduct : event->products) | |||
|
112 | { | |||
|
113 | eventProductList << QString::fromStdString(evtProduct.name); | |||
|
114 | } | |||
|
115 | return eventProductList.join(";"); | |||
|
116 | } | |||
|
117 | case EventsModel::Columns::Tags: | |||
|
118 | { | |||
|
119 | QString tagList; | |||
|
120 | for (const auto& tag : event->tags) | |||
|
121 | { | |||
|
122 | tagList += QString::fromStdString(tag); | |||
|
123 | tagList += ' '; | |||
|
124 | } | |||
|
125 | return tagList; | |||
|
126 | } | |||
|
127 | default: | |||
|
128 | break; | |||
|
129 | } | |||
|
130 | return QVariant {}; | |||
|
131 | } | |||
|
132 | ||||
|
133 | QVariant data(const CatalogueController::Product_t& product, int col) const | |||
|
134 | { | |||
|
135 | switch (static_cast<Columns>(col)) | |||
|
136 | { | |||
|
137 | case EventsModel::Columns::Name: | |||
|
138 | return QString::fromStdString(product.name); | |||
|
139 | case EventsModel::Columns::TStart: | |||
|
140 | return DateUtils::dateTime(product.startTime).toString(DATETIME_FORMAT_ONE_LINE); | |||
|
141 | case EventsModel::Columns::TEnd: | |||
|
142 | return DateUtils::dateTime(product.stopTime).toString(DATETIME_FORMAT_ONE_LINE); | |||
|
143 | case EventsModel::Columns::Product: | |||
|
144 | return QString::fromStdString(product.name); | |||
|
145 | default: | |||
|
146 | break; | |||
|
147 | } | |||
|
148 | return QVariant {}; | |||
|
149 | } | |||
|
150 | ||||
|
151 | QString text() const | |||
|
152 | { | |||
|
153 | if (type == ItemType::Event) | |||
|
154 | return QString::fromStdString(event()->name); | |||
|
155 | if (type == ItemType::Product) | |||
|
156 | return QString::fromStdString(product().name); | |||
|
157 | return QString(); | |||
|
158 | } | |||
|
159 | std::vector<std::unique_ptr<EventsModelItem>> children; | |||
|
160 | EventsModelItem* parent = nullptr; | |||
|
161 | QIcon icon; | |||
|
162 | }; | |||
51 | EventsModel(QObject* parent = nullptr); |
|
163 | EventsModel(QObject* parent = nullptr); | |
52 |
|
164 | |||
|
165 | static inline EventsModelItem* to_item(const QModelIndex& index) | |||
|
166 | { | |||
|
167 | return static_cast<EventsModelItem*>(index.internalPointer()); | |||
|
168 | } | |||
53 |
|
169 | |||
54 | ItemType type(const QModelIndex& index) const; |
|
170 | ItemType type(const QModelIndex& index) const; | |
55 |
|
171 | |||
@@ -57,8 +173,6 public: | |||||
57 | { |
|
173 | { | |
58 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; |
|
174 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; | |
59 | } |
|
175 | } | |
60 | QVariant data(int col, const CatalogueController::Event_ptr& event) const; |
|
|||
61 | QVariant data(int col, const CatalogueController::Product_t& product) const; |
|
|||
62 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
|
176 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | |
63 |
|
177 | |||
64 | QModelIndex index( |
|
178 | QModelIndex index( | |
@@ -79,9 +193,14 public slots: | |||||
79 | void setEvents(std::vector<CatalogueController::Event_ptr> events) |
|
193 | void setEvents(std::vector<CatalogueController::Event_ptr> events) | |
80 | { |
|
194 | { | |
81 | beginResetModel(); |
|
195 | beginResetModel(); | |
82 | std::swap(_events, events); |
|
196 | _items.clear(); | |
|
197 | std::transform(std::begin(events), std::end(events), std::back_inserter(_items), | |||
|
198 | [](const auto& event) { return std::make_unique<EventsModelItem>(event); }); | |||
83 | endResetModel(); |
|
199 | endResetModel(); | |
84 | } |
|
200 | } | |
|
201 | ||||
|
202 | private: | |||
|
203 | std::vector<std::unique_ptr<EventsModelItem>> _items; | |||
85 | }; |
|
204 | }; | |
86 |
|
205 | |||
87 | #endif // EVENTSMODEL_H |
|
206 | #endif // EVENTSMODEL_H |
@@ -27,8 +27,15 class EventsTreeView : public QTreeView | |||||
27 | public: |
|
27 | public: | |
28 | EventsTreeView(QWidget* parent = nullptr); |
|
28 | EventsTreeView(QWidget* parent = nullptr); | |
29 |
|
29 | |||
|
30 | signals: | |||
|
31 | void eventSelected(const CatalogueController::Event_ptr& event); | |||
|
32 | void productSelected(const CatalogueController::Product_t& product, const CatalogueController::Event_ptr& event); | |||
|
33 | ||||
30 | public slots: |
|
34 | public slots: | |
31 | void setEvents(std::vector<CatalogueController::Event_ptr> events); |
|
35 | void setEvents(std::vector<CatalogueController::Event_ptr> events); | |
|
36 | ||||
|
37 | private: | |||
|
38 | void _itemSelected(const QModelIndex& index); | |||
32 | }; |
|
39 | }; | |
33 |
|
40 | |||
34 | #endif // EVENTSTREEVIEW_H |
|
41 | #endif // EVENTSTREEVIEW_H |
@@ -26,6 +26,8 class RepositoriesModel : public QAbstractItemModel | |||||
26 | Q_OBJECT |
|
26 | Q_OBJECT | |
27 |
|
27 | |||
28 |
|
28 | |||
|
29 | ||||
|
30 | public: | |||
29 | enum class ItemType |
|
31 | enum class ItemType | |
30 | { |
|
32 | { | |
31 | None, |
|
33 | None, | |
@@ -67,12 +69,11 class RepositoriesModel : public QAbstractItemModel | |||||
67 |
|
69 | |||
68 | std::vector<std::unique_ptr<RepoModelItem>> _items; |
|
70 | std::vector<std::unique_ptr<RepoModelItem>> _items; | |
69 |
|
71 | |||
70 |
inline RepoModelItem* to_item(const QModelIndex& index) |
|
72 | static inline RepoModelItem* to_item(const QModelIndex& index) | |
71 | { |
|
73 | { | |
72 | return static_cast<RepoModelItem*>(index.internalPointer()); |
|
74 | return static_cast<RepoModelItem*>(index.internalPointer()); | |
73 | } |
|
75 | } | |
74 |
|
76 | |||
75 | public: |
|
|||
76 | RepositoriesModel(QObject* parent = nullptr); |
|
77 | RepositoriesModel(QObject* parent = nullptr); | |
77 |
|
78 | |||
78 | ItemType type(const QModelIndex& index) const; |
|
79 | ItemType type(const QModelIndex& index) const; |
@@ -17,9 +17,9 | |||||
17 | #ifndef REPOSITORIESTREEVIEW_H |
|
17 | #ifndef REPOSITORIESTREEVIEW_H | |
18 | #define REPOSITORIESTREEVIEW_H |
|
18 | #define REPOSITORIESTREEVIEW_H | |
19 |
|
19 | |||
|
20 | #include <Catalogue2/repositoriesmodel.h> | |||
20 | #include <QObject> |
|
21 | #include <QObject> | |
21 | #include <QTreeView> |
|
22 | #include <QTreeView> | |
22 | #include <Catalogue2/repositoriesmodel.h> |
|
|||
23 |
|
23 | |||
24 | class RepositoriesTreeView : public QTreeView |
|
24 | class RepositoriesTreeView : public QTreeView | |
25 | { |
|
25 | { | |
@@ -28,14 +28,25 public: | |||||
28 | RepositoriesTreeView(QWidget* parent = nullptr); |
|
28 | RepositoriesTreeView(QWidget* parent = nullptr); | |
29 |
|
29 | |||
30 | public slots: |
|
30 | public slots: | |
31 | void refresh() |
|
31 | void refresh() { static_cast<RepositoriesModel*>(model())->refresh(); } | |
32 | { |
|
|||
33 | static_cast<RepositoriesModel*>(model())->refresh(); |
|
|||
34 | } |
|
|||
35 |
|
32 | |||
36 | signals: |
|
33 | signals: | |
37 | void repositorySelected(const QString& repository); |
|
34 | void repositorySelected(const QString& repository); | |
|
35 | void catalogueSelected(const CatalogueController::Catalogue_ptr& catalogue); | |||
38 |
|
36 | |||
|
37 | private: | |||
|
38 | void _itemSelected(const QModelIndex& index) | |||
|
39 | { | |||
|
40 | auto item = RepositoriesModel::to_item(index); | |||
|
41 | if (item->type == RepositoriesModel::ItemType::Repository) | |||
|
42 | { | |||
|
43 | emit repositorySelected(item->repository()); | |||
|
44 | } | |||
|
45 | else if (item->type == RepositoriesModel::ItemType::Catalogue) | |||
|
46 | { | |||
|
47 | emit catalogueSelected(item->catalogue()); | |||
|
48 | } | |||
|
49 | } | |||
39 | }; |
|
50 | }; | |
40 |
|
51 | |||
41 | #endif // REPOSITORIESTREEVIEW_H |
|
52 | #endif // REPOSITORIESTREEVIEW_H |
@@ -16,100 +16,24 | |||||
16 | */ |
|
16 | */ | |
17 | #include "Catalogue2/eventsmodel.h" |
|
17 | #include "Catalogue2/eventsmodel.h" | |
18 | #include <SqpApplication.h> |
|
18 | #include <SqpApplication.h> | |
|
19 | #include <Common/containers.h> | |||
19 |
|
20 | |||
20 | EventsModel::EventsModel(QObject* parent) : QAbstractItemModel(parent) {} |
|
21 | EventsModel::EventsModel(QObject* parent) : QAbstractItemModel(parent) {} | |
21 |
|
22 | |||
22 | EventsModel::ItemType EventsModel::type(const QModelIndex& index) const |
|
23 | EventsModel::ItemType EventsModel::type(const QModelIndex& index) const | |
23 | { |
|
24 | { | |
24 | if (!index.isValid()) |
|
25 | if (EventsModelItem* item = to_item(index)) | |
25 | { |
|
26 | { | |
26 |
return |
|
27 | return item->type; | |
27 | } |
|
|||
28 | else if (index.internalPointer() == nullptr) |
|
|||
29 | { |
|
|||
30 | return ItemType::Event; |
|
|||
31 | } |
|
|||
32 | else |
|
|||
33 | { |
|
|||
34 | return ItemType::Product; |
|
|||
35 | } |
|
28 | } | |
36 | } |
|
29 | return ItemType::None; | |
37 |
|
||||
38 | QVariant EventsModel::data(int col, const CatalogueController::Event_ptr& event) const |
|
|||
39 | { |
|
|||
40 | switch (static_cast<Columns>(col)) |
|
|||
41 | { |
|
|||
42 | case EventsModel::Columns::Name: |
|
|||
43 | return QString::fromStdString(event->name); |
|
|||
44 | case EventsModel::Columns::TStart: |
|
|||
45 | if (auto start = event->startTime()) |
|
|||
46 | return DateUtils::dateTime(*start).toString(DATETIME_FORMAT_ONE_LINE); |
|
|||
47 | else |
|
|||
48 | return QVariant {}; |
|
|||
49 | case EventsModel::Columns::TEnd: |
|
|||
50 | if (auto stop = event->stopTime()) |
|
|||
51 | return DateUtils::dateTime(*stop).toString(DATETIME_FORMAT_ONE_LINE); |
|
|||
52 | else |
|
|||
53 | return QVariant {}; |
|
|||
54 | case EventsModel::Columns::Product: |
|
|||
55 | { |
|
|||
56 | QStringList eventProductList; |
|
|||
57 | for (const auto& evtProduct : event->products) |
|
|||
58 | { |
|
|||
59 | eventProductList << QString::fromStdString(evtProduct.name); |
|
|||
60 | } |
|
|||
61 | return eventProductList.join(";"); |
|
|||
62 | } |
|
|||
63 | case EventsModel::Columns::Tags: |
|
|||
64 | { |
|
|||
65 | QString tagList; |
|
|||
66 | for (const auto& tag : event->tags) |
|
|||
67 | { |
|
|||
68 | tagList += QString::fromStdString(tag); |
|
|||
69 | tagList += ' '; |
|
|||
70 | } |
|
|||
71 | return tagList; |
|
|||
72 | } |
|
|||
73 | default: |
|
|||
74 | break; |
|
|||
75 | } |
|
|||
76 | return QVariant {}; |
|
|||
77 | } |
|
|||
78 |
|
||||
79 | QVariant EventsModel::data(int col, const CatalogueController::Product_t& product) const |
|
|||
80 | { |
|
|||
81 | switch (static_cast<Columns>(col)) |
|
|||
82 | { |
|
|||
83 | case EventsModel::Columns::Name: |
|
|||
84 | return QString::fromStdString(product.name); |
|
|||
85 | case EventsModel::Columns::TStart: |
|
|||
86 | return DateUtils::dateTime(product.startTime).toString(DATETIME_FORMAT_ONE_LINE); |
|
|||
87 | case EventsModel::Columns::TEnd: |
|
|||
88 | return DateUtils::dateTime(product.stopTime).toString(DATETIME_FORMAT_ONE_LINE); |
|
|||
89 | case EventsModel::Columns::Product: |
|
|||
90 | return QString::fromStdString(product.name); |
|
|||
91 | default: |
|
|||
92 | break; |
|
|||
93 | } |
|
|||
94 | return QVariant {}; |
|
|||
95 | } |
|
30 | } | |
96 |
|
31 | |||
97 | QVariant EventsModel::data(const QModelIndex& index, int role) const |
|
32 | QVariant EventsModel::data(const QModelIndex& index, int role) const | |
98 | { |
|
33 | { | |
99 | if (_events.size() && index.isValid() && role == Qt::DisplayRole) |
|
34 | if (index.isValid()) | |
100 | { |
|
35 | { | |
101 | switch (type(index)) |
|
36 | return to_item(index)->data(index.column(),role); | |
102 | { |
|
|||
103 | case EventsModel::ItemType::Event: |
|
|||
104 | return data(index.column(), _events[index.row()]); |
|
|||
105 | case EventsModel::ItemType::Product: |
|
|||
106 | { |
|
|||
107 | auto event = static_cast<CatalogueController::Event_t*>(index.internalPointer()); |
|
|||
108 | return data(index.column(), event->products[index.row()]); |
|
|||
109 | } |
|
|||
110 | default: |
|
|||
111 | break; |
|
|||
112 | } |
|
|||
113 | } |
|
37 | } | |
114 | return QVariant {}; |
|
38 | return QVariant {}; | |
115 | } |
|
39 | } | |
@@ -123,16 +47,12 QModelIndex EventsModel::index(int row, int column, const QModelIndex& parent) c | |||||
123 |
|
47 | |||
124 | switch (type(parent)) |
|
48 | switch (type(parent)) | |
125 | { |
|
49 | { | |
126 |
case |
|
50 | case ItemType::None: // is an event | |
127 |
return createIndex(row, column, |
|
51 | return createIndex(row, column, _items[row].get()); | |
128 |
case |
|
52 | case ItemType::Event: // is a product | |
129 | { |
|
53 | return createIndex(row, column, to_item(parent)->children[row].get()); | |
130 | return createIndex(row, column, _events[parent.row()].get()); |
|
54 | case ItemType::Product: | |
131 | } |
|
55 | QModelIndex(); | |
132 | case EventsModel::ItemType::Product: |
|
|||
133 | break; |
|
|||
134 | default: |
|
|||
135 | break; |
|
|||
136 | } |
|
56 | } | |
137 |
|
57 | |||
138 | return QModelIndex(); |
|
58 | return QModelIndex(); | |
@@ -140,23 +60,11 QModelIndex EventsModel::index(int row, int column, const QModelIndex& parent) c | |||||
140 |
|
60 | |||
141 | QModelIndex EventsModel::parent(const QModelIndex& index) const |
|
61 | QModelIndex EventsModel::parent(const QModelIndex& index) const | |
142 | { |
|
62 | { | |
143 | switch (type(index)) |
|
63 | auto item = to_item(index); | |
|
64 | if (item->type == ItemType::Product) | |||
144 | { |
|
65 | { | |
145 | case EventsModel::ItemType::None: |
|
66 | auto repoIndex = SciQLop::containers::index_of(_items, item->parent); | |
146 | break; |
|
67 | return createIndex(repoIndex, 0, item->parent); | |
147 | case EventsModel::ItemType::Event: |
|
|||
148 | break; |
|
|||
149 | case EventsModel::ItemType::Product: |
|
|||
150 | { |
|
|||
151 | auto parentEvent = static_cast<CatalogueController::Event_t*>(index.internalPointer()); |
|
|||
152 | auto pos = std::distance(std::cbegin(_events), |
|
|||
153 | std::find_if(std::cbegin(_events), std::cend(_events), |
|
|||
154 | [parentEvent](auto event) { return event.get() == parentEvent; })); |
|
|||
155 | if (pos >= 0 && pos < _events.size()) |
|
|||
156 | { |
|
|||
157 | return createIndex(pos, 0); |
|
|||
158 | } |
|
|||
159 | } |
|
|||
160 | } |
|
68 | } | |
161 | return QModelIndex(); |
|
69 | return QModelIndex(); | |
162 | } |
|
70 | } | |
@@ -167,17 +75,13 int EventsModel::rowCount(const QModelIndex& parent) const | |||||
167 | { |
|
75 | { | |
168 | return 0; |
|
76 | return 0; | |
169 | } |
|
77 | } | |
170 |
|
||||
171 | switch (type(parent)) |
|
78 | switch (type(parent)) | |
172 | { |
|
79 | { | |
173 |
case |
|
80 | case ItemType::None: | |
174 |
return _ |
|
81 | return _items.size(); | |
175 |
case |
|
82 | case ItemType::Event: | |
176 |
return |
|
83 | return to_item(parent)->children.size(); | |
177 | break; |
|
84 | case ItemType::Product: | |
178 | case EventsModel::ItemType::Product: |
|
|||
179 | break; |
|
|||
180 | default: |
|
|||
181 | break; |
|
85 | break; | |
182 | } |
|
86 | } | |
183 | return 0; |
|
87 | return 0; |
@@ -20,9 +20,26 | |||||
20 | EventsTreeView::EventsTreeView(QWidget* parent) : QTreeView(parent) |
|
20 | EventsTreeView::EventsTreeView(QWidget* parent) : QTreeView(parent) | |
21 | { |
|
21 | { | |
22 | this->setModel(new EventsModel()); |
|
22 | this->setModel(new EventsModel()); | |
|
23 | connect(this->selectionModel(), &QItemSelectionModel::currentChanged, [this](const QModelIndex ¤t, const QModelIndex &previous){ | |||
|
24 | Q_UNUSED(previous); | |||
|
25 | this->_itemSelected(current); | |||
|
26 | }); | |||
23 | } |
|
27 | } | |
24 |
|
28 | |||
25 | void EventsTreeView::setEvents(std::vector<CatalogueController::Event_ptr> events) |
|
29 | void EventsTreeView::setEvents(std::vector<CatalogueController::Event_ptr> events) | |
26 | { |
|
30 | { | |
27 | static_cast<EventsModel*>(this->model())->setEvents(events); |
|
31 | static_cast<EventsModel*>(this->model())->setEvents(events); | |
28 | } |
|
32 | } | |
|
33 | ||||
|
34 | void EventsTreeView::_itemSelected(const QModelIndex &index) | |||
|
35 | { | |||
|
36 | auto item = EventsModel::to_item(index); | |||
|
37 | if (item->type == EventsModel::ItemType::Event) | |||
|
38 | { | |||
|
39 | emit eventSelected(item->event()); | |||
|
40 | } | |||
|
41 | else if (item->type == EventsModel::ItemType::Product) | |||
|
42 | { | |||
|
43 | emit productSelected(item->product(), item->parent->event()); | |||
|
44 | } | |||
|
45 | } |
@@ -22,6 +22,10 | |||||
22 | RepositoriesModel::RepositoriesModel(QObject* parent) : QAbstractItemModel(parent) |
|
22 | RepositoriesModel::RepositoriesModel(QObject* parent) : QAbstractItemModel(parent) | |
23 | { |
|
23 | { | |
24 | refresh(); |
|
24 | refresh(); | |
|
25 | connect(&(sqpApp->catalogueController()), &CatalogueController::repositoryAdded, this, | |||
|
26 | [this](const QString&) { this->refresh(); }); | |||
|
27 | connect(&(sqpApp->catalogueController()), &CatalogueController::catalogueAdded, this, | |||
|
28 | [this](const CatalogueController::Catalogue_ptr&, const QString&) { this->refresh(); }); | |||
25 | } |
|
29 | } | |
26 |
|
30 | |||
27 | RepositoriesModel::ItemType RepositoriesModel::type(const QModelIndex& index) const |
|
31 | RepositoriesModel::ItemType RepositoriesModel::type(const QModelIndex& index) const |
@@ -22,6 +22,10 RepositoriesTreeView::RepositoriesTreeView(QWidget* parent) : QTreeView(parent) | |||||
22 | auto m = model(); |
|
22 | auto m = model(); | |
23 | this->setModel(new RepositoriesModel(this)); |
|
23 | this->setModel(new RepositoriesModel(this)); | |
24 | delete m; |
|
24 | delete m; | |
|
25 | connect(this->selectionModel(), &QItemSelectionModel::currentChanged, [this](const QModelIndex ¤t, const QModelIndex &previous){ | |||
|
26 | Q_UNUSED(previous); | |||
|
27 | this->_itemSelected(current); | |||
|
28 | }); | |||
25 | } |
|
29 | } | |
26 |
|
30 | |||
27 |
|
31 |
@@ -5,3 +5,4 declare_test(multiple_sync_graph multiple_sync_graph multiple_sync_graph/main.cp | |||||
5 |
|
5 | |||
6 | declare_manual_test(event_list event_list catalogue/event_list/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test") |
|
6 | declare_manual_test(event_list event_list catalogue/event_list/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test") | |
7 | declare_manual_test(repository_list repository_list catalogue/repository_list/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test") |
|
7 | declare_manual_test(repository_list repository_list catalogue/repository_list/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test") | |
|
8 | declare_manual_test(catalogue_browser catalogue_browser catalogue/browser/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test") |
General Comments 0
You need to be logged in to leave comments.
Login now