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