##// END OF EJS Templates
Edition of catalogues from the inspector
trabillard -
r1180:938a31670f5f
parent child
Show More
@@ -1,36 +1,44
1 #ifndef SCIQLOP_CATALOGUEINSPECTORWIDGET_H
1 #ifndef SCIQLOP_CATALOGUEINSPECTORWIDGET_H
2 #define SCIQLOP_CATALOGUEINSPECTORWIDGET_H
2 #define SCIQLOP_CATALOGUEINSPECTORWIDGET_H
3
3
4 #include <Common/spimpl.h>
4 #include <QWidget>
5 #include <QWidget>
5 #include <memory>
6 #include <memory>
6
7
7 namespace Ui {
8 namespace Ui {
8 class CatalogueInspectorWidget;
9 class CatalogueInspectorWidget;
9 }
10 }
10
11
11 class DBCatalogue;
12 class DBCatalogue;
12 class DBEvent;
13 class DBEvent;
13
14
14 class CatalogueInspectorWidget : public QWidget {
15 class CatalogueInspectorWidget : public QWidget {
15 Q_OBJECT
16 Q_OBJECT
16
17
18 signals:
19 void catalogueUpdated(const std::shared_ptr<DBCatalogue> &catalogue);
20 void eventUpdated(const std::shared_ptr<DBEvent> &event);
21
17 public:
22 public:
18 explicit CatalogueInspectorWidget(QWidget *parent = 0);
23 explicit CatalogueInspectorWidget(QWidget *parent = 0);
19 virtual ~CatalogueInspectorWidget();
24 virtual ~CatalogueInspectorWidget();
20
25
21 /// Enum matching the pages inside the stacked widget
26 /// Enum matching the pages inside the stacked widget
22 enum class Page { Empty, CatalogueProperties, EventProperties };
27 enum class Page { Empty, CatalogueProperties, EventProperties };
23
28
24 Page currentPage() const;
29 Page currentPage() const;
25
30
26 void setEvent(const std::shared_ptr<DBEvent> &event);
31 void setEvent(const std::shared_ptr<DBEvent> &event);
27 void setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue);
32 void setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue);
28
33
29 public slots:
34 public slots:
30 void showPage(Page page);
35 void showPage(Page page);
31
36
32 private:
37 private:
33 Ui::CatalogueInspectorWidget *ui;
38 Ui::CatalogueInspectorWidget *ui;
39
40 class CatalogueInspectorWidgetPrivate;
41 spimpl::unique_impl_ptr<CatalogueInspectorWidgetPrivate> impl;
34 };
42 };
35
43
36 #endif // SCIQLOP_CATALOGUEINSPECTORWIDGET_H
44 #endif // SCIQLOP_CATALOGUEINSPECTORWIDGET_H
@@ -1,38 +1,43
1 #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H
1 #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H
2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QLoggingCategory>
5 #include <QTreeWidgetItem>
6 #include <QTreeWidgetItem>
6 #include <QWidget>
7 #include <QWidget>
7
8
8 class DBCatalogue;
9 class DBCatalogue;
9
10
10 namespace Ui {
11 namespace Ui {
11 class CatalogueSideBarWidget;
12 class CatalogueSideBarWidget;
12 }
13 }
13
14
15 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget)
16
14 class CatalogueSideBarWidget : public QWidget {
17 class CatalogueSideBarWidget : public QWidget {
15 Q_OBJECT
18 Q_OBJECT
16
19
17 signals:
20 signals:
18 void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
21 void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
19 void databaseSelected(const QStringList &databases);
22 void databaseSelected(const QStringList &databases);
20 void allEventsSelected();
23 void allEventsSelected();
21 void trashSelected();
24 void trashSelected();
22 void selectionCleared();
25 void selectionCleared();
23
26
24 public:
27 public:
25 explicit CatalogueSideBarWidget(QWidget *parent = 0);
28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
26 virtual ~CatalogueSideBarWidget();
29 virtual ~CatalogueSideBarWidget();
27
30
31 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
32
28 private:
33 private:
29 Ui::CatalogueSideBarWidget *ui;
34 Ui::CatalogueSideBarWidget *ui;
30
35
31 class CatalogueSideBarWidgetPrivate;
36 class CatalogueSideBarWidgetPrivate;
32 spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl;
37 spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl;
33
38
34 private slots:
39 private slots:
35 void onContextMenuRequested(const QPoint &pos);
40 void onContextMenuRequested(const QPoint &pos);
36 };
41 };
37
42
38 #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H
43 #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H
@@ -1,28 +1,33
1 #ifndef SCIQLOP_CATALOGUETREEWIDGETITEM_H
1 #ifndef SCIQLOP_CATALOGUETREEWIDGETITEM_H
2 #define SCIQLOP_CATALOGUETREEWIDGETITEM_H
2 #define SCIQLOP_CATALOGUETREEWIDGETITEM_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QTreeWidgetItem>
5 #include <QTreeWidgetItem>
6
6
7 class DBCatalogue;
7 class DBCatalogue;
8
8
9
9
10 class CatalogueTreeWidgetItem : public QTreeWidgetItem {
10 class CatalogueTreeWidgetItem : public QTreeWidgetItem {
11 public:
11 public:
12 CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue,
12 CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue,
13 int type = QTreeWidgetItem::Type);
13 int type = QTreeWidgetItem::Type);
14
14
15 QVariant data(int column, int role) const override;
15 QVariant data(int column, int role) const override;
16 void setData(int column, int role, const QVariant &value) override;
16 void setData(int column, int role, const QVariant &value) override;
17
17
18 /// Returns the catalogue represented by the item
18 /// Returns the catalogue represented by the item
19 std::shared_ptr<DBCatalogue> catalogue() const;
19 std::shared_ptr<DBCatalogue> catalogue() const;
20
20
21 /// Displays or hides the save and cancel buttons indicating that the catalogue has unsaved
22 /// changes
21 void setHasChanges(bool value);
23 void setHasChanges(bool value);
22
24
25 /// Refreshes the data displayed by the item from the catalogue
26 void refresh();
27
23 private:
28 private:
24 class CatalogueTreeWidgetItemPrivate;
29 class CatalogueTreeWidgetItemPrivate;
25 spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl;
30 spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl;
26 };
31 };
27
32
28 #endif // SCIQLOP_CATALOGUETREEWIDGETITEM_H
33 #endif // SCIQLOP_CATALOGUETREEWIDGETITEM_H
@@ -1,61 +1,64
1 #include "Catalogue/CatalogueExplorer.h"
1 #include "Catalogue/CatalogueExplorer.h"
2 #include "ui_CatalogueExplorer.h"
2 #include "ui_CatalogueExplorer.h"
3
3
4 #include <Visualization/VisualizationWidget.h>
4 #include <Visualization/VisualizationWidget.h>
5
5
6 #include <DBCatalogue.h>
6 #include <DBCatalogue.h>
7 #include <DBEvent.h>
7 #include <DBEvent.h>
8
8
9 struct CatalogueExplorer::CatalogueExplorerPrivate {
9 struct CatalogueExplorer::CatalogueExplorerPrivate {
10 };
10 };
11
11
12 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
12 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
13 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
13 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
14 ui(new Ui::CatalogueExplorer),
14 ui(new Ui::CatalogueExplorer),
15 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>()}
15 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>()}
16 {
16 {
17 ui->setupUi(this);
17 ui->setupUi(this);
18
18
19 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
19 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
20 if (catalogues.count() == 1) {
20 if (catalogues.count() == 1) {
21 ui->inspector->setCatalogue(catalogues.first());
21 ui->inspector->setCatalogue(catalogues.first());
22 }
22 }
23 else {
23 else {
24 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
24 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
25 }
25 }
26
26
27 ui->events->populateWithCatalogues(catalogues);
27 ui->events->populateWithCatalogues(catalogues);
28 });
28 });
29
29
30 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) {
30 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) {
31 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
31 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
32 });
32 });
33
33
34 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected,
34 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected,
35 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
35 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
36
36
37 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected,
37 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected,
38 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
38 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
39
39
40 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared,
40 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared,
41 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
41 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
42
42
43 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
43 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
44 if (events.count() == 1) {
44 if (events.count() == 1) {
45 ui->inspector->setEvent(events.first());
45 ui->inspector->setEvent(events.first());
46 }
46 }
47 else {
47 else {
48 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
48 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
49 }
49 }
50 });
50 });
51
52 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated,
53 [this](auto catalogue) { ui->catalogues->setCatalogueChanges(catalogue, true); });
51 }
54 }
52
55
53 CatalogueExplorer::~CatalogueExplorer()
56 CatalogueExplorer::~CatalogueExplorer()
54 {
57 {
55 delete ui;
58 delete ui;
56 }
59 }
57
60
58 void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization)
61 void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization)
59 {
62 {
60 ui->events->setVisualizationWidget(visualization);
63 ui->events->setVisualizationWidget(visualization);
61 }
64 }
@@ -1,56 +1,89
1 #include "Catalogue/CatalogueInspectorWidget.h"
1 #include "Catalogue/CatalogueInspectorWidget.h"
2 #include "ui_CatalogueInspectorWidget.h"
2 #include "ui_CatalogueInspectorWidget.h"
3
3
4 #include <Common/DateUtils.h>
4 #include <Common/DateUtils.h>
5 #include <DBCatalogue.h>
5 #include <DBCatalogue.h>
6 #include <DBEvent.h>
6 #include <DBEvent.h>
7 #include <DBTag.h>
7 #include <DBTag.h>
8
8
9 struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate {
10 std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr;
11 std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr;
12 };
13
9 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
14 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
10 : QWidget(parent), ui(new Ui::CatalogueInspectorWidget)
15 : QWidget(parent),
16 ui(new Ui::CatalogueInspectorWidget),
17 impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()}
11 {
18 {
12 ui->setupUi(this);
19 ui->setupUi(this);
13 showPage(Page::Empty);
20 showPage(Page::Empty);
21
22 connect(ui->leCatalogueName, &QLineEdit::editingFinished, [this]() {
23 if (ui->leCatalogueName->text() != impl->m_DisplayedCatalogue->getName()) {
24 impl->m_DisplayedCatalogue->setName(ui->leCatalogueName->text());
25 emit this->catalogueUpdated(impl->m_DisplayedCatalogue);
26 }
27 });
28
29 connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [this]() {
30 if (ui->leCatalogueAuthor->text() != impl->m_DisplayedCatalogue->getAuthor()) {
31 impl->m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text());
32 emit this->catalogueUpdated(impl->m_DisplayedCatalogue);
33 }
34 });
14 }
35 }
15
36
16 CatalogueInspectorWidget::~CatalogueInspectorWidget()
37 CatalogueInspectorWidget::~CatalogueInspectorWidget()
17 {
38 {
18 delete ui;
39 delete ui;
19 }
40 }
20
41
21 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
42 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
22 {
43 {
23 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
44 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
24 }
45 }
25
46
26 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
47 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
27 {
48 {
28 return static_cast<Page>(ui->stackedWidget->currentIndex());
49 return static_cast<Page>(ui->stackedWidget->currentIndex());
29 }
50 }
30
51
31 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
52 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
32 {
53 {
54 impl->m_DisplayedEvent = event;
55
56 blockSignals(true);
57
33 showPage(Page::EventProperties);
58 showPage(Page::EventProperties);
34 ui->leEventName->setText(event->getName());
59 ui->leEventName->setText(event->getName());
35 ui->leEventMission->setText(event->getMission());
60 ui->leEventMission->setText(event->getMission());
36 ui->leEventProduct->setText(event->getProduct());
61 ui->leEventProduct->setText(event->getProduct());
37
62
38 QString tagList;
63 QString tagList;
39 auto tags = event->getTags();
64 auto tags = event->getTags();
40 for (auto tag : tags) {
65 for (auto tag : tags) {
41 tagList += tag.getName();
66 tagList += tag.getName();
42 tagList += ' ';
67 tagList += ' ';
43 }
68 }
44
69
45 ui->leEventTags->setText(tagList);
70 ui->leEventTags->setText(tagList);
46
71
47 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
72 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
48 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
73 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
74
75 blockSignals(false);
49 }
76 }
50
77
51 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
78 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
52 {
79 {
80 impl->m_DisplayedCatalogue = catalogue;
81
82 blockSignals(true);
83
53 showPage(Page::CatalogueProperties);
84 showPage(Page::CatalogueProperties);
54 ui->leCatalogueName->setText(catalogue->getName());
85 ui->leCatalogueName->setText(catalogue->getName());
55 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
86 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
87
88 blockSignals(false);
56 }
89 }
@@ -1,198 +1,247
1 #include "Catalogue/CatalogueSideBarWidget.h"
1 #include "Catalogue/CatalogueSideBarWidget.h"
2 #include "ui_CatalogueSideBarWidget.h"
2 #include "ui_CatalogueSideBarWidget.h"
3 #include <SqpApplication.h>
3 #include <SqpApplication.h>
4
4
5 #include <Catalogue/CatalogueController.h>
5 #include <Catalogue/CatalogueController.h>
6 #include <Catalogue/CatalogueTreeWidgetItem.h>
6 #include <Catalogue/CatalogueTreeWidgetItem.h>
7 #include <CatalogueDao.h>
7 #include <CatalogueDao.h>
8 #include <ComparaisonPredicate.h>
8 #include <ComparaisonPredicate.h>
9 #include <DBCatalogue.h>
9 #include <DBCatalogue.h>
10
10
11 #include <QMenu>
11 #include <QMenu>
12
12
13 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
14
13
15
14 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
16 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
15 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
17 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
16 constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2;
18 constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2;
17 constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3;
19 constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3;
18
20
19
21
20 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
22 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
21
23
22 void configureTreeWidget(QTreeWidget *treeWidget);
24 void configureTreeWidget(QTreeWidget *treeWidget);
23 QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget);
25 QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget);
24 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
26 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
25 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
27 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
26 QTreeWidgetItem *parentDatabaseItem);
28 QTreeWidgetItem *parentDatabaseItem);
29
30 CatalogueTreeWidgetItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
31 QTreeWidget *treeWidget) const;
27 };
32 };
28
33
29 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
34 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
30 : QWidget(parent),
35 : QWidget(parent),
31 ui(new Ui::CatalogueSideBarWidget),
36 ui(new Ui::CatalogueSideBarWidget),
32 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
37 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
33 {
38 {
34 ui->setupUi(this);
39 ui->setupUi(this);
35 impl->configureTreeWidget(ui->treeWidget);
40 impl->configureTreeWidget(ui->treeWidget);
36
41
37 ui->treeWidget->setColumnCount(2);
42 ui->treeWidget->setColumnCount(2);
38 ui->treeWidget->header()->setStretchLastSection(false);
43 ui->treeWidget->header()->setStretchLastSection(false);
39 ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
44 ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
40 ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
45 ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
41
46
42 auto emitSelection = [this]() {
47 auto emitSelection = [this]() {
43
48
44 auto selectedItems = ui->treeWidget->selectedItems();
49 auto selectedItems = ui->treeWidget->selectedItems();
45 if (selectedItems.isEmpty()) {
50 if (selectedItems.isEmpty()) {
46 emit this->selectionCleared();
51 emit this->selectionCleared();
47 }
52 }
48 else {
53 else {
49 QVector<std::shared_ptr<DBCatalogue> > catalogues;
54 QVector<std::shared_ptr<DBCatalogue> > catalogues;
50 QStringList databases;
55 QStringList databases;
51 int selectionType = selectedItems.first()->type();
56 int selectionType = selectedItems.first()->type();
52
57
53 for (auto item : ui->treeWidget->selectedItems()) {
58 for (auto item : ui->treeWidget->selectedItems()) {
54 if (item->type() == selectionType) {
59 if (item->type() == selectionType) {
55 switch (selectionType) {
60 switch (selectionType) {
56 case CATALOGUE_ITEM_TYPE:
61 case CATALOGUE_ITEM_TYPE:
57 catalogues.append(
62 catalogues.append(
58 static_cast<CatalogueTreeWidgetItem *>(item)->catalogue());
63 static_cast<CatalogueTreeWidgetItem *>(item)->catalogue());
59 break;
64 break;
60 case DATABASE_ITEM_TYPE:
65 case DATABASE_ITEM_TYPE:
61 selectionType = DATABASE_ITEM_TYPE;
66 selectionType = DATABASE_ITEM_TYPE;
62 databases.append(item->text(0));
67 databases.append(item->text(0));
63 case ALL_EVENT_ITEM_TYPE: // fallthrough
68 case ALL_EVENT_ITEM_TYPE: // fallthrough
64 case TRASH_ITEM_TYPE: // fallthrough
69 case TRASH_ITEM_TYPE: // fallthrough
65 default:
70 default:
66 break;
71 break;
67 }
72 }
68 }
73 }
69 else {
74 else {
70 // Incoherent multi selection
75 // Incoherent multi selection
71 selectionType = -1;
76 selectionType = -1;
72 break;
77 break;
73 }
78 }
74 }
79 }
75
80
76 switch (selectionType) {
81 switch (selectionType) {
77 case CATALOGUE_ITEM_TYPE:
82 case CATALOGUE_ITEM_TYPE:
78 emit this->catalogueSelected(catalogues);
83 emit this->catalogueSelected(catalogues);
79 break;
84 break;
80 case DATABASE_ITEM_TYPE:
85 case DATABASE_ITEM_TYPE:
81 emit this->databaseSelected(databases);
86 emit this->databaseSelected(databases);
82 break;
87 break;
83 case ALL_EVENT_ITEM_TYPE:
88 case ALL_EVENT_ITEM_TYPE:
84 emit this->allEventsSelected();
89 emit this->allEventsSelected();
85 break;
90 break;
86 case TRASH_ITEM_TYPE:
91 case TRASH_ITEM_TYPE:
87 emit this->trashSelected();
92 emit this->trashSelected();
88 break;
93 break;
89 default:
94 default:
90 emit this->selectionCleared();
95 emit this->selectionCleared();
91 break;
96 break;
92 }
97 }
93 }
98 }
94
99
95
100
96 };
101 };
97
102
98 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
103 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
99 connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection);
104 connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection);
105 connect(ui->treeWidget, &QTreeWidget::itemChanged,
106 [emitSelection, this](auto item, auto column) {
107 auto selectedItems = ui->treeWidget->selectedItems();
108 qDebug() << "ITEM CHANGED" << column;
109 if (selectedItems.contains(item) && column == 0) {
110 emitSelection();
111 }
112 });
100
113
101 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
114 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
102 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
115 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
103 &CatalogueSideBarWidget::onContextMenuRequested);
116 &CatalogueSideBarWidget::onContextMenuRequested);
104 }
117 }
105
118
106 CatalogueSideBarWidget::~CatalogueSideBarWidget()
119 CatalogueSideBarWidget::~CatalogueSideBarWidget()
107 {
120 {
108 delete ui;
121 delete ui;
109 }
122 }
110
123
124 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
125 bool hasChanges)
126 {
127 if (auto catalogueItem = impl->getCatalogueItem(catalogue, ui->treeWidget)) {
128 catalogueItem->setHasChanges(hasChanges);
129 catalogueItem->refresh();
130 }
131 }
132
111 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
133 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
112 {
134 {
113 QMenu menu{this};
135 QMenu menu{this};
114
136
115 auto currentItem = ui->treeWidget->currentItem();
137 auto currentItem = ui->treeWidget->currentItem();
116 switch (currentItem->type()) {
138 switch (currentItem->type()) {
117 case CATALOGUE_ITEM_TYPE:
139 case CATALOGUE_ITEM_TYPE:
118 menu.addAction("Rename",
140 menu.addAction("Rename",
119 [this, currentItem]() { ui->treeWidget->editItem(currentItem); });
141 [this, currentItem]() { ui->treeWidget->editItem(currentItem); });
120 break;
142 break;
121 case DATABASE_ITEM_TYPE:
143 case DATABASE_ITEM_TYPE:
122 break;
144 break;
123 case ALL_EVENT_ITEM_TYPE:
145 case ALL_EVENT_ITEM_TYPE:
124 break;
146 break;
125 case TRASH_ITEM_TYPE:
147 case TRASH_ITEM_TYPE:
126 menu.addAction("Empty Trash", []() {
148 menu.addAction("Empty Trash", []() {
127 // TODO
149 // TODO
128 });
150 });
129 break;
151 break;
130 default:
152 default:
131 break;
153 break;
132 }
154 }
133
155
134 if (!menu.isEmpty()) {
156 if (!menu.isEmpty()) {
135 menu.exec(ui->treeWidget->mapToGlobal(pos));
157 menu.exec(ui->treeWidget->mapToGlobal(pos));
136 }
158 }
137 }
159 }
138
160
139 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(
161 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(
140 QTreeWidget *treeWidget)
162 QTreeWidget *treeWidget)
141 {
163 {
142 auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE};
164 auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE};
143 allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png"));
165 allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png"));
144 treeWidget->addTopLevelItem(allEventsItem);
166 treeWidget->addTopLevelItem(allEventsItem);
145
167
146 auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE};
168 auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE};
147 trashItem->setIcon(0, QIcon(":/icones/trash.png"));
169 trashItem->setIcon(0, QIcon(":/icones/trash.png"));
148 treeWidget->addTopLevelItem(trashItem);
170 treeWidget->addTopLevelItem(trashItem);
149
171
150 auto separator = new QFrame{treeWidget};
172 auto separator = new QFrame{treeWidget};
151 separator->setFrameShape(QFrame::HLine);
173 separator->setFrameShape(QFrame::HLine);
152 auto separatorItem = new QTreeWidgetItem{};
174 auto separatorItem = new QTreeWidgetItem{};
153 separatorItem->setFlags(Qt::NoItemFlags);
175 separatorItem->setFlags(Qt::NoItemFlags);
154 treeWidget->addTopLevelItem(separatorItem);
176 treeWidget->addTopLevelItem(separatorItem);
155 treeWidget->setItemWidget(separatorItem, 0, separator);
177 treeWidget->setItemWidget(separatorItem, 0, separator);
156
178
157 auto db = addDatabaseItem("Default", treeWidget);
179 auto db = addDatabaseItem("Default", treeWidget);
158
180
159 auto catalogues = sqpApp->catalogueController().getCatalogues("Default");
181 auto catalogues = sqpApp->catalogueController().getCatalogues("Default");
160 for (auto catalogue : catalogues) {
182 for (auto catalogue : catalogues) {
161 addCatalogueItem(catalogue, db);
183 addCatalogueItem(catalogue, db);
162 }
184 }
163
185
164 treeWidget->expandAll();
186 treeWidget->expandAll();
165 }
187 }
166
188
167 QTreeWidgetItem *
189 QTreeWidgetItem *
168 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name,
190 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name,
169 QTreeWidget *treeWidget)
191 QTreeWidget *treeWidget)
170 {
192 {
171 auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE};
193 auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE};
172 databaseItem->setIcon(0, QIcon{":/icones/database.png"});
194 databaseItem->setIcon(0, QIcon{":/icones/database.png"});
173 treeWidget->addTopLevelItem(databaseItem);
195 treeWidget->addTopLevelItem(databaseItem);
174
196
175 return databaseItem;
197 return databaseItem;
176 }
198 }
177
199
178 QTreeWidgetItem *
200 QTreeWidgetItem *
179 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name,
201 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name,
180 QTreeWidget *treeWidget)
202 QTreeWidget *treeWidget)
181 {
203 {
182 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
204 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
183 auto item = treeWidget->topLevelItem(i);
205 auto item = treeWidget->topLevelItem(i);
184 if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) {
206 if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) {
185 return item;
207 return item;
186 }
208 }
187 }
209 }
188
210
189 return nullptr;
211 return nullptr;
190 }
212 }
191
213
192 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
214 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
193 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidgetItem *parentDatabaseItem)
215 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidgetItem *parentDatabaseItem)
194 {
216 {
195 auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE};
217 auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE};
196 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
218 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
197 parentDatabaseItem->addChild(catalogueItem);
219 parentDatabaseItem->addChild(catalogueItem);
198 }
220 }
221
222 CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
223 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidget *treeWidget) const
224 {
225 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
226 auto item = treeWidget->topLevelItem(i);
227 if (item->type() == DATABASE_ITEM_TYPE) {
228 for (auto j = 0; j < item->childCount(); ++j) {
229 auto childItem = item->child(j);
230 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
231 auto catalogueItem = static_cast<CatalogueTreeWidgetItem *>(childItem);
232 if (catalogueItem->catalogue() == catalogue) {
233 return catalogueItem;
234 }
235 }
236 else {
237 qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree "
238 "structure. A database item should "
239 "only contain catalogues.";
240 Q_ASSERT(false);
241 }
242 }
243 }
244 }
245
246 return nullptr;
247 }
@@ -1,93 +1,103
1 #include "Catalogue/CatalogueTreeWidgetItem.h"
1 #include "Catalogue/CatalogueTreeWidgetItem.h"
2
2
3 #include <memory>
3 #include <memory>
4
4
5 #include <DBCatalogue.h>
5 #include <DBCatalogue.h>
6 #include <QBoxLayout>
6 #include <QBoxLayout>
7 #include <QToolButton>
7 #include <QToolButton>
8
8
9 const auto VALIDATION_BUTTON_ICON_SIZE = 12;
9 const auto VALIDATION_BUTTON_ICON_SIZE = 12;
10
10
11 /// Column in the tree widget where the apply and cancel buttons must appear
12 const auto APPLY_CANCEL_BUTTONS_COLUMN = 1;
13
11 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
14 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
12
15
13 std::shared_ptr<DBCatalogue> m_Catalogue;
16 std::shared_ptr<DBCatalogue> m_Catalogue;
14
17
15 CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue)
18 CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue)
16 {
19 {
17 }
20 }
18 };
21 };
19
22
20
23
21 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type)
24 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type)
22 : QTreeWidgetItem(type),
25 : QTreeWidgetItem(type),
23 impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
26 impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
24 {
27 {
25 setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
28 setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
26 }
29 }
27
30
28 QVariant CatalogueTreeWidgetItem::data(int column, int role) const
31 QVariant CatalogueTreeWidgetItem::data(int column, int role) const
29 {
32 {
30 if (column == 0) {
33 if (column == 0) {
31 switch (role) {
34 switch (role) {
32 case Qt::EditRole: // fallthrough
35 case Qt::EditRole: // fallthrough
33 case Qt::DisplayRole:
36 case Qt::DisplayRole:
34 return impl->m_Catalogue->getName();
37 return impl->m_Catalogue->getName();
35 default:
38 default:
36 break;
39 break;
37 }
40 }
38 }
41 }
39
42
40 return QTreeWidgetItem::data(column, role);
43 return QTreeWidgetItem::data(column, role);
41 }
44 }
42
45
43 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &value)
46 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &value)
44 {
47 {
45 if (role == Qt::EditRole && column == 0) {
48 if (role == Qt::EditRole && column == 0) {
46 auto newName = value.toString();
49 auto newName = value.toString();
47 if (newName != impl->m_Catalogue->getName()) {
50 if (newName != impl->m_Catalogue->getName()) {
48 setText(0, newName);
51 setText(0, newName);
49 impl->m_Catalogue->setName(newName);
52 impl->m_Catalogue->setName(newName);
50 setHasChanges(true);
53 setHasChanges(true);
51 }
54 }
52 }
55 }
53 else {
56 else {
54 QTreeWidgetItem::setData(column, role, value);
57 QTreeWidgetItem::setData(column, role, value);
55 }
58 }
56 }
59 }
57
60
58 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
61 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
59 {
62 {
60 return impl->m_Catalogue;
63 return impl->m_Catalogue;
61 }
64 }
62
65
63 void CatalogueTreeWidgetItem::setHasChanges(bool value)
66 void CatalogueTreeWidgetItem::setHasChanges(bool value)
64 {
67 {
65 if (value) {
68 if (value) {
69 if (treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) == nullptr) {
66 auto widet = new QWidget{treeWidget()};
70 auto widet = new QWidget{treeWidget()};
67
71
68 auto layout = new QHBoxLayout{widet};
72 auto layout = new QHBoxLayout{widet};
69 layout->setContentsMargins(0, 0, 0, 0);
73 layout->setContentsMargins(0, 0, 0, 0);
70 layout->setSpacing(0);
74 layout->setSpacing(0);
71
75
72 auto btnValid = new QToolButton{widet};
76 auto btnValid = new QToolButton{widet};
73 btnValid->setIcon(QIcon{":/icones/save"});
77 btnValid->setIcon(QIcon{":/icones/save"});
74 btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
78 btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
75 btnValid->setAutoRaise(true);
79 btnValid->setAutoRaise(true);
76 QObject::connect(btnValid, &QToolButton::clicked, [this]() { setHasChanges(false); });
80 QObject::connect(btnValid, &QToolButton::clicked, [this]() { setHasChanges(false); });
77 layout->addWidget(btnValid);
81 layout->addWidget(btnValid);
78
82
79 auto btnDiscard = new QToolButton{widet};
83 auto btnDiscard = new QToolButton{widet};
80 btnDiscard->setIcon(QIcon{":/icones/discard"});
84 btnDiscard->setIcon(QIcon{":/icones/discard"});
81 btnDiscard->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
85 btnDiscard->setIconSize(
86 QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
82 btnDiscard->setAutoRaise(true);
87 btnDiscard->setAutoRaise(true);
83 QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); });
88 QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); });
84 layout->addWidget(btnDiscard);
89 layout->addWidget(btnDiscard);
85
90
86 treeWidget()->setItemWidget(this, 1, {widet});
91 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, {widet});
87 treeWidget()->resizeColumnToContents(1);
92 }
88 }
93 }
89 else {
94 else {
90 // Note: the widget is destroyed
95 // Note: the widget is destroyed
91 treeWidget()->setItemWidget(this, 1, nullptr);
96 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr);
97 }
92 }
98 }
99
100 void CatalogueTreeWidgetItem::refresh()
101 {
102 emitDataChanged();
93 }
103 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved

Status change > Approved

You need to be logged in to leave comments. Login now