@@ -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 |
@@ -1,188 +1,194 | |||
|
1 | 1 | FILE (GLOB_RECURSE gui_SRCS |
|
2 | 2 | |
|
3 | 3 | include/DataSource/DataSourceWidget.h |
|
4 | 4 | include/DataSource/DataSourceTreeWidget.h |
|
5 | 5 | include/DataSource/DataSourceTreeWidgetItem.h |
|
6 | 6 | include/DataSource/DataSourceTreeWidgetHelper.h |
|
7 | 7 | include/SqpApplication.h |
|
8 | 8 | include/Common/ColorUtils.h |
|
9 | 9 | include/Common/VisualizationDef.h |
|
10 | 10 | include/SidePane/SqpSidePane.h |
|
11 | 11 | include/Catalogue2/eventsmodel.h |
|
12 | 12 | include/Catalogue2/eventstreeview.h |
|
13 | 13 | include/Catalogue2/repositoriestreeview.h |
|
14 | 14 | include/Catalogue2/repositoriesmodel.h |
|
15 | include/Catalogue2/browser.h | |
|
16 | include/Catalogue2/eventeditor.h | |
|
15 | 17 | # include/Catalogue/CatalogueActionManager.h |
|
16 | 18 | # include/Catalogue/CatalogueTreeModel.h |
|
17 | 19 | # include/Catalogue/CatalogueExplorer.h |
|
18 | 20 | # include/Catalogue/CatalogueSideBarWidget.h |
|
19 | 21 | # include/Catalogue/CatalogueInspectorWidget.h |
|
20 | 22 | # include/Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h |
|
21 | 23 | # include/Catalogue/CatalogueTreeItems/CatalogueTreeItem.h |
|
22 | 24 | # include/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h |
|
23 | 25 | # include/Catalogue/CatalogueEventsModel.h |
|
24 | 26 | # include/Catalogue/CatalogueEventsWidget.h |
|
25 | 27 | # include/Catalogue/CatalogueExplorerHelper.h |
|
26 | 28 | include/Visualization/VisualizationGraphHelper.h |
|
27 | 29 | include/Visualization/VisualizationTabWidget.h |
|
28 | 30 | include/Visualization/VisualizationDefs.h |
|
29 | 31 | include/Visualization/QCustomPlotSynchronizer.h |
|
30 | 32 | include/Visualization/QCPColorMapIterator.h |
|
31 | 33 | include/Visualization/operations/GenerateVariableMenuOperation.h |
|
32 | 34 | include/Visualization/operations/RemoveVariableOperation.h |
|
33 | 35 | include/Visualization/operations/FindVariableOperation.h |
|
34 | 36 | include/Visualization/operations/MenuBuilder.h |
|
35 | 37 | include/Visualization/operations/RescaleAxeOperation.h |
|
36 | 38 | include/Visualization/PlottablesRenderingUtils.h |
|
37 | 39 | include/Visualization/IVisualizationWidgetVisitor.h |
|
38 | 40 | include/Visualization/VisualizationGraphWidget.h |
|
39 | 41 | include/Visualization/IVisualizationWidget.h |
|
40 | 42 | include/Visualization/IVariableContainer.h |
|
41 | 43 | include/Visualization/SqpColorScale.h |
|
42 | 44 | include/Visualization/VisualizationWidget.h |
|
43 | 45 | include/Visualization/VisualizationZoneWidget.h |
|
44 | 46 | include/Visualization/VisualizationMultiZoneSelectionDialog.h |
|
45 | 47 | include/Visualization/VisualizationGraphRenderingDelegate.h |
|
46 | 48 | include/Visualization/AxisRenderingUtils.h |
|
47 | 49 | include/Visualization/VisualizationSelectionZoneItem.h |
|
48 | 50 | include/Visualization/VisualizationDragWidget.h |
|
49 | 51 | include/Visualization/VisualizationActionManager.h |
|
50 | 52 | include/Visualization/IGraphSynchronizer.h |
|
51 | 53 | include/Visualization/ColorScaleEditor.h |
|
52 | 54 | include/Visualization/MacScrollBarStyle.h |
|
53 | 55 | include/Visualization/VisualizationSelectionZoneManager.h |
|
54 | 56 | include/Visualization/qcustomplot.h |
|
55 | 57 | include/Visualization/VisualizationDragDropContainer.h |
|
56 | 58 | include/Visualization/VisualizationCursorItem.h |
|
57 | 59 | include/Settings/SqpSettingsDialog.h |
|
58 | 60 | include/Settings/SqpSettingsGeneralWidget.h |
|
59 | 61 | include/Variable/VariableMenuHeaderWidget.h |
|
60 | 62 | include/Variable/VariableInspectorTableView.h |
|
61 | 63 | include/Variable/VariableInspectorWidget.h |
|
62 | 64 | include/Variable/RenameVariableDialog.h |
|
63 | 65 | include/TimeWidget/TimeWidget.h |
|
64 | 66 | include/DragAndDrop/DragDropScroller.h |
|
65 | 67 | include/DragAndDrop/DragDropTabSwitcher.h |
|
66 | 68 | include/DragAndDrop/DragDropGuiController.h |
|
67 | 69 | include/Actions/FilteringAction.h |
|
68 | 70 | include/Actions/ActionsGuiController.h |
|
69 | 71 | include/Actions/SelectionZoneAction.h |
|
70 | 72 | |
|
71 | 73 | |
|
72 | 74 | |
|
73 | 75 | |
|
74 | 76 | src/DataSource/DataSourceTreeWidgetItem.cpp |
|
75 | 77 | src/DataSource/DataSourceWidget.cpp |
|
76 | 78 | src/DataSource/DataSourceTreeWidget.cpp |
|
77 | 79 | src/DataSource/DataSourceTreeWidgetHelper.cpp |
|
78 | 80 | src/Common/ColorUtils.cpp |
|
79 | 81 | src/Common/VisualizationDef.cpp |
|
80 | 82 | src/SidePane/SqpSidePane.cpp |
|
81 | 83 | src/Catalogue2/eventsmodel.cpp |
|
82 | 84 | src/Catalogue2/eventstreeview.cpp |
|
83 | 85 | src/Catalogue2/repositoriestreeview.cpp |
|
84 | 86 | src/Catalogue2/repositoriesmodel.cpp |
|
87 | src/Catalogue2/browser.cpp | |
|
88 | src/Catalogue2/eventeditor.cpp | |
|
85 | 89 | #src/Catalogue/CatalogueEventsWidget.cpp |
|
86 | 90 | #src/Catalogue/CatalogueSideBarWidget.cpp |
|
87 | 91 | #src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp |
|
88 | 92 | #src/Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.cpp |
|
89 | 93 | #src/Catalogue/CatalogueTreeItems/CatalogueTreeItem.cpp |
|
90 | 94 | #src/Catalogue/CatalogueExplorerHelper.cpp |
|
91 | 95 | #src/Catalogue/CatalogueExplorer.cpp |
|
92 | 96 | #src/Catalogue/CatalogueTreeModel.cpp |
|
93 | 97 | #src/Catalogue/CatalogueInspectorWidget.cpp |
|
94 | 98 | #src/Catalogue/CatalogueEventsModel.cpp |
|
95 | 99 | #src/Catalogue/CatalogueActionManager.cpp |
|
96 | 100 | src/Visualization/VisualizationDragDropContainer.cpp |
|
97 | 101 | src/Visualization/VisualizationTabWidget.cpp |
|
98 | 102 | src/Visualization/VisualizationWidget.cpp |
|
99 | 103 | src/Visualization/MacScrollBarStyle.cpp |
|
100 | 104 | src/Visualization/VisualizationCursorItem.cpp |
|
101 | 105 | src/Visualization/operations/MenuBuilder.cpp |
|
102 | 106 | src/Visualization/operations/RemoveVariableOperation.cpp |
|
103 | 107 | src/Visualization/operations/FindVariableOperation.cpp |
|
104 | 108 | src/Visualization/operations/GenerateVariableMenuOperation.cpp |
|
105 | 109 | src/Visualization/operations/RescaleAxeOperation.cpp |
|
106 | 110 | src/Visualization/AxisRenderingUtils.cpp |
|
107 | 111 | src/Visualization/PlottablesRenderingUtils.cpp |
|
108 | 112 | src/Visualization/VisualizationGraphRenderingDelegate.cpp |
|
109 | 113 | src/Visualization/VisualizationSelectionZoneManager.cpp |
|
110 | 114 | src/Visualization/QCPColorMapIterator.cpp |
|
111 | 115 | src/Visualization/ColorScaleEditor.cpp |
|
112 | 116 | src/Visualization/VisualizationGraphHelper.cpp |
|
113 | 117 | src/Visualization/VisualizationGraphWidget.cpp |
|
114 | 118 | src/Visualization/VisualizationDragWidget.cpp |
|
115 | 119 | src/Visualization/VisualizationZoneWidget.cpp |
|
116 | 120 | src/Visualization/VisualizationActionManager.cpp |
|
117 | 121 | src/Visualization/VisualizationSelectionZoneItem.cpp |
|
118 | 122 | src/Visualization/QCustomPlotSynchronizer.cpp |
|
119 | 123 | src/Visualization/qcustomplot.cpp |
|
120 | 124 | src/Visualization/VisualizationMultiZoneSelectionDialog.cpp |
|
121 | 125 | src/Visualization/SqpColorScale.cpp |
|
122 | 126 | src/Settings/SqpSettingsGeneralWidget.cpp |
|
123 | 127 | src/Settings/SqpSettingsDialog.cpp |
|
124 | 128 | src/SqpApplication.cpp |
|
125 | 129 | src/Variable/VariableInspectorWidget.cpp |
|
126 | 130 | src/Variable/VariableMenuHeaderWidget.cpp |
|
127 | 131 | src/Variable/RenameVariableDialog.cpp |
|
128 | 132 | src/Variable/VariableInspectorTableView.cpp |
|
129 | 133 | src/TimeWidget/TimeWidget.cpp |
|
130 | 134 | src/DragAndDrop/DragDropScroller.cpp |
|
131 | 135 | src/DragAndDrop/DragDropTabSwitcher.cpp |
|
132 | 136 | src/DragAndDrop/DragDropGuiController.cpp |
|
133 | 137 | src/Actions/ActionsGuiController.cpp |
|
134 | 138 | src/Actions/SelectionZoneAction.cpp |
|
135 | 139 | src/Actions/FilteringAction.cpp |
|
136 | 140 | |
|
137 | 141 | ./resources/sqpguiresources.qrc |
|
138 | 142 | ) |
|
139 | 143 | |
|
140 | 144 | |
|
141 | 145 | QT5_WRAP_UI( |
|
142 | 146 | UiGenerated_SRCS |
|
143 | 147 | ui/DataSource/DataSourceWidget.ui |
|
144 | 148 | ui/Settings/SqpSettingsDialog.ui |
|
145 | 149 | ui/Settings/SqpSettingsGeneralWidget.ui |
|
146 | 150 | ui/SidePane/SqpSidePane.ui |
|
147 | 151 | ui/TimeWidget/TimeWidget.ui |
|
148 | 152 | ui/Variable/RenameVariableDialog.ui |
|
149 | 153 | ui/Variable/VariableInspectorWidget.ui |
|
150 | 154 | ui/Variable/VariableMenuHeaderWidget.ui |
|
151 | 155 | ui/Visualization/ColorScaleEditor.ui |
|
152 | 156 | ui/Visualization/VisualizationGraphWidget.ui |
|
153 | 157 | ui/Visualization/VisualizationTabWidget.ui |
|
154 | 158 | ui/Visualization/VisualizationWidget.ui |
|
155 | 159 | ui/Visualization/VisualizationZoneWidget.ui |
|
156 | 160 | ui/Visualization/VisualizationMultiZoneSelectionDialog.ui |
|
161 | ui/Catalogue2/browser.ui | |
|
162 | ui/Catalogue2/eventeditor.ui | |
|
157 | 163 | #ui/Catalogue/CatalogueEventsWidget.ui |
|
158 | 164 | #ui/Catalogue/CatalogueExplorer.ui |
|
159 | 165 | #ui/Catalogue/CatalogueInspectorWidget.ui |
|
160 | 166 | #ui/Catalogue/CatalogueSideBarWidget.ui |
|
161 | 167 | ) |
|
162 | 168 | |
|
163 | 169 | add_library(sciqlopgui ${gui_SRCS} ${UiGenerated_SRCS}) |
|
164 | 170 | SET_TARGET_PROPERTIES(sciqlopgui PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) |
|
165 | 171 | |
|
166 | 172 | target_include_directories(sciqlopgui PUBLIC |
|
167 | 173 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
|
168 | 174 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/Visualization> |
|
169 | 175 | $<INSTALL_INTERFACE:include/SciQLOP> |
|
170 | 176 | ) |
|
171 | 177 | |
|
172 | 178 | target_link_libraries(sciqlopgui PUBLIC |
|
173 | 179 | Qt5::Widgets |
|
174 | 180 | Qt5::PrintSupport |
|
175 | 181 | Qt5::Svg |
|
176 | 182 | sciqlopcore |
|
177 | 183 | ) |
|
178 | 184 | |
|
179 | 185 | install(TARGETS sciqlopgui EXPORT SciQLOPGuiConfig |
|
180 | 186 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
|
181 | 187 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
|
182 | 188 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
|
183 | 189 | |
|
184 | 190 | install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SciQLOP) |
|
185 | 191 | install(EXPORT SciQLOPGuiConfig DESTINATION share/SciQLOPGui/cmake) |
|
186 | 192 | export(TARGETS sciqlopgui FILE SciQLOPGuiConfig.cmake) |
|
187 | 193 | |
|
188 | 194 | subdirs(tests) |
@@ -1,87 +1,206 | |||
|
1 | 1 | /* |
|
2 | 2 | This file is part of SciQLop. |
|
3 | 3 | |
|
4 | 4 | SciQLop is free software: you can redistribute it and/or modify |
|
5 | 5 | it under the terms of the GNU General Public License as published by |
|
6 | 6 | the Free Software Foundation, either version 3 of the License, or |
|
7 | 7 | (at your option) any later version. |
|
8 | 8 | |
|
9 | 9 | SciQLop is distributed in the hope that it will be useful, |
|
10 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | GNU General Public License for more details. |
|
13 | 13 | |
|
14 | 14 | You should have received a copy of the GNU General Public License |
|
15 | 15 | along with SciQLop. If not, see <https://www.gnu.org/licenses/>. |
|
16 | 16 | */ |
|
17 | 17 | #ifndef EVENTSMODEL_H |
|
18 | 18 | #define EVENTSMODEL_H |
|
19 | 19 | #include <Catalogue/CatalogueController.h> |
|
20 | 20 | #include <QAbstractItemModel> |
|
21 | #include <QIcon> | |
|
21 | 22 | #include <array> |
|
22 | 23 | |
|
23 | 24 | class EventsModel : public QAbstractItemModel |
|
24 | 25 | { |
|
25 | 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 | 28 | enum class Columns |
|
36 | 29 | { |
|
37 | 30 | Name = 0, |
|
38 | 31 | TStart = 1, |
|
39 | 32 | TEnd = 2, |
|
40 | 33 | Tags = 3, |
|
41 | 34 | Product = 4, |
|
42 | 35 | Validation = 5, |
|
43 | 36 | NbColumn = 6 |
|
44 | 37 | }; |
|
45 | 38 | |
|
46 | 39 | const std::array<QString, static_cast<int>(Columns::NbColumn)> ColumnsNames |
|
47 | 40 | = { "Name", "Start time", "Stop time", "Tags", "Product(s)", "" }; |
|
48 | 41 | |
|
49 | 42 | |
|
50 | 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 | 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 | 170 | ItemType type(const QModelIndex& index) const; |
|
55 | 171 | |
|
56 | 172 | Qt::ItemFlags flags(const QModelIndex& index) const override |
|
57 | 173 | { |
|
58 | 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 | 176 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
|
63 | 177 | |
|
64 | 178 | QModelIndex index( |
|
65 | 179 | int row, int column, const QModelIndex& parent = QModelIndex()) const override; |
|
66 | 180 | |
|
67 | 181 | QModelIndex parent(const QModelIndex& index) const override; |
|
68 | 182 | |
|
69 | 183 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; |
|
70 | 184 | |
|
71 | 185 | int columnCount(const QModelIndex& parent = QModelIndex()) const override; |
|
72 | 186 | |
|
73 | 187 | QVariant headerData( |
|
74 | 188 | int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; |
|
75 | 189 | |
|
76 | 190 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; |
|
77 | 191 | |
|
78 | 192 | public slots: |
|
79 | 193 | void setEvents(std::vector<CatalogueController::Event_ptr> events) |
|
80 | 194 | { |
|
81 | 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 | 199 | endResetModel(); |
|
84 | 200 | } |
|
201 | ||
|
202 | private: | |
|
203 | std::vector<std::unique_ptr<EventsModelItem>> _items; | |
|
85 | 204 | }; |
|
86 | 205 | |
|
87 | 206 | #endif // EVENTSMODEL_H |
@@ -1,34 +1,41 | |||
|
1 | 1 | /* |
|
2 | 2 | This file is part of SciQLop. |
|
3 | 3 | |
|
4 | 4 | SciQLop is free software: you can redistribute it and/or modify |
|
5 | 5 | it under the terms of the GNU General Public License as published by |
|
6 | 6 | the Free Software Foundation, either version 3 of the License, or |
|
7 | 7 | (at your option) any later version. |
|
8 | 8 | |
|
9 | 9 | SciQLop is distributed in the hope that it will be useful, |
|
10 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | GNU General Public License for more details. |
|
13 | 13 | |
|
14 | 14 | You should have received a copy of the GNU General Public License |
|
15 | 15 | along with SciQLop. If not, see <https://www.gnu.org/licenses/>. |
|
16 | 16 | */ |
|
17 | 17 | #ifndef EVENTSTREEVIEW_H |
|
18 | 18 | #define EVENTSTREEVIEW_H |
|
19 | 19 | |
|
20 | 20 | #include <Catalogue/CatalogueController.h> |
|
21 | 21 | #include <QObject> |
|
22 | 22 | #include <QTreeView> |
|
23 | 23 | |
|
24 | 24 | class EventsTreeView : public QTreeView |
|
25 | 25 | { |
|
26 | 26 | Q_OBJECT |
|
27 | 27 | public: |
|
28 | 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 | 34 | public slots: |
|
31 | 35 | void setEvents(std::vector<CatalogueController::Event_ptr> events); |
|
36 | ||
|
37 | private: | |
|
38 | void _itemSelected(const QModelIndex& index); | |
|
32 | 39 | }; |
|
33 | 40 | |
|
34 | 41 | #endif // EVENTSTREEVIEW_H |
@@ -1,99 +1,100 | |||
|
1 | 1 | /* |
|
2 | 2 | This file is part of SciQLop. |
|
3 | 3 | |
|
4 | 4 | SciQLop is free software: you can redistribute it and/or modify |
|
5 | 5 | it under the terms of the GNU General Public License as published by |
|
6 | 6 | the Free Software Foundation, either version 3 of the License, or |
|
7 | 7 | (at your option) any later version. |
|
8 | 8 | |
|
9 | 9 | SciQLop is distributed in the hope that it will be useful, |
|
10 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | GNU General Public License for more details. |
|
13 | 13 | |
|
14 | 14 | You should have received a copy of the GNU General Public License |
|
15 | 15 | along with SciQLop. If not, see <https://www.gnu.org/licenses/>. |
|
16 | 16 | */ |
|
17 | 17 | #ifndef REPOSITORIESMODEL_H |
|
18 | 18 | #define REPOSITORIESMODEL_H |
|
19 | 19 | #include <Catalogue/CatalogueController.h> |
|
20 | 20 | #include <QAbstractItemModel> |
|
21 | 21 | #include <QIcon> |
|
22 | 22 | #include <QObject> |
|
23 | 23 | |
|
24 | 24 | class RepositoriesModel : public QAbstractItemModel |
|
25 | 25 | { |
|
26 | 26 | Q_OBJECT |
|
27 | 27 | |
|
28 | 28 | |
|
29 | ||
|
30 | public: | |
|
29 | 31 | enum class ItemType |
|
30 | 32 | { |
|
31 | 33 | None, |
|
32 | 34 | Catalogue, |
|
33 | 35 | Repository |
|
34 | 36 | }; |
|
35 | 37 | |
|
36 | 38 | struct RepoModelItem |
|
37 | 39 | { |
|
38 | 40 | ItemType type; |
|
39 | 41 | std::variant<QString, CatalogueController::Catalogue_ptr> item; |
|
40 | 42 | RepoModelItem() : type { ItemType::None } {} |
|
41 | 43 | RepoModelItem(const QString& repo); |
|
42 | 44 | RepoModelItem(const CatalogueController::Catalogue_ptr& catalogue, RepoModelItem* parent) |
|
43 | 45 | : type { ItemType::Catalogue } |
|
44 | 46 | , item { catalogue } |
|
45 | 47 | , parent { parent } |
|
46 | 48 | , icon { ":/icones/catalogue.png" } |
|
47 | 49 | { |
|
48 | 50 | } |
|
49 | 51 | QString repository() const { return std::get<QString>(item); } |
|
50 | 52 | CatalogueController::Catalogue_ptr catalogue() const |
|
51 | 53 | { |
|
52 | 54 | return std::get<CatalogueController::Catalogue_ptr>(item); |
|
53 | 55 | } |
|
54 | 56 | QVariant data(int role) const; |
|
55 | 57 | QString text() const |
|
56 | 58 | { |
|
57 | 59 | if (type == ItemType::Catalogue) |
|
58 | 60 | return QString::fromStdString(catalogue()->name); |
|
59 | 61 | if (type == ItemType::Repository) |
|
60 | 62 | return repository(); |
|
61 | 63 | return QString(); |
|
62 | 64 | } |
|
63 | 65 | std::vector<std::unique_ptr<RepoModelItem>> children; |
|
64 | 66 | RepoModelItem* parent = nullptr; |
|
65 | 67 | QIcon icon; |
|
66 | 68 | }; |
|
67 | 69 | |
|
68 | 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 | 74 | return static_cast<RepoModelItem*>(index.internalPointer()); |
|
73 | 75 | } |
|
74 | 76 | |
|
75 | public: | |
|
76 | 77 | RepositoriesModel(QObject* parent = nullptr); |
|
77 | 78 | |
|
78 | 79 | ItemType type(const QModelIndex& index) const; |
|
79 | 80 | |
|
80 | 81 | Qt::ItemFlags flags(const QModelIndex& index) const override |
|
81 | 82 | { |
|
82 | 83 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; |
|
83 | 84 | } |
|
84 | 85 | |
|
85 | 86 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
|
86 | 87 | |
|
87 | 88 | QModelIndex index( |
|
88 | 89 | int row, int column, const QModelIndex& parent = QModelIndex()) const override; |
|
89 | 90 | |
|
90 | 91 | QModelIndex parent(const QModelIndex& index) const override; |
|
91 | 92 | |
|
92 | 93 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; |
|
93 | 94 | |
|
94 | 95 | int columnCount(const QModelIndex& parent = QModelIndex()) const override { return 1; } |
|
95 | 96 | public slots: |
|
96 | 97 | void refresh(); |
|
97 | 98 | }; |
|
98 | 99 | |
|
99 | 100 | #endif // REPOSITORIESMODEL_H |
@@ -1,41 +1,52 | |||
|
1 | 1 | /* |
|
2 | 2 | This file is part of SciQLop. |
|
3 | 3 | |
|
4 | 4 | SciQLop is free software: you can redistribute it and/or modify |
|
5 | 5 | it under the terms of the GNU General Public License as published by |
|
6 | 6 | the Free Software Foundation, either version 3 of the License, or |
|
7 | 7 | (at your option) any later version. |
|
8 | 8 | |
|
9 | 9 | SciQLop is distributed in the hope that it will be useful, |
|
10 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | GNU General Public License for more details. |
|
13 | 13 | |
|
14 | 14 | You should have received a copy of the GNU General Public License |
|
15 | 15 | along with SciQLop. If not, see <https://www.gnu.org/licenses/>. |
|
16 | 16 | */ |
|
17 | 17 | #ifndef REPOSITORIESTREEVIEW_H |
|
18 | 18 | #define REPOSITORIESTREEVIEW_H |
|
19 | 19 | |
|
20 | #include <Catalogue2/repositoriesmodel.h> | |
|
20 | 21 | #include <QObject> |
|
21 | 22 | #include <QTreeView> |
|
22 | #include <Catalogue2/repositoriesmodel.h> | |
|
23 | 23 | |
|
24 | 24 | class RepositoriesTreeView : public QTreeView |
|
25 | 25 | { |
|
26 | 26 | Q_OBJECT |
|
27 | 27 | public: |
|
28 | 28 | RepositoriesTreeView(QWidget* parent = nullptr); |
|
29 | 29 | |
|
30 | 30 | public slots: |
|
31 | void refresh() | |
|
32 | { | |
|
33 | static_cast<RepositoriesModel*>(model())->refresh(); | |
|
34 | } | |
|
31 | void refresh() { static_cast<RepositoriesModel*>(model())->refresh(); } | |
|
35 | 32 | |
|
36 | 33 | signals: |
|
37 | 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 | 52 | #endif // REPOSITORIESTREEVIEW_H |
@@ -1,201 +1,105 | |||
|
1 | 1 | /* |
|
2 | 2 | This file is part of SciQLop. |
|
3 | 3 | |
|
4 | 4 | SciQLop is free software: you can redistribute it and/or modify |
|
5 | 5 | it under the terms of the GNU General Public License as published by |
|
6 | 6 | the Free Software Foundation, either version 3 of the License, or |
|
7 | 7 | (at your option) any later version. |
|
8 | 8 | |
|
9 | 9 | SciQLop is distributed in the hope that it will be useful, |
|
10 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | GNU General Public License for more details. |
|
13 | 13 | |
|
14 | 14 | You should have received a copy of the GNU General Public License |
|
15 | 15 | along with SciQLop. If not, see <https://www.gnu.org/licenses/>. |
|
16 | 16 | */ |
|
17 | 17 | #include "Catalogue2/eventsmodel.h" |
|
18 | 18 | #include <SqpApplication.h> |
|
19 | #include <Common/containers.h> | |
|
19 | 20 | |
|
20 | 21 | EventsModel::EventsModel(QObject* parent) : QAbstractItemModel(parent) {} |
|
21 | 22 | |
|
22 | 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 | } | |
|
28 | else if (index.internalPointer() == nullptr) | |
|
29 | { | |
|
30 | return ItemType::Event; | |
|
31 | } | |
|
32 | else | |
|
33 | { | |
|
34 | return ItemType::Product; | |
|
27 | return item->type; | |
|
35 | 28 | } |
|
36 | } | |
|
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 {}; | |
|
29 | return ItemType::None; | |
|
95 | 30 | } |
|
96 | 31 | |
|
97 | 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)) | |
|
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 | } | |
|
36 | return to_item(index)->data(index.column(),role); | |
|
113 | 37 | } |
|
114 | 38 | return QVariant {}; |
|
115 | 39 | } |
|
116 | 40 | |
|
117 | 41 | QModelIndex EventsModel::index(int row, int column, const QModelIndex& parent) const |
|
118 | 42 | { |
|
119 | 43 | if (!hasIndex(row, column, parent)) |
|
120 | 44 | { |
|
121 | 45 | return QModelIndex(); |
|
122 | 46 | } |
|
123 | 47 | |
|
124 | 48 | switch (type(parent)) |
|
125 | 49 | { |
|
126 |
case |
|
|
127 |
return createIndex(row, column, |
|
|
128 |
case |
|
|
129 | { | |
|
130 | return createIndex(row, column, _events[parent.row()].get()); | |
|
131 | } | |
|
132 | case EventsModel::ItemType::Product: | |
|
133 | break; | |
|
134 | default: | |
|
135 | break; | |
|
50 | case ItemType::None: // is an event | |
|
51 | return createIndex(row, column, _items[row].get()); | |
|
52 | case ItemType::Event: // is a product | |
|
53 | return createIndex(row, column, to_item(parent)->children[row].get()); | |
|
54 | case ItemType::Product: | |
|
55 | QModelIndex(); | |
|
136 | 56 | } |
|
137 | 57 | |
|
138 | 58 | return QModelIndex(); |
|
139 | 59 | } |
|
140 | 60 | |
|
141 | 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: | |
|
146 | break; | |
|
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 | } | |
|
66 | auto repoIndex = SciQLop::containers::index_of(_items, item->parent); | |
|
67 | return createIndex(repoIndex, 0, item->parent); | |
|
160 | 68 | } |
|
161 | 69 | return QModelIndex(); |
|
162 | 70 | } |
|
163 | 71 | |
|
164 | 72 | int EventsModel::rowCount(const QModelIndex& parent) const |
|
165 | 73 | { |
|
166 | 74 | if (parent.column() > 0) |
|
167 | 75 | { |
|
168 | 76 | return 0; |
|
169 | 77 | } |
|
170 | ||
|
171 | 78 | switch (type(parent)) |
|
172 | 79 | { |
|
173 |
case |
|
|
174 |
return _ |
|
|
175 |
case |
|
|
176 |
return |
|
|
177 | break; | |
|
178 | case EventsModel::ItemType::Product: | |
|
179 | break; | |
|
180 | default: | |
|
80 | case ItemType::None: | |
|
81 | return _items.size(); | |
|
82 | case ItemType::Event: | |
|
83 | return to_item(parent)->children.size(); | |
|
84 | case ItemType::Product: | |
|
181 | 85 | break; |
|
182 | 86 | } |
|
183 | 87 | return 0; |
|
184 | 88 | } |
|
185 | 89 | |
|
186 | 90 | int EventsModel::columnCount(const QModelIndex& parent) const |
|
187 | 91 | { |
|
188 | 92 | return static_cast<int>(EventsModel::Columns::NbColumn); |
|
189 | 93 | } |
|
190 | 94 | |
|
191 | 95 | QVariant EventsModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
192 | 96 | { |
|
193 | 97 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section < ColumnsNames.size()) |
|
194 | 98 | { |
|
195 | 99 | return ColumnsNames[section]; |
|
196 | 100 | } |
|
197 | 101 | |
|
198 | 102 | return QVariant(); |
|
199 | 103 | } |
|
200 | 104 | |
|
201 | 105 | void EventsModel::sort(int column, Qt::SortOrder order) {} |
@@ -1,28 +1,45 | |||
|
1 | 1 | /* |
|
2 | 2 | This file is part of SciQLop. |
|
3 | 3 | |
|
4 | 4 | SciQLop is free software: you can redistribute it and/or modify |
|
5 | 5 | it under the terms of the GNU General Public License as published by |
|
6 | 6 | the Free Software Foundation, either version 3 of the License, or |
|
7 | 7 | (at your option) any later version. |
|
8 | 8 | |
|
9 | 9 | SciQLop is distributed in the hope that it will be useful, |
|
10 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | GNU General Public License for more details. |
|
13 | 13 | |
|
14 | 14 | You should have received a copy of the GNU General Public License |
|
15 | 15 | along with SciQLop. If not, see <https://www.gnu.org/licenses/>. |
|
16 | 16 | */ |
|
17 | 17 | #include <Catalogue2/eventsmodel.h> |
|
18 | 18 | #include <Catalogue2/eventstreeview.h> |
|
19 | 19 | |
|
20 | 20 | EventsTreeView::EventsTreeView(QWidget* parent) : QTreeView(parent) |
|
21 | 21 | { |
|
22 | 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 | 29 | void EventsTreeView::setEvents(std::vector<CatalogueController::Event_ptr> events) |
|
26 | 30 | { |
|
27 | 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 | } |
@@ -1,123 +1,127 | |||
|
1 | 1 | /* |
|
2 | 2 | This file is part of SciQLop. |
|
3 | 3 | |
|
4 | 4 | SciQLop is free software: you can redistribute it and/or modify |
|
5 | 5 | it under the terms of the GNU General Public License as published by |
|
6 | 6 | the Free Software Foundation, either version 3 of the License, or |
|
7 | 7 | (at your option) any later version. |
|
8 | 8 | |
|
9 | 9 | SciQLop is distributed in the hope that it will be useful, |
|
10 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | GNU General Public License for more details. |
|
13 | 13 | |
|
14 | 14 | You should have received a copy of the GNU General Public License |
|
15 | 15 | along with SciQLop. If not, see <https://www.gnu.org/licenses/>. |
|
16 | 16 | */ |
|
17 | 17 | #include <Catalogue2/repositoriesmodel.h> |
|
18 | 18 | #include <Common/containers.h> |
|
19 | 19 | #include <SqpApplication.h> |
|
20 | 20 | |
|
21 | 21 | |
|
22 | 22 | RepositoriesModel::RepositoriesModel(QObject* parent) : QAbstractItemModel(parent) |
|
23 | 23 | { |
|
24 | 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 | 31 | RepositoriesModel::ItemType RepositoriesModel::type(const QModelIndex& index) const |
|
28 | 32 | { |
|
29 | 33 | if (RepoModelItem* item = to_item(index)) |
|
30 | 34 | { |
|
31 | 35 | return item->type; |
|
32 | 36 | } |
|
33 | 37 | return ItemType::None; |
|
34 | 38 | } |
|
35 | 39 | |
|
36 | 40 | void RepositoriesModel::refresh() |
|
37 | 41 | { |
|
38 | 42 | beginResetModel(); |
|
39 | 43 | _items.clear(); |
|
40 | 44 | _items.push_back(std::make_unique<RepoModelItem>("All")); |
|
41 | 45 | _items.push_back(std::make_unique<RepoModelItem>("Trash")); |
|
42 | 46 | auto repo_list = sqpApp->catalogueController().repositories(); |
|
43 | 47 | std::transform(std::begin(repo_list), std::end(repo_list), std::back_inserter(_items), |
|
44 | 48 | [](const auto& repo_name) { return std::make_unique<RepoModelItem>(repo_name); }); |
|
45 | 49 | endResetModel(); |
|
46 | 50 | } |
|
47 | 51 | |
|
48 | 52 | QVariant RepositoriesModel::data(const QModelIndex& index, int role) const |
|
49 | 53 | { |
|
50 | 54 | if (index.isValid() && index.column() == 0) |
|
51 | 55 | { |
|
52 | 56 | return to_item(index)->data(role); |
|
53 | 57 | } |
|
54 | 58 | return QVariant {}; |
|
55 | 59 | } |
|
56 | 60 | |
|
57 | 61 | QModelIndex RepositoriesModel::index(int row, int column, const QModelIndex& parent) const |
|
58 | 62 | { |
|
59 | 63 | if (!hasIndex(row, column, parent)) |
|
60 | 64 | { |
|
61 | 65 | return QModelIndex(); |
|
62 | 66 | } |
|
63 | 67 | |
|
64 | 68 | switch (type(parent)) |
|
65 | 69 | { |
|
66 | 70 | case RepositoriesModel::ItemType::None: // is a repo |
|
67 | 71 | return createIndex(row, column, _items[row].get()); |
|
68 | 72 | case RepositoriesModel::ItemType::Repository: // is a catalogue |
|
69 | 73 | return createIndex(row, column, to_item(parent)->children[row].get()); |
|
70 | 74 | case RepositoriesModel::ItemType::Catalogue: |
|
71 | 75 | return createIndex(row, column, new RepoModelItem()); |
|
72 | 76 | } |
|
73 | 77 | |
|
74 | 78 | return QModelIndex(); |
|
75 | 79 | } |
|
76 | 80 | |
|
77 | 81 | QModelIndex RepositoriesModel::parent(const QModelIndex& index) const |
|
78 | 82 | { |
|
79 | 83 | auto item = to_item(index); |
|
80 | 84 | if (item->type == ItemType::Catalogue) |
|
81 | 85 | { |
|
82 | 86 | auto repoIndex = SciQLop::containers::index_of(_items, item->parent); |
|
83 | 87 | return createIndex(repoIndex, 0, item->parent); |
|
84 | 88 | } |
|
85 | 89 | return QModelIndex(); |
|
86 | 90 | } |
|
87 | 91 | |
|
88 | 92 | int RepositoriesModel::rowCount(const QModelIndex& parent) const |
|
89 | 93 | { |
|
90 | 94 | switch (type(parent)) |
|
91 | 95 | { |
|
92 | 96 | case RepositoriesModel::ItemType::None: |
|
93 | 97 | return _items.size(); |
|
94 | 98 | case RepositoriesModel::ItemType::Repository: |
|
95 | 99 | return to_item(parent)->children.size(); |
|
96 | 100 | case RepositoriesModel::ItemType::Catalogue: |
|
97 | 101 | break; |
|
98 | 102 | } |
|
99 | 103 | return 0; |
|
100 | 104 | } |
|
101 | 105 | |
|
102 | 106 | RepositoriesModel::RepoModelItem::RepoModelItem(const QString& repo) |
|
103 | 107 | : type { ItemType::Repository }, item { repo }, icon { ":/icones/database.png" } |
|
104 | 108 | { |
|
105 | 109 | auto catalogues = sqpApp->catalogueController().catalogues(repo); |
|
106 | 110 | std::transform(std::begin(catalogues), std::end(catalogues), std::back_inserter(children), |
|
107 | 111 | [this](auto& catalogue) { return std::make_unique<RepoModelItem>(catalogue, this); }); |
|
108 | 112 | } |
|
109 | 113 | |
|
110 | 114 | QVariant RepositoriesModel::RepoModelItem::data(int role) const |
|
111 | 115 | { |
|
112 | 116 | switch (role) |
|
113 | 117 | { |
|
114 | 118 | case Qt::EditRole: |
|
115 | 119 | case Qt::DisplayRole: |
|
116 | 120 | return text(); |
|
117 | 121 | case Qt::DecorationRole: |
|
118 | 122 | return QVariant { icon }; |
|
119 | 123 | default: |
|
120 | 124 | break; |
|
121 | 125 | } |
|
122 | 126 | return QVariant {}; |
|
123 | 127 | } |
@@ -1,27 +1,31 | |||
|
1 | 1 | /* |
|
2 | 2 | This file is part of SciQLop. |
|
3 | 3 | |
|
4 | 4 | SciQLop is free software: you can redistribute it and/or modify |
|
5 | 5 | it under the terms of the GNU General Public License as published by |
|
6 | 6 | the Free Software Foundation, either version 3 of the License, or |
|
7 | 7 | (at your option) any later version. |
|
8 | 8 | |
|
9 | 9 | SciQLop is distributed in the hope that it will be useful, |
|
10 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | GNU General Public License for more details. |
|
13 | 13 | |
|
14 | 14 | You should have received a copy of the GNU General Public License |
|
15 | 15 | along with SciQLop. If not, see <https://www.gnu.org/licenses/>. |
|
16 | 16 | */ |
|
17 | 17 | #include <Catalogue2/repositoriesmodel.h> |
|
18 | 18 | #include <Catalogue2/repositoriestreeview.h> |
|
19 | 19 | |
|
20 | 20 | RepositoriesTreeView::RepositoriesTreeView(QWidget* parent) : QTreeView(parent) |
|
21 | 21 | { |
|
22 | 22 | auto m = model(); |
|
23 | 23 | this->setModel(new RepositoriesModel(this)); |
|
24 | 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 |
@@ -1,7 +1,8 | |||
|
1 | 1 | include(sciqlop_tests) |
|
2 | 2 | subdirs(GUITestUtils) |
|
3 | 3 | declare_test(simple_graph simple_graph simple_graph/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test") |
|
4 | 4 | declare_test(multiple_sync_graph multiple_sync_graph multiple_sync_graph/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test") |
|
5 | 5 | |
|
6 | 6 | declare_manual_test(event_list event_list catalogue/event_list/main.cpp "sciqlopgui;TestUtils;GUITestUtils;Qt5::Test") |
|
7 | 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