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>
This commit is contained in:
Tomaz Canabrava 2013-06-07 11:43:45 -03:00
parent 3677f4e5ea
commit ebed836ee5
7 changed files with 216 additions and 1 deletions

View file

@ -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();
}
}