##// 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,41 +1,68
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
9 /// Model used to retrieve data source information
34 /// Model used to retrieve data source information
10 const DataSourceItem *m_Data;
35 const DataSourceItem *m_Data;
11 };
36 };
12
37
13 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
38 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
14 : DataSourceTreeWidgetItem{nullptr, data, type}
39 : DataSourceTreeWidgetItem{nullptr, data, type}
15 {
40 {
16 }
41 }
17
42
18 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
43 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
19 int type)
44 int type)
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
26 {
53 {
27 if (role == Qt::DisplayRole) {
54 if (role == Qt::DisplayRole) {
28 return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{};
55 return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{};
29 }
56 }
30 else {
57 else {
31 return QTreeWidgetItem::data(column, role);
58 return QTreeWidgetItem::data(column, role);
32 }
59 }
33 }
60 }
34
61
35 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
62 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
36 {
63 {
37 // Data can't be changed by edition
64 // Data can't be changed by edition
38 if (role != Qt::EditRole) {
65 if (role != Qt::EditRole) {
39 QTreeWidgetItem::setData(column, role, value);
66 QTreeWidgetItem::setData(column, role, value);
40 }
67 }
41 }
68 }
General Comments 0
You need to be logged in to leave comments. Login now