diff --git a/core b/core index 4e4ec68..521f954 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 4e4ec6844f702c9fe7b3c758a50430e17d186fac +Subproject commit 521f9540ac01f61c92600a4aa6c8d3c148abc74a diff --git a/gui/include/Catalogue2/eventsmodel.h b/gui/include/Catalogue2/eventsmodel.h index 27c51b9..d74f90e 100644 --- a/gui/include/Catalogue2/eventsmodel.h +++ b/gui/include/Catalogue2/eventsmodel.h @@ -52,7 +52,12 @@ public: { ItemType type; std::variant item; - EventsModelItem() : type { ItemType::None } {} + // EventsModelItem() : type { ItemType::None } {} + EventsModelItem() = delete; + EventsModelItem(const EventsModelItem&) = delete; + EventsModelItem(EventsModelItem&&) = delete; + EventsModelItem& operator=(const EventsModelItem&) = delete; + EventsModelItem& operator=(EventsModelItem&&) = delete; EventsModelItem(const CatalogueController::Event_ptr& event) : type { ItemType::Event }, item { event }, parent { nullptr }, icon {} { @@ -65,6 +70,7 @@ public: : type { ItemType::Product }, item { product }, parent { parent }, icon {} { } + ~EventsModelItem() { children.clear(); } CatalogueController::Event_ptr event() const { return std::get(item); @@ -75,19 +81,19 @@ public: } QVariant data(int col, int role) const { - if(role==Qt::DisplayRole) + if (role == Qt::DisplayRole) { switch (type) { - case ItemType::Product : - return data(product(),col); - case ItemType::Event: - return data(event(),col); - default: - break; + case ItemType::Product: + return data(product(), col); + case ItemType::Event: + return data(event(), col); + default: + break; } } - return QVariant{}; + return QVariant {}; } QVariant data(const CatalogueController::Event_ptr& event, int col) const { @@ -137,7 +143,8 @@ public: case EventsModel::Columns::Name: return QString::fromStdString(product.name); case EventsModel::Columns::TStart: - return DateUtils::dateTime(product.startTime).toString(DATETIME_FORMAT_ONE_LINE); + return DateUtils::dateTime(product.startTime) + .toString(DATETIME_FORMAT_ONE_LINE); case EventsModel::Columns::TEnd: return DateUtils::dateTime(product.stopTime).toString(DATETIME_FORMAT_ONE_LINE); case EventsModel::Columns::Product: @@ -167,6 +174,8 @@ public: return static_cast(index.internalPointer()); } + ~EventsModel() { _items.clear(); } + ItemType type(const QModelIndex& index) const; Qt::ItemFlags flags(const QModelIndex& index) const override diff --git a/gui/include/Catalogue2/eventstreeview.h b/gui/include/Catalogue2/eventstreeview.h index d670f80..37bdda1 100644 --- a/gui/include/Catalogue2/eventstreeview.h +++ b/gui/include/Catalogue2/eventstreeview.h @@ -26,10 +26,12 @@ class EventsTreeView : public QTreeView Q_OBJECT public: EventsTreeView(QWidget* parent = nullptr); + ~EventsTreeView(); signals: void eventSelected(const CatalogueController::Event_ptr& event); - void productSelected(const CatalogueController::Product_t& product, const CatalogueController::Event_ptr& event); + void productSelected( + const CatalogueController::Product_t& product, const CatalogueController::Event_ptr& event); public slots: void setEvents(std::vector events); diff --git a/gui/meson.build b/gui/meson.build index f4dcf46..965c4d8 100644 --- a/gui/meson.build +++ b/gui/meson.build @@ -166,4 +166,9 @@ sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, include_directories : gui_inc, dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core]) +gui_tests_inc = include_directories(['tests/GUITestUtils']) +catalogue_browser_moc_files = qt5.preprocess(moc_sources : 'tests/catalogue/browser/main.cpp') +catalogue_browser = executable('catalogue_browser', 'tests/catalogue/browser/main.cpp',catalogue_browser_moc_files, + include_directories : gui_tests_inc, + dependencies :[sciqlop_gui, qt5test]) diff --git a/gui/src/Catalogue2/eventsmodel.cpp b/gui/src/Catalogue2/eventsmodel.cpp index 5f1d571..0b53932 100644 --- a/gui/src/Catalogue2/eventsmodel.cpp +++ b/gui/src/Catalogue2/eventsmodel.cpp @@ -15,8 +15,8 @@ along with SciQLop. If not, see . */ #include "Catalogue2/eventsmodel.h" -#include #include +#include EventsModel::EventsModel(QObject* parent) : QAbstractItemModel(parent) {} @@ -33,7 +33,7 @@ QVariant EventsModel::data(const QModelIndex& index, int role) const { if (index.isValid()) { - return to_item(index)->data(index.column(),role); + return to_item(index)->data(index.column(), role); } return QVariant {}; } @@ -102,4 +102,93 @@ QVariant EventsModel::headerData(int section, Qt::Orientation orientation, int r return QVariant(); } -void EventsModel::sort(int column, Qt::SortOrder order) {} +void EventsModel::sort(int column, Qt::SortOrder order) +{ + beginResetModel(); + switch (static_cast(column)) + { + case EventsModel::Columns::Name: + std::sort(std::begin(_items), std::end(_items), + [inverse = order != Qt::SortOrder::AscendingOrder]( + const std::unique_ptr& a, + const std::unique_ptr& b) { + static int i = 0; + i++; + if (!a->event()) + { + throw; + } + if (!b->event()) + { + throw; + } + return (a->event()->name < b->event()->name) xor inverse; + }); + break; + case EventsModel::Columns::TStart: + std::sort(std::begin(_items), std::end(_items), + [inverse = order != Qt::SortOrder::AscendingOrder]( + const std::unique_ptr& a, + const std::unique_ptr& b) { + static int i = 0; + i++; + if (!a) + { + throw; + } + if (!b) + { + throw; + } + if (!a->event()) + { + throw; + } + if (!b->event()) + { + throw; + } + return (a->event()->name < b->event()->name) xor inverse; + }); + // std::sort(std::begin(_items), std::end(_items), + // [inverse = order != Qt::SortOrder::AscendingOrder]( + // const std::unique_ptr& a, + // const std::unique_ptr& b) { + // static int i = 0; + // i++; + // if (a and b) + // { + // if (a->type == ItemType::Event and b->type == ItemType::Event) + // { + // if (auto e1 = a->event(); auto e2 = b->event()) + // { + // return bool((e1->startTime() < e2->startTime()) xor + // inverse); + // } + // } + // } + // return false; + // }); + break; + case EventsModel::Columns::TEnd: + std::sort(std::begin(_items), std::end(_items), + [inverse = order != Qt::SortOrder::AscendingOrder]( + const std::unique_ptr& a, + const std::unique_ptr& b) { + if (auto t1 = a->event()->stopTime(); auto t2 = b->event()->stopTime()) + { + if (t1 and t2) + return bool((t1.value() < t2.value()) xor inverse); + } + return true; + }); + break; + case EventsModel::Columns::Product: + break; + case EventsModel::Columns::Tags: + break; + default: + break; + } + endResetModel(); +} diff --git a/gui/src/Catalogue2/eventstreeview.cpp b/gui/src/Catalogue2/eventstreeview.cpp index e11956e..d116904 100644 --- a/gui/src/Catalogue2/eventstreeview.cpp +++ b/gui/src/Catalogue2/eventstreeview.cpp @@ -20,10 +20,16 @@ EventsTreeView::EventsTreeView(QWidget* parent) : QTreeView(parent) { this->setModel(new EventsModel()); - connect(this->selectionModel(), &QItemSelectionModel::currentChanged, [this](const QModelIndex ¤t, const QModelIndex &previous){ - Q_UNUSED(previous); - this->_itemSelected(current); - }); + connect(this->selectionModel(), &QItemSelectionModel::currentChanged, + [this](const QModelIndex& current, const QModelIndex& previous) { + Q_UNUSED(previous); + this->_itemSelected(current); + }); +} + +EventsTreeView::~EventsTreeView() +{ + delete this->model(); } void EventsTreeView::setEvents(std::vector events) @@ -31,7 +37,7 @@ void EventsTreeView::setEvents(std::vector event static_cast(this->model())->setEvents(events); } -void EventsTreeView::_itemSelected(const QModelIndex &index) +void EventsTreeView::_itemSelected(const QModelIndex& index) { auto item = EventsModel::to_item(index); if (item->type == EventsModel::ItemType::Event) diff --git a/gui/tests/catalogue/browser/main.cpp b/gui/tests/catalogue/browser/main.cpp index 2b942cb..d5825a5 100644 --- a/gui/tests/catalogue/browser/main.cpp +++ b/gui/tests/catalogue/browser/main.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include diff --git a/gui/ui/Catalogue2/browser.ui b/gui/ui/Catalogue2/browser.ui index 94750af..bd3d654 100644 --- a/gui/ui/Catalogue2/browser.ui +++ b/gui/ui/Catalogue2/browser.ui @@ -61,6 +61,12 @@ 0 + + true + + + true +