mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Merge branch '119_divecomputerManagement' of github.com:tcanabrava/subsurface
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
commit
f465230263
11 changed files with 242 additions and 6 deletions
2
Makefile
2
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)
|
||||
|
||||
|
||||
|
|
5
device.c
5
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;
|
||||
|
|
1
device.h
1
device.h
|
@ -22,6 +22,7 @@ extern struct device_info *create_device_info(const char *model, uint32_t device
|
|||
extern struct device_info *remove_device_info(const char *model, uint32_t deviceid);
|
||||
extern struct device_info *head_of_device_info_list(void);
|
||||
extern struct divecomputer *fake_dc(struct divecomputer* dc);
|
||||
extern void remove_dive_computer(const char *model, uint32_t deviceid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
44
qt-ui/divecomputermanagementdialog.cpp
Normal file
44
qt-ui/divecomputermanagementdialog.cpp
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
27
qt-ui/divecomputermanagementdialog.h
Normal file
27
qt-ui/divecomputermanagementdialog.h
Normal file
|
@ -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
|
24
qt-ui/divecomputermanagementdialog.ui
Normal file
24
qt-ui/divecomputermanagementdialog.ui
Normal file
|
@ -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>
|
|
@ -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()
|
||||
|
|
114
qt-ui/models.cpp
114
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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue