summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-19 17:38:20 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-19 17:38:20 -0700
commitadc76548165feeb28571fecd3a3d24dc674580db (patch)
tree20d985b4ed5704e36da0efe71a95ab1ab034a137
parentf67d3d4bbcb42b8660f4f9833acc6234332d8d68 (diff)
downloadsubsurface-adc76548165feeb28571fecd3a3d24dc674580db.tar.gz
When no dive is displayed, the DiveNotes field should not be editable
This also fixes a potential crash if no dives were loaded and the user started editing the fields and clicked OK. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/maintab.cpp40
1 files changed, 32 insertions, 8 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 8267c1139..18f715f01 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -28,12 +28,14 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui->diveNotesMessage->hide();
ui->diveNotesMessage->setCloseButtonVisible(false);
- ui->location->setReadOnly(false);
- ui->divemaster->setReadOnly(false);
- ui->buddy->setReadOnly(false);
- ui->suit->setReadOnly(false);
- ui->notes->setReadOnly(false);
- ui->rating->setReadOnly(false);
+ // we start out with the fields read-only; once things are
+ // filled from a dive, they are made writeable
+ ui->location->setReadOnly(true);
+ ui->divemaster->setReadOnly(true);
+ ui->buddy->setReadOnly(true);
+ ui->suit->setReadOnly(true);
+ ui->notes->setReadOnly(true);
+ ui->rating->setReadOnly(true);
ui->editAccept->hide();
ui->editReset->hide();
@@ -62,9 +64,9 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
bool MainTab::eventFilter(QObject* object, QEvent* event)
{
if (event->type() == QEvent::FocusIn) {
- if (ui->editAccept->isVisible()) {
+ if (ui->editAccept->isVisible() || !currentDive)
return false;
- }
+
ui->editAccept->setChecked(true);
ui->editAccept->show();
ui->editReset->show();
@@ -92,6 +94,12 @@ void MainTab::clearInfo()
ui->waterTemperatureText->clear();
ui->airTemperatureText->clear();
ui->airPressureText->clear();
+ ui->location->setReadOnly(true);
+ ui->divemaster->setReadOnly(true);
+ ui->buddy->setReadOnly(true);
+ ui->suit->setReadOnly(true);
+ ui->notes->setReadOnly(true);
+ ui->rating->setReadOnly(true);
}
void MainTab::clearStats()
@@ -143,6 +151,14 @@ void MainTab::updateDiveInfo(int dive)
UPDATE_TEXT(d, buddy);
/* infoTab */
if (d) {
+ /* make the fields writeable */
+ ui->location->setReadOnly(false);
+ ui->divemaster->setReadOnly(false);
+ ui->buddy->setReadOnly(false);
+ ui->suit->setReadOnly(false);
+ ui->notes->setReadOnly(false);
+ ui->rating->setReadOnly(false);
+ /* and fill them from the dive */
ui->rating->setCurrentStars(d->rating);
ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE));
ui->averageDepthText->setText(get_depth_string(d->meandepth, TRUE));
@@ -165,6 +181,14 @@ void MainTab::updateDiveInfo(int dive)
else
ui->airPressureText->clear();
} else {
+ /* make the fields read-only */
+ ui->location->setReadOnly(true);
+ ui->divemaster->setReadOnly(true);
+ ui->buddy->setReadOnly(true);
+ ui->suit->setReadOnly(true);
+ ui->notes->setReadOnly(true);
+ ui->rating->setReadOnly(true);
+ /* clear the fields */
ui->rating->setCurrentStars(0);
ui->sacText->clear();
ui->otuText->clear();