From ebed836ee5d10659ae3d830704508f9c575181d3 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 7 Jun 2013 11:43:45 -0300 Subject: 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 --- qt-ui/divecomputermanagementdialog.cpp | 22 +++++++++ qt-ui/divecomputermanagementdialog.h | 22 +++++++++ qt-ui/divecomputermanagementdialog.ui | 67 +++++++++++++++++++++++++++ qt-ui/mainwindow.cpp | 5 +- qt-ui/models.cpp | 83 ++++++++++++++++++++++++++++++++++ qt-ui/models.h | 16 +++++++ 6 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 qt-ui/divecomputermanagementdialog.cpp create mode 100644 qt-ui/divecomputermanagementdialog.h create mode 100644 qt-ui/divecomputermanagementdialog.ui (limited to 'qt-ui') diff --git a/qt-ui/divecomputermanagementdialog.cpp b/qt-ui/divecomputermanagementdialog.cpp new file mode 100644 index 000000000..867ca2d49 --- /dev/null +++ b/qt-ui/divecomputermanagementdialog.cpp @@ -0,0 +1,22 @@ +#include "divecomputermanagementdialog.h" +#include "models.h" +#include "ui_divecomputermanagementdialog.h" + +DiveComputerManagementDialog::DiveComputerManagementDialog(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f) +, ui( new Ui::DiveComputerManagementDialog()) +{ + ui->setupUi(this); + model = new DiveComputerModel(); + ui->tableView->setModel(model); +} + +DiveComputerManagementDialog* DiveComputerManagementDialog::instance() +{ + static DiveComputerManagementDialog *self = new DiveComputerManagementDialog(); + return self; +} + +void DiveComputerManagementDialog::update() +{ + model->update(); +} diff --git a/qt-ui/divecomputermanagementdialog.h b/qt-ui/divecomputermanagementdialog.h new file mode 100644 index 000000000..27a1408ab --- /dev/null +++ b/qt-ui/divecomputermanagementdialog.h @@ -0,0 +1,22 @@ +#ifndef DIVECOMPUTERMANAGEMENTDIALOG_H +#define DIVECOMPUTERMANAGEMENTDIALOG_H +#include + +class DiveComputerModel; +namespace Ui{ + class DiveComputerManagementDialog; +}; + +class DiveComputerManagementDialog : public QDialog{ +Q_OBJECT + +public: + static DiveComputerManagementDialog *instance(); + void update(); +private: + explicit DiveComputerManagementDialog(QWidget* parent = 0, Qt::WindowFlags f = 0); + Ui::DiveComputerManagementDialog *ui; + DiveComputerModel *model; +}; + +#endif \ No newline at end of file diff --git a/qt-ui/divecomputermanagementdialog.ui b/qt-ui/divecomputermanagementdialog.ui new file mode 100644 index 000000000..abda9f5ce --- /dev/null +++ b/qt-ui/divecomputermanagementdialog.ui @@ -0,0 +1,67 @@ + + + DiveComputerManagementDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DiveComputerManagementDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DiveComputerManagementDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 286aba43e..a927c0231 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -29,6 +29,7 @@ #include "downloadfromdivecomputer.h" #include "preferences.h" #include "subsurfacewebservices.h" +#include "divecomputermanagementdialog.h" static MainWindow* instance = 0; @@ -187,7 +188,9 @@ void MainWindow::on_actionDownloadWeb_triggered() void MainWindow::on_actionEditDeviceNames_triggered() { - qDebug("actionEditDeviceNames");} + DiveComputerManagementDialog::instance()->update(); + DiveComputerManagementDialog::instance()->show(); +} void MainWindow::on_actionAddDive_triggered() { 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 #include #include @@ -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(); + } + +} diff --git a/qt-ui/models.h b/qt-ui/models.h index a012ec6bd..c0625325f 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -167,4 +167,20 @@ private: Layout currentLayout; }; +class DiveComputerModel : public QAbstractTableModel +{ + Q_OBJECT +public: + enum {REMOVE, MODEL, ID, NICKNAME, COLUMNS}; + explicit DiveComputerModel(QObject* parent = 0); + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; + virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; + virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; + void update(); +private: + int numRows; + +}; + #endif -- cgit v1.2.3-70-g09d2