##// END OF EJS Templates
Refactoring of catalogue: use a custom item class
trabillard -
r1260:af39d3a05321
parent child
Show More
@@ -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 }
@@ -1,47 +1,55
1 #ifndef SCIQLOP_CATALOGUETREEMODEL_H
1 #ifndef SCIQLOP_CATALOGUETREEMODEL_H
2 #define SCIQLOP_CATALOGUETREEMODEL_H
2 #define SCIQLOP_CATALOGUETREEMODEL_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QAbstractItemModel>
5 #include <QAbstractItemModel>
6 #include <QTreeWidgetItem>
6
7 class CatalogueAbstractTreeItem;
7
8
8 /**
9 /**
9 * @brief Model to display catalogue items based on QTreeWidgetItem
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 application will crash
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 class CatalogueTreeModel : public QAbstractItemModel {
14 class CatalogueTreeModel : public QAbstractItemModel {
13 Q_OBJECT
15 Q_OBJECT
14
16
15 signals:
17 signals:
16 void itemRenamed(const QModelIndex &index);
18 void itemRenamed(const QModelIndex &index);
17
19
18 public:
20 public:
19 CatalogueTreeModel(QObject *parent = nullptr);
21 CatalogueTreeModel(QObject *parent = nullptr);
20
22
21 enum class Column { Name, Validation, Count };
23 enum class Column { Name, Validation, Count };
22
24
23 QModelIndex addTopLevelItem(QTreeWidgetItem *item);
25 QModelIndex addTopLevelItem(CatalogueAbstractTreeItem *item);
24 int topLevelItemCount() const;
26 QVector<CatalogueAbstractTreeItem *> topLevelItems() const;
25 QTreeWidgetItem *topLevelItem(int i) const;
26
27
27 void addChildItem(QTreeWidgetItem *child, const QModelIndex &parentIndex);
28 void addChildItem(CatalogueAbstractTreeItem *child, const QModelIndex &parentIndex);
28
29
29 QTreeWidgetItem *item(const QModelIndex &index) const;
30 CatalogueAbstractTreeItem *item(const QModelIndex &index) const;
30 QModelIndex indexOf(QTreeWidgetItem *item, int column = 0) const;
31 QModelIndex indexOf(CatalogueAbstractTreeItem *item, int column = 0) const;
31
32
32 // model
33 // model
33 QModelIndex index(int row, int column,
34 QModelIndex index(int row, int column,
34 const QModelIndex &parent = QModelIndex()) const override;
35 const QModelIndex &parent = QModelIndex()) const override;
35 QModelIndex parent(const QModelIndex &index) const override;
36 QModelIndex parent(const QModelIndex &index) const override;
36 int rowCount(const QModelIndex &parent) const override;
37 int rowCount(const QModelIndex &parent) const override;
37 int columnCount(const QModelIndex &parent) const override;
38 int columnCount(const QModelIndex &parent) const override;
38 Qt::ItemFlags flags(const QModelIndex &index) const override;
39 Qt::ItemFlags flags(const QModelIndex &index) const override;
39 QVariant data(const QModelIndex &index, int role) const override;
40 QVariant data(const QModelIndex &index, int role) const override;
40 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
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 private:
50 private:
43 class CatalogueTreeModelPrivate;
51 class CatalogueTreeModelPrivate;
44 spimpl::unique_impl_ptr<CatalogueTreeModelPrivate> impl;
52 spimpl::unique_impl_ptr<CatalogueTreeModelPrivate> impl;
45 };
53 };
46
54
47 #endif // CATALOGUETREEMODEL_H
55 #endif // CATALOGUETREEMODEL_H
@@ -1,145 +1,147
1 qxorm_dep = dependency('QxOrm', required : true, fallback:['QxOrm','qxorm_dep'])
1 qxorm_dep = dependency('QxOrm', required : true, fallback:['QxOrm','qxorm_dep'])
2 catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['CatalogueAPI','CatalogueAPI_dep'])
2 catalogueapi_dep = dependency('CatalogueAPI', required : true, fallback:['CatalogueAPI','CatalogueAPI_dep'])
3
3
4 gui_moc_headers = [
4 gui_moc_headers = [
5 'include/DataSource/DataSourceWidget.h',
5 'include/DataSource/DataSourceWidget.h',
6 'include/Settings/SqpSettingsDialog.h',
6 'include/Settings/SqpSettingsDialog.h',
7 'include/Settings/SqpSettingsGeneralWidget.h',
7 'include/Settings/SqpSettingsGeneralWidget.h',
8 'include/SidePane/SqpSidePane.h',
8 'include/SidePane/SqpSidePane.h',
9 'include/SqpApplication.h',
9 'include/SqpApplication.h',
10 'include/DragAndDrop/DragDropScroller.h',
10 'include/DragAndDrop/DragDropScroller.h',
11 'include/DragAndDrop/DragDropTabSwitcher.h',
11 'include/DragAndDrop/DragDropTabSwitcher.h',
12 'include/TimeWidget/TimeWidget.h',
12 'include/TimeWidget/TimeWidget.h',
13 'include/Variable/VariableInspectorWidget.h',
13 'include/Variable/VariableInspectorWidget.h',
14 'include/Variable/RenameVariableDialog.h',
14 'include/Variable/RenameVariableDialog.h',
15 'include/Visualization/qcustomplot.h',
15 'include/Visualization/qcustomplot.h',
16 'include/Visualization/VisualizationGraphWidget.h',
16 'include/Visualization/VisualizationGraphWidget.h',
17 'include/Visualization/VisualizationTabWidget.h',
17 'include/Visualization/VisualizationTabWidget.h',
18 'include/Visualization/VisualizationWidget.h',
18 'include/Visualization/VisualizationWidget.h',
19 'include/Visualization/VisualizationZoneWidget.h',
19 'include/Visualization/VisualizationZoneWidget.h',
20 'include/Visualization/VisualizationDragDropContainer.h',
20 'include/Visualization/VisualizationDragDropContainer.h',
21 'include/Visualization/VisualizationDragWidget.h',
21 'include/Visualization/VisualizationDragWidget.h',
22 'include/Visualization/ColorScaleEditor.h',
22 'include/Visualization/ColorScaleEditor.h',
23 'include/Actions/SelectionZoneAction.h',
23 'include/Actions/SelectionZoneAction.h',
24 'include/Visualization/VisualizationMultiZoneSelectionDialog.h',
24 'include/Visualization/VisualizationMultiZoneSelectionDialog.h',
25 'include/Catalogue/CatalogueExplorer.h',
25 'include/Catalogue/CatalogueExplorer.h',
26 'include/Catalogue/CatalogueEventsWidget.h',
26 'include/Catalogue/CatalogueEventsWidget.h',
27 'include/Catalogue/CatalogueSideBarWidget.h',
27 'include/Catalogue/CatalogueSideBarWidget.h',
28 'include/Catalogue/CatalogueInspectorWidget.h',
28 'include/Catalogue/CatalogueInspectorWidget.h',
29 'include/Catalogue/CatalogueEventsModel.h',
29 'include/Catalogue/CatalogueEventsModel.h',
30 'include/Catalogue/CreateEventDialog.h',
30 'include/Catalogue/CreateEventDialog.h',
31 'include/Catalogue/CatalogueTreeModel.h'
31 'include/Catalogue/CatalogueTreeModel.h'
32 ]
32 ]
33
33
34 gui_ui_files = [
34 gui_ui_files = [
35 'ui/DataSource/DataSourceWidget.ui',
35 'ui/DataSource/DataSourceWidget.ui',
36 'ui/Settings/SqpSettingsDialog.ui',
36 'ui/Settings/SqpSettingsDialog.ui',
37 'ui/Settings/SqpSettingsGeneralWidget.ui',
37 'ui/Settings/SqpSettingsGeneralWidget.ui',
38 'ui/SidePane/SqpSidePane.ui',
38 'ui/SidePane/SqpSidePane.ui',
39 'ui/TimeWidget/TimeWidget.ui',
39 'ui/TimeWidget/TimeWidget.ui',
40 'ui/Variable/VariableInspectorWidget.ui',
40 'ui/Variable/VariableInspectorWidget.ui',
41 'ui/Variable/RenameVariableDialog.ui',
41 'ui/Variable/RenameVariableDialog.ui',
42 'ui/Variable/VariableMenuHeaderWidget.ui',
42 'ui/Variable/VariableMenuHeaderWidget.ui',
43 'ui/Visualization/VisualizationGraphWidget.ui',
43 'ui/Visualization/VisualizationGraphWidget.ui',
44 'ui/Visualization/VisualizationTabWidget.ui',
44 'ui/Visualization/VisualizationTabWidget.ui',
45 'ui/Visualization/VisualizationWidget.ui',
45 'ui/Visualization/VisualizationWidget.ui',
46 'ui/Visualization/VisualizationZoneWidget.ui',
46 'ui/Visualization/VisualizationZoneWidget.ui',
47 'ui/Visualization/ColorScaleEditor.ui',
47 'ui/Visualization/ColorScaleEditor.ui',
48 'ui/Visualization/VisualizationMultiZoneSelectionDialog.ui',
48 'ui/Visualization/VisualizationMultiZoneSelectionDialog.ui',
49 'ui/Catalogue/CatalogueExplorer.ui',
49 'ui/Catalogue/CatalogueExplorer.ui',
50 'ui/Catalogue/CatalogueEventsWidget.ui',
50 'ui/Catalogue/CatalogueEventsWidget.ui',
51 'ui/Catalogue/CatalogueSideBarWidget.ui',
51 'ui/Catalogue/CatalogueSideBarWidget.ui',
52 'ui/Catalogue/CatalogueInspectorWidget.ui',
52 'ui/Catalogue/CatalogueInspectorWidget.ui',
53 'ui/Catalogue/CreateEventDialog.ui'
53 'ui/Catalogue/CreateEventDialog.ui'
54 ]
54 ]
55
55
56 gui_qresources = ['resources/sqpguiresources.qrc']
56 gui_qresources = ['resources/sqpguiresources.qrc']
57
57
58 rcc_gen = generator(rcc,
58 rcc_gen = generator(rcc,
59 output : 'qrc_@BASENAME@.cpp',
59 output : 'qrc_@BASENAME@.cpp',
60 arguments : [
60 arguments : [
61 '--output',
61 '--output',
62 '@OUTPUT@',
62 '@OUTPUT@',
63 '@INPUT@',
63 '@INPUT@',
64 '@EXTRA_ARGS@'])
64 '@EXTRA_ARGS@'])
65
65
66 rcc_files = rcc_gen.process(gui_qresources, extra_args : ['-name', 'sqpguiresources'])
66 rcc_files = rcc_gen.process(gui_qresources, extra_args : ['-name', 'sqpguiresources'])
67
67
68 gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers,
68 gui_moc_files = qt5.preprocess(moc_headers : gui_moc_headers,
69 ui_files : gui_ui_files)
69 ui_files : gui_ui_files)
70
70
71 gui_sources = [
71 gui_sources = [
72 'src/SqpApplication.cpp',
72 'src/SqpApplication.cpp',
73 'src/DragAndDrop/DragDropGuiController.cpp',
73 'src/DragAndDrop/DragDropGuiController.cpp',
74 'src/DragAndDrop/DragDropScroller.cpp',
74 'src/DragAndDrop/DragDropScroller.cpp',
75 'src/DragAndDrop/DragDropTabSwitcher.cpp',
75 'src/DragAndDrop/DragDropTabSwitcher.cpp',
76 'src/Common/ColorUtils.cpp',
76 'src/Common/ColorUtils.cpp',
77 'src/Common/VisualizationDef.cpp',
77 'src/Common/VisualizationDef.cpp',
78 'src/DataSource/DataSourceTreeWidgetItem.cpp',
78 'src/DataSource/DataSourceTreeWidgetItem.cpp',
79 'src/DataSource/DataSourceTreeWidgetHelper.cpp',
79 'src/DataSource/DataSourceTreeWidgetHelper.cpp',
80 'src/DataSource/DataSourceWidget.cpp',
80 'src/DataSource/DataSourceWidget.cpp',
81 'src/DataSource/DataSourceTreeWidget.cpp',
81 'src/DataSource/DataSourceTreeWidget.cpp',
82 'src/Settings/SqpSettingsDialog.cpp',
82 'src/Settings/SqpSettingsDialog.cpp',
83 'src/Settings/SqpSettingsGeneralWidget.cpp',
83 'src/Settings/SqpSettingsGeneralWidget.cpp',
84 'src/SidePane/SqpSidePane.cpp',
84 'src/SidePane/SqpSidePane.cpp',
85 'src/TimeWidget/TimeWidget.cpp',
85 'src/TimeWidget/TimeWidget.cpp',
86 'src/Variable/VariableInspectorWidget.cpp',
86 'src/Variable/VariableInspectorWidget.cpp',
87 'src/Variable/VariableInspectorTableView.cpp',
87 'src/Variable/VariableInspectorTableView.cpp',
88 'src/Variable/VariableMenuHeaderWidget.cpp',
88 'src/Variable/VariableMenuHeaderWidget.cpp',
89 'src/Variable/RenameVariableDialog.cpp',
89 'src/Variable/RenameVariableDialog.cpp',
90 'src/Visualization/VisualizationGraphHelper.cpp',
90 'src/Visualization/VisualizationGraphHelper.cpp',
91 'src/Visualization/VisualizationGraphRenderingDelegate.cpp',
91 'src/Visualization/VisualizationGraphRenderingDelegate.cpp',
92 'src/Visualization/VisualizationGraphWidget.cpp',
92 'src/Visualization/VisualizationGraphWidget.cpp',
93 'src/Visualization/VisualizationTabWidget.cpp',
93 'src/Visualization/VisualizationTabWidget.cpp',
94 'src/Visualization/VisualizationWidget.cpp',
94 'src/Visualization/VisualizationWidget.cpp',
95 'src/Visualization/VisualizationZoneWidget.cpp',
95 'src/Visualization/VisualizationZoneWidget.cpp',
96 'src/Visualization/qcustomplot.cpp',
96 'src/Visualization/qcustomplot.cpp',
97 'src/Visualization/QCustomPlotSynchronizer.cpp',
97 'src/Visualization/QCustomPlotSynchronizer.cpp',
98 'src/Visualization/operations/FindVariableOperation.cpp',
98 'src/Visualization/operations/FindVariableOperation.cpp',
99 'src/Visualization/operations/GenerateVariableMenuOperation.cpp',
99 'src/Visualization/operations/GenerateVariableMenuOperation.cpp',
100 'src/Visualization/operations/MenuBuilder.cpp',
100 'src/Visualization/operations/MenuBuilder.cpp',
101 'src/Visualization/operations/RemoveVariableOperation.cpp',
101 'src/Visualization/operations/RemoveVariableOperation.cpp',
102 'src/Visualization/operations/RescaleAxeOperation.cpp',
102 'src/Visualization/operations/RescaleAxeOperation.cpp',
103 'src/Visualization/VisualizationDragDropContainer.cpp',
103 'src/Visualization/VisualizationDragDropContainer.cpp',
104 'src/Visualization/VisualizationDragWidget.cpp',
104 'src/Visualization/VisualizationDragWidget.cpp',
105 'src/Visualization/AxisRenderingUtils.cpp',
105 'src/Visualization/AxisRenderingUtils.cpp',
106 'src/Visualization/PlottablesRenderingUtils.cpp',
106 'src/Visualization/PlottablesRenderingUtils.cpp',
107 'src/Visualization/MacScrollBarStyle.cpp',
107 'src/Visualization/MacScrollBarStyle.cpp',
108 'src/Visualization/VisualizationCursorItem.cpp',
108 'src/Visualization/VisualizationCursorItem.cpp',
109 'src/Visualization/ColorScaleEditor.cpp',
109 'src/Visualization/ColorScaleEditor.cpp',
110 'src/Visualization/SqpColorScale.cpp',
110 'src/Visualization/SqpColorScale.cpp',
111 'src/Visualization/QCPColorMapIterator.cpp',
111 'src/Visualization/QCPColorMapIterator.cpp',
112 'src/Visualization/VisualizationSelectionZoneItem.cpp',
112 'src/Visualization/VisualizationSelectionZoneItem.cpp',
113 'src/Visualization/VisualizationSelectionZoneManager.cpp',
113 'src/Visualization/VisualizationSelectionZoneManager.cpp',
114 'src/Actions/SelectionZoneAction.cpp',
114 'src/Actions/SelectionZoneAction.cpp',
115 'src/Actions/ActionsGuiController.cpp',
115 'src/Actions/ActionsGuiController.cpp',
116 'src/Visualization/VisualizationActionManager.cpp',
116 'src/Visualization/VisualizationActionManager.cpp',
117 'src/Visualization/VisualizationMultiZoneSelectionDialog.cpp',
117 'src/Visualization/VisualizationMultiZoneSelectionDialog.cpp',
118 'src/Catalogue/CatalogueExplorer.cpp',
118 'src/Catalogue/CatalogueExplorer.cpp',
119 'src/Catalogue/CatalogueEventsWidget.cpp',
119 'src/Catalogue/CatalogueEventsWidget.cpp',
120 'src/Catalogue/CatalogueSideBarWidget.cpp',
120 'src/Catalogue/CatalogueSideBarWidget.cpp',
121 'src/Catalogue/CatalogueInspectorWidget.cpp',
121 'src/Catalogue/CatalogueInspectorWidget.cpp',
122 'src/Catalogue/CatalogueTreeWidgetItem.cpp',
122 'src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp',
123 'src/Catalogue/CatalogueTreeItems/CatalogueTreeItem.cpp',
124 'src/Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.cpp',
123 'src/Catalogue/CatalogueEventsModel.cpp',
125 'src/Catalogue/CatalogueEventsModel.cpp',
124 'src/Catalogue/CatalogueExplorerHelper.cpp',
126 'src/Catalogue/CatalogueExplorerHelper.cpp',
125 'src/Catalogue/CatalogueActionManager.cpp',
127 'src/Catalogue/CatalogueActionManager.cpp',
126 'src/Catalogue/CreateEventDialog.cpp',
128 'src/Catalogue/CreateEventDialog.cpp',
127 'src/Catalogue/CatalogueTreeModel.cpp'
129 'src/Catalogue/CatalogueTreeModel.cpp'
128 ]
130 ]
129
131
130 gui_inc = include_directories(['include'])
132 gui_inc = include_directories(['include'])
131
133
132 sciqlop_gui_lib = library('sciqlopgui',
134 sciqlop_gui_lib = library('sciqlopgui',
133 gui_sources,
135 gui_sources,
134 gui_moc_files,
136 gui_moc_files,
135 rcc_files,
137 rcc_files,
136 include_directories : [gui_inc],
138 include_directories : [gui_inc],
137 dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep],
139 dependencies : [ qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep],
138 install : true
140 install : true
139 )
141 )
140
142
141 sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib,
143 sciqlop_gui = declare_dependency(link_with : sciqlop_gui_lib,
142 include_directories : gui_inc,
144 include_directories : gui_inc,
143 dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep])
145 dependencies : [qt5printsupport, qt5gui, qt5widgets, qt5svg, sciqlop_core, catalogueapi_dep])
144
146
145
147
@@ -1,298 +1,295
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>
8 #include <Catalogue/CatalogueTreeItems/CatalogueTreeItem.h>
7 #include <Catalogue/CatalogueTreeModel.h>
9 #include <Catalogue/CatalogueTreeModel.h>
8 #include <Catalogue/CatalogueTreeWidgetItem.h>
9 #include <CatalogueDao.h>
10 #include <CatalogueDao.h>
10 #include <ComparaisonPredicate.h>
11 #include <ComparaisonPredicate.h>
11 #include <DBCatalogue.h>
12 #include <DBCatalogue.h>
12
13
13 #include <QMenu>
14 #include <QMenu>
14
15
15 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
16 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
16
17
17
18
18 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
19 constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1;
19 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
20 constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2;
20 constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2;
21 constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3;
21 constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3;
22 constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4;
22
23
23
24
24 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
25 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
25
26
26 CatalogueTreeModel *m_TreeModel = nullptr;
27 CatalogueTreeModel *m_TreeModel = nullptr;
27
28
28 void configureTreeWidget(QTreeView *treeView);
29 void configureTreeWidget(QTreeView *treeView);
29 QModelIndex addDatabaseItem(const QString &name);
30 QModelIndex addDatabaseItem(const QString &name);
30 QTreeWidgetItem *getDatabaseItem(const QString &name);
31 CatalogueAbstractTreeItem *getDatabaseItem(const QString &name);
31 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
32 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
32 const QModelIndex &databaseIndex);
33 const QModelIndex &databaseIndex);
33
34
34 CatalogueTreeWidgetItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const;
35 CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const;
35 void setHasChanges(bool value, const QModelIndex &index, QTreeView *treeView);
36 void setHasChanges(bool value, const QModelIndex &index, QTreeView *treeView);
36 bool hasChanges(const QModelIndex &index, QTreeView *treeView);
37 bool hasChanges(const QModelIndex &index, QTreeView *treeView);
37 };
38 };
38
39
39 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
40 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
40 : QWidget(parent),
41 : QWidget(parent),
41 ui(new Ui::CatalogueSideBarWidget),
42 ui(new Ui::CatalogueSideBarWidget),
42 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
43 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
43 {
44 {
44 ui->setupUi(this);
45 ui->setupUi(this);
45
46
46 impl->m_TreeModel = new CatalogueTreeModel(this);
47 impl->m_TreeModel = new CatalogueTreeModel(this);
47 ui->treeView->setModel(impl->m_TreeModel);
48 ui->treeView->setModel(impl->m_TreeModel);
48
49
49 impl->configureTreeWidget(ui->treeView);
50 impl->configureTreeWidget(ui->treeView);
50
51
51 ui->treeView->header()->setStretchLastSection(false);
52 ui->treeView->header()->setStretchLastSection(false);
52 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
53 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
53 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
54 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
54
55
55 auto emitSelection = [this]() {
56 auto emitSelection = [this]() {
56
57
57 auto selectedItems = ui->treeView->selectionModel()->selectedRows();
58 auto selectedItems = ui->treeView->selectionModel()->selectedRows();
58 if (selectedItems.isEmpty()) {
59 if (selectedItems.isEmpty()) {
59 emit this->selectionCleared();
60 emit this->selectionCleared();
60 }
61 }
61 else {
62 else {
62 QVector<std::shared_ptr<DBCatalogue> > catalogues;
63 QVector<std::shared_ptr<DBCatalogue> > catalogues;
63 QStringList databases;
64 QStringList databases;
64 auto firstIndex = selectedItems.first();
65 auto firstIndex = selectedItems.first();
65 auto firstItem = impl->m_TreeModel->item(firstIndex);
66 auto firstItem = impl->m_TreeModel->item(firstIndex);
66 if (!firstItem) {
67 if (!firstItem) {
67 Q_ASSERT(false);
68 Q_ASSERT(false);
68 return;
69 return;
69 }
70 }
70 auto selectionType = firstItem->type();
71 auto selectionType = firstItem->type();
71
72
72 for (auto itemIndex : selectedItems) {
73 for (auto itemIndex : selectedItems) {
73 auto item = impl->m_TreeModel->item(itemIndex);
74 auto item = impl->m_TreeModel->item(itemIndex);
74 if (item && item->type() == selectionType) {
75 if (item && item->type() == selectionType) {
75 switch (selectionType) {
76 switch (selectionType) {
76 case CATALOGUE_ITEM_TYPE:
77 case CATALOGUE_ITEM_TYPE:
77 catalogues.append(
78 catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue());
78 static_cast<CatalogueTreeWidgetItem *>(item)->catalogue());
79 break;
79 break;
80 case DATABASE_ITEM_TYPE:
80 case DATABASE_ITEM_TYPE:
81 selectionType = DATABASE_ITEM_TYPE;
81 databases.append(item->text());
82 databases.append(item->text(0));
83 case ALL_EVENT_ITEM_TYPE: // fallthrough
82 case ALL_EVENT_ITEM_TYPE: // fallthrough
84 case TRASH_ITEM_TYPE: // fallthrough
83 case TRASH_ITEM_TYPE: // fallthrough
85 default:
84 default:
86 break;
85 break;
87 }
86 }
88 }
87 }
89 else {
88 else {
90 // Incoherent multi selection
89 // Incoherent multi selection
91 selectionType = -1;
90 selectionType = -1;
92 break;
91 break;
93 }
92 }
94 }
93 }
95
94
96 switch (selectionType) {
95 switch (selectionType) {
97 case CATALOGUE_ITEM_TYPE:
96 case CATALOGUE_ITEM_TYPE:
98 emit this->catalogueSelected(catalogues);
97 emit this->catalogueSelected(catalogues);
99 break;
98 break;
100 case DATABASE_ITEM_TYPE:
99 case DATABASE_ITEM_TYPE:
101 emit this->databaseSelected(databases);
100 emit this->databaseSelected(databases);
102 break;
101 break;
103 case ALL_EVENT_ITEM_TYPE:
102 case ALL_EVENT_ITEM_TYPE:
104 emit this->allEventsSelected();
103 emit this->allEventsSelected();
105 break;
104 break;
106 case TRASH_ITEM_TYPE:
105 case TRASH_ITEM_TYPE:
107 emit this->trashSelected();
106 emit this->trashSelected();
108 break;
107 break;
109 default:
108 default:
110 emit this->selectionCleared();
109 emit this->selectionCleared();
111 break;
110 break;
112 }
111 }
113 }
112 }
114
113
115
114
116 };
115 };
117
116
118 connect(ui->treeView, &QTreeView::clicked, emitSelection);
117 connect(ui->treeView, &QTreeView::clicked, emitSelection);
119 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection);
118 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection);
120 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) {
119 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) {
121 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
120 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
122 if (selectedIndexes.contains(index)) {
121 if (selectedIndexes.contains(index)) {
123 emitSelection();
122 emitSelection();
124 }
123 }
125
124
126 auto item = impl->m_TreeModel->item(index);
125 auto item = impl->m_TreeModel->item(index);
127 impl->setHasChanges(true, index, ui->treeView);
126 impl->setHasChanges(true, index, ui->treeView);
128 });
127 });
129
128
130 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
129 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
131 connect(ui->treeView, &QTreeWidget::customContextMenuRequested, this,
130 connect(ui->treeView, &QTreeView::customContextMenuRequested, this,
132 &CatalogueSideBarWidget::onContextMenuRequested);
131 &CatalogueSideBarWidget::onContextMenuRequested);
133 }
132 }
134
133
135 CatalogueSideBarWidget::~CatalogueSideBarWidget()
134 CatalogueSideBarWidget::~CatalogueSideBarWidget()
136 {
135 {
137 delete ui;
136 delete ui;
138 }
137 }
139
138
140 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
139 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
141 bool hasChanges)
140 bool hasChanges)
142 {
141 {
143 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
142 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
144 auto index = impl->m_TreeModel->indexOf(catalogueItem);
143 auto index = impl->m_TreeModel->indexOf(catalogueItem);
145 impl->setHasChanges(hasChanges, index, ui->treeView);
144 impl->setHasChanges(hasChanges, index, ui->treeView);
146 catalogueItem->refresh();
145 // catalogueItem->refresh();
147 }
146 }
148 }
147 }
149
148
150 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
149 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
151 {
150 {
152 QMenu menu{this};
151 QMenu menu{this};
153
152
154 auto currentIndex = ui->treeView->currentIndex();
153 auto currentIndex = ui->treeView->currentIndex();
155 auto currentItem = impl->m_TreeModel->item(currentIndex);
154 auto currentItem = impl->m_TreeModel->item(currentIndex);
156 if (!currentItem) {
155 if (!currentItem) {
157 return;
156 return;
158 }
157 }
159
158
160 switch (currentItem->type()) {
159 switch (currentItem->type()) {
161 case CATALOGUE_ITEM_TYPE:
160 case CATALOGUE_ITEM_TYPE:
162 menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); });
161 menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); });
163 break;
162 break;
164 case DATABASE_ITEM_TYPE:
163 case DATABASE_ITEM_TYPE:
165 break;
164 break;
166 case ALL_EVENT_ITEM_TYPE:
165 case ALL_EVENT_ITEM_TYPE:
167 break;
166 break;
168 case TRASH_ITEM_TYPE:
167 case TRASH_ITEM_TYPE:
169 menu.addAction("Empty Trash", []() {
168 menu.addAction("Empty Trash", []() {
170 // TODO
169 // TODO
171 });
170 });
172 break;
171 break;
173 default:
172 default:
174 break;
173 break;
175 }
174 }
176
175
177 if (!menu.isEmpty()) {
176 if (!menu.isEmpty()) {
178 menu.exec(ui->treeView->mapToGlobal(pos));
177 menu.exec(ui->treeView->mapToGlobal(pos));
179 }
178 }
180 }
179 }
181
180
182 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView)
181 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView)
183 {
182 {
184 auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE};
183 auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events",
185 allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png"));
184 ALL_EVENT_ITEM_TYPE};
186 m_TreeModel->addTopLevelItem(allEventsItem);
185 m_TreeModel->addTopLevelItem(allEventsItem);
187
186
188 auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE};
187 auto trashItem
189 trashItem->setIcon(0, QIcon(":/icones/trash.png"));
188 = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE};
190 m_TreeModel->addTopLevelItem(trashItem);
189 m_TreeModel->addTopLevelItem(trashItem);
191
190
192 auto separator = new QFrame{treeView};
191 auto separator = new QFrame{treeView};
193 separator->setFrameShape(QFrame::HLine);
192 separator->setFrameShape(QFrame::HLine);
194 auto separatorItem = new QTreeWidgetItem{};
193 auto separatorItem
195 separatorItem->setFlags(Qt::NoItemFlags);
194 = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE};
195 separatorItem->setEnabled(false);
196 auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem);
196 auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem);
197 treeView->setIndexWidget(separatorIndex, separator);
197 treeView->setIndexWidget(separatorIndex, separator);
198
198
199 auto repositories = sqpApp->catalogueController().getRepositories();
199 auto repositories = sqpApp->catalogueController().getRepositories();
200 for (auto dbname : repositories) {
200 for (auto dbname : repositories) {
201 auto dbIndex = addDatabaseItem(dbname);
201 auto dbIndex = addDatabaseItem(dbname);
202 auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname);
202 auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname);
203 for (auto catalogue : catalogues) {
203 for (auto catalogue : catalogues) {
204 addCatalogueItem(catalogue, dbIndex);
204 addCatalogueItem(catalogue, dbIndex);
205 }
205 }
206 }
206 }
207
207
208 treeView->expandAll();
208 treeView->expandAll();
209 }
209 }
210
210
211 QModelIndex
211 QModelIndex
212 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name)
212 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name)
213 {
213 {
214 auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE};
214 auto databaseItem
215 databaseItem->setIcon(0, QIcon{":/icones/database.png"});
215 = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE};
216 auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem);
216 auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem);
217
217
218 return databaseIndex;
218 return databaseIndex;
219 }
219 }
220
220
221 QTreeWidgetItem *
221 CatalogueAbstractTreeItem *
222 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name)
222 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name)
223 {
223 {
224 for (auto i = 0; i < m_TreeModel->topLevelItemCount(); ++i) {
224 for (auto item : m_TreeModel->topLevelItems()) {
225 auto item = m_TreeModel->topLevelItem(i);
225 if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) {
226 if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) {
227 return item;
226 return item;
228 }
227 }
229 }
228 }
230
229
231 return nullptr;
230 return nullptr;
232 }
231 }
233
232
234 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
233 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
235 const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex)
234 const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex)
236 {
235 {
237 auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE};
236 auto catalogueItem
238 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
237 = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE};
239 m_TreeModel->addChildItem(catalogueItem, databaseIndex);
238 m_TreeModel->addChildItem(catalogueItem, databaseIndex);
240 }
239 }
241
240
242 CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
241 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
243 const std::shared_ptr<DBCatalogue> &catalogue) const
242 const std::shared_ptr<DBCatalogue> &catalogue) const
244 {
243 {
245 for (auto i = 0; i < m_TreeModel->topLevelItemCount(); ++i) {
244 for (auto item : m_TreeModel->topLevelItems()) {
246 auto item = m_TreeModel->topLevelItem(i);
247 if (item->type() == DATABASE_ITEM_TYPE) {
245 if (item->type() == DATABASE_ITEM_TYPE) {
248 for (auto j = 0; j < item->childCount(); ++j) {
246 for (auto childItem : item->children()) {
249 auto childItem = item->child(j);
250 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
247 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
251 auto catalogueItem = static_cast<CatalogueTreeWidgetItem *>(childItem);
248 auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem);
252 if (catalogueItem->catalogue() == catalogue) {
249 if (catalogueItem->catalogue() == catalogue) {
253 return catalogueItem;
250 return catalogueItem;
254 }
251 }
255 }
252 }
256 else {
253 else {
257 qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree "
254 qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree "
258 "structure. A database item should "
255 "structure. A database item should "
259 "only contain catalogues.";
256 "only contain catalogues.";
260 Q_ASSERT(false);
257 Q_ASSERT(false);
261 }
258 }
262 }
259 }
263 }
260 }
264 }
261 }
265
262
266 return nullptr;
263 return nullptr;
267 }
264 }
268
265
269 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(bool value,
266 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(bool value,
270 const QModelIndex &index,
267 const QModelIndex &index,
271 QTreeView *treeView)
268 QTreeView *treeView)
272 {
269 {
273 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
270 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
274 if (value) {
271 if (value) {
275 if (!hasChanges(validationIndex, treeView)) {
272 if (!hasChanges(validationIndex, treeView)) {
276 auto widget = CatalogueExplorerHelper::buildValidationWidget(
273 auto widget = CatalogueExplorerHelper::buildValidationWidget(
277 treeView,
274 treeView,
278 [this, validationIndex, treeView]() {
275 [this, validationIndex, treeView]() {
279 setHasChanges(false, validationIndex, treeView);
276 setHasChanges(false, validationIndex, treeView);
280 },
277 },
281 [this, validationIndex, treeView]() {
278 [this, validationIndex, treeView]() {
282 setHasChanges(false, validationIndex, treeView);
279 setHasChanges(false, validationIndex, treeView);
283 });
280 });
284 treeView->setIndexWidget(validationIndex, widget);
281 treeView->setIndexWidget(validationIndex, widget);
285 }
282 }
286 }
283 }
287 else {
284 else {
288 // Note: the widget is destroyed
285 // Note: the widget is destroyed
289 treeView->setIndexWidget(validationIndex, nullptr);
286 treeView->setIndexWidget(validationIndex, nullptr);
290 }
287 }
291 }
288 }
292
289
293 bool CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::hasChanges(const QModelIndex &index,
290 bool CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::hasChanges(const QModelIndex &index,
294 QTreeView *treeView)
291 QTreeView *treeView)
295 {
292 {
296 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
293 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
297 return treeView->indexWidget(validationIndex) != nullptr;
294 return treeView->indexWidget(validationIndex) != nullptr;
298 }
295 }
@@ -1,69 +1,85
1 #include "Catalogue/CatalogueTreeWidgetItem.h"
1 #include "Catalogue/CatalogueTreeItems/CatalogueTreeItem.h"
2 #include <Catalogue/CatalogueExplorerHelper.h>
2 #include <Catalogue/CatalogueExplorerHelper.h>
3
3
4 #include <Catalogue/CatalogueController.h>
4 #include <Catalogue/CatalogueController.h>
5 #include <Common/MimeTypesDef.h>
6 #include <QIcon>
7 #include <QMimeData>
5 #include <SqpApplication.h>
8 #include <SqpApplication.h>
6
9
7 #include <memory>
10 #include <memory>
8
11
9 #include <DBCatalogue.h>
12 #include <DBCatalogue.h>
10
13
11 /// Column in the tree widget where the apply and cancel buttons must appear
14 struct CatalogueTreeItem::CatalogueTreeItemPrivate {
12 const auto APPLY_CANCEL_BUTTONS_COLUMN = 1;
13
14 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
15
15
16 std::shared_ptr<DBCatalogue> m_Catalogue;
16 std::shared_ptr<DBCatalogue> m_Catalogue;
17 QIcon m_Icon;
17
18
18 CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue)
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 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type)
26 CatalogueTreeItem::CatalogueTreeItem(std::shared_ptr<DBCatalogue> catalogue, const QIcon &icon,
25 : QTreeWidgetItem(type),
27 int type)
26 impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
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 CatalogueTreeWidgetItem::data(int column, int role) const
33 QVariant CatalogueTreeItem::data(int column, int role) const
32 {
34 {
33 if (column == 0) {
35 if (column == 0) {
34 switch (role) {
36 switch (role) {
35 case Qt::EditRole: // fallthrough
37 case Qt::EditRole: // fallthrough
36 case Qt::DisplayRole:
38 case Qt::DisplayRole:
37 return impl->m_Catalogue->getName();
39 return impl->m_Catalogue->getName();
40 case Qt::DecorationRole:
41 return impl->m_Icon;
38 default:
42 default:
39 break;
43 break;
40 }
44 }
41 }
45 }
42
46
43 return QTreeWidgetItem::data(column, role);
47 return QVariant();
44 }
48 }
45
49
46 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &value)
50 bool CatalogueTreeItem::setData(int column, int role, const QVariant &value)
47 {
51 {
52 bool result = false;
53
48 if (role == Qt::EditRole && column == 0) {
54 if (role == Qt::EditRole && column == 0) {
49 auto newName = value.toString();
55 auto newName = value.toString();
50 if (newName != impl->m_Catalogue->getName()) {
56 if (newName != impl->m_Catalogue->getName()) {
51 setText(0, newName);
52 impl->m_Catalogue->setName(newName);
57 impl->m_Catalogue->setName(newName);
53 sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue);
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 else {
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,169 +1,190
1 #include "Catalogue/CatalogueTreeModel.h"
1 #include "Catalogue/CatalogueTreeModel.h"
2 #include <Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h>
2
3
3 #include <QTreeWidgetItem>
4 #include <QMimeData>
4 #include <memory>
5 #include <memory>
5
6
7 #include <Common/MimeTypesDef.h>
8
6 struct CatalogueTreeModel::CatalogueTreeModelPrivate {
9 struct CatalogueTreeModel::CatalogueTreeModelPrivate {
7 std::unique_ptr<QTreeWidgetItem> m_RootItem = nullptr;
10 std::unique_ptr<CatalogueAbstractTreeItem> m_RootItem = nullptr;
8
11
9 CatalogueTreeModelPrivate() : m_RootItem{std::make_unique<QTreeWidgetItem>()} {}
12 CatalogueTreeModelPrivate() : m_RootItem{std::make_unique<CatalogueAbstractTreeItem>()} {}
10 };
13 };
11
14
12 CatalogueTreeModel::CatalogueTreeModel(QObject *parent)
15 CatalogueTreeModel::CatalogueTreeModel(QObject *parent)
13 : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueTreeModelPrivate>()}
16 : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueTreeModelPrivate>()}
14 {
17 {
15 }
18 }
16
19
17 QModelIndex CatalogueTreeModel::addTopLevelItem(QTreeWidgetItem *item)
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 impl->m_RootItem->addChild(item);
24 impl->m_RootItem->addChild(item);
21 endInsertRows();
25 endInsertRows();
22
26
23 return index(impl->m_RootItem->childCount() - 1, 0);
27 emit dataChanged(QModelIndex(), QModelIndex());
24 }
25
28
26 int CatalogueTreeModel::topLevelItemCount() const
29 return index(nbTopLevelItems, 0);
27 {
28 return impl->m_RootItem->childCount();
29 }
30 }
30
31
31 QTreeWidgetItem *CatalogueTreeModel::topLevelItem(int i) const
32 QVector<CatalogueAbstractTreeItem *> CatalogueTreeModel::topLevelItems() const
32 {
33 {
33 return impl->m_RootItem->child(i);
34 return impl->m_RootItem->children();
34 }
35 }
35
36
36 void CatalogueTreeModel::addChildItem(QTreeWidgetItem *child, const QModelIndex &parentIndex)
37 void CatalogueTreeModel::addChildItem(CatalogueAbstractTreeItem *child,
38 const QModelIndex &parentIndex)
37 {
39 {
38 auto parentItem = item(parentIndex);
40 auto parentItem = item(parentIndex);
39 beginInsertRows(parentIndex, parentItem->childCount(), parentItem->childCount());
41 int c = parentItem->children().count();
42 beginInsertRows(parentIndex, c, c);
40 parentItem->addChild(child);
43 parentItem->addChild(child);
41 endInsertRows();
44 endInsertRows();
45
46 emit dataChanged(QModelIndex(), QModelIndex());
42 }
47 }
43
48
44 QTreeWidgetItem *CatalogueTreeModel::item(const QModelIndex &index) const
49 CatalogueAbstractTreeItem *CatalogueTreeModel::item(const QModelIndex &index) const
45 {
50 {
46 return static_cast<QTreeWidgetItem *>(index.internalPointer());
51 return static_cast<CatalogueAbstractTreeItem *>(index.internalPointer());
47 }
52 }
48
53
49 QModelIndex CatalogueTreeModel::indexOf(QTreeWidgetItem *item, int column) const
54 QModelIndex CatalogueTreeModel::indexOf(CatalogueAbstractTreeItem *item, int column) const
50 {
55 {
51 auto parentItem = item->parent();
56 auto parentItem = item->parent();
52 if (!parentItem) {
57 if (!parentItem) {
53 return QModelIndex();
58 return QModelIndex();
54 }
59 }
55
60
56 auto row = parentItem->indexOfChild(item);
61 auto row = parentItem->children().indexOf(item);
57 return createIndex(row, column, item);
62 return createIndex(row, column, item);
58 }
63 }
59
64
60 QModelIndex CatalogueTreeModel::index(int row, int column, const QModelIndex &parent) const
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 if (!hasIndex(row, column, parent)) {
71 if (!hasIndex(row, column, parent)) {
63 return QModelIndex();
72 return QModelIndex();
64 }
73 }
65
74
66 QTreeWidgetItem *parentItem = nullptr;
75 CatalogueAbstractTreeItem *parentItem = nullptr;
67
76
68 if (!parent.isValid()) {
77 if (!parent.isValid()) {
69 parentItem = impl->m_RootItem.get();
78 parentItem = impl->m_RootItem.get();
70 }
79 }
71 else {
80 else {
72 parentItem = static_cast<QTreeWidgetItem *>(parent.internalPointer());
81 parentItem = item(parent);
73 }
82 }
74
83
75 QTreeWidgetItem *childItem = parentItem->child(row);
84 auto childItem = parentItem->children().value(row);
76 if (childItem) {
85 if (childItem) {
77 return createIndex(row, column, childItem);
86 return createIndex(row, column, childItem);
78 }
87 }
79
88
80 return QModelIndex();
89 return QModelIndex();
81 }
90 }
82
91
83
92
84 QModelIndex CatalogueTreeModel::parent(const QModelIndex &index) const
93 QModelIndex CatalogueTreeModel::parent(const QModelIndex &index) const
85 {
94 {
86 if (!index.isValid()) {
95 if (!index.isValid()) {
87 return QModelIndex();
96 return QModelIndex();
88 }
97 }
89
98
90 auto childItem = static_cast<QTreeWidgetItem *>(index.internalPointer());
99 auto childItem = item(index);
91 auto parentItem = childItem->parent();
100 auto parentItem = childItem->parent();
92
101
93 if (parentItem == nullptr || parentItem->parent() == nullptr) {
102 if (parentItem == nullptr || parentItem->parent() == nullptr) {
94 return QModelIndex();
103 return QModelIndex();
95 }
104 }
96
105
97 auto row = parentItem->parent()->indexOfChild(parentItem);
106 auto row = parentItem->parent()->children().indexOf(parentItem);
98 return createIndex(row, 0, parentItem);
107 return createIndex(row, 0, parentItem);
99 }
108 }
100
109
101 int CatalogueTreeModel::rowCount(const QModelIndex &parent) const
110 int CatalogueTreeModel::rowCount(const QModelIndex &parent) const
102 {
111 {
103 QTreeWidgetItem *parentItem = nullptr;
112 CatalogueAbstractTreeItem *parentItem = nullptr;
104 if (parent.column() > 0) {
105 return 0;
106 }
107
113
108 if (!parent.isValid()) {
114 if (!parent.isValid()) {
109 parentItem = impl->m_RootItem.get();
115 parentItem = impl->m_RootItem.get();
110 }
116 }
111 else {
117 else {
112 parentItem = static_cast<QTreeWidgetItem *>(parent.internalPointer());
118 parentItem = item(parent);
113 }
119 }
114
120
115 return parentItem->childCount();
121 return parentItem->children().count();
116 }
122 }
117
123
118 int CatalogueTreeModel::columnCount(const QModelIndex &parent) const
124 int CatalogueTreeModel::columnCount(const QModelIndex &parent) const
119 {
125 {
120 return (int)Column::Count;
126 return (int)Column::Count;
121 }
127 }
122
128
123 Qt::ItemFlags CatalogueTreeModel::flags(const QModelIndex &index) const
129 Qt::ItemFlags CatalogueTreeModel::flags(const QModelIndex &index) const
124 {
130 {
125 if (index.column() == (int)Column::Validation) {
131 auto treeItem = item(index);
126 return Qt::NoItemFlags;
132 if (treeItem) {
127 }
133 return treeItem->flags(index.column());
128
129 auto item = static_cast<QTreeWidgetItem *>(index.internalPointer());
130 if (item) {
131 return item->flags();
132 }
134 }
133
135
134 return Qt::NoItemFlags;
136 return Qt::NoItemFlags;
135 }
137 }
136
138
137 QVariant CatalogueTreeModel::data(const QModelIndex &index, int role) const
139 QVariant CatalogueTreeModel::data(const QModelIndex &index, int role) const
138 {
140 {
139 if (!index.isValid()) {
141 auto treeItem = item(index);
140 return QModelIndex();
142 if (treeItem) {
141 }
143 return treeItem->data(index.column(), role);
142
143 auto item = static_cast<QTreeWidgetItem *>(index.internalPointer());
144 if (item) {
145 return item->data(index.column(), role);
146 }
144 }
147
145
148 return QModelIndex();
146 return QModelIndex();
149 }
147 }
150
148
151 bool CatalogueTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
149 bool CatalogueTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
152 {
150 {
153 if (!index.isValid()) {
151 auto treeItem = item(index);
154 return false;
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());
159 return result;
158 if (item) {
160 }
159 item->setData(index.column(), role, value);
160
161
161 if (index.column() == (int)Column::Name) {
162 return false;
162 emit itemRenamed(index);
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 return true;
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 return false;
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 }
@@ -1,103 +1,97
1 <?xml version="1.0" encoding="UTF-8"?>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
2 <ui version="4.0">
3 <class>CatalogueSideBarWidget</class>
3 <class>CatalogueSideBarWidget</class>
4 <widget class="QWidget" name="CatalogueSideBarWidget">
4 <widget class="QWidget" name="CatalogueSideBarWidget">
5 <property name="geometry">
5 <property name="geometry">
6 <rect>
6 <rect>
7 <x>0</x>
7 <x>0</x>
8 <y>0</y>
8 <y>0</y>
9 <width>330</width>
9 <width>330</width>
10 <height>523</height>
10 <height>523</height>
11 </rect>
11 </rect>
12 </property>
12 </property>
13 <property name="windowTitle">
13 <property name="windowTitle">
14 <string>Form</string>
14 <string>Form</string>
15 </property>
15 </property>
16 <layout class="QVBoxLayout" name="verticalLayout">
16 <layout class="QVBoxLayout" name="verticalLayout">
17 <property name="leftMargin">
17 <property name="leftMargin">
18 <number>0</number>
18 <number>0</number>
19 </property>
19 </property>
20 <property name="topMargin">
20 <property name="topMargin">
21 <number>0</number>
21 <number>0</number>
22 </property>
22 </property>
23 <property name="rightMargin">
23 <property name="rightMargin">
24 <number>0</number>
24 <number>0</number>
25 </property>
25 </property>
26 <property name="bottomMargin">
26 <property name="bottomMargin">
27 <number>0</number>
27 <number>0</number>
28 </property>
28 </property>
29 <item>
29 <item>
30 <layout class="QHBoxLayout" name="horizontalLayout">
30 <layout class="QHBoxLayout" name="horizontalLayout">
31 <item>
31 <item>
32 <widget class="QToolButton" name="btnAdd">
32 <widget class="QToolButton" name="btnAdd">
33 <property name="text">
33 <property name="text">
34 <string>+</string>
34 <string>+</string>
35 </property>
35 </property>
36 <property name="icon">
36 <property name="icon">
37 <iconset resource="../../resources/sqpguiresources.qrc">
37 <iconset resource="../../resources/sqpguiresources.qrc">
38 <normaloff>:/icones/add.png</normaloff>:/icones/add.png</iconset>
38 <normaloff>:/icones/add.png</normaloff>:/icones/add.png</iconset>
39 </property>
39 </property>
40 <property name="autoRaise">
40 <property name="autoRaise">
41 <bool>true</bool>
41 <bool>true</bool>
42 </property>
42 </property>
43 </widget>
43 </widget>
44 </item>
44 </item>
45 <item>
45 <item>
46 <widget class="QToolButton" name="btnRemove">
46 <widget class="QToolButton" name="btnRemove">
47 <property name="text">
47 <property name="text">
48 <string> - </string>
48 <string> - </string>
49 </property>
49 </property>
50 <property name="icon">
50 <property name="icon">
51 <iconset resource="../../resources/sqpguiresources.qrc">
51 <iconset resource="../../resources/sqpguiresources.qrc">
52 <normaloff>:/icones/remove.png</normaloff>:/icones/remove.png</iconset>
52 <normaloff>:/icones/remove.png</normaloff>:/icones/remove.png</iconset>
53 </property>
53 </property>
54 <property name="autoRaise">
54 <property name="autoRaise">
55 <bool>true</bool>
55 <bool>true</bool>
56 </property>
56 </property>
57 </widget>
57 </widget>
58 </item>
58 </item>
59 <item>
59 <item>
60 <spacer name="horizontalSpacer">
60 <spacer name="horizontalSpacer">
61 <property name="orientation">
61 <property name="orientation">
62 <enum>Qt::Horizontal</enum>
62 <enum>Qt::Horizontal</enum>
63 </property>
63 </property>
64 <property name="sizeHint" stdset="0">
64 <property name="sizeHint" stdset="0">
65 <size>
65 <size>
66 <width>40</width>
66 <width>40</width>
67 <height>20</height>
67 <height>20</height>
68 </size>
68 </size>
69 </property>
69 </property>
70 </spacer>
70 </spacer>
71 </item>
71 </item>
72 </layout>
72 </layout>
73 </item>
73 </item>
74 <item>
74 <item>
75 <widget class="QTreeView" name="treeView">
75 <widget class="QTreeView" name="treeView">
76 <property name="acceptDrops">
76 <property name="acceptDrops">
77 <bool>true</bool>
77 <bool>true</bool>
78 </property>
78 </property>
79 <property name="dragDropMode">
79 <property name="dragDropMode">
80 <enum>QAbstractItemView::DropOnly</enum>
80 <enum>QAbstractItemView::DragDrop</enum>
81 </property>
81 </property>
82 <property name="defaultDropAction">
82 <attribute name="headerVisible">
83 <enum>Qt::CopyAction</enum>
83 <bool>false</bool>
84 </property>
84 </attribute>
85 <property name="selectionMode">
85 <attribute name="headerStretchLastSection">
86 <enum>QAbstractItemView::ExtendedSelection</enum>
86 <bool>false</bool>
87 </property>
88 <property name="headerHidden">
89 <bool>true</bool>
90 </property>
91 <attribute name="headerDefaultSectionSize">
92 <number>0</number>
93 </attribute>
87 </attribute>
94 </widget>
88 </widget>
95 </item>
89 </item>
96 </layout>
90 </layout>
97 </widget>
91 </widget>
98 <resources>
92 <resources>
99 <include location="../../resources/sqpguiresources.qrc"/>
93 <include location="../../resources/sqpguiresources.qrc"/>
100 <include location="../../resources/sqpguiresources.qrc"/>
94 <include location="../../resources/sqpguiresources.qrc"/>
101 </resources>
95 </resources>
102 <connections/>
96 <connections/>
103 </ui>
97 </ui>
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now