mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Merge branch 'NewLocationEditDropdown'
This commit is contained in:
commit
6ee2a44235
5 changed files with 401 additions and 181 deletions
|
@ -7,12 +7,15 @@
|
|||
#include "filtermodels.h"
|
||||
#include "divelocationmodel.h"
|
||||
#include "divesitehelpers.h"
|
||||
#include "modeldelegates.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QShowEvent>
|
||||
#include <QItemSelectionModel>
|
||||
#include <qmessagebox.h>
|
||||
#include <cstdlib>
|
||||
#include <QDesktopWidget>
|
||||
#include <QScrollBar>
|
||||
|
||||
LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBox(parent), modified(false)
|
||||
{
|
||||
|
@ -256,64 +259,299 @@ void LocationInformationWidget::resetPallete()
|
|||
ui.diveSiteNotes->setPalette(p);
|
||||
}
|
||||
|
||||
bool LocationManagementEditHelper::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
QListView *view = qobject_cast<QListView*>(obj);
|
||||
if(!view)
|
||||
return false;
|
||||
|
||||
if(ev->type() == QEvent::Show) {
|
||||
last_uuid = 0;
|
||||
qDebug() << "EventFilter: " << last_uuid;
|
||||
}
|
||||
|
||||
if(ev->type() == QEvent::KeyPress) {
|
||||
QKeyEvent *keyEv = (QKeyEvent*) ev;
|
||||
if(keyEv->key() == Qt::Key_Return) {
|
||||
handleActivation(view->currentIndex());
|
||||
view->hide();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void LocationManagementEditHelper::handleActivation(const QModelIndex& activated)
|
||||
{
|
||||
if (!activated.isValid())
|
||||
return;
|
||||
QModelIndex uuidIdx = activated.model()->index(
|
||||
activated.row(), LocationInformationModel::UUID);
|
||||
last_uuid = uuidIdx.data().toInt();
|
||||
|
||||
/* if we are in 'recently added divesite mode, create a new divesite,
|
||||
* and go to dive site edit edit mode. */
|
||||
if (last_uuid == RECENTLY_ADDED_DIVESITE) {
|
||||
uint32_t ds_uuid = create_dive_site_from_current_dive(qPrintable(activated.data().toString()));
|
||||
qDebug() << "ds_uuid" << ds_uuid;
|
||||
struct dive_site *ds = get_dive_site_by_uuid(ds_uuid);
|
||||
copy_dive_site(ds, &displayed_dive_site);
|
||||
displayed_dive.dive_site_uuid = ds->uuid;
|
||||
last_uuid = ds->uuid;
|
||||
// Move this out of here later.
|
||||
MainWindow::instance()->startDiveSiteEdit();
|
||||
}
|
||||
|
||||
qDebug() << "Selected dive_site: " << last_uuid;
|
||||
}
|
||||
|
||||
void LocationManagementEditHelper::resetDiveSiteUuid() {
|
||||
last_uuid = 0;
|
||||
qDebug() << "Reset: " << last_uuid;
|
||||
}
|
||||
|
||||
uint32_t LocationManagementEditHelper::diveSiteUuid() const {
|
||||
return last_uuid;
|
||||
}
|
||||
|
||||
void LocationInformationWidget::reverseGeocode()
|
||||
{
|
||||
ReverseGeoLookupThread *geoLookup = ReverseGeoLookupThread::instance();
|
||||
geoLookup->lookup(&displayed_dive_site);
|
||||
updateLabels();
|
||||
}
|
||||
|
||||
DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject *parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DiveLocationLineEdit *location_line_edit = 0;
|
||||
|
||||
bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
|
||||
{
|
||||
if(source_row == 0)
|
||||
return true;
|
||||
|
||||
QString sourceString = sourceModel()->index(source_row, DiveLocationModel::NAME).data(Qt::DisplayRole).toString();
|
||||
return sourceString.toLower().startsWith(location_line_edit->text().toLower());
|
||||
}
|
||||
|
||||
bool DiveLocationFilterProxyModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const
|
||||
{
|
||||
return source_left.data().toString() <= source_right.data().toString();
|
||||
}
|
||||
|
||||
|
||||
DiveLocationModel::DiveLocationModel(QObject *o)
|
||||
{
|
||||
resetModel();
|
||||
}
|
||||
|
||||
void DiveLocationModel::resetModel()
|
||||
{
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QVariant DiveLocationModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if(index.row() <= 1) { // two special cases.
|
||||
if(index.column() == UUID) {
|
||||
return RECENTLY_ADDED_DIVESITE;
|
||||
}
|
||||
switch(role) {
|
||||
case Qt::DisplayRole : return new_ds_value[index.row()];
|
||||
case Qt::ToolTipRole : return "Create a new dive site";
|
||||
case Qt::DecorationRole : return QIcon(":plus");
|
||||
}
|
||||
}
|
||||
|
||||
// The dive sites are -2 because of the first two items.
|
||||
struct dive_site *ds = get_dive_site(index.row() - 2);
|
||||
switch(role) {
|
||||
case Qt::EditRole:
|
||||
case Qt::DisplayRole :
|
||||
switch(index.column()) {
|
||||
case UUID: return ds->uuid;
|
||||
case NAME: return ds->name;
|
||||
case LATITUDE: return ds->latitude.udeg;
|
||||
case LONGITUDE: return ds->longitude.udeg;
|
||||
case DESCRIPTION: return ds->description;
|
||||
case NOTES: return ds->name;
|
||||
}
|
||||
break;
|
||||
case Qt::DecorationRole : {
|
||||
if (dive_site_has_gps_location(ds))
|
||||
return QIcon(":geocode");
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int DiveLocationModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return COLUMNS;
|
||||
}
|
||||
|
||||
int DiveLocationModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return dive_site_table.nr + 2;
|
||||
}
|
||||
|
||||
bool DiveLocationModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||
{
|
||||
if(!index.isValid())
|
||||
return false;
|
||||
if (index.row() > 1)
|
||||
return false;
|
||||
|
||||
new_ds_value[index.row()] = value.toString();
|
||||
|
||||
dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) : QLineEdit(parent),
|
||||
proxy(new DiveLocationFilterProxyModel()), model(new DiveLocationModel()), view(new DiveLocationListView())
|
||||
{
|
||||
location_line_edit = this;
|
||||
|
||||
proxy->setSourceModel(model);
|
||||
proxy->setFilterKeyColumn(DiveLocationModel::NAME);
|
||||
|
||||
view->setModel(proxy);
|
||||
view->setModelColumn(DiveLocationModel::NAME);
|
||||
view->setItemDelegate(new LocationFilterDelegate());
|
||||
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
view->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
view->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
view->setParent(0, Qt::Popup);
|
||||
view->installEventFilter(this);
|
||||
view->setFocusPolicy(Qt::NoFocus);
|
||||
view->setFocusProxy(this);
|
||||
|
||||
connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName);
|
||||
connect(view, &QAbstractItemView::activated, this, &DiveLocationLineEdit::itemActivated);
|
||||
}
|
||||
|
||||
bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
if(e->type() == QEvent::KeyPress) {
|
||||
QKeyEvent *keyEv = (QKeyEvent*) e;
|
||||
|
||||
if (keyEv->key() == Qt::Key_Escape) {
|
||||
view->hide();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(keyEv->key() == Qt::Key_Return ||
|
||||
keyEv->key() == Qt::Key_Enter) {
|
||||
view->hide();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keyEv->key() == Qt::Key_Tab){
|
||||
itemActivated(view->currentIndex());
|
||||
view->hide();
|
||||
return false;
|
||||
}
|
||||
event(e);
|
||||
} else if(e->type() == QEvent::MouseButtonPress ) {
|
||||
if (!view->underMouse()) {
|
||||
view->hide();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DiveLocationLineEdit::focusOutEvent(QFocusEvent* ev)
|
||||
{
|
||||
if (!view->isVisible()) {
|
||||
QLineEdit::focusOutEvent(ev);
|
||||
}
|
||||
}
|
||||
|
||||
void DiveLocationLineEdit::itemActivated(const QModelIndex& index)
|
||||
{
|
||||
QModelIndex uuidIndex = index.model()->index(index.row(), DiveLocationModel::UUID);
|
||||
uint32_t uuid = uuidIndex.data().toInt();
|
||||
currType = uuid == 1 ? NEW_DIVE_SITE : EXISTING_DIVE_SITE;
|
||||
currUuid = uuid;
|
||||
setText(index.data().toString());
|
||||
if(currUuid == NEW_DIVE_SITE)
|
||||
qDebug() << "Setting a New dive site";
|
||||
else
|
||||
qDebug() << "Setting a Existing dive site";
|
||||
if(view->isVisible())
|
||||
view->hide();
|
||||
emit diveSiteSelected(currUuid);
|
||||
}
|
||||
|
||||
void DiveLocationLineEdit::refreshDiveSiteCache()
|
||||
{
|
||||
model->resetModel();
|
||||
}
|
||||
|
||||
static struct dive_site *get_dive_site_name_start_which_str(const QString& str) {
|
||||
struct dive_site *ds;
|
||||
int i;
|
||||
for_each_dive_site(i,ds) {
|
||||
QString dsName(ds->name);
|
||||
if (dsName.toLower().startsWith(str.toLower())) {
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s)
|
||||
{
|
||||
QModelIndex i0 = model->index(0, DiveLocationModel::NAME);
|
||||
QModelIndex i1 = model->index(1, DiveLocationModel::NAME);
|
||||
model->setData(i0, text());
|
||||
|
||||
QString i1_name = INVALID_DIVE_SITE_NAME;
|
||||
if (struct dive_site *ds = get_dive_site_name_start_which_str(text())) {
|
||||
const QString orig_name = QString(ds->name).toLower();
|
||||
const QString new_name = text().toLower();
|
||||
if (new_name != orig_name)
|
||||
i1_name = QString(ds->name);
|
||||
}
|
||||
|
||||
model->setData(i1, i1_name );
|
||||
proxy->invalidate();
|
||||
fixPopupPosition();
|
||||
if (!view->isVisible())
|
||||
view->show();
|
||||
}
|
||||
|
||||
void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev)
|
||||
{
|
||||
QLineEdit::keyPressEvent(ev);
|
||||
if(ev->key() != Qt::Key_Left &&
|
||||
ev->key() != Qt::Key_Right &&
|
||||
ev->key() != Qt::Key_Escape &&
|
||||
ev->key() != Qt::Key_Return ) {
|
||||
|
||||
if(ev->key() != Qt::Key_Up && ev->key() != Qt::Key_Down) {
|
||||
currType = NEW_DIVE_SITE;
|
||||
currUuid = RECENTLY_ADDED_DIVESITE;
|
||||
} else {
|
||||
showPopup();
|
||||
}
|
||||
} else if (ev->key() == Qt::Key_Escape) {
|
||||
view->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void DiveLocationLineEdit::fixPopupPosition()
|
||||
{
|
||||
const QRect screen = QApplication::desktop()->availableGeometry(this);
|
||||
const int maxVisibleItems = 5;
|
||||
Qt::LayoutDirection dir = layoutDirection();
|
||||
QPoint pos;
|
||||
int rh, w;
|
||||
int h = (view->sizeHintForRow(0) * qMin(maxVisibleItems, view->model()->rowCount()) + 3) + 3;
|
||||
QScrollBar *hsb = view->horizontalScrollBar();
|
||||
if (hsb && hsb->isVisible())
|
||||
h += view->horizontalScrollBar()->sizeHint().height();
|
||||
|
||||
rh = height();
|
||||
pos = mapToGlobal(QPoint(0, height() - 2));
|
||||
w = width();
|
||||
|
||||
if (w > screen.width())
|
||||
w = screen.width();
|
||||
if ((pos.x() + w) > (screen.x() + screen.width()))
|
||||
pos.setX(screen.x() + screen.width() - w);
|
||||
if (pos.x() < screen.x())
|
||||
pos.setX(screen.x());
|
||||
|
||||
int top = pos.y() - rh - screen.top() + 2;
|
||||
int bottom = screen.bottom() - pos.y();
|
||||
h = qMax(h, view->minimumHeight());
|
||||
if (h > bottom) {
|
||||
h = qMin(qMax(top, bottom), h);
|
||||
if (top > bottom)
|
||||
pos.setY(pos.y() - h - rh + 2);
|
||||
}
|
||||
|
||||
view->setGeometry(pos.x(), pos.y(), w, h);
|
||||
if(!view->currentIndex().isValid()) {
|
||||
view->setCurrentIndex(view->model()->index(0,1));
|
||||
}
|
||||
}
|
||||
|
||||
void DiveLocationLineEdit::showPopup()
|
||||
{
|
||||
fixPopupPosition();
|
||||
if (!view->isVisible()) {
|
||||
setTemporaryDiveSiteName(text());
|
||||
proxy->invalidate();
|
||||
view->show();
|
||||
}
|
||||
}
|
||||
|
||||
DiveLocationLineEdit::DiveSiteType DiveLocationLineEdit::currDiveSiteType() const
|
||||
{
|
||||
return currType;
|
||||
}
|
||||
|
||||
uint32_t DiveLocationLineEdit::currDiveSiteUuid() const
|
||||
{
|
||||
return currUuid;
|
||||
}
|
||||
|
||||
DiveLocationListView::DiveLocationListView(QWidget *parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "ui_locationInformation.h"
|
||||
#include <stdint.h>
|
||||
#include <QAbstractListModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
class LocationInformationWidget : public QGroupBox {
|
||||
Q_OBJECT
|
||||
|
@ -45,17 +46,60 @@ private:
|
|||
QAction *closeAction, *acceptAction, *rejectAction;
|
||||
};
|
||||
|
||||
class LocationManagementEditHelper : public QObject {
|
||||
Q_OBJECT
|
||||
class DiveLocationFilterProxyModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool eventFilter(QObject *obj, QEvent *ev);
|
||||
void handleActivation(const QModelIndex& activated);
|
||||
void resetDiveSiteUuid();
|
||||
uint32_t diveSiteUuid() const;
|
||||
signals:
|
||||
void setLineEditText(const QString& text);
|
||||
DiveLocationFilterProxyModel(QObject *parent = 0);
|
||||
virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
|
||||
virtual bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const;
|
||||
};
|
||||
|
||||
class DiveLocationModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum columns{UUID, NAME, LATITUDE, LONGITUDE, DESCRIPTION, NOTES, COLUMNS};
|
||||
DiveLocationModel(QObject *o = 0);
|
||||
void resetModel();
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
private:
|
||||
uint32_t last_uuid;
|
||||
QString new_ds_value[2];
|
||||
};
|
||||
|
||||
class DiveLocationListView : public QListView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiveLocationListView(QWidget *parent = 0);
|
||||
};
|
||||
|
||||
class DiveLocationLineEdit : public QLineEdit {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum DiveSiteType { NO_DIVE_SITE, NEW_DIVE_SITE, EXISTING_DIVE_SITE };
|
||||
DiveLocationLineEdit(QWidget *parent =0 );
|
||||
void refreshDiveSiteCache();
|
||||
void setTemporaryDiveSiteName(const QString& s);
|
||||
bool eventFilter(QObject*, QEvent*);
|
||||
void itemActivated(const QModelIndex& index);
|
||||
DiveSiteType currDiveSiteType() const;
|
||||
uint32_t currDiveSiteUuid() const;
|
||||
void fixPopupPosition();
|
||||
signals:
|
||||
void diveSiteSelected(uint32_t uuid);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *ev);
|
||||
void focusOutEvent(QFocusEvent *ev);
|
||||
void showPopup();
|
||||
|
||||
private:
|
||||
DiveLocationFilterProxyModel *proxy;
|
||||
DiveLocationModel *model;
|
||||
DiveLocationListView *view;
|
||||
DiveSiteType currType;
|
||||
uint32_t currUuid;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -55,24 +55,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
|||
ui.extraData->setModel(extraDataModel);
|
||||
closeMessage();
|
||||
|
||||
QCompleter *completer = new QCompleter();
|
||||
QListView *completerListview = new QListView();
|
||||
LocationInformationModel::instance()->setFirstRowTextField(ui.location);
|
||||
completer->setPopup(completerListview);
|
||||
completer->setModel(LocationInformationModel::instance());
|
||||
completer->setCompletionColumn(LocationInformationModel::NAME);
|
||||
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
completerListview->setItemDelegate(new LocationFilterDelegate());
|
||||
completerListview->setMouseTracking(true);
|
||||
locationManagementEditHelper = new LocationManagementEditHelper();
|
||||
connect(locationManagementEditHelper, &LocationManagementEditHelper::setLineEditText,
|
||||
ui.location, &QLineEdit::setText);
|
||||
completerListview->installEventFilter(locationManagementEditHelper);
|
||||
connect(completerListview, &QAbstractItemView::clicked,
|
||||
locationManagementEditHelper, &LocationManagementEditHelper::handleActivation);
|
||||
|
||||
ui.location->setCompleter(completer);
|
||||
ui.editDiveSiteButton->setEnabled(true);
|
||||
connect(ui.editDiveSiteButton, SIGNAL(clicked()), MainWindow::instance(), SIGNAL(startDiveSiteEdit()));
|
||||
|
||||
QAction *action = new QAction(tr("Apply changes"), this);
|
||||
|
@ -212,7 +194,9 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
|||
connect(ReverseGeoLookupThread::instance(), &QThread::finished,
|
||||
this, &MainTab::setCurrentLocationIndex);
|
||||
|
||||
ui.location->installEventFilter(this);
|
||||
connect(ui.diveNotesMessage, &KMessageWidget::showAnimationFinished,
|
||||
ui.location, &DiveLocationLineEdit::fixPopupPosition);
|
||||
|
||||
acceptingEdit = false;
|
||||
}
|
||||
|
||||
|
@ -227,31 +211,6 @@ MainTab::~MainTab()
|
|||
}
|
||||
}
|
||||
|
||||
bool MainTab::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
QMoveEvent *mEv;
|
||||
QResizeEvent *rEv;
|
||||
QLineEdit *line = qobject_cast<QLineEdit*>(obj);
|
||||
|
||||
if (ev->type() == QEvent::MouseMove || ev->type() == QEvent::HoverMove || ev->type() == QEvent::Paint)
|
||||
return false;
|
||||
|
||||
if (line) {
|
||||
if (ev->type() == QEvent::Resize) {
|
||||
if (line->completer()->popup()->isVisible()) {
|
||||
QListView *choices = qobject_cast<QListView*>(line->completer()->popup());
|
||||
QPoint p = ui.location->mapToGlobal(ui.location->pos());
|
||||
choices->setGeometry(
|
||||
choices->geometry().x(),
|
||||
p.y() + 3,
|
||||
choices->geometry().width(),
|
||||
choices->geometry().height());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MainTab::setCurrentLocationIndex()
|
||||
{
|
||||
if (current_dive) {
|
||||
|
@ -333,12 +292,6 @@ void MainTab::displayMessage(QString str)
|
|||
ui.diveStatisticsMessage->setText(str);
|
||||
ui.diveStatisticsMessage->animatedShow();
|
||||
updateTextLabels();
|
||||
|
||||
// TODO: this doesn't exists anymore. Find out why it was removed from
|
||||
// the KMessageWidget and try to see if this is still needed.
|
||||
// ui.tagWidget->fixPopupPosition(ui.diveNotesMessage->bestContentHeight());
|
||||
// ui.buddy->fixPopupPosition(ui.diveNotesMessage->bestContentHeight());
|
||||
// ui.divemaster->fixPopupPosition(ui.diveNotesMessage->bestContentHeight());
|
||||
}
|
||||
|
||||
void MainTab::updateTextLabels(bool showUnits)
|
||||
|
@ -377,6 +330,8 @@ void MainTab::enableEdition(EditMode newEditMode)
|
|||
MainWindow::instance()->editCurrentDive();
|
||||
return;
|
||||
}
|
||||
|
||||
ui.editDiveSiteButton->setEnabled(false);
|
||||
MainWindow::instance()->dive_list()->setEnabled(false);
|
||||
MainWindow::instance()->setEnabledToolbar(false);
|
||||
|
||||
|
@ -392,7 +347,6 @@ void MainTab::enableEdition(EditMode newEditMode)
|
|||
displayMessage(tr("Multiple dives are being edited."));
|
||||
} else {
|
||||
displayMessage(tr("This dive is being edited."));
|
||||
locationManagementEditHelper->resetDiveSiteUuid();
|
||||
}
|
||||
editMode = newEditMode != NONE ? newEditMode : DIVE;
|
||||
}
|
||||
|
@ -474,12 +428,9 @@ void MainTab::updateDiveInfo(bool clear)
|
|||
{
|
||||
// I don't like this code here - but globe() wasn't initialized on the constructor.
|
||||
{
|
||||
QListView *completerListview = qobject_cast<QListView*>(ui.location->completer()->popup());
|
||||
#ifndef NO_MARBLE
|
||||
connect(completerListview, SIGNAL(entered(QModelIndex)), GlobeGPS::instance(), SLOT(centerOnIndex(QModelIndex)), Qt::UniqueConnection);
|
||||
#endif
|
||||
}
|
||||
|
||||
ui.location->refreshDiveSiteCache();
|
||||
EditMode rememberEM = editMode;
|
||||
// don't execute this while adding / planning a dive
|
||||
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE || MainWindow::instance()->graphics()->isPlanner())
|
||||
|
@ -861,9 +812,13 @@ 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();
|
||||
const uint32_t new_uuid = ui.location->currDiveSiteUuid();
|
||||
|
||||
qDebug() << "Updating Displayed Dive Site";
|
||||
if (new_uuid == RECENTLY_ADDED_DIVESITE) {
|
||||
qDebug() << "New dive site selected, don't try to update something that doesn't exists yet.";
|
||||
return;
|
||||
}
|
||||
|
||||
if(orig_uuid) {
|
||||
if (new_uuid && orig_uuid != new_uuid) {
|
||||
|
@ -907,65 +862,37 @@ void MainTab::updateDiveSite(int divenr)
|
|||
if (!cd)
|
||||
return;
|
||||
|
||||
const uint32_t newUuid = displayed_dive_site.uuid;
|
||||
const uint32_t pickedUuid = locationManagementEditHelper->diveSiteUuid();
|
||||
const QString newName = displayed_dive_site.name;
|
||||
if (ui.location->text().isEmpty()) {
|
||||
qDebug() << "No location data set, not updating the dive site.";
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t pickedUuid = ui.location->currDiveSiteUuid();
|
||||
const uint32_t origUuid = cd->dive_site_uuid;
|
||||
struct dive_site *origDs = get_dive_site_by_uuid(origUuid);
|
||||
const QString origName = origDs ? origDs->name : "";
|
||||
// the user has accepted the changes made to the displayed_dive_site
|
||||
// so let's make them permanent
|
||||
if (!origUuid) {
|
||||
// the dive edited didn't have a dive site
|
||||
qDebug() << "current dive didn't have a dive site before edit";
|
||||
if (pickedUuid) {
|
||||
qDebug() << "assign dive_site" << pickedUuid << "to current dive";
|
||||
cd->dive_site_uuid = pickedUuid;
|
||||
} else if (newUuid) {
|
||||
// user created a new divesite
|
||||
cd->dive_site_uuid = newUuid;
|
||||
} else if (!newName.isEmpty()) {
|
||||
// user entered a name but didn't pick or create a dive site, so create a divesite
|
||||
uint32_t createdUuid = create_dive_site(displayed_dive_site.name, cd->when);
|
||||
struct dive_site *newDs = get_dive_site_by_uuid(createdUuid);
|
||||
copy_dive_site(&displayed_dive_site, newDs);
|
||||
newDs->uuid = createdUuid; // the copy overwrote the uuid
|
||||
cd->dive_site_uuid = createdUuid;
|
||||
qDebug() << "create a new dive site with name" << newName << "which is now named" << newDs->name << "and assign it as uuid" << createdUuid;
|
||||
} else {
|
||||
qDebug() << "neither uuid picked, uuid created nor new name found";
|
||||
}
|
||||
} else {
|
||||
qDebug() << "current dive had dive site with uuid" << origUuid;
|
||||
if (origUuid == newUuid) {
|
||||
// looks like nothing changed
|
||||
qDebug() << "same uuid";
|
||||
} else if (newName != origName) {
|
||||
if (newUuid == 0) {
|
||||
// so we created a new site, add it to the global list
|
||||
uint32_t createdUuid = create_dive_site(displayed_dive_site.name, cd->when);
|
||||
struct dive_site *newDs = get_dive_site_by_uuid(createdUuid);
|
||||
copy_dive_site(&displayed_dive_site, newDs);
|
||||
newDs->uuid = createdUuid; // the copy overwrote the uuid
|
||||
cd->dive_site_uuid = createdUuid;
|
||||
qDebug() << "create a new dive site with name" << newName << "which is now named" << newDs->name << "and assign it as uuid" << createdUuid;
|
||||
qDebug() << "original dive had site" << origUuid << "and" << (origDs ? QString("notes %1").arg(origDs->notes) : QString("no dive site"));
|
||||
if (origDs && same_string(origDs->notes, "SubsurfaceWebservice")) {
|
||||
// this is a special case - let's remove the original dive site if this was the only user
|
||||
if (!is_dive_site_used(origDs->uuid, false)) {
|
||||
qDebug() << "delete the autogenerated dive site" << origDs->name;
|
||||
delete_dive_site(origDs->uuid);
|
||||
free(newDs->notes);
|
||||
newDs->notes = NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qDebug() << "switched to dive site" << newName << "uuid" << newUuid << "for current dive";
|
||||
cd->dive_site_uuid = newUuid;
|
||||
// what to do with the old site?
|
||||
}
|
||||
struct dive_site *newDs = NULL;
|
||||
|
||||
if (pickedUuid == origUuid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pickedUuid == RECENTLY_ADDED_DIVESITE) {
|
||||
pickedUuid = create_dive_site(ui.location->text().isEmpty() ? qPrintable(tr("New dive site")) : qPrintable(ui.location->text()), displayed_dive.when);
|
||||
}
|
||||
|
||||
newDs = get_dive_site_by_uuid(pickedUuid);
|
||||
copy_dive_site(newDs, &displayed_dive_site);
|
||||
|
||||
if (origDs && pickedUuid != origDs->uuid && same_string(origDs->notes, "SubsurfaceWebservice")) {
|
||||
// this is a special case - let's remove the original dive site if this was the only user
|
||||
if (!is_dive_site_used(origDs->uuid, false)) {
|
||||
qDebug() << "delete the autogenerated dive site" << origDs->name;
|
||||
delete_dive_site(origDs->uuid);
|
||||
}
|
||||
}
|
||||
|
||||
cd->dive_site_uuid = pickedUuid;
|
||||
qDebug() << "Setting the dive site id on the dive:" << pickedUuid;
|
||||
}
|
||||
|
||||
void MainTab::acceptChanges()
|
||||
|
@ -1180,6 +1107,7 @@ void MainTab::acceptChanges()
|
|||
weightModel->changed = false;
|
||||
MainWindow::instance()->setEnabledToolbar(true);
|
||||
acceptingEdit = false;
|
||||
ui.editDiveSiteButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainTab::resetPallete()
|
||||
|
@ -1252,6 +1180,7 @@ void MainTab::rejectChanges()
|
|||
cylindersModel->updateDive();
|
||||
weightModel->updateDive();
|
||||
extraDataModel->updateDive();
|
||||
ui.editDiveSiteButton->setEnabled(true);
|
||||
}
|
||||
#undef EDIT_TEXT2
|
||||
|
||||
|
@ -1526,7 +1455,7 @@ void MainTab::on_location_textChanged()
|
|||
markChangedWidget(ui.location);
|
||||
}
|
||||
|
||||
void MainTab::on_location_editingFinished()
|
||||
void MainTab::on_location_diveSiteSelected()
|
||||
{
|
||||
if (editMode == IGNORE || acceptingEdit == true)
|
||||
return;
|
||||
|
@ -1536,6 +1465,13 @@ void MainTab::on_location_editingFinished()
|
|||
markChangedWidget(ui.location);
|
||||
emit diveSiteChanged(0);
|
||||
return;
|
||||
} else {
|
||||
if (ui.location->currDiveSiteUuid() != displayed_dive.dive_site_uuid) {
|
||||
markChangedWidget(ui.location);
|
||||
} else {
|
||||
QPalette p;
|
||||
ui.location->setPalette(p);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentTrip) {
|
||||
|
|
|
@ -22,7 +22,6 @@ class CylindersModel;
|
|||
class ExtraDataModel;
|
||||
class DivePictureModel;
|
||||
class QCompleter;
|
||||
class LocationManagementEditHelper;
|
||||
|
||||
struct Completers {
|
||||
QCompleter *divemaster;
|
||||
|
@ -55,7 +54,6 @@ public:
|
|||
void refreshDisplayedDiveSite();
|
||||
void nextInputField(QKeyEvent *event);
|
||||
void showAndTriggerEditSelective(struct dive_components what);
|
||||
virtual bool eventFilter(QObject*, QEvent*);
|
||||
|
||||
signals:
|
||||
void addDiveFinished();
|
||||
|
@ -69,7 +67,7 @@ slots:
|
|||
void updateDiveInfo(bool clear = false);
|
||||
void acceptChanges();
|
||||
void rejectChanges();
|
||||
void on_location_editingFinished();
|
||||
void on_location_diveSiteSelected();
|
||||
void on_location_textChanged();
|
||||
void on_divemaster_textChanged();
|
||||
void on_buddy_textChanged();
|
||||
|
@ -124,7 +122,6 @@ private:
|
|||
dive_trip_t *currentTrip;
|
||||
dive_trip_t displayedTrip;
|
||||
bool acceptingEdit;
|
||||
LocationManagementEditHelper *locationManagementEditHelper;
|
||||
void updateDisplayedDiveSite();
|
||||
void updateDiveSite(int divenr);
|
||||
};
|
||||
|
|
|
@ -188,7 +188,7 @@
|
|||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="location"/>
|
||||
<widget class="DiveLocationLineEdit" name="location"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="editDiveSiteButton">
|
||||
|
@ -1131,6 +1131,11 @@
|
|||
<header>qtwaitingspinner.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>DiveLocationLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>locationinformation.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>dateEdit</tabstop>
|
||||
|
|
Loading…
Add table
Reference in a new issue