Auto status change to "Under Review"
@@ -1,89 +1,91 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the QLop Software |
|
3 | 3 | -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 2 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | -------------------------------------------------------------------------------*/ |
|
19 | 19 | /*-- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | ----------------------------------------------------------------------------*/ |
|
22 | 22 | #include "MainWindow.h" |
|
23 | 23 | #include <QProcessEnvironment> |
|
24 | 24 | #include <QThread> |
|
25 | 25 | #include <SqpApplication.h> |
|
26 | 26 | #include <qglobal.h> |
|
27 | 27 | |
|
28 | 28 | #include <Plugin/PluginManager.h> |
|
29 | 29 | #include <QDir> |
|
30 | 30 | #include <QtPlugin> |
|
31 | 31 | |
|
32 | 32 | #include <QLoggingCategory> |
|
33 | 33 | |
|
34 | 34 | Q_LOGGING_CATEGORY(LOG_Main, "Main") |
|
35 | 35 | |
|
36 | 36 | namespace { |
|
37 | 37 | |
|
38 | 38 | const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | } // namespace |
|
42 | 42 | |
|
43 | 43 | int main(int argc, char *argv[]) |
|
44 | 44 | { |
|
45 | 45 | #ifdef QT_STATICPLUGIN |
|
46 | 46 | Q_IMPORT_PLUGIN(MockPlugin) |
|
47 | 47 | Q_IMPORT_PLUGIN(AmdaPlugin) |
|
48 | 48 | Q_INIT_RESOURCE(amdaresources); |
|
49 | 49 | #endif |
|
50 | 50 | Q_INIT_RESOURCE(sqpguiresources); |
|
51 | 51 | |
|
52 | SqpApplication a{argc, argv}; | |
|
53 | 52 | SqpApplication::setOrganizationName("LPP"); |
|
54 | 53 | SqpApplication::setOrganizationDomain("lpp.fr"); |
|
55 | 54 | SqpApplication::setApplicationName("SciQLop"); |
|
55 | ||
|
56 | SqpApplication a{argc, argv}; | |
|
57 | ||
|
56 | 58 | MainWindow w; |
|
57 | 59 | w.show(); |
|
58 | 60 | |
|
59 | 61 | // Loads plugins |
|
60 | 62 | auto pluginDir = QDir{a.applicationDirPath()}; |
|
61 | 63 | auto pluginLookupPath = { |
|
62 | 64 | a.applicationDirPath(), |
|
63 | 65 | a.applicationDirPath() + "/" + PLUGIN_DIRECTORY_NAME, |
|
64 | 66 | a.applicationDirPath() + "/../lib64/SciQlop", |
|
65 | 67 | a.applicationDirPath() + "/../lib64/sciqlop", |
|
66 | 68 | a.applicationDirPath() + "/../lib/SciQlop", |
|
67 | 69 | a.applicationDirPath() + "/../lib/sciqlop", |
|
68 | 70 | a.applicationDirPath() + "/../plugins", |
|
69 | 71 | }; |
|
70 | 72 | |
|
71 | 73 | #if _WIN32 || _WIN64 |
|
72 | 74 | pluginDir.mkdir(PLUGIN_DIRECTORY_NAME); |
|
73 | 75 | pluginDir.cd(PLUGIN_DIRECTORY_NAME); |
|
74 | 76 | #endif |
|
75 | 77 | |
|
76 | 78 | PluginManager pluginManager{}; |
|
77 | 79 | |
|
78 | 80 | for (auto &&path : pluginLookupPath) { |
|
79 | 81 | QDir directory{path}; |
|
80 | 82 | if (directory.exists()) { |
|
81 | 83 | qCDebug(LOG_Main()) |
|
82 | 84 | << QObject::tr("Plugin directory: %1").arg(directory.absolutePath()); |
|
83 | 85 | pluginManager.loadPlugins(directory); |
|
84 | 86 | } |
|
85 | 87 | } |
|
86 | 88 | pluginManager.loadStaticPlugins(); |
|
87 | 89 | |
|
88 | 90 | return a.exec(); |
|
89 | 91 | } |
@@ -1,83 +1,80 | |||
|
1 | 1 | #ifndef SCIQLOP_CATALOGUECONTROLLER_H |
|
2 | 2 | #define SCIQLOP_CATALOGUECONTROLLER_H |
|
3 | 3 | |
|
4 | 4 | #include "CoreGlobal.h" |
|
5 | 5 | |
|
6 | 6 | #include <Data/SqpRange.h> |
|
7 | 7 | |
|
8 | 8 | #include <QLoggingCategory> |
|
9 | 9 | #include <QObject> |
|
10 | 10 | #include <QUuid> |
|
11 | 11 | |
|
12 | 12 | #include <Common/spimpl.h> |
|
13 | 13 | |
|
14 | 14 | #include <memory> |
|
15 | 15 | |
|
16 | 16 | class DBCatalogue; |
|
17 | 17 | class DBEvent; |
|
18 | 18 | class DBEventProduct; |
|
19 | 19 | |
|
20 | 20 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController) |
|
21 | 21 | |
|
22 | 22 | class DataSourceItem; |
|
23 | 23 | class Variable; |
|
24 | 24 | |
|
25 | 25 | /** |
|
26 | 26 | * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI |
|
27 | 27 | * library. |
|
28 | 28 | */ |
|
29 | 29 | class SCIQLOP_CORE_EXPORT CatalogueController : public QObject { |
|
30 | 30 | Q_OBJECT |
|
31 | 31 | public: |
|
32 | 32 | explicit CatalogueController(QObject *parent = 0); |
|
33 | 33 | virtual ~CatalogueController(); |
|
34 | 34 | |
|
35 | 35 | // DB |
|
36 | 36 | QStringList getRepositories() const; |
|
37 | 37 | void addDB(const QString &dbPath); |
|
38 | 38 | void saveDB(const QString &destinationPath, const QString &repository); |
|
39 | 39 | |
|
40 | 40 | // Event |
|
41 | 41 | /// retrieveEvents with empty repository retrieve them from the default repository |
|
42 | 42 | std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const; |
|
43 | 43 | std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const; |
|
44 | 44 | std::list<std::shared_ptr<DBEvent> > |
|
45 | 45 | retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const; |
|
46 | 46 | void addEvent(std::shared_ptr<DBEvent> event); |
|
47 | 47 | void updateEvent(std::shared_ptr<DBEvent> event); |
|
48 | 48 | void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct); |
|
49 | 49 | void removeEvent(std::shared_ptr<DBEvent> event); |
|
50 | 50 | // void trashEvent(std::shared_ptr<DBEvent> event); |
|
51 | 51 | // void restore(QUuid eventId); |
|
52 | 52 | void saveEvent(std::shared_ptr<DBEvent> event); |
|
53 | 53 | |
|
54 | 54 | // Catalogue |
|
55 | 55 | // bool createCatalogue(const QString &name, QVector<QUuid> eventList); |
|
56 | 56 | /// retrieveEvents with empty repository retrieve them from the default repository |
|
57 | 57 | std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository |
|
58 | 58 | = QString()) const; |
|
59 | 59 | void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue); |
|
60 | 60 | void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue); |
|
61 | 61 | void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue); |
|
62 | 62 | |
|
63 | 63 | void saveAll(); |
|
64 | 64 | |
|
65 | 65 | /// Returns the MIME data associated to a list of variables |
|
66 | 66 | QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const; |
|
67 | 67 | |
|
68 | 68 | /// Returns the list of variables contained in a MIME data |
|
69 | 69 | QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const; |
|
70 | 70 | |
|
71 | 71 | public slots: |
|
72 | 72 | /// Manage init/end of the controller |
|
73 | 73 | void initialize(); |
|
74 | void finalize(); | |
|
75 | 74 | |
|
76 | 75 | private: |
|
77 | void waitForFinish(); | |
|
78 | ||
|
79 | 76 | class CatalogueControllerPrivate; |
|
80 | 77 | spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl; |
|
81 | 78 | }; |
|
82 | 79 | |
|
83 | 80 | #endif // SCIQLOP_CATALOGUECONTROLLER_H |
@@ -1,375 +1,368 | |||
|
1 | 1 | #include <Catalogue/CatalogueController.h> |
|
2 | 2 | |
|
3 | 3 | #include <Variable/Variable.h> |
|
4 | 4 | |
|
5 | 5 | #include <CatalogueDao.h> |
|
6 | 6 | |
|
7 | 7 | #include <ComparaisonPredicate.h> |
|
8 | 8 | #include <CompoundPredicate.h> |
|
9 | 9 | #include <DBCatalogue.h> |
|
10 | 10 | #include <DBEvent.h> |
|
11 | 11 | #include <DBEventProduct.h> |
|
12 | 12 | #include <DBTag.h> |
|
13 | 13 | #include <IRequestPredicate.h> |
|
14 | 14 | |
|
15 | 15 | #include <QDataStream> |
|
16 | 16 | #include <QMutex> |
|
17 | 17 | #include <QThread> |
|
18 | 18 | |
|
19 | 19 | #include <QDir> |
|
20 | 20 | #include <QStandardPaths> |
|
21 | 21 | |
|
22 | 22 | Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController") |
|
23 | 23 | |
|
24 | 24 | namespace { |
|
25 | 25 | |
|
26 | 26 | static QString REPOSITORY_WORK_SUFFIX = QString{"_work"}; |
|
27 | 27 | static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"}; |
|
28 | 28 | } |
|
29 | 29 | |
|
30 | 30 | class CatalogueController::CatalogueControllerPrivate { |
|
31 | 31 | |
|
32 | 32 | public: |
|
33 | 33 | explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {} |
|
34 | 34 | |
|
35 | QMutex m_WorkingMutex; | |
|
36 | 35 | CatalogueDao m_CatalogueDao; |
|
37 | 36 | |
|
38 | 37 | QStringList m_RepositoryList; |
|
39 | 38 | CatalogueController *m_Q; |
|
40 | 39 | |
|
41 | 40 | void copyDBtoDB(const QString &dbFrom, const QString &dbTo); |
|
42 | 41 | QString toWorkRepository(QString repository); |
|
43 | 42 | QString toSyncRepository(QString repository); |
|
44 | 43 | void savAllDB(); |
|
45 | 44 | |
|
46 | 45 | void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true); |
|
47 | 46 | void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true); |
|
48 | 47 | }; |
|
49 | 48 | |
|
50 | 49 | CatalogueController::CatalogueController(QObject *parent) |
|
51 | 50 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)} |
|
52 | 51 | { |
|
53 | 52 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") |
|
54 | 53 | << QThread::currentThread(); |
|
55 | 54 | } |
|
56 | 55 | |
|
57 | 56 | CatalogueController::~CatalogueController() |
|
58 | 57 | { |
|
59 | 58 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction") |
|
60 | 59 | << QThread::currentThread(); |
|
61 | this->waitForFinish(); | |
|
62 | 60 | } |
|
63 | 61 | |
|
64 | 62 | QStringList CatalogueController::getRepositories() const |
|
65 | 63 | { |
|
66 | 64 | return impl->m_RepositoryList; |
|
67 | 65 | } |
|
68 | 66 | |
|
69 | 67 | void CatalogueController::addDB(const QString &dbPath) |
|
70 | 68 | { |
|
71 | 69 | QDir dbDir(dbPath); |
|
72 | 70 | if (dbDir.exists()) { |
|
73 | 71 | auto dirName = dbDir.dirName(); |
|
74 | 72 | |
|
75 | 73 | if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName) |
|
76 | 74 | != impl->m_RepositoryList.cend()) { |
|
77 | 75 | qCCritical(LOG_CatalogueController()) |
|
78 | 76 | << tr("Impossible to addDB that is already loaded"); |
|
79 | 77 | } |
|
80 | 78 | |
|
81 | 79 | if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) { |
|
82 | 80 | qCCritical(LOG_CatalogueController()) |
|
83 | 81 | << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); |
|
84 | 82 | } |
|
85 | 83 | else { |
|
86 | 84 | impl->m_RepositoryList << dirName; |
|
87 | 85 | impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); |
|
88 | 86 | } |
|
89 | 87 | } |
|
90 | 88 | else { |
|
91 | 89 | qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ") |
|
92 | 90 | << dbPath; |
|
93 | 91 | } |
|
94 | 92 | } |
|
95 | 93 | |
|
96 | 94 | void CatalogueController::saveDB(const QString &destinationPath, const QString &repository) |
|
97 | 95 | { |
|
98 | 96 | if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) { |
|
99 | 97 | qCCritical(LOG_CatalogueController()) |
|
100 | 98 | << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath); |
|
101 | 99 | } |
|
102 | 100 | } |
|
103 | 101 | |
|
104 | 102 | std::list<std::shared_ptr<DBEvent> > |
|
105 | 103 | CatalogueController::retrieveEvents(const QString &repository) const |
|
106 | 104 | { |
|
107 | 105 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; |
|
108 | 106 | |
|
109 | 107 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
110 | 108 | auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); |
|
111 | 109 | for (auto event : events) { |
|
112 | 110 | eventsShared.push_back(std::make_shared<DBEvent>(event)); |
|
113 | 111 | } |
|
114 | 112 | return eventsShared; |
|
115 | 113 | } |
|
116 | 114 | |
|
117 | 115 | std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const |
|
118 | 116 | { |
|
119 | 117 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
120 | 118 | for (auto repository : impl->m_RepositoryList) { |
|
121 | 119 | eventsShared.splice(eventsShared.end(), retrieveEvents(repository)); |
|
122 | 120 | } |
|
123 | 121 | |
|
124 | 122 | return eventsShared; |
|
125 | 123 | } |
|
126 | 124 | |
|
127 | 125 | std::list<std::shared_ptr<DBEvent> > |
|
128 | 126 | CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const |
|
129 | 127 | { |
|
130 | 128 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; |
|
131 | 129 | auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue); |
|
132 | 130 | for (auto event : events) { |
|
133 | 131 | eventsShared.push_back(std::make_shared<DBEvent>(event)); |
|
134 | 132 | } |
|
135 | 133 | return eventsShared; |
|
136 | 134 | } |
|
137 | 135 | |
|
138 | 136 | void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event) |
|
139 | 137 | { |
|
140 | 138 | event->setRepository(impl->toWorkRepository(event->getRepository())); |
|
141 | 139 | |
|
142 | 140 | impl->m_CatalogueDao.updateEvent(*event); |
|
143 | 141 | } |
|
144 | 142 | |
|
145 | 143 | void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct) |
|
146 | 144 | { |
|
147 | 145 | impl->m_CatalogueDao.updateEventProduct(*eventProduct); |
|
148 | 146 | } |
|
149 | 147 | |
|
150 | 148 | void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event) |
|
151 | 149 | { |
|
152 | 150 | // Remove it from both repository and repository_work |
|
153 | 151 | event->setRepository(impl->toWorkRepository(event->getRepository())); |
|
154 | 152 | impl->m_CatalogueDao.removeEvent(*event); |
|
155 | 153 | event->setRepository(impl->toSyncRepository(event->getRepository())); |
|
156 | 154 | impl->m_CatalogueDao.removeEvent(*event); |
|
157 | 155 | } |
|
158 | 156 | |
|
159 | 157 | void CatalogueController::addEvent(std::shared_ptr<DBEvent> event) |
|
160 | 158 | { |
|
161 | 159 | event->setRepository(impl->toWorkRepository(event->getRepository())); |
|
162 | 160 | |
|
163 | 161 | auto eventTemp = *event; |
|
164 | 162 | impl->m_CatalogueDao.addEvent(eventTemp); |
|
165 | 163 | |
|
166 | 164 | // Call update is necessary at the creation of add Event if it has some tags or some event |
|
167 | 165 | // products |
|
168 | 166 | if (!event->getEventProducts().empty() || !event->getTags().empty()) { |
|
169 | 167 | |
|
170 | 168 | auto eventProductsTemp = eventTemp.getEventProducts(); |
|
171 | 169 | auto eventProductTempUpdated = std::list<DBEventProduct>{}; |
|
172 | 170 | for (auto eventProductTemp : eventProductsTemp) { |
|
173 | 171 | eventProductTemp.setEvent(eventTemp); |
|
174 | 172 | eventProductTempUpdated.push_back(eventProductTemp); |
|
175 | 173 | } |
|
176 | 174 | eventTemp.setEventProducts(eventProductTempUpdated); |
|
177 | 175 | |
|
178 | 176 | impl->m_CatalogueDao.updateEvent(eventTemp); |
|
179 | 177 | } |
|
180 | 178 | } |
|
181 | 179 | |
|
182 | 180 | void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event) |
|
183 | 181 | { |
|
184 | 182 | impl->saveEvent(event, true); |
|
185 | 183 | } |
|
186 | 184 | |
|
187 | 185 | std::list<std::shared_ptr<DBCatalogue> > |
|
188 | 186 | CatalogueController::retrieveCatalogues(const QString &repository) const |
|
189 | 187 | { |
|
190 | 188 | QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; |
|
191 | 189 | |
|
192 | 190 | auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; |
|
193 | 191 | auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); |
|
194 | 192 | for (auto catalogue : catalogues) { |
|
195 | 193 | cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue)); |
|
196 | 194 | } |
|
197 | 195 | return cataloguesShared; |
|
198 | 196 | } |
|
199 | 197 | |
|
200 | 198 | void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
201 | 199 | { |
|
202 | 200 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); |
|
203 | 201 | |
|
204 | 202 | impl->m_CatalogueDao.updateCatalogue(*catalogue); |
|
205 | 203 | } |
|
206 | 204 | |
|
207 | 205 | void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
208 | 206 | { |
|
209 | 207 | // Remove it from both repository and repository_work |
|
210 | 208 | catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); |
|
211 | 209 | impl->m_CatalogueDao.removeCatalogue(*catalogue); |
|
212 | 210 | catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); |
|
213 | 211 | impl->m_CatalogueDao.removeCatalogue(*catalogue); |
|
214 | 212 | } |
|
215 | 213 | |
|
216 | 214 | void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue) |
|
217 | 215 | { |
|
218 | 216 | impl->saveCatalogue(catalogue, true); |
|
219 | 217 | } |
|
220 | 218 | |
|
221 | 219 | void CatalogueController::saveAll() |
|
222 | 220 | { |
|
223 | 221 | for (auto repository : impl->m_RepositoryList) { |
|
224 | 222 | // Save Event |
|
225 | 223 | auto events = this->retrieveEvents(repository); |
|
226 | 224 | for (auto event : events) { |
|
227 | 225 | impl->saveEvent(event, false); |
|
228 | 226 | } |
|
229 | 227 | |
|
230 | 228 | // Save Catalogue |
|
231 | 229 | auto catalogues = this->retrieveCatalogues(repository); |
|
232 | 230 | for (auto catalogue : catalogues) { |
|
233 | 231 | impl->saveCatalogue(catalogue, false); |
|
234 | 232 | } |
|
235 | 233 | } |
|
236 | 234 | |
|
237 | 235 | impl->savAllDB(); |
|
238 | 236 | } |
|
239 | 237 | |
|
240 | 238 | QByteArray |
|
241 | 239 | CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const |
|
242 | 240 | { |
|
243 | 241 | auto encodedData = QByteArray{}; |
|
244 | 242 | |
|
245 | 243 | QMap<QString, QVariantList> idsPerRepository; |
|
246 | 244 | for (auto event : events) { |
|
247 | 245 | idsPerRepository[event->getRepository()] << event->getUniqId(); |
|
248 | 246 | } |
|
249 | 247 | |
|
250 | 248 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; |
|
251 | 249 | stream << idsPerRepository; |
|
252 | 250 | |
|
253 | 251 | return encodedData; |
|
254 | 252 | } |
|
255 | 253 | |
|
256 | 254 | QVector<std::shared_ptr<DBEvent> > |
|
257 | 255 | CatalogueController::eventsForMimeData(const QByteArray &mimeData) const |
|
258 | 256 | { |
|
259 | 257 | auto events = QVector<std::shared_ptr<DBEvent> >{}; |
|
260 | 258 | QDataStream stream{mimeData}; |
|
261 | 259 | |
|
262 | 260 | QMap<QString, QVariantList> idsPerRepository; |
|
263 | 261 | stream >> idsPerRepository; |
|
264 | 262 | |
|
265 | 263 | for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) { |
|
266 | 264 | auto repository = it.key(); |
|
267 | 265 | auto allRepositoryEvent = retrieveEvents(repository); |
|
268 | 266 | for (auto uuid : it.value()) { |
|
269 | 267 | for (auto repositoryEvent : allRepositoryEvent) { |
|
270 | 268 | if (uuid.toUuid() == repositoryEvent->getUniqId()) { |
|
271 | 269 | events << repositoryEvent; |
|
272 | 270 | } |
|
273 | 271 | } |
|
274 | 272 | } |
|
275 | 273 | } |
|
276 | 274 | |
|
277 | 275 | return events; |
|
278 | 276 | } |
|
279 | 277 | |
|
280 | 278 | void CatalogueController::initialize() |
|
281 | 279 | { |
|
280 | <<<<<<< HEAD | |
|
282 | 281 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") |
|
283 | 282 | << QThread::currentThread(); |
|
284 | 283 | impl->m_WorkingMutex.lock(); |
|
284 | ======= | |
|
285 | qCDebug(LOG_CatalogueController()) | |
|
286 | << tr("CatalogueController init") << QThread::currentThread(); | |
|
287 | >>>>>>> 286decc... unthread the catalogue controller | |
|
285 | 288 | impl->m_CatalogueDao.initialize(); |
|
286 | 289 | auto defaultRepositoryLocation |
|
287 | 290 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); |
|
288 | 291 | |
|
289 | 292 | QDir defaultRepositoryLocationDir; |
|
290 | 293 | if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { |
|
291 | 294 | defaultRepositoryLocationDir.cd(defaultRepositoryLocation); |
|
292 | 295 | auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); |
|
293 | 296 | qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") |
|
294 | 297 | << defaultRepository; |
|
295 | 298 | this->addDB(defaultRepository); |
|
296 | 299 | } |
|
297 | 300 | else { |
|
298 | 301 | qCWarning(LOG_CatalogueController()) |
|
299 | 302 | << tr("Cannot load the persistent default repository from ") |
|
300 | 303 | << defaultRepositoryLocation; |
|
301 | 304 | } |
|
302 | 305 | |
|
303 | 306 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); |
|
304 | 307 | } |
|
305 | 308 | |
|
306 | void CatalogueController::finalize() | |
|
307 | { | |
|
308 | impl->m_WorkingMutex.unlock(); | |
|
309 | } | |
|
310 | ||
|
311 | void CatalogueController::waitForFinish() | |
|
312 | { | |
|
313 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
|
314 | } | |
|
315 | ||
|
316 | 309 | void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom, |
|
317 | 310 | const QString &dbTo) |
|
318 | 311 | { |
|
319 | 312 | // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{}; |
|
320 | 313 | auto catalogues = m_CatalogueDao.getCatalogues(dbFrom); |
|
321 | 314 | auto events = m_CatalogueDao.getEvents(dbFrom); |
|
322 | 315 | for (auto catalogue : catalogues) { |
|
323 | 316 | m_CatalogueDao.copyCatalogue(catalogue, dbTo, true); |
|
324 | 317 | } |
|
325 | 318 | |
|
326 | 319 | for (auto event : events) { |
|
327 | 320 | m_CatalogueDao.copyEvent(event, dbTo, true); |
|
328 | 321 | } |
|
329 | 322 | } |
|
330 | 323 | |
|
331 | 324 | QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository) |
|
332 | 325 | { |
|
333 | 326 | auto syncRepository = toSyncRepository(repository); |
|
334 | 327 | |
|
335 | 328 | return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX); |
|
336 | 329 | } |
|
337 | 330 | |
|
338 | 331 | QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository) |
|
339 | 332 | { |
|
340 | 333 | auto syncRepository = repository; |
|
341 | 334 | if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) { |
|
342 | 335 | syncRepository.remove(REPOSITORY_WORK_SUFFIX); |
|
343 | 336 | } |
|
344 | 337 | else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) { |
|
345 | 338 | syncRepository.remove(REPOSITORY_TRASH_SUFFIX); |
|
346 | 339 | } |
|
347 | 340 | return syncRepository; |
|
348 | 341 | } |
|
349 | 342 | |
|
350 | 343 | void CatalogueController::CatalogueControllerPrivate::savAllDB() |
|
351 | 344 | { |
|
352 | 345 | for (auto repository : m_RepositoryList) { |
|
353 | 346 | auto defaultRepositoryLocation |
|
354 | 347 | = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); |
|
355 | 348 | m_CatalogueDao.saveDB(defaultRepositoryLocation, repository); |
|
356 | 349 | } |
|
357 | 350 | } |
|
358 | 351 | |
|
359 | 352 | void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event, |
|
360 | 353 | bool persist) |
|
361 | 354 | { |
|
362 | 355 | m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true); |
|
363 | 356 | if (persist) { |
|
364 | 357 | savAllDB(); |
|
365 | 358 | } |
|
366 | 359 | } |
|
367 | 360 | |
|
368 | 361 | void CatalogueController::CatalogueControllerPrivate::saveCatalogue( |
|
369 | 362 | std::shared_ptr<DBCatalogue> catalogue, bool persist) |
|
370 | 363 | { |
|
371 | 364 | m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true); |
|
372 | 365 | if (persist) { |
|
373 | 366 | savAllDB(); |
|
374 | 367 | } |
|
375 | 368 | } |
@@ -1,217 +1,205 | |||
|
1 | 1 | #include "SqpApplication.h" |
|
2 | 2 | |
|
3 | 3 | #include <Actions/ActionsGuiController.h> |
|
4 | 4 | #include <Catalogue/CatalogueController.h> |
|
5 | 5 | #include <Data/IDataProvider.h> |
|
6 | 6 | #include <DataSource/DataSourceController.h> |
|
7 | 7 | #include <DragAndDrop/DragDropGuiController.h> |
|
8 | 8 | #include <Network/NetworkController.h> |
|
9 | 9 | #include <QThread> |
|
10 | 10 | #include <Time/TimeController.h> |
|
11 | 11 | #include <Variable/Variable.h> |
|
12 | 12 | #include <Variable/VariableController.h> |
|
13 | 13 | #include <Variable/VariableModel.h> |
|
14 | 14 | #include <Visualization/VisualizationController.h> |
|
15 | 15 | |
|
16 | 16 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") |
|
17 | 17 | |
|
18 | 18 | class SqpApplication::SqpApplicationPrivate { |
|
19 | 19 | public: |
|
20 | 20 | SqpApplicationPrivate() |
|
21 | 21 | : m_DataSourceController{std::make_unique<DataSourceController>()}, |
|
22 | 22 | m_VariableController{std::make_unique<VariableController>()}, |
|
23 | 23 | m_TimeController{std::make_unique<TimeController>()}, |
|
24 | 24 | m_NetworkController{std::make_unique<NetworkController>()}, |
|
25 | 25 | m_VisualizationController{std::make_unique<VisualizationController>()}, |
|
26 | 26 | m_DragDropGuiController{std::make_unique<DragDropGuiController>()}, |
|
27 | 27 | m_CatalogueController{std::make_unique<CatalogueController>()}, |
|
28 | 28 | m_ActionsGuiController{std::make_unique<ActionsGuiController>()}, |
|
29 | 29 | m_PlotInterractionMode(SqpApplication::PlotsInteractionMode::None), |
|
30 | 30 | m_PlotCursorMode(SqpApplication::PlotsCursorMode::NoCursor) |
|
31 | 31 | { |
|
32 | 32 | // /////////////////////////////// // |
|
33 | 33 | // Connections between controllers // |
|
34 | 34 | // /////////////////////////////// // |
|
35 | 35 | |
|
36 | 36 | // VariableController <-> DataSourceController |
|
37 | 37 | connect(m_DataSourceController.get(), |
|
38 | 38 | SIGNAL(variableCreationRequested(const QString &, const QVariantHash &, |
|
39 | 39 | std::shared_ptr<IDataProvider>)), |
|
40 | 40 | m_VariableController.get(), |
|
41 | 41 | SLOT(createVariable(const QString &, const QVariantHash &, |
|
42 | 42 | std::shared_ptr<IDataProvider>))); |
|
43 | 43 | |
|
44 | 44 | connect(m_VariableController->variableModel(), &VariableModel::requestVariable, |
|
45 | 45 | m_DataSourceController.get(), &DataSourceController::requestVariable); |
|
46 | 46 | |
|
47 | 47 | // VariableController <-> VisualizationController |
|
48 | 48 | connect(m_VariableController.get(), |
|
49 | 49 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), |
|
50 | 50 | m_VisualizationController.get(), |
|
51 | 51 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); |
|
52 | 52 | |
|
53 | 53 | connect(m_VariableController.get(), |
|
54 | 54 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), |
|
55 | 55 | m_VisualizationController.get(), |
|
56 | 56 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &))); |
|
57 | 57 | |
|
58 | 58 | |
|
59 | 59 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); |
|
60 | 60 | m_DataSourceControllerThread.setObjectName("DataSourceControllerThread"); |
|
61 | 61 | m_NetworkController->moveToThread(&m_NetworkControllerThread); |
|
62 | 62 | m_NetworkControllerThread.setObjectName("NetworkControllerThread"); |
|
63 | 63 | m_VariableController->moveToThread(&m_VariableControllerThread); |
|
64 | 64 | m_VariableControllerThread.setObjectName("VariableControllerThread"); |
|
65 | 65 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); |
|
66 | 66 | m_VisualizationControllerThread.setObjectName("VsualizationControllerThread"); |
|
67 | m_CatalogueController->moveToThread(&m_CatalogueControllerThread); | |
|
68 | m_CatalogueControllerThread.setObjectName("CatalogueControllerThread"); | |
|
69 | ||
|
70 | 67 | |
|
71 | 68 | // Additionnal init |
|
72 | 69 | m_VariableController->setTimeController(m_TimeController.get()); |
|
73 | 70 | } |
|
74 | 71 | |
|
75 | 72 | virtual ~SqpApplicationPrivate() |
|
76 | 73 | { |
|
77 | 74 | m_DataSourceControllerThread.quit(); |
|
78 | 75 | m_DataSourceControllerThread.wait(); |
|
79 | 76 | |
|
80 | 77 | m_NetworkControllerThread.quit(); |
|
81 | 78 | m_NetworkControllerThread.wait(); |
|
82 | 79 | |
|
83 | 80 | m_VariableControllerThread.quit(); |
|
84 | 81 | m_VariableControllerThread.wait(); |
|
85 | 82 | |
|
86 | 83 | m_VisualizationControllerThread.quit(); |
|
87 | 84 | m_VisualizationControllerThread.wait(); |
|
88 | ||
|
89 | m_CatalogueControllerThread.quit(); | |
|
90 | m_CatalogueControllerThread.wait(); | |
|
91 | 85 | } |
|
92 | 86 | |
|
93 | 87 | std::unique_ptr<DataSourceController> m_DataSourceController; |
|
94 | 88 | std::unique_ptr<VariableController> m_VariableController; |
|
95 | 89 | std::unique_ptr<TimeController> m_TimeController; |
|
96 | 90 | std::unique_ptr<NetworkController> m_NetworkController; |
|
97 | 91 | std::unique_ptr<VisualizationController> m_VisualizationController; |
|
98 | 92 | std::unique_ptr<CatalogueController> m_CatalogueController; |
|
99 | 93 | |
|
100 | 94 | QThread m_DataSourceControllerThread; |
|
101 | 95 | QThread m_NetworkControllerThread; |
|
102 | 96 | QThread m_VariableControllerThread; |
|
103 | 97 | QThread m_VisualizationControllerThread; |
|
104 | QThread m_CatalogueControllerThread; | |
|
105 | 98 | |
|
106 | 99 | std::unique_ptr<DragDropGuiController> m_DragDropGuiController; |
|
107 | 100 | std::unique_ptr<ActionsGuiController> m_ActionsGuiController; |
|
108 | 101 | |
|
109 | 102 | SqpApplication::PlotsInteractionMode m_PlotInterractionMode; |
|
110 | 103 | SqpApplication::PlotsCursorMode m_PlotCursorMode; |
|
111 | 104 | }; |
|
112 | 105 | |
|
113 | 106 | |
|
114 | 107 | SqpApplication::SqpApplication(int &argc, char **argv) |
|
115 | 108 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} |
|
116 | 109 | { |
|
117 | 110 | qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread(); |
|
118 | 111 | |
|
119 | 112 | connect(&impl->m_DataSourceControllerThread, &QThread::started, |
|
120 | 113 | impl->m_DataSourceController.get(), &DataSourceController::initialize); |
|
121 | 114 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, |
|
122 | 115 | impl->m_DataSourceController.get(), &DataSourceController::finalize); |
|
123 | 116 | |
|
124 | 117 | connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(), |
|
125 | 118 | &NetworkController::initialize); |
|
126 | 119 | connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(), |
|
127 | 120 | &NetworkController::finalize); |
|
128 | 121 | |
|
129 | 122 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), |
|
130 | 123 | &VariableController::initialize); |
|
131 | 124 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), |
|
132 | 125 | &VariableController::finalize); |
|
133 | 126 | |
|
134 | 127 | connect(&impl->m_VisualizationControllerThread, &QThread::started, |
|
135 | 128 | impl->m_VisualizationController.get(), &VisualizationController::initialize); |
|
136 | 129 | connect(&impl->m_VisualizationControllerThread, &QThread::finished, |
|
137 | 130 | impl->m_VisualizationController.get(), &VisualizationController::finalize); |
|
138 | 131 | |
|
139 | connect(&impl->m_CatalogueControllerThread, &QThread::started, | |
|
140 | impl->m_CatalogueController.get(), &CatalogueController::initialize); | |
|
141 | connect(&impl->m_CatalogueControllerThread, &QThread::finished, | |
|
142 | impl->m_CatalogueController.get(), &CatalogueController::finalize); | |
|
143 | ||
|
144 | 132 | impl->m_DataSourceControllerThread.start(); |
|
145 | 133 | impl->m_NetworkControllerThread.start(); |
|
146 | 134 | impl->m_VariableControllerThread.start(); |
|
147 | 135 | impl->m_VisualizationControllerThread.start(); |
|
148 |
impl->m_CatalogueController |
|
|
136 | impl->m_CatalogueController->initialize(); | |
|
149 | 137 | } |
|
150 | 138 | |
|
151 | 139 | SqpApplication::~SqpApplication() |
|
152 | 140 | { |
|
153 | 141 | } |
|
154 | 142 | |
|
155 | 143 | void SqpApplication::initialize() |
|
156 | 144 | { |
|
157 | 145 | } |
|
158 | 146 | |
|
159 | 147 | DataSourceController &SqpApplication::dataSourceController() noexcept |
|
160 | 148 | { |
|
161 | 149 | return *impl->m_DataSourceController; |
|
162 | 150 | } |
|
163 | 151 | |
|
164 | 152 | NetworkController &SqpApplication::networkController() noexcept |
|
165 | 153 | { |
|
166 | 154 | return *impl->m_NetworkController; |
|
167 | 155 | } |
|
168 | 156 | |
|
169 | 157 | TimeController &SqpApplication::timeController() noexcept |
|
170 | 158 | { |
|
171 | 159 | return *impl->m_TimeController; |
|
172 | 160 | } |
|
173 | 161 | |
|
174 | 162 | VariableController &SqpApplication::variableController() noexcept |
|
175 | 163 | { |
|
176 | 164 | return *impl->m_VariableController; |
|
177 | 165 | } |
|
178 | 166 | |
|
179 | 167 | VisualizationController &SqpApplication::visualizationController() noexcept |
|
180 | 168 | { |
|
181 | 169 | return *impl->m_VisualizationController; |
|
182 | 170 | } |
|
183 | 171 | |
|
184 | 172 | CatalogueController &SqpApplication::catalogueController() noexcept |
|
185 | 173 | { |
|
186 | 174 | return *impl->m_CatalogueController; |
|
187 | 175 | } |
|
188 | 176 | |
|
189 | 177 | DragDropGuiController &SqpApplication::dragDropGuiController() noexcept |
|
190 | 178 | { |
|
191 | 179 | return *impl->m_DragDropGuiController; |
|
192 | 180 | } |
|
193 | 181 | |
|
194 | 182 | ActionsGuiController &SqpApplication::actionsGuiController() noexcept |
|
195 | 183 | { |
|
196 | 184 | return *impl->m_ActionsGuiController; |
|
197 | 185 | } |
|
198 | 186 | |
|
199 | 187 | SqpApplication::PlotsInteractionMode SqpApplication::plotsInteractionMode() const |
|
200 | 188 | { |
|
201 | 189 | return impl->m_PlotInterractionMode; |
|
202 | 190 | } |
|
203 | 191 | |
|
204 | 192 | void SqpApplication::setPlotsInteractionMode(SqpApplication::PlotsInteractionMode mode) |
|
205 | 193 | { |
|
206 | 194 | impl->m_PlotInterractionMode = mode; |
|
207 | 195 | } |
|
208 | 196 | |
|
209 | 197 | SqpApplication::PlotsCursorMode SqpApplication::plotsCursorMode() const |
|
210 | 198 | { |
|
211 | 199 | return impl->m_PlotCursorMode; |
|
212 | 200 | } |
|
213 | 201 | |
|
214 | 202 | void SqpApplication::setPlotsCursorMode(SqpApplication::PlotsCursorMode mode) |
|
215 | 203 | { |
|
216 | 204 | impl->m_PlotCursorMode = mode; |
|
217 | 205 | } |
General Comments 3
Status change > Approved
You need to be logged in to leave comments.
Login now