##// END OF EJS Templates
It's now possible to create the variable and ask data to be retreived...
It's now possible to create the variable and ask data to be retreived asynchronously

File last commit:

r319:c71a61da7f3d
r319:c71a61da7f3d
Show More
VariableModel.cpp
153 lines | 4.4 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
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r274 #include <QDateTime>
Alexandre Leroux
Updates headerData() method to return column width/size for role Qt::SizeHintRole
r277 #include <QSize>
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r274
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;
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r274 const auto TSTART_COLUMN = 1;
const auto TEND_COLUMN = 2;
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r149 const auto NB_COLUMNS = 3;
Alexandre Leroux
Creates struct for column properties...
r275 // Column properties
Alexandre Leroux
Adds width and height properties
r276 const auto DEFAULT_HEIGHT = 25;
const auto DEFAULT_WIDTH = 100;
Alexandre Leroux
Creates struct for column properties...
r275
struct ColumnProperties {
Alexandre Leroux
Adds width and height properties
r276 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
int height = DEFAULT_HEIGHT)
: m_Name{name}, m_Width{width}, m_Height{height}
{
}
Alexandre Leroux
Creates struct for column properties...
r275
QString m_Name;
Alexandre Leroux
Adds width and height properties
r276 int m_Width;
int m_Height;
Alexandre Leroux
Creates struct for column properties...
r275 };
const auto COLUMN_PROPERTIES
= QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}},
Alexandre Leroux
Adds width and height properties
r276 {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
{TEND_COLUMN, {QObject::tr("tEnd"), 180}}};
Alexandre Leroux
Creates struct for column properties...
r275
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r274 /// Format for datetimes
const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r149 } // 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 {
}
It's now possible to create the variable and ask data to be retreived...
r319 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
const SqpDateTime &dateTime) 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);
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
{
Alexandre Leroux
Pull request fixes
r251 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
Alexandre Leroux
Retrieves the current selected variable when clicking on the variable widget
r246 }
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
Replaces unit and mission columns by datetime columns
r274 /// Lambda function that builds the variant to return for a time value
auto dateTimeVariant = [](double time) {
auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.);
return dateTime.toString(DATETIME_FORMAT);
};
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
Replaces unit and mission columns by datetime columns
r274 case TSTART_COLUMN:
return dateTimeVariant(variable->dateTime().m_TStart);
case TEND_COLUMN:
return dateTimeVariant(variable->dateTime().m_TEnd);
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
Updates headerData() method to return column width/size for role Qt::SizeHintRole
r277 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
Alexandre Leroux
Implements headerData() method
r150 return QVariant{};
}
if (orientation == Qt::Horizontal) {
Alexandre Leroux
Creates struct for column properties...
r275 auto propertiesIt = COLUMN_PROPERTIES.find(section);
if (propertiesIt != COLUMN_PROPERTIES.cend()) {
// Role is either DisplayRole or SizeHintRole
Alexandre Leroux
Updates headerData() method to return column width/size for role Qt::SizeHintRole
r277 return (role == Qt::DisplayRole)
? QVariant{propertiesIt->m_Name}
: QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
Alexandre Leroux
Creates struct for column properties...
r275 }
else {
qWarning(LOG_VariableModel())
<< tr("Can't get header data (unknown column %1)").arg(section);
Alexandre Leroux
Implements headerData() method
r150 }
}
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r149
return QVariant{};
}