diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-07 11:43:45 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-07 11:43:45 -0300 |
commit | ebed836ee5d10659ae3d830704508f9c575181d3 (patch) | |
tree | 00efafb0433e7dc6e6f9a2c99be3b12b06a69e06 /qt-ui/models.cpp | |
parent | 3677f4e5ead410d4023668420ca4f062c4223888 (diff) | |
download | subsurface-ebed836ee5d10659ae3d830704508f9c575181d3.tar.gz |
Created a new dialog - Edit DiveComputer
Created a new dialog, Edit Divecomputer, it will currently only lists
the divecomputers that are used on the xml file. I used the same method
that the gtk version used, but only 2 divecomputers got visualized in the
dirk dive data. I'll assume that it's correct and will fix it in the next
couple of commits.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 045592deb..1fc2515c6 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -7,6 +7,7 @@ #include "models.h" #include "../helpers.h" #include "../dive.h" +#include "../device.h" #include <QCoreApplication> #include <QDebug> #include <QColor> @@ -1105,3 +1106,85 @@ void DiveTripModel::setLayout(DiveTripModel::Layout layout) currentLayout = layout; setupModelData(); } + +/*#################################################################### + * + * Dive Computer Model + * + *#################################################################### + */ + +DiveComputerModel::DiveComputerModel(QObject* parent): QAbstractTableModel(parent) +{ + +} + +int DiveComputerModel::columnCount(const QModelIndex& parent) const +{ + return COLUMNS; +} + +QVariant DiveComputerModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + QVariant ret; + if (role != Qt::DisplayRole || orientation != Qt::Horizontal){ + return ret; + } + switch(section){ + case ID : ret = tr("Device ID"); break; + case MODEL : ret = tr("Model"); break; + case NICKNAME : ret = tr("Nickname"); break; + } + return ret; +} + +QVariant DiveComputerModel::data(const QModelIndex& index, int role) const +{ + struct device_info *device = head_of_device_info_list(); + for(int i = 0; i < index.row(); i++){ + device = device->next; + } + + QVariant ret; + if (role == Qt::DisplayRole || role == Qt::EditRole){ + switch(index.column()){ + case ID : ret = device->deviceid; break; + case MODEL : ret = device->model; break; + case NICKNAME : ret = device->nickname; break; + } + } + + if (role == Qt::DecorationRole && index.column() == REMOVE){ + ret = QIcon(":trash"); + } + return ret; +} + +int DiveComputerModel::rowCount(const QModelIndex& parent) const +{ + return numRows; +} + +void DiveComputerModel::update() +{ + int count = 0; + struct device_info *nnl = head_of_device_info_list(); + while (nnl) { + nnl = nnl->next; + count++; + } + qDebug() << "Numero de Devices" << count; + + if(numRows){ + beginRemoveRows(QModelIndex(), 0, numRows-1); + numRows = 0; + endRemoveRows(); + } + + if (count){ + beginInsertRows(QModelIndex(), 0, count-1); + numRows = count; + endInsertRows(); + } + +} |