##// END OF EJS Templates
Implements headerData() method
Implements headerData() method

File last commit:

r141:1e5ae025cbab
r141:1e5ae025cbab
Show More
VariableModel.cpp
80 lines | 1.9 KiB | text/x-c | CppLexer
Alexandre Leroux
Creates the variable model...
r107 #include <Variable/VariableModel.h>
#include <Variable/Variable.h>
Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r140 namespace {
Alexandre Leroux
Implements headerData() method
r141 // Column indexes
const auto NAME_COLUMN = 0;
const auto UNIT_COLUMN = 1;
const auto MISSION_COLUMN = 2;
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r140 const auto NB_COLUMNS = 3;
} // namespace
Alexandre Leroux
Creates the variable model...
r107 struct VariableModel::VariableModelPrivate {
/// Variables created in SciQlop
std::vector<std::unique_ptr<Variable> > m_Variables;
};
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r140 VariableModel::VariableModel(QObject *parent)
: QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
Alexandre Leroux
Creates the variable model...
r107 {
}
Variable *VariableModel::createVariable(const QString &name) noexcept
{
/// @todo For the moment, the other data of the variable is initialized with default values
auto variable
= std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
impl->m_Variables.push_back(std::move(variable));
return impl->m_Variables.back().get();
}
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r140
int VariableModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return NB_COLUMNS;
}
int VariableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return impl->m_Variables.size();
}
QVariant VariableModel::data(const QModelIndex &index, int role) const
{
return QVariant{};
}
QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
Alexandre Leroux
Implements headerData() method
r141 if (role != Qt::DisplayRole) {
return QVariant{};
}
if (orientation == Qt::Horizontal) {
switch (section) {
case NAME_COLUMN:
return tr("Name");
case UNIT_COLUMN:
return tr("Unit");
case MISSION_COLUMN:
return tr("Mission");
default:
// No action
break;
}
qWarning(LOG_VariableModel())
<< tr("Can't get header data (unknown column %1)").arg(section);
}
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r140
return QVariant{};
}