##// END OF EJS Templates
drop of product on the variables
trabillard -
r874:7d2f05cda6a0
parent child
Show More
@@ -1,94 +1,99
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QObject>
7 #include <QObject>
8 #include <QUuid>
8 #include <QUuid>
9
9
10 #include <Common/spimpl.h>
10 #include <Common/spimpl.h>
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
13
13
14 class DataSourceItem;
14 class DataSourceItem;
15 class IDataProvider;
15 class IDataProvider;
16
16
17 /**
17 /**
18 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
18 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
19 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
19 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
20 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
20 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
21 * source) then others specifics method will be able to access it. You can load a data source driver
21 * source) then others specifics method will be able to access it. You can load a data source driver
22 * plugin then create a data source.
22 * plugin then create a data source.
23 */
23 */
24 class SCIQLOP_CORE_EXPORT DataSourceController : public QObject {
24 class SCIQLOP_CORE_EXPORT DataSourceController : public QObject {
25 Q_OBJECT
25 Q_OBJECT
26 public:
26 public:
27 explicit DataSourceController(QObject *parent = 0);
27 explicit DataSourceController(QObject *parent = 0);
28 virtual ~DataSourceController();
28 virtual ~DataSourceController();
29
29
30 /**
30 /**
31 * Registers a data source. The method delivers a unique id that can be used afterwards to
31 * Registers a data source. The method delivers a unique id that can be used afterwards to
32 * access to the data source properties (structure, connection parameters, data provider, etc.)
32 * access to the data source properties (structure, connection parameters, data provider, etc.)
33 * @param dataSourceName the name of the data source
33 * @param dataSourceName the name of the data source
34 * @return the unique id with which the data source has been registered
34 * @return the unique id with which the data source has been registered
35 */
35 */
36 QUuid registerDataSource(const QString &dataSourceName) noexcept;
36 QUuid registerDataSource(const QString &dataSourceName) noexcept;
37
37
38 /**
38 /**
39 * Sets the structure of a data source. The controller takes ownership of the structure.
39 * Sets the structure of a data source. The controller takes ownership of the structure.
40 * @param dataSourceUid the unique id with which the data source has been registered into the
40 * @param dataSourceUid the unique id with which the data source has been registered into the
41 * controller. If it is invalid, the method has no effect.
41 * controller. If it is invalid, the method has no effect.
42 * @param dataSourceItem the structure of the data source. It must be not null to be registered
42 * @param dataSourceItem the structure of the data source. It must be not null to be registered
43 * @sa registerDataSource()
43 * @sa registerDataSource()
44 */
44 */
45 void setDataSourceItem(const QUuid &dataSourceUid,
45 void setDataSourceItem(const QUuid &dataSourceUid,
46 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
46 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
47
47
48 /**
48 /**
49 * Sets the data provider used to retrieve data from of a data source. The controller takes
49 * Sets the data provider used to retrieve data from of a data source. The controller takes
50 * ownership of the provider.
50 * ownership of the provider.
51 * @param dataSourceUid the unique id with which the data source has been registered into the
51 * @param dataSourceUid the unique id with which the data source has been registered into the
52 * controller. If it is invalid, the method has no effect.
52 * controller. If it is invalid, the method has no effect.
53 * @param dataProvider the provider of the data source
53 * @param dataProvider the provider of the data source
54 * @sa registerDataSource()
54 * @sa registerDataSource()
55 */
55 */
56 void setDataProvider(const QUuid &dataSourceUid,
56 void setDataProvider(const QUuid &dataSourceUid,
57 std::unique_ptr<IDataProvider> dataProvider) noexcept;
57 std::unique_ptr<IDataProvider> dataProvider) noexcept;
58
58
59 /**
59 /**
60 * Loads an item (product) as a variable in SciQlop
60 * Loads an item (product) as a variable in SciQlop
61 * @param dataSourceUid the unique id of the data source containing the item. It is used to get
61 * @param dataSourceUid the unique id of the data source containing the item. It is used to get
62 * the data provider associated to the data source, and pass it to for the variable creation
62 * the data provider associated to the data source, and pass it to for the variable creation
63 * @param productItem the item to load
63 * @param productItem the item to load
64 */
64 */
65 void loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept;
65 void loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept;
66
66
67 QByteArray mimeDataForProductsData(const QVariantList &productsData) const;
68 QVariantList productsDataForMimeData(const QByteArray &mimeData) const;
69
67 public slots:
70 public slots:
68 /// Manage init/end of the controller
71 /// Manage init/end of the controller
69 void initialize();
72 void initialize();
70 void finalize();
73 void finalize();
71
74
75 void requestVariable(const QVariantHash &productData);
76
72 signals:
77 signals:
73 /// Signal emitted when a structure has been set for a data source
78 /// Signal emitted when a structure has been set for a data source
74 void dataSourceItemSet(DataSourceItem *dataSourceItem);
79 void dataSourceItemSet(DataSourceItem *dataSourceItem);
75
80
76 /**
81 /**
77 * Signal emitted when a variable creation is asked for a product
82 * Signal emitted when a variable creation is asked for a product
78 * @param variableName the name of the variable
83 * @param variableName the name of the variable
79 * @param variableMetadata the metadata of the variable
84 * @param variableMetadata the metadata of the variable
80 * @param variableProvider the provider that will be used to retrieve the data of the variable
85 * @param variableProvider the provider that will be used to retrieve the data of the variable
81 * (can be null)
86 * (can be null)
82 */
87 */
83 void variableCreationRequested(const QString &variableName,
88 void variableCreationRequested(const QString &variableName,
84 const QVariantHash &variableMetadata,
89 const QVariantHash &variableMetadata,
85 std::shared_ptr<IDataProvider> variableProvider);
90 std::shared_ptr<IDataProvider> variableProvider);
86
91
87 private:
92 private:
88 void waitForFinish();
93 void waitForFinish();
89
94
90 class DataSourceControllerPrivate;
95 class DataSourceControllerPrivate;
91 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
96 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
92 };
97 };
93
98
94 #endif // SCIQLOP_DATASOURCECONTROLLER_H
99 #endif // SCIQLOP_DATASOURCECONTROLLER_H
@@ -1,102 +1,110
1 #ifndef SCIQLOP_DATASOURCEITEM_H
1 #ifndef SCIQLOP_DATASOURCEITEM_H
2 #define SCIQLOP_DATASOURCEITEM_H
2 #define SCIQLOP_DATASOURCEITEM_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Common/spimpl.h>
6 #include <Common/spimpl.h>
7
7
8 #include <QVariant>
8 #include <QVariant>
9 #include <QVector>
9 #include <QVector>
10
10
11 class DataSourceItemAction;
11 class DataSourceItemAction;
12
12
13 /**
13 /**
14 * Possible types of an item
14 * Possible types of an item
15 */
15 */
16 enum class DataSourceItemType { NODE, PRODUCT, COMPONENT };
16 enum class DataSourceItemType { NODE, PRODUCT, COMPONENT };
17
17
18 /**
18 /**
19 * @brief The DataSourceItem class aims to represent a structure element of a data source.
19 * @brief The DataSourceItem class aims to represent a structure element of a data source.
20 * A data source has a tree structure that is made up of a main DataSourceItem object (root)
20 * A data source has a tree structure that is made up of a main DataSourceItem object (root)
21 * containing other DataSourceItem objects (children).
21 * containing other DataSourceItem objects (children).
22 * For each DataSourceItem can be associated a set of data representing it.
22 * For each DataSourceItem can be associated a set of data representing it.
23 */
23 */
24 class SCIQLOP_CORE_EXPORT DataSourceItem {
24 class SCIQLOP_CORE_EXPORT DataSourceItem {
25 public:
25 public:
26 /// Key associated with the name of the item
26 /// Key associated with the name of the item
27 static const QString NAME_DATA_KEY;
27 static const QString NAME_DATA_KEY;
28
28
29 explicit DataSourceItem(DataSourceItemType type, const QString &name);
29 explicit DataSourceItem(DataSourceItemType type, const QString &name);
30 explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {});
30 explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {});
31
31
32 /// @return the actions of the item as a vector
32 /// @return the actions of the item as a vector
33 QVector<DataSourceItemAction *> actions() const noexcept;
33 QVector<DataSourceItemAction *> actions() const noexcept;
34
34
35 /**
35 /**
36 * Adds an action to the item. The item takes ownership of the action, and the action is
36 * Adds an action to the item. The item takes ownership of the action, and the action is
37 * automatically associated to the item
37 * automatically associated to the item
38 * @param action the action to add
38 * @param action the action to add
39 */
39 */
40 void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept;
40 void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept;
41
41
42 /**
42 /**
43 * Adds a child to the item. The item takes ownership of the child.
43 * Adds a child to the item. The item takes ownership of the child.
44 * @param child the child to add
44 * @param child the child to add
45 */
45 */
46 void appendChild(std::unique_ptr<DataSourceItem> child) noexcept;
46 void appendChild(std::unique_ptr<DataSourceItem> child) noexcept;
47
47
48 /**
48 /**
49 * Returns the item's child associated to an index
49 * Returns the item's child associated to an index
50 * @param childIndex the index to search
50 * @param childIndex the index to search
51 * @return a pointer to the child if index is valid, nullptr otherwise
51 * @return a pointer to the child if index is valid, nullptr otherwise
52 */
52 */
53 DataSourceItem *child(int childIndex) const noexcept;
53 DataSourceItem *child(int childIndex) const noexcept;
54
54
55 int childCount() const noexcept;
55 int childCount() const noexcept;
56
56
57 /**
57 /**
58 * Get the data associated to a key
58 * Get the data associated to a key
59 * @param key the key to search
59 * @param key the key to search
60 * @return the data found if key is valid, default QVariant otherwise
60 * @return the data found if key is valid, default QVariant otherwise
61 */
61 */
62 QVariant data(const QString &key) const noexcept;
62 QVariant data(const QString &key) const noexcept;
63
63
64 /// Gets all data
64 /// Gets all data
65 QVariantHash data() const noexcept;
65 QVariantHash data() const noexcept;
66
66
67 bool isRoot() const noexcept;
67 bool isRoot() const noexcept;
68
68
69 QString name() const noexcept;
69 QString name() const noexcept;
70
70
71 /**
71 /**
72 * Get the item's parent
72 * Get the item's parent
73 * @return a pointer to the parent if it exists, nullptr if the item is a root
73 * @return a pointer to the parent if it exists, nullptr if the item is a root
74 */
74 */
75 DataSourceItem *parentItem() const noexcept;
75 DataSourceItem *parentItem() const noexcept;
76
76
77 /**
77 /**
78 * Gets the item's root
78 * Gets the item's root
79 * @return the top parent, the item itself if it's the root item
79 * @return the top parent, the item itself if it's the root item
80 */
80 */
81 const DataSourceItem &rootItem() const noexcept;
81 const DataSourceItem &rootItem() const noexcept;
82
82
83 /**
83 /**
84 * Sets or appends a value to a key
84 * Sets or appends a value to a key
85 * @param key the key
85 * @param key the key
86 * @param value the value
86 * @param value the value
87 * @param append if true, the value is added to the values already existing for the key,
87 * @param append if true, the value is added to the values already existing for the key,
88 * otherwise it replaces the existing values
88 * otherwise it replaces the existing values
89 */
89 */
90 void setData(const QString &key, const QVariant &value, bool append = false) noexcept;
90 void setData(const QString &key, const QVariant &value, bool append = false) noexcept;
91
91
92 DataSourceItemType type() const noexcept;
92 DataSourceItemType type() const noexcept;
93
93
94 /**
95 * @brief Searches the first child matching the specified data.
96 * @param data The data to search.
97 * @param recursive So the search recursively.
98 * @return the item matching the data or nullptr if it was not found.
99 */
100 DataSourceItem *findItem(const QVariantHash &data, bool recursive);
101
94 bool operator==(const DataSourceItem &other);
102 bool operator==(const DataSourceItem &other);
95 bool operator!=(const DataSourceItem &other);
103 bool operator!=(const DataSourceItem &other);
96
104
97 private:
105 private:
98 class DataSourceItemPrivate;
106 class DataSourceItemPrivate;
99 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
107 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
100 };
108 };
101
109
102 #endif // SCIQLOP_DATASOURCEITEMMODEL_H
110 #endif // SCIQLOP_DATASOURCEITEMMODEL_H
@@ -1,109 +1,110
1 #ifndef SCIQLOP_VARIABLEMODEL_H
1 #ifndef SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_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 <QAbstractTableModel>
8 #include <QAbstractTableModel>
9 #include <QLoggingCategory>
9 #include <QLoggingCategory>
10
10
11 #include <Common/MetaTypes.h>
11 #include <Common/MetaTypes.h>
12 #include <Common/spimpl.h>
12 #include <Common/spimpl.h>
13
13
14 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
14 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
15
15
16 enum VariableRoles { ProgressRole = Qt::UserRole };
16 enum VariableRoles { ProgressRole = Qt::UserRole };
17
17
18
18
19 class IDataSeries;
19 class IDataSeries;
20 class Variable;
20 class Variable;
21 class VariableController;
21 class VariableController;
22
22
23 /**
23 /**
24 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
24 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
25 */
25 */
26 class SCIQLOP_CORE_EXPORT VariableModel : public QAbstractTableModel {
26 class SCIQLOP_CORE_EXPORT VariableModel : public QAbstractTableModel {
27 Q_OBJECT
27 Q_OBJECT
28 public:
28 public:
29 explicit VariableModel(VariableController *parent = nullptr);
29 explicit VariableModel(VariableController *parent = nullptr);
30
30
31 /**
31 /**
32 * Adds an existing variable in the model.
32 * Adds an existing variable in the model.
33 * @param variable the variable to add.
33 * @param variable the variable to add.
34 * @remarks the variable's name is modified to avoid name duplicates
34 * @remarks the variable's name is modified to avoid name duplicates
35 * @remarks this method does nothing if the variable already exists in the model
35 * @remarks this method does nothing if the variable already exists in the model
36 */
36 */
37 void addVariable(std::shared_ptr<Variable> variable) noexcept;
37 void addVariable(std::shared_ptr<Variable> variable) noexcept;
38
38
39 /**
39 /**
40 * Checks that a variable is contained in the model
40 * Checks that a variable is contained in the model
41 * @param variable the variable to check
41 * @param variable the variable to check
42 * @return true if the variable is in the model, false otherwise
42 * @return true if the variable is in the model, false otherwise
43 */
43 */
44 bool containsVariable(std::shared_ptr<Variable> variable) const noexcept;
44 bool containsVariable(std::shared_ptr<Variable> variable) const noexcept;
45
45
46 /**
46 /**
47 * Creates a new variable in the model
47 * Creates a new variable in the model
48 * @param name the name of the new variable
48 * @param name the name of the new variable
49 * @param metadata the metadata associated to the new variable
49 * @param metadata the metadata associated to the new variable
50 * @return the pointer to the new variable
50 * @return the pointer to the new variable
51 */
51 */
52 std::shared_ptr<Variable> createVariable(const QString &name,
52 std::shared_ptr<Variable> createVariable(const QString &name,
53 const QVariantHash &metadata) noexcept;
53 const QVariantHash &metadata) noexcept;
54
54
55 /**
55 /**
56 * Deletes a variable from the model, if it exists
56 * Deletes a variable from the model, if it exists
57 * @param variable the variable to delete
57 * @param variable the variable to delete
58 */
58 */
59 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
59 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
60
60
61
61
62 std::shared_ptr<Variable> variable(int index) const;
62 std::shared_ptr<Variable> variable(int index) const;
63 std::vector<std::shared_ptr<Variable> > variables() const;
63 std::vector<std::shared_ptr<Variable> > variables() const;
64
64
65 void setDataProgress(std::shared_ptr<Variable> variable, double progress);
65 void setDataProgress(std::shared_ptr<Variable> variable, double progress);
66
66
67
67
68 // /////////////////////////// //
68 // /////////////////////////// //
69 // QAbstractTableModel methods //
69 // QAbstractTableModel methods //
70 // /////////////////////////// //
70 // /////////////////////////// //
71
71
72 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
72 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
73 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
73 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
74 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
74 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
75 virtual QVariant headerData(int section, Qt::Orientation orientation,
75 virtual QVariant headerData(int section, Qt::Orientation orientation,
76 int role = Qt::DisplayRole) const override;
76 int role = Qt::DisplayRole) const override;
77 virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
77 virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
78
78
79 // ///////////////// //
79 // ///////////////// //
80 // Drag&Drop methods //
80 // Drag&Drop methods //
81 // ///////////////// //
81 // ///////////////// //
82
82
83 virtual Qt::DropActions supportedDropActions() const override;
83 virtual Qt::DropActions supportedDropActions() const override;
84 virtual Qt::DropActions supportedDragActions() const override;
84 virtual Qt::DropActions supportedDragActions() const override;
85 virtual QStringList mimeTypes() const override;
85 virtual QStringList mimeTypes() const override;
86 virtual QMimeData *mimeData(const QModelIndexList &indexes) const override;
86 virtual QMimeData *mimeData(const QModelIndexList &indexes) const override;
87 virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
87 virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
88 const QModelIndex &parent) const override;
88 const QModelIndex &parent) const override;
89 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
89 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
90 const QModelIndex &parent) override;
90 const QModelIndex &parent) override;
91
91
92 void abortProgress(const QModelIndex &index);
92 void abortProgress(const QModelIndex &index);
93
93
94 signals:
94 signals:
95 void abortProgessRequested(std::shared_ptr<Variable> variable);
95 void abortProgessRequested(std::shared_ptr<Variable> variable);
96 void requestVariable(const QVariantHash &productData);
96
97
97 private:
98 private:
98 class VariableModelPrivate;
99 class VariableModelPrivate;
99 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
100 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
100
101
101 private slots:
102 private slots:
102 /// Slot called when data of a variable has been updated
103 /// Slot called when data of a variable has been updated
103 void onVariableUpdated() noexcept;
104 void onVariableUpdated() noexcept;
104 };
105 };
105
106
106 // Registers QVector<int> metatype so it can be used in VariableModel::dataChanged() signal
107 // Registers QVector<int> metatype so it can be used in VariableModel::dataChanged() signal
107 SCIQLOP_REGISTER_META_TYPE(QVECTOR_INT_REGISTRY, QVector<int>)
108 SCIQLOP_REGISTER_META_TYPE(QVECTOR_INT_REGISTRY, QVector<int>)
108
109
109 #endif // SCIQLOP_VARIABLEMODEL_H
110 #endif // SCIQLOP_VARIABLEMODEL_H
@@ -1,143 +1,192
1 #include "DataSource/DataSourceController.h"
1 #include "DataSource/DataSourceController.h"
2 #include "DataSource/DataSourceItem.h"
2 #include "DataSource/DataSourceItem.h"
3
3
4 #include <Data/IDataProvider.h>
4 #include <Data/IDataProvider.h>
5
5
6 #include <QMutex>
6 #include <QMutex>
7 #include <QThread>
7 #include <QThread>
8
8
9 #include <QDataStream>
9 #include <QDir>
10 #include <QDir>
10 #include <QStandardPaths>
11 #include <QStandardPaths>
11
12
12 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
13 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
13
14
14 namespace {
15 namespace {
15
16
16 /**
17 /**
17 * Builds the metadata of the variable that will be generated from the loading of an item
18 * Builds the metadata of the variable that will be generated from the loading of an item
18 * @param dataSourceItem the data source item from which to generate the metadata
19 * @param dataSourceItem the data source item from which to generate the metadata
19 * @return the metadata of the variable
20 * @return the metadata of the variable
20 */
21 */
21 QVariantHash variableMetadata(const DataSourceItem &dataSourceItem)
22 QVariantHash variableMetadata(const DataSourceItem &dataSourceItem)
22 {
23 {
23 // Variable metadata contains...
24 // Variable metadata contains...
24
25
25 // ... all metadata of the item
26 // ... all metadata of the item
26 auto result = dataSourceItem.data();
27 auto result = dataSourceItem.data();
27
28
28 // ... and the name of the plugin, recovered from root item
29 // ... and the name of the plugin, recovered from root item
29 result.insert(QStringLiteral("plugin"), dataSourceItem.rootItem().name());
30 result.insert(QStringLiteral("plugin"), dataSourceItem.rootItem().name());
30
31
31 return result;
32 return result;
32 }
33 }
33
34
34 } // namespace
35 } // namespace
35
36
36 class DataSourceController::DataSourceControllerPrivate {
37 class DataSourceController::DataSourceControllerPrivate {
37 public:
38 public:
38 QMutex m_WorkingMutex;
39 QMutex m_WorkingMutex;
39 /// Data sources registered
40 /// Data sources registered
40 QHash<QUuid, QString> m_DataSources;
41 QHash<QUuid, QString> m_DataSources;
41 /// Data sources structures
42 /// Data sources structures
42 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
43 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
43 /// Data providers registered
44 /// Data providers registered
44 /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and
45 /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and
45 /// continue to live without necessarily the data source controller
46 /// continue to live without necessarily the data source controller
46 std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders;
47 std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders;
48
49 // Search for the first datasource item matching the specified data
50 DataSourceItem *findDataSourceItem(const QVariantHash &data)
51 {
52 DataSourceItem *sourceItem = nullptr;
53 for (const auto &item : m_DataSourceItems) {
54 sourceItem = item.second->findItem(data, true);
55 if (sourceItem) {
56 break;
57 }
58 }
59
60 return sourceItem;
61 }
47 };
62 };
48
63
49 DataSourceController::DataSourceController(QObject *parent)
64 DataSourceController::DataSourceController(QObject *parent)
50 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
65 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
51 {
66 {
52 qCDebug(LOG_DataSourceController())
67 qCDebug(LOG_DataSourceController())
53 << tr("DataSourceController construction") << QThread::currentThread();
68 << tr("DataSourceController construction") << QThread::currentThread();
54 }
69 }
55
70
56 DataSourceController::~DataSourceController()
71 DataSourceController::~DataSourceController()
57 {
72 {
58 qCDebug(LOG_DataSourceController())
73 qCDebug(LOG_DataSourceController())
59 << tr("DataSourceController destruction") << QThread::currentThread();
74 << tr("DataSourceController destruction") << QThread::currentThread();
60 this->waitForFinish();
75 this->waitForFinish();
61 }
76 }
62
77
63 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
78 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
64 {
79 {
65 auto dataSourceUid = QUuid::createUuid();
80 auto dataSourceUid = QUuid::createUuid();
66 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
81 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
67
82
68 return dataSourceUid;
83 return dataSourceUid;
69 }
84 }
70
85
71 void DataSourceController::setDataSourceItem(
86 void DataSourceController::setDataSourceItem(
72 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
87 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
73 {
88 {
74 if (!dataSourceItem) {
89 if (!dataSourceItem) {
75 qCWarning(LOG_DataSourceController())
90 qCWarning(LOG_DataSourceController())
76 << tr("Data source item can't be registered (null item)");
91 << tr("Data source item can't be registered (null item)");
77 return;
92 return;
78 }
93 }
79
94
80 if (impl->m_DataSources.contains(dataSourceUid)) {
95 if (impl->m_DataSources.contains(dataSourceUid)) {
81 // The data provider is implicitly converted to a shared_ptr
96 // The data provider is implicitly converted to a shared_ptr
82 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
97 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
83
98
84 // Retrieves the data source item to emit the signal with it
99 // Retrieves the data source item to emit the signal with it
85 auto it = impl->m_DataSourceItems.find(dataSourceUid);
100 auto it = impl->m_DataSourceItems.find(dataSourceUid);
86 if (it != impl->m_DataSourceItems.end()) {
101 if (it != impl->m_DataSourceItems.end()) {
87 emit dataSourceItemSet(it->second.get());
102 emit dataSourceItemSet(it->second.get());
88 }
103 }
89 }
104 }
90 else {
105 else {
91 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
106 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
92 "data source has been registered with the uid")
107 "data source has been registered with the uid")
93 .arg(dataSourceUid.toString());
108 .arg(dataSourceUid.toString());
94 }
109 }
95 }
110 }
96
111
97 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
112 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
98 std::unique_ptr<IDataProvider> dataProvider) noexcept
113 std::unique_ptr<IDataProvider> dataProvider) noexcept
99 {
114 {
100 if (impl->m_DataSources.contains(dataSourceUid)) {
115 if (impl->m_DataSources.contains(dataSourceUid)) {
101 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
116 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
102 }
117 }
103 else {
118 else {
104 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
119 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
105 "source has been registered with the uid")
120 "source has been registered with the uid")
106 .arg(dataSourceUid.toString());
121 .arg(dataSourceUid.toString());
107 }
122 }
108 }
123 }
109
124
110 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
125 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
111 const DataSourceItem &productItem) noexcept
126 const DataSourceItem &productItem) noexcept
112 {
127 {
113 if (productItem.type() == DataSourceItemType::PRODUCT
128 if (productItem.type() == DataSourceItemType::PRODUCT
114 || productItem.type() == DataSourceItemType::COMPONENT) {
129 || productItem.type() == DataSourceItemType::COMPONENT) {
115 /// Retrieves the data provider of the data source (if any)
130 /// Retrieves the data provider of the data source (if any)
116 auto it = impl->m_DataProviders.find(dataSourceUid);
131 auto it = impl->m_DataProviders.find(dataSourceUid);
117 auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr;
132 auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr;
118
133
119 emit variableCreationRequested(productItem.name(), variableMetadata(productItem),
134 emit variableCreationRequested(productItem.name(), variableMetadata(productItem),
120 dataProvider);
135 dataProvider);
121 }
136 }
122 else {
137 else {
123 qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product");
138 qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product");
124 }
139 }
125 }
140 }
126
141
142 QByteArray DataSourceController::mimeDataForProductsData(const QVariantList &productsData) const
143 {
144 QByteArray encodedData;
145 QDataStream stream(&encodedData, QIODevice::WriteOnly);
146
147 stream << productsData;
148
149 return encodedData;
150 }
151
152 QVariantList DataSourceController::productsDataForMimeData(const QByteArray &mimeData) const
153 {
154 QDataStream stream(mimeData);
155
156 QVariantList productList;
157 stream >> productList;
158
159 return productList;
160 }
161
127 void DataSourceController::initialize()
162 void DataSourceController::initialize()
128 {
163 {
129 qCDebug(LOG_DataSourceController())
164 qCDebug(LOG_DataSourceController())
130 << tr("DataSourceController init") << QThread::currentThread();
165 << tr("DataSourceController init") << QThread::currentThread();
131 impl->m_WorkingMutex.lock();
166 impl->m_WorkingMutex.lock();
132 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
167 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
133 }
168 }
134
169
135 void DataSourceController::finalize()
170 void DataSourceController::finalize()
136 {
171 {
137 impl->m_WorkingMutex.unlock();
172 impl->m_WorkingMutex.unlock();
138 }
173 }
139
174
175 void DataSourceController::requestVariable(const QVariantHash &productData)
176 {
177 DataSourceItem *sourceItem = impl->findDataSourceItem(productData);
178
179 if (sourceItem) {
180 auto sourceName = sourceItem->rootItem().name();
181 auto sourceId = impl->m_DataSources.key(sourceName);
182 loadProductItem(sourceId, *sourceItem);
183 }
184 else {
185 qCWarning(LOG_DataSourceController()) << tr("requestVariable, product data not found");
186 }
187 }
188
140 void DataSourceController::waitForFinish()
189 void DataSourceController::waitForFinish()
141 {
190 {
142 QMutexLocker locker{&impl->m_WorkingMutex};
191 QMutexLocker locker{&impl->m_WorkingMutex};
143 }
192 }
@@ -1,145 +1,163
1 #include <DataSource/DataSourceItem.h>
1 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItemAction.h>
2 #include <DataSource/DataSourceItemAction.h>
3
3
4 #include <QVector>
4 #include <QVector>
5
5
6 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
6 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
7
7
8 struct DataSourceItem::DataSourceItemPrivate {
8 struct DataSourceItem::DataSourceItemPrivate {
9 explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data)
9 explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data)
10 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{}
10 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{}
11 {
11 {
12 }
12 }
13
13
14 DataSourceItem *m_Parent;
14 DataSourceItem *m_Parent;
15 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
15 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
16 DataSourceItemType m_Type;
16 DataSourceItemType m_Type;
17 QVariantHash m_Data;
17 QVariantHash m_Data;
18 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
18 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
19 };
19 };
20
20
21 DataSourceItem::DataSourceItem(DataSourceItemType type, const QString &name)
21 DataSourceItem::DataSourceItem(DataSourceItemType type, const QString &name)
22 : DataSourceItem{type, QVariantHash{{NAME_DATA_KEY, name}}}
22 : DataSourceItem{type, QVariantHash{{NAME_DATA_KEY, name}}}
23 {
23 {
24 }
24 }
25
25
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QVariantHash data)
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QVariantHash data)
27 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
27 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
28 {
28 {
29 }
29 }
30
30
31 QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept
31 QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept
32 {
32 {
33 auto result = QVector<DataSourceItemAction *>{};
33 auto result = QVector<DataSourceItemAction *>{};
34
34
35 std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions),
35 std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions),
36 std::back_inserter(result), [](const auto &action) { return action.get(); });
36 std::back_inserter(result), [](const auto &action) { return action.get(); });
37
37
38 return result;
38 return result;
39 }
39 }
40
40
41 void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept
41 void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept
42 {
42 {
43 action->setDataSourceItem(this);
43 action->setDataSourceItem(this);
44 impl->m_Actions.push_back(std::move(action));
44 impl->m_Actions.push_back(std::move(action));
45 }
45 }
46
46
47 void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
47 void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
48 {
48 {
49 child->impl->m_Parent = this;
49 child->impl->m_Parent = this;
50 impl->m_Children.push_back(std::move(child));
50 impl->m_Children.push_back(std::move(child));
51 }
51 }
52
52
53 DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
53 DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
54 {
54 {
55 if (childIndex < 0 || childIndex >= childCount()) {
55 if (childIndex < 0 || childIndex >= childCount()) {
56 return nullptr;
56 return nullptr;
57 }
57 }
58 else {
58 else {
59 return impl->m_Children.at(childIndex).get();
59 return impl->m_Children.at(childIndex).get();
60 }
60 }
61 }
61 }
62
62
63 int DataSourceItem::childCount() const noexcept
63 int DataSourceItem::childCount() const noexcept
64 {
64 {
65 return impl->m_Children.size();
65 return impl->m_Children.size();
66 }
66 }
67
67
68 QVariant DataSourceItem::data(const QString &key) const noexcept
68 QVariant DataSourceItem::data(const QString &key) const noexcept
69 {
69 {
70 return impl->m_Data.value(key);
70 return impl->m_Data.value(key);
71 }
71 }
72
72
73 QVariantHash DataSourceItem::data() const noexcept
73 QVariantHash DataSourceItem::data() const noexcept
74 {
74 {
75 return impl->m_Data;
75 return impl->m_Data;
76 }
76 }
77
77
78 bool DataSourceItem::isRoot() const noexcept
78 bool DataSourceItem::isRoot() const noexcept
79 {
79 {
80 return impl->m_Parent == nullptr;
80 return impl->m_Parent == nullptr;
81 }
81 }
82
82
83 QString DataSourceItem::name() const noexcept
83 QString DataSourceItem::name() const noexcept
84 {
84 {
85 return data(NAME_DATA_KEY).toString();
85 return data(NAME_DATA_KEY).toString();
86 }
86 }
87
87
88 DataSourceItem *DataSourceItem::parentItem() const noexcept
88 DataSourceItem *DataSourceItem::parentItem() const noexcept
89 {
89 {
90 return impl->m_Parent;
90 return impl->m_Parent;
91 }
91 }
92
92
93 const DataSourceItem &DataSourceItem::rootItem() const noexcept
93 const DataSourceItem &DataSourceItem::rootItem() const noexcept
94 {
94 {
95 return isRoot() ? *this : parentItem()->rootItem();
95 return isRoot() ? *this : parentItem()->rootItem();
96 }
96 }
97
97
98 void DataSourceItem::setData(const QString &key, const QVariant &value, bool append) noexcept
98 void DataSourceItem::setData(const QString &key, const QVariant &value, bool append) noexcept
99 {
99 {
100 auto it = impl->m_Data.constFind(key);
100 auto it = impl->m_Data.constFind(key);
101 if (append && it != impl->m_Data.constEnd()) {
101 if (append && it != impl->m_Data.constEnd()) {
102 // Case of an existing value to which we want to add to the new value
102 // Case of an existing value to which we want to add to the new value
103 if (it->canConvert<QVariantList>()) {
103 if (it->canConvert<QVariantList>()) {
104 auto variantList = it->value<QVariantList>();
104 auto variantList = it->value<QVariantList>();
105 variantList.append(value);
105 variantList.append(value);
106
106
107 impl->m_Data.insert(key, variantList);
107 impl->m_Data.insert(key, variantList);
108 }
108 }
109 else {
109 else {
110 impl->m_Data.insert(key, QVariantList{*it, value});
110 impl->m_Data.insert(key, QVariantList{*it, value});
111 }
111 }
112 }
112 }
113 else {
113 else {
114 // Other cases :
114 // Other cases :
115 // - new value in map OR
115 // - new value in map OR
116 // - replacement of an existing value (not appending)
116 // - replacement of an existing value (not appending)
117 impl->m_Data.insert(key, value);
117 impl->m_Data.insert(key, value);
118 }
118 }
119 }
119 }
120
120
121 DataSourceItemType DataSourceItem::type() const noexcept
121 DataSourceItemType DataSourceItem::type() const noexcept
122 {
122 {
123 return impl->m_Type;
123 return impl->m_Type;
124 }
124 }
125
125
126 DataSourceItem *DataSourceItem::findItem(const QVariantHash &data, bool recursive)
127 {
128 for (const auto &child : impl->m_Children) {
129 if (child->impl->m_Data == data) {
130 return child.get();
131 }
132
133 if (recursive) {
134 auto foundItem = child->findItem(data, true);
135 if (foundItem) {
136 return foundItem;
137 }
138 }
139 }
140
141 return nullptr;
142 }
143
126 bool DataSourceItem::operator==(const DataSourceItem &other)
144 bool DataSourceItem::operator==(const DataSourceItem &other)
127 {
145 {
128 // Compares items' attributes
146 // Compares items' attributes
129 if (std::tie(impl->m_Type, impl->m_Data) == std::tie(other.impl->m_Type, other.impl->m_Data)) {
147 if (std::tie(impl->m_Type, impl->m_Data) == std::tie(other.impl->m_Type, other.impl->m_Data)) {
130 // Compares contents of items' children
148 // Compares contents of items' children
131 return std::equal(std::cbegin(impl->m_Children), std::cend(impl->m_Children),
149 return std::equal(std::cbegin(impl->m_Children), std::cend(impl->m_Children),
132 std::cbegin(other.impl->m_Children),
150 std::cbegin(other.impl->m_Children),
133 [](const auto &itemChild, const auto &otherChild) {
151 [](const auto &itemChild, const auto &otherChild) {
134 return *itemChild == *otherChild;
152 return *itemChild == *otherChild;
135 });
153 });
136 }
154 }
137 else {
155 else {
138 return false;
156 return false;
139 }
157 }
140 }
158 }
141
159
142 bool DataSourceItem::operator!=(const DataSourceItem &other)
160 bool DataSourceItem::operator!=(const DataSourceItem &other)
143 {
161 {
144 return !(*this == other);
162 return !(*this == other);
145 }
163 }
@@ -1,351 +1,368
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableController.h>
2 #include <Variable/VariableController.h>
3 #include <Variable/VariableModel.h>
3 #include <Variable/VariableModel.h>
4
4
5 #include <Common/DateUtils.h>
5 #include <Common/DateUtils.h>
6 #include <Common/MimeTypesDef.h>
6 #include <Common/MimeTypesDef.h>
7 #include <Common/StringUtils.h>
7 #include <Common/StringUtils.h>
8
8
9 #include <Data/IDataSeries.h>
9 #include <Data/IDataSeries.h>
10
10
11 #include <QDataStream>
11 #include <QMimeData>
12 #include <QMimeData>
12 #include <QSize>
13 #include <QSize>
13 #include <unordered_map>
14 #include <unordered_map>
14
15
15 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
16 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
16
17
17 namespace {
18 namespace {
18
19
19 // Column indexes
20 // Column indexes
20 const auto NAME_COLUMN = 0;
21 const auto NAME_COLUMN = 0;
21 const auto TSTART_COLUMN = 1;
22 const auto TSTART_COLUMN = 1;
22 const auto TEND_COLUMN = 2;
23 const auto TEND_COLUMN = 2;
23 const auto NBPOINTS_COLUMN = 3;
24 const auto NBPOINTS_COLUMN = 3;
24 const auto UNIT_COLUMN = 4;
25 const auto UNIT_COLUMN = 4;
25 const auto MISSION_COLUMN = 5;
26 const auto MISSION_COLUMN = 5;
26 const auto PLUGIN_COLUMN = 6;
27 const auto PLUGIN_COLUMN = 6;
27 const auto NB_COLUMNS = 7;
28 const auto NB_COLUMNS = 7;
28
29
29 // Column properties
30 // Column properties
30 const auto DEFAULT_HEIGHT = 25;
31 const auto DEFAULT_HEIGHT = 25;
31 const auto DEFAULT_WIDTH = 100;
32 const auto DEFAULT_WIDTH = 100;
32
33
33 struct ColumnProperties {
34 struct ColumnProperties {
34 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
35 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
35 int height = DEFAULT_HEIGHT)
36 int height = DEFAULT_HEIGHT)
36 : m_Name{name}, m_Width{width}, m_Height{height}
37 : m_Name{name}, m_Width{width}, m_Height{height}
37 {
38 {
38 }
39 }
39
40
40 QString m_Name;
41 QString m_Name;
41 int m_Width;
42 int m_Width;
42 int m_Height;
43 int m_Height;
43 };
44 };
44
45
45 const auto COLUMN_PROPERTIES = QHash<int, ColumnProperties>{
46 const auto COLUMN_PROPERTIES = QHash<int, ColumnProperties>{
46 {NAME_COLUMN, {QObject::tr("Name")}}, {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
47 {NAME_COLUMN, {QObject::tr("Name")}}, {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
47 {TEND_COLUMN, {QObject::tr("tEnd"), 180}}, {NBPOINTS_COLUMN, {QObject::tr("Nb points")}},
48 {TEND_COLUMN, {QObject::tr("tEnd"), 180}}, {NBPOINTS_COLUMN, {QObject::tr("Nb points")}},
48 {UNIT_COLUMN, {QObject::tr("Unit")}}, {MISSION_COLUMN, {QObject::tr("Mission")}},
49 {UNIT_COLUMN, {QObject::tr("Unit")}}, {MISSION_COLUMN, {QObject::tr("Mission")}},
49 {PLUGIN_COLUMN, {QObject::tr("Plugin")}}};
50 {PLUGIN_COLUMN, {QObject::tr("Plugin")}}};
50
51
51 /// Format for datetimes
52 /// Format for datetimes
52 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
53 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
53
54
54 QString uniqueName(const QString &defaultName,
55 QString uniqueName(const QString &defaultName,
55 const std::vector<std::shared_ptr<Variable> > &variables)
56 const std::vector<std::shared_ptr<Variable> > &variables)
56 {
57 {
57 auto forbiddenNames = std::vector<QString>(variables.size());
58 auto forbiddenNames = std::vector<QString>(variables.size());
58 std::transform(variables.cbegin(), variables.cend(), forbiddenNames.begin(),
59 std::transform(variables.cbegin(), variables.cend(), forbiddenNames.begin(),
59 [](const auto &variable) { return variable->name(); });
60 [](const auto &variable) { return variable->name(); });
60 auto uniqueName = StringUtils::uniqueName(defaultName, forbiddenNames);
61 auto uniqueName = StringUtils::uniqueName(defaultName, forbiddenNames);
61 Q_ASSERT(!uniqueName.isEmpty());
62 Q_ASSERT(!uniqueName.isEmpty());
62
63
63 return uniqueName;
64 return uniqueName;
64 }
65 }
65
66
66 } // namespace
67 } // namespace
67
68
68 struct VariableModel::VariableModelPrivate {
69 struct VariableModel::VariableModelPrivate {
69 /// Variables created in SciQlop
70 /// Variables created in SciQlop
70 std::vector<std::shared_ptr<Variable> > m_Variables;
71 std::vector<std::shared_ptr<Variable> > m_Variables;
71 std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress;
72 std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress;
72 VariableController *m_VariableController;
73 VariableController *m_VariableController;
73
74
74 /// Return the row index of the variable. -1 if it's not found
75 /// Return the row index of the variable. -1 if it's not found
75 int indexOfVariable(Variable *variable) const noexcept;
76 int indexOfVariable(Variable *variable) const noexcept;
76 };
77 };
77
78
78 VariableModel::VariableModel(VariableController *parent)
79 VariableModel::VariableModel(VariableController *parent)
79 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
80 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
80 {
81 {
81 impl->m_VariableController = parent;
82 impl->m_VariableController = parent;
82 }
83 }
83
84
84 void VariableModel::addVariable(std::shared_ptr<Variable> variable) noexcept
85 void VariableModel::addVariable(std::shared_ptr<Variable> variable) noexcept
85 {
86 {
86 auto insertIndex = rowCount();
87 auto insertIndex = rowCount();
87 beginInsertRows({}, insertIndex, insertIndex);
88 beginInsertRows({}, insertIndex, insertIndex);
88
89
89 // Generates unique name for the variable
90 // Generates unique name for the variable
90 variable->setName(uniqueName(variable->name(), impl->m_Variables));
91 variable->setName(uniqueName(variable->name(), impl->m_Variables));
91
92
92 impl->m_Variables.push_back(variable);
93 impl->m_Variables.push_back(variable);
93 connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated);
94 connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated);
94
95
95 endInsertRows();
96 endInsertRows();
96 }
97 }
97
98
98 bool VariableModel::containsVariable(std::shared_ptr<Variable> variable) const noexcept
99 bool VariableModel::containsVariable(std::shared_ptr<Variable> variable) const noexcept
99 {
100 {
100 auto end = impl->m_Variables.cend();
101 auto end = impl->m_Variables.cend();
101 return std::find(impl->m_Variables.cbegin(), end, variable) != end;
102 return std::find(impl->m_Variables.cbegin(), end, variable) != end;
102 }
103 }
103
104
104 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
105 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
105 const QVariantHash &metadata) noexcept
106 const QVariantHash &metadata) noexcept
106 {
107 {
107 auto variable = std::make_shared<Variable>(name, metadata);
108 auto variable = std::make_shared<Variable>(name, metadata);
108 addVariable(variable);
109 addVariable(variable);
109
110
110 return variable;
111 return variable;
111 }
112 }
112
113
113 void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept
114 void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept
114 {
115 {
115 if (!variable) {
116 if (!variable) {
116 qCCritical(LOG_Variable()) << "Can't delete a null variable from the model";
117 qCCritical(LOG_Variable()) << "Can't delete a null variable from the model";
117 return;
118 return;
118 }
119 }
119
120
120 // Finds variable in the model
121 // Finds variable in the model
121 auto begin = impl->m_Variables.cbegin();
122 auto begin = impl->m_Variables.cbegin();
122 auto end = impl->m_Variables.cend();
123 auto end = impl->m_Variables.cend();
123 auto it = std::find(begin, end, variable);
124 auto it = std::find(begin, end, variable);
124 if (it != end) {
125 if (it != end) {
125 auto removeIndex = std::distance(begin, it);
126 auto removeIndex = std::distance(begin, it);
126
127
127 // Deletes variable
128 // Deletes variable
128 beginRemoveRows({}, removeIndex, removeIndex);
129 beginRemoveRows({}, removeIndex, removeIndex);
129 impl->m_Variables.erase(it);
130 impl->m_Variables.erase(it);
130 endRemoveRows();
131 endRemoveRows();
131 }
132 }
132 else {
133 else {
133 qCritical(LOG_VariableModel())
134 qCritical(LOG_VariableModel())
134 << tr("Can't delete variable %1 from the model: the variable is not in the model")
135 << tr("Can't delete variable %1 from the model: the variable is not in the model")
135 .arg(variable->name());
136 .arg(variable->name());
136 }
137 }
137
138
138 // Removes variable from progress map
139 // Removes variable from progress map
139 impl->m_VariableToProgress.erase(variable);
140 impl->m_VariableToProgress.erase(variable);
140 }
141 }
141
142
142
143
143 std::shared_ptr<Variable> VariableModel::variable(int index) const
144 std::shared_ptr<Variable> VariableModel::variable(int index) const
144 {
145 {
145 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
146 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
146 }
147 }
147
148
148 std::vector<std::shared_ptr<Variable> > VariableModel::variables() const
149 std::vector<std::shared_ptr<Variable> > VariableModel::variables() const
149 {
150 {
150 return impl->m_Variables;
151 return impl->m_Variables;
151 }
152 }
152
153
153 void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress)
154 void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress)
154 {
155 {
155 if (progress > 0.0) {
156 if (progress > 0.0) {
156 impl->m_VariableToProgress[variable] = progress;
157 impl->m_VariableToProgress[variable] = progress;
157 }
158 }
158 else {
159 else {
159 impl->m_VariableToProgress.erase(variable);
160 impl->m_VariableToProgress.erase(variable);
160 }
161 }
161 auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN);
162 auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN);
162
163
163 emit dataChanged(modelIndex, modelIndex);
164 emit dataChanged(modelIndex, modelIndex);
164 }
165 }
165
166
166 int VariableModel::columnCount(const QModelIndex &parent) const
167 int VariableModel::columnCount(const QModelIndex &parent) const
167 {
168 {
168 Q_UNUSED(parent);
169 Q_UNUSED(parent);
169
170
170 return NB_COLUMNS;
171 return NB_COLUMNS;
171 }
172 }
172
173
173 int VariableModel::rowCount(const QModelIndex &parent) const
174 int VariableModel::rowCount(const QModelIndex &parent) const
174 {
175 {
175 Q_UNUSED(parent);
176 Q_UNUSED(parent);
176
177
177 return impl->m_Variables.size();
178 return impl->m_Variables.size();
178 }
179 }
179
180
180 QVariant VariableModel::data(const QModelIndex &index, int role) const
181 QVariant VariableModel::data(const QModelIndex &index, int role) const
181 {
182 {
182 if (!index.isValid()) {
183 if (!index.isValid()) {
183 return QVariant{};
184 return QVariant{};
184 }
185 }
185
186
186 if (index.row() < 0 || index.row() >= rowCount()) {
187 if (index.row() < 0 || index.row() >= rowCount()) {
187 return QVariant{};
188 return QVariant{};
188 }
189 }
189
190
190 if (role == Qt::DisplayRole) {
191 if (role == Qt::DisplayRole) {
191 if (auto variable = impl->m_Variables.at(index.row()).get()) {
192 if (auto variable = impl->m_Variables.at(index.row()).get()) {
192 switch (index.column()) {
193 switch (index.column()) {
193 case NAME_COLUMN:
194 case NAME_COLUMN:
194 return variable->name();
195 return variable->name();
195 case TSTART_COLUMN: {
196 case TSTART_COLUMN: {
196 auto range = variable->realRange();
197 auto range = variable->realRange();
197 return range != INVALID_RANGE
198 return range != INVALID_RANGE
198 ? DateUtils::dateTime(range.m_TStart).toString(DATETIME_FORMAT)
199 ? DateUtils::dateTime(range.m_TStart).toString(DATETIME_FORMAT)
199 : QVariant{};
200 : QVariant{};
200 }
201 }
201 case TEND_COLUMN: {
202 case TEND_COLUMN: {
202 auto range = variable->realRange();
203 auto range = variable->realRange();
203 return range != INVALID_RANGE
204 return range != INVALID_RANGE
204 ? DateUtils::dateTime(range.m_TEnd).toString(DATETIME_FORMAT)
205 ? DateUtils::dateTime(range.m_TEnd).toString(DATETIME_FORMAT)
205 : QVariant{};
206 : QVariant{};
206 }
207 }
207 case NBPOINTS_COLUMN:
208 case NBPOINTS_COLUMN:
208 return variable->nbPoints();
209 return variable->nbPoints();
209 case UNIT_COLUMN:
210 case UNIT_COLUMN:
210 return variable->metadata().value(QStringLiteral("units"));
211 return variable->metadata().value(QStringLiteral("units"));
211 case MISSION_COLUMN:
212 case MISSION_COLUMN:
212 return variable->metadata().value(QStringLiteral("mission"));
213 return variable->metadata().value(QStringLiteral("mission"));
213 case PLUGIN_COLUMN:
214 case PLUGIN_COLUMN:
214 return variable->metadata().value(QStringLiteral("plugin"));
215 return variable->metadata().value(QStringLiteral("plugin"));
215 default:
216 default:
216 // No action
217 // No action
217 break;
218 break;
218 }
219 }
219
220
220 qWarning(LOG_VariableModel())
221 qWarning(LOG_VariableModel())
221 << tr("Can't get data (unknown column %1)").arg(index.column());
222 << tr("Can't get data (unknown column %1)").arg(index.column());
222 }
223 }
223 else {
224 else {
224 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
225 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
225 }
226 }
226 }
227 }
227 else if (role == VariableRoles::ProgressRole) {
228 else if (role == VariableRoles::ProgressRole) {
228 if (auto variable = impl->m_Variables.at(index.row())) {
229 if (auto variable = impl->m_Variables.at(index.row())) {
229
230
230 auto it = impl->m_VariableToProgress.find(variable);
231 auto it = impl->m_VariableToProgress.find(variable);
231 if (it != impl->m_VariableToProgress.cend()) {
232 if (it != impl->m_VariableToProgress.cend()) {
232 return it->second;
233 return it->second;
233 }
234 }
234 }
235 }
235 }
236 }
236
237
237 return QVariant{};
238 return QVariant{};
238 }
239 }
239
240
240 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
241 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
241 {
242 {
242 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
243 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
243 return QVariant{};
244 return QVariant{};
244 }
245 }
245
246
246 if (orientation == Qt::Horizontal) {
247 if (orientation == Qt::Horizontal) {
247 auto propertiesIt = COLUMN_PROPERTIES.find(section);
248 auto propertiesIt = COLUMN_PROPERTIES.find(section);
248 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
249 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
249 // Role is either DisplayRole or SizeHintRole
250 // Role is either DisplayRole or SizeHintRole
250 return (role == Qt::DisplayRole)
251 return (role == Qt::DisplayRole)
251 ? QVariant{propertiesIt->m_Name}
252 ? QVariant{propertiesIt->m_Name}
252 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
253 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
253 }
254 }
254 else {
255 else {
255 qWarning(LOG_VariableModel())
256 qWarning(LOG_VariableModel())
256 << tr("Can't get header data (unknown column %1)").arg(section);
257 << tr("Can't get header data (unknown column %1)").arg(section);
257 }
258 }
258 }
259 }
259
260
260 return QVariant{};
261 return QVariant{};
261 }
262 }
262
263
263 Qt::ItemFlags VariableModel::flags(const QModelIndex &index) const
264 Qt::ItemFlags VariableModel::flags(const QModelIndex &index) const
264 {
265 {
265 return QAbstractTableModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
266 return QAbstractTableModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
266 }
267 }
267
268
268 Qt::DropActions VariableModel::supportedDropActions() const
269 Qt::DropActions VariableModel::supportedDropActions() const
269 {
270 {
270 return Qt::MoveAction;
271 return Qt::CopyAction | Qt::MoveAction;
271 }
272 }
272
273
273 Qt::DropActions VariableModel::supportedDragActions() const
274 Qt::DropActions VariableModel::supportedDragActions() const
274 {
275 {
275 return Qt::CopyAction | Qt::MoveAction;
276 return Qt::CopyAction | Qt::MoveAction;
276 }
277 }
277
278
278 QStringList VariableModel::mimeTypes() const
279 QStringList VariableModel::mimeTypes() const
279 {
280 {
280 return {MIME_TYPE_VARIABLE_LIST};
281 return {MIME_TYPE_VARIABLE_LIST};
281 }
282 }
282
283
283 QMimeData *VariableModel::mimeData(const QModelIndexList &indexes) const
284 QMimeData *VariableModel::mimeData(const QModelIndexList &indexes) const
284 {
285 {
285 auto mimeData = new QMimeData;
286 auto mimeData = new QMimeData;
286
287
287 QList<std::shared_ptr<Variable> > variableList;
288 QList<std::shared_ptr<Variable> > variableList;
288
289
289 for (const auto &index : indexes) {
290 for (const auto &index : indexes) {
290 if (index.column() == 0) { // only the first column
291 if (index.column() == 0) { // only the first column
291 auto variable = impl->m_Variables.at(index.row());
292 auto variable = impl->m_Variables.at(index.row());
292 if (variable.get() && index.isValid()) {
293 if (variable.get() && index.isValid()) {
293 variableList << variable;
294 variableList << variable;
294 }
295 }
295 }
296 }
296 }
297 }
297
298
298 auto encodedData = impl->m_VariableController->mimeDataForVariables(variableList);
299 auto encodedData = impl->m_VariableController->mimeDataForVariables(variableList);
299 mimeData->setData(MIME_TYPE_VARIABLE_LIST, encodedData);
300 mimeData->setData(MIME_TYPE_VARIABLE_LIST, encodedData);
300
301
301 return mimeData;
302 return mimeData;
302 }
303 }
303
304
304 bool VariableModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row,
305 bool VariableModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row,
305 int column, const QModelIndex &parent) const
306 int column, const QModelIndex &parent) const
306 {
307 {
307 return false;
308 // drop of a product
309 return data->hasFormat(MIME_TYPE_PRODUCT_LIST);
308 }
310 }
309
311
310 bool VariableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
312 bool VariableModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
311 const QModelIndex &parent)
313 const QModelIndex &parent)
312 {
314 {
313 return false;
315 bool dropDone = false;
316
317 if (data->hasFormat(MIME_TYPE_PRODUCT_LIST)) {
318 QDataStream stream(data->data(MIME_TYPE_PRODUCT_LIST));
319
320 QVariantList productList;
321 stream >> productList;
322
323 for (auto metaData : productList) {
324 emit requestVariable(metaData.toHash());
325 }
326
327 dropDone = true;
328 }
329
330 return dropDone;
314 }
331 }
315
332
316 void VariableModel::abortProgress(const QModelIndex &index)
333 void VariableModel::abortProgress(const QModelIndex &index)
317 {
334 {
318 if (auto variable = impl->m_Variables.at(index.row())) {
335 if (auto variable = impl->m_Variables.at(index.row())) {
319 emit abortProgessRequested(variable);
336 emit abortProgessRequested(variable);
320 }
337 }
321 }
338 }
322
339
323 void VariableModel::onVariableUpdated() noexcept
340 void VariableModel::onVariableUpdated() noexcept
324 {
341 {
325 // Finds variable that has been updated in the model
342 // Finds variable that has been updated in the model
326 if (auto updatedVariable = dynamic_cast<Variable *>(sender())) {
343 if (auto updatedVariable = dynamic_cast<Variable *>(sender())) {
327 auto updatedVariableIndex = impl->indexOfVariable(updatedVariable);
344 auto updatedVariableIndex = impl->indexOfVariable(updatedVariable);
328
345
329 if (updatedVariableIndex > -1) {
346 if (updatedVariableIndex > -1) {
330 emit dataChanged(createIndex(updatedVariableIndex, 0),
347 emit dataChanged(createIndex(updatedVariableIndex, 0),
331 createIndex(updatedVariableIndex, columnCount() - 1));
348 createIndex(updatedVariableIndex, columnCount() - 1));
332 }
349 }
333 }
350 }
334 }
351 }
335
352
336 int VariableModel::VariableModelPrivate::indexOfVariable(Variable *variable) const noexcept
353 int VariableModel::VariableModelPrivate::indexOfVariable(Variable *variable) const noexcept
337 {
354 {
338 auto begin = std::cbegin(m_Variables);
355 auto begin = std::cbegin(m_Variables);
339 auto end = std::cend(m_Variables);
356 auto end = std::cend(m_Variables);
340 auto it
357 auto it
341 = std::find_if(begin, end, [variable](const auto &var) { return var.get() == variable; });
358 = std::find_if(begin, end, [variable](const auto &var) { return var.get() == variable; });
342
359
343 if (it != end) {
360 if (it != end) {
344 // Gets the index of the variable in the model: we assume here that views have the same
361 // Gets the index of the variable in the model: we assume here that views have the same
345 // order as the model
362 // order as the model
346 return std::distance(begin, it);
363 return std::distance(begin, it);
347 }
364 }
348 else {
365 else {
349 return -1;
366 return -1;
350 }
367 }
351 }
368 }
@@ -1,38 +1,37
1 #include "DataSource/DataSourceTreeWidget.h"
1 #include "DataSource/DataSourceTreeWidget.h"
2 #include "Common/MimeTypesDef.h"
2 #include "Common/MimeTypesDef.h"
3 #include "DataSource/DataSourceController.h"
3 #include "DataSource/DataSourceItem.h"
4 #include "DataSource/DataSourceItem.h"
4 #include "DataSource/DataSourceTreeWidgetItem.h"
5 #include "DataSource/DataSourceTreeWidgetItem.h"
5
6
7 #include "SqpApplication.h"
8
6 #include <QMimeData>
9 #include <QMimeData>
7
10
8 DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) {}
11 DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) {}
9
12
10 QMimeData *DataSourceTreeWidget::mimeData(const QList<QTreeWidgetItem *> items) const
13 QMimeData *DataSourceTreeWidget::mimeData(const QList<QTreeWidgetItem *> items) const
11 {
14 {
12 auto mimeData = new QMimeData;
15 auto mimeData = new QMimeData;
13
16
14 // Basic check to ensure the item are correctly typed
17 // Basic check to ensure the item are correctly typed
15 Q_ASSERT(items.isEmpty() || dynamic_cast<DataSourceTreeWidgetItem *>(items.first()) != nullptr);
18 Q_ASSERT(items.isEmpty() || dynamic_cast<DataSourceTreeWidgetItem *>(items.first()) != nullptr);
16
19
17 QVariantList productData;
20 QVariantList productData;
18
21
19 for (auto item : items) {
22 for (auto item : items) {
20 auto dataSourceTreeItem = static_cast<DataSourceTreeWidgetItem *>(item);
23 auto dataSourceTreeItem = static_cast<DataSourceTreeWidgetItem *>(item);
21 auto dataSource = dataSourceTreeItem->data();
24 auto dataSource = dataSourceTreeItem->data();
22
25
23 if (dataSource->type() == DataSourceItemType::COMPONENT
26 if (dataSource->type() == DataSourceItemType::COMPONENT
24 || dataSource->type() == DataSourceItemType::PRODUCT) {
27 || dataSource->type() == DataSourceItemType::PRODUCT) {
25 auto metaData = dataSource->data();
28 auto metaData = dataSource->data();
26 productData << metaData;
29 productData << metaData;
27 }
30 }
28 }
31 }
29
32
30 QByteArray encodedData;
33 auto encodedData = sqpApp->dataSourceController().mimeDataForProductsData(productData);
31 QDataStream stream(&encodedData, QIODevice::WriteOnly);
32
33 stream << productData;
34
35 mimeData->setData(MIME_TYPE_PRODUCT_LIST, encodedData);
34 mimeData->setData(MIME_TYPE_PRODUCT_LIST, encodedData);
36
35
37 return mimeData;
36 return mimeData;
38 }
37 }
@@ -1,155 +1,159
1 #include "SqpApplication.h"
1 #include "SqpApplication.h"
2
2
3 #include <Data/IDataProvider.h>
3 #include <Data/IDataProvider.h>
4 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceController.h>
5 #include <DragDropHelper.h>
5 #include <DragDropHelper.h>
6 #include <Network/NetworkController.h>
6 #include <Network/NetworkController.h>
7 #include <QThread>
7 #include <QThread>
8 #include <Time/TimeController.h>
8 #include <Time/TimeController.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
10 #include <Variable/VariableController.h>
11 #include <Variable/VariableModel.h>
11 #include <Visualization/VisualizationController.h>
12 #include <Visualization/VisualizationController.h>
12
13
13 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
14 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
14
15
15 class SqpApplication::SqpApplicationPrivate {
16 class SqpApplication::SqpApplicationPrivate {
16 public:
17 public:
17 SqpApplicationPrivate()
18 SqpApplicationPrivate()
18 : m_DataSourceController{std::make_unique<DataSourceController>()},
19 : m_DataSourceController{std::make_unique<DataSourceController>()},
19 m_NetworkController{std::make_unique<NetworkController>()},
20 m_NetworkController{std::make_unique<NetworkController>()},
20 m_TimeController{std::make_unique<TimeController>()},
21 m_TimeController{std::make_unique<TimeController>()},
21 m_VariableController{std::make_unique<VariableController>()},
22 m_VariableController{std::make_unique<VariableController>()},
22 m_VisualizationController{std::make_unique<VisualizationController>()},
23 m_VisualizationController{std::make_unique<VisualizationController>()},
23 m_DragDropHelper{std::make_unique<DragDropHelper>()}
24 m_DragDropHelper{std::make_unique<DragDropHelper>()}
24 {
25 {
25 // /////////////////////////////// //
26 // /////////////////////////////// //
26 // Connections between controllers //
27 // Connections between controllers //
27 // /////////////////////////////// //
28 // /////////////////////////////// //
28
29
29 // VariableController <-> DataSourceController
30 // VariableController <-> DataSourceController
30 connect(m_DataSourceController.get(),
31 connect(m_DataSourceController.get(),
31 SIGNAL(variableCreationRequested(const QString &, const QVariantHash &,
32 SIGNAL(variableCreationRequested(const QString &, const QVariantHash &,
32 std::shared_ptr<IDataProvider>)),
33 std::shared_ptr<IDataProvider>)),
33 m_VariableController.get(),
34 m_VariableController.get(),
34 SLOT(createVariable(const QString &, const QVariantHash &,
35 SLOT(createVariable(const QString &, const QVariantHash &,
35 std::shared_ptr<IDataProvider>)));
36 std::shared_ptr<IDataProvider>)));
36
37
38 connect(m_VariableController->variableModel(), &VariableModel::requestVariable,
39 m_DataSourceController.get(), &DataSourceController::requestVariable);
40
37 // VariableController <-> VisualizationController
41 // VariableController <-> VisualizationController
38 connect(m_VariableController.get(),
42 connect(m_VariableController.get(),
39 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
43 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
40 m_VisualizationController.get(),
44 m_VisualizationController.get(),
41 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
45 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
42
46
43 connect(m_VariableController.get(),
47 connect(m_VariableController.get(),
44 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)),
48 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)),
45 m_VisualizationController.get(),
49 m_VisualizationController.get(),
46 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)));
50 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)));
47
51
48
52
49 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
53 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
50 m_DataSourceControllerThread.setObjectName("DataSourceControllerThread");
54 m_DataSourceControllerThread.setObjectName("DataSourceControllerThread");
51 m_NetworkController->moveToThread(&m_NetworkControllerThread);
55 m_NetworkController->moveToThread(&m_NetworkControllerThread);
52 m_NetworkControllerThread.setObjectName("NetworkControllerThread");
56 m_NetworkControllerThread.setObjectName("NetworkControllerThread");
53 m_VariableController->moveToThread(&m_VariableControllerThread);
57 m_VariableController->moveToThread(&m_VariableControllerThread);
54 m_VariableControllerThread.setObjectName("VariableControllerThread");
58 m_VariableControllerThread.setObjectName("VariableControllerThread");
55 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
59 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
56 m_VisualizationControllerThread.setObjectName("VsualizationControllerThread");
60 m_VisualizationControllerThread.setObjectName("VsualizationControllerThread");
57
61
58
62
59 // Additionnal init
63 // Additionnal init
60 m_VariableController->setTimeController(m_TimeController.get());
64 m_VariableController->setTimeController(m_TimeController.get());
61 }
65 }
62
66
63 virtual ~SqpApplicationPrivate()
67 virtual ~SqpApplicationPrivate()
64 {
68 {
65 m_DataSourceControllerThread.quit();
69 m_DataSourceControllerThread.quit();
66 m_DataSourceControllerThread.wait();
70 m_DataSourceControllerThread.wait();
67
71
68 m_NetworkControllerThread.quit();
72 m_NetworkControllerThread.quit();
69 m_NetworkControllerThread.wait();
73 m_NetworkControllerThread.wait();
70
74
71 m_VariableControllerThread.quit();
75 m_VariableControllerThread.quit();
72 m_VariableControllerThread.wait();
76 m_VariableControllerThread.wait();
73
77
74 m_VisualizationControllerThread.quit();
78 m_VisualizationControllerThread.quit();
75 m_VisualizationControllerThread.wait();
79 m_VisualizationControllerThread.wait();
76 }
80 }
77
81
78 std::unique_ptr<DataSourceController> m_DataSourceController;
82 std::unique_ptr<DataSourceController> m_DataSourceController;
79 std::unique_ptr<VariableController> m_VariableController;
83 std::unique_ptr<VariableController> m_VariableController;
80 std::unique_ptr<TimeController> m_TimeController;
84 std::unique_ptr<TimeController> m_TimeController;
81 std::unique_ptr<NetworkController> m_NetworkController;
85 std::unique_ptr<NetworkController> m_NetworkController;
82 std::unique_ptr<VisualizationController> m_VisualizationController;
86 std::unique_ptr<VisualizationController> m_VisualizationController;
83 QThread m_DataSourceControllerThread;
87 QThread m_DataSourceControllerThread;
84 QThread m_NetworkControllerThread;
88 QThread m_NetworkControllerThread;
85 QThread m_VariableControllerThread;
89 QThread m_VariableControllerThread;
86 QThread m_VisualizationControllerThread;
90 QThread m_VisualizationControllerThread;
87
91
88 std::unique_ptr<DragDropHelper> m_DragDropHelper;
92 std::unique_ptr<DragDropHelper> m_DragDropHelper;
89 };
93 };
90
94
91
95
92 SqpApplication::SqpApplication(int &argc, char **argv)
96 SqpApplication::SqpApplication(int &argc, char **argv)
93 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
97 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
94 {
98 {
95 qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread();
99 qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread();
96
100
97 connect(&impl->m_DataSourceControllerThread, &QThread::started,
101 connect(&impl->m_DataSourceControllerThread, &QThread::started,
98 impl->m_DataSourceController.get(), &DataSourceController::initialize);
102 impl->m_DataSourceController.get(), &DataSourceController::initialize);
99 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
103 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
100 impl->m_DataSourceController.get(), &DataSourceController::finalize);
104 impl->m_DataSourceController.get(), &DataSourceController::finalize);
101
105
102 connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(),
106 connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(),
103 &NetworkController::initialize);
107 &NetworkController::initialize);
104 connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(),
108 connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(),
105 &NetworkController::finalize);
109 &NetworkController::finalize);
106
110
107 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
111 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
108 &VariableController::initialize);
112 &VariableController::initialize);
109 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
113 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
110 &VariableController::finalize);
114 &VariableController::finalize);
111
115
112 connect(&impl->m_VisualizationControllerThread, &QThread::started,
116 connect(&impl->m_VisualizationControllerThread, &QThread::started,
113 impl->m_VisualizationController.get(), &VisualizationController::initialize);
117 impl->m_VisualizationController.get(), &VisualizationController::initialize);
114 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
118 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
115 impl->m_VisualizationController.get(), &VisualizationController::finalize);
119 impl->m_VisualizationController.get(), &VisualizationController::finalize);
116
120
117 impl->m_DataSourceControllerThread.start();
121 impl->m_DataSourceControllerThread.start();
118 impl->m_NetworkControllerThread.start();
122 impl->m_NetworkControllerThread.start();
119 impl->m_VariableControllerThread.start();
123 impl->m_VariableControllerThread.start();
120 impl->m_VisualizationControllerThread.start();
124 impl->m_VisualizationControllerThread.start();
121 }
125 }
122
126
123 SqpApplication::~SqpApplication() {}
127 SqpApplication::~SqpApplication() {}
124
128
125 void SqpApplication::initialize() {}
129 void SqpApplication::initialize() {}
126
130
127 DataSourceController &SqpApplication::dataSourceController() noexcept
131 DataSourceController &SqpApplication::dataSourceController() noexcept
128 {
132 {
129 return *impl->m_DataSourceController;
133 return *impl->m_DataSourceController;
130 }
134 }
131
135
132 NetworkController &SqpApplication::networkController() noexcept
136 NetworkController &SqpApplication::networkController() noexcept
133 {
137 {
134 return *impl->m_NetworkController;
138 return *impl->m_NetworkController;
135 }
139 }
136
140
137 TimeController &SqpApplication::timeController() noexcept
141 TimeController &SqpApplication::timeController() noexcept
138 {
142 {
139 return *impl->m_TimeController;
143 return *impl->m_TimeController;
140 }
144 }
141
145
142 VariableController &SqpApplication::variableController() noexcept
146 VariableController &SqpApplication::variableController() noexcept
143 {
147 {
144 return *impl->m_VariableController;
148 return *impl->m_VariableController;
145 }
149 }
146
150
147 VisualizationController &SqpApplication::visualizationController() noexcept
151 VisualizationController &SqpApplication::visualizationController() noexcept
148 {
152 {
149 return *impl->m_VisualizationController;
153 return *impl->m_VisualizationController;
150 }
154 }
151
155
152 DragDropHelper &SqpApplication::dragDropHelper() noexcept
156 DragDropHelper &SqpApplication::dragDropHelper() noexcept
153 {
157 {
154 return *impl->m_DragDropHelper;
158 return *impl->m_DragDropHelper;
155 }
159 }
@@ -1,46 +1,49
1 <?xml version="1.0" encoding="UTF-8"?>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
2 <ui version="4.0">
3 <class>DataSourceWidget</class>
3 <class>DataSourceWidget</class>
4 <widget class="QWidget" name="DataSourceWidget">
4 <widget class="QWidget" name="DataSourceWidget">
5 <property name="geometry">
5 <property name="geometry">
6 <rect>
6 <rect>
7 <x>0</x>
7 <x>0</x>
8 <y>0</y>
8 <y>0</y>
9 <width>400</width>
9 <width>400</width>
10 <height>300</height>
10 <height>300</height>
11 </rect>
11 </rect>
12 </property>
12 </property>
13 <property name="windowTitle">
13 <property name="windowTitle">
14 <string>Data sources</string>
14 <string>Data sources</string>
15 </property>
15 </property>
16 <layout class="QGridLayout" name="gridLayout">
16 <layout class="QGridLayout" name="gridLayout">
17 <item row="0" column="0">
17 <item row="0" column="0">
18 <widget class="QLineEdit" name="filterLineEdit"/>
18 <widget class="QLineEdit" name="filterLineEdit"/>
19 </item>
19 </item>
20 <item row="1" column="0">
20 <item row="1" column="0">
21 <widget class="DataSourceTreeWidget" name="treeWidget">
21 <widget class="DataSourceTreeWidget" name="treeWidget">
22 <property name="dragEnabled">
22 <property name="dragEnabled">
23 <bool>true</bool>
23 <bool>true</bool>
24 </property>
24 </property>
25 <property name="dragDropMode">
25 <property name="dragDropMode">
26 <enum>QAbstractItemView::DragOnly</enum>
26 <enum>QAbstractItemView::DragOnly</enum>
27 </property>
27 </property>
28 <property name="selectionMode">
29 <enum>QAbstractItemView::ExtendedSelection</enum>
30 </property>
28 <column>
31 <column>
29 <property name="text">
32 <property name="text">
30 <string notr="true">1</string>
33 <string notr="true">1</string>
31 </property>
34 </property>
32 </column>
35 </column>
33 </widget>
36 </widget>
34 </item>
37 </item>
35 </layout>
38 </layout>
36 </widget>
39 </widget>
37 <customwidgets>
40 <customwidgets>
38 <customwidget>
41 <customwidget>
39 <class>DataSourceTreeWidget</class>
42 <class>DataSourceTreeWidget</class>
40 <extends>QTreeWidget</extends>
43 <extends>QTreeWidget</extends>
41 <header>DataSource/DataSourceTreeWidget.h</header>
44 <header>DataSource/DataSourceTreeWidget.h</header>
42 </customwidget>
45 </customwidget>
43 </customwidgets>
46 </customwidgets>
44 <resources/>
47 <resources/>
45 <connections/>
48 <connections/>
46 </ui>
49 </ui>
General Comments 0
You need to be logged in to leave comments. Login now