##// END OF EJS Templates
Adds type for a data source item...
Alexandre Leroux -
r79:0afc39d45cc4
parent child
Show More
@@ -7,6 +7,11
7 #include <QVector>
7 #include <QVector>
8
8
9 /**
9 /**
10 * Possible types of an item
11 */
12 enum class DataSourceItemType { NODE, PRODUCT };
13
14 /**
10 * @brief The DataSourceItem class aims to represent a structure element of a data source.
15 * @brief The DataSourceItem class aims to represent a structure element of a data source.
11 * A data source has a tree structure that is made up of a main DataSourceItem object (root)
16 * A data source has a tree structure that is made up of a main DataSourceItem object (root)
12 * containing other DataSourceItem objects (children).
17 * containing other DataSourceItem objects (children).
@@ -14,7 +19,7
14 */
19 */
15 class DataSourceItem {
20 class DataSourceItem {
16 public:
21 public:
17 explicit DataSourceItem(QVector<QVariant> data = {});
22 explicit DataSourceItem(DataSourceItemType type, QVector<QVariant> data = {});
18
23
19 /**
24 /**
20 * Adds a child to the item. The item takes ownership of the child.
25 * Adds a child to the item. The item takes ownership of the child.
@@ -44,6 +49,8 public:
44 */
49 */
45 DataSourceItem *parentItem() const noexcept;
50 DataSourceItem *parentItem() const noexcept;
46
51
52 DataSourceItemType type() const noexcept;
53
47 private:
54 private:
48 class DataSourceItemPrivate;
55 class DataSourceItemPrivate;
49 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
56 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
@@ -3,18 +3,19
3 #include <QVector>
3 #include <QVector>
4
4
5 struct DataSourceItem::DataSourceItemPrivate {
5 struct DataSourceItem::DataSourceItemPrivate {
6 explicit DataSourceItemPrivate(QVector<QVariant> data)
6 explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data)
7 : m_Parent{nullptr}, m_Children{}, m_Data{std::move(data)}
7 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}
8 {
8 {
9 }
9 }
10
10
11 DataSourceItem *m_Parent;
11 DataSourceItem *m_Parent;
12 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
12 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
13 DataSourceItemType m_Type;
13 QVector<QVariant> m_Data;
14 QVector<QVariant> m_Data;
14 };
15 };
15
16
16 DataSourceItem::DataSourceItem(QVector<QVariant> data)
17 DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
17 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(data)}
18 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
18 {
19 {
19 }
20 }
20
21
@@ -48,3 +49,8 DataSourceItem *DataSourceItem::parentItem() const noexcept
48 {
49 {
49 return impl->m_Parent;
50 return impl->m_Parent;
50 }
51 }
52
53 DataSourceItemType DataSourceItem::type() const noexcept
54 {
55 return impl->m_Type;
56 }
@@ -31,7 +31,8 void TestDataSourceController::testSetDataSourceItem()
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 source1Values = QVector<QVariant>{source1Name};
34 auto source1Item = std::make_unique<DataSourceItem>(std::move(source1Values));
34 auto source1Item
35 = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, std::move(source1Values));
35
36
36 // Add data source item to the controller and check that a signal has been emitted after setting
37 // Add data source item to the controller and check that a signal has been emitted after setting
37 // data source item in the controller
38 // data source item in the controller
@@ -41,7 +42,8 void TestDataSourceController::testSetDataSourceItem()
41
42
42 // Try to a data source item with an unregistered uid and check that no signal has been emitted
43 // Try to a data source item with an unregistered uid and check that no signal has been emitted
43 auto unregisteredUid = QUuid::createUuid();
44 auto unregisteredUid = QUuid::createUuid();
44 dataSourceController.setDataSourceItem(unregisteredUid, std::make_unique<DataSourceItem>());
45 dataSourceController.setDataSourceItem(
46 unregisteredUid, std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT));
45 QCOMPARE(signalSpy.count(), 1);
47 QCOMPARE(signalSpy.count(), 1);
46 }
48 }
47
49
General Comments 0
You need to be logged in to leave comments. Login now