From 11579fae1cc20683561fd8166e39f20a55d47450 2017-06-15 09:12:21 From: Alexandre Leroux Date: 2017-06-15 09:12:21 Subject: [PATCH] Adds actions for items in the DataSourceWidget For each item will be associated actions (generated from the model of the item) that will be displayed in the menu when right clicking on the item in the tree --- diff --git a/gui/include/DataSource/DataSourceTreeWidgetItem.h b/gui/include/DataSource/DataSourceTreeWidgetItem.h index 02b0122..842e5ba 100644 --- a/gui/include/DataSource/DataSourceTreeWidgetItem.h +++ b/gui/include/DataSource/DataSourceTreeWidgetItem.h @@ -24,6 +24,9 @@ public: virtual QVariant data(int column, int role) const override; virtual void setData(int column, int role, const QVariant &value) override; + /// @return the actions associated to the item + QList actions() const noexcept; + private: class DataSourceTreeWidgetItemPrivate; spimpl::unique_impl_ptr impl; diff --git a/gui/src/DataSource/DataSourceTreeWidgetItem.cpp b/gui/src/DataSource/DataSourceTreeWidgetItem.cpp index 236f0b4..bce551a 100644 --- a/gui/src/DataSource/DataSourceTreeWidgetItem.cpp +++ b/gui/src/DataSource/DataSourceTreeWidgetItem.cpp @@ -3,6 +3,8 @@ #include +#include + Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem") namespace { @@ -40,6 +42,9 @@ struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate { /// Model used to retrieve data source information const DataSourceItem *m_Data; + /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of + /// the actions + QList m_Actions; }; DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type) @@ -54,6 +59,8 @@ DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const Da { // Sets the icon depending on the data source setIcon(0, itemIcon(impl->m_Data)); + + /// @todo ALX : generate actions based on the DataSourceItem (model) } QVariant DataSourceTreeWidgetItem::data(int column, int role) const @@ -73,3 +80,8 @@ void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &val QTreeWidgetItem::setData(column, role, value); } } + +QList DataSourceTreeWidgetItem::actions() const noexcept +{ + return impl->m_Actions; +}