##// END OF EJS Templates
onRangeChanged is now based on the good range (the new one)...
onRangeChanged is now based on the good range (the new one) setTimeRange is now connected to rescaleAxes and replot methods

File last commit:

r145:d27464f6164d
r315:076efd0d6728
Show More
DataSourceTreeWidgetItem.cpp
101 lines | 3.2 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>
Alexandre Leroux
Generates tree actions based on the item actions
r145 #include <DataSource/DataSourceItemAction.h>
Alexandre Leroux
Defines the QTreeWidgetItem for a data source item
r80 #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
Adds actions for items in the DataSourceWidget...
r142 #include <QAction>
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;
}
Alexandre Leroux
Add warnings if the icon of a data source can't be set
r93
qCWarning(LOG_DataSourceTreeWidgetItem())
<< QObject::tr("Can't set data source icon : unknown data source type");
}
else {
qCWarning(LOG_DataSourceTreeWidgetItem())
<< QObject::tr("Can't set data source icon : the data source is null");
Alexandre Leroux
Handles the icon of a DataSourceTreeWidgetItem (depending of the type of the data source item)
r81 }
// 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;
Alexandre Leroux
Adds actions for items in the DataSourceWidget...
r142 /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of
/// the actions
QList<QAction *> m_Actions;
Alexandre Leroux
Defines the QTreeWidgetItem for a data source item
r80 };
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
Adds actions for items in the DataSourceWidget...
r142
Alexandre Leroux
Generates tree actions based on the item actions
r145 // Generates tree actions based on the item actions
auto createTreeAction = [this, &parent](const auto &itemAction) {
auto treeAction = new QAction{itemAction->name(), parent};
// Executes item action when tree action is triggered
QObject::connect(treeAction, &QAction::triggered, itemAction,
&DataSourceItemAction::execute);
return treeAction;
};
auto itemActions = impl->m_Data->actions();
std::transform(std::cbegin(itemActions), std::cend(itemActions),
std::back_inserter(impl->m_Actions), createTreeAction);
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);
}
}
Alexandre Leroux
Adds actions for items in the DataSourceWidget...
r142
QList<QAction *> DataSourceTreeWidgetItem::actions() const noexcept
{
return impl->m_Actions;
}