aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/divecomputermanagementdialog.cpp44
-rw-r--r--qt-ui/divecomputermanagementdialog.h27
-rw-r--r--qt-ui/divecomputermanagementdialog.ui24
-rw-r--r--qt-ui/mainwindow.cpp4
-rw-r--r--qt-ui/models.cpp114
-rw-r--r--qt-ui/models.h21
6 files changed, 233 insertions, 1 deletions
diff --git a/qt-ui/divecomputermanagementdialog.cpp b/qt-ui/divecomputermanagementdialog.cpp
new file mode 100644
index 000000000..7a96b4c63
--- /dev/null
+++ b/qt-ui/divecomputermanagementdialog.cpp
@@ -0,0 +1,44 @@
+#include "divecomputermanagementdialog.h"
+#include "models.h"
+#include "ui_divecomputermanagementdialog.h"
+#include "mainwindow.h"
+#include <QMessageBox>
+
+DiveComputerManagementDialog::DiveComputerManagementDialog(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f)
+, ui( new Ui::DiveComputerManagementDialog())
+{
+ ui->setupUi(this);
+ model = new DiveComputerModel();
+ ui->tableView->setModel(model);
+ connect(ui->tableView, SIGNAL(clicked(QModelIndex)), this, SLOT(tryRemove(QModelIndex)));
+ ui->tableView->setColumnWidth(DiveComputerModel::REMOVE, 22);
+}
+
+DiveComputerManagementDialog* DiveComputerManagementDialog::instance()
+{
+ static DiveComputerManagementDialog *self = new DiveComputerManagementDialog();
+ return self;
+}
+
+void DiveComputerManagementDialog::update()
+{
+ model->update();
+}
+
+void DiveComputerManagementDialog::tryRemove(const QModelIndex& index)
+{
+ if (index.column() != DiveComputerModel::REMOVE){
+ return;
+ }
+
+ QMessageBox::StandardButton response = QMessageBox::question(
+ this,
+ tr("Remove the selected Dive Computer?"),
+ tr("Are you sure that you want to \n remove the selected dive computer?"),
+ QMessageBox::Ok | QMessageBox::Cancel
+ );
+
+ if (response == QMessageBox::Ok){
+ model->remove(index);
+ }
+}
diff --git a/qt-ui/divecomputermanagementdialog.h b/qt-ui/divecomputermanagementdialog.h
new file mode 100644
index 000000000..e10a96db2
--- /dev/null
+++ b/qt-ui/divecomputermanagementdialog.h
@@ -0,0 +1,27 @@
+#ifndef DIVECOMPUTERMANAGEMENTDIALOG_H
+#define DIVECOMPUTERMANAGEMENTDIALOG_H
+#include <QDialog>
+
+class QModelIndex;
+class DiveComputerModel;
+namespace Ui{
+ class DiveComputerManagementDialog;
+};
+
+class DiveComputerManagementDialog : public QDialog{
+Q_OBJECT
+
+public:
+ static DiveComputerManagementDialog *instance();
+ void update();
+
+public slots:
+ void tryRemove(const QModelIndex& index);
+
+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..6685e842e
--- /dev/null
+++ b/qt-ui/divecomputermanagementdialog.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DiveComputerManagementDialog</class>
+ <widget class="QDialog" name="DiveComputerManagementDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QTableView" name="tableView"/>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 8b216bd8c..53546fa67 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;
@@ -204,7 +205,8 @@ 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 6d6459983..03300a8d6 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -7,6 +7,8 @@
#include "models.h"
#include "../helpers.h"
#include "../dive.h"
+#include "../device.h"
+
#include <QCoreApplication>
#include <QDebug>
#include <QColor>
@@ -1152,3 +1154,115 @@ 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++;
+ }
+
+ 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)
+{
+ struct device_info *nnl = head_of_device_info_list();
+
+ for(int i = 0; i < index.row(); i++){
+ nnl = nnl->next;
+ }
+
+
+ QByteArray v = value.toByteArray();
+ nnl->nickname = strdup(v.data()); // how should I free this before setting a new one?
+ // set_dc_nickname(dive); -> should this be used instead?
+
+ return true;
+}
+
+void DiveComputerModel::remove(const QModelIndex& i)
+{
+ QByteArray model = data(index(i.row(), (int)MODEL)).toByteArray();
+ uint32_t deviceid = data(index(i.row(), (int) ID)).toUInt();
+ remove_dive_computer(model.data(), deviceid);
+ update();
+}
diff --git a/qt-ui/models.h b/qt-ui/models.h
index 79af13bed..b61c79cd6 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -172,4 +172,25 @@ 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;
+ virtual Qt::ItemFlags flags(const QModelIndex& index) const;
+ virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
+ void update();
+
+public slots:
+ void remove(const QModelIndex& index);
+private:
+ int numRows;
+
+};
+
#endif