From 9abcd350a7121ddd4c91f145b532119b6333ebd9 2017-12-13 11:15:15 From: Thibaud Rabillard Date: 2017-12-13 11:15:15 Subject: [PATCH] Display catalogues and events with CatalogueAPI --- diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index dab081d..119546f 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -75,6 +75,16 @@ INSTALL(TARGETS ${SQPGUI_LIBRARY_NAME} ) add_dependencies(${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME}) +# Find CATALOGUE_API +include_directories("${CATALOGUEAPI_INCLUDE}") +TARGET_LINK_LIBRARIES(${SQPGUI_LIBRARY_NAME} ${CATALOGUEAPI_LIBRARIES}) +INSTALL(TARGETS ${SQPGUI_LIBRARY_NAME} + RUNTIME DESTINATION ${INSTALL_BINARY_DIR} + LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR} + ARCHIVE DESTINATION ${INSTALL_LIBRARY_DIR} +) + +add_dependencies(${SQPGUI_LIBRARY_NAME} CatalogueAPI) # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order. diff --git a/gui/include/Catalogue/CatalogueEventsWidget.h b/gui/include/Catalogue/CatalogueEventsWidget.h index deae927..456a176 100644 --- a/gui/include/Catalogue/CatalogueEventsWidget.h +++ b/gui/include/Catalogue/CatalogueEventsWidget.h @@ -4,6 +4,9 @@ #include #include +class DBCatalogue; +class DBEvent; + namespace Ui { class CatalogueEventsWidget; } @@ -12,14 +15,14 @@ class CatalogueEventsWidget : public QWidget { Q_OBJECT signals: - void eventSelected(const QString &event); + void eventSelected(const DBEvent &event); public: explicit CatalogueEventsWidget(QWidget *parent = 0); virtual ~CatalogueEventsWidget(); public slots: - void populateWithCatalogue(const QString &catalogue); + void populateWithCatalogue(const DBCatalogue &catalogue); private: Ui::CatalogueEventsWidget *ui; diff --git a/gui/include/Catalogue/CatalogueInspectorWidget.h b/gui/include/Catalogue/CatalogueInspectorWidget.h index b78fd55..2fbe0fd 100644 --- a/gui/include/Catalogue/CatalogueInspectorWidget.h +++ b/gui/include/Catalogue/CatalogueInspectorWidget.h @@ -7,6 +7,9 @@ namespace Ui { class CatalogueInspectorWidget; } +class DBCatalogue; +class DBEvent; + class CatalogueInspectorWidget : public QWidget { Q_OBJECT @@ -19,8 +22,8 @@ public: Page currentPage() const; - void setEvent(const QString &event); - void setCatalogue(const QString &catalogue); + void setEvent(const DBEvent &event); + void setCatalogue(const DBCatalogue &catalogue); public slots: void showPage(Page page); diff --git a/gui/include/Catalogue/CatalogueSideBarWidget.h b/gui/include/Catalogue/CatalogueSideBarWidget.h index b9855dd..7e6fb43 100644 --- a/gui/include/Catalogue/CatalogueSideBarWidget.h +++ b/gui/include/Catalogue/CatalogueSideBarWidget.h @@ -5,6 +5,8 @@ #include #include +#include + namespace Ui { class CatalogueSideBarWidget; } @@ -13,7 +15,7 @@ class CatalogueSideBarWidget : public QWidget { Q_OBJECT signals: - void catalogueSelected(const QString &catalogue); + void catalogueSelected(const DBCatalogue &catalogue); void allEventsSelected(); void trashSelected(); diff --git a/gui/include/Catalogue/CatalogueTreeWidgetItem.h b/gui/include/Catalogue/CatalogueTreeWidgetItem.h new file mode 100644 index 0000000..8402d70 --- /dev/null +++ b/gui/include/Catalogue/CatalogueTreeWidgetItem.h @@ -0,0 +1,22 @@ +#ifndef SCIQLOP_CATALOGUETREEWIDGETITEM_H +#define SCIQLOP_CATALOGUETREEWIDGETITEM_H + +#include +#include + +#include + + +class CatalogueTreeWidgetItem : public QTreeWidgetItem { +public: + CatalogueTreeWidgetItem(DBCatalogue catalogue, int type = QTreeWidgetItem::Type); + + QVariant data(int column, int role) const override; + DBCatalogue catalogue() const; + +private: + class CatalogueTreeWidgetItemPrivate; + spimpl::unique_impl_ptr impl; +}; + +#endif // SCIQLOP_CATALOGUETREEWIDGETITEM_H diff --git a/gui/meson.build b/gui/meson.build index 55e755d..0f3997b 100644 --- a/gui/meson.build +++ b/gui/meson.build @@ -1,4 +1,7 @@ +qxorm_dep = dependency('QxOrm', required : true, fallback:['QxOrm','qxorm_dep']) +catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['CatalogueAPI','CatalogueAPI_dep']) + gui_moc_headers = [ 'include/DataSource/DataSourceWidget.h', 'include/Settings/SqpSettingsDialog.h', @@ -103,7 +106,8 @@ gui_sources = [ 'src/Catalogue/CatalogueExplorer.cpp', 'src/Catalogue/CatalogueEventsWidget.cpp', 'src/Catalogue/CatalogueSideBarWidget.cpp', - 'src/Catalogue/CatalogueInspectorWidget.cpp' + 'src/Catalogue/CatalogueInspectorWidget.cpp', + 'src/Catalogue/CatalogueTreeWidgetItem.cpp' ] gui_inc = include_directories(['include']) @@ -112,11 +116,11 @@ sciqlop_gui_lib = library('sciqlopgui', gui_sources, gui_moc_files, include_directories : [gui_inc], - dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core], + dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep], install : true ) sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib, include_directories : gui_inc, - dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core]) + dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep]) diff --git a/gui/src/Catalogue/CatalogueEventsWidget.cpp b/gui/src/Catalogue/CatalogueEventsWidget.cpp index 3fe0065..5463fd5 100644 --- a/gui/src/Catalogue/CatalogueEventsWidget.cpp +++ b/gui/src/Catalogue/CatalogueEventsWidget.cpp @@ -1,13 +1,22 @@ #include "Catalogue/CatalogueEventsWidget.h" #include "ui_CatalogueEventsWidget.h" -#include +#include +#include +#include +#include + + +/// Format of the dates appearing in the label of a cursor +const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss"); struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { void addEventItem(const QStringList &data, QTableWidget *tableWidget); enum class Column { Event, TStart, TEnd, Tags, Product, NbColumn }; QStringList columnNames() { return QStringList{"Event", "TStart", "TEnd", "Tags", "Product"}; } + + QVector m_Events; }; @@ -31,14 +40,14 @@ CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) }); connect(ui->tableWidget, &QTableWidget::cellClicked, [this](auto row, auto column) { - auto event = ui->tableWidget->item(row, 0)->text(); + auto event = impl->m_Events.value(row); emit this->eventSelected(event); }); connect(ui->tableWidget, &QTableWidget::currentItemChanged, [this](auto current, auto previous) { if (current && current->row() >= 0) { - auto event = ui->tableWidget->item(current->row(), 0)->text(); + auto event = impl->m_Events.value(current->row()); emit this->eventSelected(event); } }); @@ -64,24 +73,30 @@ CatalogueEventsWidget::~CatalogueEventsWidget() delete ui; } -void CatalogueEventsWidget::populateWithCatalogue(const QString &catalogue) +void CatalogueEventsWidget::populateWithCatalogue(const DBCatalogue &catalogue) { ui->tableWidget->clearContents(); ui->tableWidget->setRowCount(0); - // TODO - impl->addEventItem( - {catalogue + " - Event 1", "12/12/2012 12:12", "12/12/2042 12:52", "cloud", "mfi/b_gse42"}, - ui->tableWidget); - impl->addEventItem( - {catalogue + " - Event 2", "12/12/2012 12:10", "12/12/2042 12:42", "Acloud", "mfi/b_gse1"}, - ui->tableWidget); - impl->addEventItem( - {catalogue + " - Event 3", "12/12/2012 12:22", "12/12/2042 12:12", "Gcloud", "mfi/b_gse2"}, - ui->tableWidget); - impl->addEventItem( - {catalogue + " - Event 4", "12/12/2012 12:00", "12/12/2042 12:62", "Bcloud", "mfi/b_gse3"}, - ui->tableWidget); + auto &dao = sqpApp->catalogueController().getDao(); + auto events = dao.getCatalogueEvents(catalogue); + + for (auto event : events) { + impl->m_Events << event; + + auto tags = event.getTags(); + QString tagList; + for (auto tag : tags) { + tagList += tag.getName(); + tagList += ' '; + } + + impl->addEventItem({event.getName(), + DateUtils::dateTime(event.getTStart()).toString(DATETIME_FORMAT), + DateUtils::dateTime(event.getTEnd()).toString(DATETIME_FORMAT), tagList, + event.getProduct()}, + ui->tableWidget); + } } void CatalogueEventsWidget::CatalogueEventsWidgetPrivate::addEventItem(const QStringList &data, diff --git a/gui/src/Catalogue/CatalogueExplorer.cpp b/gui/src/Catalogue/CatalogueExplorer.cpp index c286298..e755148 100644 --- a/gui/src/Catalogue/CatalogueExplorer.cpp +++ b/gui/src/Catalogue/CatalogueExplorer.cpp @@ -1,19 +1,22 @@ #include "Catalogue/CatalogueExplorer.h" #include "ui_CatalogueExplorer.h" +#include +#include + CatalogueExplorer::CatalogueExplorer(QWidget *parent) : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint), ui(new Ui::CatalogueExplorer) { ui->setupUi(this); - connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto name) { - ui->inspector->setCatalogue(name); - ui->events->populateWithCatalogue(name); + connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogue) { + ui->inspector->setCatalogue(catalogue); + ui->events->populateWithCatalogue(catalogue); }); connect(ui->events, &CatalogueEventsWidget::eventSelected, - [this](auto name) { ui->inspector->setEvent(name); }); + [this](auto event) { ui->inspector->setEvent(event); }); } CatalogueExplorer::~CatalogueExplorer() diff --git a/gui/src/Catalogue/CatalogueInspectorWidget.cpp b/gui/src/Catalogue/CatalogueInspectorWidget.cpp index 5cb782e..269bd50 100644 --- a/gui/src/Catalogue/CatalogueInspectorWidget.cpp +++ b/gui/src/Catalogue/CatalogueInspectorWidget.cpp @@ -1,6 +1,11 @@ #include "Catalogue/CatalogueInspectorWidget.h" #include "ui_CatalogueInspectorWidget.h" +#include +#include +#include +#include + CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent) : QWidget(parent), ui(new Ui::CatalogueInspectorWidget) { @@ -23,14 +28,29 @@ CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const return static_cast(ui->stackedWidget->currentIndex()); } -void CatalogueInspectorWidget::setEvent(const QString &event) +void CatalogueInspectorWidget::setEvent(const DBEvent &event) { showPage(Page::EventProperties); - ui->leEventName->setText(event); + ui->leEventName->setText(event.getName()); + ui->leEventMission->setText(event.getMission()); + ui->leEventProduct->setText(event.getProduct()); + + QString tagList; + auto tags = const_cast(&event)->getTags(); + for (auto tag : tags) { + tagList += tag.getName(); + tagList += ' '; + } + + ui->leEventTags->setText(tagList); + + ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event.getTStart())); + ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event.getTEnd())); } -void CatalogueInspectorWidget::setCatalogue(const QString &catalogue) +void CatalogueInspectorWidget::setCatalogue(const DBCatalogue &catalogue) { showPage(Page::CatalogueProperties); - ui->leCatalogueName->setText(catalogue); + ui->leCatalogueName->setText(catalogue.getName()); + ui->leCatalogueAuthor->setText(catalogue.getAuthor()); } diff --git a/gui/src/Catalogue/CatalogueSideBarWidget.cpp b/gui/src/Catalogue/CatalogueSideBarWidget.cpp index f5ade50..aa91bc0 100644 --- a/gui/src/Catalogue/CatalogueSideBarWidget.cpp +++ b/gui/src/Catalogue/CatalogueSideBarWidget.cpp @@ -1,5 +1,13 @@ #include "Catalogue/CatalogueSideBarWidget.h" #include "ui_CatalogueSideBarWidget.h" +#include + +#include +#include +#include +#include +#include + constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType; constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1; @@ -8,9 +16,12 @@ constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3; struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { + + QHash m_CatalogueMap; + void configureTreeWidget(QTreeWidget *treeWidget); QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget); - void addCatalogueItem(const QString &name, QTreeWidgetItem *parentDatabaseItem); + void addCatalogueItem(const DBCatalogue &catalogue, QTreeWidgetItem *parentDatabaseItem); }; CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) @@ -24,7 +35,8 @@ CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) auto emitSelection = [this](auto item) { switch (item->type()) { case CATALOGUE_ITEM_TYPE: - emit this->catalogueSelected(item->text(0)); + emit this->catalogueSelected( + static_cast(item)->catalogue()); break; case ALL_EVENT_ITEM_TYPE: emit this->allEventsSelected(); @@ -67,16 +79,16 @@ void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget( treeWidget->setItemWidget(separatorItem, 0, separator); // Test - auto db = addDatabaseItem("Database 1", treeWidget); - addCatalogueItem("Catalogue 1", db); - addCatalogueItem("Catalogue 2", db); - addCatalogueItem("Catalogue 3", db); - addCatalogueItem("Catalogue 4", db); + auto &dao = sqpApp->catalogueController().getDao(); + auto allPredicate = std::make_shared(QString{"uniqId"}, "-1", + ComparaisonOperation::DIFFERENT); + + auto db = addDatabaseItem("Default", treeWidget); - auto db2 = addDatabaseItem("Database 2", treeWidget); - addCatalogueItem("Catalogue A", db2); - addCatalogueItem("Catalogue B", db2); - addCatalogueItem("Catalogue C", db2); + auto catalogues = dao.getCatalogues(allPredicate); + for (auto catalogue : catalogues) { + addCatalogueItem(catalogue, db); + } treeWidget->expandAll(); } @@ -93,9 +105,9 @@ CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QSt } void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( - const QString &name, QTreeWidgetItem *parentDatabaseItem) + const DBCatalogue &catalogue, QTreeWidgetItem *parentDatabaseItem) { - auto catalogueItem = new QTreeWidgetItem({name}, CATALOGUE_ITEM_TYPE); + auto catalogueItem = new CatalogueTreeWidgetItem(catalogue, CATALOGUE_ITEM_TYPE); catalogueItem->setIcon(0, QIcon(":/icones/catalogue.png")); parentDatabaseItem->addChild(catalogueItem); } diff --git a/gui/src/Catalogue/CatalogueTreeWidgetItem.cpp b/gui/src/Catalogue/CatalogueTreeWidgetItem.cpp new file mode 100644 index 0000000..95fb0f1 --- /dev/null +++ b/gui/src/Catalogue/CatalogueTreeWidgetItem.cpp @@ -0,0 +1,32 @@ +#include "Catalogue/CatalogueTreeWidgetItem.h" + +struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate { + + DBCatalogue m_Catalogue; + + CatalogueTreeWidgetItemPrivate(DBCatalogue catalogue) : m_Catalogue(catalogue) {} +}; + + +CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(DBCatalogue catalogue, int type) + : QTreeWidgetItem(type), + impl{spimpl::make_unique_impl(catalogue)} +{ +} + +QVariant CatalogueTreeWidgetItem::data(int column, int role) const +{ + switch (role) { + case Qt::DisplayRole: + return impl->m_Catalogue.getName(); + default: + break; + } + + return QTreeWidgetItem::data(column, role); +} + +DBCatalogue CatalogueTreeWidgetItem::catalogue() const +{ + return impl->m_Catalogue; +}