##// END OF EJS Templates
Merge branch 'feature/PluginTreeItem' into develop
Merge branch 'feature/PluginTreeItem' into develop

File last commit:

r81:0c5b0960e82e
r87:d88ff9772a05 merge
Show More
DataSourceTreeWidgetItem.cpp
68 lines | 2.0 KiB | text/x-c | CppLexer
/ gui / src / DataSource / DataSourceTreeWidgetItem.cpp
Alexandre Leroux
Defines the QTreeWidgetItem for a data source item
r80 #include <DataSource/DataSourceItem.h>
#include <DataSource/DataSourceTreeWidgetItem.h>
Alexandre Leroux
Handles the icon of a DataSourceTreeWidgetItem (depending of the type of the data source item)
r81 #include <SqpApplication.h>
Alexandre Leroux
Defines the QTreeWidgetItem for a data source item
r80 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
Alexandre Leroux
Handles the icon of a DataSourceTreeWidgetItem (depending of the type of the data source item)
r81 namespace {
QIcon itemIcon(const DataSourceItem *dataSource)
{
if (dataSource) {
auto dataSourceType = dataSource->type();
switch (dataSourceType) {
case DataSourceItemType::NODE:
return sqpApp->style()->standardIcon(QStyle::SP_DirIcon);
case DataSourceItemType::PRODUCT:
return sqpApp->style()->standardIcon(QStyle::SP_FileIcon);
default:
// No action
break;
}
}
// Default cases
return QIcon{};
}
} // namespace
Alexandre Leroux
Defines the QTreeWidgetItem for a data source item
r80 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
/// Model used to retrieve data source information
const DataSourceItem *m_Data;
};
DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
: DataSourceTreeWidgetItem{nullptr, data, type}
{
}
DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
int type)
: QTreeWidgetItem{parent, type},
impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
{
Alexandre Leroux
Handles the icon of a DataSourceTreeWidgetItem (depending of the type of the data source item)
r81 // Sets the icon depending on the data source
setIcon(0, itemIcon(impl->m_Data));
Alexandre Leroux
Defines the QTreeWidgetItem for a data source item
r80 }
QVariant DataSourceTreeWidgetItem::data(int column, int role) const
{
if (role == Qt::DisplayRole) {
return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{};
}
else {
return QTreeWidgetItem::data(column, role);
}
}
void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
{
// Data can't be changed by edition
if (role != Qt::EditRole) {
QTreeWidgetItem::setData(column, role, value);
}
}