summaryrefslogtreecommitdiffstats
path: root/qt-ui/maintab.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-18 20:42:59 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-18 17:06:48 -0700
commitc5e7a025e4c1abcc1ad5d701991fc8f15ae82be6 (patch)
tree6c2e53fb064aecb53ddfd21296a353f86987c63b /qt-ui/maintab.cpp
parentde50f6625746928711d7fb7f0fa579d194931970 (diff)
downloadsubsurface-c5e7a025e4c1abcc1ad5d701991fc8f15ae82be6.tar.gz
Added option to edit the selected dive.
Added option to edit the selected dive. Now the user can click on 'Edit', and a nice box will appear stating that the dive is in edit mode, and the user can edit all of the 'Notes' tab fields, including the rating. When the edition is finished, the user needs to click on 'edit' again to mark as accepted, or in reset to reset the fields to it's original state Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/maintab.cpp')
-rw-r--r--qt-ui/maintab.cpp103
1 files changed, 102 insertions, 1 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 70cb3caea..63e4a33d2 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -12,15 +12,20 @@
#include "../statistics.h"
#include <QLabel>
+#include <QDebug>
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui(new Ui::MainTab()),
weightModel(new WeightModel()),
- cylindersModel(new CylindersModel())
+ cylindersModel(new CylindersModel()),
+ currentDive(0)
{
ui->setupUi(this);
ui->cylinders->setModel(cylindersModel);
ui->weights->setModel(weightModel);
+ ui->diveNotesMessage->hide();
+ ui->diveNotesMessage->setCloseButtonVisible(false);
+ ui->rating->setReadOnly(true);
/* example of where code is more concise than Qt designer */
QList<QObject *> infoTabWidgets = ui->infoTab->children();
@@ -96,6 +101,7 @@ void MainTab::updateDiveInfo(int dive)
// the access is ui->objectName from here on.
volume_t sacVal;
struct dive *d = get_dive(dive);
+ currentDive = d;
UPDATE_TEXT(d, notes);
UPDATE_TEXT(d, location);
UPDATE_TEXT(d, suit);
@@ -202,3 +208,98 @@ void MainTab::reload()
{
cylindersModel->update();
}
+
+void MainTab::on_editNotes_clicked(bool edit)
+{
+ ui->location->setReadOnly(!edit);
+ ui->divemaster->setReadOnly(!edit);
+ ui->buddy->setReadOnly(!edit);
+ ui->suit->setReadOnly(!edit);
+ ui->notes->setReadOnly(!edit);
+ ui->rating->setReadOnly(!edit);
+
+ if (edit){
+ ui->diveNotesMessage->setText("This dive is being edited. click on finish / reset when ready.");
+ ui->diveNotesMessage->animatedShow();
+ notesBackup.buddy = ui->buddy->text();
+ notesBackup.suit = ui->suit->text();
+ notesBackup.notes = ui->notes->toPlainText();
+ notesBackup.divemaster = ui->divemaster->text();
+ notesBackup.location = ui->location->text();
+ notesBackup.rating = ui->rating->currentStars();
+ }
+ else{
+ ui->diveNotesMessage->animatedHide();
+ }
+}
+
+void MainTab::on_resetNotes_clicked()
+{
+ if (!ui->editNotes->isChecked())
+ return;
+
+ ui->buddy->setText(notesBackup.buddy);
+ ui->suit->setText(notesBackup.suit);
+ ui->notes->setText(notesBackup.notes);
+ ui->divemaster->setText(notesBackup.divemaster);
+ ui->location->setText(notesBackup.location);
+ ui->rating->setCurrentStars(notesBackup.rating);
+ ui->editNotes->setChecked(false);
+ ui->diveNotesMessage->animatedHide();
+
+ ui->location->setReadOnly(false);
+ ui->divemaster->setReadOnly(false);
+ ui->buddy->setReadOnly(false);
+ ui->suit->setReadOnly(false);
+ ui->notes->setReadOnly(false);
+ ui->rating->setReadOnly(false);
+}
+
+#define EDIT_NOTES(what, text) \
+ QByteArray textByteArray = text.toLocal8Bit(); \
+ free(currentDive->what);\
+ currentDive->what = strdup(textByteArray.data());
+
+void MainTab::on_buddy_textChanged(const QString& text)
+{
+ if (!currentDive)
+ return;
+ EDIT_NOTES(buddy, text);
+}
+
+void MainTab::on_divemaster_textChanged(const QString& text)
+{
+ if (!currentDive)
+ return;
+ EDIT_NOTES(divemaster, text);
+}
+
+void MainTab::on_location_textChanged(const QString& text)
+{
+ if (!currentDive)
+ return;
+ EDIT_NOTES(location, text);
+}
+
+void MainTab::on_suit_textChanged(const QString& text)
+{
+ if (!currentDive)
+ return;
+ EDIT_NOTES(suit, text);
+}
+
+void MainTab::on_notes_textChanged()
+{
+ if (!currentDive)
+ return;
+ EDIT_NOTES(notes, ui->notes->toPlainText());
+}
+
+#undef EDIT_NOTES
+
+void MainTab::on_rating_valueChanged(int value)
+{
+ if (!currentDive)
+ return;
+ currentDive->rating = value;
+}