##// END OF EJS Templates
Added catalog columns sorting but broken :(...
jeandet -
r1474:337dc641a65f
parent child
Show More
@@ -1,1 +1,1
1 Subproject commit 4e4ec6844f702c9fe7b3c758a50430e17d186fac
1 Subproject commit 521f9540ac01f61c92600a4aa6c8d3c148abc74a
@@ -52,7 +52,12 public:
52 {
52 {
53 ItemType type;
53 ItemType type;
54 std::variant<CatalogueController::Event_ptr, CatalogueController::Product_t> item;
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 EventsModelItem(const CatalogueController::Event_ptr& event)
61 EventsModelItem(const CatalogueController::Event_ptr& event)
57 : type { ItemType::Event }, item { event }, parent { nullptr }, icon {}
62 : type { ItemType::Event }, item { event }, parent { nullptr }, icon {}
58 {
63 {
@@ -65,6 +70,7 public:
65 : type { ItemType::Product }, item { product }, parent { parent }, icon {}
70 : type { ItemType::Product }, item { product }, parent { parent }, icon {}
66 {
71 {
67 }
72 }
73 ~EventsModelItem() { children.clear(); }
68 CatalogueController::Event_ptr event() const
74 CatalogueController::Event_ptr event() const
69 {
75 {
70 return std::get<CatalogueController::Event_ptr>(item);
76 return std::get<CatalogueController::Event_ptr>(item);
@@ -75,19 +81,19 public:
75 }
81 }
76 QVariant data(int col, int role) const
82 QVariant data(int col, int role) const
77 {
83 {
78 if(role==Qt::DisplayRole)
84 if (role == Qt::DisplayRole)
79 {
85 {
80 switch (type)
86 switch (type)
81 {
87 {
82 case ItemType::Product :
88 case ItemType::Product:
83 return data(product(),col);
89 return data(product(), col);
84 case ItemType::Event:
90 case ItemType::Event:
85 return data(event(),col);
91 return data(event(), col);
86 default:
92 default:
87 break;
93 break;
88 }
94 }
89 }
95 }
90 return QVariant{};
96 return QVariant {};
91 }
97 }
92 QVariant data(const CatalogueController::Event_ptr& event, int col) const
98 QVariant data(const CatalogueController::Event_ptr& event, int col) const
93 {
99 {
@@ -137,7 +143,8 public:
137 case EventsModel::Columns::Name:
143 case EventsModel::Columns::Name:
138 return QString::fromStdString(product.name);
144 return QString::fromStdString(product.name);
139 case EventsModel::Columns::TStart:
145 case EventsModel::Columns::TStart:
140 return DateUtils::dateTime(product.startTime).toString(DATETIME_FORMAT_ONE_LINE);
146 return DateUtils::dateTime(product.startTime)
147 .toString(DATETIME_FORMAT_ONE_LINE);
141 case EventsModel::Columns::TEnd:
148 case EventsModel::Columns::TEnd:
142 return DateUtils::dateTime(product.stopTime).toString(DATETIME_FORMAT_ONE_LINE);
149 return DateUtils::dateTime(product.stopTime).toString(DATETIME_FORMAT_ONE_LINE);
143 case EventsModel::Columns::Product:
150 case EventsModel::Columns::Product:
@@ -167,6 +174,8 public:
167 return static_cast<EventsModelItem*>(index.internalPointer());
174 return static_cast<EventsModelItem*>(index.internalPointer());
168 }
175 }
169
176
177 ~EventsModel() { _items.clear(); }
178
170 ItemType type(const QModelIndex& index) const;
179 ItemType type(const QModelIndex& index) const;
171
180
172 Qt::ItemFlags flags(const QModelIndex& index) const override
181 Qt::ItemFlags flags(const QModelIndex& index) const override
@@ -26,10 +26,12 class EventsTreeView : public QTreeView
26 Q_OBJECT
26 Q_OBJECT
27 public:
27 public:
28 EventsTreeView(QWidget* parent = nullptr);
28 EventsTreeView(QWidget* parent = nullptr);
29 ~EventsTreeView();
29
30
30 signals:
31 signals:
31 void eventSelected(const CatalogueController::Event_ptr& event);
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 public slots:
36 public slots:
35 void setEvents(std::vector<CatalogueController::Event_ptr> events);
37 void setEvents(std::vector<CatalogueController::Event_ptr> events);
@@ -166,4 +166,9 sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib,
166 include_directories : gui_inc,
166 include_directories : gui_inc,
167 dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core])
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 along with SciQLop. If not, see <https://www.gnu.org/licenses/>.
15 along with SciQLop. If not, see <https://www.gnu.org/licenses/>.
16 */
16 */
17 #include "Catalogue2/eventsmodel.h"
17 #include "Catalogue2/eventsmodel.h"
18 #include <SqpApplication.h>
19 #include <Common/containers.h>
18 #include <Common/containers.h>
19 #include <SqpApplication.h>
20
20
21 EventsModel::EventsModel(QObject* parent) : QAbstractItemModel(parent) {}
21 EventsModel::EventsModel(QObject* parent) : QAbstractItemModel(parent) {}
22
22
@@ -33,7 +33,7 QVariant EventsModel::data(const QModelIndex& index, int role) const
33 {
33 {
34 if (index.isValid())
34 if (index.isValid())
35 {
35 {
36 return to_item(index)->data(index.column(),role);
36 return to_item(index)->data(index.column(), role);
37 }
37 }
38 return QVariant {};
38 return QVariant {};
39 }
39 }
@@ -102,4 +102,93 QVariant EventsModel::headerData(int section, Qt::Orientation orientation, int r
102 return QVariant();
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,10 +20,16
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 &current, const QModelIndex &previous){
23 connect(this->selectionModel(), &QItemSelectionModel::currentChanged,
24 Q_UNUSED(previous);
24 [this](const QModelIndex& current, const QModelIndex& previous) {
25 this->_itemSelected(current);
25 Q_UNUSED(previous);
26 });
26 this->_itemSelected(current);
27 });
28 }
29
30 EventsTreeView::~EventsTreeView()
31 {
32 delete this->model();
27 }
33 }
28
34
29 void EventsTreeView::setEvents(std::vector<CatalogueController::Event_ptr> events)
35 void EventsTreeView::setEvents(std::vector<CatalogueController::Event_ptr> events)
@@ -31,7 +37,7 void EventsTreeView::setEvents(std::vector<CatalogueController::Event_ptr> event
31 static_cast<EventsModel*>(this->model())->setEvents(events);
37 static_cast<EventsModel*>(this->model())->setEvents(events);
32 }
38 }
33
39
34 void EventsTreeView::_itemSelected(const QModelIndex &index)
40 void EventsTreeView::_itemSelected(const QModelIndex& index)
35 {
41 {
36 auto item = EventsModel::to_item(index);
42 auto item = EventsModel::to_item(index);
37 if (item->type == EventsModel::ItemType::Event)
43 if (item->type == EventsModel::ItemType::Event)
@@ -10,7 +10,6
10 #include <SqpApplication.h>
10 #include <SqpApplication.h>
11
11
12 #include <GUITestUtils.h>
12 #include <GUITestUtils.h>
13 #include <TestProviders.h>
14
13
15 #include <Catalogue/CatalogueController.h>
14 #include <Catalogue/CatalogueController.h>
16 #include <Catalogue2/browser.h>
15 #include <Catalogue2/browser.h>
@@ -61,6 +61,12
61 <verstretch>0</verstretch>
61 <verstretch>0</verstretch>
62 </sizepolicy>
62 </sizepolicy>
63 </property>
63 </property>
64 <property name="sortingEnabled">
65 <bool>true</bool>
66 </property>
67 <attribute name="headerShowSortIndicator" stdset="0">
68 <bool>true</bool>
69 </attribute>
64 </widget>
70 </widget>
65 </item>
71 </item>
66 <item>
72 <item>
General Comments 0
You need to be logged in to leave comments. Login now