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