@@ -30,9 +30,7 void TestDataSourceController::testSetDataSourceItem() | |||||
30 |
|
30 | |||
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 source1Item = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, source1Name); | |
34 | auto source1Item |
|
|||
35 | = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, std::move(source1Values)); |
|
|||
36 |
|
34 | |||
37 | // Add data source item to the controller and check that a signal has been emitted after setting |
|
35 | // Add data source item to the controller and check that a signal has been emitted after setting | |
38 | // data source item in the controller |
|
36 | // data source item in the controller |
@@ -10,6 +10,9 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem") | |||||
10 |
|
10 | |||
11 | namespace { |
|
11 | namespace { | |
12 |
|
12 | |||
|
13 | // Column indexes | |||
|
14 | const auto NAME_COLUMN = 0; | |||
|
15 | ||||
13 | QIcon itemIcon(const DataSourceItem *dataSource) |
|
16 | QIcon itemIcon(const DataSourceItem *dataSource) | |
14 | { |
|
17 | { | |
15 | if (dataSource) { |
|
18 | if (dataSource) { | |
@@ -80,7 +83,23 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const Da | |||||
80 | QVariant DataSourceTreeWidgetItem::data(int column, int role) const |
|
83 | QVariant DataSourceTreeWidgetItem::data(int column, int role) const | |
81 | { |
|
84 | { | |
82 | if (role == Qt::DisplayRole) { |
|
85 | if (role == Qt::DisplayRole) { | |
83 | return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{}; |
|
86 | if (impl->m_Data) { | |
|
87 | switch (column) { | |||
|
88 | case NAME_COLUMN: | |||
|
89 | return impl->m_Data->name(); | |||
|
90 | default: | |||
|
91 | // No action | |||
|
92 | break; | |||
|
93 | } | |||
|
94 | ||||
|
95 | qCWarning(LOG_DataSourceTreeWidgetItem()) | |||
|
96 | << QObject::tr("Can't get data (unknown column %1)").arg(column); | |||
|
97 | } | |||
|
98 | else { | |||
|
99 | qCCritical(LOG_DataSourceTreeWidgetItem()) << QObject::tr("Can't get data (null item)"); | |||
|
100 | } | |||
|
101 | ||||
|
102 | return QVariant{}; | |||
84 | } |
|
103 | } | |
85 | else { |
|
104 | else { | |
86 | return QTreeWidgetItem::data(column, role); |
|
105 | return QTreeWidgetItem::data(column, role); |
@@ -23,8 +23,7 std::unique_ptr<IDataProvider> createDataProvider() noexcept | |||||
23 | std::unique_ptr<DataSourceItem> createProductItem(const QString &productName, |
|
23 | std::unique_ptr<DataSourceItem> createProductItem(const QString &productName, | |
24 | const QUuid &dataSourceUid) |
|
24 | const QUuid &dataSourceUid) | |
25 | { |
|
25 | { | |
26 | auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, |
|
26 | auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, productName); | |
27 | QVector<QVariant>{productName}); |
|
|||
28 |
|
27 | |||
29 | // Add action to load product from DataSourceController |
|
28 | // Add action to load product from DataSourceController | |
30 | result->addAction(std::make_unique<DataSourceItemAction>( |
|
29 | result->addAction(std::make_unique<DataSourceItemAction>( | |
@@ -42,18 +41,17 std::unique_ptr<DataSourceItem> createProductItem(const QString &productName, | |||||
42 | std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept |
|
41 | std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept | |
43 | { |
|
42 | { | |
44 | // Magnetic field products |
|
43 | // Magnetic field products | |
45 | auto magneticFieldFolder = std::make_unique<DataSourceItem>( |
|
44 | auto magneticFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, | |
46 | DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")}); |
|
45 | QStringLiteral("Magnetic field")); | |
47 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM"), dataSourceUid)); |
|
46 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM"), dataSourceUid)); | |
48 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC"), dataSourceUid)); |
|
47 | magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC"), dataSourceUid)); | |
49 |
|
48 | |||
50 | // Electric field products |
|
49 | // Electric field products | |
51 | auto electricFieldFolder = std::make_unique<DataSourceItem>( |
|
50 | auto electricFieldFolder = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, | |
52 | DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")}); |
|
51 | QStringLiteral("Electric field")); | |
53 |
|
52 | |||
54 | // Root |
|
53 | // Root | |
55 | auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, |
|
54 | auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE, DATA_SOURCE_NAME); | |
56 | QVector<QVariant>{DATA_SOURCE_NAME}); |
|
|||
57 | root->appendChild(std::move(magneticFieldFolder)); |
|
55 | root->appendChild(std::move(magneticFieldFolder)); | |
58 | root->appendChild(std::move(electricFieldFolder)); |
|
56 | root->appendChild(std::move(electricFieldFolder)); | |
59 |
|
57 |
General Comments 0
You need to be logged in to leave comments.
Login now