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 <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-06-25 14:24:22 -03:00 committed by Dirk Hohndel
parent f763da66b3
commit 8bd9fb161a
3 changed files with 38 additions and 32 deletions

View file

@ -99,7 +99,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
connect(ui.cylinders->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editCylinderWidget(QModelIndex))); connect(ui.cylinders->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editCylinderWidget(QModelIndex)));
connect(ui.weights->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editWeightWidget(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::TYPE, new TankInfoDelegate(this));
ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::USE, new TankUseDelegate(this)); ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::USE, new TankUseDelegate(this));
ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this)); ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this));
@ -227,9 +227,9 @@ void MainTab::setCurrentLocationIndex()
if (current_dive) { if (current_dive) {
struct dive_site *ds = get_dive_site_by_uuid(current_dive->dive_site_uuid); struct dive_site *ds = get_dive_site_by_uuid(current_dive->dive_site_uuid);
if (ds) if (ds)
ui.location->setCurrentText(ds->name); ui.location->setText(ds->name);
else else
ui.location->setCurrentIndex(-1); ui.location->clear();
} }
} }
@ -430,9 +430,9 @@ bool MainTab::isEditing()
void MainTab::showLocation() void MainTab::showLocation()
{ {
if (get_dive_site_by_uuid(displayed_dive.dive_site_uuid)) 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 else
ui.location->setCurrentIndex(-1); ui.location->clear();
} }
void MainTab::updateDiveInfo(bool clear) void MainTab::updateDiveInfo(bool clear)
@ -457,7 +457,6 @@ void MainTab::updateDiveInfo(bool clear)
process_selected_dives(); process_selected_dives();
process_all_dives(&displayed_dive, &prevd); process_all_dives(&displayed_dive, &prevd);
ui.location->blockSignals(true);
divePictureModel->updateDivePictures(); divePictureModel->updateDivePictures();
@ -480,9 +479,9 @@ void MainTab::updateDiveInfo(bool clear)
if (!clear) { if (!clear) {
struct dive_site *ds = get_dive_site_by_uuid(displayed_dive.dive_site_uuid); struct dive_site *ds = get_dive_site_by_uuid(displayed_dive.dive_site_uuid);
if (ds) if (ds)
ui.location->setCurrentText(ds->name); ui.location->setText(ds->name);
else else
ui.location->setCurrentIndex(-1); ui.location->clear();
// Subsurface always uses "local time" as in "whatever was the local time at the location" // 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 // 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)); 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); ui.watertemp->setVisible(false);
// rename the remaining fields and fill data from selected trip // rename the remaining fields and fill data from selected trip
ui.LocationLabel->setText(tr("Trip location")); ui.LocationLabel->setText(tr("Trip location"));
ui.location->setCurrentText(currentTrip->location); ui.location->setText(currentTrip->location);
ui.NotesLabel->setText(tr("Trip notes")); ui.NotesLabel->setText(tr("Trip notes"));
ui.notes->setText(currentTrip->notes); ui.notes->setText(currentTrip->notes);
clearEquipment(); clearEquipment();
@ -700,8 +699,6 @@ void MainTab::updateDiveInfo(bool clear)
else else
ui.cylinders->view()->hideColumn(CylindersModel::USE); ui.cylinders->view()->hideColumn(CylindersModel::USE);
ui.location->blockSignals(false);
emit diveSiteChanged(displayed_dive.dive_site_uuid); emit diveSiteChanged(displayed_dive.dive_site_uuid);
} }
@ -1269,22 +1266,38 @@ void MainTab::on_tagWidget_textChanged()
markChangedWidget(ui.tagWidget); markChangedWidget(ui.tagWidget);
} }
void MainTab::on_location_currentIndexChanged(int idx) void MainTab::on_location_editingFinished()
{ {
if (editMode == IGNORE || acceptingEdit == true) if (editMode == IGNORE || acceptingEdit == true)
return; return;
if (currentTrip) { if (currentTrip) {
free(displayedTrip.location); 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)) if (!get_dive_site(idx))
return; return;
if (current_dive) { if (current_dive) {
struct dive_site *ds_from_dive = get_dive_site_by_uuid(displayed_dive.dive_site_uuid); 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; return;
ds_from_dive = get_dive_site(idx); ds_from_dive = get_dive_site(idx);
displayed_dive.dive_site_uuid = ds_from_dive->uuid; displayed_dive.dive_site_uuid = ds_from_dive->uuid;
@ -1420,7 +1433,7 @@ void MainTab::showAndTriggerEditSelective(struct dive_components what)
if (what.visibility) if (what.visibility)
ui.visibility->setCurrentStars(displayed_dive.visibility); ui.visibility->setCurrentStars(displayed_dive.visibility);
if (what.divesite) if (what.divesite)
ui.location->setCurrentText(get_dive_location(&displayed_dive)); ui.location->setText(get_dive_location(&displayed_dive));
if (what.tags) { if (what.tags) {
char buf[1024]; char buf[1024];
taglist_get_tagstring(displayed_dive.tag_list, buf, 1024); taglist_get_tagstring(displayed_dive.tag_list, buf, 1024);

View file

@ -65,7 +65,7 @@ slots:
void updateDiveInfo(bool clear = false); void updateDiveInfo(bool clear = false);
void acceptChanges(); void acceptChanges();
void rejectChanges(); void rejectChanges();
void on_location_currentIndexChanged(int idx); void on_location_editingFinished();
void on_divemaster_textChanged(); void on_divemaster_textChanged();
void on_buddy_textChanged(); void on_buddy_textChanged();
void on_suit_textChanged(const QString &text); void on_suit_textChanged(const QString &text);

View file

@ -55,8 +55,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>445</width> <width>449</width>
<height>760</height> <height>751</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
@ -186,14 +186,7 @@
<number>2</number> <number>2</number>
</property> </property>
<item> <item>
<widget class="QComboBox" name="location"> <widget class="QLineEdit" name="location"/>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="addDiveSite"> <widget class="QToolButton" name="addDiveSite">
@ -539,8 +532,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>445</width> <width>100</width>
<height>754</height> <height>30</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="equipmentTabScrollAreaLayout"> <layout class="QGridLayout" name="equipmentTabScrollAreaLayout">
@ -634,8 +627,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>445</width> <width>389</width>
<height>754</height> <height>430</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="diveInfoScrollAreaLayout"> <layout class="QGridLayout" name="diveInfoScrollAreaLayout">
@ -975,8 +968,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>445</width> <width>408</width>
<height>754</height> <height>253</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">