##// END OF EJS Templates
Handles the icon of a DataSourceTreeWidgetItem (depending of the type of the data source item)
Alexandre Leroux -
r81:0c5b0960e82e
parent child
Show More
@@ -1,8 +1,33
1 #include <DataSource/DataSourceItem.h>
1 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceTreeWidgetItem.h>
2 #include <DataSource/DataSourceTreeWidgetItem.h>
3
3
4 #include <SqpApplication.h>
5
4 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
6 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
5
7
8 namespace {
9
10 QIcon itemIcon(const DataSourceItem *dataSource)
11 {
12 if (dataSource) {
13 auto dataSourceType = dataSource->type();
14 switch (dataSourceType) {
15 case DataSourceItemType::NODE:
16 return sqpApp->style()->standardIcon(QStyle::SP_DirIcon);
17 case DataSourceItemType::PRODUCT:
18 return sqpApp->style()->standardIcon(QStyle::SP_FileIcon);
19 default:
20 // No action
21 break;
22 }
23 }
24
25 // Default cases
26 return QIcon{};
27 }
28
29 } // namespace
30
6 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
31 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
7 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
32 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
8
33
@@ -20,6 +45,8 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const Da
20 : QTreeWidgetItem{parent, type},
45 : QTreeWidgetItem{parent, type},
21 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
46 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
22 {
47 {
48 // Sets the icon depending on the data source
49 setIcon(0, itemIcon(impl->m_Data));
23 }
50 }
24
51
25 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
52 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
General Comments 0
You need to be logged in to leave comments. Login now