summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/divecomputermanagementdialog.cpp32
-rw-r--r--qt-ui/divecomputermanagementdialog.h5
-rw-r--r--qt-ui/divecomputermanagementdialog.ui47
-rw-r--r--qt-ui/mainwindow.cpp1
-rw-r--r--qt-ui/models.cpp63
-rw-r--r--qt-ui/models.h21
-rw-r--r--qt-ui/profilegraphics.cpp3
7 files changed, 124 insertions, 48 deletions
diff --git a/qt-ui/divecomputermanagementdialog.cpp b/qt-ui/divecomputermanagementdialog.cpp
index 4d9770a4d..2a1bb8bff 100644
--- a/qt-ui/divecomputermanagementdialog.cpp
+++ b/qt-ui/divecomputermanagementdialog.cpp
@@ -3,16 +3,26 @@
#include "ui_divecomputermanagementdialog.h"
#include "mainwindow.h"
#include <QMessageBox>
+#include "../qthelper.h"
+#include "../helpers.h"
-DiveComputerManagementDialog::DiveComputerManagementDialog(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f)
-, ui( new Ui::DiveComputerManagementDialog())
+DiveComputerManagementDialog::DiveComputerManagementDialog(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f),
+ ui( new Ui::DiveComputerManagementDialog()),
+ model(0)
{
ui->setupUi(this);
- model = new DiveComputerModel();
- ui->tableView->setModel(model);
+ init();
connect(ui->tableView, SIGNAL(clicked(QModelIndex)), this, SLOT(tryRemove(QModelIndex)));
}
+void DiveComputerManagementDialog::init()
+{
+ if (model)
+ delete model;
+ model = new DiveComputerModel(dcList.dcMap);
+ ui->tableView->setModel(model);
+}
+
DiveComputerManagementDialog* DiveComputerManagementDialog::instance()
{
static DiveComputerManagementDialog *self = new DiveComputerManagementDialog();
@@ -44,3 +54,17 @@ void DiveComputerManagementDialog::tryRemove(const QModelIndex& index)
model->remove(index);
}
}
+
+void DiveComputerManagementDialog::accept()
+{
+ model->keepWorkingList();
+ hide();
+ close();
+}
+
+void DiveComputerManagementDialog::reject()
+{
+ model->dropWorkingList();
+ hide();
+ close();
+}
diff --git a/qt-ui/divecomputermanagementdialog.h b/qt-ui/divecomputermanagementdialog.h
index e10a96db2..72d48cd2a 100644
--- a/qt-ui/divecomputermanagementdialog.h
+++ b/qt-ui/divecomputermanagementdialog.h
@@ -14,9 +14,12 @@ Q_OBJECT
public:
static DiveComputerManagementDialog *instance();
void update();
+ void init();
public slots:
void tryRemove(const QModelIndex& index);
+ void accept();
+ void reject();
private:
explicit DiveComputerManagementDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
@@ -24,4 +27,4 @@ private:
DiveComputerModel *model;
};
-#endif \ No newline at end of file
+#endif
diff --git a/qt-ui/divecomputermanagementdialog.ui b/qt-ui/divecomputermanagementdialog.ui
index ae011fc9c..8b916f925 100644
--- a/qt-ui/divecomputermanagementdialog.ui
+++ b/qt-ui/divecomputermanagementdialog.ui
@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
- <string>Dialog</string>
+ <string>Edit Dive Computer Nicknames</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
@@ -21,8 +21,51 @@
</attribute>
</widget>
</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/>
+ <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 f477a0d4f..2ab3a6771 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -206,6 +206,7 @@ void MainWindow::on_actionDownloadWeb_triggered()
void MainWindow::on_actionEditDeviceNames_triggered()
{
+ DiveComputerManagementDialog::instance()->init();
DiveComputerManagementDialog::instance()->update();
DiveComputerManagementDialog::instance()->show();
}
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 9e076930d..c56fa2f44 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -8,7 +8,7 @@
#include "../helpers.h"
#include "../dive.h"
#include "../device.h"
-
+#include "../qthelper.h"
#include <QCoreApplication>
#include <QDebug>
#include <QColor>
@@ -1162,9 +1162,10 @@ void DiveTripModel::setLayout(DiveTripModel::Layout layout)
*####################################################################
*/
-DiveComputerModel::DiveComputerModel(QObject* parent): QAbstractTableModel(parent)
+DiveComputerModel::DiveComputerModel(QMultiMap<QString, DiveComputerNode> &dcMap, QObject* parent): QAbstractTableModel(parent)
{
-
+ dcWorkingMap = dcMap;
+ numRows = 0;
}
int DiveComputerModel::columnCount(const QModelIndex& parent) const
@@ -1188,17 +1189,15 @@ QVariant DiveComputerModel::headerData(int section, Qt::Orientation orientation,
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;
- }
+ QList<DiveComputerNode> values = dcWorkingMap.values();
+ DiveComputerNode node = values.at(index.row());
QVariant ret;
if (role == Qt::DisplayRole || role == Qt::EditRole){
switch(index.column()){
- case ID: ret = QString("0x").append(QString::number(device->deviceid, 16)); break;
- case MODEL: ret = device->model; break;
- case NICKNAME: ret = device->nickname; break;
+ case ID: ret = QString("0x").append(QString::number(node.deviceId, 16)); break;
+ case MODEL: ret = node.model; break;
+ case NICKNAME: ret = node.nickName; break;
}
}
@@ -1215,12 +1214,8 @@ int DiveComputerModel::rowCount(const QModelIndex& parent) const
void DiveComputerModel::update()
{
- int count = 0;
- struct device_info *nnl = head_of_device_info_list();
- while (nnl) {
- nnl = nnl->next;
- count++;
- }
+ QList<DiveComputerNode> values = dcWorkingMap.values();
+ int count = values.count();
if(numRows){
beginRemoveRows(QModelIndex(), 0, numRows-1);
@@ -1245,24 +1240,30 @@ Qt::ItemFlags DiveComputerModel::flags(const QModelIndex& index) const
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?
-
+ QList<DiveComputerNode> values = dcWorkingMap.values();
+ DiveComputerNode node = values.at(index.row());
+ dcWorkingMap.remove(node.model, node);
+ node.nickName = value.toString();
+ dcWorkingMap.insert(node.model, node);
return true;
}
-void DiveComputerModel::remove(const QModelIndex& i)
+void DiveComputerModel::remove(const QModelIndex& index)
{
- 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);
+ QList<DiveComputerNode> values = dcWorkingMap.values();
+ DiveComputerNode node = values.at(index.row());
+ dcWorkingMap.remove(node.model, node);
update();
}
+
+void DiveComputerModel::dropWorkingList()
+{
+ // how do I prevent the memory leak ?
+}
+
+void DiveComputerModel::keepWorkingList()
+{
+ if (dcList.dcMap != dcWorkingMap)
+ mark_divelist_changed(TRUE);
+ dcList.dcMap = dcWorkingMap;
+}
diff --git a/qt-ui/models.h b/qt-ui/models.h
index b61c79cd6..e371ce1ea 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -13,6 +13,7 @@
#include "../dive.h"
#include "../divelist.h"
+#include "../qthelper.h"
QFont defaultModelFont();
@@ -177,20 +178,22 @@ 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);
+ DiveComputerModel(QMultiMap<QString, DiveComputerNode> &dcMap, 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();
-
+ void keepWorkingList();
+ void dropWorkingList();
+
public slots:
void remove(const QModelIndex& index);
private:
int numRows;
-
+ QMultiMap<QString, DiveComputerNode> dcWorkingMap;
};
#endif
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index 126690750..e580a2b44 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -21,6 +21,7 @@
#include "../dive.h"
#include "../profile.h"
#include "../device.h"
+#include "../helpers.h"
#include <libdivecomputer/parser.h>
#include <libdivecomputer/version.h>
@@ -273,7 +274,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
dc = fake_dc(dc);
}
- QString nick(get_dc_nickname(dc->model, dc->deviceid));
+ QString nick = get_dc_nickname(dc->model, dc->deviceid);
if (nick.isEmpty())
nick = QString(dc->model);