##// END OF EJS Templates
Merge pull request 178 from SCIQLOP-Initialisation develop...
leroux -
r363:2c0a115f1697 merge
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -1,73 +1,94
1 #ifndef SCIQLOP_DATASOURCEITEM_H
1 #ifndef SCIQLOP_DATASOURCEITEM_H
2 #define SCIQLOP_DATASOURCEITEM_H
2 #define SCIQLOP_DATASOURCEITEM_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5
5
6 #include <QVariant>
6 #include <QVariant>
7 #include <QVector>
7 #include <QVector>
8
8
9 class DataSourceItemAction;
9 class DataSourceItemAction;
10
10
11 /**
11 /**
12 * Possible types of an item
12 * Possible types of an item
13 */
13 */
14 enum class DataSourceItemType { NODE, PRODUCT };
14 enum class DataSourceItemType { NODE, PRODUCT, COMPONENT };
15
15
16 /**
16 /**
17 * @brief The DataSourceItem class aims to represent a structure element of a data source.
17 * @brief The DataSourceItem class aims to represent a structure element of a data source.
18 * A data source has a tree structure that is made up of a main DataSourceItem object (root)
18 * A data source has a tree structure that is made up of a main DataSourceItem object (root)
19 * containing other DataSourceItem objects (children).
19 * containing other DataSourceItem objects (children).
20 * For each DataSourceItem can be associated a set of data representing it.
20 * For each DataSourceItem can be associated a set of data representing it.
21 */
21 */
22 class DataSourceItem {
22 class DataSourceItem {
23 public:
23 public:
24 explicit DataSourceItem(DataSourceItemType type, QVector<QVariant> data = {});
24 /// Key associated with the name of the item
25 static const QString NAME_DATA_KEY;
26
27 explicit DataSourceItem(DataSourceItemType type, const QString &name);
28 explicit DataSourceItem(DataSourceItemType type, QHash<QString, QVariant> data = {});
25
29
26 /// @return the actions of the item as a vector
30 /// @return the actions of the item as a vector
27 QVector<DataSourceItemAction *> actions() const noexcept;
31 QVector<DataSourceItemAction *> actions() const noexcept;
28
32
29 /**
33 /**
30 * Adds an action to the item. The item takes ownership of the action, and the action is
34 * Adds an action to the item. The item takes ownership of the action, and the action is
31 * automatically associated to the item
35 * automatically associated to the item
32 * @param action the action to add
36 * @param action the action to add
33 */
37 */
34 void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept;
38 void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept;
35
39
36 /**
40 /**
37 * Adds a child to the item. The item takes ownership of the child.
41 * Adds a child to the item. The item takes ownership of the child.
38 * @param child the child to add
42 * @param child the child to add
39 */
43 */
40 void appendChild(std::unique_ptr<DataSourceItem> child) noexcept;
44 void appendChild(std::unique_ptr<DataSourceItem> child) noexcept;
41
45
42 /**
46 /**
43 * Returns the item's child associated to an index
47 * Returns the item's child associated to an index
44 * @param childIndex the index to search
48 * @param childIndex the index to search
45 * @return a pointer to the child if index is valid, nullptr otherwise
49 * @return a pointer to the child if index is valid, nullptr otherwise
46 */
50 */
47 DataSourceItem *child(int childIndex) const noexcept;
51 DataSourceItem *child(int childIndex) const noexcept;
48
52
49 int childCount() const noexcept;
53 int childCount() const noexcept;
50
54
51 /**
55 /**
52 * Get the data associated to an index
56 * Get the data associated to a key
53 * @param dataIndex the index to search
57 * @param key the key to search
54 * @return the data found if index is valid, default QVariant otherwise
58 * @return the data found if key is valid, default QVariant otherwise
55 */
59 */
56 QVariant data(int dataIndex) const noexcept;
60 QVariant data(const QString &key) const noexcept;
61
62 /// Gets all data
63 const QHash<QString, QVariant> &data() const noexcept;
64
65 bool isRoot() const noexcept;
57
66
58 QString name() const noexcept;
67 QString name() const noexcept;
59
68
60 /**
69 /**
61 * Get the item's parent
70 * Get the item's parent
62 * @return a pointer to the parent if it exists, nullptr if the item is a root
71 * @return a pointer to the parent if it exists, nullptr if the item is a root
63 */
72 */
64 DataSourceItem *parentItem() const noexcept;
73 DataSourceItem *parentItem() const noexcept;
65
74
75 /**
76 * Sets or appends a value to a key
77 * @param key the key
78 * @param value the value
79 * @param append if true, the value is added to the values already existing for the key,
80 * otherwise it replaces the existing values
81 */
82 void setData(const QString &key, const QVariant &value, bool append = false) noexcept;
83
66 DataSourceItemType type() const noexcept;
84 DataSourceItemType type() const noexcept;
67
85
86 bool operator==(const DataSourceItem &other);
87 bool operator!=(const DataSourceItem &other);
88
68 private:
89 private:
69 class DataSourceItemPrivate;
90 class DataSourceItemPrivate;
70 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
91 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
71 };
92 };
72
93
73 #endif // SCIQLOP_DATASOURCEITEMMODEL_H
94 #endif // SCIQLOP_DATASOURCEITEMMODEL_H
@@ -1,82 +1,80
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
3
3
4 #include <Data/SqpDateTime.h>
4 #include <Data/SqpDateTime.h>
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QObject>
7 #include <QObject>
8
8
9 #include <Common/spimpl.h>
9 #include <Common/spimpl.h>
10
10
11 class IDataProvider;
11 class IDataProvider;
12 class QItemSelectionModel;
12 class QItemSelectionModel;
13 class TimeController;
13 class TimeController;
14 class Variable;
14 class Variable;
15 class VariableModel;
15 class VariableModel;
16
16
17 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
17 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
18
18
19 /**
19 /**
20 * @brief The VariableController class aims to handle the variables in SciQlop.
20 * @brief The VariableController class aims to handle the variables in SciQlop.
21 */
21 */
22 class VariableController : public QObject {
22 class VariableController : public QObject {
23 Q_OBJECT
23 Q_OBJECT
24 public:
24 public:
25 explicit VariableController(QObject *parent = 0);
25 explicit VariableController(QObject *parent = 0);
26 virtual ~VariableController();
26 virtual ~VariableController();
27
27
28 VariableModel *variableModel() noexcept;
28 VariableModel *variableModel() noexcept;
29 QItemSelectionModel *variableSelectionModel() noexcept;
29 QItemSelectionModel *variableSelectionModel() noexcept;
30
30
31 void setTimeController(TimeController *timeController) noexcept;
31 void setTimeController(TimeController *timeController) noexcept;
32
32
33 /**
33 /**
34 * Deletes from the controller the variable passed in parameter.
34 * Deletes from the controller the variable passed in parameter.
35 *
35 *
36 * Delete a variable includes:
36 * Delete a variable includes:
37 * - the deletion of the various references to the variable in SciQlop
37 * - the deletion of the various references to the variable in SciQlop
38 * - the deletion of the model variable
38 * - the deletion of the model variable
39 * - the deletion of the provider associated with the variable
39 * - the deletion of the provider associated with the variable
40 * - removing the cache associated with the variable
40 * - removing the cache associated with the variable
41 *
41 *
42 * @param variable the variable to delete from the controller.
42 * @param variable the variable to delete from the controller.
43 */
43 */
44 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
44 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
45
45
46 /**
46 /**
47 * Deletes from the controller the variables passed in parameter.
47 * Deletes from the controller the variables passed in parameter.
48 * @param variables the variables to delete from the controller.
48 * @param variables the variables to delete from the controller.
49 * @sa deleteVariable()
49 * @sa deleteVariable()
50 */
50 */
51 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
51 void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept;
52
52
53 signals:
53 signals:
54 /// Signal emitted when a variable is about to be deleted from the controller
54 /// Signal emitted when a variable is about to be deleted from the controller
55 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
55 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
56 /// Signal emitted when a variable has been created
57 void variableCreated(std::shared_ptr<Variable> variable);
58
56
59 public slots:
57 public slots:
60 /// Request the data loading of the variable whithin dateTime
58 /// Request the data loading of the variable whithin dateTime
61 void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
59 void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
62 /**
60 /**
63 * Creates a new variable and adds it to the model
61 * Creates a new variable and adds it to the model
64 * @param name the name of the new variable
62 * @param name the name of the new variable
65 * @param provider the data provider for the new variable
63 * @param provider the data provider for the new variable
66 */
64 */
67 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
65 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
68
66
69 /// Update the temporal parameters of every selected variable to dateTime
67 /// Update the temporal parameters of every selected variable to dateTime
70 void onDateTimeOnSelection(const SqpDateTime &dateTime);
68 void onDateTimeOnSelection(const SqpDateTime &dateTime);
71
69
72 void initialize();
70 void initialize();
73 void finalize();
71 void finalize();
74
72
75 private:
73 private:
76 void waitForFinish();
74 void waitForFinish();
77
75
78 class VariableControllerPrivate;
76 class VariableControllerPrivate;
79 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
77 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
80 };
78 };
81
79
82 #endif // SCIQLOP_VARIABLECONTROLLER_H
80 #endif // SCIQLOP_VARIABLECONTROLLER_H
@@ -1,46 +1,44
1 #ifndef SCIQLOP_VISUALIZATIONCONTROLLER_H
1 #ifndef SCIQLOP_VISUALIZATIONCONTROLLER_H
2 #define SCIQLOP_VISUALIZATIONCONTROLLER_H
2 #define SCIQLOP_VISUALIZATIONCONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QObject>
5 #include <QObject>
6 #include <QUuid>
6 #include <QUuid>
7
7
8 #include <Common/spimpl.h>
8 #include <Common/spimpl.h>
9
9
10 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationController)
10 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationController)
11
11
12 class DataSourceItem;
12 class DataSourceItem;
13 class Variable;
13 class Variable;
14
14
15 /**
15 /**
16 * @brief The VisualizationController class aims to make the link between SciQlop and its plugins.
16 * @brief The VisualizationController class aims to make the link between SciQlop and its plugins.
17 * This is the intermediate class that SciQlop has to use in the way to connect a data source.
17 * This is the intermediate class that SciQlop has to use in the way to connect a data source.
18 * Please first use register method to initialize a plugin specified by its metadata name (JSON
18 * Please first use register method to initialize a plugin specified by its metadata name (JSON
19 * plugin source) then others specifics method will be able to access it. You can load a data source
19 * plugin source) then others specifics method will be able to access it. You can load a data source
20 * driver plugin then create a data source.
20 * driver plugin then create a data source.
21 */
21 */
22 class VisualizationController : public QObject {
22 class VisualizationController : public QObject {
23 Q_OBJECT
23 Q_OBJECT
24 public:
24 public:
25 explicit VisualizationController(QObject *parent = 0);
25 explicit VisualizationController(QObject *parent = 0);
26 virtual ~VisualizationController();
26 virtual ~VisualizationController();
27
27
28 signals:
28 signals:
29 /// Signal emitted when a variable is about to be deleted from SciQlop
29 /// Signal emitted when a variable is about to be deleted from SciQlop
30 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
30 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
31 /// Signal emitted when a variable has been created in SciQlop
32 void variableCreated(std::shared_ptr<Variable> variable);
33
31
34 public slots:
32 public slots:
35 /// Manage init/end of the controller
33 /// Manage init/end of the controller
36 void initialize();
34 void initialize();
37 void finalize();
35 void finalize();
38
36
39 private:
37 private:
40 void waitForFinish();
38 void waitForFinish();
41
39
42 class VisualizationControllerPrivate;
40 class VisualizationControllerPrivate;
43 spimpl::unique_impl_ptr<VisualizationControllerPrivate> impl;
41 spimpl::unique_impl_ptr<VisualizationControllerPrivate> impl;
44 };
42 };
45
43
46 #endif // SCIQLOP_VISUALIZATIONCONTROLLER_H
44 #endif // SCIQLOP_VISUALIZATIONCONTROLLER_H
@@ -1,86 +1,140
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 namespace {
6 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
7
8 /// Index of the 'name' value in the item
9 const auto NAME_INDEX = 0;
10
11 } // namespace
12
7
13 struct DataSourceItem::DataSourceItemPrivate {
8 struct DataSourceItem::DataSourceItemPrivate {
14 explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data)
9 explicit DataSourceItemPrivate(DataSourceItemType type, QHash<QString, QVariant> data)
15 : 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{}
16 {
11 {
17 }
12 }
18
13
19 DataSourceItem *m_Parent;
14 DataSourceItem *m_Parent;
20 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
15 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
21 DataSourceItemType m_Type;
16 DataSourceItemType m_Type;
22 QVector<QVariant> m_Data;
17 QHash<QString, QVariant> m_Data;
23 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
18 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
24 };
19 };
25
20
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
21 DataSourceItem::DataSourceItem(DataSourceItemType type, const QString &name)
22 : DataSourceItem{type, QHash<QString, QVariant>{{NAME_DATA_KEY, name}}}
23 {
24 }
25
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QHash<QString, QVariant> 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(int dataIndex) const noexcept
68 QVariant DataSourceItem::data(const QString &key) const noexcept
69 {
70 return impl->m_Data.value(key);
71 }
72
73 const QHash<QString, QVariant> &DataSourceItem::data() const noexcept
69 {
74 {
70 return impl->m_Data.value(dataIndex);
75 return impl->m_Data;
76 }
77
78 bool DataSourceItem::isRoot() const noexcept
79 {
80 return impl->m_Parent == nullptr;
71 }
81 }
72
82
73 QString DataSourceItem::name() const noexcept
83 QString DataSourceItem::name() const noexcept
74 {
84 {
75 return data(NAME_INDEX).toString();
85 return data(NAME_DATA_KEY).toString();
76 }
86 }
77
87
78 DataSourceItem *DataSourceItem::parentItem() const noexcept
88 DataSourceItem *DataSourceItem::parentItem() const noexcept
79 {
89 {
80 return impl->m_Parent;
90 return impl->m_Parent;
81 }
91 }
82
92
93 void DataSourceItem::setData(const QString &key, const QVariant &value, bool append) noexcept
94 {
95 auto it = impl->m_Data.constFind(key);
96 if (append && it != impl->m_Data.constEnd()) {
97 // Case of an existing value to which we want to add to the new value
98 if (it->canConvert<QVariantList>()) {
99 auto variantList = it->value<QVariantList>();
100 variantList.append(value);
101
102 impl->m_Data.insert(key, variantList);
103 }
104 else {
105 impl->m_Data.insert(key, QVariantList{*it, value});
106 }
107 }
108 else {
109 // Other cases :
110 // - new value in map OR
111 // - replacement of an existing value (not appending)
112 impl->m_Data.insert(key, value);
113 }
114 }
115
83 DataSourceItemType DataSourceItem::type() const noexcept
116 DataSourceItemType DataSourceItem::type() const noexcept
84 {
117 {
85 return impl->m_Type;
118 return impl->m_Type;
86 }
119 }
120
121 bool DataSourceItem::operator==(const DataSourceItem &other)
122 {
123 // Compares items' attributes
124 if (std::tie(impl->m_Type, impl->m_Data) == std::tie(other.impl->m_Type, other.impl->m_Data)) {
125 // Compares contents of items' children
126 return std::equal(std::cbegin(impl->m_Children), std::cend(impl->m_Children),
127 std::cbegin(other.impl->m_Children),
128 [](const auto &itemChild, const auto &otherChild) {
129 return *itemChild == *otherChild;
130 });
131 }
132 else {
133 return false;
134 }
135 }
136
137 bool DataSourceItem::operator!=(const DataSourceItem &other)
138 {
139 return !(*this == other);
140 }
@@ -1,209 +1,207
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableCacheController.h>
2 #include <Variable/VariableCacheController.h>
3 #include <Variable/VariableController.h>
3 #include <Variable/VariableController.h>
4 #include <Variable/VariableModel.h>
4 #include <Variable/VariableModel.h>
5
5
6 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
7 #include <Data/IDataProvider.h>
7 #include <Data/IDataProvider.h>
8 #include <Data/IDataSeries.h>
8 #include <Data/IDataSeries.h>
9 #include <Time/TimeController.h>
9 #include <Time/TimeController.h>
10
10
11 #include <QDateTime>
11 #include <QDateTime>
12 #include <QMutex>
12 #include <QMutex>
13 #include <QThread>
13 #include <QThread>
14 #include <QtCore/QItemSelectionModel>
14 #include <QtCore/QItemSelectionModel>
15
15
16 #include <unordered_map>
16 #include <unordered_map>
17
17
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
19
19
20 namespace {
20 namespace {
21
21
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
23 /// will be deleted when the timerange is recovered from SciQlop
23 /// will be deleted when the timerange is recovered from SciQlop
24 std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
24 std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
25 const SqpDateTime &dateTime) noexcept
25 const SqpDateTime &dateTime) noexcept
26 {
26 {
27 auto parameters = DataProviderParameters{dateTime};
27 auto parameters = DataProviderParameters{dateTime};
28
28
29 return provider.retrieveData(parameters);
29 return provider.retrieveData(parameters);
30 }
30 }
31
31
32 } // namespace
32 } // namespace
33
33
34 struct VariableController::VariableControllerPrivate {
34 struct VariableController::VariableControllerPrivate {
35 explicit VariableControllerPrivate(VariableController *parent)
35 explicit VariableControllerPrivate(VariableController *parent)
36 : m_WorkingMutex{},
36 : m_WorkingMutex{},
37 m_VariableModel{new VariableModel{parent}},
37 m_VariableModel{new VariableModel{parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
40 {
40 {
41 }
41 }
42
42
43 QMutex m_WorkingMutex;
43 QMutex m_WorkingMutex;
44 /// Variable model. The VariableController has the ownership
44 /// Variable model. The VariableController has the ownership
45 VariableModel *m_VariableModel;
45 VariableModel *m_VariableModel;
46 QItemSelectionModel *m_VariableSelectionModel;
46 QItemSelectionModel *m_VariableSelectionModel;
47
47
48
48
49 TimeController *m_TimeController{nullptr};
49 TimeController *m_TimeController{nullptr};
50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
51
51
52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
53 m_VariableToProviderMap;
53 m_VariableToProviderMap;
54 };
54 };
55
55
56 VariableController::VariableController(QObject *parent)
56 VariableController::VariableController(QObject *parent)
57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
58 {
58 {
59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
60 << QThread::currentThread();
60 << QThread::currentThread();
61 }
61 }
62
62
63 VariableController::~VariableController()
63 VariableController::~VariableController()
64 {
64 {
65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
66 << QThread::currentThread();
66 << QThread::currentThread();
67 this->waitForFinish();
67 this->waitForFinish();
68 }
68 }
69
69
70 VariableModel *VariableController::variableModel() noexcept
70 VariableModel *VariableController::variableModel() noexcept
71 {
71 {
72 return impl->m_VariableModel;
72 return impl->m_VariableModel;
73 }
73 }
74
74
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
76 {
76 {
77 return impl->m_VariableSelectionModel;
77 return impl->m_VariableSelectionModel;
78 }
78 }
79
79
80 void VariableController::setTimeController(TimeController *timeController) noexcept
80 void VariableController::setTimeController(TimeController *timeController) noexcept
81 {
81 {
82 impl->m_TimeController = timeController;
82 impl->m_TimeController = timeController;
83 }
83 }
84
84
85 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
85 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
86 {
86 {
87 if (!variable) {
87 if (!variable) {
88 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
88 qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null";
89 return;
89 return;
90 }
90 }
91
91
92 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
92 // Spreads in SciQlop that the variable will be deleted, so that potential receivers can
93 // make some treatments before the deletion
93 // make some treatments before the deletion
94 emit variableAboutToBeDeleted(variable);
94 emit variableAboutToBeDeleted(variable);
95
95
96 // Deletes provider
96 // Deletes provider
97 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
97 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
98 qCDebug(LOG_VariableController())
98 qCDebug(LOG_VariableController())
99 << tr("Number of providers deleted for variable %1: %2")
99 << tr("Number of providers deleted for variable %1: %2")
100 .arg(variable->name(), QString::number(nbProvidersDeleted));
100 .arg(variable->name(), QString::number(nbProvidersDeleted));
101
101
102 // Clears cache
102 // Clears cache
103 impl->m_VariableCacheController->clear(variable);
103 impl->m_VariableCacheController->clear(variable);
104
104
105 // Deletes from model
105 // Deletes from model
106 impl->m_VariableModel->deleteVariable(variable);
106 impl->m_VariableModel->deleteVariable(variable);
107 }
107 }
108
108
109 void VariableController::deleteVariables(
109 void VariableController::deleteVariables(
110 const QVector<std::shared_ptr<Variable> > &variables) noexcept
110 const QVector<std::shared_ptr<Variable> > &variables) noexcept
111 {
111 {
112 for (auto variable : qAsConst(variables)) {
112 for (auto variable : qAsConst(variables)) {
113 deleteVariable(variable);
113 deleteVariable(variable);
114 }
114 }
115 }
115 }
116
116
117 void VariableController::createVariable(const QString &name,
117 void VariableController::createVariable(const QString &name,
118 std::shared_ptr<IDataProvider> provider) noexcept
118 std::shared_ptr<IDataProvider> provider) noexcept
119 {
119 {
120
120
121 if (!impl->m_TimeController) {
121 if (!impl->m_TimeController) {
122 qCCritical(LOG_VariableController())
122 qCCritical(LOG_VariableController())
123 << tr("Impossible to create variable: The time controller is null");
123 << tr("Impossible to create variable: The time controller is null");
124 return;
124 return;
125 }
125 }
126
126
127
127
128 /// @todo : for the moment :
128 /// @todo : for the moment :
129 /// - the provider is only used to retrieve data from the variable for its initialization, but
129 /// - the provider is only used to retrieve data from the variable for its initialization, but
130 /// it will be retained later
130 /// it will be retained later
131 /// - default data are generated for the variable, without taking into account the timerange set
131 /// - default data are generated for the variable, without taking into account the timerange set
132 /// in sciqlop
132 /// in sciqlop
133 auto dateTime = impl->m_TimeController->dateTime();
133 auto dateTime = impl->m_TimeController->dateTime();
134 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
134 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
135
135
136 // store the provider
136 // store the provider
137 impl->m_VariableToProviderMap[newVariable] = provider;
137 impl->m_VariableToProviderMap[newVariable] = provider;
138
138
139 auto addDateTimeAcquired
139 auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ](
140 = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) {
140 auto dataSeriesAcquired, auto dateTimeToPutInCache)
141
141 {
142 impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache);
142 if (auto variable = varW.lock()) {
143 newVariable->setDataSeries(dataSeriesAcquired);
143 impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache);
144
144 variable->setDataSeries(dataSeriesAcquired);
145 }
145 };
146 };
146
147
147 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
148 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
148 this->onRequestDataLoading(newVariable, dateTime);
149 this->onRequestDataLoading(newVariable, dateTime);
149
150 // notify the creation
151 emit variableCreated(newVariable);
152 }
150 }
153 }
151 }
154
152
155 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
153 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
156 {
154 {
157 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
155 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
158
156
159 for (const auto &selectedRow : qAsConst(selectedRows)) {
157 for (const auto &selectedRow : qAsConst(selectedRows)) {
160 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
158 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
161 selectedVariable->setDateTime(dateTime);
159 selectedVariable->setDateTime(dateTime);
162 this->onRequestDataLoading(selectedVariable, dateTime);
160 this->onRequestDataLoading(selectedVariable, dateTime);
163 }
161 }
164 }
162 }
165 }
163 }
166
164
167
165
168 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
166 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
169 const SqpDateTime &dateTime)
167 const SqpDateTime &dateTime)
170 {
168 {
171 // we want to load data of the variable for the dateTime.
169 // we want to load data of the variable for the dateTime.
172 // First we check if the cache contains some of them.
170 // First we check if the cache contains some of them.
173 // For the other, we ask the provider to give them.
171 // For the other, we ask the provider to give them.
174 if (variable) {
172 if (variable) {
175
173
176 auto dateTimeListNotInCache
174 auto dateTimeListNotInCache
177 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
175 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
178
176
179 if (!dateTimeListNotInCache.empty()) {
177 if (!dateTimeListNotInCache.empty()) {
180 // Ask the provider for each data on the dateTimeListNotInCache
178 // Ask the provider for each data on the dateTimeListNotInCache
181 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
179 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
182 std::move(dateTimeListNotInCache));
180 std::move(dateTimeListNotInCache));
183 }
181 }
184 else {
182 else {
185 emit variable->updated();
183 emit variable->updated();
186 }
184 }
187 }
185 }
188 else {
186 else {
189 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
187 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
190 }
188 }
191 }
189 }
192
190
193
191
194 void VariableController::initialize()
192 void VariableController::initialize()
195 {
193 {
196 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
194 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
197 impl->m_WorkingMutex.lock();
195 impl->m_WorkingMutex.lock();
198 qCDebug(LOG_VariableController()) << tr("VariableController init END");
196 qCDebug(LOG_VariableController()) << tr("VariableController init END");
199 }
197 }
200
198
201 void VariableController::finalize()
199 void VariableController::finalize()
202 {
200 {
203 impl->m_WorkingMutex.unlock();
201 impl->m_WorkingMutex.unlock();
204 }
202 }
205
203
206 void VariableController::waitForFinish()
204 void VariableController::waitForFinish()
207 {
205 {
208 QMutexLocker locker{&impl->m_WorkingMutex};
206 QMutexLocker locker{&impl->m_WorkingMutex};
209 }
207 }
@@ -1,51 +1,49
1 #include <DataSource/DataSourceController.h>
1 #include <DataSource/DataSourceController.h>
2 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItem.h>
3
3
4 #include <QObject>
4 #include <QObject>
5 #include <QtTest>
5 #include <QtTest>
6
6
7 #include <memory>
7 #include <memory>
8
8
9 class TestDataSourceController : public QObject {
9 class TestDataSourceController : public QObject {
10 Q_OBJECT
10 Q_OBJECT
11 private slots:
11 private slots:
12 void testRegisterDataSource();
12 void testRegisterDataSource();
13 void testSetDataSourceItem();
13 void testSetDataSourceItem();
14 };
14 };
15
15
16 void TestDataSourceController::testRegisterDataSource()
16 void TestDataSourceController::testRegisterDataSource()
17 {
17 {
18 DataSourceController dataSourceController{};
18 DataSourceController dataSourceController{};
19
19
20 auto uid = dataSourceController.registerDataSource(QStringLiteral("Source1"));
20 auto uid = dataSourceController.registerDataSource(QStringLiteral("Source1"));
21 QVERIFY(!uid.isNull());
21 QVERIFY(!uid.isNull());
22 }
22 }
23
23
24 void TestDataSourceController::testSetDataSourceItem()
24 void TestDataSourceController::testSetDataSourceItem()
25 {
25 {
26 DataSourceController dataSourceController{};
26 DataSourceController dataSourceController{};
27
27
28 // Spy to test controllers' signals
28 // Spy to test controllers' signals
29 QSignalSpy signalSpy{&dataSourceController, SIGNAL(dataSourceItemSet(DataSourceItem *))};
29 QSignalSpy signalSpy{&dataSourceController, SIGNAL(dataSourceItemSet(DataSourceItem *))};
30
30
31 // Create a data source item
31 // Create a data source item
32 auto source1Name = QStringLiteral("Source1");
32 auto source1Name = QStringLiteral("Source1");
33 auto source1Values = QVector<QVariant>{source1Name};
33 auto source1Item = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, source1Name);
34 auto source1Item
35 = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, std::move(source1Values));
36
34
37 // Add data source item to the controller and check that a signal has been emitted after setting
35 // Add data source item to the controller and check that a signal has been emitted after setting
38 // data source item in the controller
36 // data source item in the controller
39 auto source1Uid = dataSourceController.registerDataSource(source1Name);
37 auto source1Uid = dataSourceController.registerDataSource(source1Name);
40 dataSourceController.setDataSourceItem(source1Uid, std::move(source1Item));
38 dataSourceController.setDataSourceItem(source1Uid, std::move(source1Item));
41 QCOMPARE(signalSpy.count(), 1);
39 QCOMPARE(signalSpy.count(), 1);
42
40
43 // Try to a data source item with an unregistered uid and check that no signal has been emitted
41 // Try to a data source item with an unregistered uid and check that no signal has been emitted
44 auto unregisteredUid = QUuid::createUuid();
42 auto unregisteredUid = QUuid::createUuid();
45 dataSourceController.setDataSourceItem(
43 dataSourceController.setDataSourceItem(
46 unregisteredUid, std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT));
44 unregisteredUid, std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT));
47 QCOMPARE(signalSpy.count(), 1);
45 QCOMPARE(signalSpy.count(), 1);
48 }
46 }
49
47
50 QTEST_MAIN(TestDataSourceController)
48 QTEST_MAIN(TestDataSourceController)
51 #include "TestDataSourceController.moc"
49 #include "TestDataSourceController.moc"
@@ -1,10 +1,14
1 <RCC>
1 <RCC>
2 <qresource prefix="/">
2 <qresource prefix="/">
3 <file>icones/dataSourceComponent.png</file>
4 <file>icones/dataSourceNode.png</file>
5 <file>icones/dataSourceProduct.png</file>
6 <file>icones/dataSourceRoot.png</file>
3 <file>icones/delete.png</file>
7 <file>icones/delete.png</file>
4 <file>icones/openInspector.png</file>
8 <file>icones/openInspector.png</file>
5 <file>icones/next.png</file>
9 <file>icones/next.png</file>
6 <file>icones/plot.png</file>
10 <file>icones/plot.png</file>
7 <file>icones/previous.png</file>
11 <file>icones/previous.png</file>
8 <file>icones/unplot.png</file>
12 <file>icones/unplot.png</file>
9 </qresource>
13 </qresource>
10 </RCC>
14 </RCC>
@@ -1,101 +1,171
1 #include <DataSource/DataSourceItem.h>
1 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItemAction.h>
2 #include <DataSource/DataSourceItemAction.h>
3 #include <DataSource/DataSourceTreeWidgetItem.h>
3 #include <DataSource/DataSourceTreeWidgetItem.h>
4
4
5 #include <SqpApplication.h>
6
7 #include <QAction>
5 #include <QAction>
8
6
9 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
7 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
10
8
11 namespace {
9 namespace {
12
10
11 // Column indexes
12 const auto NAME_COLUMN = 0;
13
13 QIcon itemIcon(const DataSourceItem *dataSource)
14 QIcon itemIcon(const DataSourceItem *dataSource)
14 {
15 {
15 if (dataSource) {
16 if (dataSource) {
16 auto dataSourceType = dataSource->type();
17 auto dataSourceType = dataSource->type();
17 switch (dataSourceType) {
18 switch (dataSourceType) {
18 case DataSourceItemType::NODE:
19 case DataSourceItemType::NODE: {
19 return sqpApp->style()->standardIcon(QStyle::SP_DirIcon);
20 return dataSource->isRoot() ? QIcon{":/icones/dataSourceRoot.png"}
21 : QIcon{":/icones/dataSourceNode.png"};
22 }
20 case DataSourceItemType::PRODUCT:
23 case DataSourceItemType::PRODUCT:
21 return sqpApp->style()->standardIcon(QStyle::SP_FileIcon);
24 return QIcon{":/icones/dataSourceProduct.png"};
25 case DataSourceItemType::COMPONENT:
26 return QIcon{":/icones/dataSourceComponent.png"};
22 default:
27 default:
23 // No action
28 // No action
24 break;
29 break;
25 }
30 }
26
31
27 qCWarning(LOG_DataSourceTreeWidgetItem())
32 qCWarning(LOG_DataSourceTreeWidgetItem())
28 << QObject::tr("Can't set data source icon : unknown data source type");
33 << QObject::tr("Can't set data source icon : unknown data source type");
29 }
34 }
30 else {
35 else {
31 qCWarning(LOG_DataSourceTreeWidgetItem())
36 qCCritical(LOG_DataSourceTreeWidgetItem())
32 << QObject::tr("Can't set data source icon : the data source is null");
37 << QObject::tr("Can't set data source icon : the data source is null");
33 }
38 }
34
39
35 // Default cases
40 // Default cases
36 return QIcon{};
41 return QIcon{};
37 }
42 }
38
43
44 /// @return the tooltip text for a variant. The text depends on whether the data is a simple variant
45 /// or a list of variants
46 QString tooltipValue(const QVariant &variant) noexcept
47 {
48 // If the variant is a list of variants, the text of the tooltip is of the form: {val1, val2,
49 // ...}
50 if (variant.canConvert<QVariantList>()) {
51 auto valueString = QStringLiteral("{");
52
53 auto variantList = variant.value<QVariantList>();
54 for (auto it = variantList.cbegin(), end = variantList.cend(); it != end; ++it) {
55 valueString.append(it->toString());
56
57 if (std::distance(it, end) != 1) {
58 valueString.append(", ");
59 }
60 }
61
62 valueString.append(QStringLiteral("}"));
63
64 return valueString;
65 }
66 else {
67 return variant.toString();
68 }
69 }
70
71 QString itemTooltip(const DataSourceItem *dataSource) noexcept
72 {
73 // The tooltip displays all item's data
74 if (dataSource) {
75 auto result = QString{};
76
77 const auto &data = dataSource->data();
78 for (auto it = data.cbegin(), end = data.cend(); it != end; ++it) {
79 result.append(QString{"<b>%1:</b> %2<br/>"}.arg(it.key(), tooltipValue(it.value())));
80 }
81
82 return result;
83 }
84 else {
85 qCCritical(LOG_DataSourceTreeWidgetItem())
86 << QObject::tr("Can't set data source tooltip : the data source is null");
87
88 return QString{};
89 }
90 }
91
39 } // namespace
92 } // namespace
40
93
41 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
94 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
42 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
95 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
43
96
44 /// Model used to retrieve data source information
97 /// Model used to retrieve data source information
45 const DataSourceItem *m_Data;
98 const DataSourceItem *m_Data;
46 /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of
99 /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of
47 /// the actions
100 /// the actions
48 QList<QAction *> m_Actions;
101 QList<QAction *> m_Actions;
49 };
102 };
50
103
51 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
104 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
52 : DataSourceTreeWidgetItem{nullptr, data, type}
105 : DataSourceTreeWidgetItem{nullptr, data, type}
53 {
106 {
54 }
107 }
55
108
56 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
109 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
57 int type)
110 int type)
58 : QTreeWidgetItem{parent, type},
111 : QTreeWidgetItem{parent, type},
59 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
112 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
60 {
113 {
61 // Sets the icon depending on the data source
114 // Sets the icon and the tooltip depending on the data source
62 setIcon(0, itemIcon(impl->m_Data));
115 setIcon(0, itemIcon(impl->m_Data));
116 setToolTip(0, itemTooltip(impl->m_Data));
63
117
64 // Generates tree actions based on the item actions
118 // Generates tree actions based on the item actions
65 auto createTreeAction = [this, &parent](const auto &itemAction) {
119 auto createTreeAction = [this, &parent](const auto &itemAction) {
66 auto treeAction = new QAction{itemAction->name(), parent};
120 auto treeAction = new QAction{itemAction->name(), parent};
67
121
68 // Executes item action when tree action is triggered
122 // Executes item action when tree action is triggered
69 QObject::connect(treeAction, &QAction::triggered, itemAction,
123 QObject::connect(treeAction, &QAction::triggered, itemAction,
70 &DataSourceItemAction::execute);
124 &DataSourceItemAction::execute);
71
125
72 return treeAction;
126 return treeAction;
73 };
127 };
74
128
75 auto itemActions = impl->m_Data->actions();
129 auto itemActions = impl->m_Data->actions();
76 std::transform(std::cbegin(itemActions), std::cend(itemActions),
130 std::transform(std::cbegin(itemActions), std::cend(itemActions),
77 std::back_inserter(impl->m_Actions), createTreeAction);
131 std::back_inserter(impl->m_Actions), createTreeAction);
78 }
132 }
79
133
80 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
134 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
81 {
135 {
82 if (role == Qt::DisplayRole) {
136 if (role == Qt::DisplayRole) {
83 return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{};
137 if (impl->m_Data) {
138 switch (column) {
139 case NAME_COLUMN:
140 return impl->m_Data->name();
141 default:
142 // No action
143 break;
144 }
145
146 qCWarning(LOG_DataSourceTreeWidgetItem())
147 << QObject::tr("Can't get data (unknown column %1)").arg(column);
148 }
149 else {
150 qCCritical(LOG_DataSourceTreeWidgetItem()) << QObject::tr("Can't get data (null item)");
151 }
152
153 return QVariant{};
84 }
154 }
85 else {
155 else {
86 return QTreeWidgetItem::data(column, role);
156 return QTreeWidgetItem::data(column, role);
87 }
157 }
88 }
158 }
89
159
90 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
160 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
91 {
161 {
92 // Data can't be changed by edition
162 // Data can't be changed by edition
93 if (role != Qt::EditRole) {
163 if (role != Qt::EditRole) {
94 QTreeWidgetItem::setData(column, role, value);
164 QTreeWidgetItem::setData(column, role, value);
95 }
165 }
96 }
166 }
97
167
98 QList<QAction *> DataSourceTreeWidgetItem::actions() const noexcept
168 QList<QAction *> DataSourceTreeWidgetItem::actions() const noexcept
99 {
169 {
100 return impl->m_Actions;
170 return impl->m_Actions;
101 }
171 }
@@ -1,122 +1,119
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 <QThread>
5 #include <QThread>
6 #include <Time/TimeController.h>
6 #include <Time/TimeController.h>
7 #include <Variable/Variable.h>
7 #include <Variable/Variable.h>
8 #include <Variable/VariableController.h>
8 #include <Variable/VariableController.h>
9 #include <Visualization/VisualizationController.h>
9 #include <Visualization/VisualizationController.h>
10
10
11 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
11 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
12
12
13 class SqpApplication::SqpApplicationPrivate {
13 class SqpApplication::SqpApplicationPrivate {
14 public:
14 public:
15 SqpApplicationPrivate()
15 SqpApplicationPrivate()
16 : m_DataSourceController{std::make_unique<DataSourceController>()},
16 : m_DataSourceController{std::make_unique<DataSourceController>()},
17 m_TimeController{std::make_unique<TimeController>()},
17 m_TimeController{std::make_unique<TimeController>()},
18 m_VariableController{std::make_unique<VariableController>()},
18 m_VariableController{std::make_unique<VariableController>()},
19 m_VisualizationController{std::make_unique<VisualizationController>()}
19 m_VisualizationController{std::make_unique<VisualizationController>()}
20 {
20 {
21 // /////////////////////////////// //
21 // /////////////////////////////// //
22 // Connections between controllers //
22 // Connections between controllers //
23 // /////////////////////////////// //
23 // /////////////////////////////// //
24
24
25 // VariableController <-> DataSourceController
25 // VariableController <-> DataSourceController
26 connect(m_DataSourceController.get(),
26 connect(m_DataSourceController.get(),
27 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
27 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
28 m_VariableController.get(),
28 m_VariableController.get(),
29 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
29 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
30
30
31 // VariableController <-> VisualizationController
31 // VariableController <-> VisualizationController
32 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
33 m_VisualizationController.get(),
34 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
35 connect(m_VariableController.get(),
32 connect(m_VariableController.get(),
36 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
33 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)),
37 m_VisualizationController.get(),
34 m_VisualizationController.get(),
38 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
35 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection);
39
36
40 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
37 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
41 m_VariableController->moveToThread(&m_VariableControllerThread);
38 m_VariableController->moveToThread(&m_VariableControllerThread);
42 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
39 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
43
40
44 // Additionnal init
41 // Additionnal init
45 m_VariableController->setTimeController(m_TimeController.get());
42 m_VariableController->setTimeController(m_TimeController.get());
46 }
43 }
47
44
48 virtual ~SqpApplicationPrivate()
45 virtual ~SqpApplicationPrivate()
49 {
46 {
50 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
47 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
51 m_DataSourceControllerThread.quit();
48 m_DataSourceControllerThread.quit();
52 m_DataSourceControllerThread.wait();
49 m_DataSourceControllerThread.wait();
53
50
54 m_VariableControllerThread.quit();
51 m_VariableControllerThread.quit();
55 m_VariableControllerThread.wait();
52 m_VariableControllerThread.wait();
56
53
57 m_VisualizationControllerThread.quit();
54 m_VisualizationControllerThread.quit();
58 m_VisualizationControllerThread.wait();
55 m_VisualizationControllerThread.wait();
59 }
56 }
60
57
61 std::unique_ptr<DataSourceController> m_DataSourceController;
58 std::unique_ptr<DataSourceController> m_DataSourceController;
62 std::unique_ptr<VariableController> m_VariableController;
59 std::unique_ptr<VariableController> m_VariableController;
63 std::unique_ptr<TimeController> m_TimeController;
60 std::unique_ptr<TimeController> m_TimeController;
64 std::unique_ptr<VisualizationController> m_VisualizationController;
61 std::unique_ptr<VisualizationController> m_VisualizationController;
65 QThread m_DataSourceControllerThread;
62 QThread m_DataSourceControllerThread;
66 QThread m_VariableControllerThread;
63 QThread m_VariableControllerThread;
67 QThread m_VisualizationControllerThread;
64 QThread m_VisualizationControllerThread;
68 };
65 };
69
66
70
67
71 SqpApplication::SqpApplication(int &argc, char **argv)
68 SqpApplication::SqpApplication(int &argc, char **argv)
72 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
69 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
73 {
70 {
74 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
71 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
75
72
76 connect(&impl->m_DataSourceControllerThread, &QThread::started,
73 connect(&impl->m_DataSourceControllerThread, &QThread::started,
77 impl->m_DataSourceController.get(), &DataSourceController::initialize);
74 impl->m_DataSourceController.get(), &DataSourceController::initialize);
78 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
75 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
79 impl->m_DataSourceController.get(), &DataSourceController::finalize);
76 impl->m_DataSourceController.get(), &DataSourceController::finalize);
80
77
81 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
78 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
82 &VariableController::initialize);
79 &VariableController::initialize);
83 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
80 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
84 &VariableController::finalize);
81 &VariableController::finalize);
85
82
86 connect(&impl->m_VisualizationControllerThread, &QThread::started,
83 connect(&impl->m_VisualizationControllerThread, &QThread::started,
87 impl->m_VisualizationController.get(), &VisualizationController::initialize);
84 impl->m_VisualizationController.get(), &VisualizationController::initialize);
88 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
85 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
89 impl->m_VisualizationController.get(), &VisualizationController::finalize);
86 impl->m_VisualizationController.get(), &VisualizationController::finalize);
90
87
91 impl->m_DataSourceControllerThread.start();
88 impl->m_DataSourceControllerThread.start();
92 impl->m_VariableControllerThread.start();
89 impl->m_VariableControllerThread.start();
93 impl->m_VisualizationControllerThread.start();
90 impl->m_VisualizationControllerThread.start();
94 }
91 }
95
92
96 SqpApplication::~SqpApplication()
93 SqpApplication::~SqpApplication()
97 {
94 {
98 }
95 }
99
96
100 void SqpApplication::initialize()
97 void SqpApplication::initialize()
101 {
98 {
102 }
99 }
103
100
104 DataSourceController &SqpApplication::dataSourceController() noexcept
101 DataSourceController &SqpApplication::dataSourceController() noexcept
105 {
102 {
106 return *impl->m_DataSourceController;
103 return *impl->m_DataSourceController;
107 }
104 }
108
105
109 TimeController &SqpApplication::timeController() noexcept
106 TimeController &SqpApplication::timeController() noexcept
110 {
107 {
111 return *impl->m_TimeController;
108 return *impl->m_TimeController;
112 }
109 }
113
110
114 VariableController &SqpApplication::variableController() noexcept
111 VariableController &SqpApplication::variableController() noexcept
115 {
112 {
116 return *impl->m_VariableController;
113 return *impl->m_VariableController;
117 }
114 }
118
115
119 VisualizationController &SqpApplication::visualizationController() noexcept
116 VisualizationController &SqpApplication::visualizationController() noexcept
120 {
117 {
121 return *impl->m_VisualizationController;
118 return *impl->m_VisualizationController;
122 }
119 }
@@ -1,183 +1,196
1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
2 #include "Visualization/operations/MenuBuilder.h"
2 #include "Visualization/operations/MenuBuilder.h"
3
3
4 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationTabWidget.h"
6 #include "Visualization/VisualizationZoneWidget.h"
6 #include "Visualization/VisualizationZoneWidget.h"
7
7
8 #include <Variable/Variable.h>
8 #include <Variable/Variable.h>
9
9
10 #include <QMenu>
10 #include <QMenu>
11 #include <QStack>
11 #include <QStack>
12
12
13 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
13 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
14
14
15 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
15 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
16 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
16 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
17 : m_Variable{variable}, m_PlotMenuBuilder{menu}, m_UnplotMenuBuilder{menu}
17 : m_Variable{variable}, m_PlotMenuBuilder{menu}, m_UnplotMenuBuilder{menu}
18 {
18 {
19 }
19 }
20
20
21 void visitRootEnter()
21 void visitRootEnter()
22 {
22 {
23 // Creates the root menu
23 // Creates the root menu
24 m_PlotMenuBuilder.addMenu(QObject::tr("Plot"), QIcon{":/icones/plot.png"});
24 m_PlotMenuBuilder.addMenu(QObject::tr("Plot"), QIcon{":/icones/plot.png"});
25 m_UnplotMenuBuilder.addMenu(QObject::tr("Unplot"), QIcon{":/icones/unplot.png"});
25 m_UnplotMenuBuilder.addMenu(QObject::tr("Unplot"), QIcon{":/icones/unplot.png"});
26 }
26 }
27
27
28 void visitRootLeave()
28 void visitRootLeave()
29 {
29 {
30 // Closes the root menu
30 // Closes the root menu
31 m_PlotMenuBuilder.closeMenu();
31 m_PlotMenuBuilder.closeMenu();
32 m_UnplotMenuBuilder.closeMenu();
32 m_UnplotMenuBuilder.closeMenu();
33 }
33 }
34
34
35 void visitNodeEnter(const IVisualizationWidget &container)
35 void visitNodeEnter(const IVisualizationWidget &container)
36 {
36 {
37 // Opens a new menu associated to the node
37 // Opens a new menu associated to the node
38 m_PlotMenuBuilder.addMenu(container.name());
38 m_PlotMenuBuilder.addMenu(container.name());
39 m_UnplotMenuBuilder.addMenu(container.name());
39 m_UnplotMenuBuilder.addMenu(container.name());
40 }
40 }
41
41
42 template <typename ActionFun>
42 template <typename ActionFun>
43 void visitNodeLeavePlot(const IVisualizationWidget &container, const QString &actionName,
43 void visitNodeLeavePlot(const IVisualizationWidget &container, const QString &actionName,
44 ActionFun actionFunction)
44 ActionFun actionFunction)
45 {
45 {
46 if (m_Variable && container.canDrop(*m_Variable)) {
46 if (m_Variable && container.canDrop(*m_Variable)) {
47 m_PlotMenuBuilder.addSeparator();
47 m_PlotMenuBuilder.addSeparator();
48 m_PlotMenuBuilder.addAction(actionName, actionFunction);
48 m_PlotMenuBuilder.addAction(actionName, actionFunction);
49 }
49 }
50
50
51 // Closes the menu associated to the node
51 // Closes the menu associated to the node
52 m_PlotMenuBuilder.closeMenu();
52 m_PlotMenuBuilder.closeMenu();
53 }
53 }
54
54
55 void visitNodeLeaveUnplot()
55 void visitNodeLeaveUnplot()
56 {
56 {
57 // Closes the menu associated to the node
57 // Closes the menu associated to the node
58 m_UnplotMenuBuilder.closeMenu();
58 m_UnplotMenuBuilder.closeMenu();
59 }
59 }
60
60
61 template <typename ActionFun>
61 template <typename ActionFun>
62 void visitLeafPlot(const IVisualizationWidget &container, const QString &actionName,
62 void visitLeafPlot(const IVisualizationWidget &container, const QString &actionName,
63 ActionFun actionFunction)
63 ActionFun actionFunction)
64 {
64 {
65 if (m_Variable && container.canDrop(*m_Variable)) {
65 if (m_Variable && container.canDrop(*m_Variable)) {
66 m_PlotMenuBuilder.addAction(actionName, actionFunction);
66 m_PlotMenuBuilder.addAction(actionName, actionFunction);
67 }
67 }
68 }
68 }
69
69
70 template <typename ActionFun>
70 template <typename ActionFun>
71 void visitLeafUnplot(const IVisualizationWidget &container, const QString &actionName,
71 void visitLeafUnplot(const IVisualizationWidget &container, const QString &actionName,
72 ActionFun actionFunction)
72 ActionFun actionFunction)
73 {
73 {
74 if (m_Variable && container.contains(*m_Variable)) {
74 if (m_Variable && container.contains(*m_Variable)) {
75 m_UnplotMenuBuilder.addAction(actionName, actionFunction);
75 m_UnplotMenuBuilder.addAction(actionName, actionFunction);
76 }
76 }
77 }
77 }
78
78
79 std::shared_ptr<Variable> m_Variable;
79 std::shared_ptr<Variable> m_Variable;
80 MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu
80 MenuBuilder m_PlotMenuBuilder; ///< Builder for the 'Plot' menu
81 MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu
81 MenuBuilder m_UnplotMenuBuilder; ///< Builder for the 'Unplot' menu
82 };
82 };
83
83
84 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
84 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
85 std::shared_ptr<Variable> variable)
85 std::shared_ptr<Variable> variable)
86 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
86 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
87 {
87 {
88 }
88 }
89
89
90 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
90 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
91 {
91 {
92 // VisualizationWidget is not intended to accommodate a variable
92 // VisualizationWidget is not intended to accommodate a variable
93 Q_UNUSED(widget)
93 Q_UNUSED(widget)
94
94
95 // 'Plot' and 'Unplot' menus
95 // 'Plot' and 'Unplot' menus
96 impl->visitRootEnter();
96 impl->visitRootEnter();
97 }
97 }
98
98
99 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
99 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
100 {
100 {
101 // VisualizationWidget is not intended to accommodate a variable
101 // VisualizationWidget is not intended to accommodate a variable
102 Q_UNUSED(widget)
102 Q_UNUSED(widget)
103
103
104 // 'Plot' and 'Unplot' menus
104 // 'Plot' and 'Unplot' menus
105 impl->visitRootLeave();
105 impl->visitRootLeave();
106 }
106 }
107
107
108 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
108 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
109 {
109 {
110 if (tabWidget) {
110 if (tabWidget) {
111 // 'Plot' and 'Unplot' menus
111 // 'Plot' and 'Unplot' menus
112 impl->visitNodeEnter(*tabWidget);
112 impl->visitNodeEnter(*tabWidget);
113 }
113 }
114 else {
114 else {
115 qCCritical(LOG_GenerateVariableMenuOperation(),
115 qCCritical(LOG_GenerateVariableMenuOperation(),
116 "Can't visit enter VisualizationTabWidget : the widget is null");
116 "Can't visit enter VisualizationTabWidget : the widget is null");
117 }
117 }
118 }
118 }
119
119
120 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
120 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
121 {
121 {
122 if (tabWidget) {
122 if (tabWidget) {
123 // 'Plot' menu
123 // 'Plot' menu
124 impl->visitNodeLeavePlot(
124 impl->visitNodeLeavePlot(*tabWidget, QObject::tr("Open in a new zone"),
125 *tabWidget, QObject::tr("Open in a new zone"),
125 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, tabWidget ]() {
126 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
126 if (auto var = varW.lock()) {
127 tabWidget->createZone(var);
128 }
129 });
127
130
128 // 'Unplot' menu
131 // 'Unplot' menu
129 impl->visitNodeLeaveUnplot();
132 impl->visitNodeLeaveUnplot();
130 }
133 }
131 else {
134 else {
132 qCCritical(LOG_GenerateVariableMenuOperation(),
135 qCCritical(LOG_GenerateVariableMenuOperation(),
133 "Can't visit leave VisualizationTabWidget : the widget is null");
136 "Can't visit leave VisualizationTabWidget : the widget is null");
134 }
137 }
135 }
138 }
136
139
137 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
140 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
138 {
141 {
139 if (zoneWidget) {
142 if (zoneWidget) {
140 // 'Plot' and 'Unplot' menus
143 // 'Plot' and 'Unplot' menus
141 impl->visitNodeEnter(*zoneWidget);
144 impl->visitNodeEnter(*zoneWidget);
142 }
145 }
143 else {
146 else {
144 qCCritical(LOG_GenerateVariableMenuOperation(),
147 qCCritical(LOG_GenerateVariableMenuOperation(),
145 "Can't visit enter VisualizationZoneWidget : the widget is null");
148 "Can't visit enter VisualizationZoneWidget : the widget is null");
146 }
149 }
147 }
150 }
148
151
149 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
152 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
150 {
153 {
151 if (zoneWidget) {
154 if (zoneWidget) {
152 // 'Plot' menu
155 // 'Plot' menu
153 impl->visitNodeLeavePlot(
156 impl->visitNodeLeavePlot(
154 *zoneWidget, QObject::tr("Open in a new graph"),
157 *zoneWidget, QObject::tr("Open in a new graph"),
155 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
158 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, zoneWidget ]() {
159 if (auto var = varW.lock()) {
160 zoneWidget->createGraph(var);
161 }
162 });
156
163
157 // 'Unplot' menu
164 // 'Unplot' menu
158 impl->visitNodeLeaveUnplot();
165 impl->visitNodeLeaveUnplot();
159 }
166 }
160 else {
167 else {
161 qCCritical(LOG_GenerateVariableMenuOperation(),
168 qCCritical(LOG_GenerateVariableMenuOperation(),
162 "Can't visit leave VisualizationZoneWidget : the widget is null");
169 "Can't visit leave VisualizationZoneWidget : the widget is null");
163 }
170 }
164 }
171 }
165
172
166 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
173 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
167 {
174 {
168 if (graphWidget) {
175 if (graphWidget) {
169 // 'Plot' menu
176 // 'Plot' menu
170 impl->visitLeafPlot(
177 impl->visitLeafPlot(*graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
171 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
178 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, graphWidget ]() {
172 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
179 if (auto var = varW.lock()) {
180 graphWidget->addVariableUsingGraph(var);
181 }
182 });
173
183
174 // 'Unplot' menu
184 // 'Unplot' menu
175 impl->visitLeafUnplot(
185 impl->visitLeafUnplot(*graphWidget, QObject::tr("Remove from %1").arg(graphWidget->name()),
176 *graphWidget, QObject::tr("Remove from %1").arg(graphWidget->name()),
186 [ varW = std::weak_ptr<Variable>{impl->m_Variable}, graphWidget ]() {
177 [ var = impl->m_Variable, graphWidget ]() { graphWidget->removeVariable(var); });
187 if (auto var = varW.lock()) {
188 graphWidget->removeVariable(var);
189 }
190 });
178 }
191 }
179 else {
192 else {
180 qCCritical(LOG_GenerateVariableMenuOperation(),
193 qCCritical(LOG_GenerateVariableMenuOperation(),
181 "Can't visit VisualizationGraphWidget : the widget is null");
194 "Can't visit VisualizationGraphWidget : the widget is null");
182 }
195 }
183 }
196 }
@@ -1,81 +1,79
1 #include "MockPlugin.h"
1 #include "MockPlugin.h"
2 #include "CosinusProvider.h"
2 #include "CosinusProvider.h"
3
3
4 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceController.h>
5 #include <DataSource/DataSourceItem.h>
5 #include <DataSource/DataSourceItem.h>
6 #include <DataSource/DataSourceItemAction.h>
6 #include <DataSource/DataSourceItemAction.h>
7
7
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9
9
10 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
10 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
11
11
12 namespace {
12 namespace {
13
13
14 /// Name of the data source
14 /// Name of the data source
15 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
15 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
16
16
17 /// Creates the data provider relative to the plugin
17 /// Creates the data provider relative to the plugin
18 std::unique_ptr<IDataProvider> createDataProvider() noexcept
18 std::unique_ptr<IDataProvider> createDataProvider() noexcept
19 {
19 {
20 return std::make_unique<CosinusProvider>();
20 return std::make_unique<CosinusProvider>();
21 }
21 }
22
22
23 std::unique_ptr<DataSourceItem> createProductItem(const QString &productName,
23 std::unique_ptr<DataSourceItem> createProductItem(const QString &productName,
24 const QUuid &dataSourceUid)
24 const QUuid &dataSourceUid)
25 {
25 {
26 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
26 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, productName);
27 QVector<QVariant>{productName});
28
27
29 // Add action to load product from DataSourceController
28 // Add action to load product from DataSourceController
30 result->addAction(std::make_unique<DataSourceItemAction>(
29 result->addAction(std::make_unique<DataSourceItemAction>(
31 QObject::tr("Load %1 product").arg(productName),
30 QObject::tr("Load %1 product").arg(productName),
32 [productName, dataSourceUid](DataSourceItem &item) {
31 [productName, dataSourceUid](DataSourceItem &item) {
33 if (auto app = sqpApp) {
32 if (auto app = sqpApp) {
34 app->dataSourceController().loadProductItem(dataSourceUid, item);
33 app->dataSourceController().loadProductItem(dataSourceUid, item);
35 }
34 }
36 }));
35 }));
37
36
38 return result;
37 return result;
39 }
38 }
40
39
41 /// Creates the data source item relative to the plugin
40 /// Creates the data source item relative to the plugin
42 std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept
41 std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept
43 {
42 {
44 // Magnetic field products
43 // Magnetic field products
45 auto magneticFieldFolder = std::make_unique<DataSourceItem>(
44 auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
46 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")});
45 QStringLiteral("Magnetic field"));
47 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM"), dataSourceUid));
46 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM"), dataSourceUid));
48 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC"), dataSourceUid));
47 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC"), dataSourceUid));
49
48
50 // Electric field products
49 // Electric field products
51 auto electricFieldFolder = std::make_unique<DataSourceItem>(
50 auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
52 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")});
51 QStringLiteral("Electric field"));
53
52
54 // Root
53 // Root
55 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
54 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME);
56 QVector<QVariant>{DATA_SOURCE_NAME});
57 root->appendChild(std::move(magneticFieldFolder));
55 root->appendChild(std::move(magneticFieldFolder));
58 root->appendChild(std::move(electricFieldFolder));
56 root->appendChild(std::move(electricFieldFolder));
59
57
60 return root;
58 return root;
61 }
59 }
62
60
63 } // namespace
61 } // namespace
64
62
65 void MockPlugin::initialize()
63 void MockPlugin::initialize()
66 {
64 {
67 if (auto app = sqpApp) {
65 if (auto app = sqpApp) {
68 // Registers to the data source controller
66 // Registers to the data source controller
69 auto &dataSourceController = app->dataSourceController();
67 auto &dataSourceController = app->dataSourceController();
70 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
68 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
71
69
72 // Sets data source tree
70 // Sets data source tree
73 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid));
71 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid));
74
72
75 // Sets data provider
73 // Sets data provider
76 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
74 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
77 }
75 }
78 else {
76 else {
79 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
77 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
80 }
78 }
81 }
79 }
General Comments 0
You need to be logged in to leave comments. Login now