mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Move DiveComputerModel to qt-models
Another attempt to make it easyer to create the mobile version of Subsurface. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
257f8063c4
commit
a56429d31e
6 changed files with 144 additions and 139 deletions
|
@ -255,6 +255,7 @@ set(SUBSURFACE_MODELS_LIB_SRCS
|
|||
qt-models/tankinfomodel.cpp
|
||||
qt-models/weigthsysteminfomodel.cpp
|
||||
qt-models/weightmodel.cpp
|
||||
qt-models/divecomputermodel.cpp
|
||||
qt-models/divecomputerextradatamodel.cpp
|
||||
qt-models/completionmodels.cpp
|
||||
)
|
||||
|
|
108
qt-models/divecomputermodel.cpp
Normal file
108
qt-models/divecomputermodel.cpp
Normal file
|
@ -0,0 +1,108 @@
|
|||
#include "divecomputermodel.h"
|
||||
#include "dive.h"
|
||||
#include "divelist.h"
|
||||
|
||||
DiveComputerModel::DiveComputerModel(QMultiMap<QString, DiveComputerNode> &dcMap, QObject *parent) : CleanerTableModel()
|
||||
{
|
||||
setHeaderDataStrings(QStringList() << "" << tr("Model") << tr("Device ID") << tr("Nickname"));
|
||||
dcWorkingMap = dcMap;
|
||||
numRows = 0;
|
||||
}
|
||||
|
||||
QVariant DiveComputerModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
QList<DiveComputerNode> values = dcWorkingMap.values();
|
||||
DiveComputerNode node = values.at(index.row());
|
||||
|
||||
QVariant ret;
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||
switch (index.column()) {
|
||||
case ID:
|
||||
ret = QString("0x").append(QString::number(node.deviceId, 16));
|
||||
break;
|
||||
case MODEL:
|
||||
ret = node.model;
|
||||
break;
|
||||
case NICKNAME:
|
||||
ret = node.nickName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index.column() == REMOVE) {
|
||||
switch (role) {
|
||||
case Qt::DecorationRole:
|
||||
ret = trashIcon();
|
||||
break;
|
||||
case Qt::SizeHintRole:
|
||||
ret = trashIcon().size();
|
||||
break;
|
||||
case Qt::ToolTipRole:
|
||||
ret = tr("Clicking here will remove this dive computer.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DiveComputerModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return numRows;
|
||||
}
|
||||
|
||||
void DiveComputerModel::update()
|
||||
{
|
||||
QList<DiveComputerNode> values = dcWorkingMap.values();
|
||||
int count = values.count();
|
||||
|
||||
if (numRows) {
|
||||
beginRemoveRows(QModelIndex(), 0, numRows - 1);
|
||||
numRows = 0;
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
if (count) {
|
||||
beginInsertRows(QModelIndex(), 0, count - 1);
|
||||
numRows = count;
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
|
||||
Qt::ItemFlags DiveComputerModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
||||
if (index.column() == NICKNAME)
|
||||
flags |= Qt::ItemIsEditable;
|
||||
return flags;
|
||||
}
|
||||
|
||||
bool DiveComputerModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
QList<DiveComputerNode> values = dcWorkingMap.values();
|
||||
DiveComputerNode node = values.at(index.row());
|
||||
dcWorkingMap.remove(node.model, node);
|
||||
node.nickName = value.toString();
|
||||
dcWorkingMap.insert(node.model, node);
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DiveComputerModel::remove(const QModelIndex &index)
|
||||
{
|
||||
QList<DiveComputerNode> values = dcWorkingMap.values();
|
||||
DiveComputerNode node = values.at(index.row());
|
||||
dcWorkingMap.remove(node.model, node);
|
||||
update();
|
||||
}
|
||||
|
||||
void DiveComputerModel::dropWorkingList()
|
||||
{
|
||||
// how do I prevent the memory leak ?
|
||||
}
|
||||
|
||||
void DiveComputerModel::keepWorkingList()
|
||||
{
|
||||
if (dcList.dcMap != dcWorkingMap)
|
||||
mark_divelist_changed(true);
|
||||
dcList.dcMap = dcWorkingMap;
|
||||
}
|
34
qt-models/divecomputermodel.h
Normal file
34
qt-models/divecomputermodel.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef DIVECOMPUTERMODEL_H
|
||||
#define DIVECOMPUTERMODEL_H
|
||||
|
||||
#include "cleanertablemodel.h"
|
||||
#include "divecomputer.h"
|
||||
|
||||
class DiveComputerModel : public CleanerTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum {
|
||||
REMOVE,
|
||||
MODEL,
|
||||
ID,
|
||||
NICKNAME
|
||||
};
|
||||
DiveComputerModel(QMultiMap<QString, DiveComputerNode> &dcMap, QObject *parent = 0);
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
void update();
|
||||
void keepWorkingList();
|
||||
void dropWorkingList();
|
||||
|
||||
public
|
||||
slots:
|
||||
void remove(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
int numRows;
|
||||
QMultiMap<QString, DiveComputerNode> dcWorkingMap;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -699,118 +699,6 @@ bool DiveTripModel::setData(const QModelIndex &index, const QVariant &value, int
|
|||
return diveItem->setData(index, value, role);
|
||||
}
|
||||
|
||||
/*####################################################################
|
||||
*
|
||||
* Dive Computer Model
|
||||
*
|
||||
*####################################################################
|
||||
*/
|
||||
|
||||
DiveComputerModel::DiveComputerModel(QMultiMap<QString, DiveComputerNode> &dcMap, QObject *parent) : CleanerTableModel()
|
||||
{
|
||||
setHeaderDataStrings(QStringList() << "" << tr("Model") << tr("Device ID") << tr("Nickname"));
|
||||
dcWorkingMap = dcMap;
|
||||
numRows = 0;
|
||||
}
|
||||
|
||||
QVariant DiveComputerModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
QList<DiveComputerNode> values = dcWorkingMap.values();
|
||||
DiveComputerNode node = values.at(index.row());
|
||||
|
||||
QVariant ret;
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||
switch (index.column()) {
|
||||
case ID:
|
||||
ret = QString("0x").append(QString::number(node.deviceId, 16));
|
||||
break;
|
||||
case MODEL:
|
||||
ret = node.model;
|
||||
break;
|
||||
case NICKNAME:
|
||||
ret = node.nickName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index.column() == REMOVE) {
|
||||
switch (role) {
|
||||
case Qt::DecorationRole:
|
||||
ret = trashIcon();
|
||||
break;
|
||||
case Qt::SizeHintRole:
|
||||
ret = trashIcon().size();
|
||||
break;
|
||||
case Qt::ToolTipRole:
|
||||
ret = tr("Clicking here will remove this dive computer.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DiveComputerModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return numRows;
|
||||
}
|
||||
|
||||
void DiveComputerModel::update()
|
||||
{
|
||||
QList<DiveComputerNode> values = dcWorkingMap.values();
|
||||
int count = values.count();
|
||||
|
||||
if (numRows) {
|
||||
beginRemoveRows(QModelIndex(), 0, numRows - 1);
|
||||
numRows = 0;
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
if (count) {
|
||||
beginInsertRows(QModelIndex(), 0, count - 1);
|
||||
numRows = count;
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
|
||||
Qt::ItemFlags DiveComputerModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
||||
if (index.column() == NICKNAME)
|
||||
flags |= Qt::ItemIsEditable;
|
||||
return flags;
|
||||
}
|
||||
|
||||
bool DiveComputerModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
QList<DiveComputerNode> values = dcWorkingMap.values();
|
||||
DiveComputerNode node = values.at(index.row());
|
||||
dcWorkingMap.remove(node.model, node);
|
||||
node.nickName = value.toString();
|
||||
dcWorkingMap.insert(node.model, node);
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DiveComputerModel::remove(const QModelIndex &index)
|
||||
{
|
||||
QList<DiveComputerNode> values = dcWorkingMap.values();
|
||||
DiveComputerNode node = values.at(index.row());
|
||||
dcWorkingMap.remove(node.model, node);
|
||||
update();
|
||||
}
|
||||
|
||||
void DiveComputerModel::dropWorkingList()
|
||||
{
|
||||
// how do I prevent the memory leak ?
|
||||
}
|
||||
|
||||
void DiveComputerModel::keepWorkingList()
|
||||
{
|
||||
if (dcList.dcMap != dcWorkingMap)
|
||||
mark_divelist_changed(true);
|
||||
dcList.dcMap = dcWorkingMap;
|
||||
}
|
||||
|
||||
/*#################################################################
|
||||
* #
|
||||
* # Yearly Statistics Model
|
||||
|
|
|
@ -138,33 +138,6 @@ private:
|
|||
Layout currentLayout;
|
||||
};
|
||||
|
||||
class DiveComputerModel : public CleanerTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum {
|
||||
REMOVE,
|
||||
MODEL,
|
||||
ID,
|
||||
NICKNAME
|
||||
};
|
||||
DiveComputerModel(QMultiMap<QString, DiveComputerNode> &dcMap, QObject *parent = 0);
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
void update();
|
||||
void keepWorkingList();
|
||||
void dropWorkingList();
|
||||
|
||||
public
|
||||
slots:
|
||||
void remove(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
int numRows;
|
||||
QMultiMap<QString, DiveComputerNode> dcWorkingMap;
|
||||
};
|
||||
|
||||
class YearlyStatisticsModel : public TreeModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "divecomputermanagementdialog.h"
|
||||
#include "mainwindow.h"
|
||||
#include "helpers.h"
|
||||
#include "divecomputermodel.h"
|
||||
#include "models.h"
|
||||
#include <QMessageBox>
|
||||
#include <QShortcut>
|
||||
|
|
Loading…
Reference in a new issue