@@ -21,7 +21,11 enum class DataSourceItemType { NODE, PRODUCT }; | |||||
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; | |
@@ -49,11 +53,11 public: | |||||
49 | int childCount() const noexcept; |
|
53 | int childCount() const noexcept; | |
50 |
|
54 | |||
51 | /** |
|
55 | /** | |
52 |
* Get the data associated to a |
|
56 | * Get the data associated to a key | |
53 |
* @param |
|
57 | * @param key the key to search | |
54 |
* @return the data found if |
|
58 | * @return the data found if key is valid, default QVariant otherwise | |
55 | */ |
|
59 | */ | |
56 |
QVariant data( |
|
60 | QVariant data(const QString &key) const noexcept; | |
57 |
|
61 | |||
58 | QString name() const noexcept; |
|
62 | QString name() const noexcept; | |
59 |
|
63 |
@@ -3,15 +3,10 | |||||
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, Q |
|
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 | } | |
@@ -19,11 +14,16 struct DataSourceItem::DataSourceItemPrivate { | |||||
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 |
Q |
|
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, |
|
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 | } | |
@@ -65,14 +65,14 int DataSourceItem::childCount() const noexcept | |||||
65 | return impl->m_Children.size(); |
|
65 | return impl->m_Children.size(); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 |
QVariant DataSourceItem::data( |
|
68 | QVariant DataSourceItem::data(const QString &key) const noexcept | |
69 | { |
|
69 | { | |
70 |
return impl->m_Data.value( |
|
70 | return impl->m_Data.value(key); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | QString DataSourceItem::name() const noexcept |
|
73 | QString DataSourceItem::name() const noexcept | |
74 | { |
|
74 | { | |
75 |
return data(NAME_ |
|
75 | return data(NAME_DATA_KEY).toString(); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | DataSourceItem *DataSourceItem::parentItem() const noexcept |
|
78 | DataSourceItem *DataSourceItem::parentItem() const noexcept |
General Comments 0
You need to be logged in to leave comments.
Login now