mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
338c0f22aa
commit
6e4aa7d044
5 changed files with 63 additions and 46 deletions
|
@ -247,6 +247,7 @@ endif()
|
||||||
# the data models that will interface
|
# the data models that will interface
|
||||||
# with the views.
|
# with the views.
|
||||||
set(SUBSURFACE_MODELS_LIB_SRCS
|
set(SUBSURFACE_MODELS_LIB_SRCS
|
||||||
|
qt-models/cleanertablemodel.cpp
|
||||||
qt-models/models.cpp
|
qt-models/models.cpp
|
||||||
qt-models/filtermodels.cpp
|
qt-models/filtermodels.cpp
|
||||||
qt-models/completionmodels.cpp
|
qt-models/completionmodels.cpp
|
||||||
|
|
33
qt-models/cleanertablemodel.cpp
Normal file
33
qt-models/cleanertablemodel.cpp
Normal 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;
|
||||||
|
}
|
27
qt-models/cleanertablemodel.h
Normal file
27
qt-models/cleanertablemodel.h
Normal 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
|
|
@ -15,6 +15,7 @@
|
||||||
#include "gettextfromc.h"
|
#include "gettextfromc.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
|
#include "cleanertablemodel.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -27,37 +28,6 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QStringListModel>
|
#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;
|
static QPixmap *trashIconPixmap;
|
||||||
|
|
||||||
// initialize the trash icon if necessary
|
// initialize the trash icon if necessary
|
||||||
|
|
|
@ -18,21 +18,7 @@
|
||||||
#include "../dive.h"
|
#include "../dive.h"
|
||||||
#include "../divelist.h"
|
#include "../divelist.h"
|
||||||
#include "../divecomputer.h"
|
#include "../divecomputer.h"
|
||||||
|
#include "cleanertablemodel.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;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Encapsulates the tank_info global variable
|
/* Encapsulates the tank_info global variable
|
||||||
* to show on Qt's Model View System.*/
|
* to show on Qt's Model View System.*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue