##// END OF EJS Templates
Merge pull request 150 from SCIQLOP-Initialisation develop...
perrinel -
r154:42e91aee0749 merge
parent child
Show More
@@ -0,0 +1,48
1 #ifndef SCIQLOP_DATASOURCEITEMACTION_H
2 #define SCIQLOP_DATASOURCEITEMACTION_H
3
4 #include <Common/spimpl.h>
5
6 #include <QLoggingCategory>
7 #include <QObject>
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceItemAction)
10
11 class DataSourceItem;
12
13 /**
14 * @brief The DataSourceItemAction class represents an action on a data source item.
15 *
16 * An action is a function that will be executed when the slot execute() is called.
17 */
18 class DataSourceItemAction : public QObject {
19
20 Q_OBJECT
21
22 public:
23 /// Signature of the function associated to the action
24 using ExecuteFunction = std::function<void(DataSourceItem &dataSourceItem)>;
25
26 /**
27 * Ctor
28 * @param name the name of the action
29 * @param fun the function that will be called when the action is executed
30 * @sa execute()
31 */
32 explicit DataSourceItemAction(const QString &name, ExecuteFunction fun);
33
34 QString name() const noexcept;
35
36 /// Sets the data source item concerned by the action
37 void setDataSourceItem(DataSourceItem *dataSourceItem) noexcept;
38
39 public slots:
40 /// Executes the action
41 void execute();
42
43 private:
44 class DataSourceItemActionPrivate;
45 spimpl::unique_impl_ptr<DataSourceItemActionPrivate> impl;
46 };
47
48 #endif // SCIQLOP_DATASOURCEITEMACTION_H
@@ -0,0 +1,42
1 #include <DataSource/DataSourceItemAction.h>
2
3 Q_LOGGING_CATEGORY(LOG_DataSourceItemAction, "DataSourceItemAction")
4
5 struct DataSourceItemAction::DataSourceItemActionPrivate {
6 explicit DataSourceItemActionPrivate(const QString &name,
7 DataSourceItemAction::ExecuteFunction fun)
8 : m_Name{name}, m_Fun{std::move(fun)}, m_DataSourceItem{nullptr}
9 {
10 }
11
12 QString m_Name;
13 DataSourceItemAction::ExecuteFunction m_Fun;
14 /// Item associated to the action (can be null, in which case the action will not be executed)
15 DataSourceItem *m_DataSourceItem;
16 };
17
18 DataSourceItemAction::DataSourceItemAction(const QString &name, ExecuteFunction fun)
19 : impl{spimpl::make_unique_impl<DataSourceItemActionPrivate>(name, std::move(fun))}
20 {
21 }
22
23 QString DataSourceItemAction::name() const noexcept
24 {
25 return impl->m_Name;
26 }
27
28 void DataSourceItemAction::setDataSourceItem(DataSourceItem *dataSourceItem) noexcept
29 {
30 impl->m_DataSourceItem = dataSourceItem;
31 }
32
33 void DataSourceItemAction::execute()
34 {
35 if (impl->m_DataSourceItem) {
36 impl->m_Fun(*impl->m_DataSourceItem);
37 }
38 else {
39 qCDebug(LOG_DataSourceItemAction())
40 << tr("Can't execute action : no item has been associated");
41 }
42 }
@@ -1,73 +1,79
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_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_DataSourceController)
10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
11
11
12 class DataSourceItem;
12 class DataSourceItem;
13 class IDataProvider;
13 class IDataProvider;
14
14
15 /**
15 /**
16 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
16 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
17 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
17 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
18 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
18 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
19 * source) then others specifics method will be able to access it. You can load a data source driver
19 * source) then others specifics method will be able to access it. You can load a data source driver
20 * plugin then create a data source.
20 * plugin then create a data source.
21 */
21 */
22 class DataSourceController : public QObject {
22 class DataSourceController : public QObject {
23 Q_OBJECT
23 Q_OBJECT
24 public:
24 public:
25 explicit DataSourceController(QObject *parent = 0);
25 explicit DataSourceController(QObject *parent = 0);
26 virtual ~DataSourceController();
26 virtual ~DataSourceController();
27
27
28 /**
28 /**
29 * Registers a data source. The method delivers a unique id that can be used afterwards to
29 * Registers a data source. The method delivers a unique id that can be used afterwards to
30 * access to the data source properties (structure, connection parameters, data provider, etc.)
30 * access to the data source properties (structure, connection parameters, data provider, etc.)
31 * @param dataSourceName the name of the data source
31 * @param dataSourceName the name of the data source
32 * @return the unique id with which the data source has been registered
32 * @return the unique id with which the data source has been registered
33 */
33 */
34 QUuid registerDataSource(const QString &dataSourceName) noexcept;
34 QUuid registerDataSource(const QString &dataSourceName) noexcept;
35
35
36 /**
36 /**
37 * Sets the structure of a data source. The controller takes ownership of the structure.
37 * Sets the structure of a data source. The controller takes ownership of the structure.
38 * @param dataSourceUid the unique id with which the data source has been registered into the
38 * @param dataSourceUid the unique id with which the data source has been registered into the
39 * controller. If it is invalid, the method has no effect.
39 * controller. If it is invalid, the method has no effect.
40 * @param dataSourceItem the structure of the data source
40 * @param dataSourceItem the structure of the data source
41 * @sa registerDataSource()
41 * @sa registerDataSource()
42 */
42 */
43 void setDataSourceItem(const QUuid &dataSourceUid,
43 void setDataSourceItem(const QUuid &dataSourceUid,
44 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
44 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
45
45
46 /**
46 /**
47 * Sets the data provider used to retrieve data from of a data source. The controller takes
47 * Sets the data provider used to retrieve data from of a data source. The controller takes
48 * ownership of the provider.
48 * ownership of the provider.
49 * @param dataSourceUid the unique id with which the data source has been registered into the
49 * @param dataSourceUid the unique id with which the data source has been registered into the
50 * controller. If it is invalid, the method has no effect.
50 * controller. If it is invalid, the method has no effect.
51 * @param dataProvider the provider of the data source
51 * @param dataProvider the provider of the data source
52 * @sa registerDataSource()
52 * @sa registerDataSource()
53 */
53 */
54 void setDataProvider(const QUuid &dataSourceUid,
54 void setDataProvider(const QUuid &dataSourceUid,
55 std::unique_ptr<IDataProvider> dataProvider) noexcept;
55 std::unique_ptr<IDataProvider> dataProvider) noexcept;
56
56
57 /**
58 * Loads an item (product) as a variable in SciQlop
59 * @param productItem the item to load
60 */
61 void loadProductItem(const DataSourceItem &productItem) noexcept;
62
57 public slots:
63 public slots:
58 /// Manage init/end of the controller
64 /// Manage init/end of the controller
59 void initialize();
65 void initialize();
60 void finalize();
66 void finalize();
61
67
62 signals:
68 signals:
63 /// Signal emitted when a structure has been set for a data source
69 /// Signal emitted when a structure has been set for a data source
64 void dataSourceItemSet(DataSourceItem *dataSourceItem);
70 void dataSourceItemSet(DataSourceItem *dataSourceItem);
65
71
66 private:
72 private:
67 void waitForFinish();
73 void waitForFinish();
68
74
69 class DataSourceControllerPrivate;
75 class DataSourceControllerPrivate;
70 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
76 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
71 };
77 };
72
78
73 #endif // SCIQLOP_DATASOURCECONTROLLER_H
79 #endif // SCIQLOP_DATASOURCECONTROLLER_H
@@ -1,59 +1,73
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;
10
9 /**
11 /**
10 * Possible types of an item
12 * Possible types of an item
11 */
13 */
12 enum class DataSourceItemType { NODE, PRODUCT };
14 enum class DataSourceItemType { NODE, PRODUCT };
13
15
14 /**
16 /**
15 * @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.
16 * 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)
17 * containing other DataSourceItem objects (children).
19 * containing other DataSourceItem objects (children).
18 * 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.
19 */
21 */
20 class DataSourceItem {
22 class DataSourceItem {
21 public:
23 public:
22 explicit DataSourceItem(DataSourceItemType type, QVector<QVariant> data = {});
24 explicit DataSourceItem(DataSourceItemType type, QVector<QVariant> data = {});
23
25
26 /// @return the actions of the item as a vector
27 QVector<DataSourceItemAction *> actions() const noexcept;
28
29 /**
30 * Adds an action to the item. The item takes ownership of the action, and the action is
31 * automatically associated to the item
32 * @param action the action to add
33 */
34 void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept;
35
24 /**
36 /**
25 * Adds a child to the item. The item takes ownership of the child.
37 * Adds a child to the item. The item takes ownership of the child.
26 * @param child the child to add
38 * @param child the child to add
27 */
39 */
28 void appendChild(std::unique_ptr<DataSourceItem> child) noexcept;
40 void appendChild(std::unique_ptr<DataSourceItem> child) noexcept;
29
41
30 /**
42 /**
31 * Returns the item's child associated to an index
43 * Returns the item's child associated to an index
32 * @param childIndex the index to search
44 * @param childIndex the index to search
33 * @return a pointer to the child if index is valid, nullptr otherwise
45 * @return a pointer to the child if index is valid, nullptr otherwise
34 */
46 */
35 DataSourceItem *child(int childIndex) const noexcept;
47 DataSourceItem *child(int childIndex) const noexcept;
36
48
37 int childCount() const noexcept;
49 int childCount() const noexcept;
38
50
39 /**
51 /**
40 * Get the data associated to an index
52 * Get the data associated to an index
41 * @param dataIndex the index to search
53 * @param dataIndex the index to search
42 * @return the data found if index is valid, default QVariant otherwise
54 * @return the data found if index is valid, default QVariant otherwise
43 */
55 */
44 QVariant data(int dataIndex) const noexcept;
56 QVariant data(int dataIndex) const noexcept;
45
57
58 QString name() const noexcept;
59
46 /**
60 /**
47 * Get the item's parent
61 * Get the item's parent
48 * @return a pointer to the parent if it exists, nullptr if the item is a root
62 * @return a pointer to the parent if it exists, nullptr if the item is a root
49 */
63 */
50 DataSourceItem *parentItem() const noexcept;
64 DataSourceItem *parentItem() const noexcept;
51
65
52 DataSourceItemType type() const noexcept;
66 DataSourceItemType type() const noexcept;
53
67
54 private:
68 private:
55 class DataSourceItemPrivate;
69 class DataSourceItemPrivate;
56 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
70 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
57 };
71 };
58
72
59 #endif // SCIQLOP_DATASOURCEITEMMODEL_H
73 #endif // SCIQLOP_DATASOURCEITEMMODEL_H
@@ -1,95 +1,100
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 <QDir>
9 #include <QDir>
10 #include <QStandardPaths>
10 #include <QStandardPaths>
11
11
12 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
12 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
13
13
14 class DataSourceController::DataSourceControllerPrivate {
14 class DataSourceController::DataSourceControllerPrivate {
15 public:
15 public:
16 QMutex m_WorkingMutex;
16 QMutex m_WorkingMutex;
17 /// Data sources registered
17 /// Data sources registered
18 QHash<QUuid, QString> m_DataSources;
18 QHash<QUuid, QString> m_DataSources;
19 /// Data sources structures
19 /// Data sources structures
20 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
20 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
21 /// Data providers registered
21 /// Data providers registered
22 std::map<QUuid, std::unique_ptr<IDataProvider> > m_DataProviders;
22 std::map<QUuid, std::unique_ptr<IDataProvider> > m_DataProviders;
23 };
23 };
24
24
25 DataSourceController::DataSourceController(QObject *parent)
25 DataSourceController::DataSourceController(QObject *parent)
26 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
26 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
27 {
27 {
28 qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction")
28 qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction")
29 << QThread::currentThread();
29 << QThread::currentThread();
30 }
30 }
31
31
32 DataSourceController::~DataSourceController()
32 DataSourceController::~DataSourceController()
33 {
33 {
34 qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction")
34 qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction")
35 << QThread::currentThread();
35 << QThread::currentThread();
36 this->waitForFinish();
36 this->waitForFinish();
37 }
37 }
38
38
39 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
39 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
40 {
40 {
41 auto dataSourceUid = QUuid::createUuid();
41 auto dataSourceUid = QUuid::createUuid();
42 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
42 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
43
43
44 return dataSourceUid;
44 return dataSourceUid;
45 }
45 }
46
46
47 void DataSourceController::setDataSourceItem(
47 void DataSourceController::setDataSourceItem(
48 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
48 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
49 {
49 {
50 if (impl->m_DataSources.contains(dataSourceUid)) {
50 if (impl->m_DataSources.contains(dataSourceUid)) {
51 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
51 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
52
52
53 // Retrieves the data source item to emit the signal with it
53 // Retrieves the data source item to emit the signal with it
54 auto it = impl->m_DataSourceItems.find(dataSourceUid);
54 auto it = impl->m_DataSourceItems.find(dataSourceUid);
55 if (it != impl->m_DataSourceItems.end()) {
55 if (it != impl->m_DataSourceItems.end()) {
56 emit dataSourceItemSet(it->second.get());
56 emit dataSourceItemSet(it->second.get());
57 }
57 }
58 }
58 }
59 else {
59 else {
60 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
60 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
61 "data source has been registered with the uid")
61 "data source has been registered with the uid")
62 .arg(dataSourceUid.toString());
62 .arg(dataSourceUid.toString());
63 }
63 }
64 }
64 }
65
65
66 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
66 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
67 std::unique_ptr<IDataProvider> dataProvider) noexcept
67 std::unique_ptr<IDataProvider> dataProvider) noexcept
68 {
68 {
69 if (impl->m_DataSources.contains(dataSourceUid)) {
69 if (impl->m_DataSources.contains(dataSourceUid)) {
70 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
70 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
71 }
71 }
72 else {
72 else {
73 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
73 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
74 "source has been registered with the uid")
74 "source has been registered with the uid")
75 .arg(dataSourceUid.toString());
75 .arg(dataSourceUid.toString());
76 }
76 }
77 }
77 }
78
78
79 void DataSourceController::loadProductItem(const DataSourceItem &productItem) noexcept
80 {
81 /// @todo ALX
82 }
83
79 void DataSourceController::initialize()
84 void DataSourceController::initialize()
80 {
85 {
81 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
86 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
82 << QThread::currentThread();
87 << QThread::currentThread();
83 impl->m_WorkingMutex.lock();
88 impl->m_WorkingMutex.lock();
84 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
89 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
85 }
90 }
86
91
87 void DataSourceController::finalize()
92 void DataSourceController::finalize()
88 {
93 {
89 impl->m_WorkingMutex.unlock();
94 impl->m_WorkingMutex.unlock();
90 }
95 }
91
96
92 void DataSourceController::waitForFinish()
97 void DataSourceController::waitForFinish()
93 {
98 {
94 QMutexLocker locker{&impl->m_WorkingMutex};
99 QMutexLocker locker{&impl->m_WorkingMutex};
95 }
100 }
@@ -1,56 +1,86
1 #include <DataSource/DataSourceItem.h>
1 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItemAction.h>
2
3
3 #include <QVector>
4 #include <QVector>
4
5
6 namespace {
7
8 /// Index of the 'name' value in the item
9 const auto NAME_INDEX = 0;
10
11 } // namespace
12
5 struct DataSourceItem::DataSourceItemPrivate {
13 struct DataSourceItem::DataSourceItemPrivate {
6 explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data)
14 explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data)
7 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}
15 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{}
8 {
16 {
9 }
17 }
10
18
11 DataSourceItem *m_Parent;
19 DataSourceItem *m_Parent;
12 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
20 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
13 DataSourceItemType m_Type;
21 DataSourceItemType m_Type;
14 QVector<QVariant> m_Data;
22 QVector<QVariant> m_Data;
23 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
15 };
24 };
16
25
17 DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
18 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
27 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
19 {
28 {
20 }
29 }
21
30
31 QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept
32 {
33 QVector<DataSourceItemAction *> result{};
34
35 std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions),
36 std::back_inserter(result), [](const auto &action) { return action.get(); });
37
38 return result;
39 }
40
41 void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept
42 {
43 action->setDataSourceItem(this);
44 impl->m_Actions.push_back(std::move(action));
45 }
46
22 void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
47 void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
23 {
48 {
24 child->impl->m_Parent = this;
49 child->impl->m_Parent = this;
25 impl->m_Children.push_back(std::move(child));
50 impl->m_Children.push_back(std::move(child));
26 }
51 }
27
52
28 DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
53 DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
29 {
54 {
30 if (childIndex < 0 || childIndex >= childCount()) {
55 if (childIndex < 0 || childIndex >= childCount()) {
31 return nullptr;
56 return nullptr;
32 }
57 }
33 else {
58 else {
34 return impl->m_Children.at(childIndex).get();
59 return impl->m_Children.at(childIndex).get();
35 }
60 }
36 }
61 }
37
62
38 int DataSourceItem::childCount() const noexcept
63 int DataSourceItem::childCount() const noexcept
39 {
64 {
40 return impl->m_Children.size();
65 return impl->m_Children.size();
41 }
66 }
42
67
43 QVariant DataSourceItem::data(int dataIndex) const noexcept
68 QVariant DataSourceItem::data(int dataIndex) const noexcept
44 {
69 {
45 return impl->m_Data.value(dataIndex);
70 return impl->m_Data.value(dataIndex);
46 }
71 }
47
72
73 QString DataSourceItem::name() const noexcept
74 {
75 return data(NAME_INDEX).toString();
76 }
77
48 DataSourceItem *DataSourceItem::parentItem() const noexcept
78 DataSourceItem *DataSourceItem::parentItem() const noexcept
49 {
79 {
50 return impl->m_Parent;
80 return impl->m_Parent;
51 }
81 }
52
82
53 DataSourceItemType DataSourceItem::type() const noexcept
83 DataSourceItemType DataSourceItem::type() const noexcept
54 {
84 {
55 return impl->m_Type;
85 return impl->m_Type;
56 }
86 }
@@ -1,10 +1,13
1 # On ignore toutes les règles vera++ pour le fichier spimpl
1 # On ignore toutes les règles vera++ pour le fichier spimpl
2 Common/spimpl\.h:\d+:.*
2 Common/spimpl\.h:\d+:.*
3
3
4 # Ignore false positive relative to two class definitions in a same file
4 # Ignore false positive relative to two class definitions in a same file
5 DataSourceItem\.h:\d+:.*IPSIS_S01.*
5 DataSourceItem\.h:\d+:.*IPSIS_S01.*
6
6
7 # Ignore false positive relative to a template class
7 # Ignore false positive relative to a template class
8 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D)
8 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D)
9 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D)
9 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D)
10 ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim)
10 ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim)
11
12 # Ignore false positive relative to an alias
13 DataSourceItemAction\.h:\d+:.*IPSIS_S06.*found: (ExecuteFunction)
@@ -1,32 +1,35
1 #ifndef SCIQLOP_DATASOURCETREEWIDGETITEM_H
1 #ifndef SCIQLOP_DATASOURCETREEWIDGETITEM_H
2 #define SCIQLOP_DATASOURCETREEWIDGETITEM_H
2 #define SCIQLOP_DATASOURCETREEWIDGETITEM_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QTreeWidgetItem>
7 #include <QTreeWidgetItem>
8
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem)
9 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem)
10
10
11 class DataSourceItem;
11 class DataSourceItem;
12
12
13 /**
13 /**
14 * @brief The DataSourceTreeWidgetItem is the graphical representation of a data source item. It is
14 * @brief The DataSourceTreeWidgetItem is the graphical representation of a data source item. It is
15 * intended to be displayed in a QTreeWidget.
15 * intended to be displayed in a QTreeWidget.
16 * @sa DataSourceItem
16 * @sa DataSourceItem
17 */
17 */
18 class DataSourceTreeWidgetItem : public QTreeWidgetItem {
18 class DataSourceTreeWidgetItem : public QTreeWidgetItem {
19 public:
19 public:
20 explicit DataSourceTreeWidgetItem(const DataSourceItem *data, int type = Type);
20 explicit DataSourceTreeWidgetItem(const DataSourceItem *data, int type = Type);
21 explicit DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
21 explicit DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
22 int type = Type);
22 int type = Type);
23
23
24 virtual QVariant data(int column, int role) const override;
24 virtual QVariant data(int column, int role) const override;
25 virtual void setData(int column, int role, const QVariant &value) override;
25 virtual void setData(int column, int role, const QVariant &value) override;
26
26
27 /// @return the actions associated to the item
28 QList<QAction *> actions() const noexcept;
29
27 private:
30 private:
28 class DataSourceTreeWidgetItemPrivate;
31 class DataSourceTreeWidgetItemPrivate;
29 spimpl::unique_impl_ptr<DataSourceTreeWidgetItemPrivate> impl;
32 spimpl::unique_impl_ptr<DataSourceTreeWidgetItemPrivate> impl;
30 };
33 };
31
34
32 #endif // SCIQLOP_DATASOURCETREEWIDGETITEM_H
35 #endif // SCIQLOP_DATASOURCETREEWIDGETITEM_H
@@ -1,34 +1,38
1 #ifndef SCIQLOP_DATASOURCEWIDGET_H
1 #ifndef SCIQLOP_DATASOURCEWIDGET_H
2 #define SCIQLOP_DATASOURCEWIDGET_H
2 #define SCIQLOP_DATASOURCEWIDGET_H
3
3
4 #include <QWidget>
4 #include <QWidget>
5
5
6 namespace Ui {
6 namespace Ui {
7 class DataSourceWidget;
7 class DataSourceWidget;
8 } // Ui
8 } // Ui
9
9
10 class DataSourceItem;
10 class DataSourceItem;
11
11
12 /**
12 /**
13 * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources
13 * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources
14 * attached to SciQlop.
14 * attached to SciQlop.
15 */
15 */
16 class DataSourceWidget : public QWidget {
16 class DataSourceWidget : public QWidget {
17 Q_OBJECT
17 Q_OBJECT
18
18
19 public:
19 public:
20 explicit DataSourceWidget(QWidget *parent = 0);
20 explicit DataSourceWidget(QWidget *parent = 0);
21
21
22 public slots:
22 public slots:
23 /**
23 /**
24 * Adds a data source. An item associated to the data source is created and then added to the
24 * Adds a data source. An item associated to the data source is created and then added to the
25 * representation tree
25 * representation tree
26 * @param dataSource the data source to add. The pointer has to be not null
26 * @param dataSource the data source to add. The pointer has to be not null
27 */
27 */
28 void addDataSource(DataSourceItem *dataSource) noexcept;
28 void addDataSource(DataSourceItem *dataSource) noexcept;
29
29
30 private:
30 private:
31 Ui::DataSourceWidget *ui;
31 Ui::DataSourceWidget *ui;
32
33 private slots:
34 /// Slot called when right clicking on an item in the tree (displays a menu)
35 void onTreeMenuRequested(const QPoint &pos) noexcept;
32 };
36 };
33
37
34 #endif // SCIQLOP_DATASOURCEWIDGET_H
38 #endif // SCIQLOP_DATASOURCEWIDGET_H
@@ -1,75 +1,101
1 #include <DataSource/DataSourceItem.h>
1 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItemAction.h>
2 #include <DataSource/DataSourceTreeWidgetItem.h>
3 #include <DataSource/DataSourceTreeWidgetItem.h>
3
4
4 #include <SqpApplication.h>
5 #include <SqpApplication.h>
5
6
7 #include <QAction>
8
6 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
9 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
7
10
8 namespace {
11 namespace {
9
12
10 QIcon itemIcon(const DataSourceItem *dataSource)
13 QIcon itemIcon(const DataSourceItem *dataSource)
11 {
14 {
12 if (dataSource) {
15 if (dataSource) {
13 auto dataSourceType = dataSource->type();
16 auto dataSourceType = dataSource->type();
14 switch (dataSourceType) {
17 switch (dataSourceType) {
15 case DataSourceItemType::NODE:
18 case DataSourceItemType::NODE:
16 return sqpApp->style()->standardIcon(QStyle::SP_DirIcon);
19 return sqpApp->style()->standardIcon(QStyle::SP_DirIcon);
17 case DataSourceItemType::PRODUCT:
20 case DataSourceItemType::PRODUCT:
18 return sqpApp->style()->standardIcon(QStyle::SP_FileIcon);
21 return sqpApp->style()->standardIcon(QStyle::SP_FileIcon);
19 default:
22 default:
20 // No action
23 // No action
21 break;
24 break;
22 }
25 }
23
26
24 qCWarning(LOG_DataSourceTreeWidgetItem())
27 qCWarning(LOG_DataSourceTreeWidgetItem())
25 << QObject::tr("Can't set data source icon : unknown data source type");
28 << QObject::tr("Can't set data source icon : unknown data source type");
26 }
29 }
27 else {
30 else {
28 qCWarning(LOG_DataSourceTreeWidgetItem())
31 qCWarning(LOG_DataSourceTreeWidgetItem())
29 << QObject::tr("Can't set data source icon : the data source is null");
32 << QObject::tr("Can't set data source icon : the data source is null");
30 }
33 }
31
34
32 // Default cases
35 // Default cases
33 return QIcon{};
36 return QIcon{};
34 }
37 }
35
38
36 } // namespace
39 } // namespace
37
40
38 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
41 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
39 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
42 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
40
43
41 /// Model used to retrieve data source information
44 /// Model used to retrieve data source information
42 const DataSourceItem *m_Data;
45 const DataSourceItem *m_Data;
46 /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of
47 /// the actions
48 QList<QAction *> m_Actions;
43 };
49 };
44
50
45 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
51 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
46 : DataSourceTreeWidgetItem{nullptr, data, type}
52 : DataSourceTreeWidgetItem{nullptr, data, type}
47 {
53 {
48 }
54 }
49
55
50 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
56 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
51 int type)
57 int type)
52 : QTreeWidgetItem{parent, type},
58 : QTreeWidgetItem{parent, type},
53 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
59 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
54 {
60 {
55 // Sets the icon depending on the data source
61 // Sets the icon depending on the data source
56 setIcon(0, itemIcon(impl->m_Data));
62 setIcon(0, itemIcon(impl->m_Data));
63
64 // Generates tree actions based on the item actions
65 auto createTreeAction = [this, &parent](const auto &itemAction) {
66 auto treeAction = new QAction{itemAction->name(), parent};
67
68 // Executes item action when tree action is triggered
69 QObject::connect(treeAction, &QAction::triggered, itemAction,
70 &DataSourceItemAction::execute);
71
72 return treeAction;
73 };
74
75 auto itemActions = impl->m_Data->actions();
76 std::transform(std::cbegin(itemActions), std::cend(itemActions),
77 std::back_inserter(impl->m_Actions), createTreeAction);
57 }
78 }
58
79
59 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
80 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
60 {
81 {
61 if (role == Qt::DisplayRole) {
82 if (role == Qt::DisplayRole) {
62 return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{};
83 return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{};
63 }
84 }
64 else {
85 else {
65 return QTreeWidgetItem::data(column, role);
86 return QTreeWidgetItem::data(column, role);
66 }
87 }
67 }
88 }
68
89
69 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
90 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
70 {
91 {
71 // Data can't be changed by edition
92 // Data can't be changed by edition
72 if (role != Qt::EditRole) {
93 if (role != Qt::EditRole) {
73 QTreeWidgetItem::setData(column, role, value);
94 QTreeWidgetItem::setData(column, role, value);
74 }
95 }
75 }
96 }
97
98 QList<QAction *> DataSourceTreeWidgetItem::actions() const noexcept
99 {
100 return impl->m_Actions;
101 }
@@ -1,52 +1,72
1 #include <DataSource/DataSourceWidget.h>
1 #include <DataSource/DataSourceWidget.h>
2
2
3 #include <ui_DataSourceWidget.h>
3 #include <ui_DataSourceWidget.h>
4
4
5 #include <DataSource/DataSourceItem.h>
5 #include <DataSource/DataSourceItem.h>
6 #include <DataSource/DataSourceTreeWidgetItem.h>
6 #include <DataSource/DataSourceTreeWidgetItem.h>
7
7
8 #include <QMenu>
9
8 namespace {
10 namespace {
9
11
10 /// Number of columns displayed in the tree
12 /// Number of columns displayed in the tree
11 const auto TREE_NB_COLUMNS = 1;
13 const auto TREE_NB_COLUMNS = 1;
12
14
13 /// Header labels for the tree
15 /// Header labels for the tree
14 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
16 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
15
17
16 /**
18 /**
17 * Creates the item associated to a data source
19 * Creates the item associated to a data source
18 * @param dataSource the data source for which to create the item
20 * @param dataSource the data source for which to create the item
19 * @return the new item
21 * @return the new item
20 */
22 */
21 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
23 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
22 {
24 {
23 // Creates item for the data source
25 // Creates item for the data source
24 auto item = new DataSourceTreeWidgetItem{dataSource};
26 auto item = new DataSourceTreeWidgetItem{dataSource};
25
27
26 // Generates items for the children of the data source
28 // Generates items for the children of the data source
27 for (auto i = 0; i < dataSource->childCount(); ++i) {
29 for (auto i = 0; i < dataSource->childCount(); ++i) {
28 item->addChild(createTreeWidgetItem(dataSource->child(i)));
30 item->addChild(createTreeWidgetItem(dataSource->child(i)));
29 }
31 }
30
32
31 return item;
33 return item;
32 }
34 }
33
35
34 } // namespace
36 } // namespace
35
37
36 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget}
38 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget}
37 {
39 {
38 ui->setupUi(this);
40 ui->setupUi(this);
39
41
40 // Set tree properties
42 // Set tree properties
41 ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
43 ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
42 ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
44 ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
45 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
46
47 // Connection to show a menu when right clicking on the tree
48 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
49 &DataSourceWidget::onTreeMenuRequested);
43 }
50 }
44
51
45 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept
52 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept
46 {
53 {
47 // Creates the item associated to the source and adds it to the tree widget. The tree widget
54 // Creates the item associated to the source and adds it to the tree widget. The tree widget
48 // takes the ownership of the item
55 // takes the ownership of the item
49 if (dataSource) {
56 if (dataSource) {
50 ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource));
57 ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource));
51 }
58 }
52 }
59 }
60
61 void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept
62 {
63 // Retrieves the selected item in the tree, and build the menu from its actions
64 if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem *>(ui->treeWidget->itemAt(pos))) {
65 QMenu treeMenu{};
66 treeMenu.addActions(selectedItem->actions());
67
68 if (!treeMenu.isEmpty()) {
69 treeMenu.exec(mapToGlobal(pos));
70 }
71 }
72 }
@@ -1,67 +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
7
7 #include <SqpApplication.h>
8 #include <SqpApplication.h>
8
9
9 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
10 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
10
11
11 namespace {
12 namespace {
12
13
13 /// Name of the data source
14 /// Name of the data source
14 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
15 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
15
16
16 /// Creates the data provider relative to the plugin
17 /// Creates the data provider relative to the plugin
17 std::unique_ptr<IDataProvider> createDataProvider() noexcept
18 std::unique_ptr<IDataProvider> createDataProvider() noexcept
18 {
19 {
19 return std::make_unique<CosinusProvider>();
20 return std::make_unique<CosinusProvider>();
20 }
21 }
21
22
23 std::unique_ptr<DataSourceItem> createProductItem(const QString &productName)
24 {
25 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
26 QVector<QVariant>{productName});
27
28 // Add action to load product from DataSourceController
29 result->addAction(std::make_unique<DataSourceItemAction>(
30 QObject::tr("Load %1 product").arg(productName), [productName](DataSourceItem &item) {
31 if (auto app = sqpApp) {
32 app->dataSourceController().loadProductItem(item);
33 }
34 }));
35
36 return result;
37 }
38
22 /// Creates the data source item relative to the plugin
39 /// Creates the data source item relative to the plugin
23 std::unique_ptr<DataSourceItem> createDataSourceItem() noexcept
40 std::unique_ptr<DataSourceItem> createDataSourceItem() noexcept
24 {
41 {
25 // Magnetic field products
42 // Magnetic field products
26 auto fgmProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
27 QVector<QVariant>{QStringLiteral("FGM")});
28 auto scProduct = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
29 QVector<QVariant>{QStringLiteral("SC")});
30
31 auto magneticFieldFolder = std::make_unique<DataSourceItem>(
43 auto magneticFieldFolder = std::make_unique<DataSourceItem>(
32 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")});
44 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")});
33 magneticFieldFolder->appendChild(std::move(fgmProduct));
45 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM")));
34 magneticFieldFolder->appendChild(std::move(scProduct));
46 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC")));
35
47
36 // Electric field products
48 // Electric field products
37 auto electricFieldFolder = std::make_unique<DataSourceItem>(
49 auto electricFieldFolder = std::make_unique<DataSourceItem>(
38 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")});
50 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")});
39
51
40 // Root
52 // Root
41 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
53 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
42 QVector<QVariant>{DATA_SOURCE_NAME});
54 QVector<QVariant>{DATA_SOURCE_NAME});
43 root->appendChild(std::move(magneticFieldFolder));
55 root->appendChild(std::move(magneticFieldFolder));
44 root->appendChild(std::move(electricFieldFolder));
56 root->appendChild(std::move(electricFieldFolder));
45
57
46 return root;
58 return root;
47 }
59 }
48
60
49 } // namespace
61 } // namespace
50
62
51 void MockPlugin::initialize()
63 void MockPlugin::initialize()
52 {
64 {
53 if (auto app = sqpApp) {
65 if (auto app = sqpApp) {
54 // Registers to the data source controller
66 // Registers to the data source controller
55 auto &dataSourceController = app->dataSourceController();
67 auto &dataSourceController = app->dataSourceController();
56 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
68 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
57
69
58 // Sets data source tree
70 // Sets data source tree
59 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem());
71 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem());
60
72
61 // Sets data provider
73 // Sets data provider
62 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
74 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
63 }
75 }
64 else {
76 else {
65 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
77 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
66 }
78 }
67 }
79 }
General Comments 0
You need to be logged in to leave comments. Login now