##// END OF EJS Templates
Adds actions for items in the DataSourceWidget...
Alexandre Leroux -
r133:11579fae1cc2
parent child
Show More
@@ -1,32 +1,35
1 #ifndef SCIQLOP_DATASOURCETREEWIDGETITEM_H
1 #ifndef SCIQLOP_DATASOURCETREEWIDGETITEM_H
2 #define SCIQLOP_DATASOURCETREEWIDGETITEM_H
2 #define SCIQLOP_DATASOURCETREEWIDGETITEM_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QTreeWidgetItem>
7 #include <QTreeWidgetItem>
8
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem)
9 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem)
10
10
11 class DataSourceItem;
11 class DataSourceItem;
12
12
13 /**
13 /**
14 * @brief The DataSourceTreeWidgetItem is the graphical representation of a data source item. It is
14 * @brief The DataSourceTreeWidgetItem is the graphical representation of a data source item. It is
15 * intended to be displayed in a QTreeWidget.
15 * intended to be displayed in a QTreeWidget.
16 * @sa DataSourceItem
16 * @sa DataSourceItem
17 */
17 */
18 class DataSourceTreeWidgetItem : public QTreeWidgetItem {
18 class DataSourceTreeWidgetItem : public QTreeWidgetItem {
19 public:
19 public:
20 explicit DataSourceTreeWidgetItem(const DataSourceItem *data, int type = Type);
20 explicit DataSourceTreeWidgetItem(const DataSourceItem *data, int type = Type);
21 explicit DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
21 explicit DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
22 int type = Type);
22 int type = Type);
23
23
24 virtual QVariant data(int column, int role) const override;
24 virtual QVariant data(int column, int role) const override;
25 virtual void setData(int column, int role, const QVariant &value) override;
25 virtual void setData(int column, int role, const QVariant &value) override;
26
26
27 /// @return the actions associated to the item
28 QList<QAction *> actions() const noexcept;
29
27 private:
30 private:
28 class DataSourceTreeWidgetItemPrivate;
31 class DataSourceTreeWidgetItemPrivate;
29 spimpl::unique_impl_ptr<DataSourceTreeWidgetItemPrivate> impl;
32 spimpl::unique_impl_ptr<DataSourceTreeWidgetItemPrivate> impl;
30 };
33 };
31
34
32 #endif // SCIQLOP_DATASOURCETREEWIDGETITEM_H
35 #endif // SCIQLOP_DATASOURCETREEWIDGETITEM_H
@@ -1,75 +1,87
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 #include <QAction>
7
6 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
8 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
7
9
8 namespace {
10 namespace {
9
11
10 QIcon itemIcon(const DataSourceItem *dataSource)
12 QIcon itemIcon(const DataSourceItem *dataSource)
11 {
13 {
12 if (dataSource) {
14 if (dataSource) {
13 auto dataSourceType = dataSource->type();
15 auto dataSourceType = dataSource->type();
14 switch (dataSourceType) {
16 switch (dataSourceType) {
15 case DataSourceItemType::NODE:
17 case DataSourceItemType::NODE:
16 return sqpApp->style()->standardIcon(QStyle::SP_DirIcon);
18 return sqpApp->style()->standardIcon(QStyle::SP_DirIcon);
17 case DataSourceItemType::PRODUCT:
19 case DataSourceItemType::PRODUCT:
18 return sqpApp->style()->standardIcon(QStyle::SP_FileIcon);
20 return sqpApp->style()->standardIcon(QStyle::SP_FileIcon);
19 default:
21 default:
20 // No action
22 // No action
21 break;
23 break;
22 }
24 }
23
25
24 qCWarning(LOG_DataSourceTreeWidgetItem())
26 qCWarning(LOG_DataSourceTreeWidgetItem())
25 << QObject::tr("Can't set data source icon : unknown data source type");
27 << QObject::tr("Can't set data source icon : unknown data source type");
26 }
28 }
27 else {
29 else {
28 qCWarning(LOG_DataSourceTreeWidgetItem())
30 qCWarning(LOG_DataSourceTreeWidgetItem())
29 << QObject::tr("Can't set data source icon : the data source is null");
31 << QObject::tr("Can't set data source icon : the data source is null");
30 }
32 }
31
33
32 // Default cases
34 // Default cases
33 return QIcon{};
35 return QIcon{};
34 }
36 }
35
37
36 } // namespace
38 } // namespace
37
39
38 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
40 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
39 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
41 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
40
42
41 /// Model used to retrieve data source information
43 /// Model used to retrieve data source information
42 const DataSourceItem *m_Data;
44 const DataSourceItem *m_Data;
45 /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of
46 /// the actions
47 QList<QAction *> m_Actions;
43 };
48 };
44
49
45 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
50 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
46 : DataSourceTreeWidgetItem{nullptr, data, type}
51 : DataSourceTreeWidgetItem{nullptr, data, type}
47 {
52 {
48 }
53 }
49
54
50 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
55 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
51 int type)
56 int type)
52 : QTreeWidgetItem{parent, type},
57 : QTreeWidgetItem{parent, type},
53 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
58 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
54 {
59 {
55 // Sets the icon depending on the data source
60 // Sets the icon depending on the data source
56 setIcon(0, itemIcon(impl->m_Data));
61 setIcon(0, itemIcon(impl->m_Data));
62
63 /// @todo ALX : generate actions based on the DataSourceItem (model)
57 }
64 }
58
65
59 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
66 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
60 {
67 {
61 if (role == Qt::DisplayRole) {
68 if (role == Qt::DisplayRole) {
62 return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{};
69 return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{};
63 }
70 }
64 else {
71 else {
65 return QTreeWidgetItem::data(column, role);
72 return QTreeWidgetItem::data(column, role);
66 }
73 }
67 }
74 }
68
75
69 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
76 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
70 {
77 {
71 // Data can't be changed by edition
78 // Data can't be changed by edition
72 if (role != Qt::EditRole) {
79 if (role != Qt::EditRole) {
73 QTreeWidgetItem::setData(column, role, value);
80 QTreeWidgetItem::setData(column, role, value);
74 }
81 }
75 }
82 }
83
84 QList<QAction *> DataSourceTreeWidgetItem::actions() const noexcept
85 {
86 return impl->m_Actions;
87 }
General Comments 0
You need to be logged in to leave comments. Login now