@@ -0,0 +1,34 | |||
|
1 | #ifndef SCIQLOP_CATALOGUEABSTRACTTREEITEM_H | |
|
2 | #define SCIQLOP_CATALOGUEABSTRACTTREEITEM_H | |
|
3 | ||
|
4 | #include <Common/spimpl.h> | |
|
5 | #include <QVariant> | |
|
6 | #include <QVector> | |
|
7 | ||
|
8 | class QMimeData; | |
|
9 | ||
|
10 | class CatalogueAbstractTreeItem { | |
|
11 | public: | |
|
12 | constexpr static const int DEFAULT_TYPE = -1; | |
|
13 | ||
|
14 | CatalogueAbstractTreeItem(int type = DEFAULT_TYPE); | |
|
15 | virtual ~CatalogueAbstractTreeItem(); | |
|
16 | ||
|
17 | void addChild(CatalogueAbstractTreeItem *child); | |
|
18 | QVector<CatalogueAbstractTreeItem *> children() const; | |
|
19 | CatalogueAbstractTreeItem *parent() const; | |
|
20 | ||
|
21 | int type() const; | |
|
22 | QString text(int column = 0) const; | |
|
23 | ||
|
24 | virtual QVariant data(int column, int role) const; | |
|
25 | virtual Qt::ItemFlags flags(int column) const; | |
|
26 | virtual bool setData(int column, int role, const QVariant &value); | |
|
27 | virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action); | |
|
28 | ||
|
29 | private: | |
|
30 | class CatalogueAbstractTreeItemPrivate; | |
|
31 | spimpl::unique_impl_ptr<CatalogueAbstractTreeItemPrivate> impl; | |
|
32 | }; | |
|
33 | ||
|
34 | #endif // SCIQLOP_CATALOGUEABSTRACTTREEITEM_H |
@@ -0,0 +1,23 | |||
|
1 | #ifndef SCIQLOP_CATALOGUETEXTTREEITEM_H | |
|
2 | #define SCIQLOP_CATALOGUETEXTTREEITEM_H | |
|
3 | ||
|
4 | #include <Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h> | |
|
5 | #include <Common/spimpl.h> | |
|
6 | ||
|
7 | class CatalogueTextTreeItem : public CatalogueAbstractTreeItem { | |
|
8 | public: | |
|
9 | CatalogueTextTreeItem(const QIcon &icon, const QString &text, int type); | |
|
10 | ||
|
11 | QVariant data(int column, int role) const override; | |
|
12 | Qt::ItemFlags flags(int column) const override; | |
|
13 | ||
|
14 | QString text() const; | |
|
15 | ||
|
16 | void setEnabled(bool value); | |
|
17 | ||
|
18 | private: | |
|
19 | class CatalogueTextTreeItemPrivate; | |
|
20 | spimpl::unique_impl_ptr<CatalogueTextTreeItemPrivate> impl; | |
|
21 | }; | |
|
22 | ||
|
23 | #endif // SCIQLOP_CATALOGUETEXTTREEITEM_H |
@@ -0,0 +1,27 | |||
|
1 | #ifndef SCIQLOP_CATALOGUETREEITEM_H | |
|
2 | #define SCIQLOP_CATALOGUETREEITEM_H | |
|
3 | ||
|
4 | #include <Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h> | |
|
5 | #include <Common/spimpl.h> | |
|
6 | ||
|
7 | class DBCatalogue; | |
|
8 | ||
|
9 | ||
|
10 | class CatalogueTreeItem : public CatalogueAbstractTreeItem { | |
|
11 | public: | |
|
12 | CatalogueTreeItem(std::shared_ptr<DBCatalogue> catalogue, const QIcon &icon, int type); | |
|
13 | ||
|
14 | QVariant data(int column, int role) const override; | |
|
15 | bool setData(int column, int role, const QVariant &value) override; | |
|
16 | Qt::ItemFlags flags(int column) const override; | |
|
17 | bool canDropMimeData(const QMimeData *data, Qt::DropAction action) override; | |
|
18 | ||
|
19 | /// Returns the catalogue represented by the item | |
|
20 | std::shared_ptr<DBCatalogue> catalogue() const; | |
|
21 | ||
|
22 | private: | |
|
23 | class CatalogueTreeItemPrivate; | |
|
24 | spimpl::unique_impl_ptr<CatalogueTreeItemPrivate> impl; | |
|
25 | }; | |
|
26 | ||
|
27 | #endif // SCIQLOP_CATALOGUETREEITEM_H |
@@ -0,0 +1,74 | |||
|
1 | #include "Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h" | |
|
2 | ||
|
3 | struct CatalogueAbstractTreeItem::CatalogueAbstractTreeItemPrivate { | |
|
4 | int m_Type; | |
|
5 | QVector<CatalogueAbstractTreeItem *> m_Children; | |
|
6 | CatalogueAbstractTreeItem *m_Parent = nullptr; | |
|
7 | ||
|
8 | CatalogueAbstractTreeItemPrivate(int type) : m_Type(type) {} | |
|
9 | }; | |
|
10 | ||
|
11 | CatalogueAbstractTreeItem::CatalogueAbstractTreeItem(int type) | |
|
12 | : impl{spimpl::make_unique_impl<CatalogueAbstractTreeItemPrivate>(type)} | |
|
13 | { | |
|
14 | } | |
|
15 | ||
|
16 | CatalogueAbstractTreeItem::~CatalogueAbstractTreeItem() | |
|
17 | { | |
|
18 | qDeleteAll(impl->m_Children); | |
|
19 | } | |
|
20 | ||
|
21 | void CatalogueAbstractTreeItem::addChild(CatalogueAbstractTreeItem *child) | |
|
22 | { | |
|
23 | impl->m_Children << child; | |
|
24 | child->impl->m_Parent = this; | |
|
25 | } | |
|
26 | ||
|
27 | QVector<CatalogueAbstractTreeItem *> CatalogueAbstractTreeItem::children() const | |
|
28 | { | |
|
29 | return impl->m_Children; | |
|
30 | } | |
|
31 | ||
|
32 | CatalogueAbstractTreeItem *CatalogueAbstractTreeItem::parent() const | |
|
33 | { | |
|
34 | return impl->m_Parent; | |
|
35 | } | |
|
36 | ||
|
37 | int CatalogueAbstractTreeItem::type() const | |
|
38 | { | |
|
39 | return impl->m_Type; | |
|
40 | } | |
|
41 | ||
|
42 | QString CatalogueAbstractTreeItem::text(int column) const | |
|
43 | { | |
|
44 | return data(0, Qt::DisplayRole).toString(); | |
|
45 | } | |
|
46 | ||
|
47 | QVariant CatalogueAbstractTreeItem::data(int column, int role) const | |
|
48 | { | |
|
49 | Q_UNUSED(column); | |
|
50 | Q_UNUSED(role); | |
|
51 | return QVariant(); | |
|
52 | } | |
|
53 | ||
|
54 | Qt::ItemFlags CatalogueAbstractTreeItem::flags(int column) const | |
|
55 | { | |
|
56 | Q_UNUSED(column); | |
|
57 | return Qt::NoItemFlags; | |
|
58 | } | |
|
59 | ||
|
60 | bool CatalogueAbstractTreeItem::setData(int column, int role, const QVariant &value) | |
|
61 | { | |
|
62 | Q_UNUSED(column); | |
|
63 | Q_UNUSED(role); | |
|
64 | Q_UNUSED(value); | |
|
65 | ||
|
66 | return false; | |
|
67 | } | |
|
68 | ||
|
69 | bool CatalogueAbstractTreeItem::canDropMimeData(const QMimeData *data, Qt::DropAction action) | |
|
70 | { | |
|
71 | Q_UNUSED(data); | |
|
72 | Q_UNUSED(action); | |
|
73 | return false; | |
|
74 | } |
@@ -0,0 +1,59 | |||
|
1 | #include "Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h" | |
|
2 | ||
|
3 | #include <QIcon> | |
|
4 | ||
|
5 | struct CatalogueTextTreeItem::CatalogueTextTreeItemPrivate { | |
|
6 | ||
|
7 | QString m_Text; | |
|
8 | QIcon m_Icon; | |
|
9 | bool m_IsEnabled = true; | |
|
10 | ||
|
11 | CatalogueTextTreeItemPrivate(const QIcon &icon, const QString &text) | |
|
12 | : m_Text(text), m_Icon(icon) | |
|
13 | { | |
|
14 | } | |
|
15 | }; | |
|
16 | ||
|
17 | ||
|
18 | CatalogueTextTreeItem::CatalogueTextTreeItem(const QIcon &icon, const QString &text, int type) | |
|
19 | : CatalogueAbstractTreeItem(type), | |
|
20 | impl{spimpl::make_unique_impl<CatalogueTextTreeItemPrivate>(icon, text)} | |
|
21 | { | |
|
22 | } | |
|
23 | ||
|
24 | QVariant CatalogueTextTreeItem::data(int column, int role) const | |
|
25 | { | |
|
26 | if (column > 0) { | |
|
27 | return QVariant(); | |
|
28 | } | |
|
29 | ||
|
30 | switch (role) { | |
|
31 | case Qt::DisplayRole: | |
|
32 | return impl->m_Text; | |
|
33 | case Qt::DecorationRole: | |
|
34 | return impl->m_Icon; | |
|
35 | } | |
|
36 | ||
|
37 | return QVariant(); | |
|
38 | } | |
|
39 | ||
|
40 | Qt::ItemFlags CatalogueTextTreeItem::flags(int column) const | |
|
41 | { | |
|
42 | Q_UNUSED(column); | |
|
43 | ||
|
44 | if (!impl->m_IsEnabled) { | |
|
45 | return Qt::NoItemFlags; | |
|
46 | } | |
|
47 | ||
|
48 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable; | |
|
49 | } | |
|
50 | ||
|
51 | QString CatalogueTextTreeItem::text() const | |
|
52 | { | |
|
53 | return impl->m_Text; | |
|
54 | } | |
|
55 | ||
|
56 | void CatalogueTextTreeItem::setEnabled(bool value) | |
|
57 | { | |
|
58 | impl->m_IsEnabled = value; | |
|
59 | } |
@@ -3,11 +3,13 | |||
|
3 | 3 | |
|
4 | 4 | #include <Common/spimpl.h> |
|
5 | 5 | #include <QAbstractItemModel> |
|
6 | #include <QTreeWidgetItem> | |
|
6 | ||
|
7 | class CatalogueAbstractTreeItem; | |
|
7 | 8 | |
|
8 | 9 | /** |
|
9 | 10 | * @brief Model to display catalogue items based on QTreeWidgetItem |
|
10 |
* @warning Do not use the method QTreeWidgetItem::treeWidget for an item added to this model or the |
|
|
11 | * @warning Do not use the method QTreeWidgetItem::treeWidget for an item added to this model or the | |
|
12 | * application will crash | |
|
11 | 13 | */ |
|
12 | 14 | class CatalogueTreeModel : public QAbstractItemModel { |
|
13 | 15 | Q_OBJECT |
@@ -20,14 +22,13 public: | |||
|
20 | 22 | |
|
21 | 23 | enum class Column { Name, Validation, Count }; |
|
22 | 24 | |
|
23 |
QModelIndex addTopLevelItem( |
|
|
24 | int topLevelItemCount() const; | |
|
25 | QTreeWidgetItem *topLevelItem(int i) const; | |
|
25 | QModelIndex addTopLevelItem(CatalogueAbstractTreeItem *item); | |
|
26 | QVector<CatalogueAbstractTreeItem *> topLevelItems() const; | |
|
26 | 27 | |
|
27 |
void addChildItem( |
|
|
28 | void addChildItem(CatalogueAbstractTreeItem *child, const QModelIndex &parentIndex); | |
|
28 | 29 | |
|
29 |
|
|
|
30 |
QModelIndex indexOf( |
|
|
30 | CatalogueAbstractTreeItem *item(const QModelIndex &index) const; | |
|
31 | QModelIndex indexOf(CatalogueAbstractTreeItem *item, int column = 0) const; | |
|
31 | 32 | |
|
32 | 33 | // model |
|
33 | 34 | QModelIndex index(int row, int column, |
@@ -39,6 +40,13 public: | |||
|
39 | 40 | QVariant data(const QModelIndex &index, int role) const override; |
|
40 | 41 | bool setData(const QModelIndex &index, const QVariant &value, int role) override; |
|
41 | 42 | |
|
43 | bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, | |
|
44 | const QModelIndex &parent) const override; | |
|
45 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, | |
|
46 | const QModelIndex &parent) override; | |
|
47 | Qt::DropActions supportedDropActions() const; | |
|
48 | QStringList mimeTypes() const; | |
|
49 | ||
|
42 | 50 | private: |
|
43 | 51 | class CatalogueTreeModelPrivate; |
|
44 | 52 | spimpl::unique_impl_ptr<CatalogueTreeModelPrivate> impl; |
@@ -119,7 +119,9 gui_sources = [ | |||
|
119 | 119 | 'src/Catalogue/CatalogueEventsWidget.cpp', |
|
120 | 120 | 'src/Catalogue/CatalogueSideBarWidget.cpp', |
|
121 | 121 | 'src/Catalogue/CatalogueInspectorWidget.cpp', |
|
122 |
'src/Catalogue/CatalogueTree |
|
|
122 | 'src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp', | |
|
123 | 'src/Catalogue/CatalogueTreeItems/CatalogueTreeItem.cpp', | |
|
124 | 'src/Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.cpp', | |
|
123 | 125 | 'src/Catalogue/CatalogueEventsModel.cpp', |
|
124 | 126 | 'src/Catalogue/CatalogueExplorerHelper.cpp', |
|
125 | 127 | 'src/Catalogue/CatalogueActionManager.cpp', |
@@ -4,8 +4,9 | |||
|
4 | 4 | |
|
5 | 5 | #include <Catalogue/CatalogueController.h> |
|
6 | 6 | #include <Catalogue/CatalogueExplorerHelper.h> |
|
7 | #include <Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h> | |
|
8 | #include <Catalogue/CatalogueTreeItems/CatalogueTreeItem.h> | |
|
7 | 9 | #include <Catalogue/CatalogueTreeModel.h> |
|
8 | #include <Catalogue/CatalogueTreeWidgetItem.h> | |
|
9 | 10 | #include <CatalogueDao.h> |
|
10 | 11 | #include <ComparaisonPredicate.h> |
|
11 | 12 | #include <DBCatalogue.h> |
@@ -15,10 +16,10 | |||
|
15 | 16 | Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget") |
|
16 | 17 | |
|
17 | 18 | |
|
18 |
constexpr auto ALL_EVENT_ITEM_TYPE = |
|
|
19 |
constexpr auto TRASH_ITEM_TYPE = |
|
|
20 |
constexpr auto CATALOGUE_ITEM_TYPE = |
|
|
21 |
constexpr auto DATABASE_ITEM_TYPE = |
|
|
19 | constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1; | |
|
20 | constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2; | |
|
21 | constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3; | |
|
22 | constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4; | |
|
22 | 23 | |
|
23 | 24 | |
|
24 | 25 | struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { |
@@ -27,11 +28,11 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate { | |||
|
27 | 28 | |
|
28 | 29 | void configureTreeWidget(QTreeView *treeView); |
|
29 | 30 | QModelIndex addDatabaseItem(const QString &name); |
|
30 |
|
|
|
31 | CatalogueAbstractTreeItem *getDatabaseItem(const QString &name); | |
|
31 | 32 | void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue, |
|
32 | 33 | const QModelIndex &databaseIndex); |
|
33 | 34 | |
|
34 |
CatalogueTree |
|
|
35 | CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const; | |
|
35 | 36 | void setHasChanges(bool value, const QModelIndex &index, QTreeView *treeView); |
|
36 | 37 | bool hasChanges(const QModelIndex &index, QTreeView *treeView); |
|
37 | 38 | }; |
@@ -74,12 +75,10 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) | |||
|
74 | 75 | if (item && item->type() == selectionType) { |
|
75 | 76 | switch (selectionType) { |
|
76 | 77 | case CATALOGUE_ITEM_TYPE: |
|
77 | catalogues.append( | |
|
78 | static_cast<CatalogueTreeWidgetItem *>(item)->catalogue()); | |
|
78 | catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue()); | |
|
79 | 79 | break; |
|
80 | 80 | case DATABASE_ITEM_TYPE: |
|
81 | selectionType = DATABASE_ITEM_TYPE; | |
|
82 | databases.append(item->text(0)); | |
|
81 | databases.append(item->text()); | |
|
83 | 82 | case ALL_EVENT_ITEM_TYPE: // fallthrough |
|
84 | 83 | case TRASH_ITEM_TYPE: // fallthrough |
|
85 | 84 | default: |
@@ -128,7 +127,7 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent) | |||
|
128 | 127 | }); |
|
129 | 128 | |
|
130 | 129 | ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); |
|
131 |
connect(ui->treeView, &QTree |
|
|
130 | connect(ui->treeView, &QTreeView::customContextMenuRequested, this, | |
|
132 | 131 | &CatalogueSideBarWidget::onContextMenuRequested); |
|
133 | 132 | } |
|
134 | 133 | |
@@ -143,7 +142,7 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalog | |||
|
143 | 142 | if (auto catalogueItem = impl->getCatalogueItem(catalogue)) { |
|
144 | 143 | auto index = impl->m_TreeModel->indexOf(catalogueItem); |
|
145 | 144 | impl->setHasChanges(hasChanges, index, ui->treeView); |
|
146 | catalogueItem->refresh(); | |
|
145 | // catalogueItem->refresh(); | |
|
147 | 146 | } |
|
148 | 147 | } |
|
149 | 148 | |
@@ -181,18 +180,19 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos) | |||
|
181 | 180 | |
|
182 | 181 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView) |
|
183 | 182 | { |
|
184 | auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE}; | |
|
185 | allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png")); | |
|
183 | auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events", | |
|
184 | ALL_EVENT_ITEM_TYPE}; | |
|
186 | 185 | m_TreeModel->addTopLevelItem(allEventsItem); |
|
187 | 186 | |
|
188 | auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE}; | |
|
189 | trashItem->setIcon(0, QIcon(":/icones/trash.png")); | |
|
187 | auto trashItem | |
|
188 | = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE}; | |
|
190 | 189 | m_TreeModel->addTopLevelItem(trashItem); |
|
191 | 190 | |
|
192 | 191 | auto separator = new QFrame{treeView}; |
|
193 | 192 | separator->setFrameShape(QFrame::HLine); |
|
194 |
auto separatorItem |
|
|
195 | separatorItem->setFlags(Qt::NoItemFlags); | |
|
193 | auto separatorItem | |
|
194 | = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE}; | |
|
195 | separatorItem->setEnabled(false); | |
|
196 | 196 | auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem); |
|
197 | 197 | treeView->setIndexWidget(separatorIndex, separator); |
|
198 | 198 | |
@@ -211,19 +211,18 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget( | |||
|
211 | 211 | QModelIndex |
|
212 | 212 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name) |
|
213 | 213 | { |
|
214 | auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE}; | |
|
215 | databaseItem->setIcon(0, QIcon{":/icones/database.png"}); | |
|
214 | auto databaseItem | |
|
215 | = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE}; | |
|
216 | 216 | auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem); |
|
217 | 217 | |
|
218 | 218 | return databaseIndex; |
|
219 | 219 | } |
|
220 | 220 | |
|
221 | QTreeWidgetItem * | |
|
221 | CatalogueAbstractTreeItem * | |
|
222 | 222 | CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name) |
|
223 | 223 | { |
|
224 |
for (auto i |
|
|
225 | auto item = m_TreeModel->topLevelItem(i); | |
|
226 | if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) { | |
|
224 | for (auto item : m_TreeModel->topLevelItems()) { | |
|
225 | if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) { | |
|
227 | 226 | return item; |
|
228 | 227 | } |
|
229 | 228 | } |
@@ -234,21 +233,19 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QSt | |||
|
234 | 233 | void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem( |
|
235 | 234 | const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex) |
|
236 | 235 | { |
|
237 | auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE}; | |
|
238 | catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"}); | |
|
236 | auto catalogueItem | |
|
237 | = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE}; | |
|
239 | 238 | m_TreeModel->addChildItem(catalogueItem, databaseIndex); |
|
240 | 239 | } |
|
241 | 240 | |
|
242 |
CatalogueTree |
|
|
241 | CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem( | |
|
243 | 242 | const std::shared_ptr<DBCatalogue> &catalogue) const |
|
244 | 243 | { |
|
245 |
for (auto i |
|
|
246 | auto item = m_TreeModel->topLevelItem(i); | |
|
244 | for (auto item : m_TreeModel->topLevelItems()) { | |
|
247 | 245 | if (item->type() == DATABASE_ITEM_TYPE) { |
|
248 |
for (auto |
|
|
249 | auto childItem = item->child(j); | |
|
246 | for (auto childItem : item->children()) { | |
|
250 | 247 | if (childItem->type() == CATALOGUE_ITEM_TYPE) { |
|
251 |
auto catalogueItem = static_cast<CatalogueTree |
|
|
248 | auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem); | |
|
252 | 249 | if (catalogueItem->catalogue() == catalogue) { |
|
253 | 250 | return catalogueItem; |
|
254 | 251 | } |
@@ -1,69 +1,85 | |||
|
1 |
#include "Catalogue/CatalogueTree |
|
|
1 | #include "Catalogue/CatalogueTreeItems/CatalogueTreeItem.h" | |
|
2 | 2 | #include <Catalogue/CatalogueExplorerHelper.h> |
|
3 | 3 | |
|
4 | 4 | #include <Catalogue/CatalogueController.h> |
|
5 | #include <Common/MimeTypesDef.h> | |
|
6 | #include <QIcon> | |
|
7 | #include <QMimeData> | |
|
5 | 8 | #include <SqpApplication.h> |
|
6 | 9 | |
|
7 | 10 | #include <memory> |
|
8 | 11 | |
|
9 | 12 | #include <DBCatalogue.h> |
|
10 | 13 | |
|
11 | /// Column in the tree widget where the apply and cancel buttons must appear | |
|
12 | const auto APPLY_CANCEL_BUTTONS_COLUMN = 1; | |
|
13 | ||
|
14 | struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate { | |
|
14 | struct CatalogueTreeItem::CatalogueTreeItemPrivate { | |
|
15 | 15 | |
|
16 | 16 | std::shared_ptr<DBCatalogue> m_Catalogue; |
|
17 | QIcon m_Icon; | |
|
17 | 18 | |
|
18 |
CatalogueTree |
|
|
19 | CatalogueTreeItemPrivate(std::shared_ptr<DBCatalogue> catalogue, const QIcon &icon) | |
|
20 | : m_Catalogue(catalogue), m_Icon(icon) | |
|
19 | 21 | { |
|
20 | 22 | } |
|
21 | 23 | }; |
|
22 | 24 | |
|
23 | 25 | |
|
24 |
CatalogueTree |
|
|
25 | : QTreeWidgetItem(type), | |
|
26 | impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)} | |
|
26 | CatalogueTreeItem::CatalogueTreeItem(std::shared_ptr<DBCatalogue> catalogue, const QIcon &icon, | |
|
27 | int type) | |
|
28 | : CatalogueAbstractTreeItem(type), | |
|
29 | impl{spimpl::make_unique_impl<CatalogueTreeItemPrivate>(catalogue, icon)} | |
|
27 | 30 | { |
|
28 | setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDropEnabled); | |
|
29 | 31 | } |
|
30 | 32 | |
|
31 |
QVariant CatalogueTree |
|
|
33 | QVariant CatalogueTreeItem::data(int column, int role) const | |
|
32 | 34 | { |
|
33 | 35 | if (column == 0) { |
|
34 | 36 | switch (role) { |
|
35 | 37 | case Qt::EditRole: // fallthrough |
|
36 | 38 | case Qt::DisplayRole: |
|
37 | 39 | return impl->m_Catalogue->getName(); |
|
40 | case Qt::DecorationRole: | |
|
41 | return impl->m_Icon; | |
|
38 | 42 | default: |
|
39 | 43 | break; |
|
40 | 44 | } |
|
41 | 45 | } |
|
42 | 46 | |
|
43 | return QTreeWidgetItem::data(column, role); | |
|
47 | return QVariant(); | |
|
44 | 48 | } |
|
45 | 49 | |
|
46 |
|
|
|
50 | bool CatalogueTreeItem::setData(int column, int role, const QVariant &value) | |
|
47 | 51 | { |
|
52 | bool result = false; | |
|
53 | ||
|
48 | 54 | if (role == Qt::EditRole && column == 0) { |
|
49 | 55 | auto newName = value.toString(); |
|
50 | 56 | if (newName != impl->m_Catalogue->getName()) { |
|
51 | setText(0, newName); | |
|
52 | 57 | impl->m_Catalogue->setName(newName); |
|
53 | 58 | sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue); |
|
59 | result = true; | |
|
60 | } | |
|
61 | } | |
|
62 | ||
|
63 | return result; | |
|
54 | 64 | } |
|
65 | ||
|
66 | Qt::ItemFlags CatalogueTreeItem::flags(int column) const | |
|
67 | { | |
|
68 | if (column == 0) { | |
|
69 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | |
|
70 | | Qt::ItemIsDropEnabled; | |
|
55 | 71 | } |
|
56 | 72 | else { |
|
57 | QTreeWidgetItem::setData(column, role, value); | |
|
73 | return Qt::ItemIsEnabled | Qt::ItemIsSelectable; | |
|
58 | 74 | } |
|
59 | 75 | } |
|
60 | 76 | |
|
61 | std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const | |
|
77 | bool CatalogueTreeItem::canDropMimeData(const QMimeData *data, Qt::DropAction action) | |
|
62 | 78 | { |
|
63 | return impl->m_Catalogue; | |
|
79 | return data->hasFormat(MIME_TYPE_EVENT_LIST); | |
|
64 | 80 | } |
|
65 | 81 | |
|
66 | void CatalogueTreeWidgetItem::refresh() | |
|
82 | std::shared_ptr<DBCatalogue> CatalogueTreeItem::catalogue() const | |
|
67 | 83 | { |
|
68 | emitDataChanged(); | |
|
84 | return impl->m_Catalogue; | |
|
69 | 85 | } |
@@ -1,12 +1,15 | |||
|
1 | 1 | #include "Catalogue/CatalogueTreeModel.h" |
|
2 | #include <Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h> | |
|
2 | 3 | |
|
3 |
#include <Q |
|
|
4 | #include <QMimeData> | |
|
4 | 5 | #include <memory> |
|
5 | 6 | |
|
7 | #include <Common/MimeTypesDef.h> | |
|
8 | ||
|
6 | 9 | struct CatalogueTreeModel::CatalogueTreeModelPrivate { |
|
7 |
std::unique_ptr< |
|
|
10 | std::unique_ptr<CatalogueAbstractTreeItem> m_RootItem = nullptr; | |
|
8 | 11 | |
|
9 |
CatalogueTreeModelPrivate() : m_RootItem{std::make_unique< |
|
|
12 | CatalogueTreeModelPrivate() : m_RootItem{std::make_unique<CatalogueAbstractTreeItem>()} {} | |
|
10 | 13 | }; |
|
11 | 14 | |
|
12 | 15 | CatalogueTreeModel::CatalogueTreeModel(QObject *parent) |
@@ -14,65 +17,71 CatalogueTreeModel::CatalogueTreeModel(QObject *parent) | |||
|
14 | 17 | { |
|
15 | 18 | } |
|
16 | 19 | |
|
17 |
QModelIndex CatalogueTreeModel::addTopLevelItem( |
|
|
20 | QModelIndex CatalogueTreeModel::addTopLevelItem(CatalogueAbstractTreeItem *item) | |
|
18 | 21 | { |
|
19 | beginInsertRows(QModelIndex(), impl->m_RootItem->childCount(), impl->m_RootItem->childCount()); | |
|
22 | auto nbTopLevelItems = impl->m_RootItem->children().count(); | |
|
23 | beginInsertRows(QModelIndex(), nbTopLevelItems, nbTopLevelItems); | |
|
20 | 24 | impl->m_RootItem->addChild(item); |
|
21 | 25 | endInsertRows(); |
|
22 | 26 | |
|
23 | return index(impl->m_RootItem->childCount() - 1, 0); | |
|
24 | } | |
|
27 | emit dataChanged(QModelIndex(), QModelIndex()); | |
|
25 | 28 | |
|
26 | int CatalogueTreeModel::topLevelItemCount() const | |
|
27 | { | |
|
28 | return impl->m_RootItem->childCount(); | |
|
29 | return index(nbTopLevelItems, 0); | |
|
29 | 30 | } |
|
30 | 31 | |
|
31 |
Q |
|
|
32 | QVector<CatalogueAbstractTreeItem *> CatalogueTreeModel::topLevelItems() const | |
|
32 | 33 | { |
|
33 |
return impl->m_RootItem->child( |
|
|
34 | return impl->m_RootItem->children(); | |
|
34 | 35 | } |
|
35 | 36 | |
|
36 |
void CatalogueTreeModel::addChildItem( |
|
|
37 | void CatalogueTreeModel::addChildItem(CatalogueAbstractTreeItem *child, | |
|
38 | const QModelIndex &parentIndex) | |
|
37 | 39 | { |
|
38 | 40 | auto parentItem = item(parentIndex); |
|
39 | beginInsertRows(parentIndex, parentItem->childCount(), parentItem->childCount()); | |
|
41 | int c = parentItem->children().count(); | |
|
42 | beginInsertRows(parentIndex, c, c); | |
|
40 | 43 | parentItem->addChild(child); |
|
41 | 44 | endInsertRows(); |
|
45 | ||
|
46 | emit dataChanged(QModelIndex(), QModelIndex()); | |
|
42 | 47 | } |
|
43 | 48 | |
|
44 |
|
|
|
49 | CatalogueAbstractTreeItem *CatalogueTreeModel::item(const QModelIndex &index) const | |
|
45 | 50 | { |
|
46 |
return static_cast< |
|
|
51 | return static_cast<CatalogueAbstractTreeItem *>(index.internalPointer()); | |
|
47 | 52 | } |
|
48 | 53 | |
|
49 |
QModelIndex CatalogueTreeModel::indexOf( |
|
|
54 | QModelIndex CatalogueTreeModel::indexOf(CatalogueAbstractTreeItem *item, int column) const | |
|
50 | 55 | { |
|
51 | 56 | auto parentItem = item->parent(); |
|
52 | 57 | if (!parentItem) { |
|
53 | 58 | return QModelIndex(); |
|
54 | 59 | } |
|
55 | 60 | |
|
56 |
auto row = parentItem->indexOf |
|
|
61 | auto row = parentItem->children().indexOf(item); | |
|
57 | 62 | return createIndex(row, column, item); |
|
58 | 63 | } |
|
59 | 64 | |
|
60 | 65 | QModelIndex CatalogueTreeModel::index(int row, int column, const QModelIndex &parent) const |
|
61 | 66 | { |
|
67 | if (column > 0) { | |
|
68 | int a = 0; | |
|
69 | } | |
|
70 | ||
|
62 | 71 | if (!hasIndex(row, column, parent)) { |
|
63 | 72 | return QModelIndex(); |
|
64 | 73 | } |
|
65 | 74 | |
|
66 |
|
|
|
75 | CatalogueAbstractTreeItem *parentItem = nullptr; | |
|
67 | 76 | |
|
68 | 77 | if (!parent.isValid()) { |
|
69 | 78 | parentItem = impl->m_RootItem.get(); |
|
70 | 79 | } |
|
71 | 80 | else { |
|
72 |
parentItem = |
|
|
81 | parentItem = item(parent); | |
|
73 | 82 | } |
|
74 | 83 | |
|
75 |
|
|
|
84 | auto childItem = parentItem->children().value(row); | |
|
76 | 85 | if (childItem) { |
|
77 | 86 | return createIndex(row, column, childItem); |
|
78 | 87 | } |
@@ -87,32 +96,29 QModelIndex CatalogueTreeModel::parent(const QModelIndex &index) const | |||
|
87 | 96 | return QModelIndex(); |
|
88 | 97 | } |
|
89 | 98 | |
|
90 |
auto childItem = |
|
|
99 | auto childItem = item(index); | |
|
91 | 100 | auto parentItem = childItem->parent(); |
|
92 | 101 | |
|
93 | 102 | if (parentItem == nullptr || parentItem->parent() == nullptr) { |
|
94 | 103 | return QModelIndex(); |
|
95 | 104 | } |
|
96 | 105 | |
|
97 |
auto row = parentItem->parent()->indexOf |
|
|
106 | auto row = parentItem->parent()->children().indexOf(parentItem); | |
|
98 | 107 | return createIndex(row, 0, parentItem); |
|
99 | 108 | } |
|
100 | 109 | |
|
101 | 110 | int CatalogueTreeModel::rowCount(const QModelIndex &parent) const |
|
102 | 111 | { |
|
103 |
|
|
|
104 | if (parent.column() > 0) { | |
|
105 | return 0; | |
|
106 | } | |
|
112 | CatalogueAbstractTreeItem *parentItem = nullptr; | |
|
107 | 113 | |
|
108 | 114 | if (!parent.isValid()) { |
|
109 | 115 | parentItem = impl->m_RootItem.get(); |
|
110 | 116 | } |
|
111 | 117 | else { |
|
112 |
parentItem = |
|
|
118 | parentItem = item(parent); | |
|
113 | 119 | } |
|
114 | 120 | |
|
115 |
return parentItem->child |
|
|
121 | return parentItem->children().count(); | |
|
116 | 122 | } |
|
117 | 123 | |
|
118 | 124 | int CatalogueTreeModel::columnCount(const QModelIndex &parent) const |
@@ -122,13 +128,9 int CatalogueTreeModel::columnCount(const QModelIndex &parent) const | |||
|
122 | 128 | |
|
123 | 129 | Qt::ItemFlags CatalogueTreeModel::flags(const QModelIndex &index) const |
|
124 | 130 | { |
|
125 | if (index.column() == (int)Column::Validation) { | |
|
126 | return Qt::NoItemFlags; | |
|
127 | } | |
|
128 | ||
|
129 | auto item = static_cast<QTreeWidgetItem *>(index.internalPointer()); | |
|
130 | if (item) { | |
|
131 | return item->flags(); | |
|
131 | auto treeItem = item(index); | |
|
132 | if (treeItem) { | |
|
133 | return treeItem->flags(index.column()); | |
|
132 | 134 | } |
|
133 | 135 | |
|
134 | 136 | return Qt::NoItemFlags; |
@@ -136,13 +138,9 Qt::ItemFlags CatalogueTreeModel::flags(const QModelIndex &index) const | |||
|
136 | 138 | |
|
137 | 139 | QVariant CatalogueTreeModel::data(const QModelIndex &index, int role) const |
|
138 | 140 | { |
|
139 | if (!index.isValid()) { | |
|
140 | return QModelIndex(); | |
|
141 | } | |
|
142 | ||
|
143 | auto item = static_cast<QTreeWidgetItem *>(index.internalPointer()); | |
|
144 | if (item) { | |
|
145 | return item->data(index.column(), role); | |
|
141 | auto treeItem = item(index); | |
|
142 | if (treeItem) { | |
|
143 | return treeItem->data(index.column(), role); | |
|
146 | 144 | } |
|
147 | 145 | |
|
148 | 146 | return QModelIndex(); |
@@ -150,20 +148,43 QVariant CatalogueTreeModel::data(const QModelIndex &index, int role) const | |||
|
150 | 148 | |
|
151 | 149 | bool CatalogueTreeModel::setData(const QModelIndex &index, const QVariant &value, int role) |
|
152 | 150 | { |
|
153 | if (!index.isValid()) { | |
|
154 | return false; | |
|
151 | auto treeItem = item(index); | |
|
152 | if (treeItem) { | |
|
153 | auto result = treeItem->setData(index.column(), role, value); | |
|
154 | ||
|
155 | if (result && index.column() == (int)Column::Name) { | |
|
156 | emit itemRenamed(index); | |
|
155 | 157 | } |
|
156 | 158 | |
|
157 | auto item = static_cast<QTreeWidgetItem *>(index.internalPointer()); | |
|
158 | if (item) { | |
|
159 | item->setData(index.column(), role, value); | |
|
159 | return result; | |
|
160 | } | |
|
160 | 161 | |
|
161 | if (index.column() == (int)Column::Name) { | |
|
162 | emit itemRenamed(index); | |
|
162 | return false; | |
|
163 | } | |
|
164 | bool CatalogueTreeModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, | |
|
165 | int column, const QModelIndex &parent) const | |
|
166 | { | |
|
167 | auto draggedIndex = parent; | |
|
168 | auto draggedItem = item(draggedIndex); | |
|
169 | if (draggedItem) { | |
|
170 | return draggedItem->canDropMimeData(data, action); | |
|
163 | 171 |
|
|
164 | 172 | |
|
165 |
|
|
|
173 | return false; | |
|
166 | 174 | } |
|
167 | 175 | |
|
176 | bool CatalogueTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, | |
|
177 | int column, const QModelIndex &parent) | |
|
178 | { | |
|
168 | 179 | return false; |
|
169 | 180 | } |
|
181 | ||
|
182 | Qt::DropActions CatalogueTreeModel::supportedDropActions() const | |
|
183 | { | |
|
184 | return Qt::CopyAction | Qt::MoveAction; | |
|
185 | } | |
|
186 | ||
|
187 | QStringList CatalogueTreeModel::mimeTypes() const | |
|
188 | { | |
|
189 | return {MIME_TYPE_EVENT_LIST}; | |
|
190 | } |
@@ -77,19 +77,13 | |||
|
77 | 77 | <bool>true</bool> |
|
78 | 78 | </property> |
|
79 | 79 | <property name="dragDropMode"> |
|
80 |
<enum>QAbstractItemView::Drop |
|
|
80 | <enum>QAbstractItemView::DragDrop</enum> | |
|
81 | 81 | </property> |
|
82 | <property name="defaultDropAction"> | |
|
83 | <enum>Qt::CopyAction</enum> | |
|
84 |
</ |
|
|
85 | <property name="selectionMode"> | |
|
86 | <enum>QAbstractItemView::ExtendedSelection</enum> | |
|
87 | </property> | |
|
88 | <property name="headerHidden"> | |
|
89 | <bool>true</bool> | |
|
90 | </property> | |
|
91 | <attribute name="headerDefaultSectionSize"> | |
|
92 | <number>0</number> | |
|
82 | <attribute name="headerVisible"> | |
|
83 | <bool>false</bool> | |
|
84 | </attribute> | |
|
85 | <attribute name="headerStretchLastSection"> | |
|
86 | <bool>false</bool> | |
|
93 | 87 | </attribute> |
|
94 | 88 | </widget> |
|
95 | 89 | </item> |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now