##// END OF EJS Templates
Adaptation to the shared pointers of catalogue controller
trabillard -
r1143:20294bb49a24
parent child
Show More
@@ -1,70 +1,69
1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
2 #define SCIQLOP_CATALOGUECONTROLLER_H
2 #define SCIQLOP_CATALOGUECONTROLLER_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Data/SqpRange.h>
6 #include <Data/SqpRange.h>
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9 #include <QObject>
9 #include <QObject>
10 #include <QUuid>
10 #include <QUuid>
11
11
12 #include <Common/spimpl.h>
12 #include <Common/spimpl.h>
13
13
14 #include <memory>
14 #include <memory>
15
15
16 class DBCatalogue;
16 class DBCatalogue;
17 class DBEvent;
17 class DBEvent;
18
18
19 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
19 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
20
20
21 class DataSourceItem;
21 class DataSourceItem;
22 class Variable;
22 class Variable;
23
23
24 /**
24 /**
25 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
25 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
26 * library.
26 * library.
27 */
27 */
28 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
28 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
29 Q_OBJECT
29 Q_OBJECT
30 public:
30 public:
31 explicit CatalogueController(QObject *parent = 0);
31 explicit CatalogueController(QObject *parent = 0);
32 virtual ~CatalogueController();
32 virtual ~CatalogueController();
33
33
34 // DB
34 // DB
35 // QStringList getRepositories() const;
35 // QStringList getRepositories() const;
36 void addDB(const QString &dbPath);
36 void addDB(const QString &dbPath);
37 void saveDB(const QString &destinationPath, const QString &repository);
37 void saveDB(const QString &destinationPath, const QString &repository);
38
38
39 // Event
39 // Event
40 // bool createEvent(const QString &name);
40 // bool createEvent(const QString &name);
41 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
41 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
42 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
42 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
43 std::list<std::shared_ptr<DBEvent> >
43 std::list<std::shared_ptr<DBEvent> >
44 retrieveEventsFromCatalogue(const QString &repository,
44 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
45 std::shared_ptr<DBCatalogue> catalogue) const;
46 // void updateEvent(std::shared_ptr<DBEvent> event);
45 // void updateEvent(std::shared_ptr<DBEvent> event);
47 // void trashEvent(std::shared_ptr<DBEvent> event);
46 // void trashEvent(std::shared_ptr<DBEvent> event);
48 // void removeEvent(std::shared_ptr<DBEvent> event);
47 // void removeEvent(std::shared_ptr<DBEvent> event);
49 // void restore(QUuid eventId);
48 // void restore(QUuid eventId);
50 // void saveEvent(std::shared_ptr<DBEvent> event);
49 // void saveEvent(std::shared_ptr<DBEvent> event);
51
50
52 // Catalogue
51 // Catalogue
53 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
52 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
54 std::list<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
53 std::list<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
55 // void removeEvent(QUuid catalogueId, const QString &repository);
54 // void removeEvent(QUuid catalogueId, const QString &repository);
56 // void saveCatalogue(std::shared_ptr<DBEvent> event);
55 // void saveCatalogue(std::shared_ptr<DBEvent> event);
57
56
58 public slots:
57 public slots:
59 /// Manage init/end of the controller
58 /// Manage init/end of the controller
60 void initialize();
59 void initialize();
61 void finalize();
60 void finalize();
62
61
63 private:
62 private:
64 void waitForFinish();
63 void waitForFinish();
65
64
66 class CatalogueControllerPrivate;
65 class CatalogueControllerPrivate;
67 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
66 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
68 };
67 };
69
68
70 #endif // SCIQLOP_CATALOGUECONTROLLER_H
69 #endif // SCIQLOP_CATALOGUECONTROLLER_H
@@ -1,162 +1,161
1 #include <Catalogue/CatalogueController.h>
1 #include <Catalogue/CatalogueController.h>
2
2
3 #include <Variable/Variable.h>
3 #include <Variable/Variable.h>
4
4
5 #include <CatalogueDao.h>
5 #include <CatalogueDao.h>
6
6
7 #include <ComparaisonPredicate.h>
7 #include <ComparaisonPredicate.h>
8 #include <CompoundPredicate.h>
8 #include <CompoundPredicate.h>
9 #include <DBCatalogue.h>
9 #include <DBCatalogue.h>
10 #include <DBEvent.h>
10 #include <DBEvent.h>
11 #include <DBTag.h>
11 #include <DBTag.h>
12 #include <IRequestPredicate.h>
12 #include <IRequestPredicate.h>
13
13
14 #include <QMutex>
14 #include <QMutex>
15 #include <QThread>
15 #include <QThread>
16
16
17 #include <QDir>
17 #include <QDir>
18 #include <QStandardPaths>
18 #include <QStandardPaths>
19
19
20 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
20 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
21
21
22 namespace {
22 namespace {
23
23
24 static QString REPOSITORY_WORK_SUFFIX = QString{"Work"};
24 static QString REPOSITORY_WORK_SUFFIX = QString{"Work"};
25
25
26 }
26 }
27
27
28 class CatalogueController::CatalogueControllerPrivate {
28 class CatalogueController::CatalogueControllerPrivate {
29 public:
29 public:
30 QMutex m_WorkingMutex;
30 QMutex m_WorkingMutex;
31 CatalogueDao m_CatalogueDao;
31 CatalogueDao m_CatalogueDao;
32
32
33 std::list<QString> m_RepositoryList;
33 std::list<QString> m_RepositoryList;
34 };
34 };
35
35
36 CatalogueController::CatalogueController(QObject *parent)
36 CatalogueController::CatalogueController(QObject *parent)
37 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>()}
37 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>()}
38 {
38 {
39 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
39 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
40 << QThread::currentThread();
40 << QThread::currentThread();
41 }
41 }
42
42
43 CatalogueController::~CatalogueController()
43 CatalogueController::~CatalogueController()
44 {
44 {
45 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
45 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
46 << QThread::currentThread();
46 << QThread::currentThread();
47 this->waitForFinish();
47 this->waitForFinish();
48 }
48 }
49
49
50 void CatalogueController::addDB(const QString &dbPath)
50 void CatalogueController::addDB(const QString &dbPath)
51 {
51 {
52 QDir dbDir(dbPath);
52 QDir dbDir(dbPath);
53 if (dbDir.exists()) {
53 if (dbDir.exists()) {
54 auto dirName = dbDir.dirName();
54 auto dirName = dbDir.dirName();
55
55
56 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
56 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
57 != impl->m_RepositoryList.cend()) {
57 != impl->m_RepositoryList.cend()) {
58 qCCritical(LOG_CatalogueController())
58 qCCritical(LOG_CatalogueController())
59 << tr("Impossible to addDB that is already loaded");
59 << tr("Impossible to addDB that is already loaded");
60 }
60 }
61
61
62 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
62 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
63 qCCritical(LOG_CatalogueController())
63 qCCritical(LOG_CatalogueController())
64 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
64 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
65 }
65 }
66 else {
66 else {
67 impl->m_RepositoryList.push_back(dirName);
67 impl->m_RepositoryList.push_back(dirName);
68 }
68 }
69 }
69 }
70 else {
70 else {
71 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
71 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
72 << dbPath;
72 << dbPath;
73 }
73 }
74 }
74 }
75
75
76 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
76 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
77 {
77 {
78 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
78 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
79 qCCritical(LOG_CatalogueController())
79 qCCritical(LOG_CatalogueController())
80 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
80 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
81 }
81 }
82 }
82 }
83
83
84 std::list<std::shared_ptr<DBEvent> >
84 std::list<std::shared_ptr<DBEvent> >
85 CatalogueController::retrieveEvents(const QString &repository) const
85 CatalogueController::retrieveEvents(const QString &repository) const
86 {
86 {
87 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
87 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
88 auto events = impl->m_CatalogueDao.getEvents(repository);
88 auto events = impl->m_CatalogueDao.getEvents(repository);
89 for (auto event : events) {
89 for (auto event : events) {
90 eventsShared.push_back(std::make_shared<DBEvent>(event));
90 eventsShared.push_back(std::make_shared<DBEvent>(event));
91 }
91 }
92 return eventsShared;
92 return eventsShared;
93 }
93 }
94
94
95 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
95 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
96 {
96 {
97 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
97 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
98 for (auto repository : impl->m_RepositoryList) {
98 for (auto repository : impl->m_RepositoryList) {
99 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
99 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
100 }
100 }
101
101
102 return eventsShared;
102 return eventsShared;
103 }
103 }
104
104
105 std::list<std::shared_ptr<DBEvent> >
105 std::list<std::shared_ptr<DBEvent> >
106 CatalogueController::retrieveEventsFromCatalogue(const QString &repository,
106 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const
107 std::shared_ptr<DBCatalogue> catalogue) const
108 {
107 {
109 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
108 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
110 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
109 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
111 for (auto event : events) {
110 for (auto event : events) {
112 eventsShared.push_back(std::make_shared<DBEvent>(event));
111 eventsShared.push_back(std::make_shared<DBEvent>(event));
113 }
112 }
114 return eventsShared;
113 return eventsShared;
115 }
114 }
116
115
117 std::list<std::shared_ptr<DBCatalogue> >
116 std::list<std::shared_ptr<DBCatalogue> >
118 CatalogueController::getCatalogues(const QString &repository) const
117 CatalogueController::getCatalogues(const QString &repository) const
119 {
118 {
120 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
119 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
121 auto catalogues = impl->m_CatalogueDao.getCatalogues(repository);
120 auto catalogues = impl->m_CatalogueDao.getCatalogues(repository);
122 for (auto catalogue : catalogues) {
121 for (auto catalogue : catalogues) {
123 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
122 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
124 }
123 }
125 return cataloguesShared;
124 return cataloguesShared;
126 }
125 }
127
126
128 void CatalogueController::initialize()
127 void CatalogueController::initialize()
129 {
128 {
130 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
129 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
131 << QThread::currentThread();
130 << QThread::currentThread();
132 impl->m_WorkingMutex.lock();
131 impl->m_WorkingMutex.lock();
133 impl->m_CatalogueDao.initialize();
132 impl->m_CatalogueDao.initialize();
134 auto defaultRepositoryLocation
133 auto defaultRepositoryLocation
135 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
134 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
136
135
137 QDir defaultRepositoryLocationDir;
136 QDir defaultRepositoryLocationDir;
138 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
137 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
139 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
138 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
140 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
139 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
141 qCInfo(LOG_CatalogueController())
140 qCInfo(LOG_CatalogueController())
142 << tr("Persistant data loading from: ") << defaultRepository;
141 << tr("Persistant data loading from: ") << defaultRepository;
143 this->addDB(defaultRepository);
142 this->addDB(defaultRepository);
144 }
143 }
145 else {
144 else {
146 qCWarning(LOG_CatalogueController())
145 qCWarning(LOG_CatalogueController())
147 << tr("Cannot load the persistent default repository from ")
146 << tr("Cannot load the persistent default repository from ")
148 << defaultRepositoryLocation;
147 << defaultRepositoryLocation;
149 }
148 }
150
149
151 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
150 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
152 }
151 }
153
152
154 void CatalogueController::finalize()
153 void CatalogueController::finalize()
155 {
154 {
156 impl->m_WorkingMutex.unlock();
155 impl->m_WorkingMutex.unlock();
157 }
156 }
158
157
159 void CatalogueController::waitForFinish()
158 void CatalogueController::waitForFinish()
160 {
159 {
161 QMutexLocker locker{&impl->m_WorkingMutex};
160 QMutexLocker locker{&impl->m_WorkingMutex};
162 }
161 }
@@ -1,38 +1,38
1 #ifndef SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H
1 #ifndef SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H
2 #define SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H
2 #define SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QAbstractTableModel>
5 #include <QAbstractTableModel>
6
6
7 #include <DBEvent.h>
7 class DBEvent;
8
8
9 class CatalogueEventsTableModel : public QAbstractTableModel {
9 class CatalogueEventsTableModel : public QAbstractTableModel {
10 public:
10 public:
11 CatalogueEventsTableModel(QObject *parent = nullptr);
11 CatalogueEventsTableModel(QObject *parent = nullptr);
12
12
13 void setEvents(const QVector<DBEvent> &events);
13 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events);
14 DBEvent getEvent(int row) const;
14 std::shared_ptr<DBEvent> getEvent(int row) const;
15
15
16 void addEvent(const DBEvent &events);
16 void addEvent(const std::shared_ptr<DBEvent> &events);
17 void removeEvent(const DBEvent &events);
17 void removeEvent(const std::shared_ptr<DBEvent> &events);
18
18
19 // Model
19 // Model
20 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
20 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
21 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
21 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
22 Qt::ItemFlags flags(const QModelIndex &index) const override;
22 Qt::ItemFlags flags(const QModelIndex &index) const override;
23 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
23 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
24 QVariant headerData(int section, Qt::Orientation orientation,
24 QVariant headerData(int section, Qt::Orientation orientation,
25 int role = Qt::DisplayRole) const override;
25 int role = Qt::DisplayRole) const override;
26 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
26 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
27
27
28 Qt::DropActions supportedDragActions() const override;
28 Qt::DropActions supportedDragActions() const override;
29 QStringList mimeTypes() const override;
29 QStringList mimeTypes() const override;
30 QMimeData *mimeData(const QModelIndexList &indexes) const override;
30 QMimeData *mimeData(const QModelIndexList &indexes) const override;
31
31
32
32
33 private:
33 private:
34 class CatalogueEventsTableModelPrivate;
34 class CatalogueEventsTableModelPrivate;
35 spimpl::unique_impl_ptr<CatalogueEventsTableModelPrivate> impl;
35 spimpl::unique_impl_ptr<CatalogueEventsTableModelPrivate> impl;
36 };
36 };
37
37
38 #endif // SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H
38 #endif // SCIQLOP_CATALOGUEEVENTSTABLEMODEL_H
@@ -1,40 +1,40
1 #ifndef SCIQLOP_CATALOGUEEVENTSWIDGET_H
1 #ifndef SCIQLOP_CATALOGUEEVENTSWIDGET_H
2 #define SCIQLOP_CATALOGUEEVENTSWIDGET_H
2 #define SCIQLOP_CATALOGUEEVENTSWIDGET_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QLoggingCategory>
5 #include <QLoggingCategory>
6 #include <QWidget>
6 #include <QWidget>
7
7
8 class DBCatalogue;
8 class DBCatalogue;
9 class DBEvent;
9 class DBEvent;
10 class VisualizationWidget;
10 class VisualizationWidget;
11
11
12 namespace Ui {
12 namespace Ui {
13 class CatalogueEventsWidget;
13 class CatalogueEventsWidget;
14 }
14 }
15
15
16 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget)
16 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueEventsWidget)
17
17
18 class CatalogueEventsWidget : public QWidget {
18 class CatalogueEventsWidget : public QWidget {
19 Q_OBJECT
19 Q_OBJECT
20
20
21 signals:
21 signals:
22 void eventsSelected(const QVector<DBEvent> &event);
22 void eventsSelected(const QVector<std::shared_ptr<DBEvent> > &event);
23
23
24 public:
24 public:
25 explicit CatalogueEventsWidget(QWidget *parent = 0);
25 explicit CatalogueEventsWidget(QWidget *parent = 0);
26 virtual ~CatalogueEventsWidget();
26 virtual ~CatalogueEventsWidget();
27
27
28 void setVisualizationWidget(VisualizationWidget *visualization);
28 void setVisualizationWidget(VisualizationWidget *visualization);
29
29
30 public slots:
30 public slots:
31 void populateWithCatalogues(const QVector<DBCatalogue> &catalogues);
31 void populateWithCatalogues(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
32
32
33 private:
33 private:
34 Ui::CatalogueEventsWidget *ui;
34 Ui::CatalogueEventsWidget *ui;
35
35
36 class CatalogueEventsWidgetPrivate;
36 class CatalogueEventsWidgetPrivate;
37 spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl;
37 spimpl::unique_impl_ptr<CatalogueEventsWidgetPrivate> impl;
38 };
38 };
39
39
40 #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H
40 #endif // SCIQLOP_CATALOGUEEVENTSWIDGET_H
@@ -1,35 +1,36
1 #ifndef SCIQLOP_CATALOGUEINSPECTORWIDGET_H
1 #ifndef SCIQLOP_CATALOGUEINSPECTORWIDGET_H
2 #define SCIQLOP_CATALOGUEINSPECTORWIDGET_H
2 #define SCIQLOP_CATALOGUEINSPECTORWIDGET_H
3
3
4 #include <QWidget>
4 #include <QWidget>
5 #include <memory>
5
6
6 namespace Ui {
7 namespace Ui {
7 class CatalogueInspectorWidget;
8 class CatalogueInspectorWidget;
8 }
9 }
9
10
10 class DBCatalogue;
11 class DBCatalogue;
11 class DBEvent;
12 class DBEvent;
12
13
13 class CatalogueInspectorWidget : public QWidget {
14 class CatalogueInspectorWidget : public QWidget {
14 Q_OBJECT
15 Q_OBJECT
15
16
16 public:
17 public:
17 explicit CatalogueInspectorWidget(QWidget *parent = 0);
18 explicit CatalogueInspectorWidget(QWidget *parent = 0);
18 virtual ~CatalogueInspectorWidget();
19 virtual ~CatalogueInspectorWidget();
19
20
20 /// Enum matching the pages inside the stacked widget
21 /// Enum matching the pages inside the stacked widget
21 enum class Page { Empty, CatalogueProperties, EventProperties };
22 enum class Page { Empty, CatalogueProperties, EventProperties };
22
23
23 Page currentPage() const;
24 Page currentPage() const;
24
25
25 void setEvent(const DBEvent &event);
26 void setEvent(const std::shared_ptr<DBEvent> &event);
26 void setCatalogue(const DBCatalogue &catalogue);
27 void setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue);
27
28
28 public slots:
29 public slots:
29 void showPage(Page page);
30 void showPage(Page page);
30
31
31 private:
32 private:
32 Ui::CatalogueInspectorWidget *ui;
33 Ui::CatalogueInspectorWidget *ui;
33 };
34 };
34
35
35 #endif // SCIQLOP_CATALOGUEINSPECTORWIDGET_H
36 #endif // SCIQLOP_CATALOGUEINSPECTORWIDGET_H
@@ -1,38 +1,38
1 #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H
1 #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H
2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QTreeWidgetItem>
5 #include <QTreeWidgetItem>
6 #include <QWidget>
6 #include <QWidget>
7
7
8 #include <DBCatalogue.h>
8 class DBCatalogue;
9
9
10 namespace Ui {
10 namespace Ui {
11 class CatalogueSideBarWidget;
11 class CatalogueSideBarWidget;
12 }
12 }
13
13
14 class CatalogueSideBarWidget : public QWidget {
14 class CatalogueSideBarWidget : public QWidget {
15 Q_OBJECT
15 Q_OBJECT
16
16
17 signals:
17 signals:
18 void catalogueSelected(const QVector<DBCatalogue> &catalogues);
18 void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
19 void databaseSelected(const QStringList &databases);
19 void databaseSelected(const QStringList &databases);
20 void allEventsSelected();
20 void allEventsSelected();
21 void trashSelected();
21 void trashSelected();
22 void selectionCleared();
22 void selectionCleared();
23
23
24 public:
24 public:
25 explicit CatalogueSideBarWidget(QWidget *parent = 0);
25 explicit CatalogueSideBarWidget(QWidget *parent = 0);
26 virtual ~CatalogueSideBarWidget();
26 virtual ~CatalogueSideBarWidget();
27
27
28 private:
28 private:
29 Ui::CatalogueSideBarWidget *ui;
29 Ui::CatalogueSideBarWidget *ui;
30
30
31 class CatalogueSideBarWidgetPrivate;
31 class CatalogueSideBarWidgetPrivate;
32 spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl;
32 spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl;
33
33
34 private slots:
34 private slots:
35 void onContextMenuRequested(const QPoint &pos);
35 void onContextMenuRequested(const QPoint &pos);
36 };
36 };
37
37
38 #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H
38 #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H
@@ -1,27 +1,28
1 #ifndef SCIQLOP_CATALOGUETREEWIDGETITEM_H
1 #ifndef SCIQLOP_CATALOGUETREEWIDGETITEM_H
2 #define SCIQLOP_CATALOGUETREEWIDGETITEM_H
2 #define SCIQLOP_CATALOGUETREEWIDGETITEM_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QTreeWidgetItem>
5 #include <QTreeWidgetItem>
6
6
7 #include <DBCatalogue.h>
7 class DBCatalogue;
8
8
9
9
10 class CatalogueTreeWidgetItem : public QTreeWidgetItem {
10 class CatalogueTreeWidgetItem : public QTreeWidgetItem {
11 public:
11 public:
12 CatalogueTreeWidgetItem(DBCatalogue catalogue, int type = QTreeWidgetItem::Type);
12 CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue,
13 int type = QTreeWidgetItem::Type);
13
14
14 QVariant data(int column, int role) const override;
15 QVariant data(int column, int role) const override;
15 void setData(int column, int role, const QVariant &value) override;
16 void setData(int column, int role, const QVariant &value) override;
16
17
17 /// Returns the catalogue represented by the item
18 /// Returns the catalogue represented by the item
18 DBCatalogue catalogue() const;
19 std::shared_ptr<DBCatalogue> catalogue() const;
19
20
20 void setHasChanges(bool value);
21 void setHasChanges(bool value);
21
22
22 private:
23 private:
23 class CatalogueTreeWidgetItemPrivate;
24 class CatalogueTreeWidgetItemPrivate;
24 spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl;
25 spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl;
25 };
26 };
26
27
27 #endif // SCIQLOP_CATALOGUETREEWIDGETITEM_H
28 #endif // SCIQLOP_CATALOGUETREEWIDGETITEM_H
@@ -1,185 +1,185
1 #include "Catalogue/CatalogueEventsTableModel.h"
1 #include "Catalogue/CatalogueEventsTableModel.h"
2
2
3 #include <Common/DateUtils.h>
3 #include <Common/DateUtils.h>
4 #include <Common/MimeTypesDef.h>
4 #include <Common/MimeTypesDef.h>
5 #include <DBEvent.h>
5 #include <DBEvent.h>
6 #include <DBTag.h>
6 #include <DBTag.h>
7 #include <Data/SqpRange.h>
7 #include <Data/SqpRange.h>
8 #include <QMimeData>
8 #include <QMimeData>
9 #include <SqpApplication.h>
9 #include <SqpApplication.h>
10 #include <Time/TimeController.h>
10 #include <Time/TimeController.h>
11
11
12 struct CatalogueEventsTableModel::CatalogueEventsTableModelPrivate {
12 struct CatalogueEventsTableModel::CatalogueEventsTableModelPrivate {
13 QVector<DBEvent> m_Events;
13 QVector<std::shared_ptr<DBEvent> > m_Events;
14
14
15 enum class Column { Event, TStart, TEnd, Tags, Product, NbColumn };
15 enum class Column { Event, TStart, TEnd, Tags, Product, NbColumn };
16 QStringList columnNames()
16 QStringList columnNames()
17 {
17 {
18 return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")};
18 return QStringList{tr("Event"), tr("TStart"), tr("TEnd"), tr("Tags"), tr("Product")};
19 }
19 }
20
20
21 QVariant eventData(int col, const DBEvent &event) const
21 QVariant eventData(int col, const std::shared_ptr<DBEvent> &event) const
22 {
22 {
23 switch (static_cast<Column>(col)) {
23 switch (static_cast<Column>(col)) {
24 case Column::Event:
24 case Column::Event:
25 return event.getName();
25 return event->getName();
26 case Column::TStart:
26 case Column::TStart:
27 return DateUtils::dateTime(event.getTStart());
27 return DateUtils::dateTime(event->getTStart());
28 case Column::TEnd:
28 case Column::TEnd:
29 return DateUtils::dateTime(event.getTEnd());
29 return DateUtils::dateTime(event->getTEnd());
30 case Column::Product:
30 case Column::Product:
31 return event.getProduct();
31 return event->getProduct();
32 case Column::Tags: {
32 case Column::Tags: {
33 QString tagList;
33 QString tagList;
34 auto tags = const_cast<DBEvent *>(&event)->getTags();
34 auto tags = event->getTags();
35 for (auto tag : tags) {
35 for (auto tag : tags) {
36 tagList += tag.getName();
36 tagList += tag.getName();
37 tagList += ' ';
37 tagList += ' ';
38 }
38 }
39
39
40 return tagList;
40 return tagList;
41 }
41 }
42 default:
42 default:
43 break;
43 break;
44 }
44 }
45
45
46 Q_ASSERT(false);
46 Q_ASSERT(false);
47 return QStringLiteral("Unknown Data");
47 return QStringLiteral("Unknown Data");
48 }
48 }
49 };
49 };
50
50
51 CatalogueEventsTableModel::CatalogueEventsTableModel(QObject *parent)
51 CatalogueEventsTableModel::CatalogueEventsTableModel(QObject *parent)
52 : QAbstractTableModel(parent),
52 : QAbstractTableModel(parent),
53 impl{spimpl::make_unique_impl<CatalogueEventsTableModelPrivate>()}
53 impl{spimpl::make_unique_impl<CatalogueEventsTableModelPrivate>()}
54 {
54 {
55 }
55 }
56
56
57 void CatalogueEventsTableModel::setEvents(const QVector<DBEvent> &events)
57 void CatalogueEventsTableModel::setEvents(const QVector<std::shared_ptr<DBEvent> > &events)
58 {
58 {
59 beginResetModel();
59 beginResetModel();
60 impl->m_Events = events;
60 impl->m_Events = events;
61 endResetModel();
61 endResetModel();
62 }
62 }
63
63
64 DBEvent CatalogueEventsTableModel::getEvent(int row) const
64 std::shared_ptr<DBEvent> CatalogueEventsTableModel::getEvent(int row) const
65 {
65 {
66 return impl->m_Events.value(row);
66 return impl->m_Events.value(row);
67 }
67 }
68
68
69 void CatalogueEventsTableModel::addEvent(const DBEvent &events)
69 void CatalogueEventsTableModel::addEvent(const std::shared_ptr<DBEvent> &events)
70 {
70 {
71 beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1);
71 beginInsertRows(QModelIndex(), impl->m_Events.count() - 1, impl->m_Events.count() - 1);
72 // impl->m_Events.append(event); TODO
72 // impl->m_Events.append(event); TODO
73 endInsertRows();
73 endInsertRows();
74 }
74 }
75
75
76 void CatalogueEventsTableModel::removeEvent(const DBEvent &events)
76 void CatalogueEventsTableModel::removeEvent(const std::shared_ptr<DBEvent> &events)
77 {
77 {
78 // TODO
78 // TODO
79 auto index = -1; // impl->m_Events.indexOf(event);
79 auto index = -1; // impl->m_Events.indexOf(event);
80 if (index >= 0) {
80 if (index >= 0) {
81 beginRemoveRows(QModelIndex(), index, index);
81 beginRemoveRows(QModelIndex(), index, index);
82 impl->m_Events.removeAt(index);
82 impl->m_Events.removeAt(index);
83 endRemoveRows();
83 endRemoveRows();
84 }
84 }
85 }
85 }
86
86
87 int CatalogueEventsTableModel::rowCount(const QModelIndex &parent) const
87 int CatalogueEventsTableModel::rowCount(const QModelIndex &parent) const
88 {
88 {
89 int r = impl->m_Events.count();
89 int r = impl->m_Events.count();
90 return r;
90 return r;
91 }
91 }
92
92
93 int CatalogueEventsTableModel::columnCount(const QModelIndex &parent) const
93 int CatalogueEventsTableModel::columnCount(const QModelIndex &parent) const
94 {
94 {
95 int c = static_cast<int>(CatalogueEventsTableModelPrivate::Column::NbColumn);
95 int c = static_cast<int>(CatalogueEventsTableModelPrivate::Column::NbColumn);
96 return c;
96 return c;
97 }
97 }
98
98
99 Qt::ItemFlags CatalogueEventsTableModel::flags(const QModelIndex &index) const
99 Qt::ItemFlags CatalogueEventsTableModel::flags(const QModelIndex &index) const
100 {
100 {
101 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
101 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
102 }
102 }
103
103
104 QVariant CatalogueEventsTableModel::data(const QModelIndex &index, int role) const
104 QVariant CatalogueEventsTableModel::data(const QModelIndex &index, int role) const
105 {
105 {
106 if (index.isValid()) {
106 if (index.isValid()) {
107 auto event = getEvent(index.row());
107 auto event = getEvent(index.row());
108
108
109 switch (role) {
109 switch (role) {
110 case Qt::DisplayRole:
110 case Qt::DisplayRole:
111 return impl->eventData(index.column(), event);
111 return impl->eventData(index.column(), event);
112 break;
112 break;
113 }
113 }
114 }
114 }
115
115
116 return QVariant{};
116 return QVariant{};
117 }
117 }
118
118
119 QVariant CatalogueEventsTableModel::headerData(int section, Qt::Orientation orientation,
119 QVariant CatalogueEventsTableModel::headerData(int section, Qt::Orientation orientation,
120 int role) const
120 int role) const
121 {
121 {
122 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
122 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
123 return impl->columnNames().value(section);
123 return impl->columnNames().value(section);
124 }
124 }
125
125
126 return QVariant();
126 return QVariant();
127 }
127 }
128
128
129 void CatalogueEventsTableModel::sort(int column, Qt::SortOrder order)
129 void CatalogueEventsTableModel::sort(int column, Qt::SortOrder order)
130 {
130 {
131 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
131 std::sort(impl->m_Events.begin(), impl->m_Events.end(),
132 [this, column, order](auto e1, auto e2) {
132 [this, column, order](auto e1, auto e2) {
133 auto data1 = impl->eventData(column, e1);
133 auto data1 = impl->eventData(column, e1);
134 auto data2 = impl->eventData(column, e2);
134 auto data2 = impl->eventData(column, e2);
135
135
136 auto result = data1.toString() < data2.toString();
136 auto result = data1.toString() < data2.toString();
137
137
138 return order == Qt::AscendingOrder ? result : !result;
138 return order == Qt::AscendingOrder ? result : !result;
139 });
139 });
140
140
141 emit dataChanged(QModelIndex(), QModelIndex());
141 emit dataChanged(QModelIndex(), QModelIndex());
142 }
142 }
143
143
144 Qt::DropActions CatalogueEventsTableModel::supportedDragActions() const
144 Qt::DropActions CatalogueEventsTableModel::supportedDragActions() const
145 {
145 {
146 return Qt::CopyAction | Qt::MoveAction;
146 return Qt::CopyAction | Qt::MoveAction;
147 }
147 }
148
148
149 QStringList CatalogueEventsTableModel::mimeTypes() const
149 QStringList CatalogueEventsTableModel::mimeTypes() const
150 {
150 {
151 return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE};
151 return {MIME_TYPE_EVENT_LIST, MIME_TYPE_TIME_RANGE};
152 }
152 }
153
153
154 QMimeData *CatalogueEventsTableModel::mimeData(const QModelIndexList &indexes) const
154 QMimeData *CatalogueEventsTableModel::mimeData(const QModelIndexList &indexes) const
155 {
155 {
156 auto mimeData = new QMimeData;
156 auto mimeData = new QMimeData;
157
157
158 QVector<DBEvent> eventList;
158 QVector<std::shared_ptr<DBEvent> > eventList;
159
159
160 SqpRange firstTimeRange;
160 SqpRange firstTimeRange;
161 for (const auto &index : indexes) {
161 for (const auto &index : indexes) {
162 if (index.column() == 0) { // only the first column
162 if (index.column() == 0) { // only the first column
163 auto event = getEvent(index.row());
163 auto event = getEvent(index.row());
164 if (eventList.isEmpty()) {
164 if (eventList.isEmpty()) {
165 // Gets the range of the first variable
165 // Gets the range of the first variable
166 firstTimeRange.m_TStart = event.getTStart();
166 firstTimeRange.m_TStart = event->getTStart();
167 firstTimeRange.m_TEnd = event.getTEnd();
167 firstTimeRange.m_TEnd = event->getTEnd();
168 }
168 }
169
169
170 eventList << event;
170 eventList << event;
171 }
171 }
172 }
172 }
173
173
174 auto eventsEncodedData
174 auto eventsEncodedData
175 = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO
175 = QByteArray{}; // sqpApp->catalogueController().->mimeDataForEvents(eventList); //TODO
176 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
176 mimeData->setData(MIME_TYPE_EVENT_LIST, eventsEncodedData);
177
177
178 if (eventList.count() == 1) {
178 if (eventList.count() == 1) {
179 // No time range MIME data if multiple events are dragged
179 // No time range MIME data if multiple events are dragged
180 auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange);
180 auto timeEncodedData = TimeController::mimeDataForTimeRange(firstTimeRange);
181 mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData);
181 mimeData->setData(MIME_TYPE_TIME_RANGE, timeEncodedData);
182 }
182 }
183
183
184 return mimeData;
184 return mimeData;
185 }
185 }
@@ -1,292 +1,291
1 #include "Catalogue/CatalogueEventsWidget.h"
1 #include "Catalogue/CatalogueEventsWidget.h"
2 #include "ui_CatalogueEventsWidget.h"
2 #include "ui_CatalogueEventsWidget.h"
3
3
4 #include <Catalogue/CatalogueController.h>
4 #include <Catalogue/CatalogueController.h>
5 #include <Catalogue/CatalogueEventsTableModel.h>
5 #include <Catalogue/CatalogueEventsTableModel.h>
6 #include <CatalogueDao.h>
6 #include <CatalogueDao.h>
7 #include <DBCatalogue.h>
7 #include <DBCatalogue.h>
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9 #include <Visualization/VisualizationTabWidget.h>
9 #include <Visualization/VisualizationTabWidget.h>
10 #include <Visualization/VisualizationWidget.h>
10 #include <Visualization/VisualizationWidget.h>
11 #include <Visualization/VisualizationZoneWidget.h>
11 #include <Visualization/VisualizationZoneWidget.h>
12
12
13 #include <QDialog>
13 #include <QDialog>
14 #include <QDialogButtonBox>
14 #include <QDialogButtonBox>
15 #include <QListWidget>
15 #include <QListWidget>
16
16
17 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
17 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
18
18
19 /// Format of the dates appearing in the label of a cursor
19 /// Format of the dates appearing in the label of a cursor
20 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss");
20 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss");
21
21
22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
22 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
23
23
24 CatalogueEventsTableModel *m_Model = nullptr;
24 CatalogueEventsTableModel *m_Model = nullptr;
25 QStringList m_ZonesForTimeMode;
25 QStringList m_ZonesForTimeMode;
26 QString m_ZoneForGraphMode;
26 QString m_ZoneForGraphMode;
27
27
28 VisualizationWidget *m_VisualizationWidget = nullptr;
28 VisualizationWidget *m_VisualizationWidget = nullptr;
29
29
30 void setEvents(const QVector<DBEvent> &events, QTableView *tableView)
30 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTableView *tableView)
31 {
31 {
32 tableView->setSortingEnabled(false);
32 tableView->setSortingEnabled(false);
33 m_Model->setEvents(events);
33 m_Model->setEvents(events);
34 tableView->setSortingEnabled(true);
34 tableView->setSortingEnabled(true);
35 }
35 }
36
36
37 void addEvent(const DBEvent &event, QTableView *tableView)
37 void addEvent(const std::shared_ptr<DBEvent> &event, QTableView *tableView)
38 {
38 {
39 tableView->setSortingEnabled(false);
39 tableView->setSortingEnabled(false);
40 m_Model->addEvent(event);
40 m_Model->addEvent(event);
41 tableView->setSortingEnabled(true);
41 tableView->setSortingEnabled(true);
42 }
42 }
43
43
44 void removeEvent(const DBEvent &event, QTableView *tableView)
44 void removeEvent(const std::shared_ptr<DBEvent> &event, QTableView *tableView)
45 {
45 {
46 tableView->setSortingEnabled(false);
46 tableView->setSortingEnabled(false);
47 m_Model->removeEvent(event);
47 m_Model->removeEvent(event);
48 tableView->setSortingEnabled(true);
48 tableView->setSortingEnabled(true);
49 }
49 }
50
50
51 QStringList getAvailableVisualizationZoneList() const
51 QStringList getAvailableVisualizationZoneList() const
52 {
52 {
53 if (m_VisualizationWidget) {
53 if (m_VisualizationWidget) {
54 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
54 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
55 return tab->availableZoneWidgets();
55 return tab->availableZoneWidgets();
56 }
56 }
57 }
57 }
58
58
59 return QStringList{};
59 return QStringList{};
60 }
60 }
61
61
62 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
62 QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
63 bool allowMultiSelection, const QPoint &location)
63 bool allowMultiSelection, const QPoint &location)
64 {
64 {
65 auto availableZones = getAvailableVisualizationZoneList();
65 auto availableZones = getAvailableVisualizationZoneList();
66 if (availableZones.isEmpty()) {
66 if (availableZones.isEmpty()) {
67 return QStringList{};
67 return QStringList{};
68 }
68 }
69
69
70 QDialog d(parent, Qt::Tool);
70 QDialog d(parent, Qt::Tool);
71 d.setWindowTitle("Choose a zone");
71 d.setWindowTitle("Choose a zone");
72 auto layout = new QVBoxLayout{&d};
72 auto layout = new QVBoxLayout{&d};
73 layout->setContentsMargins(0, 0, 0, 0);
73 layout->setContentsMargins(0, 0, 0, 0);
74 auto listWidget = new QListWidget{&d};
74 auto listWidget = new QListWidget{&d};
75 layout->addWidget(listWidget);
75 layout->addWidget(listWidget);
76
76
77 QSet<QListWidgetItem *> checkedItems;
77 QSet<QListWidgetItem *> checkedItems;
78 for (auto zone : availableZones) {
78 for (auto zone : availableZones) {
79 auto item = new QListWidgetItem{zone};
79 auto item = new QListWidgetItem{zone};
80 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
80 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
81 if (selectedZones.contains(zone)) {
81 if (selectedZones.contains(zone)) {
82 item->setCheckState(Qt::Checked);
82 item->setCheckState(Qt::Checked);
83 checkedItems << item;
83 checkedItems << item;
84 }
84 }
85 else {
85 else {
86 item->setCheckState(Qt::Unchecked);
86 item->setCheckState(Qt::Unchecked);
87 }
87 }
88
88
89 listWidget->addItem(item);
89 listWidget->addItem(item);
90 }
90 }
91
91
92 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
92 auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
93 layout->addWidget(buttonBox);
93 layout->addWidget(buttonBox);
94
94
95 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
95 QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
96 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
96 QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
97
97
98 QObject::connect(listWidget, &QListWidget::itemChanged,
98 QObject::connect(listWidget, &QListWidget::itemChanged,
99 [&checkedItems, allowMultiSelection, listWidget](auto item) {
99 [&checkedItems, allowMultiSelection, listWidget](auto item) {
100 if (item->checkState() == Qt::Checked) {
100 if (item->checkState() == Qt::Checked) {
101 if (!allowMultiSelection) {
101 if (!allowMultiSelection) {
102 for (auto checkedItem : checkedItems) {
102 for (auto checkedItem : checkedItems) {
103 listWidget->blockSignals(true);
103 listWidget->blockSignals(true);
104 checkedItem->setCheckState(Qt::Unchecked);
104 checkedItem->setCheckState(Qt::Unchecked);
105 listWidget->blockSignals(false);
105 listWidget->blockSignals(false);
106 }
106 }
107
107
108 checkedItems.clear();
108 checkedItems.clear();
109 }
109 }
110 checkedItems << item;
110 checkedItems << item;
111 }
111 }
112 else {
112 else {
113 checkedItems.remove(item);
113 checkedItems.remove(item);
114 }
114 }
115 });
115 });
116
116
117 QStringList result;
117 QStringList result;
118
118
119 d.setMinimumWidth(120);
119 d.setMinimumWidth(120);
120 d.resize(d.minimumSizeHint());
120 d.resize(d.minimumSizeHint());
121 d.move(location);
121 d.move(location);
122 if (d.exec() == QDialog::Accepted) {
122 if (d.exec() == QDialog::Accepted) {
123 for (auto item : checkedItems) {
123 for (auto item : checkedItems) {
124 result += item->text();
124 result += item->text();
125 }
125 }
126 }
126 }
127 else {
127 else {
128 result = selectedZones;
128 result = selectedZones;
129 }
129 }
130
130
131 return result;
131 return result;
132 }
132 }
133
133
134 void updateForTimeMode(QTableView *tableView)
134 void updateForTimeMode(QTableView *tableView)
135 {
135 {
136 auto selectedRows = tableView->selectionModel()->selectedRows();
136 auto selectedRows = tableView->selectionModel()->selectedRows();
137
137
138 if (selectedRows.count() == 1) {
138 if (selectedRows.count() == 1) {
139 auto event = m_Model->getEvent(selectedRows.first().row());
139 auto event = m_Model->getEvent(selectedRows.first().row());
140 if (m_VisualizationWidget) {
140 if (m_VisualizationWidget) {
141 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
141 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
142
142
143 for (auto zoneName : m_ZonesForTimeMode) {
143 for (auto zoneName : m_ZonesForTimeMode) {
144 if (auto zone = tab->getZoneWithName(zoneName)) {
144 if (auto zone = tab->getZoneWithName(zoneName)) {
145 SqpRange eventRange;
145 SqpRange eventRange;
146 eventRange.m_TStart = event.getTStart();
146 eventRange.m_TStart = event->getTStart();
147 eventRange.m_TEnd = event.getTEnd();
147 eventRange.m_TEnd = event->getTEnd();
148 zone->setZoneRange(eventRange);
148 zone->setZoneRange(eventRange);
149 }
149 }
150 }
150 }
151 }
151 }
152 else {
152 else {
153 qCWarning(LOG_CatalogueEventsWidget())
153 qCWarning(LOG_CatalogueEventsWidget())
154 << "updateTimeZone: no tab found in the visualization";
154 << "updateTimeZone: no tab found in the visualization";
155 }
155 }
156 }
156 }
157 else {
157 else {
158 qCWarning(LOG_CatalogueEventsWidget())
158 qCWarning(LOG_CatalogueEventsWidget())
159 << "updateTimeZone: visualization widget not found";
159 << "updateTimeZone: visualization widget not found";
160 }
160 }
161 }
161 }
162 else {
162 else {
163 qCWarning(LOG_CatalogueEventsWidget())
163 qCWarning(LOG_CatalogueEventsWidget())
164 << "updateTimeZone: not compatible with multiple events selected";
164 << "updateTimeZone: not compatible with multiple events selected";
165 }
165 }
166 }
166 }
167
167
168 void updateForGraphMode(QTableView *tableView)
168 void updateForGraphMode(QTableView *tableView)
169 {
169 {
170 auto selectedRows = tableView->selectionModel()->selectedRows();
170 auto selectedRows = tableView->selectionModel()->selectedRows();
171
171
172 if (selectedRows.count() == 1) {
172 if (selectedRows.count() == 1) {
173 auto event = m_Model->getEvent(selectedRows.first().row());
173 auto event = m_Model->getEvent(selectedRows.first().row());
174 if (m_VisualizationWidget) {
174 if (m_VisualizationWidget) {
175 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
175 if (auto tab = m_VisualizationWidget->currentTabWidget()) {
176 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
176 if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
177 // TODO
177 // TODO
178 }
178 }
179 }
179 }
180 else {
180 else {
181 qCWarning(LOG_CatalogueEventsWidget())
181 qCWarning(LOG_CatalogueEventsWidget())
182 << "updateGraphMode: no tab found in the visualization";
182 << "updateGraphMode: no tab found in the visualization";
183 }
183 }
184 }
184 }
185 else {
185 else {
186 qCWarning(LOG_CatalogueEventsWidget())
186 qCWarning(LOG_CatalogueEventsWidget())
187 << "updateGraphMode: visualization widget not found";
187 << "updateGraphMode: visualization widget not found";
188 }
188 }
189 }
189 }
190 else {
190 else {
191 qCWarning(LOG_CatalogueEventsWidget())
191 qCWarning(LOG_CatalogueEventsWidget())
192 << "updateGraphMode: not compatible with multiple events selected";
192 << "updateGraphMode: not compatible with multiple events selected";
193 }
193 }
194 }
194 }
195 };
195 };
196
196
197 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
197 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
198 : QWidget(parent),
198 : QWidget(parent),
199 ui(new Ui::CatalogueEventsWidget),
199 ui(new Ui::CatalogueEventsWidget),
200 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
200 impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
201 {
201 {
202 ui->setupUi(this);
202 ui->setupUi(this);
203
203
204 impl->m_Model = new CatalogueEventsTableModel{this};
204 impl->m_Model = new CatalogueEventsTableModel{this};
205 ui->tableView->setModel(impl->m_Model);
205 ui->tableView->setModel(impl->m_Model);
206
206
207 ui->tableView->setSortingEnabled(true);
207 ui->tableView->setSortingEnabled(true);
208 ui->tableView->setDragDropMode(QAbstractItemView::DragDrop);
208 ui->tableView->setDragDropMode(QAbstractItemView::DragDrop);
209 ui->tableView->setDragEnabled(true);
209 ui->tableView->setDragEnabled(true);
210
210
211 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
211 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
212 if (checked) {
212 if (checked) {
213 ui->btnChart->setChecked(false);
213 ui->btnChart->setChecked(false);
214 impl->m_ZonesForTimeMode
214 impl->m_ZonesForTimeMode
215 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
215 = impl->selectZone(this, impl->m_ZonesForTimeMode, true,
216 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
216 this->mapToGlobal(ui->btnTime->frameGeometry().center()));
217
217
218 impl->updateForTimeMode(ui->tableView);
218 impl->updateForTimeMode(ui->tableView);
219 }
219 }
220 });
220 });
221
221
222 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
222 connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
223 if (checked) {
223 if (checked) {
224 ui->btnTime->setChecked(false);
224 ui->btnTime->setChecked(false);
225 impl->m_ZoneForGraphMode
225 impl->m_ZoneForGraphMode
226 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
226 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
227 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
227 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
228 .value(0);
228 .value(0);
229
229
230 impl->updateForGraphMode(ui->tableView);
230 impl->updateForGraphMode(ui->tableView);
231 }
231 }
232 });
232 });
233
233
234 auto emitSelection = [this]() {
234 auto emitSelection = [this]() {
235 QVector<DBEvent> events;
235 QVector<std::shared_ptr<DBEvent> > events;
236 for (auto rowIndex : ui->tableView->selectionModel()->selectedRows()) {
236 for (auto rowIndex : ui->tableView->selectionModel()->selectedRows()) {
237 events << impl->m_Model->getEvent(rowIndex.row());
237 events << impl->m_Model->getEvent(rowIndex.row());
238 }
238 }
239
239
240 emit this->eventsSelected(events);
240 emit this->eventsSelected(events);
241 };
241 };
242
242
243 connect(ui->tableView, &QTableView::clicked, emitSelection);
243 connect(ui->tableView, &QTableView::clicked, emitSelection);
244 connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
244 connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
245
245
246 connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
246 connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
247 auto isNotMultiSelection = ui->tableView->selectionModel()->selectedRows().count() <= 1;
247 auto isNotMultiSelection = ui->tableView->selectionModel()->selectedRows().count() <= 1;
248 ui->btnChart->setEnabled(isNotMultiSelection);
248 ui->btnChart->setEnabled(isNotMultiSelection);
249 ui->btnTime->setEnabled(isNotMultiSelection);
249 ui->btnTime->setEnabled(isNotMultiSelection);
250
250
251 if (isNotMultiSelection && ui->btnTime->isChecked()) {
251 if (isNotMultiSelection && ui->btnTime->isChecked()) {
252 impl->updateForTimeMode(ui->tableView);
252 impl->updateForTimeMode(ui->tableView);
253 }
253 }
254 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
254 else if (isNotMultiSelection && ui->btnChart->isChecked()) {
255 impl->updateForGraphMode(ui->tableView);
255 impl->updateForGraphMode(ui->tableView);
256 }
256 }
257 });
257 });
258
258
259 ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
259 ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
260 ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
260 ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
261 ui->tableView->horizontalHeader()->setSortIndicatorShown(true);
261 ui->tableView->horizontalHeader()->setSortIndicatorShown(true);
262 }
262 }
263
263
264 CatalogueEventsWidget::~CatalogueEventsWidget()
264 CatalogueEventsWidget::~CatalogueEventsWidget()
265 {
265 {
266 delete ui;
266 delete ui;
267 }
267 }
268
268
269 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
269 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
270 {
270 {
271 impl->m_VisualizationWidget = visualization;
271 impl->m_VisualizationWidget = visualization;
272 }
272 }
273
273
274 void CatalogueEventsWidget::populateWithCatalogues(const QVector<DBCatalogue> &catalogues)
274 void CatalogueEventsWidget::populateWithCatalogues(
275 const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
275 {
276 {
276 auto &dao = sqpApp->catalogueController().getDao();
277
278 QSet<QUuid> eventIds;
277 QSet<QUuid> eventIds;
279 QVector<DBEvent> events;
278 QVector<std::shared_ptr<DBEvent> > events;
280
279
281 for (auto catalogue : catalogues) {
280 for (auto catalogue : catalogues) {
282 auto catalogueEvents = dao.getCatalogueEvents(catalogue);
281 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
283 for (auto event : catalogueEvents) {
282 for (auto event : catalogueEvents) {
284 if (!eventIds.contains(event.getUniqId())) {
283 if (!eventIds.contains(event->getUniqId())) {
285 events << event;
284 events << event;
286 eventIds.insert(event.getUniqId());
285 eventIds.insert(event->getUniqId());
287 }
286 }
288 }
287 }
289 }
288 }
290
289
291 impl->setEvents(events, ui->tableView);
290 impl->setEvents(events, ui->tableView);
292 }
291 }
@@ -1,56 +1,56
1 #include "Catalogue/CatalogueInspectorWidget.h"
1 #include "Catalogue/CatalogueInspectorWidget.h"
2 #include "ui_CatalogueInspectorWidget.h"
2 #include "ui_CatalogueInspectorWidget.h"
3
3
4 #include <Common/DateUtils.h>
4 #include <Common/DateUtils.h>
5 #include <DBCatalogue.h>
5 #include <DBCatalogue.h>
6 #include <DBEvent.h>
6 #include <DBEvent.h>
7 #include <DBTag.h>
7 #include <DBTag.h>
8
8
9 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
9 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
10 : QWidget(parent), ui(new Ui::CatalogueInspectorWidget)
10 : QWidget(parent), ui(new Ui::CatalogueInspectorWidget)
11 {
11 {
12 ui->setupUi(this);
12 ui->setupUi(this);
13 showPage(Page::Empty);
13 showPage(Page::Empty);
14 }
14 }
15
15
16 CatalogueInspectorWidget::~CatalogueInspectorWidget()
16 CatalogueInspectorWidget::~CatalogueInspectorWidget()
17 {
17 {
18 delete ui;
18 delete ui;
19 }
19 }
20
20
21 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
21 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
22 {
22 {
23 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
23 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
24 }
24 }
25
25
26 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
26 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
27 {
27 {
28 return static_cast<Page>(ui->stackedWidget->currentIndex());
28 return static_cast<Page>(ui->stackedWidget->currentIndex());
29 }
29 }
30
30
31 void CatalogueInspectorWidget::setEvent(const DBEvent &event)
31 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
32 {
32 {
33 showPage(Page::EventProperties);
33 showPage(Page::EventProperties);
34 ui->leEventName->setText(event.getName());
34 ui->leEventName->setText(event->getName());
35 ui->leEventMission->setText(event.getMission());
35 ui->leEventMission->setText(event->getMission());
36 ui->leEventProduct->setText(event.getProduct());
36 ui->leEventProduct->setText(event->getProduct());
37
37
38 QString tagList;
38 QString tagList;
39 auto tags = const_cast<DBEvent *>(&event)->getTags();
39 auto tags = event->getTags();
40 for (auto tag : tags) {
40 for (auto tag : tags) {
41 tagList += tag.getName();
41 tagList += tag.getName();
42 tagList += ' ';
42 tagList += ' ';
43 }
43 }
44
44
45 ui->leEventTags->setText(tagList);
45 ui->leEventTags->setText(tagList);
46
46
47 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event.getTStart()));
47 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
48 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event.getTEnd()));
48 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
49 }
49 }
50
50
51 void CatalogueInspectorWidget::setCatalogue(const DBCatalogue &catalogue)
51 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
52 {
52 {
53 showPage(Page::CatalogueProperties);
53 showPage(Page::CatalogueProperties);
54 ui->leCatalogueName->setText(catalogue.getName());
54 ui->leCatalogueName->setText(catalogue->getName());
55 ui->leCatalogueAuthor->setText(catalogue.getAuthor());
55 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
56 }
56 }
@@ -1,203 +1,198
1 #include "Catalogue/CatalogueSideBarWidget.h"
1 #include "Catalogue/CatalogueSideBarWidget.h"
2 #include "ui_CatalogueSideBarWidget.h"
2 #include "ui_CatalogueSideBarWidget.h"
3 #include <SqpApplication.h>
3 #include <SqpApplication.h>
4
4
5 #include <Catalogue/CatalogueController.h>
5 #include <Catalogue/CatalogueController.h>
6 #include <Catalogue/CatalogueTreeWidgetItem.h>
6 #include <Catalogue/CatalogueTreeWidgetItem.h>
7 #include <CatalogueDao.h>
7 #include <CatalogueDao.h>
8 #include <ComparaisonPredicate.h>
8 #include <ComparaisonPredicate.h>
9 #include <DBCatalogue.h>
9 #include <DBCatalogue.h>
10
10
11 #include <QMenu>
11 #include <QMenu>
12
12
13
13
14 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
14 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
15 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
15 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
16 constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2;
16 constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2;
17 constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3;
17 constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3;
18
18
19
19
20 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
20 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
21
21
22 QHash<QTreeWidgetItem *, DBCatalogue> m_CatalogueMap;
23
24 void configureTreeWidget(QTreeWidget *treeWidget);
22 void configureTreeWidget(QTreeWidget *treeWidget);
25 QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget);
23 QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget);
26 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
24 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
27 void addCatalogueItem(const DBCatalogue &catalogue, QTreeWidgetItem *parentDatabaseItem);
25 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
26 QTreeWidgetItem *parentDatabaseItem);
28 };
27 };
29
28
30 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
29 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
31 : QWidget(parent),
30 : QWidget(parent),
32 ui(new Ui::CatalogueSideBarWidget),
31 ui(new Ui::CatalogueSideBarWidget),
33 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
32 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
34 {
33 {
35 ui->setupUi(this);
34 ui->setupUi(this);
36 impl->configureTreeWidget(ui->treeWidget);
35 impl->configureTreeWidget(ui->treeWidget);
37
36
38 ui->treeWidget->setColumnCount(2);
37 ui->treeWidget->setColumnCount(2);
39 ui->treeWidget->header()->setStretchLastSection(false);
38 ui->treeWidget->header()->setStretchLastSection(false);
40 ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
39 ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
41 ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
40 ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
42
41
43 auto emitSelection = [this]() {
42 auto emitSelection = [this]() {
44
43
45 auto selectedItems = ui->treeWidget->selectedItems();
44 auto selectedItems = ui->treeWidget->selectedItems();
46 if (selectedItems.isEmpty()) {
45 if (selectedItems.isEmpty()) {
47 emit this->selectionCleared();
46 emit this->selectionCleared();
48 }
47 }
49 else {
48 else {
50 QVector<DBCatalogue> catalogues;
49 QVector<std::shared_ptr<DBCatalogue> > catalogues;
51 QStringList databases;
50 QStringList databases;
52 int selectionType = selectedItems.first()->type();
51 int selectionType = selectedItems.first()->type();
53
52
54 for (auto item : ui->treeWidget->selectedItems()) {
53 for (auto item : ui->treeWidget->selectedItems()) {
55 if (item->type() == selectionType) {
54 if (item->type() == selectionType) {
56 switch (selectionType) {
55 switch (selectionType) {
57 case CATALOGUE_ITEM_TYPE:
56 case CATALOGUE_ITEM_TYPE:
58 catalogues.append(
57 catalogues.append(
59 static_cast<CatalogueTreeWidgetItem *>(item)->catalogue());
58 static_cast<CatalogueTreeWidgetItem *>(item)->catalogue());
60 break;
59 break;
61 case DATABASE_ITEM_TYPE:
60 case DATABASE_ITEM_TYPE:
62 selectionType = DATABASE_ITEM_TYPE;
61 selectionType = DATABASE_ITEM_TYPE;
63 databases.append(item->text(0));
62 databases.append(item->text(0));
64 case ALL_EVENT_ITEM_TYPE: // fallthrough
63 case ALL_EVENT_ITEM_TYPE: // fallthrough
65 case TRASH_ITEM_TYPE: // fallthrough
64 case TRASH_ITEM_TYPE: // fallthrough
66 default:
65 default:
67 break;
66 break;
68 }
67 }
69 }
68 }
70 else {
69 else {
71 // Incoherent multi selection
70 // Incoherent multi selection
72 selectionType = -1;
71 selectionType = -1;
73 break;
72 break;
74 }
73 }
75 }
74 }
76
75
77 switch (selectionType) {
76 switch (selectionType) {
78 case CATALOGUE_ITEM_TYPE:
77 case CATALOGUE_ITEM_TYPE:
79 emit this->catalogueSelected(catalogues);
78 emit this->catalogueSelected(catalogues);
80 break;
79 break;
81 case DATABASE_ITEM_TYPE:
80 case DATABASE_ITEM_TYPE:
82 emit this->databaseSelected(databases);
81 emit this->databaseSelected(databases);
83 break;
82 break;
84 case ALL_EVENT_ITEM_TYPE:
83 case ALL_EVENT_ITEM_TYPE:
85 emit this->allEventsSelected();
84 emit this->allEventsSelected();
86 break;
85 break;
87 case TRASH_ITEM_TYPE:
86 case TRASH_ITEM_TYPE:
88 emit this->trashSelected();
87 emit this->trashSelected();
89 break;
88 break;
90 default:
89 default:
91 emit this->selectionCleared();
90 emit this->selectionCleared();
92 break;
91 break;
93 }
92 }
94 }
93 }
95
94
96
95
97 };
96 };
98
97
99 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
98 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
100 connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection);
99 connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection);
101
100
102 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
101 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
103 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
102 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
104 &CatalogueSideBarWidget::onContextMenuRequested);
103 &CatalogueSideBarWidget::onContextMenuRequested);
105 }
104 }
106
105
107 CatalogueSideBarWidget::~CatalogueSideBarWidget()
106 CatalogueSideBarWidget::~CatalogueSideBarWidget()
108 {
107 {
109 delete ui;
108 delete ui;
110 }
109 }
111
110
112 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
111 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
113 {
112 {
114 QMenu menu{this};
113 QMenu menu{this};
115
114
116 auto currentItem = ui->treeWidget->currentItem();
115 auto currentItem = ui->treeWidget->currentItem();
117 switch (currentItem->type()) {
116 switch (currentItem->type()) {
118 case CATALOGUE_ITEM_TYPE:
117 case CATALOGUE_ITEM_TYPE:
119 menu.addAction("Rename",
118 menu.addAction("Rename",
120 [this, currentItem]() { ui->treeWidget->editItem(currentItem); });
119 [this, currentItem]() { ui->treeWidget->editItem(currentItem); });
121 break;
120 break;
122 case DATABASE_ITEM_TYPE:
121 case DATABASE_ITEM_TYPE:
123 break;
122 break;
124 case ALL_EVENT_ITEM_TYPE:
123 case ALL_EVENT_ITEM_TYPE:
125 break;
124 break;
126 case TRASH_ITEM_TYPE:
125 case TRASH_ITEM_TYPE:
127 menu.addAction("Empty Trash", []() {
126 menu.addAction("Empty Trash", []() {
128 // TODO
127 // TODO
129 });
128 });
130 break;
129 break;
131 default:
130 default:
132 break;
131 break;
133 }
132 }
134
133
135 if (!menu.isEmpty()) {
134 if (!menu.isEmpty()) {
136 menu.exec(ui->treeWidget->mapToGlobal(pos));
135 menu.exec(ui->treeWidget->mapToGlobal(pos));
137 }
136 }
138 }
137 }
139
138
140 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(
139 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(
141 QTreeWidget *treeWidget)
140 QTreeWidget *treeWidget)
142 {
141 {
143 auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE};
142 auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE};
144 allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png"));
143 allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png"));
145 treeWidget->addTopLevelItem(allEventsItem);
144 treeWidget->addTopLevelItem(allEventsItem);
146
145
147 auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE};
146 auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE};
148 trashItem->setIcon(0, QIcon(":/icones/trash.png"));
147 trashItem->setIcon(0, QIcon(":/icones/trash.png"));
149 treeWidget->addTopLevelItem(trashItem);
148 treeWidget->addTopLevelItem(trashItem);
150
149
151 auto separator = new QFrame{treeWidget};
150 auto separator = new QFrame{treeWidget};
152 separator->setFrameShape(QFrame::HLine);
151 separator->setFrameShape(QFrame::HLine);
153 auto separatorItem = new QTreeWidgetItem{};
152 auto separatorItem = new QTreeWidgetItem{};
154 separatorItem->setFlags(Qt::NoItemFlags);
153 separatorItem->setFlags(Qt::NoItemFlags);
155 treeWidget->addTopLevelItem(separatorItem);
154 treeWidget->addTopLevelItem(separatorItem);
156 treeWidget->setItemWidget(separatorItem, 0, separator);
155 treeWidget->setItemWidget(separatorItem, 0, separator);
157
156
158 auto &dao = sqpApp->catalogueController().getDao();
159 auto allPredicate = std::make_shared<ComparaisonPredicate>(QString{"uniqId"}, "-1",
160 ComparaisonOperation::DIFFERENT);
161
162 auto db = addDatabaseItem("Default", treeWidget);
157 auto db = addDatabaseItem("Default", treeWidget);
163
158
164 auto catalogues = dao.getCatalogues(allPredicate);
159 auto catalogues = sqpApp->catalogueController().getCatalogues("Default");
165 for (auto catalogue : catalogues) {
160 for (auto catalogue : catalogues) {
166 addCatalogueItem(catalogue, db);
161 addCatalogueItem(catalogue, db);
167 }
162 }
168
163
169 treeWidget->expandAll();
164 treeWidget->expandAll();
170 }
165 }
171
166
172 QTreeWidgetItem *
167 QTreeWidgetItem *
173 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name,
168 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name,
174 QTreeWidget *treeWidget)
169 QTreeWidget *treeWidget)
175 {
170 {
176 auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE};
171 auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE};
177 databaseItem->setIcon(0, QIcon{":/icones/database.png"});
172 databaseItem->setIcon(0, QIcon{":/icones/database.png"});
178 treeWidget->addTopLevelItem(databaseItem);
173 treeWidget->addTopLevelItem(databaseItem);
179
174
180 return databaseItem;
175 return databaseItem;
181 }
176 }
182
177
183 QTreeWidgetItem *
178 QTreeWidgetItem *
184 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name,
179 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name,
185 QTreeWidget *treeWidget)
180 QTreeWidget *treeWidget)
186 {
181 {
187 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
182 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
188 auto item = treeWidget->topLevelItem(i);
183 auto item = treeWidget->topLevelItem(i);
189 if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) {
184 if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) {
190 return item;
185 return item;
191 }
186 }
192 }
187 }
193
188
194 return nullptr;
189 return nullptr;
195 }
190 }
196
191
197 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
192 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
198 const DBCatalogue &catalogue, QTreeWidgetItem *parentDatabaseItem)
193 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidgetItem *parentDatabaseItem)
199 {
194 {
200 auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE};
195 auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE};
201 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
196 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
202 parentDatabaseItem->addChild(catalogueItem);
197 parentDatabaseItem->addChild(catalogueItem);
203 }
198 }
@@ -1,90 +1,93
1 #include "Catalogue/CatalogueTreeWidgetItem.h"
1 #include "Catalogue/CatalogueTreeWidgetItem.h"
2
2
3 #include <memory>
3 #include <memory>
4
4
5 #include <DBCatalogue.h>
5 #include <QBoxLayout>
6 #include <QBoxLayout>
6 #include <QToolButton>
7 #include <QToolButton>
7
8
8 const auto VALIDATION_BUTTON_ICON_SIZE = 12;
9 const auto VALIDATION_BUTTON_ICON_SIZE = 12;
9
10
10 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
11 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
11
12
12 DBCatalogue m_Catalogue;
13 std::shared_ptr<DBCatalogue> m_Catalogue;
13
14
14 CatalogueTreeWidgetItemPrivate(DBCatalogue catalogue) : m_Catalogue(catalogue) {}
15 CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue)
16 {
17 }
15 };
18 };
16
19
17
20
18 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(DBCatalogue catalogue, int type)
21 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type)
19 : QTreeWidgetItem(type),
22 : QTreeWidgetItem(type),
20 impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
23 impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
21 {
24 {
22 setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
25 setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
23 }
26 }
24
27
25 QVariant CatalogueTreeWidgetItem::data(int column, int role) const
28 QVariant CatalogueTreeWidgetItem::data(int column, int role) const
26 {
29 {
27 if (column == 0) {
30 if (column == 0) {
28 switch (role) {
31 switch (role) {
29 case Qt::EditRole: // fallthrough
32 case Qt::EditRole: // fallthrough
30 case Qt::DisplayRole:
33 case Qt::DisplayRole:
31 return impl->m_Catalogue.getName();
34 return impl->m_Catalogue->getName();
32 default:
35 default:
33 break;
36 break;
34 }
37 }
35 }
38 }
36
39
37 return QTreeWidgetItem::data(column, role);
40 return QTreeWidgetItem::data(column, role);
38 }
41 }
39
42
40 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &value)
43 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &value)
41 {
44 {
42 if (role == Qt::EditRole && column == 0) {
45 if (role == Qt::EditRole && column == 0) {
43 auto newName = value.toString();
46 auto newName = value.toString();
44 if (newName != impl->m_Catalogue.getName()) {
47 if (newName != impl->m_Catalogue->getName()) {
45 setText(0, newName);
48 setText(0, newName);
46 impl->m_Catalogue.setName(newName);
49 impl->m_Catalogue->setName(newName);
47 setHasChanges(true);
50 setHasChanges(true);
48 }
51 }
49 }
52 }
50 else {
53 else {
51 QTreeWidgetItem::setData(column, role, value);
54 QTreeWidgetItem::setData(column, role, value);
52 }
55 }
53 }
56 }
54
57
55 DBCatalogue CatalogueTreeWidgetItem::catalogue() const
58 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
56 {
59 {
57 return impl->m_Catalogue;
60 return impl->m_Catalogue;
58 }
61 }
59
62
60 void CatalogueTreeWidgetItem::setHasChanges(bool value)
63 void CatalogueTreeWidgetItem::setHasChanges(bool value)
61 {
64 {
62 if (value) {
65 if (value) {
63 auto widet = new QWidget{treeWidget()};
66 auto widet = new QWidget{treeWidget()};
64
67
65 auto layout = new QHBoxLayout{widet};
68 auto layout = new QHBoxLayout{widet};
66 layout->setContentsMargins(0, 0, 0, 0);
69 layout->setContentsMargins(0, 0, 0, 0);
67 layout->setSpacing(0);
70 layout->setSpacing(0);
68
71
69 auto btnValid = new QToolButton{widet};
72 auto btnValid = new QToolButton{widet};
70 btnValid->setIcon(QIcon{":/icones/save"});
73 btnValid->setIcon(QIcon{":/icones/save"});
71 btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
74 btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
72 btnValid->setAutoRaise(true);
75 btnValid->setAutoRaise(true);
73 QObject::connect(btnValid, &QToolButton::clicked, [this]() { setHasChanges(false); });
76 QObject::connect(btnValid, &QToolButton::clicked, [this]() { setHasChanges(false); });
74 layout->addWidget(btnValid);
77 layout->addWidget(btnValid);
75
78
76 auto btnDiscard = new QToolButton{widet};
79 auto btnDiscard = new QToolButton{widet};
77 btnDiscard->setIcon(QIcon{":/icones/discard"});
80 btnDiscard->setIcon(QIcon{":/icones/discard"});
78 btnDiscard->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
81 btnDiscard->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
79 btnDiscard->setAutoRaise(true);
82 btnDiscard->setAutoRaise(true);
80 QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); });
83 QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); });
81 layout->addWidget(btnDiscard);
84 layout->addWidget(btnDiscard);
82
85
83 treeWidget()->setItemWidget(this, 1, {widet});
86 treeWidget()->setItemWidget(this, 1, {widet});
84 treeWidget()->resizeColumnToContents(1);
87 treeWidget()->resizeColumnToContents(1);
85 }
88 }
86 else {
89 else {
87 // Note: the widget is destroyed
90 // Note: the widget is destroyed
88 treeWidget()->setItemWidget(this, 1, nullptr);
91 treeWidget()->setItemWidget(this, 1, nullptr);
89 }
92 }
90 }
93 }
General Comments 0
You need to be logged in to leave comments. Login now