mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Second model converted to be less boilerplated.
Second model converted to be less boilerplated, there are right now 7 models that will need to be ported. each model can remove around 30 to 40 LOC, so this is not such a bigger improvement, but it's an 'keeping an eye on the future'. Also fixed a bug where the returned value was dummy. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
26c87fafc2
commit
a4efa8c444
2 changed files with 7 additions and 35 deletions
|
@ -46,8 +46,9 @@ QVariant CleanerTableModel::headerData(int section, Qt::Orientation orientation,
|
||||||
ret = defaultModelFont();
|
ret = defaultModelFont();
|
||||||
break;
|
break;
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return headers.at(section);
|
ret = headers.at(section);
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CleanerTableModel::setHeaderDataStrings(const QStringList& newHeaders)
|
void CleanerTableModel::setHeaderDataStrings(const QStringList& newHeaders)
|
||||||
|
@ -349,8 +350,10 @@ void CylindersModel::remove(const QModelIndex& index)
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
WeightModel::WeightModel(QObject* parent): QAbstractTableModel(parent), current(0), rows(0)
|
WeightModel::WeightModel(QObject* parent): current(0), rows(0)
|
||||||
{
|
{
|
||||||
|
//enum Column {REMOVE, TYPE, WEIGHT};
|
||||||
|
setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("Weight"));
|
||||||
}
|
}
|
||||||
|
|
||||||
weightsystem_t* WeightModel::weightSystemAt(const QModelIndex& index)
|
weightsystem_t* WeightModel::weightSystemAt(const QModelIndex& index)
|
||||||
|
@ -378,11 +381,6 @@ void WeightModel::clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int WeightModel::columnCount(const QModelIndex& parent) const
|
|
||||||
{
|
|
||||||
return COLUMNS;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant WeightModel::data(const QModelIndex& index, int role) const
|
QVariant WeightModel::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
QVariant ret;
|
QVariant ret;
|
||||||
|
@ -476,30 +474,6 @@ int WeightModel::rowCount(const QModelIndex& parent) const
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
||||||
{
|
|
||||||
QVariant ret;
|
|
||||||
if (orientation == Qt::Vertical)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
switch (role) {
|
|
||||||
case Qt::FontRole:
|
|
||||||
ret = defaultModelFont();
|
|
||||||
break;
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
switch(section) {
|
|
||||||
case TYPE:
|
|
||||||
ret = tr("Type");
|
|
||||||
break;
|
|
||||||
case WEIGHT:
|
|
||||||
ret = tr("Weight");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WeightModel::add()
|
void WeightModel::add()
|
||||||
{
|
{
|
||||||
if (rows >= MAX_WEIGHTSYSTEMS)
|
if (rows >= MAX_WEIGHTSYSTEMS)
|
||||||
|
|
|
@ -109,14 +109,12 @@ private:
|
||||||
|
|
||||||
/* Encapsulation of the Weight Model, that represents
|
/* Encapsulation of the Weight Model, that represents
|
||||||
* the current weights on a dive. */
|
* the current weights on a dive. */
|
||||||
class WeightModel : public QAbstractTableModel {
|
class WeightModel : public CleanerTableModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum Column {REMOVE, TYPE, WEIGHT, COLUMNS};
|
enum Column {REMOVE, TYPE, WEIGHT};
|
||||||
|
|
||||||
explicit WeightModel(QObject *parent = 0);
|
explicit WeightModel(QObject *parent = 0);
|
||||||
/*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
|
||||||
/*reimp*/ int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
|
||||||
/*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
/*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||||
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||||
/*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const;
|
/*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue