mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Merge branch 'tomaz'
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
commit
9d622996ba
12 changed files with 208 additions and 266 deletions
|
@ -574,7 +574,7 @@ if(NOT NO_DOCS)
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
documentation ALL
|
documentation ALL
|
||||||
COMMAND
|
COMMAND
|
||||||
make -C ${CMAKE_SOURCE_DIR}/Documentation OUT=${CMAKE_BINARY_DIR}/Documentation/ doc
|
${MAKE} -C ${CMAKE_SOURCE_DIR}/Documentation OUT=${CMAKE_BINARY_DIR}/Documentation/ doc
|
||||||
DEPENDS documentationLink
|
DEPENDS documentationLink
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
16
divesite.c
16
divesite.c
|
@ -200,3 +200,19 @@ void clear_dive_site(struct dive_site *ds)
|
||||||
ds->taxonomy.nr = 0;
|
ds->taxonomy.nr = 0;
|
||||||
free_taxonomy(&ds->taxonomy);
|
free_taxonomy(&ds->taxonomy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t find_or_create_dive_site_with_name(const char *name)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct dive_site *ds;
|
||||||
|
bool found = false;
|
||||||
|
for_each_dive_site(i,ds) {
|
||||||
|
if (same_string(name, ds->name)) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ds)
|
||||||
|
return ds->uuid;
|
||||||
|
return create_dive_site(name);
|
||||||
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ bool dive_site_is_empty(struct dive_site *ds);
|
||||||
void copy_dive_site(struct dive_site *orig, struct dive_site *copy);
|
void copy_dive_site(struct dive_site *orig, struct dive_site *copy);
|
||||||
void clear_dive_site(struct dive_site *ds);
|
void clear_dive_site(struct dive_site *ds);
|
||||||
unsigned int get_distance(degrees_t lat1, degrees_t lon1, degrees_t lat2, degrees_t lon2);
|
unsigned int get_distance(degrees_t lat1, degrees_t lon1, degrees_t lat2, degrees_t lon2);
|
||||||
|
uint32_t find_or_create_dive_site_with_name(const char *name);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "divelocationmodel.h"
|
#include "divelocationmodel.h"
|
||||||
#include "dive.h"
|
#include "dive.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QIcon>
|
||||||
|
|
||||||
bool dive_site_less_than(dive_site *a, dive_site *b)
|
bool dive_site_less_than(dive_site *a, dive_site *b)
|
||||||
{
|
{
|
||||||
|
@ -13,7 +15,9 @@ LocationInformationModel *LocationInformationModel::instance()
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractTableModel(obj), internalRowCount(0)
|
LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractTableModel(obj),
|
||||||
|
internalRowCount(0),
|
||||||
|
textField(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,19 +29,45 @@ int LocationInformationModel::columnCount(const QModelIndex &parent) const
|
||||||
int LocationInformationModel::rowCount(const QModelIndex &parent) const
|
int LocationInformationModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
return internalRowCount;
|
return internalRowCount + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
|
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
struct dive_site *ds = get_dive_site(index.row());
|
|
||||||
|
// Special case to handle the 'create dive site' with name.
|
||||||
|
if (index.row() == 0) {
|
||||||
|
if (index.column() == UUID)
|
||||||
|
return 0;
|
||||||
|
switch(role) {
|
||||||
|
case Qt::DisplayRole : {
|
||||||
|
struct dive_site *ds;
|
||||||
|
int i;
|
||||||
|
for_each_dive_site(i, ds) {
|
||||||
|
QString dsName(ds->name);
|
||||||
|
if (dsName.startsWith(textField->text()))
|
||||||
|
return dsName;
|
||||||
|
}
|
||||||
|
return textField->text();
|
||||||
|
}
|
||||||
|
case Qt::ToolTipRole : {
|
||||||
|
return QString(tr("Create dive site"));
|
||||||
|
}
|
||||||
|
case Qt::EditRole : return textField->text();
|
||||||
|
case Qt::DecorationRole : return QIcon(":plus");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The dive sites are -1 because of the first item.
|
||||||
|
struct dive_site *ds = get_dive_site(index.row()-1);
|
||||||
|
|
||||||
if (!ds)
|
if (!ds)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
switch(role) {
|
switch(role) {
|
||||||
|
case Qt::EditRole:
|
||||||
case Qt::DisplayRole :
|
case Qt::DisplayRole :
|
||||||
switch(index.column()) {
|
switch(index.column()) {
|
||||||
case UUID: return ds->uuid;
|
case UUID: return ds->uuid;
|
||||||
|
@ -52,11 +82,22 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
|
||||||
case TAXONOMY_3: return "TODO";
|
case TAXONOMY_3: return "TODO";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Qt::DecorationRole : {
|
||||||
|
if (dive_site_has_gps_location(ds))
|
||||||
|
return QIcon(":geocode");
|
||||||
|
else
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocationInformationModel::setFirstRowTextField(QLineEdit *t)
|
||||||
|
{
|
||||||
|
textField = t;
|
||||||
|
}
|
||||||
|
|
||||||
void LocationInformationModel::update()
|
void LocationInformationModel::update()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
@ -71,7 +112,7 @@ int32_t LocationInformationModel::addDiveSite(const QString& name, int lon, int
|
||||||
latitude.udeg = lat;
|
latitude.udeg = lat;
|
||||||
longitude.udeg = lon;
|
longitude.udeg = lon;
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), dive_site_table.nr, dive_site_table.nr);
|
beginInsertRows(QModelIndex(), dive_site_table.nr + 1, dive_site_table.nr + 1);
|
||||||
uint32_t uuid = create_dive_site_with_gps(name.toUtf8().data(), latitude, longitude);
|
uint32_t uuid = create_dive_site_with_gps(name.toUtf8().data(), latitude, longitude);
|
||||||
qSort(dive_site_table.dive_sites, dive_site_table.dive_sites + dive_site_table.nr, dive_site_less_than);
|
qSort(dive_site_table.dive_sites, dive_site_table.dive_sites + dive_site_table.nr, dive_site_less_than);
|
||||||
internalRowCount = dive_site_table.nr;
|
internalRowCount = dive_site_table.nr;
|
||||||
|
@ -81,7 +122,7 @@ int32_t LocationInformationModel::addDiveSite(const QString& name, int lon, int
|
||||||
|
|
||||||
bool LocationInformationModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool LocationInformationModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid() || index.row() == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (role != Qt::EditRole)
|
if (role != Qt::EditRole)
|
||||||
|
@ -99,7 +140,7 @@ bool LocationInformationModel::removeRows(int row, int count, const QModelIndex
|
||||||
if(row >= rowCount())
|
if(row >= rowCount())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row + 1, row + 1);
|
||||||
struct dive_site *ds = get_dive_site(row);
|
struct dive_site *ds = get_dive_site(row);
|
||||||
if (ds)
|
if (ds)
|
||||||
delete_dive_site(ds->uuid);
|
delete_dive_site(ds->uuid);
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
class QLineEdit;
|
||||||
|
|
||||||
class LocationInformationModel : public QAbstractTableModel {
|
class LocationInformationModel : public QAbstractTableModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -16,12 +18,14 @@ public:
|
||||||
int32_t addDiveSite(const QString& name, int lat = 0, int lon = 0);
|
int32_t addDiveSite(const QString& name, int lat = 0, int lon = 0);
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||||
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
|
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
|
||||||
|
void setFirstRowTextField(QLineEdit *textField);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void update();
|
void update();
|
||||||
private:
|
private:
|
||||||
LocationInformationModel(QObject *obj = 0);
|
LocationInformationModel(QObject *obj = 0);
|
||||||
int internalRowCount;
|
int internalRowCount;
|
||||||
|
QLineEdit *textField;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GeoReferencingOptionsModel : public QStringListModel {
|
class GeoReferencingOptionsModel : public QStringListModel {
|
||||||
|
|
|
@ -227,100 +227,48 @@ void LocationInformationWidget::resetPallete()
|
||||||
ui.diveSiteNotes->setPalette(p);
|
ui.diveSiteNotes->setPalette(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleDiveSiteEditDialog::SimpleDiveSiteEditDialog(QWidget *parent) :
|
bool LocationManagementEditHelper::eventFilter(QObject *obj, QEvent *ev)
|
||||||
QDialog(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::Popup),
|
|
||||||
ui(new Ui::SimpleDiveSiteEditDialog()), changed_dive_site(false)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
QListView *view = qobject_cast<QListView*>(obj);
|
||||||
ui->diveSiteDescription->installEventFilter(this);
|
if(!view)
|
||||||
ui->diveSiteNotes->installEventFilter(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleDiveSiteEditDialog::~SimpleDiveSiteEditDialog()
|
|
||||||
{
|
|
||||||
delete ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SimpleDiveSiteEditDialog::eventFilter(QObject *obj, QEvent *ev)
|
|
||||||
{
|
|
||||||
if (ev->type() != QEvent::FocusOut)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == ui->diveSiteDescription) {
|
if(ev->type() == QEvent::Show) {
|
||||||
diveSiteDescription_editingFinished();
|
last_uuid = 0;
|
||||||
} else if (obj == ui->diveSiteNotes) {
|
qDebug() << "EventFilter: " << last_uuid;
|
||||||
diveSiteNotes_editingFinished();
|
}
|
||||||
|
|
||||||
|
if(ev->type() == QEvent::KeyPress) {
|
||||||
|
QKeyEvent *keyEv = (QKeyEvent*) ev;
|
||||||
|
if(keyEv->key() == Qt::Key_Space || keyEv->key() == Qt::Key_Return) {
|
||||||
|
handleActivation(view->currentIndex());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleDiveSiteEditDialog::showEvent(QShowEvent *ev)
|
void LocationManagementEditHelper::handleActivation(const QModelIndex& activated)
|
||||||
{
|
{
|
||||||
const int heigth = 275;
|
if (!activated.isValid())
|
||||||
const int width = 450;
|
|
||||||
|
|
||||||
// Position.
|
|
||||||
QDialog::showEvent(ev);
|
|
||||||
QRect currGeometry = geometry();
|
|
||||||
currGeometry.setX(QCursor::pos().x() + 15);
|
|
||||||
currGeometry.setY(QCursor::pos().y() - heigth / 2);
|
|
||||||
currGeometry.setWidth(width);
|
|
||||||
currGeometry.setHeight(heigth);
|
|
||||||
setGeometry(currGeometry);
|
|
||||||
ev->accept();
|
|
||||||
|
|
||||||
//Da
|
|
||||||
ui->diveSiteName->setText(displayed_dive_site.name);
|
|
||||||
ui->diveSiteNotes->setPlainText(displayed_dive_site.notes);
|
|
||||||
ui->diveSiteDescription->setPlainText(displayed_dive_site.description);
|
|
||||||
|
|
||||||
const char *gps_text = printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg);
|
|
||||||
ui->diveSiteCoordinates->setText(QString(gps_text));
|
|
||||||
free( (void*) gps_text);
|
|
||||||
|
|
||||||
changed_dive_site = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleDiveSiteEditDialog::on_diveSiteName_editingFinished()
|
|
||||||
{
|
|
||||||
if (ui->diveSiteName->text() == displayed_dive_site.name)
|
|
||||||
return;
|
return;
|
||||||
free(displayed_dive_site.name);
|
QModelIndex uuidIdx = activated.model()->index(
|
||||||
displayed_dive_site.name = copy_string(qPrintable(ui->diveSiteName->text()));
|
activated.row(), LocationInformationModel::UUID);
|
||||||
changed_dive_site = true;
|
last_uuid = uuidIdx.data().toInt();
|
||||||
|
|
||||||
|
// Special case: first option, add dive site.
|
||||||
|
if (activated.row() == 0) {
|
||||||
|
qDebug() << "Setting to " << activated.data().toString();
|
||||||
|
emit setLineEditText(activated.data().toString());
|
||||||
|
}
|
||||||
|
qDebug() << "Selected dive_site: " << last_uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleDiveSiteEditDialog::on_diveSiteCoordinates_editingFinished()
|
void LocationManagementEditHelper::resetDiveSiteUuid() {
|
||||||
{
|
last_uuid = 0;
|
||||||
double lat, lon;
|
qDebug() << "Reset: " << last_uuid;
|
||||||
uint32_t uLat, uLon;
|
|
||||||
|
|
||||||
parseGpsText(ui->diveSiteCoordinates->text(), &lat, &lon);
|
|
||||||
uLat = lat * 1000000;
|
|
||||||
uLon = lon * 1000000;
|
|
||||||
|
|
||||||
if (uLat == displayed_dive_site.latitude.udeg && uLon == displayed_dive_site.longitude.udeg)
|
|
||||||
return;
|
|
||||||
|
|
||||||
displayed_dive_site.latitude.udeg = uLat;
|
|
||||||
displayed_dive_site.longitude.udeg = uLon;
|
|
||||||
changed_dive_site = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleDiveSiteEditDialog::diveSiteDescription_editingFinished()
|
uint32_t LocationManagementEditHelper::diveSiteUuid() const {
|
||||||
{
|
return last_uuid;
|
||||||
if (ui->diveSiteDescription->toPlainText() == displayed_dive_site.description)
|
|
||||||
return;
|
|
||||||
free(displayed_dive_site.description);
|
|
||||||
displayed_dive_site.description = copy_string(qPrintable(ui->diveSiteDescription->toPlainText()));
|
|
||||||
changed_dive_site = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleDiveSiteEditDialog::diveSiteNotes_editingFinished()
|
|
||||||
{
|
|
||||||
if (ui->diveSiteNotes->toPlainText() == displayed_dive_site.notes)
|
|
||||||
return;
|
|
||||||
free(displayed_dive_site.notes);
|
|
||||||
displayed_dive_site.notes = copy_string(qPrintable(ui->diveSiteNotes->toPlainText()));
|
|
||||||
changed_dive_site = true;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,24 +44,17 @@ private:
|
||||||
mode current_mode;
|
mode current_mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LocationManagementEditHelper : public QObject {
|
||||||
#include "ui_simpledivesiteedit.h"
|
|
||||||
class SimpleDiveSiteEditDialog : public QDialog {
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SimpleDiveSiteEditDialog(QWidget *parent);
|
|
||||||
virtual ~SimpleDiveSiteEditDialog();
|
|
||||||
bool changed_dive_site;
|
|
||||||
bool eventFilter(QObject *obj, QEvent *ev);
|
bool eventFilter(QObject *obj, QEvent *ev);
|
||||||
public slots:
|
void handleActivation(const QModelIndex& activated);
|
||||||
void on_diveSiteName_editingFinished();
|
void resetDiveSiteUuid();
|
||||||
void on_diveSiteCoordinates_editingFinished();
|
uint32_t diveSiteUuid() const;
|
||||||
void diveSiteDescription_editingFinished();
|
signals:
|
||||||
void diveSiteNotes_editingFinished();
|
void setLineEditText(const QString& text);
|
||||||
protected:
|
|
||||||
void showEvent(QShowEvent *ev);
|
|
||||||
private:
|
private:
|
||||||
Ui::SimpleDiveSiteEditDialog *ui;
|
uint32_t last_uuid;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "divelocationmodel.h"
|
#include "divelocationmodel.h"
|
||||||
#include "divesite.h"
|
#include "divesite.h"
|
||||||
#include "locationinformation.h"
|
#include "locationinformation.h"
|
||||||
|
#include "divesite.h"
|
||||||
|
|
||||||
#if defined(FBSUPPORT)
|
#if defined(FBSUPPORT)
|
||||||
#include "socialnetworks.h"
|
#include "socialnetworks.h"
|
||||||
|
@ -60,15 +61,21 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
||||||
|
|
||||||
QCompleter *completer = new QCompleter();
|
QCompleter *completer = new QCompleter();
|
||||||
QListView *completerListview = new QListView();
|
QListView *completerListview = new QListView();
|
||||||
|
LocationInformationModel::instance()->setFirstRowTextField(ui.location);
|
||||||
completer->setPopup(completerListview);
|
completer->setPopup(completerListview);
|
||||||
completer->setModel(LocationInformationModel::instance());
|
completer->setModel(LocationInformationModel::instance());
|
||||||
completer->setCompletionColumn(LocationInformationModel::NAME);
|
completer->setCompletionColumn(LocationInformationModel::NAME);
|
||||||
completer->setCompletionRole(Qt::DisplayRole);
|
|
||||||
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
completerListview->setItemDelegate(new LocationFilterDelegate());
|
completerListview->setItemDelegate(new LocationFilterDelegate());
|
||||||
|
|
||||||
|
locationManagementEditHelper = new LocationManagementEditHelper();
|
||||||
|
connect(locationManagementEditHelper, &LocationManagementEditHelper::setLineEditText,
|
||||||
|
ui.location, &QLineEdit::setText);
|
||||||
|
completerListview->installEventFilter(locationManagementEditHelper);
|
||||||
|
connect(completerListview, &QAbstractItemView::activated,
|
||||||
|
locationManagementEditHelper, &LocationManagementEditHelper::handleActivation);
|
||||||
|
|
||||||
ui.location->setCompleter(completer);
|
ui.location->setCompleter(completer);
|
||||||
connect(ui.addDiveSite, SIGNAL(clicked()), this, SLOT(showDiveSiteSimpleEdit()));
|
|
||||||
connect(ui.geocodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode()));
|
connect(ui.geocodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode()));
|
||||||
|
|
||||||
QAction *action = new QAction(tr("Apply changes"), this);
|
QAction *action = new QAction(tr("Apply changes"), this);
|
||||||
|
@ -244,27 +251,14 @@ void MainTab::setCurrentLocationIndex()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTab::showDiveSiteSimpleEdit()
|
|
||||||
{
|
|
||||||
if (ui.location->text().isEmpty())
|
|
||||||
return;
|
|
||||||
SimpleDiveSiteEditDialog dlg(this);
|
|
||||||
dlg.exec();
|
|
||||||
if (dlg.changed_dive_site) {
|
|
||||||
markChangedWidget(ui.location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainTab::enableGeoLookupEdition()
|
void MainTab::enableGeoLookupEdition()
|
||||||
{
|
{
|
||||||
ui.waitingSpinner->stop();
|
ui.waitingSpinner->stop();
|
||||||
ui.addDiveSite->show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTab::disableGeoLookupEdition()
|
void MainTab::disableGeoLookupEdition()
|
||||||
{
|
{
|
||||||
ui.waitingSpinner->start();
|
ui.waitingSpinner->start();
|
||||||
ui.addDiveSite->hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTab::toggleTriggeredColumn()
|
void MainTab::toggleTriggeredColumn()
|
||||||
|
@ -386,6 +380,7 @@ void MainTab::enableEdition(EditMode newEditMode)
|
||||||
displayMessage(tr("Multiple dives are being edited."));
|
displayMessage(tr("Multiple dives are being edited."));
|
||||||
} else {
|
} else {
|
||||||
displayMessage(tr("This dive is being edited."));
|
displayMessage(tr("This dive is being edited."));
|
||||||
|
locationManagementEditHelper->resetDiveSiteUuid();
|
||||||
}
|
}
|
||||||
editMode = newEditMode != NONE ? newEditMode : DIVE;
|
editMode = newEditMode != NONE ? newEditMode : DIVE;
|
||||||
}
|
}
|
||||||
|
@ -754,6 +749,7 @@ void MainTab::updateDiveInfo(bool clear)
|
||||||
else
|
else
|
||||||
ui.cylinders->view()->hideColumn(CylindersModel::USE);
|
ui.cylinders->view()->hideColumn(CylindersModel::USE);
|
||||||
|
|
||||||
|
qDebug() << "Set the current dive site:" << displayed_dive.dive_site_uuid;
|
||||||
emit diveSiteChanged(displayed_dive.dive_site_uuid);
|
emit diveSiteChanged(displayed_dive.dive_site_uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,12 +806,64 @@ void MainTab::reload()
|
||||||
mydive->what = displayed_dive.what; \
|
mydive->what = displayed_dive.what; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainTab::updateDisplayedDiveSite()
|
||||||
|
{
|
||||||
|
const QString new_name = ui.location->text();
|
||||||
|
const QString orig_name = displayed_dive_site.name;
|
||||||
|
const uint32_t orig_uuid = displayed_dive_site.uuid;
|
||||||
|
const uint32_t new_uuid = locationManagementEditHelper->diveSiteUuid();
|
||||||
|
|
||||||
|
qDebug() << "Updating Displayed Dive Site";
|
||||||
|
if(current_dive) {
|
||||||
|
struct dive_site *ds_from_dive = get_dive_site_by_uuid(current_dive->dive_site_uuid);
|
||||||
|
if (!dive_site_has_gps_location(ds_from_dive) &&
|
||||||
|
same_string(displayed_dive_site.notes, "SubsurfaceWebservice")) {
|
||||||
|
ds_from_dive->latitude = displayed_dive_site.latitude;
|
||||||
|
ds_from_dive->longitude = displayed_dive_site.longitude;
|
||||||
|
delete_dive_site(displayed_dive_site.uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(orig_uuid) {
|
||||||
|
if (new_uuid && orig_uuid != new_uuid) {
|
||||||
|
displayed_dive.dive_site_uuid = new_uuid;
|
||||||
|
copy_dive_site(get_dive_site_by_uuid(displayed_dive.dive_site_uuid), &displayed_dive_site);
|
||||||
|
} else if (new_name.count() && orig_name != new_name) {
|
||||||
|
// As per linus request.: If I enter the name of a dive site,
|
||||||
|
// do not select a new one, but "clone" the old one and copy
|
||||||
|
// the information of it, just changing it's name.
|
||||||
|
uint32_t new_ds_uuid = create_dive_site(NULL);
|
||||||
|
struct dive_site *new_ds = get_dive_site_by_uuid(new_ds_uuid);
|
||||||
|
copy_dive_site(&displayed_dive_site, new_ds);
|
||||||
|
new_ds->name = copy_string(qPrintable(new_name));
|
||||||
|
displayed_dive.dive_site_uuid = new_ds->uuid;
|
||||||
|
copy_dive_site(new_ds, &displayed_dive_site);
|
||||||
|
} else {
|
||||||
|
qDebug() << "Current divesite is the same as informed";
|
||||||
|
}
|
||||||
|
} else if (!orig_uuid) {
|
||||||
|
if (new_uuid) {
|
||||||
|
displayed_dive.dive_site_uuid = new_uuid;
|
||||||
|
copy_dive_site(get_dive_site_by_uuid(displayed_dive.dive_site_uuid), &displayed_dive_site);
|
||||||
|
} else if (new_name.count()) {
|
||||||
|
displayed_dive.dive_site_uuid = find_or_create_dive_site_with_name(qPrintable(new_name));
|
||||||
|
copy_dive_site(get_dive_site_by_uuid(displayed_dive.dive_site_uuid), &displayed_dive_site);
|
||||||
|
} else {
|
||||||
|
qDebug() << "No divesite will be set";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainTab::acceptChanges()
|
void MainTab::acceptChanges()
|
||||||
{
|
{
|
||||||
int i, addedId = -1;
|
int i, addedId = -1;
|
||||||
struct dive *d;
|
struct dive *d;
|
||||||
bool do_replot = false;
|
bool do_replot = false;
|
||||||
|
|
||||||
|
if(ui.location->hasFocus()) {
|
||||||
|
this->setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
acceptingEdit = true;
|
acceptingEdit = true;
|
||||||
tabBar()->setTabIcon(0, QIcon()); // Notes
|
tabBar()->setTabIcon(0, QIcon()); // Notes
|
||||||
tabBar()->setTabIcon(1, QIcon()); // Equipment
|
tabBar()->setTabIcon(1, QIcon()); // Equipment
|
||||||
|
@ -828,12 +876,8 @@ void MainTab::acceptChanges()
|
||||||
struct dive *added_dive = clone_dive(&displayed_dive);
|
struct dive *added_dive = clone_dive(&displayed_dive);
|
||||||
record_dive(added_dive);
|
record_dive(added_dive);
|
||||||
addedId = added_dive->id;
|
addedId = added_dive->id;
|
||||||
if (displayed_dive_site.uuid)
|
get_dive_by_uniq_id(added_dive->id)->dive_site_uuid = displayed_dive_site.uuid;
|
||||||
copy_dive_site(&displayed_dive_site, get_dive_site_by_uuid(displayed_dive_site.uuid));
|
|
||||||
else if (ui.location->text().count()) {
|
|
||||||
uint32_t uuid = create_dive_site(qPrintable(ui.location->text()));
|
|
||||||
added_dive->dive_site_uuid = uuid;
|
|
||||||
}
|
|
||||||
// unselect everything as far as the UI is concerned and select the new
|
// unselect everything as far as the UI is concerned and select the new
|
||||||
// dive - we'll have to undo/redo this later after we resort the dive_table
|
// dive - we'll have to undo/redo this later after we resort the dive_table
|
||||||
// but we need the dive selected for the middle part of this function - this
|
// but we need the dive selected for the middle part of this function - this
|
||||||
|
@ -889,6 +933,7 @@ void MainTab::acceptChanges()
|
||||||
time_t offset = cd->when - displayed_dive.when;
|
time_t offset = cd->when - displayed_dive.when;
|
||||||
MODIFY_SELECTED_DIVES(mydive->when -= offset;);
|
MODIFY_SELECTED_DIVES(mydive->when -= offset;);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (displayed_dive.dive_site_uuid != cd->dive_site_uuid)
|
if (displayed_dive.dive_site_uuid != cd->dive_site_uuid)
|
||||||
MODIFY_SELECTED_DIVES(EDIT_VALUE(dive_site_uuid));
|
MODIFY_SELECTED_DIVES(EDIT_VALUE(dive_site_uuid));
|
||||||
|
|
||||||
|
@ -897,9 +942,6 @@ void MainTab::acceptChanges()
|
||||||
saveTaggedStrings();
|
saveTaggedStrings();
|
||||||
saveTags();
|
saveTags();
|
||||||
|
|
||||||
if (displayed_dive_site.uuid)
|
|
||||||
copy_dive_site(&displayed_dive_site, get_dive_site_by_uuid(displayed_dive_site.uuid));
|
|
||||||
|
|
||||||
if (editMode != ADD && cylindersModel->changed) {
|
if (editMode != ADD && cylindersModel->changed) {
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
MODIFY_SELECTED_DIVES(
|
MODIFY_SELECTED_DIVES(
|
||||||
|
@ -956,6 +998,8 @@ void MainTab::acceptChanges()
|
||||||
cd->weightsystem[i].description = copy_string(displayed_dive.weightsystem[i].description);
|
cd->weightsystem[i].description = copy_string(displayed_dive.weightsystem[i].description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// each dive that was selected might have had the temperatures in its active divecomputer changed
|
// each dive that was selected might have had the temperatures in its active divecomputer changed
|
||||||
// so re-populate the temperatures - easiest way to do this is by calling fixup_dive
|
// so re-populate the temperatures - easiest way to do this is by calling fixup_dive
|
||||||
for_each_dive (i, d) {
|
for_each_dive (i, d) {
|
||||||
|
@ -1370,54 +1414,7 @@ void MainTab::on_location_editingFinished()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString currText = ui.location->text();
|
updateDisplayedDiveSite();
|
||||||
|
|
||||||
struct dive_site *ds;
|
|
||||||
int idx;
|
|
||||||
bool found = false;
|
|
||||||
for_each_dive_site (idx,ds) {
|
|
||||||
if (same_string(ds->name, qPrintable(currText))) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
uint32_t uuid = create_dive_site(qPrintable(ui.location->text()));
|
|
||||||
ds = get_dive_site_by_uuid(uuid);
|
|
||||||
if (same_string(displayed_dive_site.notes, "SubsurfaceWebservice")) {
|
|
||||||
ds->latitude = displayed_dive_site.latitude;
|
|
||||||
ds->longitude = displayed_dive_site.longitude;
|
|
||||||
delete_dive_site(displayed_dive_site.uuid);
|
|
||||||
}
|
|
||||||
displayed_dive.dive_site_uuid = uuid;
|
|
||||||
copy_dive_site(get_dive_site_by_uuid(uuid), &displayed_dive_site);
|
|
||||||
markChangedWidget(ui.location);
|
|
||||||
|
|
||||||
LocationInformationModel::instance()->update();
|
|
||||||
emit diveSiteChanged(uuid);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!get_dive_site(idx))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (current_dive) {
|
|
||||||
struct dive_site *ds_from_dive = get_dive_site_by_uuid(displayed_dive.dive_site_uuid);
|
|
||||||
if(ds_from_dive && ui.location->text() == ds_from_dive->name)
|
|
||||||
return;
|
|
||||||
ds_from_dive = get_dive_site(idx);
|
|
||||||
if (!dive_site_has_gps_location(ds_from_dive) &&
|
|
||||||
same_string(displayed_dive_site.notes, "SubsurfaceWebservice")) {
|
|
||||||
ds_from_dive->latitude = displayed_dive_site.latitude;
|
|
||||||
ds_from_dive->longitude = displayed_dive_site.longitude;
|
|
||||||
delete_dive_site(displayed_dive_site.uuid);
|
|
||||||
}
|
|
||||||
displayed_dive.dive_site_uuid = ds_from_dive->uuid;
|
|
||||||
copy_dive_site(get_dive_site_by_uuid(ds_from_dive->uuid), &displayed_dive_site);
|
|
||||||
markChangedWidget(ui.location);
|
|
||||||
emit diveSiteChanged(ds_from_dive->uuid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTab::on_suit_textChanged(const QString &text)
|
void MainTab::on_suit_textChanged(const QString &text)
|
||||||
|
|
|
@ -22,6 +22,7 @@ class CylindersModel;
|
||||||
class ExtraDataModel;
|
class ExtraDataModel;
|
||||||
class DivePictureModel;
|
class DivePictureModel;
|
||||||
class QCompleter;
|
class QCompleter;
|
||||||
|
class LocationManagementEditHelper;
|
||||||
|
|
||||||
struct Completers {
|
struct Completers {
|
||||||
QCompleter *divemaster;
|
QCompleter *divemaster;
|
||||||
|
@ -97,7 +98,6 @@ slots:
|
||||||
void enableGeoLookupEdition();
|
void enableGeoLookupEdition();
|
||||||
void disableGeoLookupEdition();
|
void disableGeoLookupEdition();
|
||||||
void setCurrentLocationIndex();
|
void setCurrentLocationIndex();
|
||||||
void showDiveSiteSimpleEdit();
|
|
||||||
void reverseGeocode();
|
void reverseGeocode();
|
||||||
private:
|
private:
|
||||||
Ui::MainTab ui;
|
Ui::MainTab ui;
|
||||||
|
@ -121,6 +121,8 @@ private:
|
||||||
dive_trip_t *currentTrip;
|
dive_trip_t *currentTrip;
|
||||||
dive_trip_t displayedTrip;
|
dive_trip_t displayedTrip;
|
||||||
bool acceptingEdit;
|
bool acceptingEdit;
|
||||||
|
LocationManagementEditHelper *locationManagementEditHelper;
|
||||||
|
void updateDisplayedDiveSite();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINTAB_H
|
#endif // MAINTAB_H
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>449</width>
|
<width>449</width>
|
||||||
<height>751</height>
|
<height>758</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
@ -167,15 +167,15 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>5</number>
|
<number>5</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>5</number>
|
<number>5</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="spacing">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="LocationLayout" stretch="0,1">
|
<layout class="QHBoxLayout" name="LocationLayout" stretch="0,1">
|
||||||
<item>
|
<item>
|
||||||
|
@ -208,17 +208,6 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="location"/>
|
<widget class="QLineEdit" name="location"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QToolButton" name="addDiveSite">
|
|
||||||
<property name="text">
|
|
||||||
<string>...</string>
|
|
||||||
</property>
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../subsurface.qrc">
|
|
||||||
<normaloff>:/edit</normaloff>:/edit</iconset>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="geocodeButton">
|
<widget class="QToolButton" name="geocodeButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -658,8 +647,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>286</width>
|
<width>317</width>
|
||||||
<height>300</height>
|
<height>365</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="diveInfoScrollAreaLayout">
|
<layout class="QGridLayout" name="diveInfoScrollAreaLayout">
|
||||||
|
@ -999,8 +988,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>297</width>
|
<width>331</width>
|
||||||
<height>177</height>
|
<height>220</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
|
|
@ -498,14 +498,22 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||||
QStyledItemDelegate::initStyleOption(&opt, index);
|
QStyledItemDelegate::initStyleOption(&opt, index);
|
||||||
QBrush bg;
|
QBrush bg;
|
||||||
QString diveSiteName = index.data().toString();
|
QString diveSiteName = index.data().toString();
|
||||||
|
QString bottomText;
|
||||||
|
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
|
||||||
struct dive_site *ds = get_dive_site_by_uuid(
|
struct dive_site *ds = get_dive_site_by_uuid(
|
||||||
index.model()->data(index.model()->index(index.row(),0)).toInt()
|
index.model()->data(index.model()->index(index.row(),0)).toInt()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//Special case: do not show name, but instead, show
|
||||||
|
if (index.row() == 0) {
|
||||||
|
diveSiteName = index.data().toString();
|
||||||
|
bottomText = index.data(Qt::ToolTipRole).toString();
|
||||||
|
goto print_part;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ds)
|
if (!ds)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString bottomText;
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
if (prefs.geocoding.category[i] == TC_NONE)
|
if (prefs.geocoding.category[i] == TC_NONE)
|
||||||
continue;
|
continue;
|
||||||
|
@ -542,11 +550,14 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||||
bottomText += tr(" (~ %1 away)").arg(distance);
|
bottomText += tr(" (~ %1 away)").arg(distance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
print_part:
|
||||||
|
|
||||||
fontBigger.setPointSize(fontBigger.pointSize() + 1);
|
fontBigger.setPointSize(fontBigger.pointSize() + 1);
|
||||||
fontBigger.setBold(true);
|
fontBigger.setBold(true);
|
||||||
|
|
||||||
initStyleOption(&opt, index);
|
initStyleOption(&opt, index);
|
||||||
opt.text = QString();
|
opt.text = QString();
|
||||||
|
opt.icon = QIcon();
|
||||||
qApp->style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, NULL);
|
qApp->style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, NULL);
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
@ -564,6 +575,14 @@ void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||||
painter->setBrush(option.palette.brightText());
|
painter->setBrush(option.palette.brightText());
|
||||||
painter->drawText(option.rect.x(),option.rect.y() + fmBigger.boundingRect("YH").height() * 2, bottomText);
|
painter->drawText(option.rect.x(),option.rect.y() + fmBigger.boundingRect("YH").height() * 2, bottomText);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
|
if (!icon.isNull()) {
|
||||||
|
painter->save();
|
||||||
|
painter->drawPixmap(
|
||||||
|
option.rect.x() + option.rect.width() - 24,
|
||||||
|
option.rect.y() + option.rect.height() - 24, icon.pixmap(20,20));
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize LocationFilterDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
QSize LocationFilterDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>SimpleDiveSiteEditDialog</class>
|
|
||||||
<widget class="QDialog" name="SimpleDiveSiteEditDialog">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>449</width>
|
|
||||||
<height>338</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>Dialog</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Name</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QLineEdit" name="diveSiteName"/>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>Coordinates</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QLineEdit" name="diveSiteCoordinates"/>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0">
|
|
||||||
<widget class="QLabel" name="label_3">
|
|
||||||
<property name="text">
|
|
||||||
<string>Description</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1">
|
|
||||||
<widget class="QPlainTextEdit" name="diveSiteNotes"/>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QPlainTextEdit" name="diveSiteDescription"/>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0">
|
|
||||||
<widget class="QLabel" name="label_4">
|
|
||||||
<property name="text">
|
|
||||||
<string>Notes</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0" colspan="2">
|
|
||||||
<widget class="QLabel" name="label_5">
|
|
||||||
<property name="text">
|
|
||||||
<string>Dive site quick edit. Hit ESC or click outside to close</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
Loading…
Add table
Reference in a new issue