##// END OF EJS Templates
Add warnings if the icon of a data source can't be set
Alexandre Leroux -
r93:1f6db623b170
parent child
Show More
@@ -1,68 +1,75
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>
4 #include <SqpApplication.h>
5
5
6 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
6 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
7
7
8 namespace {
8 namespace {
9
9
10 QIcon itemIcon(const DataSourceItem *dataSource)
10 QIcon itemIcon(const DataSourceItem *dataSource)
11 {
11 {
12 if (dataSource) {
12 if (dataSource) {
13 auto dataSourceType = dataSource->type();
13 auto dataSourceType = dataSource->type();
14 switch (dataSourceType) {
14 switch (dataSourceType) {
15 case DataSourceItemType::NODE:
15 case DataSourceItemType::NODE:
16 return sqpApp->style()->standardIcon(QStyle::SP_DirIcon);
16 return sqpApp->style()->standardIcon(QStyle::SP_DirIcon);
17 case DataSourceItemType::PRODUCT:
17 case DataSourceItemType::PRODUCT:
18 return sqpApp->style()->standardIcon(QStyle::SP_FileIcon);
18 return sqpApp->style()->standardIcon(QStyle::SP_FileIcon);
19 default:
19 default:
20 // No action
20 // No action
21 break;
21 break;
22 }
22 }
23
24 qCWarning(LOG_DataSourceTreeWidgetItem())
25 << QObject::tr("Can't set data source icon : unknown data source type");
26 }
27 else {
28 qCWarning(LOG_DataSourceTreeWidgetItem())
29 << QObject::tr("Can't set data source icon : the data source is null");
23 }
30 }
24
31
25 // Default cases
32 // Default cases
26 return QIcon{};
33 return QIcon{};
27 }
34 }
28
35
29 } // namespace
36 } // namespace
30
37
31 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
38 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
32 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
39 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
33
40
34 /// Model used to retrieve data source information
41 /// Model used to retrieve data source information
35 const DataSourceItem *m_Data;
42 const DataSourceItem *m_Data;
36 };
43 };
37
44
38 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
45 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
39 : DataSourceTreeWidgetItem{nullptr, data, type}
46 : DataSourceTreeWidgetItem{nullptr, data, type}
40 {
47 {
41 }
48 }
42
49
43 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
50 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
44 int type)
51 int type)
45 : QTreeWidgetItem{parent, type},
52 : QTreeWidgetItem{parent, type},
46 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
53 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
47 {
54 {
48 // Sets the icon depending on the data source
55 // Sets the icon depending on the data source
49 setIcon(0, itemIcon(impl->m_Data));
56 setIcon(0, itemIcon(impl->m_Data));
50 }
57 }
51
58
52 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
59 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
53 {
60 {
54 if (role == Qt::DisplayRole) {
61 if (role == Qt::DisplayRole) {
55 return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{};
62 return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{};
56 }
63 }
57 else {
64 else {
58 return QTreeWidgetItem::data(column, role);
65 return QTreeWidgetItem::data(column, role);
59 }
66 }
60 }
67 }
61
68
62 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
69 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
63 {
70 {
64 // Data can't be changed by edition
71 // Data can't be changed by edition
65 if (role != Qt::EditRole) {
72 if (role != Qt::EditRole) {
66 QTreeWidgetItem::setData(column, role, value);
73 QTreeWidgetItem::setData(column, role, value);
67 }
74 }
68 }
75 }
General Comments 0
You need to be logged in to leave comments. Login now