@@ -1,1 +1,1 | |||
|
1 | Subproject commit 4e4ec6844f702c9fe7b3c758a50430e17d186fac | |
|
1 | Subproject commit 521f9540ac01f61c92600a4aa6c8d3c148abc74a |
@@ -52,7 +52,12 public: | |||
|
52 | 52 | { |
|
53 | 53 | ItemType type; |
|
54 | 54 | std::variant<CatalogueController::Event_ptr, CatalogueController::Product_t> item; |
|
55 | EventsModelItem() : type { ItemType::None } {} | |
|
55 | // EventsModelItem() : type { ItemType::None } {} | |
|
56 | EventsModelItem() = delete; | |
|
57 | EventsModelItem(const EventsModelItem&) = delete; | |
|
58 | EventsModelItem(EventsModelItem&&) = delete; | |
|
59 | EventsModelItem& operator=(const EventsModelItem&) = delete; | |
|
60 | EventsModelItem& operator=(EventsModelItem&&) = delete; | |
|
56 | 61 | EventsModelItem(const CatalogueController::Event_ptr& event) |
|
57 | 62 | : type { ItemType::Event }, item { event }, parent { nullptr }, icon {} |
|
58 | 63 | { |
@@ -65,6 +70,7 public: | |||
|
65 | 70 | : type { ItemType::Product }, item { product }, parent { parent }, icon {} |
|
66 | 71 | { |
|
67 | 72 | } |
|
73 | ~EventsModelItem() { children.clear(); } | |
|
68 | 74 | CatalogueController::Event_ptr event() const |
|
69 | 75 | { |
|
70 | 76 | return std::get<CatalogueController::Event_ptr>(item); |
@@ -137,7 +143,8 public: | |||
|
137 | 143 | case EventsModel::Columns::Name: |
|
138 | 144 | return QString::fromStdString(product.name); |
|
139 | 145 | case EventsModel::Columns::TStart: |
|
140 |
return DateUtils::dateTime(product.startTime) |
|
|
146 | return DateUtils::dateTime(product.startTime) | |
|
147 | .toString(DATETIME_FORMAT_ONE_LINE); | |
|
141 | 148 | case EventsModel::Columns::TEnd: |
|
142 | 149 | return DateUtils::dateTime(product.stopTime).toString(DATETIME_FORMAT_ONE_LINE); |
|
143 | 150 | case EventsModel::Columns::Product: |
@@ -167,6 +174,8 public: | |||
|
167 | 174 | return static_cast<EventsModelItem*>(index.internalPointer()); |
|
168 | 175 | } |
|
169 | 176 | |
|
177 | ~EventsModel() { _items.clear(); } | |
|
178 | ||
|
170 | 179 | ItemType type(const QModelIndex& index) const; |
|
171 | 180 | |
|
172 | 181 | Qt::ItemFlags flags(const QModelIndex& index) const override |
@@ -26,10 +26,12 class EventsTreeView : public QTreeView | |||
|
26 | 26 | Q_OBJECT |
|
27 | 27 | public: |
|
28 | 28 | EventsTreeView(QWidget* parent = nullptr); |
|
29 | ~EventsTreeView(); | |
|
29 | 30 | |
|
30 | 31 | signals: |
|
31 | 32 | void eventSelected(const CatalogueController::Event_ptr& event); |
|
32 | void productSelected(const CatalogueController::Product_t& product, const CatalogueController::Event_ptr& event); | |
|
33 | void productSelected( | |
|
34 | const CatalogueController::Product_t& product, const CatalogueController::Event_ptr& event); | |
|
33 | 35 | |
|
34 | 36 | public slots: |
|
35 | 37 | void setEvents(std::vector<CatalogueController::Event_ptr> events); |
@@ -166,4 +166,9 sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, | |||
|
166 | 166 | include_directories : gui_inc, |
|
167 | 167 | dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core]) |
|
168 | 168 | |
|
169 | gui_tests_inc = include_directories(['tests/GUITestUtils']) | |
|
169 | 170 | |
|
171 | catalogue_browser_moc_files = qt5.preprocess(moc_sources : 'tests/catalogue/browser/main.cpp') | |
|
172 | catalogue_browser = executable('catalogue_browser', 'tests/catalogue/browser/main.cpp',catalogue_browser_moc_files, | |
|
173 | include_directories : gui_tests_inc, | |
|
174 | dependencies :[sciqlop_gui, qt5test]) |
@@ -15,8 +15,8 | |||
|
15 | 15 | along with SciQLop. If not, see <https://www.gnu.org/licenses/>. |
|
16 | 16 | */ |
|
17 | 17 | #include "Catalogue2/eventsmodel.h" |
|
18 | #include <SqpApplication.h> | |
|
19 | 18 | #include <Common/containers.h> |
|
19 | #include <SqpApplication.h> | |
|
20 | 20 | |
|
21 | 21 | EventsModel::EventsModel(QObject* parent) : QAbstractItemModel(parent) {} |
|
22 | 22 | |
@@ -102,4 +102,93 QVariant EventsModel::headerData(int section, Qt::Orientation orientation, int r | |||
|
102 | 102 | return QVariant(); |
|
103 | 103 | } |
|
104 | 104 | |
|
105 |
void EventsModel::sort(int column, Qt::SortOrder order) |
|
|
105 | void EventsModel::sort(int column, Qt::SortOrder order) | |
|
106 | { | |
|
107 | beginResetModel(); | |
|
108 | switch (static_cast<Columns>(column)) | |
|
109 | { | |
|
110 | case EventsModel::Columns::Name: | |
|
111 | std::sort(std::begin(_items), std::end(_items), | |
|
112 | [inverse = order != Qt::SortOrder::AscendingOrder]( | |
|
113 | const std::unique_ptr<EventsModelItem>& a, | |
|
114 | const std::unique_ptr<EventsModelItem>& b) { | |
|
115 | static int i = 0; | |
|
116 | i++; | |
|
117 | if (!a->event()) | |
|
118 | { | |
|
119 | throw; | |
|
120 | } | |
|
121 | if (!b->event()) | |
|
122 | { | |
|
123 | throw; | |
|
124 | } | |
|
125 | return (a->event()->name < b->event()->name) xor inverse; | |
|
126 | }); | |
|
127 | break; | |
|
128 | case EventsModel::Columns::TStart: | |
|
129 | std::sort(std::begin(_items), std::end(_items), | |
|
130 | [inverse = order != Qt::SortOrder::AscendingOrder]( | |
|
131 | const std::unique_ptr<EventsModelItem>& a, | |
|
132 | const std::unique_ptr<EventsModelItem>& b) { | |
|
133 | static int i = 0; | |
|
134 | i++; | |
|
135 | if (!a) | |
|
136 | { | |
|
137 | throw; | |
|
138 | } | |
|
139 | if (!b) | |
|
140 | { | |
|
141 | throw; | |
|
142 | } | |
|
143 | if (!a->event()) | |
|
144 | { | |
|
145 | throw; | |
|
146 | } | |
|
147 | if (!b->event()) | |
|
148 | { | |
|
149 | throw; | |
|
150 | } | |
|
151 | return (a->event()->name < b->event()->name) xor inverse; | |
|
152 | }); | |
|
153 | // std::sort(std::begin(_items), std::end(_items), | |
|
154 | // [inverse = order != Qt::SortOrder::AscendingOrder]( | |
|
155 | // const std::unique_ptr<EventsModelItem>& a, | |
|
156 | // const std::unique_ptr<EventsModelItem>& b) { | |
|
157 | // static int i = 0; | |
|
158 | // i++; | |
|
159 | // if (a and b) | |
|
160 | // { | |
|
161 | // if (a->type == ItemType::Event and b->type == ItemType::Event) | |
|
162 | // { | |
|
163 | // if (auto e1 = a->event(); auto e2 = b->event()) | |
|
164 | // { | |
|
165 | // return bool((e1->startTime() < e2->startTime()) xor | |
|
166 | // inverse); | |
|
167 | // } | |
|
168 | // } | |
|
169 | // } | |
|
170 | // return false; | |
|
171 | // }); | |
|
172 | break; | |
|
173 | case EventsModel::Columns::TEnd: | |
|
174 | std::sort(std::begin(_items), std::end(_items), | |
|
175 | [inverse = order != Qt::SortOrder::AscendingOrder]( | |
|
176 | const std::unique_ptr<EventsModelItem>& a, | |
|
177 | const std::unique_ptr<EventsModelItem>& b) { | |
|
178 | if (auto t1 = a->event()->stopTime(); auto t2 = b->event()->stopTime()) | |
|
179 | { | |
|
180 | if (t1 and t2) | |
|
181 | return bool((t1.value() < t2.value()) xor inverse); | |
|
182 | } | |
|
183 | return true; | |
|
184 | }); | |
|
185 | break; | |
|
186 | case EventsModel::Columns::Product: | |
|
187 | break; | |
|
188 | case EventsModel::Columns::Tags: | |
|
189 | break; | |
|
190 | default: | |
|
191 | break; | |
|
192 | } | |
|
193 | endResetModel(); | |
|
194 | } |
@@ -20,12 +20,18 | |||
|
20 | 20 | EventsTreeView::EventsTreeView(QWidget* parent) : QTreeView(parent) |
|
21 | 21 | { |
|
22 | 22 | this->setModel(new EventsModel()); |
|
23 |
connect(this->selectionModel(), &QItemSelectionModel::currentChanged, |
|
|
23 | connect(this->selectionModel(), &QItemSelectionModel::currentChanged, | |
|
24 | [this](const QModelIndex& current, const QModelIndex& previous) { | |
|
24 | 25 | Q_UNUSED(previous); |
|
25 | 26 | this->_itemSelected(current); |
|
26 | 27 | }); |
|
27 | 28 | } |
|
28 | 29 | |
|
30 | EventsTreeView::~EventsTreeView() | |
|
31 | { | |
|
32 | delete this->model(); | |
|
33 | } | |
|
34 | ||
|
29 | 35 | void EventsTreeView::setEvents(std::vector<CatalogueController::Event_ptr> events) |
|
30 | 36 | { |
|
31 | 37 | static_cast<EventsModel*>(this->model())->setEvents(events); |
General Comments 0
You need to be logged in to leave comments.
Login now