##// END OF EJS Templates
Merge branch 'feature/CatalogueGuiPart4' into feature/CatalogueDevelop
trabillard -
r1273:e23e5777c6b5 merge
parent child
Show More
@@ -0,0 +1,35
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 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action);
29
30 private:
31 class CatalogueAbstractTreeItemPrivate;
32 spimpl::unique_impl_ptr<CatalogueAbstractTreeItemPrivate> impl;
33 };
34
35 #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,28
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 bool dropMimeData(const QMimeData *data, Qt::DropAction action) override;
19
20 /// Returns the catalogue represented by the item
21 std::shared_ptr<DBCatalogue> catalogue() const;
22
23 private:
24 class CatalogueTreeItemPrivate;
25 spimpl::unique_impl_ptr<CatalogueTreeItemPrivate> impl;
26 };
27
28 #endif // SCIQLOP_CATALOGUETREEITEM_H
@@ -0,0 +1,56
1 #ifndef SCIQLOP_CATALOGUETREEMODEL_H
2 #define SCIQLOP_CATALOGUETREEMODEL_H
3
4 #include <Common/spimpl.h>
5 #include <QAbstractItemModel>
6
7 class CatalogueAbstractTreeItem;
8
9 /**
10 * @brief Model to display catalogue items based on QTreeWidgetItem
11 * @warning Do not use the method QTreeWidgetItem::treeWidget for an item added to this model or the
12 * application will crash
13 */
14 class CatalogueTreeModel : public QAbstractItemModel {
15 Q_OBJECT
16
17 signals:
18 void itemRenamed(const QModelIndex &index);
19 void itemDropped(const QModelIndex &parentIndex);
20
21 public:
22 CatalogueTreeModel(QObject *parent = nullptr);
23
24 enum class Column { Name, Validation, Count };
25
26 QModelIndex addTopLevelItem(CatalogueAbstractTreeItem *item);
27 QVector<CatalogueAbstractTreeItem *> topLevelItems() const;
28
29 void addChildItem(CatalogueAbstractTreeItem *child, const QModelIndex &parentIndex);
30
31 CatalogueAbstractTreeItem *item(const QModelIndex &index) const;
32 QModelIndex indexOf(CatalogueAbstractTreeItem *item, int column = 0) const;
33
34 // model
35 QModelIndex index(int row, int column,
36 const QModelIndex &parent = QModelIndex()) const override;
37 QModelIndex parent(const QModelIndex &index) const override;
38 int rowCount(const QModelIndex &parent) const override;
39 int columnCount(const QModelIndex &parent) const override;
40 Qt::ItemFlags flags(const QModelIndex &index) const override;
41 QVariant data(const QModelIndex &index, int role) const override;
42 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
43
44 bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
45 const QModelIndex &parent) const override;
46 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
47 const QModelIndex &parent) override;
48 Qt::DropActions supportedDropActions() const;
49 QStringList mimeTypes() const;
50
51 private:
52 class CatalogueTreeModelPrivate;
53 spimpl::unique_impl_ptr<CatalogueTreeModelPrivate> impl;
54 };
55
56 #endif // CATALOGUETREEMODEL_H
@@ -0,0 +1,81
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 }
75
76 bool CatalogueAbstractTreeItem::dropMimeData(const QMimeData *data, Qt::DropAction action)
77 {
78 Q_UNUSED(data);
79 Q_UNUSED(action);
80 return false;
81 }
@@ -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 }
@@ -0,0 +1,201
1 #include "Catalogue/CatalogueTreeModel.h"
2 #include <Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.h>
3
4 #include <QMimeData>
5 #include <memory>
6
7 #include <Common/MimeTypesDef.h>
8
9 struct CatalogueTreeModel::CatalogueTreeModelPrivate {
10 std::unique_ptr<CatalogueAbstractTreeItem> m_RootItem = nullptr;
11
12 CatalogueTreeModelPrivate() : m_RootItem{std::make_unique<CatalogueAbstractTreeItem>()} {}
13 };
14
15 CatalogueTreeModel::CatalogueTreeModel(QObject *parent)
16 : QAbstractItemModel(parent), impl{spimpl::make_unique_impl<CatalogueTreeModelPrivate>()}
17 {
18 }
19
20 QModelIndex CatalogueTreeModel::addTopLevelItem(CatalogueAbstractTreeItem *item)
21 {
22 auto nbTopLevelItems = impl->m_RootItem->children().count();
23 beginInsertRows(QModelIndex(), nbTopLevelItems, nbTopLevelItems);
24 impl->m_RootItem->addChild(item);
25 endInsertRows();
26
27 emit dataChanged(QModelIndex(), QModelIndex());
28
29 return index(nbTopLevelItems, 0);
30 }
31
32 QVector<CatalogueAbstractTreeItem *> CatalogueTreeModel::topLevelItems() const
33 {
34 return impl->m_RootItem->children();
35 }
36
37 void CatalogueTreeModel::addChildItem(CatalogueAbstractTreeItem *child,
38 const QModelIndex &parentIndex)
39 {
40 auto parentItem = item(parentIndex);
41 int c = parentItem->children().count();
42 beginInsertRows(parentIndex, c, c);
43 parentItem->addChild(child);
44 endInsertRows();
45
46 emit dataChanged(parentIndex, parentIndex);
47 }
48
49 CatalogueAbstractTreeItem *CatalogueTreeModel::item(const QModelIndex &index) const
50 {
51 return static_cast<CatalogueAbstractTreeItem *>(index.internalPointer());
52 }
53
54 QModelIndex CatalogueTreeModel::indexOf(CatalogueAbstractTreeItem *item, int column) const
55 {
56 auto parentItem = item->parent();
57 if (!parentItem) {
58 return QModelIndex();
59 }
60
61 auto row = parentItem->children().indexOf(item);
62 return createIndex(row, column, item);
63 }
64
65 QModelIndex CatalogueTreeModel::index(int row, int column, const QModelIndex &parent) const
66 {
67 if (column > 0) {
68 int a = 0;
69 }
70
71 if (!hasIndex(row, column, parent)) {
72 return QModelIndex();
73 }
74
75 CatalogueAbstractTreeItem *parentItem = nullptr;
76
77 if (!parent.isValid()) {
78 parentItem = impl->m_RootItem.get();
79 }
80 else {
81 parentItem = item(parent);
82 }
83
84 auto childItem = parentItem->children().value(row);
85 if (childItem) {
86 return createIndex(row, column, childItem);
87 }
88
89 return QModelIndex();
90 }
91
92
93 QModelIndex CatalogueTreeModel::parent(const QModelIndex &index) const
94 {
95 if (!index.isValid()) {
96 return QModelIndex();
97 }
98
99 auto childItem = item(index);
100 auto parentItem = childItem->parent();
101
102 if (parentItem == nullptr || parentItem->parent() == nullptr) {
103 return QModelIndex();
104 }
105
106 auto row = parentItem->parent()->children().indexOf(parentItem);
107 return createIndex(row, 0, parentItem);
108 }
109
110 int CatalogueTreeModel::rowCount(const QModelIndex &parent) const
111 {
112 CatalogueAbstractTreeItem *parentItem = nullptr;
113
114 if (!parent.isValid()) {
115 parentItem = impl->m_RootItem.get();
116 }
117 else {
118 parentItem = item(parent);
119 }
120
121 return parentItem->children().count();
122 }
123
124 int CatalogueTreeModel::columnCount(const QModelIndex &parent) const
125 {
126 return (int)Column::Count;
127 }
128
129 Qt::ItemFlags CatalogueTreeModel::flags(const QModelIndex &index) const
130 {
131 auto treeItem = item(index);
132 if (treeItem) {
133 return treeItem->flags(index.column());
134 }
135
136 return Qt::NoItemFlags;
137 }
138
139 QVariant CatalogueTreeModel::data(const QModelIndex &index, int role) const
140 {
141 auto treeItem = item(index);
142 if (treeItem) {
143 return treeItem->data(index.column(), role);
144 }
145
146 return QModelIndex();
147 }
148
149 bool CatalogueTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
150 {
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);
157 }
158
159 return result;
160 }
161
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);
171 }
172
173 return false;
174 }
175
176 bool CatalogueTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row,
177 int column, const QModelIndex &parent)
178 {
179 bool result = false;
180
181 auto draggedIndex = parent;
182 auto draggedItem = item(draggedIndex);
183 if (draggedItem) {
184 result = draggedItem->dropMimeData(data, action);
185 if (result) {
186 emit itemDropped(draggedIndex);
187 }
188 }
189
190 return result;
191 }
192
193 Qt::DropActions CatalogueTreeModel::supportedDropActions() const
194 {
195 return Qt::CopyAction | Qt::MoveAction;
196 }
197
198 QStringList CatalogueTreeModel::mimeTypes() const
199 {
200 return {MIME_TYPE_EVENT_LIST};
201 }
@@ -52,6 +52,7 public slots:
52
52
53 protected:
53 protected:
54 void changeEvent(QEvent *e);
54 void changeEvent(QEvent *e);
55 void closeEvent(QCloseEvent *event);
55
56
56 private:
57 private:
57 std::unique_ptr<Ui::MainWindow> m_Ui;
58 std::unique_ptr<Ui::MainWindow> m_Ui;
@@ -49,10 +49,12 int main(int argc, char *argv[])
49 #endif
49 #endif
50 Q_INIT_RESOURCE(sqpguiresources);
50 Q_INIT_RESOURCE(sqpguiresources);
51
51
52 SqpApplication a{argc, argv};
53 SqpApplication::setOrganizationName("LPP");
52 SqpApplication::setOrganizationName("LPP");
54 SqpApplication::setOrganizationDomain("lpp.fr");
53 SqpApplication::setOrganizationDomain("lpp.fr");
55 SqpApplication::setApplicationName("SciQLop");
54 SqpApplication::setApplicationName("SciQLop");
55
56 SqpApplication a{argc, argv};
57
56 MainWindow w;
58 MainWindow w;
57 w.show();
59 w.show();
58
60
@@ -22,6 +22,7
22 #include "MainWindow.h"
22 #include "MainWindow.h"
23 #include "ui_MainWindow.h"
23 #include "ui_MainWindow.h"
24
24
25 #include <Catalogue/CatalogueController.h>
25 #include <Catalogue/CatalogueExplorer.h>
26 #include <Catalogue/CatalogueExplorer.h>
26 #include <DataSource/DataSourceController.h>
27 #include <DataSource/DataSourceController.h>
27 #include <DataSource/DataSourceWidget.h>
28 #include <DataSource/DataSourceWidget.h>
@@ -36,9 +37,11
36 #include <Visualization/VisualizationController.h>
37 #include <Visualization/VisualizationController.h>
37
38
38 #include <QAction>
39 #include <QAction>
40 #include <QCloseEvent>
39 #include <QDate>
41 #include <QDate>
40 #include <QDir>
42 #include <QDir>
41 #include <QFileDialog>
43 #include <QFileDialog>
44 #include <QMessageBox>
42 #include <QToolBar>
45 #include <QToolBar>
43 #include <QToolButton>
46 #include <QToolButton>
44 #include <memory.h>
47 #include <memory.h>
@@ -74,6 +77,8 public:
74 SqpSettingsDialog *m_SettingsDialog;
77 SqpSettingsDialog *m_SettingsDialog;
75 /// Catalogue dialog. MainWindow has the ownership
78 /// Catalogue dialog. MainWindow has the ownership
76 CatalogueExplorer *m_CatalogExplorer;
79 CatalogueExplorer *m_CatalogExplorer;
80
81 bool checkDataToSave(QWidget *parentWidget);
77 };
82 };
78
83
79 MainWindow::MainWindow(QWidget *parent)
84 MainWindow::MainWindow(QWidget *parent)
@@ -364,3 +369,37 void MainWindow::changeEvent(QEvent *e)
364 break;
369 break;
365 }
370 }
366 }
371 }
372
373 void MainWindow::closeEvent(QCloseEvent *event)
374 {
375 if (!impl->checkDataToSave(this)) {
376 event->ignore();
377 }
378 else {
379 event->accept();
380 }
381 }
382
383 bool MainWindow::MainWindowPrivate::checkDataToSave(QWidget *parentWidget)
384 {
385 auto hasChanges = sqpApp->catalogueController().hasChanges();
386 if (hasChanges) {
387 // There are some unsaved changes
388 switch (QMessageBox::question(
389 parentWidget, "Save changes",
390 tr("The catalogue controller unsaved changes.\nDo you want to save them ?"),
391 QMessageBox::SaveAll | QMessageBox::Discard | QMessageBox::Cancel,
392 QMessageBox::SaveAll)) {
393 case QMessageBox::SaveAll:
394 sqpApp->catalogueController().saveAll();
395 break;
396 case QMessageBox::Discard:
397 break;
398 case QMessageBox::Cancel:
399 default:
400 return false;
401 }
402 }
403
404 return true;
405 }
@@ -50,6 +50,7 public:
50 // void trashEvent(std::shared_ptr<DBEvent> event);
50 // void trashEvent(std::shared_ptr<DBEvent> event);
51 // void restore(QUuid eventId);
51 // void restore(QUuid eventId);
52 void saveEvent(std::shared_ptr<DBEvent> event);
52 void saveEvent(std::shared_ptr<DBEvent> event);
53 bool eventHasChanges(std::shared_ptr<DBEvent> event) const;
53
54
54 // Catalogue
55 // Catalogue
55 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
56 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
@@ -61,15 +62,19 public:
61 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
62 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
62
63
63 void saveAll();
64 void saveAll();
65 bool hasChanges() const;
66
67 /// Returns the MIME data associated to a list of variables
68 QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const;
69
70 /// Returns the list of variables contained in a MIME data
71 QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const;
64
72
65 public slots:
73 public slots:
66 /// Manage init/end of the controller
74 /// Manage init/end of the controller
67 void initialize();
75 void initialize();
68 void finalize();
69
76
70 private:
77 private:
71 void waitForFinish();
72
73 class CatalogueControllerPrivate;
78 class CatalogueControllerPrivate;
74 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
79 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
75 };
80 };
@@ -27,6 +27,8 public:
27 static const QString NAME_DATA_KEY;
27 static const QString NAME_DATA_KEY;
28 /// Key associated with the plugin of the item
28 /// Key associated with the plugin of the item
29 static const QString PLUGIN_DATA_KEY;
29 static const QString PLUGIN_DATA_KEY;
30 /// Key associated with a unique id of the plugin
31 static const QString ID_DATA_KEY;
30
32
31 explicit DataSourceItem(DataSourceItemType type, const QString &name);
33 explicit DataSourceItem(DataSourceItemType type, const QString &name);
32 explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {});
34 explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {});
@@ -12,6 +12,7
12 #include <DBTag.h>
12 #include <DBTag.h>
13 #include <IRequestPredicate.h>
13 #include <IRequestPredicate.h>
14
14
15 #include <QDataStream>
15 #include <QMutex>
16 #include <QMutex>
16 #include <QThread>
17 #include <QThread>
17
18
@@ -31,12 +32,15 class CatalogueController::CatalogueControllerPrivate {
31 public:
32 public:
32 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
33 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
33
34
34 QMutex m_WorkingMutex;
35 CatalogueDao m_CatalogueDao;
35 CatalogueDao m_CatalogueDao;
36
36
37 QStringList m_RepositoryList;
37 QStringList m_RepositoryList;
38 CatalogueController *m_Q;
38 CatalogueController *m_Q;
39
39
40 QSet<QString> m_EventKeysWithChanges;
41
42 QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const;
43
40 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
44 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
41 QString toWorkRepository(QString repository);
45 QString toWorkRepository(QString repository);
42 QString toSyncRepository(QString repository);
46 QString toSyncRepository(QString repository);
@@ -57,7 +61,6 CatalogueController::~CatalogueController()
57 {
61 {
58 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
62 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
59 << QThread::currentThread();
63 << QThread::currentThread();
60 this->waitForFinish();
61 }
64 }
62
65
63 QStringList CatalogueController::getRepositories() const
66 QStringList CatalogueController::getRepositories() const
@@ -138,6 +141,9 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
138 {
141 {
139 event->setRepository(impl->toWorkRepository(event->getRepository()));
142 event->setRepository(impl->toWorkRepository(event->getRepository()));
140
143
144 auto uniqueId = impl->eventUniqueKey(event);
145 impl->m_EventKeysWithChanges.insert(uniqueId);
146
141 impl->m_CatalogueDao.updateEvent(*event);
147 impl->m_CatalogueDao.updateEvent(*event);
142 }
148 }
143
149
@@ -153,6 +159,7 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
153 impl->m_CatalogueDao.removeEvent(*event);
159 impl->m_CatalogueDao.removeEvent(*event);
154 event->setRepository(impl->toSyncRepository(event->getRepository()));
160 event->setRepository(impl->toSyncRepository(event->getRepository()));
155 impl->m_CatalogueDao.removeEvent(*event);
161 impl->m_CatalogueDao.removeEvent(*event);
162 impl->savAllDB();
156 }
163 }
157
164
158 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
165 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
@@ -181,6 +188,12 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
181 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
188 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
182 {
189 {
183 impl->saveEvent(event, true);
190 impl->saveEvent(event, true);
191 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
192 }
193
194 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
195 {
196 return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event));
184 }
197 }
185
198
186 std::list<std::shared_ptr<DBCatalogue> >
199 std::list<std::shared_ptr<DBCatalogue> >
@@ -234,13 +247,64 void CatalogueController::saveAll()
234 }
247 }
235
248
236 impl->savAllDB();
249 impl->savAllDB();
250 impl->m_EventKeysWithChanges.clear();
251 }
252
253 bool CatalogueController::hasChanges() const
254 {
255 return !impl->m_EventKeysWithChanges.isEmpty(); // TODO: catalogues
256 }
257
258 QByteArray
259 CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const
260 {
261 auto encodedData = QByteArray{};
262
263 QMap<QString, QVariantList> idsPerRepository;
264 for (auto event : events) {
265 idsPerRepository[event->getRepository()] << event->getUniqId();
266 }
267
268 QDataStream stream{&encodedData, QIODevice::WriteOnly};
269 stream << idsPerRepository;
270
271 return encodedData;
272 }
273
274 QVector<std::shared_ptr<DBEvent> >
275 CatalogueController::eventsForMimeData(const QByteArray &mimeData) const
276 {
277 auto events = QVector<std::shared_ptr<DBEvent> >{};
278 QDataStream stream{mimeData};
279
280 QMap<QString, QVariantList> idsPerRepository;
281 stream >> idsPerRepository;
282
283 for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) {
284 auto repository = it.key();
285 auto allRepositoryEvent = retrieveEvents(repository);
286 for (auto uuid : it.value()) {
287 for (auto repositoryEvent : allRepositoryEvent) {
288 if (uuid.toUuid() == repositoryEvent->getUniqId()) {
289 events << repositoryEvent;
290 }
291 }
292 }
293 }
294
295 return events;
237 }
296 }
238
297
239 void CatalogueController::initialize()
298 void CatalogueController::initialize()
240 {
299 {
300 <<<<<<< HEAD
241 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
301 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
242 << QThread::currentThread();
302 << QThread::currentThread();
243 impl->m_WorkingMutex.lock();
303 impl->m_WorkingMutex.lock();
304 =======
305 qCDebug(LOG_CatalogueController())
306 << tr("CatalogueController init") << QThread::currentThread();
307 >>>>>>> 286decc... unthread the catalogue controller
244 impl->m_CatalogueDao.initialize();
308 impl->m_CatalogueDao.initialize();
245 auto defaultRepositoryLocation
309 auto defaultRepositoryLocation
246 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
310 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
@@ -262,14 +326,10 void CatalogueController::initialize()
262 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
326 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
263 }
327 }
264
328
265 void CatalogueController::finalize()
329 QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey(
266 {
330 const std::shared_ptr<DBEvent> &event) const
267 impl->m_WorkingMutex.unlock();
268 }
269
270 void CatalogueController::waitForFinish()
271 {
331 {
272 QMutexLocker locker{&impl->m_WorkingMutex};
332 return event->getUniqId().toString().append(event->getRepository());
273 }
333 }
274
334
275 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
335 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
@@ -6,6 +6,7
6
6
7 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
7 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
8 const QString DataSourceItem::PLUGIN_DATA_KEY = QStringLiteral("plugin");
8 const QString DataSourceItem::PLUGIN_DATA_KEY = QStringLiteral("plugin");
9 const QString DataSourceItem::ID_DATA_KEY = QStringLiteral("uuid");
9
10
10 struct DataSourceItem::DataSourceItemPrivate {
11 struct DataSourceItem::DataSourceItemPrivate {
11 explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data)
12 explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data)
@@ -3,9 +3,11
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5
5
6 class CatalogueExplorer;
7
6 class CatalogueActionManager {
8 class CatalogueActionManager {
7 public:
9 public:
8 CatalogueActionManager();
10 CatalogueActionManager(CatalogueExplorer *catalogueExplorer);
9
11
10 void installSelectionZoneActions();
12 void installSelectionZoneActions();
11
13
@@ -32,11 +32,18 public:
32
32
33 void setVisualizationWidget(VisualizationWidget *visualization);
33 void setVisualizationWidget(VisualizationWidget *visualization);
34
34
35 void addEvent(const std::shared_ptr<DBEvent> &event);
35 void setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges);
36 void setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges);
36
37
38 QVector<std::shared_ptr<DBCatalogue> > displayedCatalogues() const;
39 bool isAllEventsDisplayed() const;
40 bool isEventDisplayed(const std::shared_ptr<DBEvent> &event) const;
41
37 public slots:
42 public slots:
38 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
43 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
39 void populateWithAllEvents();
44 void populateWithAllEvents();
45 void clear();
46 void refresh();
40
47
41 private:
48 private:
42 Ui::CatalogueEventsWidget *ui;
49 Ui::CatalogueEventsWidget *ui;
@@ -8,6 +8,9 namespace Ui {
8 class CatalogueExplorer;
8 class CatalogueExplorer;
9 }
9 }
10
10
11 class CatalogueEventsWidget;
12 class CatalogueSideBarWidget;
13
11 class VisualizationWidget;
14 class VisualizationWidget;
12
15
13 class CatalogueExplorer : public QDialog {
16 class CatalogueExplorer : public QDialog {
@@ -19,6 +22,9 public:
19
22
20 void setVisualizationWidget(VisualizationWidget *visualization);
23 void setVisualizationWidget(VisualizationWidget *visualization);
21
24
25 CatalogueEventsWidget &eventsWidget() const;
26 CatalogueSideBarWidget &sideBarWidget() const;
27
22 private:
28 private:
23 Ui::CatalogueExplorer *ui;
29 Ui::CatalogueExplorer *ui;
24
30
@@ -28,8 +28,11 public:
28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
29 virtual ~CatalogueSideBarWidget();
29 virtual ~CatalogueSideBarWidget();
30
30
31 void addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue, const QString &repository);
31 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
32 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
32
33
34 QVector<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
35
33 private:
36 private:
34 Ui::CatalogueSideBarWidget *ui;
37 Ui::CatalogueSideBarWidget *ui;
35
38
@@ -15,7 +15,8 class CreateEventDialog : public QDialog {
15 Q_OBJECT
15 Q_OBJECT
16
16
17 public:
17 public:
18 explicit CreateEventDialog(QWidget *parent = 0);
18 explicit CreateEventDialog(const QVector<std::shared_ptr<DBCatalogue> > &catalogues,
19 QWidget *parent = 0);
19 virtual ~CreateEventDialog();
20 virtual ~CreateEventDialog();
20
21
21 void hideCatalogueChoice();
22 void hideCatalogueChoice();
@@ -27,7 +27,8 gui_moc_headers = [
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 ]
32 ]
32
33
33 gui_ui_files = [
34 gui_ui_files = [
@@ -118,11 +119,14 gui_sources = [
118 'src/Catalogue/CatalogueEventsWidget.cpp',
119 'src/Catalogue/CatalogueEventsWidget.cpp',
119 'src/Catalogue/CatalogueSideBarWidget.cpp',
120 'src/Catalogue/CatalogueSideBarWidget.cpp',
120 'src/Catalogue/CatalogueInspectorWidget.cpp',
121 'src/Catalogue/CatalogueInspectorWidget.cpp',
121 'src/Catalogue/CatalogueTreeWidgetItem.cpp',
122 'src/Catalogue/CatalogueTreeItems/CatalogueAbstractTreeItem.cpp',
123 'src/Catalogue/CatalogueTreeItems/CatalogueTreeItem.cpp',
124 'src/Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.cpp',
122 'src/Catalogue/CatalogueEventsModel.cpp',
125 'src/Catalogue/CatalogueEventsModel.cpp',
123 'src/Catalogue/CatalogueExplorerHelper.cpp',
126 'src/Catalogue/CatalogueExplorerHelper.cpp',
124 'src/Catalogue/CatalogueActionManager.cpp',
127 'src/Catalogue/CatalogueActionManager.cpp',
125 'src/Catalogue/CreateEventDialog.cpp'
128 'src/Catalogue/CreateEventDialog.cpp',
129 'src/Catalogue/CatalogueTreeModel.cpp'
126 ]
130 ]
127
131
128 gui_inc = include_directories(['include'])
132 gui_inc = include_directories(['include'])
@@ -2,13 +2,18
2
2
3 #include <Actions/ActionsGuiController.h>
3 #include <Actions/ActionsGuiController.h>
4 #include <Catalogue/CatalogueController.h>
4 #include <Catalogue/CatalogueController.h>
5 #include <DataSource/DataSourceItem.h>
5 #include <SqpApplication.h>
6 #include <SqpApplication.h>
6 #include <Variable/Variable.h>
7 #include <Variable/Variable.h>
7 #include <Visualization/VisualizationGraphWidget.h>
8 #include <Visualization/VisualizationGraphWidget.h>
8 #include <Visualization/VisualizationSelectionZoneItem.h>
9 #include <Visualization/VisualizationSelectionZoneItem.h>
9
10
11 #include <Catalogue/CatalogueEventsWidget.h>
12 #include <Catalogue/CatalogueExplorer.h>
13 #include <Catalogue/CatalogueSideBarWidget.h>
10 #include <Catalogue/CreateEventDialog.h>
14 #include <Catalogue/CreateEventDialog.h>
11
15
16 #include <CatalogueDao.h>
12 #include <DBCatalogue.h>
17 #include <DBCatalogue.h>
13 #include <DBEvent.h>
18 #include <DBEvent.h>
14 #include <DBEventProduct.h>
19 #include <DBEventProduct.h>
@@ -21,6 +26,14
21 #include <memory>
26 #include <memory>
22
27
23 struct CatalogueActionManager::CatalogueActionManagerPrivate {
28 struct CatalogueActionManager::CatalogueActionManagerPrivate {
29
30 CatalogueExplorer *m_CatalogueExplorer = nullptr;
31
32 CatalogueActionManagerPrivate(CatalogueExplorer *catalogueExplorer)
33 : m_CatalogueExplorer(catalogueExplorer)
34 {
35 }
36
24 void createEventFromZones(const QString &eventName,
37 void createEventFromZones(const QString &eventName,
25 const QVector<VisualizationSelectionZoneItem *> &zones,
38 const QVector<VisualizationSelectionZoneItem *> &zones,
26 const std::shared_ptr<DBCatalogue> &catalogue = nullptr)
39 const std::shared_ptr<DBCatalogue> &catalogue = nullptr)
@@ -39,7 +52,8 struct CatalogueActionManager::CatalogueActionManagerPrivate {
39 eventProduct->setTStart(zoneRange.m_TStart);
52 eventProduct->setTStart(zoneRange.m_TStart);
40 eventProduct->setTEnd(zoneRange.m_TEnd);
53 eventProduct->setTEnd(zoneRange.m_TEnd);
41
54
42 eventProduct->setProductId(var->metadata().value("id", "TODO").toString()); // todo
55 eventProduct->setProductId(
56 var->metadata().value(DataSourceItem::ID_DATA_KEY, "UnknownID").toString());
43
57
44 productList.push_back(*eventProduct);
58 productList.push_back(*eventProduct);
45 }
59 }
@@ -49,15 +63,25 struct CatalogueActionManager::CatalogueActionManagerPrivate {
49
63
50 sqpApp->catalogueController().addEvent(event);
64 sqpApp->catalogueController().addEvent(event);
51
65
66
52 if (catalogue) {
67 if (catalogue) {
53 // TODO
68 // TODO
54 // catalogue->addEvent(event);
69 // catalogue->addEvent(event);
70 m_CatalogueExplorer->sideBarWidget().setCatalogueChanges(catalogue, true);
71 if (m_CatalogueExplorer->eventsWidget().displayedCatalogues().contains(catalogue)) {
72 m_CatalogueExplorer->eventsWidget().addEvent(event);
73 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
74 }
75 }
76 else if (m_CatalogueExplorer->eventsWidget().isAllEventsDisplayed()) {
77 m_CatalogueExplorer->eventsWidget().addEvent(event);
78 m_CatalogueExplorer->eventsWidget().setEventChanges(event, true);
55 }
79 }
56 }
80 }
57 };
81 };
58
82
59 CatalogueActionManager::CatalogueActionManager()
83 CatalogueActionManager::CatalogueActionManager(CatalogueExplorer *catalogueExplorer)
60 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>()}
84 : impl{spimpl::make_unique_impl<CatalogueActionManagerPrivate>(catalogueExplorer)}
61 {
85 {
62 }
86 }
63
87
@@ -82,7 +106,8 void CatalogueActionManager::installSelectionZoneActions()
82
106
83 auto createEventAction = actionController.addSectionZoneAction(
107 auto createEventAction = actionController.addSectionZoneAction(
84 {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
108 {QObject::tr("Catalogues")}, QObject::tr("New Event..."), [this](auto zones) {
85 CreateEventDialog dialog;
109 CreateEventDialog dialog(
110 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
86 dialog.hideCatalogueChoice();
111 dialog.hideCatalogueChoice();
87 if (dialog.exec() == QDialog::Accepted) {
112 if (dialog.exec() == QDialog::Accepted) {
88 impl->createEventFromZones(dialog.eventName(), zones);
113 impl->createEventFromZones(dialog.eventName(), zones);
@@ -92,12 +117,16 void CatalogueActionManager::installSelectionZoneActions()
92
117
93 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
118 auto createEventInCatalogueAction = actionController.addSectionZoneAction(
94 {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) {
119 {QObject::tr("Catalogues")}, QObject::tr("New Event in Catalogue..."), [this](auto zones) {
95 CreateEventDialog dialog;
120 CreateEventDialog dialog(
121 impl->m_CatalogueExplorer->sideBarWidget().getCatalogues(REPOSITORY_DEFAULT));
96 if (dialog.exec() == QDialog::Accepted) {
122 if (dialog.exec() == QDialog::Accepted) {
97 auto selectedCatalogue = dialog.selectedCatalogue();
123 auto selectedCatalogue = dialog.selectedCatalogue();
98 if (!selectedCatalogue) {
124 if (!selectedCatalogue) {
99 selectedCatalogue = std::make_shared<DBCatalogue>();
125 selectedCatalogue = std::make_shared<DBCatalogue>();
100 selectedCatalogue->setName(dialog.catalogueName());
126 selectedCatalogue->setName(dialog.catalogueName());
127 // sqpApp->catalogueController().addCatalogue(selectedCatalogue); TODO
128 impl->m_CatalogueExplorer->sideBarWidget().addCatalogue(selectedCatalogue,
129 REPOSITORY_DEFAULT);
101 }
130 }
102
131
103 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
132 impl->createEventFromZones(dialog.eventName(), zones, selectedCatalogue);
@@ -1,5 +1,6
1 #include "Catalogue/CatalogueEventsModel.h"
1 #include "Catalogue/CatalogueEventsModel.h"
2
2
3 #include <Catalogue/CatalogueController.h>
3 #include <Common/DateUtils.h>
4 #include <Common/DateUtils.h>
4 #include <Common/MimeTypesDef.h>
5 #include <Common/MimeTypesDef.h>
5 #include <DBEvent.h>
6 #include <DBEvent.h>
@@ -23,7 +24,6 const auto EVENT_PRODUCT_ITEM_TYPE = 2;
23 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
24 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
24 QVector<std::shared_ptr<DBEvent> > m_Events;
25 QVector<std::shared_ptr<DBEvent> > m_Events;
25 std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts;
26 std::unordered_map<DBEvent *, QVector<std::shared_ptr<DBEventProduct> > > m_EventProducts;
26 std::unordered_set<std::shared_ptr<DBEvent> > m_EventsWithChanges;
27
27
28 QStringList columnNames()
28 QStringList columnNames()
29 {
29 {
@@ -34,8 +34,8 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
34 QVariant sortData(int col, const std::shared_ptr<DBEvent> &event) const
34 QVariant sortData(int col, const std::shared_ptr<DBEvent> &event) const
35 {
35 {
36 if (col == (int)CatalogueEventsModel::Column::Validation) {
36 if (col == (int)CatalogueEventsModel::Column::Validation) {
37 return m_EventsWithChanges.find(event) != m_EventsWithChanges.cend() ? true
37 auto hasChanges = sqpApp->catalogueController().eventHasChanges(event);
38 : QVariant();
38 return hasChanges ? true : QVariant();
39 }
39 }
40
40
41 return eventData(col, event);
41 return eventData(col, event);
@@ -114,6 +114,14 struct CatalogueEventsModel::CatalogueEventsModelPrivate {
114 Q_ASSERT(false);
114 Q_ASSERT(false);
115 return QStringLiteral("Unknown Data");
115 return QStringLiteral("Unknown Data");
116 }
116 }
117
118 void refreshChildrenOfIndex(CatalogueEventsModel *model, const QModelIndex &index) const
119 {
120 auto childCount = model->rowCount(index);
121 auto colCount = model->columnCount();
122 emit model->dataChanged(model->index(0, 0, index),
123 model->index(childCount, colCount, index));
124 }
117 };
125 };
118
126
119 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
127 CatalogueEventsModel::CatalogueEventsModel(QObject *parent)
@@ -127,7 +135,6 void CatalogueEventsModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &e
127
135
128 impl->m_Events = events;
136 impl->m_Events = events;
129 impl->m_EventProducts.clear();
137 impl->m_EventProducts.clear();
130 impl->m_EventsWithChanges.clear();
131 for (auto event : events) {
138 for (auto event : events) {
132 impl->parseEventProduct(event);
139 impl->parseEventProduct(event);
133 }
140 }
@@ -169,10 +176,14 CatalogueEventsModel::getEventProduct(const QModelIndex &index) const
169
176
170 void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event)
177 void CatalogueEventsModel::addEvent(const std::shared_ptr<DBEvent> &event)
171 {
178 {
172 beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1);
179 beginInsertRows(QModelIndex(), impl->m_Events.count(), impl->m_Events.count());
173 impl->m_Events.append(event);
180 impl->m_Events.append(event);
174 impl->parseEventProduct(event);
181 impl->parseEventProduct(event);
175 endInsertRows();
182 endInsertRows();
183
184 // Also refreshes its children event products
185 auto eventIndex = index(impl->m_Events.count(), 0);
186 impl->refreshChildrenOfIndex(this, eventIndex);
176 }
187 }
177
188
178 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
189 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
@@ -182,7 +193,6 void CatalogueEventsModel::removeEvent(const std::shared_ptr<DBEvent> &event)
182 beginRemoveRows(QModelIndex(), index, index);
193 beginRemoveRows(QModelIndex(), index, index);
183 impl->m_Events.removeAt(index);
194 impl->m_Events.removeAt(index);
184 impl->m_EventProducts.erase(event.get());
195 impl->m_EventProducts.erase(event.get());
185 impl->m_EventsWithChanges.erase(event);
186 endRemoveRows();
196 endRemoveRows();
187 }
197 }
188 }
198 }
@@ -202,8 +212,7 void CatalogueEventsModel::refreshEvent(const std::shared_ptr<DBEvent> &event)
202 emit dataChanged(eventIndex, index(eventIndex.row(), colCount));
212 emit dataChanged(eventIndex, index(eventIndex.row(), colCount));
203
213
204 // Also refreshes its children event products
214 // Also refreshes its children event products
205 auto childCount = rowCount(eventIndex);
215 impl->refreshChildrenOfIndex(this, eventIndex);
206 emit dataChanged(index(0, 0, eventIndex), index(childCount, colCount, eventIndex));
207 }
216 }
208 else {
217 else {
209 qCWarning(LOG_CatalogueEventsModel()) << "refreshEvent: event not found.";
218 qCWarning(LOG_CatalogueEventsModel()) << "refreshEvent: event not found.";
@@ -220,22 +229,6 QModelIndex CatalogueEventsModel::indexOf(const std::shared_ptr<DBEvent> &event)
220 return QModelIndex();
229 return QModelIndex();
221 }
230 }
222
231
223 void CatalogueEventsModel::setEventHasChanges(const std::shared_ptr<DBEvent> &event,
224 bool hasChanges)
225 {
226 if (hasChanges) {
227 impl->m_EventsWithChanges.insert(event);
228 }
229 else {
230 impl->m_EventsWithChanges.erase(event);
231 }
232 }
233
234 bool CatalogueEventsModel::eventsHasChanges(const std::shared_ptr<DBEvent> &event) const
235 {
236 return impl->m_EventsWithChanges.find(event) != impl->m_EventsWithChanges.cend();
237 }
238
239 QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const
232 QModelIndex CatalogueEventsModel::index(int row, int column, const QModelIndex &parent) const
240 {
233 {
241 if (!hasIndex(row, column, parent)) {
234 if (!hasIndex(row, column, parent)) {
@@ -354,6 +347,7 QVariant CatalogueEventsModel::headerData(int section, Qt::Orientation orientati
354
347
355 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
348 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
356 {
349 {
350 beginResetModel();
357 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
351 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
358 [this, column, order](auto e1, auto e2) {
352 [this, column, order](auto e1, auto e2) {
359 auto data1 = impl->sortData(column, e1);
353 auto data1 = impl->sortData(column, e1);
@@ -364,13 +358,13 void CatalogueEventsModel::sort(int column, Qt::SortOrder order)
364 return order == Qt::AscendingOrder ? result : !result;
358 return order == Qt::AscendingOrder ? result : !result;
365 });
359 });
366
360
367 emit dataChanged(QModelIndex(), QModelIndex());
361 endResetModel();
368 emit modelSorted();
362 emit modelSorted();
369 }
363 }
370
364
371 Qt::DropActions CatalogueEventsModel::supportedDragActions() const
365 Qt::DropActions CatalogueEventsModel::supportedDragActions() const
372 {
366 {
373 return Qt::CopyAction | Qt::MoveAction;
367 return Qt::CopyAction;
374 }
368 }
375
369
376 QStringList CatalogueEventsModel::mimeTypes() const
370 QStringList CatalogueEventsModel::mimeTypes() const
@@ -415,9 +409,10 QMimeData *CatalogueEventsModel::mimeData(const QModelIndexList &indexes) const
415 }
409 }
416 }
410 }
417
411
418 auto eventsEncodedData
412 if (!eventList.isEmpty() && eventProductList.isEmpty()) {
419 = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO
413 auto eventsEncodedData = sqpApp->catalogueController().mimeDataForEvents(eventList);
420 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
414 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
415 }
421
416
422 if (eventList.count() + eventProductList.count() == 1) {
417 if (eventList.count() + eventProductList.count() == 1) {
423 // No time range MIME data if multiple events are dragged
418 // No time range MIME data if multiple events are dragged
@@ -14,6 +14,7
14 #include <QDialog>
14 #include <QDialog>
15 #include <QDialogButtonBox>
15 #include <QDialogButtonBox>
16 #include <QListWidget>
16 #include <QListWidget>
17 #include <QMessageBox>
17
18
18 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
19 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
19
20
@@ -25,14 +26,22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
25 CatalogueEventsModel *m_Model = nullptr;
26 CatalogueEventsModel *m_Model = nullptr;
26 QStringList m_ZonesForTimeMode;
27 QStringList m_ZonesForTimeMode;
27 QString m_ZoneForGraphMode;
28 QString m_ZoneForGraphMode;
29 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
28
30
29 VisualizationWidget *m_VisualizationWidget = nullptr;
31 VisualizationWidget *m_VisualizationWidget = nullptr;
30
32
31 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
33 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget)
32 {
34 {
33 treeView->setSortingEnabled(false);
35 widget->ui->treeView->setSortingEnabled(false);
34 m_Model->setEvents(events);
36 m_Model->setEvents(events);
35 treeView->setSortingEnabled(true);
37 widget->ui->treeView->setSortingEnabled(true);
38
39 for (auto event : events) {
40 if (sqpApp->catalogueController().eventHasChanges(event)) {
41 auto index = m_Model->indexOf(event);
42 widget->setEventChanges(event, true);
43 }
44 }
36 }
45 }
37
46
38 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
47 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
@@ -195,6 +204,22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
195 << "updateGraphMode: not compatible with multiple events selected";
204 << "updateGraphMode: not compatible with multiple events selected";
196 }
205 }
197 }
206 }
207
208 void getSelectedItems(
209 QTreeView *treeView, QVector<std::shared_ptr<DBEvent> > &events,
210 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > &eventProducts)
211 {
212 for (auto rowIndex : treeView->selectionModel()->selectedRows()) {
213 auto itemType = m_Model->itemTypeOf(rowIndex);
214 if (itemType == CatalogueEventsModel::ItemType::Event) {
215 events << m_Model->getEvent(rowIndex);
216 }
217 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
218 eventProducts << qMakePair(m_Model->getParentEvent(rowIndex),
219 m_Model->getEventProduct(rowIndex));
220 }
221 }
222 }
198 };
223 };
199
224
200 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
225 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
@@ -234,21 +259,31 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
234 }
259 }
235 });
260 });
236
261
237 auto emitSelection = [this]() {
262 connect(ui->btnRemove, &QToolButton::clicked, [this]() {
238 QVector<std::shared_ptr<DBEvent> > events;
263 QVector<std::shared_ptr<DBEvent> > events;
239 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
264 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
265 impl->getSelectedItems(ui->treeView, events, eventProducts);
240
266
241 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
267 if (!events.isEmpty() && eventProducts.isEmpty()) {
242
268
243 auto itemType = impl->m_Model->itemTypeOf(rowIndex);
269 if (QMessageBox::warning(this, tr("Remove Event(s)"),
244 if (itemType == CatalogueEventsModel::ItemType::Event) {
270 tr("The selected event(s) will be completly removed "
245 events << impl->m_Model->getEvent(rowIndex);
271 "from the repository!\nAre you sure you want to continue?"),
272 QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
273 == QMessageBox::Yes) {
274
275 for (auto event : events) {
276 sqpApp->catalogueController().removeEvent(event);
277 impl->removeEvent(event, ui->treeView);
246 }
278 }
247 else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
248 eventProducts << qMakePair(impl->m_Model->getParentEvent(rowIndex),
249 impl->m_Model->getEventProduct(rowIndex));
250 }
279 }
251 }
280 }
281 });
282
283 auto emitSelection = [this]() {
284 QVector<std::shared_ptr<DBEvent> > events;
285 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
286 impl->getSelectedItems(ui->treeView, events, eventProducts);
252
287
253 if (!events.isEmpty() && eventProducts.isEmpty()) {
288 if (!events.isEmpty() && eventProducts.isEmpty()) {
254 emit this->eventsSelected(events);
289 emit this->eventsSelected(events);
@@ -264,6 +299,7 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
264 connect(ui->treeView, &QTreeView::clicked, emitSelection);
299 connect(ui->treeView, &QTreeView::clicked, emitSelection);
265 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
300 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
266
301
302 ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected
267 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
303 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
268 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
304 auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
269 ui->btnChart->setEnabled(isNotMultiSelection);
305 ui->btnChart->setEnabled(isNotMultiSelection);
@@ -275,13 +311,20 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
275 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
311 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
276 impl->updateForGraphMode(ui->treeView);
312 impl->updateForGraphMode(ui->treeView);
277 }
313 }
314
315 QVector<std::shared_ptr<DBEvent> > events;
316 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
317 impl->getSelectedItems(ui->treeView, events, eventProducts);
318 ui->btnRemove->setEnabled(!events.isEmpty() && eventProducts.isEmpty());
278 });
319 });
279
320
280 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
321 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
281 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
322 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Tags,
282 QHeaderView::Stretch);
323 QHeaderView::Stretch);
283 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
324 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
284 QHeaderView::Fixed);
325 QHeaderView::Fixed);
326 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
327 QHeaderView::Interactive);
285 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
328 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
286 VALIDATION_COLUMN_SIZE);
329 VALIDATION_COLUMN_SIZE);
287 ui->treeView->header()->setSortIndicatorShown(true);
330 ui->treeView->header()->setSortIndicatorShown(true);
@@ -289,9 +332,11 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
289 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
332 connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
290 auto allEvents = impl->m_Model->events();
333 auto allEvents = impl->m_Model->events();
291 for (auto event : allEvents) {
334 for (auto event : allEvents) {
292 setEventChanges(event, impl->m_Model->eventsHasChanges(event));
335 setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event));
293 }
336 }
294 });
337 });
338
339 populateWithAllEvents();
295 }
340 }
296
341
297 CatalogueEventsWidget::~CatalogueEventsWidget()
342 CatalogueEventsWidget::~CatalogueEventsWidget()
@@ -304,6 +349,11 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualiz
304 impl->m_VisualizationWidget = visualization;
349 impl->m_VisualizationWidget = visualization;
305 }
350 }
306
351
352 void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event)
353 {
354 impl->addEvent(event, ui->treeView);
355 }
356
307 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
357 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
308 {
358 {
309 impl->m_Model->refreshEvent(event);
359 impl->m_Model->refreshEvent(event);
@@ -312,6 +362,7 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &even
312 auto validationIndex
362 auto validationIndex
313 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
363 = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
314
364
365 if (validationIndex.isValid()) {
315 if (hasChanges) {
366 if (hasChanges) {
316 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
367 if (ui->treeView->indexWidget(validationIndex) == nullptr) {
317 auto widget = CatalogueExplorerHelper::buildValidationWidget(
368 auto widget = CatalogueExplorerHelper::buildValidationWidget(
@@ -328,13 +379,33 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &even
328 // Note: the widget is destroyed
379 // Note: the widget is destroyed
329 ui->treeView->setIndexWidget(validationIndex, nullptr);
380 ui->treeView->setIndexWidget(validationIndex, nullptr);
330 }
381 }
382 }
383 else {
384 qCWarning(LOG_CatalogueEventsWidget())
385 << "setEventChanges: the event is not displayed in the model.";
386 }
387 }
331
388
332 impl->m_Model->setEventHasChanges(event, hasChanges);
389 QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const
390 {
391 return impl->m_DisplayedCatalogues;
392 }
393
394 bool CatalogueEventsWidget::isAllEventsDisplayed() const
395 {
396 return impl->m_DisplayedCatalogues.isEmpty() && !impl->m_Model->events().isEmpty();
397 }
398
399 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const
400 {
401 return impl->m_Model->indexOf(event).isValid();
333 }
402 }
334
403
335 void CatalogueEventsWidget::populateWithCatalogues(
404 void CatalogueEventsWidget::populateWithCatalogues(
336 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
405 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
337 {
406 {
407 impl->m_DisplayedCatalogues = catalogues;
408
338 QSet<QUuid> eventIds;
409 QSet<QUuid> eventIds;
339 QVector<std::shared_ptr<DBEvent> > events;
410 QVector<std::shared_ptr<DBEvent> > events;
340
411
@@ -348,11 +419,13 void CatalogueEventsWidget::populateWithCatalogues(
348 }
419 }
349 }
420 }
350
421
351 impl->setEvents(events, ui->treeView);
422 impl->setEvents(events, this);
352 }
423 }
353
424
354 void CatalogueEventsWidget::populateWithAllEvents()
425 void CatalogueEventsWidget::populateWithAllEvents()
355 {
426 {
427 impl->m_DisplayedCatalogues.clear();
428
356 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
429 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
357
430
358 QVector<std::shared_ptr<DBEvent> > events;
431 QVector<std::shared_ptr<DBEvent> > events;
@@ -360,5 +433,21 void CatalogueEventsWidget::populateWithAllEvents()
360 events << event;
433 events << event;
361 }
434 }
362
435
363 impl->setEvents(events, ui->treeView);
436 impl->setEvents(events, this);
437 }
438
439 void CatalogueEventsWidget::clear()
440 {
441 impl->m_DisplayedCatalogues.clear();
442 impl->setEvents({}, this);
443 }
444
445 void CatalogueEventsWidget::refresh()
446 {
447 if (impl->m_DisplayedCatalogues.isEmpty()) {
448 populateWithAllEvents();
449 }
450 else {
451 populateWithCatalogues(impl->m_DisplayedCatalogues);
452 }
364 }
453 }
@@ -11,12 +11,17
11
11
12 struct CatalogueExplorer::CatalogueExplorerPrivate {
12 struct CatalogueExplorer::CatalogueExplorerPrivate {
13 CatalogueActionManager m_ActionManager;
13 CatalogueActionManager m_ActionManager;
14
15 CatalogueExplorerPrivate(CatalogueExplorer *catalogueExplorer)
16 : m_ActionManager(catalogueExplorer)
17 {
18 }
14 };
19 };
15
20
16 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
21 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
17 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
22 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
18 ui(new Ui::CatalogueExplorer),
23 ui(new Ui::CatalogueExplorer),
19 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>()}
24 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>(this)}
20 {
25 {
21 ui->setupUi(this);
26 ui->setupUi(this);
22
27
@@ -37,16 +42,29 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
37 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
42 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
38 });
43 });
39
44
40 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected,
45 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected, [this]() {
41 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
46 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
47 ui->events->clear();
48 });
42
49
43 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() {
50 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected, [this]() {
44 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
51 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
45 ui->events->populateWithAllEvents();
52 ui->events->populateWithAllEvents();
46 });
53 });
47
54
48 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared,
55 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databaseList) {
49 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
56 QVector<std::shared_ptr<DBCatalogue> > catalogueList;
57 for (auto database : databaseList) {
58 catalogueList.append(ui->catalogues->getCatalogues(database));
59 }
60 ui->events->populateWithCatalogues(catalogueList);
61 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
62 });
63
64 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared, [this]() {
65 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
66 ui->events->clear();
67 });
50
68
51 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
69 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
52 if (events.count() == 1) {
70 if (events.count() == 1) {
@@ -96,3 +114,13 void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualizatio
96 {
114 {
97 ui->events->setVisualizationWidget(visualization);
115 ui->events->setVisualizationWidget(visualization);
98 }
116 }
117
118 CatalogueEventsWidget &CatalogueExplorer::eventsWidget() const
119 {
120 return *ui->events;
121 }
122
123 CatalogueSideBarWidget &CatalogueExplorer::sideBarWidget() const
124 {
125 return *ui->catalogues;
126 }
@@ -182,7 +182,7 void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &e
182 showPage(Page::EventProperties);
182 showPage(Page::EventProperties);
183 ui->leEventName->setEnabled(false);
183 ui->leEventName->setEnabled(false);
184 ui->leEventName->setText(event->getName());
184 ui->leEventName->setText(event->getName());
185 ui->leEventProduct->setEnabled(true);
185 ui->leEventProduct->setEnabled(false);
186 ui->leEventProduct->setText(eventProduct->getProductId());
186 ui->leEventProduct->setText(eventProduct->getProductId());
187
187
188 ui->leEventTags->setEnabled(false);
188 ui->leEventTags->setEnabled(false);
@@ -3,7 +3,10
3 #include <SqpApplication.h>
3 #include <SqpApplication.h>
4
4
5 #include <Catalogue/CatalogueController.h>
5 #include <Catalogue/CatalogueController.h>
6 #include <Catalogue/CatalogueTreeWidgetItem.h>
6 #include <Catalogue/CatalogueExplorerHelper.h>
7 #include <Catalogue/CatalogueTreeItems/CatalogueTextTreeItem.h>
8 #include <Catalogue/CatalogueTreeItems/CatalogueTreeItem.h>
9 #include <Catalogue/CatalogueTreeModel.h>
7 #include <CatalogueDao.h>
10 #include <CatalogueDao.h>
8 #include <ComparaisonPredicate.h>
11 #include <ComparaisonPredicate.h>
9 #include <DBCatalogue.h>
12 #include <DBCatalogue.h>
@@ -13,22 +16,81
13 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
16 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
14
17
15
18
16 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
19 constexpr auto ALL_EVENT_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 1;
17 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
20 constexpr auto TRASH_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 2;
18 constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2;
21 constexpr auto CATALOGUE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 3;
19 constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3;
22 constexpr auto DATABASE_ITEM_TYPE = CatalogueAbstractTreeItem::DEFAULT_TYPE + 4;
20
23
21
24
22 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
25 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
23
26
24 void configureTreeWidget(QTreeWidget *treeWidget);
27 CatalogueTreeModel *m_TreeModel = nullptr;
25 QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget);
28
26 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
29 void configureTreeWidget(QTreeView *treeView);
30 QModelIndex addDatabaseItem(const QString &name);
31 CatalogueAbstractTreeItem *getDatabaseItem(const QString &name);
27 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
32 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
28 QTreeWidgetItem *parentDatabaseItem);
33 const QModelIndex &databaseIndex);
34
35 CatalogueTreeItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue) const;
36 void setHasChanges(bool value, const QModelIndex &index, QTreeView *treeView);
37 bool hasChanges(const QModelIndex &index, QTreeView *treeView);
38
39 int selectionType(QTreeView *treeView) const
40 {
41 auto selectedItems = treeView->selectionModel()->selectedRows();
42 if (selectedItems.isEmpty()) {
43 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
44 }
45 else {
46 auto firstIndex = selectedItems.first();
47 auto firstItem = m_TreeModel->item(firstIndex);
48 if (!firstItem) {
49 Q_ASSERT(false);
50 return CatalogueAbstractTreeItem::DEFAULT_TYPE;
51 }
52 auto selectionType = firstItem->type();
53
54 for (auto itemIndex : selectedItems) {
55 auto item = m_TreeModel->item(itemIndex);
56 if (!item || item->type() != selectionType) {
57 // Incoherent multi selection
58 selectionType = CatalogueAbstractTreeItem::DEFAULT_TYPE;
59 break;
60 }
61 }
62
63 return selectionType;
64 }
65 }
66
67 QVector<std::shared_ptr<DBCatalogue> > selectedCatalogues(QTreeView *treeView) const
68 {
69 QVector<std::shared_ptr<DBCatalogue> > catalogues;
70 auto selectedItems = treeView->selectionModel()->selectedRows();
71 for (auto itemIndex : selectedItems) {
72 auto item = m_TreeModel->item(itemIndex);
73 if (item && item->type() == CATALOGUE_ITEM_TYPE) {
74 catalogues.append(static_cast<CatalogueTreeItem *>(item)->catalogue());
75 }
76 }
77
78 return catalogues;
79 }
80
81 QStringList selectedRepositories(QTreeView *treeView) const
82 {
83 QStringList repositories;
84 auto selectedItems = treeView->selectionModel()->selectedRows();
85 for (auto itemIndex : selectedItems) {
86 auto item = m_TreeModel->item(itemIndex);
87 if (item && item->type() == DATABASE_ITEM_TYPE) {
88 repositories.append(item->text());
89 }
90 }
29
91
30 CatalogueTreeWidgetItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
92 return repositories;
31 QTreeWidget *treeWidget) const;
93 }
32 };
94 };
33
95
34 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
96 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
@@ -37,53 +99,26 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
37 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
99 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
38 {
100 {
39 ui->setupUi(this);
101 ui->setupUi(this);
40 impl->configureTreeWidget(ui->treeWidget);
41
102
42 ui->treeWidget->setColumnCount(2);
103 impl->m_TreeModel = new CatalogueTreeModel(this);
43 ui->treeWidget->header()->setStretchLastSection(false);
104 ui->treeView->setModel(impl->m_TreeModel);
44 ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
45 ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
46
105
47 auto emitSelection = [this]() {
106 impl->configureTreeWidget(ui->treeView);
48
107
49 auto selectedItems = ui->treeWidget->selectedItems();
108 ui->treeView->header()->setStretchLastSection(false);
50 if (selectedItems.isEmpty()) {
109 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
51 emit this->selectionCleared();
110 ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
52 }
53 else {
54 QVector<std::shared_ptr<DBCatalogue> > catalogues;
55 QStringList databases;
56 int selectionType = selectedItems.first()->type();
57
111
58 for (auto item : ui->treeWidget->selectedItems()) {
112 auto emitSelection = [this]() {
59 if (item->type() == selectionType) {
113
60 switch (selectionType) {
114 auto selectionType = impl->selectionType(ui->treeView);
61 case CATALOGUE_ITEM_TYPE:
62 catalogues.append(
63 static_cast<CatalogueTreeWidgetItem *>(item)->catalogue());
64 break;
65 case DATABASE_ITEM_TYPE:
66 selectionType = DATABASE_ITEM_TYPE;
67 databases.append(item->text(0));
68 case ALL_EVENT_ITEM_TYPE: // fallthrough
69 case TRASH_ITEM_TYPE: // fallthrough
70 default:
71 break;
72 }
73 }
74 else {
75 // Incoherent multi selection
76 selectionType = -1;
77 break;
78 }
79 }
80
115
81 switch (selectionType) {
116 switch (selectionType) {
82 case CATALOGUE_ITEM_TYPE:
117 case CATALOGUE_ITEM_TYPE:
83 emit this->catalogueSelected(catalogues);
118 emit this->catalogueSelected(impl->selectedCatalogues(ui->treeView));
84 break;
119 break;
85 case DATABASE_ITEM_TYPE:
120 case DATABASE_ITEM_TYPE:
86 emit this->databaseSelected(databases);
121 emit this->databaseSelected(impl->selectedRepositories(ui->treeView));
87 break;
122 break;
88 case ALL_EVENT_ITEM_TYPE:
123 case ALL_EVENT_ITEM_TYPE:
89 emit this->allEventsSelected();
124 emit this->allEventsSelected();
@@ -95,24 +130,22 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
95 emit this->selectionCleared();
130 emit this->selectionCleared();
96 break;
131 break;
97 }
132 }
98 }
99
100
101 };
133 };
102
134
103 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
135 connect(ui->treeView, &QTreeView::clicked, emitSelection);
104 connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection);
136 connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, emitSelection);
105 connect(ui->treeWidget, &QTreeWidget::itemChanged,
137 connect(impl->m_TreeModel, &CatalogueTreeModel::itemRenamed, [emitSelection, this](auto index) {
106 [emitSelection, this](auto item, auto column) {
138 auto selectedIndexes = ui->treeView->selectionModel()->selectedRows();
107 auto selectedItems = ui->treeWidget->selectedItems();
139 if (selectedIndexes.contains(index)) {
108 qDebug() << "ITEM CHANGED" << column;
109 if (selectedItems.contains(item) && column == 0) {
110 emitSelection();
140 emitSelection();
111 }
141 }
142
143 auto item = impl->m_TreeModel->item(index);
144 impl->setHasChanges(true, index, ui->treeView);
112 });
145 });
113
146
114 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
147 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
115 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
148 connect(ui->treeView, &QTreeView::customContextMenuRequested, this,
116 &CatalogueSideBarWidget::onContextMenuRequested);
149 &CatalogueSideBarWidget::onContextMenuRequested);
117 }
150 }
118
151
@@ -121,24 +154,54 CatalogueSideBarWidget::~CatalogueSideBarWidget()
121 delete ui;
154 delete ui;
122 }
155 }
123
156
157 void CatalogueSideBarWidget::addCatalogue(const std::shared_ptr<DBCatalogue> &catalogue,
158 const QString &repository)
159 {
160 auto repositoryItem = impl->getDatabaseItem(repository);
161 impl->addCatalogueItem(catalogue, impl->m_TreeModel->indexOf(repositoryItem));
162 }
163
124 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
164 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
125 bool hasChanges)
165 bool hasChanges)
126 {
166 {
127 if (auto catalogueItem = impl->getCatalogueItem(catalogue, ui->treeWidget)) {
167 if (auto catalogueItem = impl->getCatalogueItem(catalogue)) {
128 catalogueItem->setHasChanges(hasChanges);
168 auto index = impl->m_TreeModel->indexOf(catalogueItem);
129 catalogueItem->refresh();
169 impl->setHasChanges(hasChanges, index, ui->treeView);
170 // catalogueItem->refresh();
130 }
171 }
131 }
172 }
132
173
174 QVector<std::shared_ptr<DBCatalogue> >
175 CatalogueSideBarWidget::getCatalogues(const QString &repository) const
176 {
177 QVector<std::shared_ptr<DBCatalogue> > result;
178 auto repositoryItem = impl->getDatabaseItem(repository);
179 for (auto child : repositoryItem->children()) {
180 if (child->type() == CATALOGUE_ITEM_TYPE) {
181 auto catalogueItem = static_cast<CatalogueTreeItem *>(child);
182 result << catalogueItem->catalogue();
183 }
184 else {
185 qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogues: invalid structure";
186 }
187 }
188
189 return result;
190 }
191
133 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
192 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
134 {
193 {
135 QMenu menu{this};
194 QMenu menu{this};
136
195
137 auto currentItem = ui->treeWidget->currentItem();
196 auto currentIndex = ui->treeView->currentIndex();
197 auto currentItem = impl->m_TreeModel->item(currentIndex);
198 if (!currentItem) {
199 return;
200 }
201
138 switch (currentItem->type()) {
202 switch (currentItem->type()) {
139 case CATALOGUE_ITEM_TYPE:
203 case CATALOGUE_ITEM_TYPE:
140 menu.addAction("Rename",
204 menu.addAction("Rename", [this, currentIndex]() { ui->treeView->edit(currentIndex); });
141 [this, currentItem]() { ui->treeWidget->editItem(currentItem); });
142 break;
205 break;
143 case DATABASE_ITEM_TYPE:
206 case DATABASE_ITEM_TYPE:
144 break;
207 break;
@@ -154,59 +217,56 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
154 }
217 }
155
218
156 if (!menu.isEmpty()) {
219 if (!menu.isEmpty()) {
157 menu.exec(ui->treeWidget->mapToGlobal(pos));
220 menu.exec(ui->treeView->mapToGlobal(pos));
158 }
221 }
159 }
222 }
160
223
161 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(
224 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(QTreeView *treeView)
162 QTreeWidget *treeWidget)
163 {
225 {
164 auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE};
226 auto allEventsItem = new CatalogueTextTreeItem{QIcon{":/icones/allEvents.png"}, "All Events",
165 allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png"));
227 ALL_EVENT_ITEM_TYPE};
166 treeWidget->addTopLevelItem(allEventsItem);
228 auto allEventIndex = m_TreeModel->addTopLevelItem(allEventsItem);
229 treeView->setCurrentIndex(allEventIndex);
167
230
168 auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE};
231 auto trashItem
169 trashItem->setIcon(0, QIcon(":/icones/trash.png"));
232 = new CatalogueTextTreeItem{QIcon{":/icones/trash.png"}, "Trash", TRASH_ITEM_TYPE};
170 treeWidget->addTopLevelItem(trashItem);
233 m_TreeModel->addTopLevelItem(trashItem);
171
234
172 auto separator = new QFrame{treeWidget};
235 auto separator = new QFrame{treeView};
173 separator->setFrameShape(QFrame::HLine);
236 separator->setFrameShape(QFrame::HLine);
174 auto separatorItem = new QTreeWidgetItem{};
237 auto separatorItem
175 separatorItem->setFlags(Qt::NoItemFlags);
238 = new CatalogueTextTreeItem{QIcon{}, QString{}, CatalogueAbstractTreeItem::DEFAULT_TYPE};
176 treeWidget->addTopLevelItem(separatorItem);
239 separatorItem->setEnabled(false);
177 treeWidget->setItemWidget(separatorItem, 0, separator);
240 auto separatorIndex = m_TreeModel->addTopLevelItem(separatorItem);
241 treeView->setIndexWidget(separatorIndex, separator);
178
242
179 auto repositories = sqpApp->catalogueController().getRepositories();
243 auto repositories = sqpApp->catalogueController().getRepositories();
180 for (auto dbname : repositories) {
244 for (auto dbname : repositories) {
181 auto db = addDatabaseItem(dbname, treeWidget);
245 auto dbIndex = addDatabaseItem(dbname);
182
183 auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname);
246 auto catalogues = sqpApp->catalogueController().retrieveCatalogues(dbname);
184 for (auto catalogue : catalogues) {
247 for (auto catalogue : catalogues) {
185 addCatalogueItem(catalogue, db);
248 addCatalogueItem(catalogue, dbIndex);
186 }
249 }
187 }
250 }
188
251
189 treeWidget->expandAll();
252 treeView->expandAll();
190 }
253 }
191
254
192 QTreeWidgetItem *
255 QModelIndex
193 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name,
256 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name)
194 QTreeWidget *treeWidget)
195 {
257 {
196 auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE};
258 auto databaseItem
197 databaseItem->setIcon(0, QIcon{":/icones/database.png"});
259 = new CatalogueTextTreeItem{QIcon{":/icones/database.png"}, {name}, DATABASE_ITEM_TYPE};
198 treeWidget->addTopLevelItem(databaseItem);
260 auto databaseIndex = m_TreeModel->addTopLevelItem(databaseItem);
199
261
200 return databaseItem;
262 return databaseIndex;
201 }
263 }
202
264
203 QTreeWidgetItem *
265 CatalogueAbstractTreeItem *
204 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name,
266 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name)
205 QTreeWidget *treeWidget)
206 {
267 {
207 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
268 for (auto item : m_TreeModel->topLevelItems()) {
208 auto item = treeWidget->topLevelItem(i);
269 if (item->type() == DATABASE_ITEM_TYPE && item->text() == name) {
209 if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) {
210 return item;
270 return item;
211 }
271 }
212 }
272 }
@@ -215,23 +275,21 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QSt
215 }
275 }
216
276
217 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
277 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
218 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidgetItem *parentDatabaseItem)
278 const std::shared_ptr<DBCatalogue> &catalogue, const QModelIndex &databaseIndex)
219 {
279 {
220 auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE};
280 auto catalogueItem
221 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
281 = new CatalogueTreeItem{catalogue, QIcon{":/icones/catalogue.png"}, CATALOGUE_ITEM_TYPE};
222 parentDatabaseItem->addChild(catalogueItem);
282 m_TreeModel->addChildItem(catalogueItem, databaseIndex);
223 }
283 }
224
284
225 CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
285 CatalogueTreeItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
226 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidget *treeWidget) const
286 const std::shared_ptr<DBCatalogue> &catalogue) const
227 {
287 {
228 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
288 for (auto item : m_TreeModel->topLevelItems()) {
229 auto item = treeWidget->topLevelItem(i);
230 if (item->type() == DATABASE_ITEM_TYPE) {
289 if (item->type() == DATABASE_ITEM_TYPE) {
231 for (auto j = 0; j < item->childCount(); ++j) {
290 for (auto childItem : item->children()) {
232 auto childItem = item->child(j);
233 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
291 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
234 auto catalogueItem = static_cast<CatalogueTreeWidgetItem *>(childItem);
292 auto catalogueItem = static_cast<CatalogueTreeItem *>(childItem);
235 if (catalogueItem->catalogue() == catalogue) {
293 if (catalogueItem->catalogue() == catalogue) {
236 return catalogueItem;
294 return catalogueItem;
237 }
295 }
@@ -248,3 +306,34 CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::
248
306
249 return nullptr;
307 return nullptr;
250 }
308 }
309
310 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::setHasChanges(bool value,
311 const QModelIndex &index,
312 QTreeView *treeView)
313 {
314 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
315 if (value) {
316 if (!hasChanges(validationIndex, treeView)) {
317 auto widget = CatalogueExplorerHelper::buildValidationWidget(
318 treeView,
319 [this, validationIndex, treeView]() {
320 setHasChanges(false, validationIndex, treeView);
321 },
322 [this, validationIndex, treeView]() {
323 setHasChanges(false, validationIndex, treeView);
324 });
325 treeView->setIndexWidget(validationIndex, widget);
326 }
327 }
328 else {
329 // Note: the widget is destroyed
330 treeView->setIndexWidget(validationIndex, nullptr);
331 }
332 }
333
334 bool CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::hasChanges(const QModelIndex &index,
335 QTreeView *treeView)
336 {
337 auto validationIndex = index.sibling(index.row(), (int)CatalogueTreeModel::Column::Validation);
338 return treeView->indexWidget(validationIndex) != nullptr;
339 }
@@ -1,91 +1,95
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);
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);
54 setHasChanges(true);
59 result = true;
55 }
56 }
57 else {
58 QTreeWidgetItem::setData(column, role, value);
59 }
60 }
60 }
61 }
61
62
62 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
63 return result;
63 {
64 return impl->m_Catalogue;
65 }
64 }
66
65
67 void CatalogueTreeWidgetItem::setHasChanges(bool value)
66 Qt::ItemFlags CatalogueTreeItem::flags(int column) const
68 {
67 {
69 if (value) {
68 if (column == 0) {
70 if (!hasChanges()) {
69 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable
71 auto widget = CatalogueExplorerHelper::buildValidationWidget(
70 | Qt::ItemIsDropEnabled;
72 treeWidget(), [this]() { setHasChanges(false); },
73 [this]() { setHasChanges(false); });
74 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, widget);
75 }
76 }
71 }
77 else {
72 else {
78 // Note: the widget is destroyed
73 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
79 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr);
80 }
74 }
81 }
75 }
82
76
83 bool CatalogueTreeWidgetItem::hasChanges()
77 bool CatalogueTreeItem::canDropMimeData(const QMimeData *data, Qt::DropAction action)
84 {
78 {
85 return treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) != nullptr;
79 return data->hasFormat(MIME_TYPE_EVENT_LIST);
86 }
80 }
87
81
88 void CatalogueTreeWidgetItem::refresh()
82 bool CatalogueTreeItem::dropMimeData(const QMimeData *data, Qt::DropAction action)
89 {
83 {
90 emitDataChanged();
84 Q_ASSERT(canDropMimeData(data, action));
85
86 auto events = sqpApp->catalogueController().eventsForMimeData(data->data(MIME_TYPE_EVENT_LIST));
87 // impl->m_Catalogue->addEvents(events); TODO: move events in the new catalogue
88 // Warning: Check that the events aren't already in the catalogue
89 // Also check for the repository !!!
90 }
91
92 std::shared_ptr<DBCatalogue> CatalogueTreeItem::catalogue() const
93 {
94 return impl->m_Catalogue;
91 }
95 }
@@ -10,7 +10,8 struct CreateEventDialog::CreateEventDialogPrivate {
10 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
10 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
11 };
11 };
12
12
13 CreateEventDialog::CreateEventDialog(QWidget *parent)
13 CreateEventDialog::CreateEventDialog(const QVector<std::shared_ptr<DBCatalogue> > &catalogues,
14 QWidget *parent)
14 : QDialog(parent),
15 : QDialog(parent),
15 ui(new Ui::CreateEventDialog),
16 ui(new Ui::CreateEventDialog),
16 impl{spimpl::make_unique_impl<CreateEventDialogPrivate>()}
17 impl{spimpl::make_unique_impl<CreateEventDialogPrivate>()}
@@ -20,10 +21,9 CreateEventDialog::CreateEventDialog(QWidget *parent)
20 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
21 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
21 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
22 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
22
23
23 auto catalogues = sqpApp->catalogueController().retrieveCatalogues();
24 impl->m_DisplayedCatalogues = catalogues;
24 for (auto cat : catalogues) {
25 for (auto cat : impl->m_DisplayedCatalogues) {
25 ui->cbCatalogue->addItem(cat->getName());
26 ui->cbCatalogue->addItem(cat->getName());
26 impl->m_DisplayedCatalogues << cat;
27 }
27 }
28 }
28 }
29
29
@@ -64,9 +64,6 public:
64 m_VariableControllerThread.setObjectName("VariableControllerThread");
64 m_VariableControllerThread.setObjectName("VariableControllerThread");
65 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
65 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
66 m_VisualizationControllerThread.setObjectName("VsualizationControllerThread");
66 m_VisualizationControllerThread.setObjectName("VsualizationControllerThread");
67 m_CatalogueController->moveToThread(&m_CatalogueControllerThread);
68 m_CatalogueControllerThread.setObjectName("CatalogueControllerThread");
69
70
67
71 // Additionnal init
68 // Additionnal init
72 m_VariableController->setTimeController(m_TimeController.get());
69 m_VariableController->setTimeController(m_TimeController.get());
@@ -85,9 +82,6 public:
85
82
86 m_VisualizationControllerThread.quit();
83 m_VisualizationControllerThread.quit();
87 m_VisualizationControllerThread.wait();
84 m_VisualizationControllerThread.wait();
88
89 m_CatalogueControllerThread.quit();
90 m_CatalogueControllerThread.wait();
91 }
85 }
92
86
93 std::unique_ptr<DataSourceController> m_DataSourceController;
87 std::unique_ptr<DataSourceController> m_DataSourceController;
@@ -101,7 +95,6 public:
101 QThread m_NetworkControllerThread;
95 QThread m_NetworkControllerThread;
102 QThread m_VariableControllerThread;
96 QThread m_VariableControllerThread;
103 QThread m_VisualizationControllerThread;
97 QThread m_VisualizationControllerThread;
104 QThread m_CatalogueControllerThread;
105
98
106 std::unique_ptr<DragDropGuiController> m_DragDropGuiController;
99 std::unique_ptr<DragDropGuiController> m_DragDropGuiController;
107 std::unique_ptr<ActionsGuiController> m_ActionsGuiController;
100 std::unique_ptr<ActionsGuiController> m_ActionsGuiController;
@@ -136,16 +129,11 SqpApplication::SqpApplication(int &argc, char **argv)
136 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
129 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
137 impl->m_VisualizationController.get(), &VisualizationController::finalize);
130 impl->m_VisualizationController.get(), &VisualizationController::finalize);
138
131
139 connect(&impl->m_CatalogueControllerThread, &QThread::started,
140 impl->m_CatalogueController.get(), &CatalogueController::initialize);
141 connect(&impl->m_CatalogueControllerThread, &QThread::finished,
142 impl->m_CatalogueController.get(), &CatalogueController::finalize);
143
144 impl->m_DataSourceControllerThread.start();
132 impl->m_DataSourceControllerThread.start();
145 impl->m_NetworkControllerThread.start();
133 impl->m_NetworkControllerThread.start();
146 impl->m_VariableControllerThread.start();
134 impl->m_VariableControllerThread.start();
147 impl->m_VisualizationControllerThread.start();
135 impl->m_VisualizationControllerThread.start();
148 impl->m_CatalogueControllerThread.start();
136 impl->m_CatalogueController->initialize();
149 }
137 }
150
138
151 SqpApplication::~SqpApplication()
139 SqpApplication::~SqpApplication()
@@ -30,6 +30,9
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="enabled">
34 <bool>false</bool>
35 </property>
33 <property name="text">
36 <property name="text">
34 <string>+</string>
37 <string>+</string>
35 </property>
38 </property>
@@ -82,6 +85,9
82 </item>
85 </item>
83 <item>
86 <item>
84 <widget class="QToolButton" name="btnChart">
87 <widget class="QToolButton" name="btnChart">
88 <property name="enabled">
89 <bool>false</bool>
90 </property>
85 <property name="text">
91 <property name="text">
86 <string>G</string>
92 <string>G</string>
87 </property>
93 </property>
@@ -30,6 +30,9
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="enabled">
34 <bool>false</bool>
35 </property>
33 <property name="text">
36 <property name="text">
34 <string>+</string>
37 <string>+</string>
35 </property>
38 </property>
@@ -44,6 +47,9
44 </item>
47 </item>
45 <item>
48 <item>
46 <widget class="QToolButton" name="btnRemove">
49 <widget class="QToolButton" name="btnRemove">
50 <property name="enabled">
51 <bool>false</bool>
52 </property>
47 <property name="text">
53 <property name="text">
48 <string> - </string>
54 <string> - </string>
49 </property>
55 </property>
@@ -72,18 +78,22
72 </layout>
78 </layout>
73 </item>
79 </item>
74 <item>
80 <item>
75 <widget class="QTreeWidget" name="treeWidget">
81 <widget class="QTreeView" name="treeView">
82 <property name="acceptDrops">
83 <bool>true</bool>
84 </property>
85 <property name="dragDropMode">
86 <enum>QAbstractItemView::DragDrop</enum>
87 </property>
76 <property name="selectionMode">
88 <property name="selectionMode">
77 <enum>QAbstractItemView::ExtendedSelection</enum>
89 <enum>QAbstractItemView::ExtendedSelection</enum>
78 </property>
90 </property>
79 <attribute name="headerVisible">
91 <attribute name="headerVisible">
80 <bool>false</bool>
92 <bool>false</bool>
81 </attribute>
93 </attribute>
82 <column>
94 <attribute name="headerStretchLastSection">
83 <property name="text">
95 <bool>false</bool>
84 <string notr="true">1</string>
96 </attribute>
85 </property>
86 </column>
87 </widget>
97 </widget>
88 </item>
98 </item>
89 </layout>
99 </layout>
@@ -37,6 +37,7 void associateActions(DataSourceItem &item, const QUuid &dataSourceUid)
37 auto actionLabel = QObject::tr(
37 auto actionLabel = QObject::tr(
38 itemType == DataSourceItemType::PRODUCT ? "Load %1 product" : "Load %1 component");
38 itemType == DataSourceItemType::PRODUCT ? "Load %1 product" : "Load %1 component");
39 addLoadAction(actionLabel.arg(item.name()));
39 addLoadAction(actionLabel.arg(item.name()));
40 item.setData(DataSourceItem::ID_DATA_KEY, item.data(AMDA_XML_ID_KEY));
40 }
41 }
41
42
42 auto count = item.childCount();
43 auto count = item.childCount();
@@ -28,6 +28,7 std::unique_ptr<DataSourceItem> createProductItem(const QVariantHash &data,
28
28
29 // Adds plugin name to product metadata
29 // Adds plugin name to product metadata
30 result->setData(DataSourceItem::PLUGIN_DATA_KEY, DATA_SOURCE_NAME);
30 result->setData(DataSourceItem::PLUGIN_DATA_KEY, DATA_SOURCE_NAME);
31 result->setData(DataSourceItem::ID_DATA_KEY, data.value(DataSourceItem::NAME_DATA_KEY));
31
32
32 auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString();
33 auto productName = data.value(DataSourceItem::NAME_DATA_KEY).toString();
33
34
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