##// END OF EJS Templates
Connects variable widget to visualization widget...
Connects variable widget to visualization widget The connection is used to populate variable menu with the plot menu

File last commit:

r246:37254eb43d9f
r249:3d1d1572319d
Show More
VariableModel.cpp
125 lines | 3.3 KiB | text/x-c | CppLexer
Alexandre Leroux
Changes Variable from struct to class
r163 #include <Variable/Variable.h>
Alexandre Leroux
Creates the variable model...
r112 #include <Variable/VariableModel.h>
Alexandre Leroux
Updates VariableModel::createVariable() method...
r165 #include <Data/IDataSeries.h>
Alexandre Leroux
Creates the variable model...
r112
Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r149 namespace {
Alexandre Leroux
Implements headerData() method
r150 // 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...
r149 const auto NB_COLUMNS = 3;
} // namespace
Alexandre Leroux
Creates the variable model...
r112 struct VariableModel::VariableModelPrivate {
/// Variables created in SciQlop
Alexandre Leroux
Updates VariableModel::createVariable() method...
r165 std::vector<std::shared_ptr<Variable> > m_Variables;
Alexandre Leroux
Creates the variable model...
r112 };
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r149 VariableModel::VariableModel(QObject *parent)
: QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
Alexandre Leroux
Creates the variable model...
r112 {
}
Alexandre Leroux
Updates VariableModel::createVariable() method...
r165 std::shared_ptr<Variable>
A variable is now created with its dateTime too....
r228 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
Alexandre Leroux
Updates VariableModel::createVariable() method...
r165 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
Alexandre Leroux
Creates the variable model...
r112 {
Alexandre Leroux
Notifies view when a variable is added to the model
r153 auto insertIndex = rowCount();
beginInsertRows({}, insertIndex, insertIndex);
Alexandre Leroux
Creates the variable model...
r112 /// @todo For the moment, the other data of the variable is initialized with default values
A variable is now created with its dateTime too....
r228 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
QStringLiteral("mission"), dateTime);
The mock plugin can now create data with view operation
r235 variable->setDataSeries(std::move(defaultDataSeries));
Alexandre Leroux
Updates VariableModel::createVariable() method...
r165
impl->m_Variables.push_back(variable);
Alexandre Leroux
Creates the variable model...
r112
Alexandre Leroux
Notifies view when a variable is added to the model
r153 endInsertRows();
Alexandre Leroux
Updates VariableModel::createVariable() method...
r165 return variable;
Alexandre Leroux
Creates the variable model...
r112 }
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r149
Alexandre Leroux
Retrieves the current selected variable when clicking on the variable widget
r246 std::shared_ptr<Variable> VariableModel::variable(int index) const
{
return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables.at(index) : nullptr;
}
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r149 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
{
Alexandre Leroux
Implements data() method
r151 if (!index.isValid()) {
return QVariant{};
}
if (index.row() < 0 || index.row() >= rowCount()) {
return QVariant{};
}
if (role == Qt::DisplayRole) {
Alexandre Leroux
Removes useless const ref
r157 if (auto variable = impl->m_Variables.at(index.row()).get()) {
Alexandre Leroux
Implements data() method
r151 switch (index.column()) {
case NAME_COLUMN:
Alexandre Leroux
Changes Variable from struct to class
r163 return variable->name();
Alexandre Leroux
Implements data() method
r151 case UNIT_COLUMN:
Alexandre Leroux
Changes Variable from struct to class
r163 return variable->unit();
Alexandre Leroux
Implements data() method
r151 case MISSION_COLUMN:
Alexandre Leroux
Changes Variable from struct to class
r163 return variable->mission();
Alexandre Leroux
Implements data() method
r151 default:
// No action
break;
}
qWarning(LOG_VariableModel())
<< tr("Can't get data (unknown column %1)").arg(index.column());
}
else {
qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
}
}
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r149 return QVariant{};
}
QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
Alexandre Leroux
Implements headerData() method
r150 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...
r149
return QVariant{};
}