##// END OF EJS Templates
Add the VarRequestId on the AcquisitionPacket
Add the VarRequestId on the AcquisitionPacket

File last commit:

r565:6cc1dd13aa83
r583:eca175f15252
Show More
VariableModel.cpp
271 lines | 8.6 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
Uses DateUtils
r450 #include <Common/DateUtils.h>
Alexandre Leroux
Updates VariableModel::createVariable() method...
r153 #include <Data/IDataSeries.h>
Alexandre Leroux
Creates the variable model...
r107
Alexandre Leroux
Updates headerData() method to return column width/size for role Qt::SizeHintRole
r257 #include <QSize>
Add implementation of progress bar on variable inspector connected to...
r369 #include <unordered_map>
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
Adds "unit" and "mission" columns to variable widget
r519 const auto UNIT_COLUMN = 3;
const auto MISSION_COLUMN = 4;
Alexandre Leroux
Adds plugin column to variable widget...
r520 const auto PLUGIN_COLUMN = 5;
const auto NB_COLUMNS = 6;
Alexandre Leroux
Adapts VariableModel to be a QabstractTableModel...
r140
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 };
Alexandre Leroux
Adds "unit" and "mission" columns to variable widget
r519 const auto COLUMN_PROPERTIES = QHash<int, ColumnProperties>{
{NAME_COLUMN, {QObject::tr("Name")}}, {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
{TEND_COLUMN, {QObject::tr("tEnd"), 180}}, {UNIT_COLUMN, {QObject::tr("Unit")}},
Alexandre Leroux
Adds plugin column to variable widget...
r520 {MISSION_COLUMN, {QObject::tr("Mission")}}, {PLUGIN_COLUMN, {QObject::tr("Plugin")}}};
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");
Add implementation of progress bar on variable inspector connected to...
r369
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
Corrects regression on variable destruction
r387 std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress;
Add implementation of progress bar on variable inspector connected to...
r369
Correction MR
r370 /// Return the row index of the variable. -1 if it's not found
Add implementation of progress bar on variable inspector connected to...
r369 int indexOfVariable(Variable *variable) const noexcept;
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,
Change SqpRange for SqpDateTime
r471 const SqpRange &dateTime,
Alexandre Leroux
Updates variable creation to pass metadata...
r377 const QVariantHash &metadata) 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
Updates variable creation to pass metadata...
r377 auto variable = std::make_shared<Variable>(name, dateTime, metadata);
Alexandre Leroux
Updates VariableModel::createVariable() method...
r153
impl->m_Variables.push_back(variable);
Alexandre Leroux
Fixes refresh problem in Variable widget
r340 connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated);
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
Variable deletion (3)...
r306 void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept
{
if (!variable) {
qCCritical(LOG_Variable()) << "Can't delete a null variable from the model";
return;
}
// Finds variable in the model
auto begin = impl->m_Variables.cbegin();
auto end = impl->m_Variables.cend();
auto it = std::find(begin, end, variable);
if (it != end) {
auto removeIndex = std::distance(begin, it);
// Deletes variable
beginRemoveRows({}, removeIndex, removeIndex);
impl->m_Variables.erase(it);
endRemoveRows();
}
else {
qCritical(LOG_VariableModel())
<< tr("Can't delete variable %1 from the model: the variable is not in the model")
.arg(variable->name());
}
Alexandre Leroux
Corrects regression on variable destruction
r387
// Removes variable from progress map
impl->m_VariableToProgress.erase(variable);
Alexandre Leroux
Variable deletion (3)...
r306 }
Add implementation of progress bar on variable inspector connected to...
r369
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 }
Add implementation of progress bar on variable inspector connected to...
r369 void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress)
{
Remove abort button validity when the progress is finished (eg. == 0)
r398 if (progress > 0.0) {
impl->m_VariableToProgress[variable] = progress;
}
else {
impl->m_VariableToProgress.erase(variable);
}
Add implementation of progress bar on variable inspector connected to...
r369 auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN);
emit dataChanged(modelIndex, modelIndex);
}
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
Alexandre Leroux
Shows min/max x-axis data in Variable widget (3)...
r563 /// @param getValueFun function used to get for a data series the iterator on the entry
/// that contains the time value to display
auto dateTimeVariant = [variable](const auto &getValueFun) {
if (auto dataSeries = variable->dataSeries()) {
auto it = getValueFun(*dataSeries);
return (it != dataSeries->cend())
? DateUtils::dateTime(it->x()).toString(DATETIME_FORMAT)
: QVariant{};
}
else {
return QVariant{};
}
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r254 };
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:
Alexandre Leroux
Shows min/max x-axis data in Variable widget (3)...
r563 // Shows the min value of the data series above the range tstart
return dateTimeVariant([min = variable->range().m_TStart](
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r565 const auto &dataSeries) { return dataSeries.minXAxisData(min); });
Alexandre Leroux
Replaces unit and mission columns by datetime columns
r254 case TEND_COLUMN:
Alexandre Leroux
Shows min/max x-axis data in Variable widget (3)...
r563 // Shows the max value of the data series under the range tend
return dateTimeVariant([max = variable->range().m_TEnd](
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r565 const auto &dataSeries) { return dataSeries.maxXAxisData(max); });
Alexandre Leroux
Adds "unit" and "mission" columns to variable widget
r519 case UNIT_COLUMN:
return variable->metadata().value(QStringLiteral("units"));
case MISSION_COLUMN:
return variable->metadata().value(QStringLiteral("mission"));
Alexandre Leroux
Adds plugin column to variable widget...
r520 case PLUGIN_COLUMN:
return variable->metadata().value(QStringLiteral("plugin"));
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)");
}
}
Correction MR
r370 else if (role == VariableRoles::ProgressRole) {
Add implementation of progress bar on variable inspector connected to...
r369 if (auto variable = impl->m_Variables.at(index.row())) {
Alexandre Leroux
Corrects regression on variable destruction
r387 auto it = impl->m_VariableToProgress.find(variable);
Add implementation of progress bar on variable inspector connected to...
r369 if (it != impl->m_VariableToProgress.cend()) {
return it->second;
}
}
}
Alexandre Leroux
Implements data() method
r142
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{};
}
Alexandre Leroux
Fixes refresh problem in Variable widget
r340
Implement of the abort download process
r388 void VariableModel::abortProgress(const QModelIndex &index)
{
if (auto variable = impl->m_Variables.at(index.row())) {
emit abortProgessRequested(variable);
}
}
Alexandre Leroux
Fixes refresh problem in Variable widget
r340 void VariableModel::onVariableUpdated() noexcept
{
// Finds variable that has been updated in the model
if (auto updatedVariable = dynamic_cast<Variable *>(sender())) {
Add implementation of progress bar on variable inspector connected to...
r369 auto updatedVariableIndex = impl->indexOfVariable(updatedVariable);
if (updatedVariableIndex > -1) {
emit dataChanged(createIndex(updatedVariableIndex, 0),
createIndex(updatedVariableIndex, columnCount() - 1));
Alexandre Leroux
Fixes refresh problem in Variable widget
r340 }
}
}
Add implementation of progress bar on variable inspector connected to...
r369
int VariableModel::VariableModelPrivate::indexOfVariable(Variable *variable) const noexcept
{
auto begin = std::cbegin(m_Variables);
auto end = std::cend(m_Variables);
auto it
= std::find_if(begin, end, [variable](const auto &var) { return var.get() == variable; });
if (it != end) {
// Gets the index of the variable in the model: we assume here that views have the same
// order as the model
return std::distance(begin, it);
}
else {
return -1;
}
}