##// 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:

r294:c71a61da7f3d
r294:c71a61da7f3d
Show More
VariableModel.cpp
153 lines | 4.4 KiB | text/x-c | CppLexer
Alexandre Leroux
Changes Variable from struct to class
r151 #include <Variable/Variable.h>
Alexandre Leroux
Creates the variable model...
r107 #include <Variable/VariableModel.h>
Alexandre Leroux
Updates VariableModel::createVariable() method...
r153 #include <Data/IDataSeries.h>
Alexandre Leroux
Creates the variable model...
r107
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r254 #include <QDateTime>
Alexandre Leroux
Updates headerData() method to return column width/size for role Qt::SizeHintRole
r257 #include <QSize>
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r254
Alexandre Leroux
Creates the variable model...
r107 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;
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r254 const auto TSTART_COLUMN = 1;
const auto TEND_COLUMN = 2;
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r140 const auto NB_COLUMNS = 3;
Alexandre Leroux
Creates struct for column properties...
r255 // Column properties
Alexandre Leroux
Adds width and height properties
r256 const auto DEFAULT_HEIGHT = 25;
const auto DEFAULT_WIDTH = 100;
Alexandre Leroux
Creates struct for column properties...
r255
struct ColumnProperties {
Alexandre Leroux
Adds width and height properties
r256 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...
r255
QString m_Name;
Alexandre Leroux
Adds width and height properties
r256 int m_Width;
int m_Height;
Alexandre Leroux
Creates struct for column properties...
r255 };
const auto COLUMN_PROPERTIES
= QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}},
Alexandre Leroux
Adds width and height properties
r256 {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
{TEND_COLUMN, {QObject::tr("tEnd"), 180}}};
Alexandre Leroux
Creates struct for column properties...
r255
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r254 /// Format for datetimes
const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r140 } // namespace
Alexandre Leroux
Creates the variable model...
r107 struct VariableModel::VariableModelPrivate {
/// Variables created in SciQlop
Alexandre Leroux
Updates VariableModel::createVariable() method...
r153 std::vector<std::shared_ptr<Variable> > m_Variables;
Alexandre Leroux
Creates the variable model...
r107 };
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 {
}
It's now possible to create the variable and ask data to be retreived...
r294 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
const SqpDateTime &dateTime) noexcept
Alexandre Leroux
Creates the variable model...
r107 {
Alexandre Leroux
Notifies view when a variable is added to the model
r144 auto insertIndex = rowCount();
beginInsertRows({}, insertIndex, insertIndex);
Alexandre Leroux
Creates the variable model...
r107 /// @todo For the moment, the other data of the variable is initialized with default values
A variable is now created with its dateTime too....
r212 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
QStringLiteral("mission"), dateTime);
Alexandre Leroux
Updates VariableModel::createVariable() method...
r153
impl->m_Variables.push_back(variable);
Alexandre Leroux
Creates the variable model...
r107
Alexandre Leroux
Notifies view when a variable is added to the model
r144 endInsertRows();
Alexandre Leroux
Updates VariableModel::createVariable() method...
r153 return variable;
Alexandre Leroux
Creates the variable model...
r107 }
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r140
Alexandre Leroux
Retrieves the current selected variable when clicking on the variable widget
r229 std::shared_ptr<Variable> VariableModel::variable(int index) const
{
Alexandre Leroux
Pull request fixes
r234 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
r229 }
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
{
Alexandre Leroux
Implements data() method
r142 if (!index.isValid()) {
return QVariant{};
}
if (index.row() < 0 || index.row() >= rowCount()) {
return QVariant{};
}
if (role == Qt::DisplayRole) {
Alexandre Leroux
Removes useless const ref
r147 if (auto variable = impl->m_Variables.at(index.row()).get()) {
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r254 /// 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
r142 switch (index.column()) {
case NAME_COLUMN:
Alexandre Leroux
Changes Variable from struct to class
r151 return variable->name();
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r254 case TSTART_COLUMN:
return dateTimeVariant(variable->dateTime().m_TStart);
case TEND_COLUMN:
return dateTimeVariant(variable->dateTime().m_TEnd);
Alexandre Leroux
Implements data() method
r142 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...
r140 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
r257 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
Alexandre Leroux
Implements headerData() method
r141 return QVariant{};
}
if (orientation == Qt::Horizontal) {
Alexandre Leroux
Creates struct for column properties...
r255 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
r257 return (role == Qt::DisplayRole)
? QVariant{propertiesIt->m_Name}
: QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
Alexandre Leroux
Creates struct for column properties...
r255 }
else {
qWarning(LOG_VariableModel())
<< tr("Can't get header data (unknown column %1)").arg(section);
Alexandre Leroux
Implements headerData() method
r141 }
}
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r140
return QVariant{};
}