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,77 +1,77 | |||||
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 | /// Key associated with the name of the item |
|
24 | /// Key associated with the name of the item | |
25 | static const QString NAME_DATA_KEY; |
|
25 | static const QString NAME_DATA_KEY; | |
26 |
|
26 | |||
27 | explicit DataSourceItem(DataSourceItemType type, const QString &name); |
|
27 | explicit DataSourceItem(DataSourceItemType type, const QString &name); | |
28 | explicit DataSourceItem(DataSourceItemType type, QHash<QString, QVariant> data = {}); |
|
28 | explicit DataSourceItem(DataSourceItemType type, QHash<QString, QVariant> data = {}); | |
29 |
|
29 | |||
30 | /// @return the actions of the item as a vector |
|
30 | /// @return the actions of the item as a vector | |
31 | QVector<DataSourceItemAction *> actions() const noexcept; |
|
31 | QVector<DataSourceItemAction *> actions() const noexcept; | |
32 |
|
32 | |||
33 | /** |
|
33 | /** | |
34 | * 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 | |
35 | * automatically associated to the item |
|
35 | * automatically associated to the item | |
36 | * @param action the action to add |
|
36 | * @param action the action to add | |
37 | */ |
|
37 | */ | |
38 | void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept; |
|
38 | void addAction(std::unique_ptr<DataSourceItemAction> action) noexcept; | |
39 |
|
39 | |||
40 | /** |
|
40 | /** | |
41 | * 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. | |
42 | * @param child the child to add |
|
42 | * @param child the child to add | |
43 | */ |
|
43 | */ | |
44 | void appendChild(std::unique_ptr<DataSourceItem> child) noexcept; |
|
44 | void appendChild(std::unique_ptr<DataSourceItem> child) noexcept; | |
45 |
|
45 | |||
46 | /** |
|
46 | /** | |
47 | * Returns the item's child associated to an index |
|
47 | * Returns the item's child associated to an index | |
48 | * @param childIndex the index to search |
|
48 | * @param childIndex the index to search | |
49 | * @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 | |
50 | */ |
|
50 | */ | |
51 | DataSourceItem *child(int childIndex) const noexcept; |
|
51 | DataSourceItem *child(int childIndex) const noexcept; | |
52 |
|
52 | |||
53 | int childCount() const noexcept; |
|
53 | int childCount() const noexcept; | |
54 |
|
54 | |||
55 | /** |
|
55 | /** | |
56 | * Get the data associated to a key |
|
56 | * Get the data associated to a key | |
57 | * @param key the key to search |
|
57 | * @param key the key to search | |
58 | * @return the data found if key is valid, default QVariant otherwise |
|
58 | * @return the data found if key is valid, default QVariant otherwise | |
59 | */ |
|
59 | */ | |
60 | QVariant data(const QString &key) const noexcept; |
|
60 | QVariant data(const QString &key) const noexcept; | |
61 |
|
61 | |||
62 | QString name() const noexcept; |
|
62 | QString name() const noexcept; | |
63 |
|
63 | |||
64 | /** |
|
64 | /** | |
65 | * Get the item's parent |
|
65 | * Get the item's parent | |
66 | * @return a pointer to the parent if it exists, nullptr if the item is a root |
|
66 | * @return a pointer to the parent if it exists, nullptr if the item is a root | |
67 | */ |
|
67 | */ | |
68 | DataSourceItem *parentItem() const noexcept; |
|
68 | DataSourceItem *parentItem() const noexcept; | |
69 |
|
69 | |||
70 | DataSourceItemType type() const noexcept; |
|
70 | DataSourceItemType type() const noexcept; | |
71 |
|
71 | |||
72 | private: |
|
72 | private: | |
73 | class DataSourceItemPrivate; |
|
73 | class DataSourceItemPrivate; | |
74 | spimpl::unique_impl_ptr<DataSourceItemPrivate> impl; |
|
74 | spimpl::unique_impl_ptr<DataSourceItemPrivate> impl; | |
75 | }; |
|
75 | }; | |
76 |
|
76 | |||
77 | #endif // SCIQLOP_DATASOURCEITEMMODEL_H |
|
77 | #endif // SCIQLOP_DATASOURCEITEMMODEL_H |
@@ -1,10 +1,13 | |||||
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> | |||
3 | <file>icones/delete.png</file> |
|
6 | <file>icones/delete.png</file> | |
4 | <file>icones/openInspector.png</file> |
|
7 | <file>icones/openInspector.png</file> | |
5 | <file>icones/next.png</file> |
|
8 | <file>icones/next.png</file> | |
6 | <file>icones/plot.png</file> |
|
9 | <file>icones/plot.png</file> | |
7 | <file>icones/previous.png</file> |
|
10 | <file>icones/previous.png</file> | |
8 | <file>icones/unplot.png</file> |
|
11 | <file>icones/unplot.png</file> | |
9 | </qresource> |
|
12 | </qresource> | |
10 | </RCC> |
|
13 | </RCC> |
@@ -1,120 +1,120 | |||||
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 | |||
13 | // Column indexes |
|
11 | // Column indexes | |
14 | const auto NAME_COLUMN = 0; |
|
12 | const auto NAME_COLUMN = 0; | |
15 |
|
13 | |||
16 | QIcon itemIcon(const DataSourceItem *dataSource) |
|
14 | QIcon itemIcon(const DataSourceItem *dataSource) | |
17 | { |
|
15 | { | |
18 | if (dataSource) { |
|
16 | if (dataSource) { | |
19 | auto dataSourceType = dataSource->type(); |
|
17 | auto dataSourceType = dataSource->type(); | |
20 | switch (dataSourceType) { |
|
18 | switch (dataSourceType) { | |
21 | case DataSourceItemType::NODE: |
|
19 | case DataSourceItemType::NODE: | |
22 | return sqpApp->style()->standardIcon(QStyle::SP_DirIcon); |
|
20 | return QIcon{":/icones/dataSourceNode.png"}; | |
23 | case DataSourceItemType::PRODUCT: |
|
21 | case DataSourceItemType::PRODUCT: | |
24 | return sqpApp->style()->standardIcon(QStyle::SP_FileIcon); |
|
22 | return QIcon{":/icones/dataSourceProduct.png"}; | |
|
23 | case DataSourceItemType::COMPONENT: | |||
|
24 | return QIcon{":/icones/dataSourceComponent.png"}; | |||
25 | default: |
|
25 | default: | |
26 | // No action |
|
26 | // No action | |
27 | break; |
|
27 | break; | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | qCWarning(LOG_DataSourceTreeWidgetItem()) |
|
30 | qCWarning(LOG_DataSourceTreeWidgetItem()) | |
31 | << QObject::tr("Can't set data source icon : unknown data source type"); |
|
31 | << QObject::tr("Can't set data source icon : unknown data source type"); | |
32 | } |
|
32 | } | |
33 | else { |
|
33 | else { | |
34 | qCWarning(LOG_DataSourceTreeWidgetItem()) |
|
34 | qCWarning(LOG_DataSourceTreeWidgetItem()) | |
35 | << QObject::tr("Can't set data source icon : the data source is null"); |
|
35 | << QObject::tr("Can't set data source icon : the data source is null"); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | // Default cases |
|
38 | // Default cases | |
39 | return QIcon{}; |
|
39 | return QIcon{}; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | } // namespace |
|
42 | } // namespace | |
43 |
|
43 | |||
44 | struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate { |
|
44 | struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate { | |
45 | explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {} |
|
45 | explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {} | |
46 |
|
46 | |||
47 | /// Model used to retrieve data source information |
|
47 | /// Model used to retrieve data source information | |
48 | const DataSourceItem *m_Data; |
|
48 | const DataSourceItem *m_Data; | |
49 | /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of |
|
49 | /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of | |
50 | /// the actions |
|
50 | /// the actions | |
51 | QList<QAction *> m_Actions; |
|
51 | QList<QAction *> m_Actions; | |
52 | }; |
|
52 | }; | |
53 |
|
53 | |||
54 | DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type) |
|
54 | DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type) | |
55 | : DataSourceTreeWidgetItem{nullptr, data, type} |
|
55 | : DataSourceTreeWidgetItem{nullptr, data, type} | |
56 | { |
|
56 | { | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data, |
|
59 | DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data, | |
60 | int type) |
|
60 | int type) | |
61 | : QTreeWidgetItem{parent, type}, |
|
61 | : QTreeWidgetItem{parent, type}, | |
62 | impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)} |
|
62 | impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)} | |
63 | { |
|
63 | { | |
64 | // Sets the icon depending on the data source |
|
64 | // Sets the icon depending on the data source | |
65 | setIcon(0, itemIcon(impl->m_Data)); |
|
65 | setIcon(0, itemIcon(impl->m_Data)); | |
66 |
|
66 | |||
67 | // Generates tree actions based on the item actions |
|
67 | // Generates tree actions based on the item actions | |
68 | auto createTreeAction = [this, &parent](const auto &itemAction) { |
|
68 | auto createTreeAction = [this, &parent](const auto &itemAction) { | |
69 | auto treeAction = new QAction{itemAction->name(), parent}; |
|
69 | auto treeAction = new QAction{itemAction->name(), parent}; | |
70 |
|
70 | |||
71 | // Executes item action when tree action is triggered |
|
71 | // Executes item action when tree action is triggered | |
72 | QObject::connect(treeAction, &QAction::triggered, itemAction, |
|
72 | QObject::connect(treeAction, &QAction::triggered, itemAction, | |
73 | &DataSourceItemAction::execute); |
|
73 | &DataSourceItemAction::execute); | |
74 |
|
74 | |||
75 | return treeAction; |
|
75 | return treeAction; | |
76 | }; |
|
76 | }; | |
77 |
|
77 | |||
78 | auto itemActions = impl->m_Data->actions(); |
|
78 | auto itemActions = impl->m_Data->actions(); | |
79 | std::transform(std::cbegin(itemActions), std::cend(itemActions), |
|
79 | std::transform(std::cbegin(itemActions), std::cend(itemActions), | |
80 | std::back_inserter(impl->m_Actions), createTreeAction); |
|
80 | std::back_inserter(impl->m_Actions), createTreeAction); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | QVariant DataSourceTreeWidgetItem::data(int column, int role) const |
|
83 | QVariant DataSourceTreeWidgetItem::data(int column, int role) const | |
84 | { |
|
84 | { | |
85 | if (role == Qt::DisplayRole) { |
|
85 | if (role == Qt::DisplayRole) { | |
86 | if (impl->m_Data) { |
|
86 | if (impl->m_Data) { | |
87 | switch (column) { |
|
87 | switch (column) { | |
88 | case NAME_COLUMN: |
|
88 | case NAME_COLUMN: | |
89 | return impl->m_Data->name(); |
|
89 | return impl->m_Data->name(); | |
90 | default: |
|
90 | default: | |
91 | // No action |
|
91 | // No action | |
92 | break; |
|
92 | break; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | qCWarning(LOG_DataSourceTreeWidgetItem()) |
|
95 | qCWarning(LOG_DataSourceTreeWidgetItem()) | |
96 | << QObject::tr("Can't get data (unknown column %1)").arg(column); |
|
96 | << QObject::tr("Can't get data (unknown column %1)").arg(column); | |
97 | } |
|
97 | } | |
98 | else { |
|
98 | else { | |
99 | qCCritical(LOG_DataSourceTreeWidgetItem()) << QObject::tr("Can't get data (null item)"); |
|
99 | qCCritical(LOG_DataSourceTreeWidgetItem()) << QObject::tr("Can't get data (null item)"); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | return QVariant{}; |
|
102 | return QVariant{}; | |
103 | } |
|
103 | } | |
104 | else { |
|
104 | else { | |
105 | return QTreeWidgetItem::data(column, role); |
|
105 | return QTreeWidgetItem::data(column, role); | |
106 | } |
|
106 | } | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value) |
|
109 | void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value) | |
110 | { |
|
110 | { | |
111 | // Data can't be changed by edition |
|
111 | // Data can't be changed by edition | |
112 | if (role != Qt::EditRole) { |
|
112 | if (role != Qt::EditRole) { | |
113 | QTreeWidgetItem::setData(column, role, value); |
|
113 | QTreeWidgetItem::setData(column, role, value); | |
114 | } |
|
114 | } | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | QList<QAction *> DataSourceTreeWidgetItem::actions() const noexcept |
|
117 | QList<QAction *> DataSourceTreeWidgetItem::actions() const noexcept | |
118 | { |
|
118 | { | |
119 | return impl->m_Actions; |
|
119 | return impl->m_Actions; | |
120 | } |
|
120 | } |
General Comments 0
You need to be logged in to leave comments.
Login now