summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-07 11:43:45 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-07 11:43:45 -0300
commitebed836ee5d10659ae3d830704508f9c575181d3 (patch)
tree00efafb0433e7dc6e6f9a2c99be3b12b06a69e06
parent3677f4e5ead410d4023668420ca4f062c4223888 (diff)
downloadsubsurface-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>
-rw-r--r--Makefile2
-rw-r--r--qt-ui/divecomputermanagementdialog.cpp22
-rw-r--r--qt-ui/divecomputermanagementdialog.h22
-rw-r--r--qt-ui/divecomputermanagementdialog.ui67
-rw-r--r--qt-ui/mainwindow.cpp5
-rw-r--r--qt-ui/models.cpp83
-rw-r--r--qt-ui/models.h16
7 files changed, 216 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index ab4c8b2ef..870c832bb 100644
--- a/Makefile
+++ b/Makefile
@@ -49,6 +49,7 @@ HEADERS = \
qt-ui/preferences.h \
qt-ui/simplewidgets.h \
qt-ui/subsurfacewebservices.h \
+ qt-ui/divecomputermanagementdialog.h \
SOURCES = \
@@ -82,6 +83,7 @@ SOURCES = \
qt-ui/preferences.cpp \
qt-ui/simplewidgets.cpp \
qt-ui/subsurfacewebservices.cpp \
+ qt-ui/divecomputermanagementdialog.cpp \
$(RESFILE)
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 <QDialog>
+
+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 @@
+<?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>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>DiveComputerManagementDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>DiveComputerManagementDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
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 <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();
+ }
+
+}
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