@@ -1,84 +1,84 | |||||
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 | class DBEventProduct; |
|
18 | class DBEventProduct; | |
19 |
|
19 | |||
20 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController) |
|
20 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController) | |
21 |
|
21 | |||
22 | class DataSourceItem; |
|
22 | class DataSourceItem; | |
23 | class Variable; |
|
23 | class Variable; | |
24 |
|
24 | |||
25 | /** |
|
25 | /** | |
26 | * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI |
|
26 | * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI | |
27 | * library. |
|
27 | * library. | |
28 | */ |
|
28 | */ | |
29 | class SCIQLOP_CORE_EXPORT CatalogueController : public QObject { |
|
29 | class SCIQLOP_CORE_EXPORT CatalogueController : public QObject { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | public: |
|
31 | public: | |
32 | explicit CatalogueController(QObject *parent = 0); |
|
32 | explicit CatalogueController(QObject *parent = 0); | |
33 | virtual ~CatalogueController(); |
|
33 | virtual ~CatalogueController(); | |
34 |
|
34 | |||
35 | // DB |
|
35 | // DB | |
36 | QStringList getRepositories() const; |
|
36 | QStringList getRepositories() const; | |
37 | void addDB(const QString &dbPath); |
|
37 | void addDB(const QString &dbPath); | |
38 | void saveDB(const QString &destinationPath, const QString &repository); |
|
38 | void saveDB(const QString &destinationPath, const QString &repository); | |
39 |
|
39 | |||
40 | // Event |
|
40 | // Event | |
41 | /// retrieveEvents with empty repository retrieve them from the default repository |
|
41 | /// retrieveEvents with empty repository retrieve them from the default repository | |
42 | std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const; |
|
42 | std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const; | |
43 | std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const; |
|
43 | std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const; | |
44 |
|
44 | |||
45 | void addEvent(std::shared_ptr<DBEvent> event); |
|
45 | void addEvent(std::shared_ptr<DBEvent> event); | |
46 | void updateEvent(std::shared_ptr<DBEvent> event); |
|
46 | void updateEvent(std::shared_ptr<DBEvent> event); | |
47 | void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct); |
|
47 | void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct); | |
48 | void removeEvent(std::shared_ptr<DBEvent> event); |
|
48 | void removeEvent(std::shared_ptr<DBEvent> event); | |
49 | // void trashEvent(std::shared_ptr<DBEvent> event); |
|
49 | // void trashEvent(std::shared_ptr<DBEvent> event); | |
50 | // void restore(std::shared_ptr<DBEvent> event); |
|
50 | // void restore(std::shared_ptr<DBEvent> event); | |
51 | void saveEvent(std::shared_ptr<DBEvent> event); |
|
51 | void saveEvent(std::shared_ptr<DBEvent> event); | |
52 | void discardEvent(std::shared_ptr<DBEvent> event); |
|
52 | void discardEvent(std::shared_ptr<DBEvent> event, bool &removed); | |
53 | bool eventHasChanges(std::shared_ptr<DBEvent> event) const; |
|
53 | bool eventHasChanges(std::shared_ptr<DBEvent> event) const; | |
54 |
|
54 | |||
55 | // Catalogue |
|
55 | // Catalogue | |
56 | std::list<std::shared_ptr<DBEvent> > |
|
56 | std::list<std::shared_ptr<DBEvent> > | |
57 | retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const; |
|
57 | retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const; | |
58 | // bool createCatalogue(const QString &name, QVector<QUuid> eventList); |
|
58 | // bool createCatalogue(const QString &name, QVector<QUuid> eventList); | |
59 | /// retrieveEvents with empty repository retrieve them from the default repository |
|
59 | /// retrieveEvents with empty repository retrieve them from the default repository | |
60 | std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository |
|
60 | std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository | |
61 | = QString()) const; |
|
61 | = QString()) const; | |
62 | void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue); |
|
62 | void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue); | |
63 | void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue); |
|
63 | void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue); | |
64 | void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue); |
|
64 | void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue); | |
65 |
|
65 | |||
66 | void saveAll(); |
|
66 | void saveAll(); | |
67 | bool hasChanges() const; |
|
67 | bool hasChanges() const; | |
68 |
|
68 | |||
69 | /// Returns the MIME data associated to a list of variables |
|
69 | /// Returns the MIME data associated to a list of variables | |
70 | QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const; |
|
70 | QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const; | |
71 |
|
71 | |||
72 | /// Returns the list of variables contained in a MIME data |
|
72 | /// Returns the list of variables contained in a MIME data | |
73 | QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const; |
|
73 | QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const; | |
74 |
|
74 | |||
75 | public slots: |
|
75 | public slots: | |
76 | /// Manage init/end of the controller |
|
76 | /// Manage init/end of the controller | |
77 | void initialize(); |
|
77 | void initialize(); | |
78 |
|
78 | |||
79 | private: |
|
79 | private: | |
80 | class CatalogueControllerPrivate; |
|
80 | class CatalogueControllerPrivate; | |
81 | spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl; |
|
81 | spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl; | |
82 | }; |
|
82 | }; | |
83 |
|
83 | |||
84 | #endif // SCIQLOP_CATALOGUECONTROLLER_H |
|
84 | #endif // SCIQLOP_CATALOGUECONTROLLER_H |
@@ -1,434 +1,461 | |||||
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 <DBEventProduct.h> |
|
11 | #include <DBEventProduct.h> | |
12 | #include <DBTag.h> |
|
12 | #include <DBTag.h> | |
13 | #include <IRequestPredicate.h> |
|
13 | #include <IRequestPredicate.h> | |
14 |
|
14 | |||
15 | #include <QDataStream> |
|
15 | #include <QDataStream> | |
16 | #include <QMutex> |
|
16 | #include <QMutex> | |
17 | #include <QThread> |
|
17 | #include <QThread> | |
18 |
|
18 | |||
19 | #include <QDir> |
|
19 | #include <QDir> | |
20 | #include <QStandardPaths> |
|
20 | #include <QStandardPaths> | |
21 |
|
21 | |||
22 | Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController") |
|
22 | Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController") | |
23 |
|
23 | |||
24 | namespace { |
|
24 | namespace { | |
25 |
|
25 | |||
26 | static QString REPOSITORY_WORK_SUFFIX = QString{"_work"}; |
|
26 | static QString REPOSITORY_WORK_SUFFIX = QString{"_work"}; | |
27 | static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"}; |
|
27 | static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"}; | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | class CatalogueController::CatalogueControllerPrivate { |
|
30 | class CatalogueController::CatalogueControllerPrivate { | |
31 |
|
31 | |||
32 | public: |
|
32 | public: | |
33 | explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {} |
|
33 | explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {} | |
34 |
|
34 | |||
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; |
|
40 | QSet<QString> m_EventKeysWithChanges; | |
41 |
|
41 | |||
42 | QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const; |
|
42 | QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const; | |
43 |
|
43 | |||
44 | void copyDBtoDB(const QString &dbFrom, const QString &dbTo); |
|
44 | void copyDBtoDB(const QString &dbFrom, const QString &dbTo); | |
45 | QString toWorkRepository(QString repository); |
|
45 | QString toWorkRepository(QString repository); | |
46 | QString toSyncRepository(QString repository); |
|
46 | QString toSyncRepository(QString repository); | |
47 | void savAllDB(); |
|
47 | void savAllDB(); | |
48 |
|
48 | |||
49 | void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true); |
|
49 | void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true); | |
50 | void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true); |
|
50 | void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true); | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | CatalogueController::CatalogueController(QObject *parent) |
|
53 | CatalogueController::CatalogueController(QObject *parent) | |
54 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)} |
|
54 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)} | |
55 | { |
|
55 | { | |
56 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") |
|
56 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") | |
57 | << QThread::currentThread(); |
|
57 | << QThread::currentThread(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | CatalogueController::~CatalogueController() |
|
60 | CatalogueController::~CatalogueController() | |
61 | { |
|
61 | { | |
62 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction") |
|
62 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction") | |
63 | << QThread::currentThread(); |
|
63 | << QThread::currentThread(); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QStringList CatalogueController::getRepositories() const |
|
66 | QStringList CatalogueController::getRepositories() const | |
67 | { |
|
67 | { | |
68 | return impl->m_RepositoryList; |
|
68 | return impl->m_RepositoryList; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void CatalogueController::addDB(const QString &dbPath) |
|
71 | void CatalogueController::addDB(const QString &dbPath) | |
72 | { |
|
72 | { | |
73 | QDir dbDir(dbPath); |
|
73 | QDir dbDir(dbPath); | |
74 | if (dbDir.exists()) { |
|
74 | if (dbDir.exists()) { | |
75 | auto dirName = dbDir.dirName(); |
|
75 | auto dirName = dbDir.dirName(); | |
76 |
|
76 | |||
77 | if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName) |
|
77 | if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName) | |
78 | != impl->m_RepositoryList.cend()) { |
|
78 | != impl->m_RepositoryList.cend()) { | |
79 | qCCritical(LOG_CatalogueController()) |
|
79 | qCCritical(LOG_CatalogueController()) | |
80 | << tr("Impossible to addDB that is already loaded"); |
|
80 | << tr("Impossible to addDB that is already loaded"); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) { |
|
83 | if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) { | |
84 | qCCritical(LOG_CatalogueController()) |
|
84 | qCCritical(LOG_CatalogueController()) | |
85 | << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); |
|
85 | << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); | |
86 | } |
|
86 | } | |
87 | else { |
|
87 | else { | |
88 | impl->m_RepositoryList << dirName; |
|
88 | impl->m_RepositoryList << dirName; | |
89 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); |
|
89 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); | |
90 | } |
|
90 | } | |
91 | } |
|
91 | } | |
92 | else { |
|
92 | else { | |
93 | qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ") |
|
93 | qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ") | |
94 | << dbPath; |
|
94 | << dbPath; | |
95 | } |
|
95 | } | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void CatalogueController::saveDB(const QString &destinationPath, const QString &repository) |
|
98 | void CatalogueController::saveDB(const QString &destinationPath, const QString &repository) | |
99 | { |
|
99 | { | |
100 | if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) { |
|
100 | if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) { | |
101 | qCCritical(LOG_CatalogueController()) |
|
101 | qCCritical(LOG_CatalogueController()) | |
102 | << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath); |
|
102 | << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath); | |
103 | } |
|
103 | } | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | std::list<std::shared_ptr<DBEvent> > |
|
106 | std::list<std::shared_ptr<DBEvent> > | |
107 | CatalogueController::retrieveEvents(const QString &repository) const |
|
107 | CatalogueController::retrieveEvents(const QString &repository) const | |
108 | { |
|
108 | { | |
109 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; |
|
109 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; | |
110 |
|
110 | |||
111 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
111 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
112 | auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); |
|
112 | auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); | |
113 | for (auto event : events) { |
|
113 | for (auto event : events) { | |
114 | eventsShared.push_back(std::make_shared<DBEvent>(event)); |
|
114 | eventsShared.push_back(std::make_shared<DBEvent>(event)); | |
115 | } |
|
115 | } | |
116 | return eventsShared; |
|
116 | return eventsShared; | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const |
|
119 | std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const | |
120 | { |
|
120 | { | |
121 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
121 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
122 | for (auto repository : impl->m_RepositoryList) { |
|
122 | for (auto repository : impl->m_RepositoryList) { | |
123 | eventsShared.splice(eventsShared.end(), retrieveEvents(repository)); |
|
123 | eventsShared.splice(eventsShared.end(), retrieveEvents(repository)); | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | return eventsShared; |
|
126 | return eventsShared; | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | std::list<std::shared_ptr<DBEvent> > |
|
129 | std::list<std::shared_ptr<DBEvent> > | |
130 | CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const |
|
130 | CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const | |
131 | { |
|
131 | { | |
132 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
132 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
133 | auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue); |
|
133 | auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue); | |
134 | for (auto event : events) { |
|
134 | for (auto event : events) { | |
135 | eventsShared.push_back(std::make_shared<DBEvent>(event)); |
|
135 | eventsShared.push_back(std::make_shared<DBEvent>(event)); | |
136 | } |
|
136 | } | |
137 | return eventsShared; |
|
137 | return eventsShared; | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event) |
|
140 | void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event) | |
141 | { |
|
141 | { | |
142 | event->setRepository(impl->toWorkRepository(event->getRepository())); |
|
142 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |
143 |
|
143 | |||
144 | auto uniqueId = impl->eventUniqueKey(event); |
|
144 | auto uniqueId = impl->eventUniqueKey(event); | |
145 | impl->m_EventKeysWithChanges.insert(uniqueId); |
|
145 | impl->m_EventKeysWithChanges.insert(uniqueId); | |
146 |
|
146 | |||
147 | impl->m_CatalogueDao.updateEvent(*event); |
|
147 | impl->m_CatalogueDao.updateEvent(*event); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct) |
|
150 | void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct) | |
151 | { |
|
151 | { | |
152 | impl->m_CatalogueDao.updateEventProduct(*eventProduct); |
|
152 | impl->m_CatalogueDao.updateEventProduct(*eventProduct); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event) |
|
155 | void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event) | |
156 | { |
|
156 | { | |
157 | // Remove it from both repository and repository_work |
|
157 | // Remove it from both repository and repository_work | |
158 | event->setRepository(impl->toWorkRepository(event->getRepository())); |
|
158 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |
159 | impl->m_CatalogueDao.removeEvent(*event); |
|
159 | impl->m_CatalogueDao.removeEvent(*event); | |
160 | event->setRepository(impl->toSyncRepository(event->getRepository())); |
|
160 | event->setRepository(impl->toSyncRepository(event->getRepository())); | |
161 | impl->m_CatalogueDao.removeEvent(*event); |
|
161 | impl->m_CatalogueDao.removeEvent(*event); | |
162 | impl->savAllDB(); |
|
162 | impl->savAllDB(); | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | void CatalogueController::addEvent(std::shared_ptr<DBEvent> event) |
|
165 | void CatalogueController::addEvent(std::shared_ptr<DBEvent> event) | |
166 | { |
|
166 | { | |
167 | event->setRepository(impl->toWorkRepository(event->getRepository())); |
|
167 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |
168 |
|
168 | |||
169 | auto eventTemp = *event; |
|
169 | auto eventTemp = *event; | |
170 | impl->m_CatalogueDao.addEvent(eventTemp); |
|
170 | impl->m_CatalogueDao.addEvent(eventTemp); | |
171 |
|
171 | |||
172 | // Call update is necessary at the creation of add Event if it has some tags or some event |
|
172 | // Call update is necessary at the creation of add Event if it has some tags or some event | |
173 | // products |
|
173 | // products | |
174 | if (!event->getEventProducts().empty() || !event->getTags().empty()) { |
|
174 | if (!event->getEventProducts().empty() || !event->getTags().empty()) { | |
175 |
|
175 | |||
176 | auto eventProductsTemp = eventTemp.getEventProducts(); |
|
176 | auto eventProductsTemp = eventTemp.getEventProducts(); | |
177 | auto eventProductTempUpdated = std::list<DBEventProduct>{}; |
|
177 | auto eventProductTempUpdated = std::list<DBEventProduct>{}; | |
178 | for (auto eventProductTemp : eventProductsTemp) { |
|
178 | for (auto eventProductTemp : eventProductsTemp) { | |
179 | eventProductTemp.setEvent(eventTemp); |
|
179 | eventProductTemp.setEvent(eventTemp); | |
180 | eventProductTempUpdated.push_back(eventProductTemp); |
|
180 | eventProductTempUpdated.push_back(eventProductTemp); | |
181 | } |
|
181 | } | |
182 | eventTemp.setEventProducts(eventProductTempUpdated); |
|
182 | eventTemp.setEventProducts(eventProductTempUpdated); | |
183 |
|
183 | |||
184 | impl->m_CatalogueDao.updateEvent(eventTemp); |
|
184 | impl->m_CatalogueDao.updateEvent(eventTemp); | |
185 | } |
|
185 | } | |
|
186 | ||||
|
187 | ||||
|
188 | // update event parameter | |||
|
189 | auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>( | |||
|
190 | QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL); | |||
|
191 | ||||
|
192 | auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>( | |||
|
193 | QString{"repository"}, impl->toWorkRepository(event->getRepository()), | |||
|
194 | ComparaisonOperation::EQUALEQUAL); | |||
|
195 | ||||
|
196 | auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND); | |||
|
197 | workPred->AddRequestPredicate(uniqIdPredicate); | |||
|
198 | workPred->AddRequestPredicate(workRepositoryPredicate); | |||
|
199 | ||||
|
200 | ||||
|
201 | auto workEvent = impl->m_CatalogueDao.getEvent(workPred); | |||
|
202 | *event = workEvent; | |||
186 | } |
|
203 | } | |
187 |
|
204 | |||
188 | void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event) |
|
205 | void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event) | |
189 | { |
|
206 | { | |
190 | impl->saveEvent(event, true); |
|
207 | impl->saveEvent(event, true); | |
191 | impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event)); |
|
208 | impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event)); | |
192 | } |
|
209 | } | |
193 |
|
210 | |||
194 | void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event) |
|
211 | void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &removed) | |
195 | { |
|
212 | { | |
196 | auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>( |
|
213 | auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>( | |
197 | QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL); |
|
214 | QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL); | |
198 |
|
215 | |||
199 | auto syncRepositoryPredicate = std::make_shared<ComparaisonPredicate>( |
|
216 | auto syncRepositoryPredicate = std::make_shared<ComparaisonPredicate>( | |
200 | QString{"repository"}, impl->toSyncRepository(event->getRepository()), |
|
217 | QString{"repository"}, impl->toSyncRepository(event->getRepository()), | |
201 | ComparaisonOperation::EQUALEQUAL); |
|
218 | ComparaisonOperation::EQUALEQUAL); | |
202 |
|
219 | |||
203 | auto syncPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND); |
|
220 | auto syncPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND); | |
204 | syncPred->AddRequestPredicate(uniqIdPredicate); |
|
221 | syncPred->AddRequestPredicate(uniqIdPredicate); | |
205 | syncPred->AddRequestPredicate(syncRepositoryPredicate); |
|
222 | syncPred->AddRequestPredicate(syncRepositoryPredicate); | |
206 |
|
223 | |||
207 |
|
224 | |||
208 | auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>( |
|
225 | auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>( | |
209 | QString{"repository"}, impl->toWorkRepository(event->getRepository()), |
|
226 | QString{"repository"}, impl->toWorkRepository(event->getRepository()), | |
210 | ComparaisonOperation::EQUALEQUAL); |
|
227 | ComparaisonOperation::EQUALEQUAL); | |
211 |
|
228 | |||
212 | auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND); |
|
229 | auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND); | |
213 | workPred->AddRequestPredicate(uniqIdPredicate); |
|
230 | workPred->AddRequestPredicate(uniqIdPredicate); | |
214 | workPred->AddRequestPredicate(workRepositoryPredicate); |
|
231 | workPred->AddRequestPredicate(workRepositoryPredicate); | |
215 |
|
232 | |||
216 |
|
233 | |||
217 | auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred); |
|
234 | auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred); | |
218 | impl->m_CatalogueDao.copyEvent(syncEvent, impl->toWorkRepository(event->getRepository()), true); |
|
235 | if (!syncEvent.getUniqId().isNull()) { | |
|
236 | removed = false; | |||
|
237 | impl->m_CatalogueDao.copyEvent(syncEvent, impl->toWorkRepository(event->getRepository()), | |||
|
238 | true); | |||
219 |
|
239 | |||
220 | auto workEvent = impl->m_CatalogueDao.getEvent(workPred); |
|
240 | auto workEvent = impl->m_CatalogueDao.getEvent(workPred); | |
221 | *event = workEvent; |
|
241 | *event = workEvent; | |
222 | impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event)); |
|
242 | impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event)); | |
223 | } |
|
243 | } | |
|
244 | else { | |||
|
245 | removed = true; | |||
|
246 | // Since the element wasn't in sync repository. Discard it means remove it | |||
|
247 | event->setRepository(impl->toWorkRepository(event->getRepository())); | |||
|
248 | impl->m_CatalogueDao.removeEvent(*event); | |||
|
249 | } | |||
|
250 | } | |||
224 |
|
251 | |||
225 | bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const |
|
252 | bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const | |
226 | { |
|
253 | { | |
227 | return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event)); |
|
254 | return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event)); | |
228 | } |
|
255 | } | |
229 |
|
256 | |||
230 | std::list<std::shared_ptr<DBCatalogue> > |
|
257 | std::list<std::shared_ptr<DBCatalogue> > | |
231 | CatalogueController::retrieveCatalogues(const QString &repository) const |
|
258 | CatalogueController::retrieveCatalogues(const QString &repository) const | |
232 | { |
|
259 | { | |
233 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; |
|
260 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; | |
234 |
|
261 | |||
235 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; |
|
262 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; | |
236 | auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); |
|
263 | auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); | |
237 | for (auto catalogue : catalogues) { |
|
264 | for (auto catalogue : catalogues) { | |
238 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); |
|
265 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); | |
239 | } |
|
266 | } | |
240 | return cataloguesShared; |
|
267 | return cataloguesShared; | |
241 | } |
|
268 | } | |
242 |
|
269 | |||
243 | void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
270 | void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
244 | { |
|
271 | { | |
245 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); |
|
272 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); | |
246 |
|
273 | |||
247 | impl->m_CatalogueDao.updateCatalogue(*catalogue); |
|
274 | impl->m_CatalogueDao.updateCatalogue(*catalogue); | |
248 | } |
|
275 | } | |
249 |
|
276 | |||
250 | void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
277 | void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
251 | { |
|
278 | { | |
252 | // Remove it from both repository and repository_work |
|
279 | // Remove it from both repository and repository_work | |
253 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); |
|
280 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); | |
254 | impl->m_CatalogueDao.removeCatalogue(*catalogue); |
|
281 | impl->m_CatalogueDao.removeCatalogue(*catalogue); | |
255 | catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); |
|
282 | catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); | |
256 | impl->m_CatalogueDao.removeCatalogue(*catalogue); |
|
283 | impl->m_CatalogueDao.removeCatalogue(*catalogue); | |
257 | } |
|
284 | } | |
258 |
|
285 | |||
259 | void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
286 | void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue) | |
260 | { |
|
287 | { | |
261 | impl->saveCatalogue(catalogue, true); |
|
288 | impl->saveCatalogue(catalogue, true); | |
262 | } |
|
289 | } | |
263 |
|
290 | |||
264 | void CatalogueController::saveAll() |
|
291 | void CatalogueController::saveAll() | |
265 | { |
|
292 | { | |
266 | for (auto repository : impl->m_RepositoryList) { |
|
293 | for (auto repository : impl->m_RepositoryList) { | |
267 | // Save Event |
|
294 | // Save Event | |
268 | auto events = this->retrieveEvents(repository); |
|
295 | auto events = this->retrieveEvents(repository); | |
269 | for (auto event : events) { |
|
296 | for (auto event : events) { | |
270 | impl->saveEvent(event, false); |
|
297 | impl->saveEvent(event, false); | |
271 | } |
|
298 | } | |
272 |
|
299 | |||
273 | // Save Catalogue |
|
300 | // Save Catalogue | |
274 | auto catalogues = this->retrieveCatalogues(repository); |
|
301 | auto catalogues = this->retrieveCatalogues(repository); | |
275 | for (auto catalogue : catalogues) { |
|
302 | for (auto catalogue : catalogues) { | |
276 | impl->saveCatalogue(catalogue, false); |
|
303 | impl->saveCatalogue(catalogue, false); | |
277 | } |
|
304 | } | |
278 | } |
|
305 | } | |
279 |
|
306 | |||
280 | impl->savAllDB(); |
|
307 | impl->savAllDB(); | |
281 | impl->m_EventKeysWithChanges.clear(); |
|
308 | impl->m_EventKeysWithChanges.clear(); | |
282 | } |
|
309 | } | |
283 |
|
310 | |||
284 | bool CatalogueController::hasChanges() const |
|
311 | bool CatalogueController::hasChanges() const | |
285 | { |
|
312 | { | |
286 | return !impl->m_EventKeysWithChanges.isEmpty(); // TODO: catalogues |
|
313 | return !impl->m_EventKeysWithChanges.isEmpty(); // TODO: catalogues | |
287 | } |
|
314 | } | |
288 |
|
315 | |||
289 | QByteArray |
|
316 | QByteArray | |
290 | CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const |
|
317 | CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const | |
291 | { |
|
318 | { | |
292 | auto encodedData = QByteArray{}; |
|
319 | auto encodedData = QByteArray{}; | |
293 |
|
320 | |||
294 | QMap<QString, QVariantList> idsPerRepository; |
|
321 | QMap<QString, QVariantList> idsPerRepository; | |
295 | for (auto event : events) { |
|
322 | for (auto event : events) { | |
296 | idsPerRepository[event->getRepository()] << event->getUniqId(); |
|
323 | idsPerRepository[event->getRepository()] << event->getUniqId(); | |
297 | } |
|
324 | } | |
298 |
|
325 | |||
299 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; |
|
326 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; | |
300 | stream << idsPerRepository; |
|
327 | stream << idsPerRepository; | |
301 |
|
328 | |||
302 | return encodedData; |
|
329 | return encodedData; | |
303 | } |
|
330 | } | |
304 |
|
331 | |||
305 | QVector<std::shared_ptr<DBEvent> > |
|
332 | QVector<std::shared_ptr<DBEvent> > | |
306 | CatalogueController::eventsForMimeData(const QByteArray &mimeData) const |
|
333 | CatalogueController::eventsForMimeData(const QByteArray &mimeData) const | |
307 | { |
|
334 | { | |
308 | auto events = QVector<std::shared_ptr<DBEvent> >{}; |
|
335 | auto events = QVector<std::shared_ptr<DBEvent> >{}; | |
309 | QDataStream stream{mimeData}; |
|
336 | QDataStream stream{mimeData}; | |
310 |
|
337 | |||
311 | QMap<QString, QVariantList> idsPerRepository; |
|
338 | QMap<QString, QVariantList> idsPerRepository; | |
312 | stream >> idsPerRepository; |
|
339 | stream >> idsPerRepository; | |
313 |
|
340 | |||
314 | for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) { |
|
341 | for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) { | |
315 | auto repository = it.key(); |
|
342 | auto repository = it.key(); | |
316 | auto allRepositoryEvent = retrieveEvents(repository); |
|
343 | auto allRepositoryEvent = retrieveEvents(repository); | |
317 | for (auto uuid : it.value()) { |
|
344 | for (auto uuid : it.value()) { | |
318 | for (auto repositoryEvent : allRepositoryEvent) { |
|
345 | for (auto repositoryEvent : allRepositoryEvent) { | |
319 | if (uuid.toUuid() == repositoryEvent->getUniqId()) { |
|
346 | if (uuid.toUuid() == repositoryEvent->getUniqId()) { | |
320 | events << repositoryEvent; |
|
347 | events << repositoryEvent; | |
321 | } |
|
348 | } | |
322 | } |
|
349 | } | |
323 | } |
|
350 | } | |
324 | } |
|
351 | } | |
325 |
|
352 | |||
326 | return events; |
|
353 | return events; | |
327 | } |
|
354 | } | |
328 |
|
355 | |||
329 | void CatalogueController::initialize() |
|
356 | void CatalogueController::initialize() | |
330 | { |
|
357 | { | |
331 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") |
|
358 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") | |
332 | << QThread::currentThread(); |
|
359 | << QThread::currentThread(); | |
333 |
|
360 | |||
334 | impl->m_CatalogueDao.initialize(); |
|
361 | impl->m_CatalogueDao.initialize(); | |
335 | auto defaultRepositoryLocation |
|
362 | auto defaultRepositoryLocation | |
336 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); |
|
363 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); | |
337 |
|
364 | |||
338 | QDir defaultRepositoryLocationDir; |
|
365 | QDir defaultRepositoryLocationDir; | |
339 | if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { |
|
366 | if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { | |
340 | defaultRepositoryLocationDir.cd(defaultRepositoryLocation); |
|
367 | defaultRepositoryLocationDir.cd(defaultRepositoryLocation); | |
341 | auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); |
|
368 | auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); | |
342 |
|
369 | |||
343 | qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") |
|
370 | qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") | |
344 | << defaultRepository; |
|
371 | << defaultRepository; | |
345 |
|
372 | |||
346 | QDir dbDir(defaultRepository); |
|
373 | QDir dbDir(defaultRepository); | |
347 | impl->m_RepositoryList << REPOSITORY_DEFAULT; |
|
374 | impl->m_RepositoryList << REPOSITORY_DEFAULT; | |
348 | if (dbDir.exists()) { |
|
375 | if (dbDir.exists()) { | |
349 | auto dirName = dbDir.dirName(); |
|
376 | auto dirName = dbDir.dirName(); | |
350 |
|
377 | |||
351 | if (impl->m_CatalogueDao.addDB(defaultRepository, dirName)) { |
|
378 | if (impl->m_CatalogueDao.addDB(defaultRepository, dirName)) { | |
352 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); |
|
379 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); | |
353 | } |
|
380 | } | |
354 | } |
|
381 | } | |
355 | else { |
|
382 | else { | |
356 | qCInfo(LOG_CatalogueController()) << tr("Initialisation of Default repository detected") |
|
383 | qCInfo(LOG_CatalogueController()) << tr("Initialisation of Default repository detected") | |
357 | << defaultRepository; |
|
384 | << defaultRepository; | |
358 | } |
|
385 | } | |
359 | } |
|
386 | } | |
360 | else { |
|
387 | else { | |
361 | qCWarning(LOG_CatalogueController()) |
|
388 | qCWarning(LOG_CatalogueController()) | |
362 | << tr("Cannot load the persistent default repository from ") |
|
389 | << tr("Cannot load the persistent default repository from ") | |
363 | << defaultRepositoryLocation; |
|
390 | << defaultRepositoryLocation; | |
364 | } |
|
391 | } | |
365 |
|
392 | |||
366 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); |
|
393 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); | |
367 | } |
|
394 | } | |
368 |
|
395 | |||
369 | QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey( |
|
396 | QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey( | |
370 | const std::shared_ptr<DBEvent> &event) const |
|
397 | const std::shared_ptr<DBEvent> &event) const | |
371 | { |
|
398 | { | |
372 | return event->getUniqId().toString().append(event->getRepository()); |
|
399 | return event->getUniqId().toString().append(event->getRepository()); | |
373 | } |
|
400 | } | |
374 |
|
401 | |||
375 | void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom, |
|
402 | void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom, | |
376 | const QString &dbTo) |
|
403 | const QString &dbTo) | |
377 | { |
|
404 | { | |
378 | // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; |
|
405 | // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; | |
379 | auto catalogues = m_CatalogueDao.getCatalogues(dbFrom); |
|
406 | auto catalogues = m_CatalogueDao.getCatalogues(dbFrom); | |
380 | auto events = m_CatalogueDao.getEvents(dbFrom); |
|
407 | auto events = m_CatalogueDao.getEvents(dbFrom); | |
381 | for (auto catalogue : catalogues) { |
|
408 | for (auto catalogue : catalogues) { | |
382 | m_CatalogueDao.copyCatalogue(catalogue, dbTo, true); |
|
409 | m_CatalogueDao.copyCatalogue(catalogue, dbTo, true); | |
383 | } |
|
410 | } | |
384 |
|
411 | |||
385 | for (auto event : events) { |
|
412 | for (auto event : events) { | |
386 | m_CatalogueDao.copyEvent(event, dbTo, true); |
|
413 | m_CatalogueDao.copyEvent(event, dbTo, true); | |
387 | } |
|
414 | } | |
388 | } |
|
415 | } | |
389 |
|
416 | |||
390 | QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository) |
|
417 | QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository) | |
391 | { |
|
418 | { | |
392 | auto syncRepository = toSyncRepository(repository); |
|
419 | auto syncRepository = toSyncRepository(repository); | |
393 |
|
420 | |||
394 | return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX); |
|
421 | return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX); | |
395 | } |
|
422 | } | |
396 |
|
423 | |||
397 | QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository) |
|
424 | QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository) | |
398 | { |
|
425 | { | |
399 | auto syncRepository = repository; |
|
426 | auto syncRepository = repository; | |
400 | if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) { |
|
427 | if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) { | |
401 | syncRepository.remove(REPOSITORY_WORK_SUFFIX); |
|
428 | syncRepository.remove(REPOSITORY_WORK_SUFFIX); | |
402 | } |
|
429 | } | |
403 | else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) { |
|
430 | else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) { | |
404 | syncRepository.remove(REPOSITORY_TRASH_SUFFIX); |
|
431 | syncRepository.remove(REPOSITORY_TRASH_SUFFIX); | |
405 | } |
|
432 | } | |
406 | return syncRepository; |
|
433 | return syncRepository; | |
407 | } |
|
434 | } | |
408 |
|
435 | |||
409 | void CatalogueController::CatalogueControllerPrivate::savAllDB() |
|
436 | void CatalogueController::CatalogueControllerPrivate::savAllDB() | |
410 | { |
|
437 | { | |
411 | for (auto repository : m_RepositoryList) { |
|
438 | for (auto repository : m_RepositoryList) { | |
412 | auto defaultRepositoryLocation |
|
439 | auto defaultRepositoryLocation | |
413 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); |
|
440 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); | |
414 | m_CatalogueDao.saveDB(defaultRepositoryLocation, repository); |
|
441 | m_CatalogueDao.saveDB(defaultRepositoryLocation, repository); | |
415 | } |
|
442 | } | |
416 | } |
|
443 | } | |
417 |
|
444 | |||
418 | void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event, |
|
445 | void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event, | |
419 | bool persist) |
|
446 | bool persist) | |
420 | { |
|
447 | { | |
421 | m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true); |
|
448 | m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true); | |
422 | if (persist) { |
|
449 | if (persist) { | |
423 | savAllDB(); |
|
450 | savAllDB(); | |
424 | } |
|
451 | } | |
425 | } |
|
452 | } | |
426 |
|
453 | |||
427 | void CatalogueController::CatalogueControllerPrivate::saveCatalogue( |
|
454 | void CatalogueController::CatalogueControllerPrivate::saveCatalogue( | |
428 | std::shared_ptr<DBCatalogue> catalogue, bool persist) |
|
455 | std::shared_ptr<DBCatalogue> catalogue, bool persist) | |
429 | { |
|
456 | { | |
430 | m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true); |
|
457 | m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true); | |
431 | if (persist) { |
|
458 | if (persist) { | |
432 | savAllDB(); |
|
459 | savAllDB(); | |
433 | } |
|
460 | } | |
434 | } |
|
461 | } |
@@ -1,460 +1,466 | |||||
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/CatalogueEventsModel.h> |
|
5 | #include <Catalogue/CatalogueEventsModel.h> | |
6 | #include <Catalogue/CatalogueExplorerHelper.h> |
|
6 | #include <Catalogue/CatalogueExplorerHelper.h> | |
7 | #include <CatalogueDao.h> |
|
7 | #include <CatalogueDao.h> | |
8 | #include <DBCatalogue.h> |
|
8 | #include <DBCatalogue.h> | |
9 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
10 | #include <Visualization/VisualizationTabWidget.h> |
|
10 | #include <Visualization/VisualizationTabWidget.h> | |
11 | #include <Visualization/VisualizationWidget.h> |
|
11 | #include <Visualization/VisualizationWidget.h> | |
12 | #include <Visualization/VisualizationZoneWidget.h> |
|
12 | #include <Visualization/VisualizationZoneWidget.h> | |
13 |
|
13 | |||
14 | #include <QDialog> |
|
14 | #include <QDialog> | |
15 | #include <QDialogButtonBox> |
|
15 | #include <QDialogButtonBox> | |
16 | #include <QListWidget> |
|
16 | #include <QListWidget> | |
17 | #include <QMessageBox> |
|
17 | #include <QMessageBox> | |
18 |
|
18 | |||
19 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget") |
|
19 | Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget") | |
20 |
|
20 | |||
21 | /// Fixed size of the validation column |
|
21 | /// Fixed size of the validation column | |
22 | const auto VALIDATION_COLUMN_SIZE = 35; |
|
22 | const auto VALIDATION_COLUMN_SIZE = 35; | |
23 |
|
23 | |||
24 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { |
|
24 | struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate { | |
25 |
|
25 | |||
26 | CatalogueEventsModel *m_Model = nullptr; |
|
26 | CatalogueEventsModel *m_Model = nullptr; | |
27 | QStringList m_ZonesForTimeMode; |
|
27 | QStringList m_ZonesForTimeMode; | |
28 | QString m_ZoneForGraphMode; |
|
28 | QString m_ZoneForGraphMode; | |
29 | QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues; |
|
29 | QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues; | |
30 |
|
30 | |||
31 | VisualizationWidget *m_VisualizationWidget = nullptr; |
|
31 | VisualizationWidget *m_VisualizationWidget = nullptr; | |
32 |
|
32 | |||
33 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget) |
|
33 | void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget) | |
34 | { |
|
34 | { | |
35 | widget->ui->treeView->setSortingEnabled(false); |
|
35 | widget->ui->treeView->setSortingEnabled(false); | |
36 | m_Model->setEvents(events); |
|
36 | m_Model->setEvents(events); | |
37 | widget->ui->treeView->setSortingEnabled(true); |
|
37 | widget->ui->treeView->setSortingEnabled(true); | |
38 |
|
38 | |||
39 | for (auto event : events) { |
|
39 | for (auto event : events) { | |
40 | if (sqpApp->catalogueController().eventHasChanges(event)) { |
|
40 | if (sqpApp->catalogueController().eventHasChanges(event)) { | |
41 | auto index = m_Model->indexOf(event); |
|
41 | auto index = m_Model->indexOf(event); | |
42 | widget->setEventChanges(event, true); |
|
42 | widget->setEventChanges(event, true); | |
43 | } |
|
43 | } | |
44 | } |
|
44 | } | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) |
|
47 | void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) | |
48 | { |
|
48 | { | |
49 | treeView->setSortingEnabled(false); |
|
49 | treeView->setSortingEnabled(false); | |
50 | m_Model->addEvent(event); |
|
50 | m_Model->addEvent(event); | |
51 | treeView->setSortingEnabled(true); |
|
51 | treeView->setSortingEnabled(true); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) |
|
54 | void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView) | |
55 | { |
|
55 | { | |
56 | treeView->setSortingEnabled(false); |
|
56 | treeView->setSortingEnabled(false); | |
57 | m_Model->removeEvent(event); |
|
57 | m_Model->removeEvent(event); | |
58 | treeView->setSortingEnabled(true); |
|
58 | treeView->setSortingEnabled(true); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | QStringList getAvailableVisualizationZoneList() const |
|
61 | QStringList getAvailableVisualizationZoneList() const | |
62 | { |
|
62 | { | |
63 | if (m_VisualizationWidget) { |
|
63 | if (m_VisualizationWidget) { | |
64 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
64 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { | |
65 | return tab->availableZoneWidgets(); |
|
65 | return tab->availableZoneWidgets(); | |
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | return QStringList{}; |
|
69 | return QStringList{}; | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | QStringList selectZone(QWidget *parent, const QStringList &selectedZones, |
|
72 | QStringList selectZone(QWidget *parent, const QStringList &selectedZones, | |
73 | bool allowMultiSelection, const QPoint &location) |
|
73 | bool allowMultiSelection, const QPoint &location) | |
74 | { |
|
74 | { | |
75 | auto availableZones = getAvailableVisualizationZoneList(); |
|
75 | auto availableZones = getAvailableVisualizationZoneList(); | |
76 | if (availableZones.isEmpty()) { |
|
76 | if (availableZones.isEmpty()) { | |
77 | return QStringList{}; |
|
77 | return QStringList{}; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | QDialog d(parent, Qt::Tool); |
|
80 | QDialog d(parent, Qt::Tool); | |
81 | d.setWindowTitle("Choose a zone"); |
|
81 | d.setWindowTitle("Choose a zone"); | |
82 | auto layout = new QVBoxLayout{&d}; |
|
82 | auto layout = new QVBoxLayout{&d}; | |
83 | layout->setContentsMargins(0, 0, 0, 0); |
|
83 | layout->setContentsMargins(0, 0, 0, 0); | |
84 | auto listWidget = new QListWidget{&d}; |
|
84 | auto listWidget = new QListWidget{&d}; | |
85 | layout->addWidget(listWidget); |
|
85 | layout->addWidget(listWidget); | |
86 |
|
86 | |||
87 | QSet<QListWidgetItem *> checkedItems; |
|
87 | QSet<QListWidgetItem *> checkedItems; | |
88 | for (auto zone : availableZones) { |
|
88 | for (auto zone : availableZones) { | |
89 | auto item = new QListWidgetItem{zone}; |
|
89 | auto item = new QListWidgetItem{zone}; | |
90 | item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); |
|
90 | item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); | |
91 | if (selectedZones.contains(zone)) { |
|
91 | if (selectedZones.contains(zone)) { | |
92 | item->setCheckState(Qt::Checked); |
|
92 | item->setCheckState(Qt::Checked); | |
93 | checkedItems << item; |
|
93 | checkedItems << item; | |
94 | } |
|
94 | } | |
95 | else { |
|
95 | else { | |
96 | item->setCheckState(Qt::Unchecked); |
|
96 | item->setCheckState(Qt::Unchecked); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | listWidget->addItem(item); |
|
99 | listWidget->addItem(item); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d}; |
|
102 | auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d}; | |
103 | layout->addWidget(buttonBox); |
|
103 | layout->addWidget(buttonBox); | |
104 |
|
104 | |||
105 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept); |
|
105 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept); | |
106 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject); |
|
106 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject); | |
107 |
|
107 | |||
108 | QObject::connect(listWidget, &QListWidget::itemChanged, |
|
108 | QObject::connect(listWidget, &QListWidget::itemChanged, | |
109 | [&checkedItems, allowMultiSelection, listWidget](auto item) { |
|
109 | [&checkedItems, allowMultiSelection, listWidget](auto item) { | |
110 | if (item->checkState() == Qt::Checked) { |
|
110 | if (item->checkState() == Qt::Checked) { | |
111 | if (!allowMultiSelection) { |
|
111 | if (!allowMultiSelection) { | |
112 | for (auto checkedItem : checkedItems) { |
|
112 | for (auto checkedItem : checkedItems) { | |
113 | listWidget->blockSignals(true); |
|
113 | listWidget->blockSignals(true); | |
114 | checkedItem->setCheckState(Qt::Unchecked); |
|
114 | checkedItem->setCheckState(Qt::Unchecked); | |
115 | listWidget->blockSignals(false); |
|
115 | listWidget->blockSignals(false); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | checkedItems.clear(); |
|
118 | checkedItems.clear(); | |
119 | } |
|
119 | } | |
120 | checkedItems << item; |
|
120 | checkedItems << item; | |
121 | } |
|
121 | } | |
122 | else { |
|
122 | else { | |
123 | checkedItems.remove(item); |
|
123 | checkedItems.remove(item); | |
124 | } |
|
124 | } | |
125 | }); |
|
125 | }); | |
126 |
|
126 | |||
127 | QStringList result; |
|
127 | QStringList result; | |
128 |
|
128 | |||
129 | d.setMinimumWidth(120); |
|
129 | d.setMinimumWidth(120); | |
130 | d.resize(d.minimumSizeHint()); |
|
130 | d.resize(d.minimumSizeHint()); | |
131 | d.move(location); |
|
131 | d.move(location); | |
132 | if (d.exec() == QDialog::Accepted) { |
|
132 | if (d.exec() == QDialog::Accepted) { | |
133 | for (auto item : checkedItems) { |
|
133 | for (auto item : checkedItems) { | |
134 | result += item->text(); |
|
134 | result += item->text(); | |
135 | } |
|
135 | } | |
136 | } |
|
136 | } | |
137 | else { |
|
137 | else { | |
138 | result = selectedZones; |
|
138 | result = selectedZones; | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | return result; |
|
141 | return result; | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void updateForTimeMode(QTreeView *treeView) |
|
144 | void updateForTimeMode(QTreeView *treeView) | |
145 | { |
|
145 | { | |
146 | auto selectedRows = treeView->selectionModel()->selectedRows(); |
|
146 | auto selectedRows = treeView->selectionModel()->selectedRows(); | |
147 |
|
147 | |||
148 | if (selectedRows.count() == 1) { |
|
148 | if (selectedRows.count() == 1) { | |
149 | auto event = m_Model->getEvent(selectedRows.first()); |
|
149 | auto event = m_Model->getEvent(selectedRows.first()); | |
150 | if (event) { |
|
150 | if (event) { | |
151 | if (m_VisualizationWidget) { |
|
151 | if (m_VisualizationWidget) { | |
152 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
152 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { | |
153 |
|
153 | |||
154 | for (auto zoneName : m_ZonesForTimeMode) { |
|
154 | for (auto zoneName : m_ZonesForTimeMode) { | |
155 | if (auto zone = tab->getZoneWithName(zoneName)) { |
|
155 | if (auto zone = tab->getZoneWithName(zoneName)) { | |
156 | SqpRange eventRange; |
|
156 | SqpRange eventRange; | |
157 | eventRange.m_TStart = event->getTStart(); |
|
157 | eventRange.m_TStart = event->getTStart(); | |
158 | eventRange.m_TEnd = event->getTEnd(); |
|
158 | eventRange.m_TEnd = event->getTEnd(); | |
159 | zone->setZoneRange(eventRange); |
|
159 | zone->setZoneRange(eventRange); | |
160 | } |
|
160 | } | |
161 | } |
|
161 | } | |
162 | } |
|
162 | } | |
163 | else { |
|
163 | else { | |
164 | qCWarning(LOG_CatalogueEventsWidget()) |
|
164 | qCWarning(LOG_CatalogueEventsWidget()) | |
165 | << "updateTimeZone: no tab found in the visualization"; |
|
165 | << "updateTimeZone: no tab found in the visualization"; | |
166 | } |
|
166 | } | |
167 | } |
|
167 | } | |
168 | else { |
|
168 | else { | |
169 | qCWarning(LOG_CatalogueEventsWidget()) |
|
169 | qCWarning(LOG_CatalogueEventsWidget()) | |
170 | << "updateTimeZone: visualization widget not found"; |
|
170 | << "updateTimeZone: visualization widget not found"; | |
171 | } |
|
171 | } | |
172 | } |
|
172 | } | |
173 | } |
|
173 | } | |
174 | else { |
|
174 | else { | |
175 | qCWarning(LOG_CatalogueEventsWidget()) |
|
175 | qCWarning(LOG_CatalogueEventsWidget()) | |
176 | << "updateTimeZone: not compatible with multiple events selected"; |
|
176 | << "updateTimeZone: not compatible with multiple events selected"; | |
177 | } |
|
177 | } | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | void updateForGraphMode(QTreeView *treeView) |
|
180 | void updateForGraphMode(QTreeView *treeView) | |
181 | { |
|
181 | { | |
182 | auto selectedRows = treeView->selectionModel()->selectedRows(); |
|
182 | auto selectedRows = treeView->selectionModel()->selectedRows(); | |
183 |
|
183 | |||
184 | if (selectedRows.count() == 1) { |
|
184 | if (selectedRows.count() == 1) { | |
185 | auto event = m_Model->getEvent(selectedRows.first()); |
|
185 | auto event = m_Model->getEvent(selectedRows.first()); | |
186 | if (m_VisualizationWidget) { |
|
186 | if (m_VisualizationWidget) { | |
187 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { |
|
187 | if (auto tab = m_VisualizationWidget->currentTabWidget()) { | |
188 | if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) { |
|
188 | if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) { | |
189 | // TODO |
|
189 | // TODO | |
190 | } |
|
190 | } | |
191 | } |
|
191 | } | |
192 | else { |
|
192 | else { | |
193 | qCWarning(LOG_CatalogueEventsWidget()) |
|
193 | qCWarning(LOG_CatalogueEventsWidget()) | |
194 | << "updateGraphMode: no tab found in the visualization"; |
|
194 | << "updateGraphMode: no tab found in the visualization"; | |
195 | } |
|
195 | } | |
196 | } |
|
196 | } | |
197 | else { |
|
197 | else { | |
198 | qCWarning(LOG_CatalogueEventsWidget()) |
|
198 | qCWarning(LOG_CatalogueEventsWidget()) | |
199 | << "updateGraphMode: visualization widget not found"; |
|
199 | << "updateGraphMode: visualization widget not found"; | |
200 | } |
|
200 | } | |
201 | } |
|
201 | } | |
202 | else { |
|
202 | else { | |
203 | qCWarning(LOG_CatalogueEventsWidget()) |
|
203 | qCWarning(LOG_CatalogueEventsWidget()) | |
204 | << "updateGraphMode: not compatible with multiple events selected"; |
|
204 | << "updateGraphMode: not compatible with multiple events selected"; | |
205 | } |
|
205 | } | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | void getSelectedItems( |
|
208 | void getSelectedItems( | |
209 | QTreeView *treeView, QVector<std::shared_ptr<DBEvent> > &events, |
|
209 | QTreeView *treeView, QVector<std::shared_ptr<DBEvent> > &events, | |
210 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > &eventProducts) |
|
210 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > &eventProducts) | |
211 | { |
|
211 | { | |
212 | for (auto rowIndex : treeView->selectionModel()->selectedRows()) { |
|
212 | for (auto rowIndex : treeView->selectionModel()->selectedRows()) { | |
213 | auto itemType = m_Model->itemTypeOf(rowIndex); |
|
213 | auto itemType = m_Model->itemTypeOf(rowIndex); | |
214 | if (itemType == CatalogueEventsModel::ItemType::Event) { |
|
214 | if (itemType == CatalogueEventsModel::ItemType::Event) { | |
215 | events << m_Model->getEvent(rowIndex); |
|
215 | events << m_Model->getEvent(rowIndex); | |
216 | } |
|
216 | } | |
217 | else if (itemType == CatalogueEventsModel::ItemType::EventProduct) { |
|
217 | else if (itemType == CatalogueEventsModel::ItemType::EventProduct) { | |
218 | eventProducts << qMakePair(m_Model->getParentEvent(rowIndex), |
|
218 | eventProducts << qMakePair(m_Model->getParentEvent(rowIndex), | |
219 | m_Model->getEventProduct(rowIndex)); |
|
219 | m_Model->getEventProduct(rowIndex)); | |
220 | } |
|
220 | } | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 | }; |
|
223 | }; | |
224 |
|
224 | |||
225 | CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) |
|
225 | CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent) | |
226 | : QWidget(parent), |
|
226 | : QWidget(parent), | |
227 | ui(new Ui::CatalogueEventsWidget), |
|
227 | ui(new Ui::CatalogueEventsWidget), | |
228 | impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()} |
|
228 | impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()} | |
229 | { |
|
229 | { | |
230 | ui->setupUi(this); |
|
230 | ui->setupUi(this); | |
231 |
|
231 | |||
232 | impl->m_Model = new CatalogueEventsModel{this}; |
|
232 | impl->m_Model = new CatalogueEventsModel{this}; | |
233 | ui->treeView->setModel(impl->m_Model); |
|
233 | ui->treeView->setModel(impl->m_Model); | |
234 |
|
234 | |||
235 | ui->treeView->setSortingEnabled(true); |
|
235 | ui->treeView->setSortingEnabled(true); | |
236 | ui->treeView->setDragDropMode(QAbstractItemView::DragDrop); |
|
236 | ui->treeView->setDragDropMode(QAbstractItemView::DragDrop); | |
237 | ui->treeView->setDragEnabled(true); |
|
237 | ui->treeView->setDragEnabled(true); | |
238 |
|
238 | |||
239 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { |
|
239 | connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) { | |
240 | if (checked) { |
|
240 | if (checked) { | |
241 | ui->btnChart->setChecked(false); |
|
241 | ui->btnChart->setChecked(false); | |
242 | impl->m_ZonesForTimeMode |
|
242 | impl->m_ZonesForTimeMode | |
243 | = impl->selectZone(this, impl->m_ZonesForTimeMode, true, |
|
243 | = impl->selectZone(this, impl->m_ZonesForTimeMode, true, | |
244 | this->mapToGlobal(ui->btnTime->frameGeometry().center())); |
|
244 | this->mapToGlobal(ui->btnTime->frameGeometry().center())); | |
245 |
|
245 | |||
246 | impl->updateForTimeMode(ui->treeView); |
|
246 | impl->updateForTimeMode(ui->treeView); | |
247 | } |
|
247 | } | |
248 | }); |
|
248 | }); | |
249 |
|
249 | |||
250 | connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) { |
|
250 | connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) { | |
251 | if (checked) { |
|
251 | if (checked) { | |
252 | ui->btnTime->setChecked(false); |
|
252 | ui->btnTime->setChecked(false); | |
253 | impl->m_ZoneForGraphMode |
|
253 | impl->m_ZoneForGraphMode | |
254 | = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false, |
|
254 | = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false, | |
255 | this->mapToGlobal(ui->btnChart->frameGeometry().center())) |
|
255 | this->mapToGlobal(ui->btnChart->frameGeometry().center())) | |
256 | .value(0); |
|
256 | .value(0); | |
257 |
|
257 | |||
258 | impl->updateForGraphMode(ui->treeView); |
|
258 | impl->updateForGraphMode(ui->treeView); | |
259 | } |
|
259 | } | |
260 | }); |
|
260 | }); | |
261 |
|
261 | |||
262 | connect(ui->btnRemove, &QToolButton::clicked, [this]() { |
|
262 | connect(ui->btnRemove, &QToolButton::clicked, [this]() { | |
263 | QVector<std::shared_ptr<DBEvent> > events; |
|
263 | QVector<std::shared_ptr<DBEvent> > events; | |
264 | 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); |
|
265 | impl->getSelectedItems(ui->treeView, events, eventProducts); | |
266 |
|
266 | |||
267 | if (!events.isEmpty() && eventProducts.isEmpty()) { |
|
267 | if (!events.isEmpty() && eventProducts.isEmpty()) { | |
268 |
|
268 | |||
269 | if (QMessageBox::warning(this, tr("Remove Event(s)"), |
|
269 | if (QMessageBox::warning(this, tr("Remove Event(s)"), | |
270 | tr("The selected event(s) will be completly removed " |
|
270 | tr("The selected event(s) will be completly removed " | |
271 | "from the repository!\nAre you sure you want to continue?"), |
|
271 | "from the repository!\nAre you sure you want to continue?"), | |
272 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) |
|
272 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) | |
273 | == QMessageBox::Yes) { |
|
273 | == QMessageBox::Yes) { | |
274 |
|
274 | |||
275 | for (auto event : events) { |
|
275 | for (auto event : events) { | |
276 | sqpApp->catalogueController().removeEvent(event); |
|
276 | sqpApp->catalogueController().removeEvent(event); | |
277 | impl->removeEvent(event, ui->treeView); |
|
277 | impl->removeEvent(event, ui->treeView); | |
278 | } |
|
278 | } | |
279 | } |
|
279 | } | |
280 | } |
|
280 | } | |
281 | }); |
|
281 | }); | |
282 |
|
282 | |||
283 | connect(ui->treeView, &QTreeView::clicked, this, &CatalogueEventsWidget::emitSelection); |
|
283 | connect(ui->treeView, &QTreeView::clicked, this, &CatalogueEventsWidget::emitSelection); | |
284 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, |
|
284 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, | |
285 | &CatalogueEventsWidget::emitSelection); |
|
285 | &CatalogueEventsWidget::emitSelection); | |
286 |
|
286 | |||
287 | ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected |
|
287 | ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected | |
288 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { |
|
288 | connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() { | |
289 | auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1; |
|
289 | auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1; | |
290 | ui->btnChart->setEnabled(isNotMultiSelection); |
|
290 | ui->btnChart->setEnabled(isNotMultiSelection); | |
291 | ui->btnTime->setEnabled(isNotMultiSelection); |
|
291 | ui->btnTime->setEnabled(isNotMultiSelection); | |
292 |
|
292 | |||
293 | if (isNotMultiSelection && ui->btnTime->isChecked()) { |
|
293 | if (isNotMultiSelection && ui->btnTime->isChecked()) { | |
294 | impl->updateForTimeMode(ui->treeView); |
|
294 | impl->updateForTimeMode(ui->treeView); | |
295 | } |
|
295 | } | |
296 | else if (isNotMultiSelection && ui->btnChart->isChecked()) { |
|
296 | else if (isNotMultiSelection && ui->btnChart->isChecked()) { | |
297 | impl->updateForGraphMode(ui->treeView); |
|
297 | impl->updateForGraphMode(ui->treeView); | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | QVector<std::shared_ptr<DBEvent> > events; |
|
300 | QVector<std::shared_ptr<DBEvent> > events; | |
301 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; |
|
301 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; | |
302 | impl->getSelectedItems(ui->treeView, events, eventProducts); |
|
302 | impl->getSelectedItems(ui->treeView, events, eventProducts); | |
303 | ui->btnRemove->setEnabled(!events.isEmpty() && eventProducts.isEmpty()); |
|
303 | ui->btnRemove->setEnabled(!events.isEmpty() && eventProducts.isEmpty()); | |
304 | }); |
|
304 | }); | |
305 |
|
305 | |||
306 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); |
|
306 | ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | |
307 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Tags, |
|
307 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Tags, | |
308 | QHeaderView::Stretch); |
|
308 | QHeaderView::Stretch); | |
309 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation, |
|
309 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation, | |
310 | QHeaderView::Fixed); |
|
310 | QHeaderView::Fixed); | |
311 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name, |
|
311 | ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name, | |
312 | QHeaderView::Interactive); |
|
312 | QHeaderView::Interactive); | |
313 | ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation, |
|
313 | ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation, | |
314 | VALIDATION_COLUMN_SIZE); |
|
314 | VALIDATION_COLUMN_SIZE); | |
315 | ui->treeView->header()->setSortIndicatorShown(true); |
|
315 | ui->treeView->header()->setSortIndicatorShown(true); | |
316 |
|
316 | |||
317 | connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() { |
|
317 | connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() { | |
318 | auto allEvents = impl->m_Model->events(); |
|
318 | auto allEvents = impl->m_Model->events(); | |
319 | for (auto event : allEvents) { |
|
319 | for (auto event : allEvents) { | |
320 | setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event)); |
|
320 | setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event)); | |
321 | } |
|
321 | } | |
322 | }); |
|
322 | }); | |
323 |
|
323 | |||
324 | populateWithAllEvents(); |
|
324 | populateWithAllEvents(); | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | CatalogueEventsWidget::~CatalogueEventsWidget() |
|
327 | CatalogueEventsWidget::~CatalogueEventsWidget() | |
328 | { |
|
328 | { | |
329 | delete ui; |
|
329 | delete ui; | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization) |
|
332 | void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization) | |
333 | { |
|
333 | { | |
334 | impl->m_VisualizationWidget = visualization; |
|
334 | impl->m_VisualizationWidget = visualization; | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event) |
|
337 | void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event) | |
338 | { |
|
338 | { | |
339 | impl->addEvent(event, ui->treeView); |
|
339 | impl->addEvent(event, ui->treeView); | |
340 | } |
|
340 | } | |
341 |
|
341 | |||
342 | void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges) |
|
342 | void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges) | |
343 | { |
|
343 | { | |
344 | impl->m_Model->refreshEvent(event); |
|
344 | impl->m_Model->refreshEvent(event); | |
345 |
|
345 | |||
346 | auto eventIndex = impl->m_Model->indexOf(event); |
|
346 | auto eventIndex = impl->m_Model->indexOf(event); | |
347 | auto validationIndex |
|
347 | auto validationIndex | |
348 | = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation); |
|
348 | = eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation); | |
349 |
|
349 | |||
350 | if (validationIndex.isValid()) { |
|
350 | if (validationIndex.isValid()) { | |
351 | if (hasChanges) { |
|
351 | if (hasChanges) { | |
352 | if (ui->treeView->indexWidget(validationIndex) == nullptr) { |
|
352 | if (ui->treeView->indexWidget(validationIndex) == nullptr) { | |
353 | auto widget = CatalogueExplorerHelper::buildValidationWidget( |
|
353 | auto widget = CatalogueExplorerHelper::buildValidationWidget( | |
354 | ui->treeView, |
|
354 | ui->treeView, | |
355 | [this, event]() { |
|
355 | [this, event]() { | |
356 | sqpApp->catalogueController().saveEvent(event); |
|
356 | sqpApp->catalogueController().saveEvent(event); | |
357 | setEventChanges(event, false); |
|
357 | setEventChanges(event, false); | |
358 | }, |
|
358 | }, | |
359 | [this, event]() { |
|
359 | [this, event]() { | |
360 | sqpApp->catalogueController().discardEvent(event); |
|
360 | bool removed = false; | |
|
361 | sqpApp->catalogueController().discardEvent(event, removed); | |||
|
362 | if (removed) { | |||
|
363 | impl->m_Model->removeEvent(event); | |||
|
364 | } | |||
|
365 | else { | |||
361 | setEventChanges(event, false); |
|
366 | setEventChanges(event, false); | |
362 | impl->m_Model->refreshEvent(event, true); |
|
367 | impl->m_Model->refreshEvent(event, true); | |
|
368 | } | |||
363 | emitSelection(); |
|
369 | emitSelection(); | |
364 | }); |
|
370 | }); | |
365 | ui->treeView->setIndexWidget(validationIndex, widget); |
|
371 | ui->treeView->setIndexWidget(validationIndex, widget); | |
366 | } |
|
372 | } | |
367 | } |
|
373 | } | |
368 | else { |
|
374 | else { | |
369 | // Note: the widget is destroyed |
|
375 | // Note: the widget is destroyed | |
370 | ui->treeView->setIndexWidget(validationIndex, nullptr); |
|
376 | ui->treeView->setIndexWidget(validationIndex, nullptr); | |
371 | } |
|
377 | } | |
372 | } |
|
378 | } | |
373 | else { |
|
379 | else { | |
374 | qCWarning(LOG_CatalogueEventsWidget()) |
|
380 | qCWarning(LOG_CatalogueEventsWidget()) | |
375 | << "setEventChanges: the event is not displayed in the model."; |
|
381 | << "setEventChanges: the event is not displayed in the model."; | |
376 | } |
|
382 | } | |
377 | } |
|
383 | } | |
378 |
|
384 | |||
379 | QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const |
|
385 | QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const | |
380 | { |
|
386 | { | |
381 | return impl->m_DisplayedCatalogues; |
|
387 | return impl->m_DisplayedCatalogues; | |
382 | } |
|
388 | } | |
383 |
|
389 | |||
384 | bool CatalogueEventsWidget::isAllEventsDisplayed() const |
|
390 | bool CatalogueEventsWidget::isAllEventsDisplayed() const | |
385 | { |
|
391 | { | |
386 | return impl->m_DisplayedCatalogues.isEmpty() && !impl->m_Model->events().isEmpty(); |
|
392 | return impl->m_DisplayedCatalogues.isEmpty() && !impl->m_Model->events().isEmpty(); | |
387 | } |
|
393 | } | |
388 |
|
394 | |||
389 | bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const |
|
395 | bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const | |
390 | { |
|
396 | { | |
391 | return impl->m_Model->indexOf(event).isValid(); |
|
397 | return impl->m_Model->indexOf(event).isValid(); | |
392 | } |
|
398 | } | |
393 |
|
399 | |||
394 | void CatalogueEventsWidget::populateWithCatalogues( |
|
400 | void CatalogueEventsWidget::populateWithCatalogues( | |
395 | const QVector<std::shared_ptr<DBCatalogue> > &catalogues) |
|
401 | const QVector<std::shared_ptr<DBCatalogue> > &catalogues) | |
396 | { |
|
402 | { | |
397 | impl->m_DisplayedCatalogues = catalogues; |
|
403 | impl->m_DisplayedCatalogues = catalogues; | |
398 |
|
404 | |||
399 | QSet<QUuid> eventIds; |
|
405 | QSet<QUuid> eventIds; | |
400 | QVector<std::shared_ptr<DBEvent> > events; |
|
406 | QVector<std::shared_ptr<DBEvent> > events; | |
401 |
|
407 | |||
402 | for (auto catalogue : catalogues) { |
|
408 | for (auto catalogue : catalogues) { | |
403 | auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue); |
|
409 | auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue); | |
404 | for (auto event : catalogueEvents) { |
|
410 | for (auto event : catalogueEvents) { | |
405 | if (!eventIds.contains(event->getUniqId())) { |
|
411 | if (!eventIds.contains(event->getUniqId())) { | |
406 | events << event; |
|
412 | events << event; | |
407 | eventIds.insert(event->getUniqId()); |
|
413 | eventIds.insert(event->getUniqId()); | |
408 | } |
|
414 | } | |
409 | } |
|
415 | } | |
410 | } |
|
416 | } | |
411 |
|
417 | |||
412 | impl->setEvents(events, this); |
|
418 | impl->setEvents(events, this); | |
413 | } |
|
419 | } | |
414 |
|
420 | |||
415 | void CatalogueEventsWidget::populateWithAllEvents() |
|
421 | void CatalogueEventsWidget::populateWithAllEvents() | |
416 | { |
|
422 | { | |
417 | impl->m_DisplayedCatalogues.clear(); |
|
423 | impl->m_DisplayedCatalogues.clear(); | |
418 |
|
424 | |||
419 | auto allEvents = sqpApp->catalogueController().retrieveAllEvents(); |
|
425 | auto allEvents = sqpApp->catalogueController().retrieveAllEvents(); | |
420 |
|
426 | |||
421 | QVector<std::shared_ptr<DBEvent> > events; |
|
427 | QVector<std::shared_ptr<DBEvent> > events; | |
422 | for (auto event : allEvents) { |
|
428 | for (auto event : allEvents) { | |
423 | events << event; |
|
429 | events << event; | |
424 | } |
|
430 | } | |
425 |
|
431 | |||
426 | impl->setEvents(events, this); |
|
432 | impl->setEvents(events, this); | |
427 | } |
|
433 | } | |
428 |
|
434 | |||
429 | void CatalogueEventsWidget::clear() |
|
435 | void CatalogueEventsWidget::clear() | |
430 | { |
|
436 | { | |
431 | impl->m_DisplayedCatalogues.clear(); |
|
437 | impl->m_DisplayedCatalogues.clear(); | |
432 | impl->setEvents({}, this); |
|
438 | impl->setEvents({}, this); | |
433 | } |
|
439 | } | |
434 |
|
440 | |||
435 | void CatalogueEventsWidget::refresh() |
|
441 | void CatalogueEventsWidget::refresh() | |
436 | { |
|
442 | { | |
437 | if (impl->m_DisplayedCatalogues.isEmpty()) { |
|
443 | if (impl->m_DisplayedCatalogues.isEmpty()) { | |
438 | populateWithAllEvents(); |
|
444 | populateWithAllEvents(); | |
439 | } |
|
445 | } | |
440 | else { |
|
446 | else { | |
441 | populateWithCatalogues(impl->m_DisplayedCatalogues); |
|
447 | populateWithCatalogues(impl->m_DisplayedCatalogues); | |
442 | } |
|
448 | } | |
443 | } |
|
449 | } | |
444 |
|
450 | |||
445 | void CatalogueEventsWidget::emitSelection() |
|
451 | void CatalogueEventsWidget::emitSelection() | |
446 | { |
|
452 | { | |
447 | QVector<std::shared_ptr<DBEvent> > events; |
|
453 | QVector<std::shared_ptr<DBEvent> > events; | |
448 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; |
|
454 | QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts; | |
449 | impl->getSelectedItems(ui->treeView, events, eventProducts); |
|
455 | impl->getSelectedItems(ui->treeView, events, eventProducts); | |
450 |
|
456 | |||
451 | if (!events.isEmpty() && eventProducts.isEmpty()) { |
|
457 | if (!events.isEmpty() && eventProducts.isEmpty()) { | |
452 | emit eventsSelected(events); |
|
458 | emit eventsSelected(events); | |
453 | } |
|
459 | } | |
454 | else if (events.isEmpty() && !eventProducts.isEmpty()) { |
|
460 | else if (events.isEmpty() && !eventProducts.isEmpty()) { | |
455 | emit eventProductsSelected(eventProducts); |
|
461 | emit eventProductsSelected(eventProducts); | |
456 | } |
|
462 | } | |
457 | else { |
|
463 | else { | |
458 | emit selectionCleared(); |
|
464 | emit selectionCleared(); | |
459 | } |
|
465 | } | |
460 | } |
|
466 | } |
@@ -1,211 +1,211 | |||||
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 <DBEventProduct.h> |
|
7 | #include <DBEventProduct.h> | |
8 | #include <DBTag.h> |
|
8 | #include <DBTag.h> | |
9 |
|
9 | |||
10 | struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate { |
|
10 | struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate { | |
11 | std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr; |
|
11 | std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr; | |
12 | std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr; |
|
12 | std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr; | |
13 | std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr; |
|
13 | std::shared_ptr<DBEventProduct> m_DisplayedEventProduct = nullptr; | |
14 |
|
14 | |||
15 | void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector, |
|
15 | void connectCatalogueUpdateSignals(CatalogueInspectorWidget *inspector, | |
16 | Ui::CatalogueInspectorWidget *ui); |
|
16 | Ui::CatalogueInspectorWidget *ui); | |
17 | void connectEventUpdateSignals(CatalogueInspectorWidget *inspector, |
|
17 | void connectEventUpdateSignals(CatalogueInspectorWidget *inspector, | |
18 | Ui::CatalogueInspectorWidget *ui); |
|
18 | Ui::CatalogueInspectorWidget *ui); | |
19 | }; |
|
19 | }; | |
20 |
|
20 | |||
21 | CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent) |
|
21 | CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent) | |
22 | : QWidget(parent), |
|
22 | : QWidget(parent), | |
23 | ui(new Ui::CatalogueInspectorWidget), |
|
23 | ui(new Ui::CatalogueInspectorWidget), | |
24 | impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()} |
|
24 | impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()} | |
25 | { |
|
25 | { | |
26 | ui->setupUi(this); |
|
26 | ui->setupUi(this); | |
27 | showPage(Page::Empty); |
|
27 | showPage(Page::Empty); | |
28 |
|
28 | |||
29 | impl->connectCatalogueUpdateSignals(this, ui); |
|
29 | impl->connectCatalogueUpdateSignals(this, ui); | |
30 | impl->connectEventUpdateSignals(this, ui); |
|
30 | impl->connectEventUpdateSignals(this, ui); | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | CatalogueInspectorWidget::~CatalogueInspectorWidget() |
|
33 | CatalogueInspectorWidget::~CatalogueInspectorWidget() | |
34 | { |
|
34 | { | |
35 | delete ui; |
|
35 | delete ui; | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals( |
|
38 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectCatalogueUpdateSignals( | |
39 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) |
|
39 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) | |
40 | { |
|
40 | { | |
41 | connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
41 | connect(ui->leCatalogueName, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
42 | if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) { |
|
42 | if (ui->leCatalogueName->text() != m_DisplayedCatalogue->getName()) { | |
43 | m_DisplayedCatalogue->setName(ui->leCatalogueName->text()); |
|
43 | m_DisplayedCatalogue->setName(ui->leCatalogueName->text()); | |
44 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); |
|
44 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); | |
45 | } |
|
45 | } | |
46 | }); |
|
46 | }); | |
47 |
|
47 | |||
48 | connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
48 | connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
49 | if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) { |
|
49 | if (ui->leCatalogueAuthor->text() != m_DisplayedCatalogue->getAuthor()) { | |
50 | m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text()); |
|
50 | m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text()); | |
51 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); |
|
51 | emit inspector->catalogueUpdated(m_DisplayedCatalogue); | |
52 | } |
|
52 | } | |
53 | }); |
|
53 | }); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals( |
|
56 | void CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate::connectEventUpdateSignals( | |
57 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) |
|
57 | CatalogueInspectorWidget *inspector, Ui::CatalogueInspectorWidget *ui) | |
58 | { |
|
58 | { | |
59 | connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
59 | connect(ui->leEventName, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
60 | if (ui->leEventName->text() != m_DisplayedEvent->getName()) { |
|
60 | if (ui->leEventName->text() != m_DisplayedEvent->getName()) { | |
61 | m_DisplayedEvent->setName(ui->leEventName->text()); |
|
61 | m_DisplayedEvent->setName(ui->leEventName->text()); | |
62 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
62 | emit inspector->eventUpdated(m_DisplayedEvent); | |
63 | } |
|
63 | } | |
64 | }); |
|
64 | }); | |
65 |
|
65 | |||
66 | connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
66 | connect(ui->leEventTags, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
67 | auto tags = ui->leEventTags->text().split(QRegExp("\\s+")); |
|
67 | auto tags = ui->leEventTags->text().split(QRegExp("\\s+"), QString::SkipEmptyParts); | |
68 | std::list<QString> tagNames; |
|
68 | std::list<QString> tagNames; | |
69 | for (auto tag : tags) { |
|
69 | for (auto tag : tags) { | |
70 | tagNames.push_back(tag); |
|
70 | tagNames.push_back(tag); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | if (m_DisplayedEvent->getTagsNames() != tagNames) { |
|
73 | if (m_DisplayedEvent->getTagsNames() != tagNames) { | |
74 | m_DisplayedEvent->setTagsNames(tagNames); |
|
74 | m_DisplayedEvent->setTagsNames(tagNames); | |
75 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
75 | emit inspector->eventUpdated(m_DisplayedEvent); | |
76 | } |
|
76 | } | |
77 | }); |
|
77 | }); | |
78 |
|
78 | |||
79 | connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() { |
|
79 | connect(ui->leEventProduct, &QLineEdit::editingFinished, [ui, inspector, this]() { | |
80 | if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) { |
|
80 | if (ui->leEventProduct->text() != m_DisplayedEventProduct->getProductId()) { | |
81 | auto oldProductId = m_DisplayedEventProduct->getProductId(); |
|
81 | auto oldProductId = m_DisplayedEventProduct->getProductId(); | |
82 | m_DisplayedEventProduct->setProductId(ui->leEventProduct->text()); |
|
82 | m_DisplayedEventProduct->setProductId(ui->leEventProduct->text()); | |
83 |
|
83 | |||
84 | auto eventProducts = m_DisplayedEvent->getEventProducts(); |
|
84 | auto eventProducts = m_DisplayedEvent->getEventProducts(); | |
85 | for (auto &eventProduct : eventProducts) { |
|
85 | for (auto &eventProduct : eventProducts) { | |
86 | if (eventProduct.getProductId() == oldProductId) { |
|
86 | if (eventProduct.getProductId() == oldProductId) { | |
87 | eventProduct.setProductId(m_DisplayedEventProduct->getProductId()); |
|
87 | eventProduct.setProductId(m_DisplayedEventProduct->getProductId()); | |
88 | } |
|
88 | } | |
89 | } |
|
89 | } | |
90 | m_DisplayedEvent->setEventProducts(eventProducts); |
|
90 | m_DisplayedEvent->setEventProducts(eventProducts); | |
91 |
|
91 | |||
92 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
92 | emit inspector->eventUpdated(m_DisplayedEvent); | |
93 | } |
|
93 | } | |
94 | }); |
|
94 | }); | |
95 |
|
95 | |||
96 | connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { |
|
96 | connect(ui->dateTimeEventTStart, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { | |
97 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime()); |
|
97 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTStart->dateTime()); | |
98 | if (time != m_DisplayedEventProduct->getTStart()) { |
|
98 | if (time != m_DisplayedEventProduct->getTStart()) { | |
99 | m_DisplayedEventProduct->setTStart(time); |
|
99 | m_DisplayedEventProduct->setTStart(time); | |
100 |
|
100 | |||
101 | auto eventProducts = m_DisplayedEvent->getEventProducts(); |
|
101 | auto eventProducts = m_DisplayedEvent->getEventProducts(); | |
102 | for (auto &eventProduct : eventProducts) { |
|
102 | for (auto &eventProduct : eventProducts) { | |
103 | if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) { |
|
103 | if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) { | |
104 | eventProduct.setTStart(m_DisplayedEventProduct->getTStart()); |
|
104 | eventProduct.setTStart(m_DisplayedEventProduct->getTStart()); | |
105 | } |
|
105 | } | |
106 | } |
|
106 | } | |
107 | m_DisplayedEvent->setEventProducts(eventProducts); |
|
107 | m_DisplayedEvent->setEventProducts(eventProducts); | |
108 |
|
108 | |||
109 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
109 | emit inspector->eventUpdated(m_DisplayedEvent); | |
110 | } |
|
110 | } | |
111 | }); |
|
111 | }); | |
112 |
|
112 | |||
113 | connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { |
|
113 | connect(ui->dateTimeEventTEnd, &QDateTimeEdit::editingFinished, [ui, inspector, this]() { | |
114 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime()); |
|
114 | auto time = DateUtils::secondsSinceEpoch(ui->dateTimeEventTEnd->dateTime()); | |
115 | if (time != m_DisplayedEventProduct->getTEnd()) { |
|
115 | if (time != m_DisplayedEventProduct->getTEnd()) { | |
116 | m_DisplayedEventProduct->setTEnd(time); |
|
116 | m_DisplayedEventProduct->setTEnd(time); | |
117 |
|
117 | |||
118 | auto eventProducts = m_DisplayedEvent->getEventProducts(); |
|
118 | auto eventProducts = m_DisplayedEvent->getEventProducts(); | |
119 | for (auto &eventProduct : eventProducts) { |
|
119 | for (auto &eventProduct : eventProducts) { | |
120 | if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) { |
|
120 | if (eventProduct.getProductId() == m_DisplayedEventProduct->getProductId()) { | |
121 | eventProduct.setTEnd(m_DisplayedEventProduct->getTEnd()); |
|
121 | eventProduct.setTEnd(m_DisplayedEventProduct->getTEnd()); | |
122 | } |
|
122 | } | |
123 | } |
|
123 | } | |
124 | m_DisplayedEvent->setEventProducts(eventProducts); |
|
124 | m_DisplayedEvent->setEventProducts(eventProducts); | |
125 |
|
125 | |||
126 | emit inspector->eventUpdated(m_DisplayedEvent); |
|
126 | emit inspector->eventUpdated(m_DisplayedEvent); | |
127 | } |
|
127 | } | |
128 | }); |
|
128 | }); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page) |
|
131 | void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page) | |
132 | { |
|
132 | { | |
133 | ui->stackedWidget->setCurrentIndex(static_cast<int>(page)); |
|
133 | ui->stackedWidget->setCurrentIndex(static_cast<int>(page)); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const |
|
136 | CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const | |
137 | { |
|
137 | { | |
138 | return static_cast<Page>(ui->stackedWidget->currentIndex()); |
|
138 | return static_cast<Page>(ui->stackedWidget->currentIndex()); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event) |
|
141 | void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event) | |
142 | { |
|
142 | { | |
143 | impl->m_DisplayedEvent = event; |
|
143 | impl->m_DisplayedEvent = event; | |
144 |
|
144 | |||
145 | blockSignals(true); |
|
145 | blockSignals(true); | |
146 |
|
146 | |||
147 | showPage(Page::EventProperties); |
|
147 | showPage(Page::EventProperties); | |
148 | ui->leEventName->setEnabled(true); |
|
148 | ui->leEventName->setEnabled(true); | |
149 | ui->leEventName->setText(event->getName()); |
|
149 | ui->leEventName->setText(event->getName()); | |
150 | ui->leEventProduct->setEnabled(false); |
|
150 | ui->leEventProduct->setEnabled(false); | |
151 | ui->leEventProduct->setText( |
|
151 | ui->leEventProduct->setText( | |
152 | QString::number(event->getEventProducts().size()).append(" product(s)")); |
|
152 | QString::number(event->getEventProducts().size()).append(" product(s)")); | |
153 |
|
153 | |||
154 | QString tagList; |
|
154 | QString tagList; | |
155 | auto tags = event->getTagsNames(); |
|
155 | auto tags = event->getTagsNames(); | |
156 | for (auto tag : tags) { |
|
156 | for (auto tag : tags) { | |
157 | tagList += tag; |
|
157 | tagList += tag; | |
158 | tagList += ' '; |
|
158 | tagList += ' '; | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | ui->leEventTags->setEnabled(true); |
|
161 | ui->leEventTags->setEnabled(true); | |
162 | ui->leEventTags->setText(tagList); |
|
162 | ui->leEventTags->setText(tagList); | |
163 |
|
163 | |||
164 | ui->dateTimeEventTStart->setEnabled(false); |
|
164 | ui->dateTimeEventTStart->setEnabled(false); | |
165 | ui->dateTimeEventTEnd->setEnabled(false); |
|
165 | ui->dateTimeEventTEnd->setEnabled(false); | |
166 |
|
166 | |||
167 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart())); |
|
167 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart())); | |
168 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd())); |
|
168 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd())); | |
169 |
|
169 | |||
170 | blockSignals(false); |
|
170 | blockSignals(false); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event, |
|
173 | void CatalogueInspectorWidget::setEventProduct(const std::shared_ptr<DBEvent> &event, | |
174 | const std::shared_ptr<DBEventProduct> &eventProduct) |
|
174 | const std::shared_ptr<DBEventProduct> &eventProduct) | |
175 | { |
|
175 | { | |
176 |
|
176 | |||
177 | impl->m_DisplayedEvent = event; |
|
177 | impl->m_DisplayedEvent = event; | |
178 | impl->m_DisplayedEventProduct = eventProduct; |
|
178 | impl->m_DisplayedEventProduct = eventProduct; | |
179 |
|
179 | |||
180 | blockSignals(true); |
|
180 | blockSignals(true); | |
181 |
|
181 | |||
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(false); |
|
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); | |
189 | ui->leEventTags->clear(); |
|
189 | ui->leEventTags->clear(); | |
190 |
|
190 | |||
191 | ui->dateTimeEventTStart->setEnabled(true); |
|
191 | ui->dateTimeEventTStart->setEnabled(true); | |
192 | ui->dateTimeEventTEnd->setEnabled(true); |
|
192 | ui->dateTimeEventTEnd->setEnabled(true); | |
193 |
|
193 | |||
194 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart())); |
|
194 | ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(eventProduct->getTStart())); | |
195 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd())); |
|
195 | ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(eventProduct->getTEnd())); | |
196 |
|
196 | |||
197 | blockSignals(false); |
|
197 | blockSignals(false); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue) |
|
200 | void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue) | |
201 | { |
|
201 | { | |
202 | impl->m_DisplayedCatalogue = catalogue; |
|
202 | impl->m_DisplayedCatalogue = catalogue; | |
203 |
|
203 | |||
204 | blockSignals(true); |
|
204 | blockSignals(true); | |
205 |
|
205 | |||
206 | showPage(Page::CatalogueProperties); |
|
206 | showPage(Page::CatalogueProperties); | |
207 | ui->leCatalogueName->setText(catalogue->getName()); |
|
207 | ui->leCatalogueName->setText(catalogue->getName()); | |
208 | ui->leCatalogueAuthor->setText(catalogue->getAuthor()); |
|
208 | ui->leCatalogueAuthor->setText(catalogue->getAuthor()); | |
209 |
|
209 | |||
210 | blockSignals(false); |
|
210 | blockSignals(false); | |
211 | } |
|
211 | } |
General Comments 0
You need to be logged in to leave comments.
Login now