@@ -1,49 +1,51 | |||||
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 <QLoggingCategory> | |
6 | #include <QTreeWidgetItem> |
|
6 | #include <QTreeWidgetItem> | |
7 | #include <QWidget> |
|
7 | #include <QWidget> | |
8 |
|
8 | |||
|
9 | class CatalogueAbstractTreeItem; | |||
9 | class DBCatalogue; |
|
10 | class DBCatalogue; | |
10 |
|
11 | |||
11 | namespace Ui { |
|
12 | namespace Ui { | |
12 | class CatalogueSideBarWidget; |
|
13 | class CatalogueSideBarWidget; | |
13 | } |
|
14 | } | |
14 |
|
15 | |||
15 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget) |
|
16 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget) | |
16 |
|
17 | |||
17 | class CatalogueSideBarWidget : public QWidget { |
|
18 | class CatalogueSideBarWidget : public QWidget { | |
18 | Q_OBJECT |
|
19 | Q_OBJECT | |
19 |
|
20 | |||
20 | signals: |
|
21 | signals: | |
21 | void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); |
|
22 | void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues); | |
22 | void databaseSelected(const QStringList &databases); |
|
23 | void databaseSelected(const QStringList &databases); | |
23 | void allEventsSelected(); |
|
24 | void allEventsSelected(); | |
24 | void trashSelected(); |
|
25 | void trashSelected(); | |
25 | void selectionCleared(); |
|
26 | void selectionCleared(); | |
26 |
|
27 | |||
27 | public: |
|
28 | public: | |
28 | explicit CatalogueSideBarWidget(QWidget *parent = 0); |
|
29 | explicit CatalogueSideBarWidget(QWidget *parent = 0); | |
29 | virtual ~CatalogueSideBarWidget(); |
|
30 | virtual ~CatalogueSideBarWidget(); | |
30 |
|
31 | |||
31 |
|
|
32 | CatalogueAbstractTreeItem *addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, | |
|
33 | const QString &repository); | |||
32 | void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges); |
|
34 | void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges); | |
33 |
|
35 | |||
34 | QVector<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const; |
|
36 | QVector<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const; | |
35 |
|
37 | |||
36 | private slots: |
|
38 | private slots: | |
37 | void emitSelection(); |
|
39 | void emitSelection(); | |
38 |
|
40 | |||
39 | private: |
|
41 | private: | |
40 | Ui::CatalogueSideBarWidget *ui; |
|
42 | Ui::CatalogueSideBarWidget *ui; | |
41 |
|
43 | |||
42 | class CatalogueSideBarWidgetPrivate; |
|
44 | class CatalogueSideBarWidgetPrivate; | |
43 | spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl; |
|
45 | spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl; | |
44 |
|
46 | |||
45 | private slots: |
|
47 | private slots: | |
46 | void onContextMenuRequested(const QPoint &pos); |
|
48 | void onContextMenuRequested(const QPoint &pos); | |
47 | }; |
|
49 | }; | |
48 |
|
50 | |||
49 | #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H |
|
51 | #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H |
@@ -1,422 +1,414 | |||||
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/CatalogueExplorerHelper.h> |
|
6 | #include <Catalogue/CatalogueExplorerHelper.h> | |
7 | #include <Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h> |
|
7 | #include <Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h> | |
8 | #include <Catalogue/CatalogueTreeItems/CatalogueTreeItem.h> |
|
8 | #include <Catalogue/CatalogueTreeItems/CatalogueTreeItem.h> | |
9 | #include <Catalogue/CatalogueTreeModel.h> |
|
9 | #include <Catalogue/CatalogueTreeModel.h> | |
10 | #include <CatalogueDao.h> |
|
10 | #include <CatalogueDao.h> | |
11 | #include <ComparaisonPredicate.h> |
|
11 | #include <ComparaisonPredicate.h> | |
12 | #include <DBCatalogue.h> |
|
12 | #include <DBCatalogue.h> | |
13 |
|
13 | |||
14 | #include <QMenu> |
|
14 | #include <QMenu> | |
15 | #include <QMessageBox> |
|
15 | #include <QMessageBox> | |
16 |
|
16 | |||
17 | Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget") |
|
17 | Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget") | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1; |
|
20 | constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1; | |
21 | constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2; |
|
21 | constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2; | |
22 | constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3; |
|
22 | constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3; | |
23 | constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4; |
|
23 | constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4; | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { |
|
26 | struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { | |
27 |
|
27 | |||
28 | CatalogueTreeModel *m_TreeModel = nullptr; |
|
28 | CatalogueTreeModel *m_TreeModel = nullptr; | |
29 |
|
29 | |||
30 | void configureTreeWidget(QTreeView *treeView); |
|
30 | void configureTreeWidget(QTreeView *treeView); | |
31 | QModelIndex addDatabaseItem(const QString &name); |
|
31 | QModelIndex addDatabaseItem(const QString &name); | |
32 | CatalogueAbstractTreeItem *getDatabaseItem(const QString &name); |
|
32 | CatalogueAbstractTreeItem *getDatabaseItem(const QString &name); | |
33 |
|
|
33 | CatalogueAbstractTreeItem *addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue, | |
34 | const QModelIndex &databaseIndex); |
|
34 | const QModelIndex &databaseIndex); | |
35 |
|
35 | |||
36 | CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const; |
|
36 | CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const; | |
37 | void setHasChanges(bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget); |
|
37 | void setHasChanges(bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget); | |
38 | bool hasChanges(const QModelIndex &index, QTreeView *treeView); |
|
38 | bool hasChanges(const QModelIndex &index, QTreeView *treeView); | |
39 |
|
39 | |||
40 | int selectionType(QTreeView *treeView) const |
|
40 | int selectionType(QTreeView *treeView) const | |
41 | { |
|
41 | { | |
42 | auto selectedItems = treeView->selectionModel()->selectedRows(); |
|
42 | auto selectedItems = treeView->selectionModel()->selectedRows(); | |
43 | if (selectedItems.isEmpty()) { |
|
43 | if (selectedItems.isEmpty()) { | |
44 | return CatalogueAbstractTreeItem::DEFAULT_TYPE; |
|
44 | return CatalogueAbstractTreeItem::DEFAULT_TYPE; | |
45 | } |
|
45 | } | |
46 | else { |
|
46 | else { | |
47 | auto firstIndex = selectedItems.first(); |
|
47 | auto firstIndex = selectedItems.first(); | |
48 | auto firstItem = m_TreeModel->item(firstIndex); |
|
48 | auto firstItem = m_TreeModel->item(firstIndex); | |
49 | if (!firstItem) { |
|
49 | if (!firstItem) { | |
50 | Q_ASSERT(false); |
|
50 | Q_ASSERT(false); | |
51 | return CatalogueAbstractTreeItem::DEFAULT_TYPE; |
|
51 | return CatalogueAbstractTreeItem::DEFAULT_TYPE; | |
52 | } |
|
52 | } | |
53 | auto selectionType = firstItem->type(); |
|
53 | auto selectionType = firstItem->type(); | |
54 |
|
54 | |||
55 | for (auto itemIndex : selectedItems) { |
|
55 | for (auto itemIndex : selectedItems) { | |
56 | auto item = m_TreeModel->item(itemIndex); |
|
56 | auto item = m_TreeModel->item(itemIndex); | |
57 | if (!item || item->type() != selectionType) { |
|
57 | if (!item || item->type() != selectionType) { | |
58 | // Incoherent multi selection |
|
58 | // Incoherent multi selection | |
59 | selectionType = CatalogueAbstractTreeItem::DEFAULT_TYPE; |
|
59 | selectionType = CatalogueAbstractTreeItem::DEFAULT_TYPE; | |
60 | break; |
|
60 | break; | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | return selectionType; |
|
64 | return selectionType; | |
65 | } |
|
65 | } | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | QVector<std::shared_ptr<DBCatalogue> > selectedCatalogues(QTreeView *treeView) const |
|
68 | QVector<std::shared_ptr<DBCatalogue> > selectedCatalogues(QTreeView *treeView) const | |
69 | { |
|
69 | { | |
70 | QVector<std::shared_ptr<DBCatalogue> > catalogues; |
|
70 | QVector<std::shared_ptr<DBCatalogue> > catalogues; | |
71 | auto selectedItems = treeView->selectionModel()->selectedRows(); |
|
71 | auto selectedItems = treeView->selectionModel()->selectedRows(); | |
72 | for (auto itemIndex : selectedItems) { |
|
72 | for (auto itemIndex : selectedItems) { | |
73 | auto item = m_TreeModel->item(itemIndex); |
|
73 | auto item = m_TreeModel->item(itemIndex); | |
74 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { |
|
74 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { | |
75 | catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue()); |
|
75 | catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue()); | |
76 | } |
|
76 | } | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | return catalogues; |
|
79 | return catalogues; | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | QStringList selectedRepositories(QTreeView *treeView) const |
|
82 | QStringList selectedRepositories(QTreeView *treeView) const | |
83 | { |
|
83 | { | |
84 | QStringList repositories; |
|
84 | QStringList repositories; | |
85 | auto selectedItems = treeView->selectionModel()->selectedRows(); |
|
85 | auto selectedItems = treeView->selectionModel()->selectedRows(); | |
86 | for (auto itemIndex : selectedItems) { |
|
86 | for (auto itemIndex : selectedItems) { | |
87 | auto item = m_TreeModel->item(itemIndex); |
|
87 | auto item = m_TreeModel->item(itemIndex); | |
88 | if (item && item->type() == DATABASE_ITEM_TYPE) { |
|
88 | if (item && item->type() == DATABASE_ITEM_TYPE) { | |
89 | repositories.append(item->text()); |
|
89 | repositories.append(item->text()); | |
90 | } |
|
90 | } | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | return repositories; |
|
93 | return repositories; | |
94 | } |
|
94 | } | |
95 | }; |
|
95 | }; | |
96 |
|
96 | |||
97 | CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) |
|
97 | CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) | |
98 | : QWidget(parent), |
|
98 | : QWidget(parent), | |
99 | ui(new Ui::CatalogueSideBarWidget), |
|
99 | ui(new Ui::CatalogueSideBarWidget), | |
100 | impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()} |
|
100 | impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()} | |
101 | { |
|
101 | { | |
102 | ui->setupUi(this); |
|
102 | ui->setupUi(this); | |
103 |
|
103 | |||
104 | impl->m_TreeModel = new CatalogueTreeModel(this); |
|
104 | impl->m_TreeModel = new CatalogueTreeModel(this); | |
105 | ui->treeView->setModel(impl->m_TreeModel); |
|
105 | ui->treeView->setModel(impl->m_TreeModel); | |
106 |
|
106 | |||
107 | impl->configureTreeWidget(ui->treeView); |
|
107 | impl->configureTreeWidget(ui->treeView); | |
108 |
|
108 | |||
109 | ui->treeView->header()->setStretchLastSection(false); |
|
109 | ui->treeView->header()->setStretchLastSection(false); | |
110 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); |
|
110 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | |
111 | ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); |
|
111 | ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); | |
112 |
|
112 | |||
113 | connect(ui->treeView, &QTreeView::clicked, this, &CatalogueSideBarWidget::emitSelection); |
|
113 | connect(ui->treeView, &QTreeView::clicked, this, &CatalogueSideBarWidget::emitSelection); | |
114 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, |
|
114 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, | |
115 | &CatalogueSideBarWidget::emitSelection); |
|
115 | &CatalogueSideBarWidget::emitSelection); | |
116 |
|
116 | |||
117 |
|
117 | |||
118 |
|
|
118 | connect(ui->btnAdd, &QToolButton::clicked, [this]() { | |
119 | // QVector<std::shared_ptr<DBCatalogue> > catalogues; |
|
119 | auto catalogue = std::make_shared<DBCatalogue>(); | |
120 | // impl->getSelectedItems(ui->treeView, events, eventProducts); |
|
120 | catalogue->setName(QString("Cat")); | |
|
121 | sqpApp->catalogueController().addCatalogue(catalogue); | |||
|
122 | auto item = this->addCatalogue(catalogue, REPOSITORY_DEFAULT); | |||
|
123 | this->setCatalogueChanges(catalogue, true); | |||
|
124 | ui->treeView->edit(impl->m_TreeModel->indexOf(item)); | |||
121 |
|
125 | |||
122 | // if (!events.isEmpty() && eventProducts.isEmpty()) { |
|
126 | }); | |
123 |
|
||||
124 | // if (QMessageBox::warning(this, tr("Remove Event(s)"), |
|
|||
125 | // tr("The selected event(s) will be completly removed " |
|
|||
126 | // "from the repository!\nAre you sure you want to |
|
|||
127 | // continue?"), |
|
|||
128 | // QMessageBox::Yes | QMessageBox::No, QMessageBox::No) |
|
|||
129 | // == QMessageBox::Yes) { |
|
|||
130 |
|
||||
131 | // for (auto event : events) { |
|
|||
132 | // sqpApp->catalogueController().removeEvent(event); |
|
|||
133 | // impl->removeEvent(event, ui->treeView); |
|
|||
134 | // } |
|
|||
135 | // } |
|
|||
136 | // } |
|
|||
137 | // }); |
|
|||
138 |
|
127 | |||
139 |
|
128 | |||
140 | connect(impl->m_TreeModel, &CatalogueTreeModel::itemDropped, [this](auto index) { |
|
129 | connect(impl->m_TreeModel, &CatalogueTreeModel::itemDropped, [this](auto index) { | |
141 | auto item = impl->m_TreeModel->item(index); |
|
130 | auto item = impl->m_TreeModel->item(index); | |
142 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { |
|
131 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { | |
143 | auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); |
|
132 | auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); | |
144 | this->setCatalogueChanges(catalogue, true); |
|
133 | this->setCatalogueChanges(catalogue, true); | |
145 | } |
|
134 | } | |
146 | }); |
|
135 | }); | |
147 | connect(ui->btnRemove, &QToolButton::clicked, [this]() { |
|
136 | connect(ui->btnRemove, &QToolButton::clicked, [this]() { | |
148 | QVector<QPair<std::shared_ptr<DBCatalogue>, CatalogueAbstractTreeItem *> > |
|
137 | QVector<QPair<std::shared_ptr<DBCatalogue>, CatalogueAbstractTreeItem *> > | |
149 | cataloguesToItems; |
|
138 | cataloguesToItems; | |
150 | auto selectedIndexes = ui->treeView->selectionModel()->selectedRows(); |
|
139 | auto selectedIndexes = ui->treeView->selectionModel()->selectedRows(); | |
151 |
|
140 | |||
152 | for (auto index : selectedIndexes) { |
|
141 | for (auto index : selectedIndexes) { | |
153 | auto item = impl->m_TreeModel->item(index); |
|
142 | auto item = impl->m_TreeModel->item(index); | |
154 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { |
|
143 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { | |
155 | auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); |
|
144 | auto catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); | |
156 | cataloguesToItems << qMakePair(catalogue, item); |
|
145 | cataloguesToItems << qMakePair(catalogue, item); | |
157 | } |
|
146 | } | |
158 | } |
|
147 | } | |
159 |
|
148 | |||
160 | if (!cataloguesToItems.isEmpty()) { |
|
149 | if (!cataloguesToItems.isEmpty()) { | |
161 |
|
150 | |||
162 | if (QMessageBox::warning(this, tr("Remove Catalogue(s)"), |
|
151 | if (QMessageBox::warning(this, tr("Remove Catalogue(s)"), | |
163 | tr("The selected catalogues(s) will be completly removed " |
|
152 | tr("The selected catalogues(s) will be completly removed " | |
164 | "from the repository!\nAre you sure you want to continue?"), |
|
153 | "from the repository!\nAre you sure you want to continue?"), | |
165 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) |
|
154 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) | |
166 | == QMessageBox::Yes) { |
|
155 | == QMessageBox::Yes) { | |
167 |
|
156 | |||
168 | for (auto catalogueToItem : cataloguesToItems) { |
|
157 | for (auto catalogueToItem : cataloguesToItems) { | |
169 | sqpApp->catalogueController().removeCatalogue(catalogueToItem.first); |
|
158 | sqpApp->catalogueController().removeCatalogue(catalogueToItem.first); | |
170 | impl->m_TreeModel->removeChildItem( |
|
159 | impl->m_TreeModel->removeChildItem( | |
171 | catalogueToItem.second, |
|
160 | catalogueToItem.second, | |
172 | impl->m_TreeModel->indexOf(catalogueToItem.second->parent())); |
|
161 | impl->m_TreeModel->indexOf(catalogueToItem.second->parent())); | |
173 | } |
|
162 | } | |
174 | } |
|
163 | } | |
175 | } |
|
164 | } | |
176 | }); |
|
165 | }); | |
177 |
|
166 | |||
178 | connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [this](auto index) { |
|
167 | connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [this](auto index) { | |
179 | auto selectedIndexes = ui->treeView->selectionModel()->selectedRows(); |
|
168 | auto selectedIndexes = ui->treeView->selectionModel()->selectedRows(); | |
180 | if (selectedIndexes.contains(index)) { |
|
169 | if (selectedIndexes.contains(index)) { | |
181 | this->emitSelection(); |
|
170 | this->emitSelection(); | |
182 | } |
|
171 | } | |
183 | impl->setHasChanges(true, index, this); |
|
172 | impl->setHasChanges(true, index, this); | |
184 | }); |
|
173 | }); | |
185 |
|
174 | |||
186 | ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); |
|
175 | ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); | |
187 | connect(ui->treeView, &QTreeView::customContextMenuRequested, this, |
|
176 | connect(ui->treeView, &QTreeView::customContextMenuRequested, this, | |
188 | &CatalogueSideBarWidget::onContextMenuRequested); |
|
177 | &CatalogueSideBarWidget::onContextMenuRequested); | |
189 | } |
|
178 | } | |
190 |
|
179 | |||
191 | CatalogueSideBarWidget::~CatalogueSideBarWidget() |
|
180 | CatalogueSideBarWidget::~CatalogueSideBarWidget() | |
192 | { |
|
181 | { | |
193 | delete ui; |
|
182 | delete ui; | |
194 | } |
|
183 | } | |
195 |
|
184 | |||
196 | void CatalogueSideBarWidget::addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, |
|
185 | CatalogueAbstractTreeItem * | |
197 | const QString &repository) |
|
186 | CatalogueSideBarWidget::addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, | |
|
187 | const QString &repository) | |||
198 | { |
|
188 | { | |
199 | auto repositoryItem = impl->getDatabaseItem(repository); |
|
189 | auto repositoryItem = impl->getDatabaseItem(repository); | |
200 | impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem)); |
|
190 | return impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem)); | |
201 | } |
|
191 | } | |
202 |
|
192 | |||
203 | void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, |
|
193 | void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, | |
204 | bool hasChanges) |
|
194 | bool hasChanges) | |
205 | { |
|
195 | { | |
206 | if (auto catalogueItem = impl->getCatalogueItem(catalogue)) { |
|
196 | if (auto catalogueItem = impl->getCatalogueItem(catalogue)) { | |
207 | auto index = impl->m_TreeModel->indexOf(catalogueItem); |
|
197 | auto index = impl->m_TreeModel->indexOf(catalogueItem); | |
208 | impl->setHasChanges(hasChanges, index, this); |
|
198 | impl->setHasChanges(hasChanges, index, this); | |
209 | // catalogueItem->refresh(); |
|
199 | // catalogueItem->refresh(); | |
210 | } |
|
200 | } | |
211 | } |
|
201 | } | |
212 |
|
202 | |||
213 | QVector<std::shared_ptr<DBCatalogue> > |
|
203 | QVector<std::shared_ptr<DBCatalogue> > | |
214 | CatalogueSideBarWidget::getCatalogues(const QString &repository) const |
|
204 | CatalogueSideBarWidget::getCatalogues(const QString &repository) const | |
215 | { |
|
205 | { | |
216 | QVector<std::shared_ptr<DBCatalogue> > result; |
|
206 | QVector<std::shared_ptr<DBCatalogue> > result; | |
217 | auto repositoryItem = impl->getDatabaseItem(repository); |
|
207 | auto repositoryItem = impl->getDatabaseItem(repository); | |
218 | for (auto child : repositoryItem->children()) { |
|
208 | for (auto child : repositoryItem->children()) { | |
219 | if (child->type() == CATALOGUE_ITEM_TYPE) { |
|
209 | if (child->type() == CATALOGUE_ITEM_TYPE) { | |
220 | auto catalogueItem = static_cast<CatalogueTreeItem *>(child); |
|
210 | auto catalogueItem = static_cast<CatalogueTreeItem *>(child); | |
221 | result << catalogueItem->catalogue(); |
|
211 | result << catalogueItem->catalogue(); | |
222 | } |
|
212 | } | |
223 | else { |
|
213 | else { | |
224 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogues: invalid structure"; |
|
214 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogues: invalid structure"; | |
225 | } |
|
215 | } | |
226 | } |
|
216 | } | |
227 |
|
217 | |||
228 | return result; |
|
218 | return result; | |
229 | } |
|
219 | } | |
230 |
|
220 | |||
231 | void CatalogueSideBarWidget::emitSelection() |
|
221 | void CatalogueSideBarWidget::emitSelection() | |
232 | { |
|
222 | { | |
233 | auto selectionType = impl->selectionType(ui->treeView); |
|
223 | auto selectionType = impl->selectionType(ui->treeView); | |
234 |
|
224 | |||
235 | switch (selectionType) { |
|
225 | switch (selectionType) { | |
236 | case CATALOGUE_ITEM_TYPE: |
|
226 | case CATALOGUE_ITEM_TYPE: | |
237 | emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView)); |
|
227 | emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView)); | |
238 | break; |
|
228 | break; | |
239 | case DATABASE_ITEM_TYPE: |
|
229 | case DATABASE_ITEM_TYPE: | |
240 | emit this->databaseSelected(impl->selectedRepositories(ui->treeView)); |
|
230 | emit this->databaseSelected(impl->selectedRepositories(ui->treeView)); | |
241 | break; |
|
231 | break; | |
242 | case ALL_EVENT_ITEM_TYPE: |
|
232 | case ALL_EVENT_ITEM_TYPE: | |
243 | emit this->allEventsSelected(); |
|
233 | emit this->allEventsSelected(); | |
244 | break; |
|
234 | break; | |
245 | case TRASH_ITEM_TYPE: |
|
235 | case TRASH_ITEM_TYPE: | |
246 | emit this->trashSelected(); |
|
236 | emit this->trashSelected(); | |
247 | break; |
|
237 | break; | |
248 | default: |
|
238 | default: | |
249 | emit this->selectionCleared(); |
|
239 | emit this->selectionCleared(); | |
250 | break; |
|
240 | break; | |
251 | } |
|
241 | } | |
252 | } |
|
242 | } | |
253 |
|
243 | |||
254 | void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos) |
|
244 | void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos) | |
255 | { |
|
245 | { | |
256 | QMenu menu{this}; |
|
246 | QMenu menu{this}; | |
257 |
|
247 | |||
258 | auto currentIndex = ui->treeView->currentIndex(); |
|
248 | auto currentIndex = ui->treeView->currentIndex(); | |
259 | auto currentItem = impl->m_TreeModel->item(currentIndex); |
|
249 | auto currentItem = impl->m_TreeModel->item(currentIndex); | |
260 | if (!currentItem) { |
|
250 | if (!currentItem) { | |
261 | return; |
|
251 | return; | |
262 | } |
|
252 | } | |
263 |
|
253 | |||
264 | switch (currentItem->type()) { |
|
254 | switch (currentItem->type()) { | |
265 | case CATALOGUE_ITEM_TYPE: |
|
255 | case CATALOGUE_ITEM_TYPE: | |
266 | menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); }); |
|
256 | menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); }); | |
267 | break; |
|
257 | break; | |
268 | case DATABASE_ITEM_TYPE: |
|
258 | case DATABASE_ITEM_TYPE: | |
269 | break; |
|
259 | break; | |
270 | case ALL_EVENT_ITEM_TYPE: |
|
260 | case ALL_EVENT_ITEM_TYPE: | |
271 | break; |
|
261 | break; | |
272 | case TRASH_ITEM_TYPE: |
|
262 | case TRASH_ITEM_TYPE: | |
273 | menu.addAction("Empty Trash", []() { |
|
263 | menu.addAction("Empty Trash", []() { | |
274 | // TODO |
|
264 | // TODO | |
275 | }); |
|
265 | }); | |
276 | break; |
|
266 | break; | |
277 | default: |
|
267 | default: | |
278 | break; |
|
268 | break; | |
279 | } |
|
269 | } | |
280 |
|
270 | |||
281 | if (!menu.isEmpty()) { |
|
271 | if (!menu.isEmpty()) { | |
282 | menu.exec(ui->treeView->mapToGlobal(pos)); |
|
272 | menu.exec(ui->treeView->mapToGlobal(pos)); | |
283 | } |
|
273 | } | |
284 | } |
|
274 | } | |
285 |
|
275 | |||
286 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView) |
|
276 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView) | |
287 | { |
|
277 | { | |
288 | auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events", |
|
278 | auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events", | |
289 | ALL_EVENT_ITEM_TYPE}; |
|
279 | ALL_EVENT_ITEM_TYPE}; | |
290 | auto allEventIndex = m_TreeModel->addTopLevelItem(allEventsItem); |
|
280 | auto allEventIndex = m_TreeModel->addTopLevelItem(allEventsItem); | |
291 | treeView->setCurrentIndex(allEventIndex); |
|
281 | treeView->setCurrentIndex(allEventIndex); | |
292 |
|
282 | |||
293 | auto trashItem |
|
283 | auto trashItem | |
294 | = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE}; |
|
284 | = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE}; | |
295 | m_TreeModel->addTopLevelItem(trashItem); |
|
285 | m_TreeModel->addTopLevelItem(trashItem); | |
296 |
|
286 | |||
297 | auto separator = new QFrame{treeView}; |
|
287 | auto separator = new QFrame{treeView}; | |
298 | separator->setFrameShape(QFrame::HLine); |
|
288 | separator->setFrameShape(QFrame::HLine); | |
299 | auto separatorItem |
|
289 | auto separatorItem | |
300 | = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE}; |
|
290 | = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE}; | |
301 | separatorItem->setEnabled(false); |
|
291 | separatorItem->setEnabled(false); | |
302 | auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem); |
|
292 | auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem); | |
303 | treeView->setIndexWidget(separatorIndex, separator); |
|
293 | treeView->setIndexWidget(separatorIndex, separator); | |
304 |
|
294 | |||
305 | auto repositories = sqpApp->catalogueController().getRepositories(); |
|
295 | auto repositories = sqpApp->catalogueController().getRepositories(); | |
306 | for (auto dbname : repositories) { |
|
296 | for (auto dbname : repositories) { | |
307 | auto dbIndex = addDatabaseItem(dbname); |
|
297 | auto dbIndex = addDatabaseItem(dbname); | |
308 | auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname); |
|
298 | auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname); | |
309 | for (auto catalogue : catalogues) { |
|
299 | for (auto catalogue : catalogues) { | |
310 | addCatalogueItem(catalogue, dbIndex); |
|
300 | addCatalogueItem(catalogue, dbIndex); | |
311 | } |
|
301 | } | |
312 | } |
|
302 | } | |
313 |
|
303 | |||
314 | treeView->expandAll(); |
|
304 | treeView->expandAll(); | |
315 | } |
|
305 | } | |
316 |
|
306 | |||
317 | QModelIndex |
|
307 | QModelIndex | |
318 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name) |
|
308 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name) | |
319 | { |
|
309 | { | |
320 | auto databaseItem |
|
310 | auto databaseItem | |
321 | = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE}; |
|
311 | = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE}; | |
322 | auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem); |
|
312 | auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem); | |
323 |
|
313 | |||
324 | return databaseIndex; |
|
314 | return databaseIndex; | |
325 | } |
|
315 | } | |
326 |
|
316 | |||
327 | CatalogueAbstractTreeItem * |
|
317 | CatalogueAbstractTreeItem * | |
328 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name) |
|
318 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name) | |
329 | { |
|
319 | { | |
330 | for (auto item : m_TreeModel->topLevelItems()) { |
|
320 | for (auto item : m_TreeModel->topLevelItems()) { | |
331 | if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) { |
|
321 | if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) { | |
332 | return item; |
|
322 | return item; | |
333 | } |
|
323 | } | |
334 | } |
|
324 | } | |
335 |
|
325 | |||
336 | return nullptr; |
|
326 | return nullptr; | |
337 | } |
|
327 | } | |
338 |
|
328 | |||
339 |
|
|
329 | CatalogueAbstractTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( | |
340 | const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex) |
|
330 | const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex) | |
341 | { |
|
331 | { | |
342 | auto catalogueItem |
|
332 | auto catalogueItem | |
343 | = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE}; |
|
333 | = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE}; | |
344 | m_TreeModel->addChildItem(catalogueItem, databaseIndex); |
|
334 | m_TreeModel->addChildItem(catalogueItem, databaseIndex); | |
|
335 | ||||
|
336 | return catalogueItem; | |||
345 | } |
|
337 | } | |
346 |
|
338 | |||
347 | CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem( |
|
339 | CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem( | |
348 | const std::shared_ptr<DBCatalogue> &catalogue) const |
|
340 | const std::shared_ptr<DBCatalogue> &catalogue) const | |
349 | { |
|
341 | { | |
350 | for (auto item : m_TreeModel->topLevelItems()) { |
|
342 | for (auto item : m_TreeModel->topLevelItems()) { | |
351 | if (item->type() == DATABASE_ITEM_TYPE) { |
|
343 | if (item->type() == DATABASE_ITEM_TYPE) { | |
352 | for (auto childItem : item->children()) { |
|
344 | for (auto childItem : item->children()) { | |
353 | if (childItem->type() == CATALOGUE_ITEM_TYPE) { |
|
345 | if (childItem->type() == CATALOGUE_ITEM_TYPE) { | |
354 | auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem); |
|
346 | auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem); | |
355 | if (catalogueItem->catalogue() == catalogue) { |
|
347 | if (catalogueItem->catalogue() == catalogue) { | |
356 | return catalogueItem; |
|
348 | return catalogueItem; | |
357 | } |
|
349 | } | |
358 | } |
|
350 | } | |
359 | else { |
|
351 | else { | |
360 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree " |
|
352 | qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree " | |
361 | "structure. A database item should " |
|
353 | "structure. A database item should " | |
362 | "only contain catalogues."; |
|
354 | "only contain catalogues."; | |
363 | Q_ASSERT(false); |
|
355 | Q_ASSERT(false); | |
364 | } |
|
356 | } | |
365 | } |
|
357 | } | |
366 | } |
|
358 | } | |
367 | } |
|
359 | } | |
368 |
|
360 | |||
369 | return nullptr; |
|
361 | return nullptr; | |
370 | } |
|
362 | } | |
371 |
|
363 | |||
372 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges( |
|
364 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges( | |
373 | bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget) |
|
365 | bool value, const QModelIndex &index, CatalogueSideBarWidget *sideBarWidget) | |
374 | { |
|
366 | { | |
375 | std::shared_ptr<DBCatalogue> catalogue = nullptr; |
|
367 | std::shared_ptr<DBCatalogue> catalogue = nullptr; | |
376 | auto item = m_TreeModel->item(index); |
|
368 | auto item = m_TreeModel->item(index); | |
377 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { |
|
369 | if (item && item->type() == CATALOGUE_ITEM_TYPE) { | |
378 | catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); |
|
370 | catalogue = static_cast<CatalogueTreeItem *>(item)->catalogue(); | |
379 | } |
|
371 | } | |
380 |
|
372 | |||
381 | auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation); |
|
373 | auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation); | |
382 | if (value) { |
|
374 | if (value) { | |
383 | if (!hasChanges(validationIndex, sideBarWidget->ui->treeView)) { |
|
375 | if (!hasChanges(validationIndex, sideBarWidget->ui->treeView)) { | |
384 | auto widget = CatalogueExplorerHelper::buildValidationWidget( |
|
376 | auto widget = CatalogueExplorerHelper::buildValidationWidget( | |
385 | sideBarWidget->ui->treeView, |
|
377 | sideBarWidget->ui->treeView, | |
386 | [this, validationIndex, sideBarWidget, catalogue]() { |
|
378 | [this, validationIndex, sideBarWidget, catalogue]() { | |
387 | if (catalogue) { |
|
379 | if (catalogue) { | |
388 | sqpApp->catalogueController().saveCatalogue(catalogue); |
|
380 | sqpApp->catalogueController().saveCatalogue(catalogue); | |
389 | } |
|
381 | } | |
390 | setHasChanges(false, validationIndex, sideBarWidget); |
|
382 | setHasChanges(false, validationIndex, sideBarWidget); | |
391 | }, |
|
383 | }, | |
392 | [this, validationIndex, sideBarWidget, catalogue, item]() { |
|
384 | [this, validationIndex, sideBarWidget, catalogue, item]() { | |
393 | if (catalogue) { |
|
385 | if (catalogue) { | |
394 | bool removed; |
|
386 | bool removed; | |
395 | sqpApp->catalogueController().discardCatalogue(catalogue, removed); |
|
387 | sqpApp->catalogueController().discardCatalogue(catalogue, removed); | |
396 |
|
388 | |||
397 | if (removed) { |
|
389 | if (removed) { | |
398 | m_TreeModel->removeChildItem(item, |
|
390 | m_TreeModel->removeChildItem(item, | |
399 | m_TreeModel->indexOf(item->parent())); |
|
391 | m_TreeModel->indexOf(item->parent())); | |
400 | } |
|
392 | } | |
401 | else { |
|
393 | else { | |
402 | m_TreeModel->refresh(m_TreeModel->indexOf(item)); |
|
394 | m_TreeModel->refresh(m_TreeModel->indexOf(item)); | |
403 | setHasChanges(false, validationIndex, sideBarWidget); |
|
395 | setHasChanges(false, validationIndex, sideBarWidget); | |
404 | } |
|
396 | } | |
405 | sideBarWidget->emitSelection(); |
|
397 | sideBarWidget->emitSelection(); | |
406 | } |
|
398 | } | |
407 | }); |
|
399 | }); | |
408 | sideBarWidget->ui->treeView->setIndexWidget(validationIndex, widget); |
|
400 | sideBarWidget->ui->treeView->setIndexWidget(validationIndex, widget); | |
409 | } |
|
401 | } | |
410 | } |
|
402 | } | |
411 | else { |
|
403 | else { | |
412 | // Note: the widget is destroyed |
|
404 | // Note: the widget is destroyed | |
413 | sideBarWidget->ui->treeView->setIndexWidget(validationIndex, nullptr); |
|
405 | sideBarWidget->ui->treeView->setIndexWidget(validationIndex, nullptr); | |
414 | } |
|
406 | } | |
415 | } |
|
407 | } | |
416 |
|
408 | |||
417 | bool CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::hasChanges(const QModelIndex &index, |
|
409 | bool CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::hasChanges(const QModelIndex &index, | |
418 | QTreeView *treeView) |
|
410 | QTreeView *treeView) | |
419 | { |
|
411 | { | |
420 | auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation); |
|
412 | auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation); | |
421 | return treeView->indexWidget(validationIndex) != nullptr; |
|
413 | return treeView->indexWidget(validationIndex) != nullptr; | |
422 | } |
|
414 | } |
General Comments 0
You need to be logged in to leave comments.
Login now