From 8bd9fb161a8607683d94b7179f46888cb44be9f4 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 25 Jun 2015 14:24:22 -0300 Subject: [PATCH] Dive site rewrite: location edit on notes tab is again a LineEdit Hopefully we now have the UI semantics figured out. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 43 ++++++++++++++++++++++++++++--------------- qt-ui/maintab.h | 2 +- qt-ui/maintab.ui | 25 +++++++++---------------- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index c6660fc6b..adc60aec0 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -99,7 +99,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), connect(ui.cylinders->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editCylinderWidget(QModelIndex))); connect(ui.weights->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editWeightWidget(QModelIndex))); - ui.location->setModel(LocationInformationModel::instance()); + ui.location->setCompleter(new QCompleter(LocationInformationModel::instance())); ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this)); ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::USE, new TankUseDelegate(this)); ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this)); @@ -227,9 +227,9 @@ void MainTab::setCurrentLocationIndex() if (current_dive) { struct dive_site *ds = get_dive_site_by_uuid(current_dive->dive_site_uuid); if (ds) - ui.location->setCurrentText(ds->name); + ui.location->setText(ds->name); else - ui.location->setCurrentIndex(-1); + ui.location->clear(); } } @@ -430,9 +430,9 @@ bool MainTab::isEditing() void MainTab::showLocation() { if (get_dive_site_by_uuid(displayed_dive.dive_site_uuid)) - ui.location->setCurrentText(get_dive_location(&displayed_dive)); + ui.location->setText(get_dive_location(&displayed_dive)); else - ui.location->setCurrentIndex(-1); + ui.location->clear(); } void MainTab::updateDiveInfo(bool clear) @@ -457,7 +457,6 @@ void MainTab::updateDiveInfo(bool clear) process_selected_dives(); process_all_dives(&displayed_dive, &prevd); - ui.location->blockSignals(true); divePictureModel->updateDivePictures(); @@ -480,9 +479,9 @@ void MainTab::updateDiveInfo(bool clear) if (!clear) { struct dive_site *ds = get_dive_site_by_uuid(displayed_dive.dive_site_uuid); if (ds) - ui.location->setCurrentText(ds->name); + ui.location->setText(ds->name); else - ui.location->setCurrentIndex(-1); + ui.location->clear(); // Subsurface always uses "local time" as in "whatever was the local time at the location" // so all time stamps have no time zone information and are in UTC QDateTime localTime = QDateTime::fromTime_t(displayed_dive.when - gettimezoneoffset(displayed_dive.when)); @@ -513,7 +512,7 @@ void MainTab::updateDiveInfo(bool clear) ui.watertemp->setVisible(false); // rename the remaining fields and fill data from selected trip ui.LocationLabel->setText(tr("Trip location")); - ui.location->setCurrentText(currentTrip->location); + ui.location->setText(currentTrip->location); ui.NotesLabel->setText(tr("Trip notes")); ui.notes->setText(currentTrip->notes); clearEquipment(); @@ -700,8 +699,6 @@ void MainTab::updateDiveInfo(bool clear) else ui.cylinders->view()->hideColumn(CylindersModel::USE); - ui.location->blockSignals(false); - emit diveSiteChanged(displayed_dive.dive_site_uuid); } @@ -1269,22 +1266,38 @@ void MainTab::on_tagWidget_textChanged() markChangedWidget(ui.tagWidget); } -void MainTab::on_location_currentIndexChanged(int idx) +void MainTab::on_location_editingFinished() { if (editMode == IGNORE || acceptingEdit == true) return; if (currentTrip) { free(displayedTrip.location); - displayedTrip.location = strdup(qPrintable(ui.location->currentText())); + displayedTrip.location = strdup(qPrintable(ui.location->text())); } + QString currText = ui.location->text(); + QModelIndexList list = LocationInformationModel::instance()->match( + LocationInformationModel::instance()->index(0,0), + Qt::DisplayRole, + currText, + 1, + Qt::MatchExactly + ); + + if (list.isEmpty()) { + qDebug() << "TODO: add this string on the location management."; + return; + } + + int idx = list.first().row(); + 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->currentText() == ds_from_dive->name) + if(ds_from_dive && ui.location->text() == ds_from_dive->name) return; ds_from_dive = get_dive_site(idx); displayed_dive.dive_site_uuid = ds_from_dive->uuid; @@ -1420,7 +1433,7 @@ void MainTab::showAndTriggerEditSelective(struct dive_components what) if (what.visibility) ui.visibility->setCurrentStars(displayed_dive.visibility); if (what.divesite) - ui.location->setCurrentText(get_dive_location(&displayed_dive)); + ui.location->setText(get_dive_location(&displayed_dive)); if (what.tags) { char buf[1024]; taglist_get_tagstring(displayed_dive.tag_list, buf, 1024); diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h index 8b5880cb9..39350c956 100644 --- a/qt-ui/maintab.h +++ b/qt-ui/maintab.h @@ -65,7 +65,7 @@ slots: void updateDiveInfo(bool clear = false); void acceptChanges(); void rejectChanges(); - void on_location_currentIndexChanged(int idx); + void on_location_editingFinished(); void on_divemaster_textChanged(); void on_buddy_textChanged(); void on_suit_textChanged(const QString &text); diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index d681fbdbb..c78ced6f3 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -55,8 +55,8 @@ 0 0 - 445 - 760 + 449 + 751 @@ -186,14 +186,7 @@ 2 - - - - 0 - 0 - - - + @@ -539,8 +532,8 @@ 0 0 - 445 - 754 + 100 + 30 @@ -634,8 +627,8 @@ 0 0 - 445 - 754 + 389 + 430 @@ -975,8 +968,8 @@ 0 0 - 445 - 754 + 408 + 253