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/models.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'qt-ui/models.cpp') 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(); + } + +} -- cgit v1.2.3-70-g09d2 From 24446f9c3ce3b48c59b2ceb212b7ac49eb6dbff7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 7 Jun 2013 12:57:35 -0300 Subject: Edit the name of the Dive Computer via dialog. The GTK version seems to be bugged on this, since the dialog doesn't save the dive computer nickname that I setted, but the Qt version shows less dive-computers than the GTK one on the same dive. I want somebody to do a quick review of my code too. :) I also plan to remove the 'OK' and 'Cancel' buttom, they seem to be overrated on this dialog - fairly uneeded. Signed-off-by: Tomaz Canabrava --- qt-ui/models.cpp | 23 ++++++++++++++++++++--- qt-ui/models.h | 2 ++ 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'qt-ui/models.cpp') diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 1fc2515c6..787dbd8cf 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -1173,18 +1173,35 @@ void DiveComputerModel::update() 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(); } +} + +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? } diff --git a/qt-ui/models.h b/qt-ui/models.h index c0625325f..7a32998ce 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -177,6 +177,8 @@ public: 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(); private: int numRows; -- cgit v1.2.3-70-g09d2 From 478c24d79795b34efb42c1ac29abd8fa777b9c90 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 7 Jun 2013 14:59:06 -0300 Subject: Removed the buttons on the Edit Dive computers. This edit dive computers thing doesn't really need buttons anyway. Signed-off-by: Tomaz Canabrava --- qt-gui.cpp | 1 + qt-ui/divecomputermanagementdialog.ui | 45 +---------------------------------- qt-ui/models.cpp | 2 ++ 3 files changed, 4 insertions(+), 44 deletions(-) (limited to 'qt-ui/models.cpp') diff --git a/qt-gui.cpp b/qt-gui.cpp index bab27a318..d85198d68 100644 --- a/qt-gui.cpp +++ b/qt-gui.cpp @@ -157,6 +157,7 @@ const char *get_dc_nickname(const char *model, uint32_t deviceid) void set_dc_nickname(struct dive *dive) { /* needs Qt implementation */ + /*well, I don't know how to do this here... = ( */ } QString get_depth_string(depth_t depth, bool showunit) diff --git a/qt-ui/divecomputermanagementdialog.ui b/qt-ui/divecomputermanagementdialog.ui index abda9f5ce..6685e842e 100644 --- a/qt-ui/divecomputermanagementdialog.ui +++ b/qt-ui/divecomputermanagementdialog.ui @@ -17,51 +17,8 @@ - - - - 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/models.cpp b/qt-ui/models.cpp index 787dbd8cf..6cb1fa079 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -1198,10 +1198,12 @@ 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? } -- cgit v1.2.3-70-g09d2 From 54128aa52fe5c765ce6ced8bd05611e202195d6b Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 7 Jun 2013 15:25:29 -0300 Subject: Added the code to remove a dive computer. Added the code to remove a dive computer, plus a few fixes Signed-off-by: Tomaz Canabrava --- device.c | 5 +++++ device.h | 1 + gtk-gui.c | 5 ----- qt-ui/models.cpp | 12 ++++++++++++ qt-ui/models.h | 3 +++ 5 files changed, 21 insertions(+), 5 deletions(-) (limited to 'qt-ui/models.cpp') diff --git a/device.c b/device.c index 660cfc1ab..52c49a5bd 100644 --- a/device.c +++ b/device.c @@ -9,6 +9,11 @@ struct device_info *head_of_device_info_list(void) return device_info_list; } +void remove_dive_computer(const char *model, uint32_t deviceid) +{ + free(remove_device_info(model, deviceid)); +} + static int match_device_info(struct device_info *entry, const char *model, uint32_t deviceid) { return !strcmp(entry->model, model) && entry->deviceid == deviceid; diff --git a/device.h b/device.h index 636eb73c6..3efa42900 100644 --- a/device.h +++ b/device.h @@ -20,6 +20,7 @@ extern struct device_info *get_different_device_info(const char *model, uint32_t extern struct device_info *create_device_info(const char *model, uint32_t deviceid); extern struct device_info *remove_device_info(const char *model, uint32_t deviceid); extern struct device_info *head_of_device_info_list(void); +extern void remove_dive_computer(const char *model, uint32_t deviceid); #ifdef __cplusplus } diff --git a/gtk-gui.c b/gtk-gui.c index 666438c33..e873fc622 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -101,11 +101,6 @@ static void remember_dc(const char *model, uint32_t deviceid, const char *nickna nn_entry->nickname = strdup(nickname); } -static void remove_dc(const char *model, uint32_t deviceid) -{ - free(remove_device_info(model, deviceid)); -} - static GtkWidget *dive_profile; GtkActionGroup *action_group; diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 6cb1fa079..868cba952 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -8,6 +8,7 @@ #include "../helpers.h" #include "../dive.h" #include "../device.h" + #include #include #include @@ -1203,7 +1204,18 @@ bool DiveComputerModel::setData(const QModelIndex& index, const QVariant& value, 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 7a32998ce..5a7d2b214 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -180,6 +180,9 @@ public: 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; -- cgit v1.2.3-70-g09d2