Move CleanerTableModel to its own file

models.h / .cpp was getting too big (around 2.5k lines), and each change
triggered a rebuild in tons of parts of Subsurface, this is the first
commit trying to make the models code sane by removing them all of the
models.h/cpp file and also clearning code in the process.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-05-28 15:00:58 -03:00 committed by Dirk Hohndel
parent 338c0f22aa
commit 6e4aa7d044
5 changed files with 63 additions and 46 deletions

View file

@ -247,6 +247,7 @@ endif()
# the data models that will interface
# with the views.
set(SUBSURFACE_MODELS_LIB_SRCS
qt-models/cleanertablemodel.cpp
qt-models/models.cpp
qt-models/filtermodels.cpp
qt-models/completionmodels.cpp

View file

@ -0,0 +1,33 @@
#include "cleanertablemodel.h"
#include "metrics.h"
CleanerTableModel::CleanerTableModel(QObject *parent) : QAbstractTableModel(parent)
{
}
int CleanerTableModel::columnCount(const QModelIndex &parent) const
{
return headers.count();
}
QVariant CleanerTableModel::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:
ret = headers.at(section);
}
return ret;
}
void CleanerTableModel::setHeaderDataStrings(const QStringList &newHeaders)
{
headers = newHeaders;
}

View file

@ -0,0 +1,27 @@
#ifndef CLEANERTABLEMODEL_H
#define CLEANERTABLEMODEL_H
#include <QAbstractTableModel>
#include <QStringList>
/* When using a QAbstractTableModel, consider using this instead
* of the default implementation, as it's easyer to setup the columns
* and headers.
* Most subsurface classes uses this one to save loads of lines
* of code and share a consistent layout. */
class CleanerTableModel : public QAbstractTableModel {
Q_OBJECT
public:
explicit CleanerTableModel(QObject *parent = 0);
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;
};
#endif

View file

@ -15,6 +15,7 @@
#include "gettextfromc.h"
#include "display.h"
#include "color.h"
#include "cleanertablemodel.h"
#include <QCoreApplication>
#include <QDebug>
@ -27,37 +28,6 @@
#include <QMessageBox>
#include <QStringListModel>
CleanerTableModel::CleanerTableModel(QObject *parent) : QAbstractTableModel(parent)
{
}
int CleanerTableModel::columnCount(const QModelIndex &parent) const
{
return headers.count();
}
QVariant CleanerTableModel::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:
ret = headers.at(section);
}
return ret;
}
void CleanerTableModel::setHeaderDataStrings(const QStringList &newHeaders)
{
headers = newHeaders;
}
static QPixmap *trashIconPixmap;
// initialize the trash icon if necessary

View file

@ -18,21 +18,7 @@
#include "../dive.h"
#include "../divelist.h"
#include "../divecomputer.h"
// Encapsulates Boilerplate.
class CleanerTableModel : public QAbstractTableModel {
Q_OBJECT
public:
explicit CleanerTableModel(QObject *parent = 0);
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;
};
#include "cleanertablemodel.h"
/* Encapsulates the tank_info global variable
* to show on Qt's Model View System.*/