##// END OF EJS Templates
Changes structure of data hold by the item...
Alexandre Leroux -
r342:2fbf66a7ca8a
parent child
Show More
@@ -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 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;
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, 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 }
@@ -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 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 }
@@ -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(int dataIndex) const noexcept
68 QVariant DataSourceItem::data(const QString &key) const noexcept
69 {
69 {
70 return impl->m_Data.value(dataIndex);
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_INDEX).toString();
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