models: pass header descriptions in CleanerTableModel constructor

For the "CleanerHeaderModel" to work, the deriving class has to
set the header descriptions. Failing to do so led to bug #4294.

To avoid that in the future force the deriving class to pass
the headers in the constructor.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-08-31 07:36:38 +02:00
parent 7106c4d5f0
commit c0e8ea5188
8 changed files with 19 additions and 29 deletions

View file

@ -20,7 +20,8 @@ const QPixmap &editIcon()
return edit; return edit;
} }
CleanerTableModel::CleanerTableModel(QObject *parent) : QAbstractTableModel(parent) CleanerTableModel::CleanerTableModel(QStringList headers, QObject *parent) : QAbstractTableModel(parent),
headers(headers)
{ {
} }
@ -42,8 +43,3 @@ QVariant CleanerTableModel::headerData(int section, Qt::Orientation orientation,
} }
return QVariant(); return QVariant();
} }
void CleanerTableModel::setHeaderDataStrings(const QStringList &newHeaders)
{
headers = newHeaders;
}

View file

@ -20,15 +20,12 @@ const QPixmap &editIcon();
class CleanerTableModel : public QAbstractTableModel { class CleanerTableModel : public QAbstractTableModel {
Q_OBJECT Q_OBJECT
public: public:
explicit CleanerTableModel(QObject *parent = 0); explicit CleanerTableModel(QStringList headers, QObject *parent = 0);
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
protected:
void setHeaderDataStrings(const QStringList &headers);
private: private:
QStringList headers; QStringList headers;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
}; };
#endif #endif

View file

@ -13,18 +13,17 @@
#include "core/subsurface-string.h" #include "core/subsurface-string.h"
#include <string> #include <string>
CylindersModel::CylindersModel(bool planner, QObject *parent) : CleanerTableModel(parent), CylindersModel::CylindersModel(bool planner, QObject *parent) :
// enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH, MOD, MND, USE, WORKINGPRESS_INT, SIZE_INT, SENSORS};
CleanerTableModel(QStringList { QString(), tr("Type"), tr("Size"), tr("Work press."), tr("Start press."), tr("End press."), tr("O₂%"), tr("He%"),
tr("Deco switch at"), tr("Bot. MOD"), tr("MND"), tr("Use"), QString(),
QString(), tr("Sensors") }, parent),
d(nullptr), d(nullptr),
dcNr(-1), dcNr(-1),
inPlanner(planner), inPlanner(planner),
numRows(0), numRows(0),
tempRow(-1) tempRow(-1)
{ {
// enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH, MOD, MND, USE, WORKINGPRESS_INT, SIZE_INT, SENSORS};
setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << tr("O₂%") << tr("He%")
<< tr("Deco switch at") << tr("Bot. MOD") << tr("MND") << tr("Use") << ""
<< "" << tr("Sensors"));
connect(&diveListNotifier, &DiveListNotifier::cylindersReset, this, &CylindersModel::cylindersReset); connect(&diveListNotifier, &DiveListNotifier::cylindersReset, this, &CylindersModel::cylindersReset);
connect(&diveListNotifier, &DiveListNotifier::cylinderAdded, this, &CylindersModel::cylinderAdded); connect(&diveListNotifier, &DiveListNotifier::cylinderAdded, this, &CylindersModel::cylinderAdded);
connect(&diveListNotifier, &DiveListNotifier::cylinderRemoved, this, &CylindersModel::cylinderRemoved); connect(&diveListNotifier, &DiveListNotifier::cylinderRemoved, this, &CylindersModel::cylinderRemoved);

View file

@ -3,10 +3,9 @@
#include "core/divecomputer.h" #include "core/divecomputer.h"
#include "core/metrics.h" #include "core/metrics.h"
ExtraDataModel::ExtraDataModel(QObject *parent) : CleanerTableModel(parent) ExtraDataModel::ExtraDataModel(QObject *parent) :
CleanerTableModel(QStringList { tr("Key"), tr("Value") }, parent)
{ {
//enum Column {KEY, VALUE};
setHeaderDataStrings(QStringList() << tr("Key") << tr("Value"));
} }
void ExtraDataModel::clear() void ExtraDataModel::clear()

View file

@ -7,9 +7,9 @@
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/subsurface-qt/divelistnotifier.h" #include "core/subsurface-qt/divelistnotifier.h"
FilterPresetModel::FilterPresetModel() FilterPresetModel::FilterPresetModel() :
CleanerTableModel(QStringList { QString(), tr("Name") })
{ {
setHeaderDataStrings(QStringList{ "", tr("Name") });
connect(&diveListNotifier, &DiveListNotifier::dataReset, this, &FilterPresetModel::reset); connect(&diveListNotifier, &DiveListNotifier::dataReset, this, &FilterPresetModel::reset);
connect(&diveListNotifier, &DiveListNotifier::filterPresetAdded, this, &FilterPresetModel::filterPresetAdded); connect(&diveListNotifier, &DiveListNotifier::filterPresetAdded, this, &FilterPresetModel::filterPresetAdded);
connect(&diveListNotifier, &DiveListNotifier::filterPresetRemoved, this, &FilterPresetModel::filterPresetRemoved); connect(&diveListNotifier, &DiveListNotifier::filterPresetRemoved, this, &FilterPresetModel::filterPresetRemoved);

View file

@ -32,7 +32,7 @@ int TankInfoModel::rowCount(const QModelIndex&) const
return (int)tank_info_table.size(); return (int)tank_info_table.size();
} }
TankInfoModel::TankInfoModel(QObject *parent) : CleanerTableModel(parent) TankInfoModel::TankInfoModel(QObject *parent) :
CleanerTableModel(QStringList{ tr("Description"), tr("ml"), tr("bar") }, parent)
{ {
setHeaderDataStrings(QStringList() << tr("Description") << tr("ml") << tr("bar"));
} }

View file

@ -10,12 +10,11 @@
#include "commands/command.h" #include "commands/command.h"
#endif #endif
WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent), WeightModel::WeightModel(QObject *parent) :
CleanerTableModel(QStringList { QString(), tr("Type"), tr("Weight") }, parent),
d(nullptr), d(nullptr),
tempRow(-1) tempRow(-1)
{ {
//enum Column {REMOVE, TYPE, WEIGHT};
setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("Weight"));
connect(&diveListNotifier, &DiveListNotifier::weightsystemsReset, this, &WeightModel::weightsystemsReset); connect(&diveListNotifier, &DiveListNotifier::weightsystemsReset, this, &WeightModel::weightsystemsReset);
connect(&diveListNotifier, &DiveListNotifier::weightAdded, this, &WeightModel::weightAdded); connect(&diveListNotifier, &DiveListNotifier::weightAdded, this, &WeightModel::weightAdded);
connect(&diveListNotifier, &DiveListNotifier::weightRemoved, this, &WeightModel::weightRemoved); connect(&diveListNotifier, &DiveListNotifier::weightRemoved, this, &WeightModel::weightRemoved);

View file

@ -32,7 +32,7 @@ int WSInfoModel::rowCount(const QModelIndex&) const
return static_cast<int>(ws_info_table.size()); return static_cast<int>(ws_info_table.size());
} }
WSInfoModel::WSInfoModel(QObject *parent) : CleanerTableModel(parent) WSInfoModel::WSInfoModel(QObject *parent) :
CleanerTableModel(QStringList { tr("Description"), tr("kg") }, parent)
{ {
setHeaderDataStrings(QStringList() << tr("Description") << tr("kg"));
} }