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