mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Begin to Cleanup the Models, trying to reduce boilerplate.
The Model View system in Qt is *very* verbose, this is the beginning of a series of patches that will concentrate the boilerplate somewhere and reduce the amount of lines and will also try to make the code cleaner and easyer to understand, Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
1b9a4f2bf8
commit
26c87fafc2
3 changed files with 31 additions and 19 deletions
|
@ -25,11 +25,16 @@ QFont defaultModelFont()
|
|||
return font;
|
||||
}
|
||||
|
||||
CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent), current(0), rows(0)
|
||||
CleanerTableModel::CleanerTableModel(): QAbstractTableModel()
|
||||
{
|
||||
}
|
||||
|
||||
QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
int CleanerTableModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return headers.count();
|
||||
}
|
||||
|
||||
QVariant CleanerTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
QVariant ret;
|
||||
|
||||
|
@ -41,22 +46,19 @@ QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, in
|
|||
ret = defaultModelFont();
|
||||
break;
|
||||
case Qt::DisplayRole:
|
||||
switch(section) {
|
||||
case TYPE: ret = tr("Type"); break;
|
||||
case SIZE: ret = tr("Size"); break;
|
||||
case WORKINGPRESS: ret = tr("WorkPress"); break;
|
||||
case START: ret = tr("StartPress"); break;
|
||||
case END: ret = tr("EndPress "); break;
|
||||
case O2: ret = tr("O2% "); break;
|
||||
case HE: ret = tr("He% "); break;
|
||||
}
|
||||
return headers.at(section);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CylindersModel::columnCount(const QModelIndex& parent) const
|
||||
void CleanerTableModel::setHeaderDataStrings(const QStringList& newHeaders)
|
||||
{
|
||||
return COLUMNS;
|
||||
headers = newHeaders;
|
||||
}
|
||||
|
||||
CylindersModel::CylindersModel(QObject* parent): current(0), rows(0)
|
||||
{
|
||||
// enum{REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE,};
|
||||
setHeaderDataStrings( QStringList() << "" << tr("Type") << tr("Size") << tr("WorkPress") << tr("StartPress") << tr("O2%") << tr("HE"));
|
||||
}
|
||||
|
||||
static QVariant percent_string(fraction_t fraction)
|
||||
|
|
|
@ -17,6 +17,19 @@
|
|||
|
||||
QFont defaultModelFont();
|
||||
|
||||
// Encapsulates Boilerplate.
|
||||
class CleanerTableModel : public QAbstractTableModel{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CleanerTableModel();
|
||||
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
protected:
|
||||
void setHeaderDataStrings(const QStringList& headers);
|
||||
private:
|
||||
QStringList headers;
|
||||
};
|
||||
|
||||
/* Encapsulates the tank_info global variable
|
||||
* to show on Qt's Model View System.*/
|
||||
class TankInfoModel : public QAbstractTableModel {
|
||||
|
@ -67,14 +80,12 @@ private:
|
|||
|
||||
/* Encapsulation of the Cylinder Model, that presents the
|
||||
* Current cylinders that are used on a dive. */
|
||||
class CylindersModel : public QAbstractTableModel {
|
||||
class CylindersModel : public CleanerTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Column {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, COLUMNS};
|
||||
enum Column {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE};
|
||||
|
||||
explicit CylindersModel(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*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
/*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
|
|
|
@ -32,7 +32,6 @@ SubsurfaceWebServices::SubsurfaceWebServices(QWidget* parent, Qt::WindowFlags f)
|
|||
ui.userID->setText(s.value("webservice_uid").toString());
|
||||
}
|
||||
|
||||
|
||||
static void clear_table(struct dive_table *table)
|
||||
{
|
||||
int i;
|
||||
|
|
Loading…
Add table
Reference in a new issue