##// END OF EJS Templates
Handles items with same names in the same node...
Alexandre Leroux -
r1037:c90049fe7bc2
parent child
Show More
@@ -11,6 +11,41 namespace {
11 // Column indexes
11 // Column indexes
12 const auto NAME_COLUMN = 0;
12 const auto NAME_COLUMN = 0;
13
13
14 /**
15 * Generates the full name of an item.
16 *
17 * The full name of an item is its name possibly suffixed by the name of its plugin, in case there
18 * are items of the same name in its relatives
19 * @param item the item for which to generate the complete name
20 * @return the complete name of the item
21 */
22 QString completeName(const DataSourceItem &item)
23 {
24 auto name = item.name();
25
26 if (item.type() == DataSourceItemType::NODE) {
27 return name;
28 }
29
30 auto parentItem = item.parentItem();
31 if (!parentItem) {
32 return name;
33 }
34
35 // Finds in item's relatives items that have the same name
36 bool foundSameName = false;
37 for (auto i = 0, count = parentItem->childCount(); i < count && !foundSameName; ++i) {
38 auto child = parentItem->child(i);
39 foundSameName = child != &item
40 && QString::compare(child->name(), item.name(), Qt::CaseInsensitive) == 0;
41 }
42
43 // If the name of the item is not unique, it is completed by the plugin suffix
44 return foundSameName
45 ? QString{"%1 (%2)"}.arg(name, item.data(DataSourceItem::PLUGIN_DATA_KEY).toString())
46 : name;
47 }
48
14 QIcon itemIcon(const DataSourceItem *dataSource)
49 QIcon itemIcon(const DataSourceItem *dataSource)
15 {
50 {
16 if (dataSource) {
51 if (dataSource) {
@@ -92,10 +127,15 QString itemTooltip(const DataSourceItem *dataSource) noexcept
92 } // namespace
127 } // namespace
93
128
94 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
129 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
95 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
130 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data)
131 : m_Data{data}, m_Name{completeName(*m_Data)}
132 {
133 }
96
134
97 /// Model used to retrieve data source information
135 /// Model used to retrieve data source information
98 const DataSourceItem *m_Data;
136 const DataSourceItem *m_Data;
137 /// Name displayed
138 QString m_Name;
99 /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of
139 /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of
100 /// the actions
140 /// the actions
101 QList<QAction *> m_Actions;
141 QList<QAction *> m_Actions;
@@ -151,7 +191,7 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
151 if (impl->m_Data) {
191 if (impl->m_Data) {
152 switch (column) {
192 switch (column) {
153 case NAME_COLUMN:
193 case NAME_COLUMN:
154 return impl->m_Data->name();
194 return impl->m_Name;
155 default:
195 default:
156 // No action
196 // No action
157 break;
197 break;
General Comments 0
You need to be logged in to leave comments. Login now