##// END OF EJS Templates
Inits merge method of two items
Alexandre Leroux -
r1031:b92faa6e4b21
parent child
Show More
@@ -0,0 +1,15
1 #ifndef SCIQLOP_DATASOURCEITEMMERGEHELPER_H
2 #define SCIQLOP_DATASOURCEITEMMERGEHELPER_H
3
4 class DataSourceItem;
5
6 /**
7 * @brief The DataSourceItemMergeHelper struct is used to merge two data source items
8 * @sa DataSourceItem::merge()
9 */
10 struct DataSourceItemMergeHelper {
11 /// Merges source item into dest item
12 static void merge(const DataSourceItem &source, DataSourceItem &dest);
13 };
14
15 #endif // SCIQLOP_DATASOURCEITEMMERGEHELPER_H
@@ -0,0 +1,8
1 #include "DataSource/DataSourceItemMergeHelper.h"
2
3 #include <DataSource/DataSourceItem.h>
4
5 void DataSourceItemMergeHelper::merge(const DataSourceItem &source, DataSourceItem &dest)
6 {
7 /// @todo ALX
8 }
@@ -64,6 +64,46 public:
64 /// Gets all data
64 /// Gets all data
65 QVariantHash data() const noexcept;
65 QVariantHash data() const noexcept;
66
66
67 /**
68 * Merge in the item the source item passed as parameter.
69 *
70 * The merge is done by adding as child of the item the complete tree represented by the source
71 * item. If a part of the tree already exists in the item (based on the name of the nodes), it
72 * is merged by completing the existing tree by items "leaves" (products, components or nodes
73 * with no child).
74 *
75 * For example, with item representing the tree:
76 * R (root node)
77 * - N1 (node)
78 * -- N11 (node)
79 * --- P1 (product)
80 * --- P2 (product)
81 * - N2 (node)
82 *
83 * and the source item representing the tree:
84 * N1 (root node)
85 * - N11 (node)
86 * -- P3 (product)
87 * - N12 (node)
88 *
89 * The leaves of the source item to merge into the item are N1/N11/P3 and N1/N12 => we therefore
90 * have the following merge result:
91 * R
92 * - N1
93 * -- N11
94 * --- P1
95 * --- P2
96 * --- P3 (added leaf)
97 * -- N12 (added leaf)
98 *
99 * @param item the source item
100 * @remarks No control is performed on products or components that are merged into the same tree
101 * part (two products or components may have the same name)
102 * @remarks the merge is made by copy (source item is not changed and still exists after the
103 * operation)
104 */
105 void merge(const DataSourceItem &item);
106
67 bool isRoot() const noexcept;
107 bool isRoot() const noexcept;
68
108
69 QString name() const noexcept;
109 QString name() const noexcept;
@@ -31,6 +31,7 core_sources = [
31 'src/DataSource/DataSourceController.cpp',
31 'src/DataSource/DataSourceController.cpp',
32 'src/DataSource/DataSourceItem.cpp',
32 'src/DataSource/DataSourceItem.cpp',
33 'src/DataSource/DataSourceItemAction.cpp',
33 'src/DataSource/DataSourceItemAction.cpp',
34 'src/DataSource/DataSourceItemMergeHelper.cpp',
34 'src/Network/NetworkController.cpp',
35 'src/Network/NetworkController.cpp',
35 'src/Plugin/PluginManager.cpp',
36 'src/Plugin/PluginManager.cpp',
36 'src/Settings/SqpSettingsDefs.cpp',
37 'src/Settings/SqpSettingsDefs.cpp',
@@ -1,5 +1,6
1 #include <DataSource/DataSourceItem.h>
1 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItemAction.h>
2 #include <DataSource/DataSourceItemAction.h>
3 #include <DataSource/DataSourceItemMergeHelper.h>
3
4
4 #include <QVector>
5 #include <QVector>
5
6
@@ -75,6 +76,11 QVariantHash DataSourceItem::data() const noexcept
75 return impl->m_Data;
76 return impl->m_Data;
76 }
77 }
77
78
79 void DataSourceItem::merge(const DataSourceItem &item)
80 {
81 DataSourceItemMergeHelper::merge(item, *this);
82 }
83
78 bool DataSourceItem::isRoot() const noexcept
84 bool DataSourceItem::isRoot() const noexcept
79 {
85 {
80 return impl->m_Parent == nullptr;
86 return impl->m_Parent == nullptr;
General Comments 0
You need to be logged in to leave comments. Login now