##// END OF EJS Templates
Implements the method for setting data source structure
Alexandre Leroux -
r37:20b8bea56acf
parent child
Show More
@@ -9,6 +9,8
9
9
10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
11
11
12 class DataSourceItem;
13
12 /**
14 /**
13 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
15 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
14 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
16 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
@@ -30,11 +32,25 public:
30 */
32 */
31 QUuid registerDataSource(const QString &dataSourceName) noexcept;
33 QUuid registerDataSource(const QString &dataSourceName) noexcept;
32
34
35 /**
36 * Sets the structure of a data source. The controller takes ownership of the structure.
37 * @param dataSourceUid the unique id with which the data source has been registered into the
38 * controller. If it is invalid, the method has no effect.
39 * @param dataSourceItem the structure of the data source
40 * @sa registerDataSource()
41 */
42 void setDataSourceItem(const QUuid &dataSourceUid,
43 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
44
33 public slots:
45 public slots:
34 /// Manage init/end of the controller
46 /// Manage init/end of the controller
35 void initialize();
47 void initialize();
36 void finalize();
48 void finalize();
37
49
50 signals:
51 /// Signal emitted when a structure has been set for a data source
52 void dataSourceItemSet(const DataSourceItem &dataSourceItem);
53
38 private:
54 private:
39 void waitForFinish();
55 void waitForFinish();
40
56
@@ -1,4 +1,5
1 #include <DataSource/DataSourceController.h>
1 #include <DataSource/DataSourceController.h>
2 #include <DataSource/DataSourceItem.h>
2
3
3 #include <QMutex>
4 #include <QMutex>
4 #include <QThread>
5 #include <QThread>
@@ -11,7 +12,10 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
11 class DataSourceController::DataSourceControllerPrivate {
12 class DataSourceController::DataSourceControllerPrivate {
12 public:
13 public:
13 QMutex m_WorkingMutex;
14 QMutex m_WorkingMutex;
15 /// Data sources registered
14 QHash<QUuid, QString> m_DataSources;
16 QHash<QUuid, QString> m_DataSources;
17 /// Data sources structures
18 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
15 };
19 };
16
20
17 DataSourceController::DataSourceController(QObject *parent)
21 DataSourceController::DataSourceController(QObject *parent)
@@ -36,6 +40,25 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) no
36 return dataSourceUid;
40 return dataSourceUid;
37 }
41 }
38
42
43 void DataSourceController::setDataSourceItem(
44 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
45 {
46 if (impl->m_DataSources.contains(dataSourceUid)) {
47 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
48
49 // Retrieves the data source item to emit the signal with it
50 auto it = impl->m_DataSourceItems.find(dataSourceUid);
51 if (it != impl->m_DataSourceItems.end()) {
52 emit dataSourceItemSet(*it->second);
53 }
54 }
55 else {
56 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
57 "data source has been registered with the uid")
58 .arg(dataSourceUid.toString());
59 }
60 }
61
39 void DataSourceController::initialize()
62 void DataSourceController::initialize()
40 {
63 {
41 qCDebug(LOG_DataSourceController())
64 qCDebug(LOG_DataSourceController())
General Comments 0
You need to be logged in to leave comments. Login now