Show & edit trip location and notes when exactly one trip is selected

While we still show the selected_dive in the profile and use it for Dive
Info and Equipment, in the Dive Notes tab we now show the trip location
and trip notes (and none of the other fields), if the user directly
selects a whole trip by clicking on the trip header.

This clever reuse of the widget now allows trip location and notes to be
edited in place.

As a side note: the Gtk version has long allowed the user to edit the
trip location and trip notes, but nowhere did it ever SHOW the trip
notes... so this is more than just feature parity...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-06-14 09:17:46 -07:00
parent 8669de63e1
commit a960cd2d45
5 changed files with 135 additions and 76 deletions

View file

@ -42,6 +42,7 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
searchBox->hide(); searchBox->hide();
connect(showSearchBox, SIGNAL(triggered(bool)), this, SLOT(showSearchEdit())); connect(showSearchBox, SIGNAL(triggered(bool)), this, SLOT(showSearchEdit()));
connect(searchBox, SIGNAL(textChanged(QString)), model, SLOT(setFilterFixedString(QString))); connect(searchBox, SIGNAL(textChanged(QString)), model, SLOT(setFilterFixedString(QString)));
selectedTrips.clear();
} }
void DiveListView::fixMessyQtModelBehaviour() void DiveListView::fixMessyQtModelBehaviour()
@ -253,6 +254,8 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
if (!dive) { // it's a trip! if (!dive) { // it's a trip!
if (model->rowCount(index)) { if (model->rowCount(index)) {
struct dive *child = (struct dive*) model->data(index.child(0,0), TreeItemDT::DIVE_ROLE).value<void*>(); struct dive *child = (struct dive*) model->data(index.child(0,0), TreeItemDT::DIVE_ROLE).value<void*>();
if (child && child->divetrip)
selectedTrips.remove(child->divetrip);
while (child) { while (child) {
deselect_dive(get_index_for_dive(child)); deselect_dive(get_index_for_dive(child));
child = child->next; child = child->next;
@ -272,6 +275,8 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
if (model->rowCount(index)) { if (model->rowCount(index)) {
QItemSelection selection; QItemSelection selection;
struct dive *child = (struct dive*) model->data(index.child(0,0), TreeItemDT::DIVE_ROLE).value<void*>(); struct dive *child = (struct dive*) model->data(index.child(0,0), TreeItemDT::DIVE_ROLE).value<void*>();
if (child && child->divetrip)
selectedTrips.insert(child->divetrip);
while (child) { while (child) {
select_dive(get_index_for_dive(child)); select_dive(get_index_for_dive(child));
child = child->next; child = child->next;

View file

@ -29,6 +29,7 @@ public:
void unselectDives(); void unselectDives();
void selectDive(struct dive *, bool scrollto = false, bool toggle = false); void selectDive(struct dive *, bool scrollto = false, bool toggle = false);
void contextMenuEvent(QContextMenuEvent *event); void contextMenuEvent(QContextMenuEvent *event);
QSet<dive_trip_t *> selectedTrips;
public slots: public slots:
void toggleColumnVisibilityByIndex(); void toggleColumnVisibilityByIndex();
@ -39,7 +40,7 @@ public slots:
void deleteDive(); void deleteDive();
void testSlot(); void testSlot();
void fixMessyQtModelBehaviour(); void fixMessyQtModelBehaviour();
Q_SIGNALS: Q_SIGNALS:
void currentDiveChanged(int divenr); void currentDiveChanged(int divenr);

View file

@ -15,12 +15,14 @@
#include <QLabel> #include <QLabel>
#include <QDebug> #include <QDebug>
#include <QSet>
MainTab::MainTab(QWidget *parent) : QTabWidget(parent), MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui(new Ui::MainTab()), ui(new Ui::MainTab()),
weightModel(new WeightModel()), weightModel(new WeightModel()),
cylindersModel(new CylindersModel()), cylindersModel(new CylindersModel()),
currentDive(0) currentDive(0),
editMode(NONE)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->cylinders->setModel(cylindersModel); ui->cylinders->setModel(cylindersModel);
@ -159,15 +161,11 @@ void MainTab::clearStats()
void MainTab::updateDiveInfo(int dive) void MainTab::updateDiveInfo(int dive)
{ {
// So, this is what happens now: // This method updates ALL tabs whenever a new dive or trip is
// Every tab should be populated from this method, // selected.
// it will be called whenever a new dive is selected // If exactly one trip has been selected, we show the location / notes
// I'm already populating the 'notes' box // for the trip in the Info tab, otherwise we show the info of the
// to show how it can be done. // selected_dive
// If you are unsure about the name of something,
// open the file maintab.ui on the designer
// click on the item and check its objectName,
// the access is ui->objectName from here on.
volume_t sacVal; volume_t sacVal;
temperature_t temp; temperature_t temp;
struct dive *prevd; struct dive *prevd;
@ -181,18 +179,48 @@ void MainTab::updateDiveInfo(int dive)
UPDATE_TEXT(d, suit); UPDATE_TEXT(d, suit);
UPDATE_TEXT(d, divemaster); UPDATE_TEXT(d, divemaster);
UPDATE_TEXT(d, buddy); UPDATE_TEXT(d, buddy);
/* infoTab */
if (d) { if (d) {
/* make the fields writeable */ if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
ui->location->setReadOnly(false); // only use trip relevant fields
ui->divemaster->setReadOnly(false); ui->divemaster->setVisible(false);
ui->buddy->setReadOnly(false); ui->DivemasterLabel->setVisible(false);
ui->suit->setReadOnly(false); ui->buddy->setVisible(false);
ui->notes->setReadOnly(false); ui->BuddyLabel->setVisible(false);
ui->rating->setReadOnly(false); ui->suit->setVisible(false);
ui->visibility->setReadOnly(false); ui->SuitLabel->setVisible(false);
/* and fill them from the dive */ ui->rating->setVisible(false);
ui->rating->setCurrentStars(d->rating); ui->RatingLabel->setVisible(false);
ui->visibility->setVisible(false);
ui->visibilityLabel->setVisible(false);
// rename the remaining fields and fill data from selected trip
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
ui->location->setReadOnly(false);
ui->LocationLabel->setText(tr("Trip Location"));
ui->location->setText(currentTrip->location);
ui->notes->setReadOnly(false);
ui->NotesLabel->setText(tr("Trip Notes"));
ui->notes->setText(currentTrip->notes);
} else {
// make all the fields visible writeable
ui->divemaster->setVisible(true);
ui->buddy->setVisible(true);
ui->suit->setVisible(true);
ui->rating->setVisible(true);
ui->visibility->setVisible(true);
ui->divemaster->setReadOnly(false);
ui->buddy->setReadOnly(false);
ui->suit->setReadOnly(false);
ui->rating->setReadOnly(false);
ui->visibility->setReadOnly(false);
/* and fill them from the dive */
ui->rating->setCurrentStars(d->rating);
ui->visibility->setCurrentStars(d->visibility);
// reset labels in case we last displayed trip notes
ui->location->setReadOnly(false);
ui->LocationLabel->setText(tr("Location"));
ui->notes->setReadOnly(false);
ui->NotesLabel->setText(tr("Notes"));
}
ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE)); ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE));
ui->averageDepthText->setText(get_depth_string(d->meandepth, TRUE)); ui->averageDepthText->setText(get_depth_string(d->meandepth, TRUE));
ui->otuText->setText(QString("%1").arg(d->otu)); ui->otuText->setText(QString("%1").arg(d->otu));
@ -213,7 +241,6 @@ void MainTab::updateDiveInfo(int dive)
ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar)); ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar));
else else
ui->airPressureText->clear(); ui->airPressureText->clear();
ui->visibility->setCurrentStars(d->visibility);
ui->depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, TRUE)); ui->depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, TRUE));
ui->depthLimits->setMinimum(get_depth_string(stats_selection.min_depth, TRUE)); ui->depthLimits->setMinimum(get_depth_string(stats_selection.min_depth, TRUE));
ui->depthLimits->setAverage(get_depth_string(stats_selection.avg_depth, TRUE)); ui->depthLimits->setAverage(get_depth_string(stats_selection.avg_depth, TRUE));
@ -276,13 +303,6 @@ void MainTab::updateDiveInfo(int dive)
ui->totalTimeAllText->clear(); ui->totalTimeAllText->clear();
ui->timeLimits->clear(); ui->timeLimits->clear();
} }
/* statisticsTab*/
/* we can access the stats_selection struct, but how do we ensure the relevant dives are selected
* if we don't use the gtk widget to drive this?
* Maybe call process_selected_dives? Or re-write to query our Qt list view.
*/
// qDebug("max temp %u",stats_selection.max_temp);
// qDebug("min temp %u",stats_selection.min_temp);
} }
void MainTab::addCylinder_clicked() void MainTab::addCylinder_clicked()
@ -312,30 +332,47 @@ void MainTab::on_editAccept_clicked(bool edit)
mainWindow()->dive_list()->setEnabled(!edit); mainWindow()->dive_list()->setEnabled(!edit);
if (edit) { if (edit) {
ui->diveNotesMessage->setText(tr("This dive is being edited. Select Save or Undo when ready.")); if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
ui->diveNotesMessage->animatedShow(); // we are editing trip location and notes
notesBackup.buddy = ui->buddy->text(); ui->diveNotesMessage->setText(tr("This trip is being edited. Select Save or Undo when ready."));
notesBackup.suit = ui->suit->text(); ui->diveNotesMessage->animatedShow();
notesBackup.notes = ui->notes->toPlainText(); notesBackup.notes = ui->notes->toPlainText();
notesBackup.divemaster = ui->divemaster->text(); notesBackup.location = ui->location->text();
notesBackup.location = ui->location->text(); editMode = TRIP;
notesBackup.rating = ui->rating->currentStars(); } else {
notesBackup.visibility = ui->visibility->currentStars(); ui->diveNotesMessage->setText(tr("This dive is being edited. Select Save or Undo 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();
notesBackup.visibility = ui->visibility->currentStars();
editMode = DIVE;
}
} else { } else {
ui->diveNotesMessage->animatedHide(); ui->diveNotesMessage->animatedHide();
ui->editAccept->hide(); ui->editAccept->hide();
ui->editReset->hide(); ui->editReset->hide();
/* now figure out if things have changed */ /* now figure out if things have changed */
if (notesBackup.buddy != ui->buddy->text() || if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
notesBackup.suit != ui->suit->text() || if (notesBackup.notes != ui->notes->toPlainText() ||
notesBackup.notes != ui->notes->toPlainText() || notesBackup.location != ui->location->text())
notesBackup.divemaster != ui->divemaster->text() || mark_divelist_changed(TRUE);
notesBackup.location != ui->location->text() || } else {
notesBackup.visibility != ui->visibility->currentStars() || if (notesBackup.buddy != ui->buddy->text() ||
notesBackup.rating != ui->rating->currentStars()) notesBackup.suit != ui->suit->text() ||
mark_divelist_changed(TRUE); notesBackup.notes != ui->notes->toPlainText() ||
if (notesBackup.location != ui->location->text()) notesBackup.divemaster != ui->divemaster->text() ||
mainWindow()->globe()->reload(); notesBackup.location != ui->location->text() ||
notesBackup.visibility != ui->visibility->currentStars() ||
notesBackup.rating != ui->rating->currentStars())
mark_divelist_changed(TRUE);
if (notesBackup.location != ui->location->text())
mainWindow()->globe()->reload();
}
editMode = NONE;
} }
} }
@ -344,13 +381,15 @@ void MainTab::on_editReset_clicked()
if (!ui->editAccept->isChecked()) if (!ui->editAccept->isChecked())
return; return;
ui->buddy->setText(notesBackup.buddy);
ui->suit->setText(notesBackup.suit);
ui->notes->setText(notesBackup.notes); ui->notes->setText(notesBackup.notes);
ui->divemaster->setText(notesBackup.divemaster);
ui->location->setText(notesBackup.location); ui->location->setText(notesBackup.location);
ui->rating->setCurrentStars(notesBackup.rating); if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() != 1) {
ui->visibility->setCurrentStars(notesBackup.visibility); ui->buddy->setText(notesBackup.buddy);
ui->suit->setText(notesBackup.suit);
ui->divemaster->setText(notesBackup.divemaster);
ui->rating->setCurrentStars(notesBackup.rating);
ui->visibility->setCurrentStars(notesBackup.visibility);
}
ui->editAccept->setChecked(false); ui->editAccept->setChecked(false);
ui->diveNotesMessage->animatedHide(); ui->diveNotesMessage->animatedHide();
@ -365,49 +404,62 @@ void MainTab::on_editReset_clicked()
ui->editAccept->hide(); ui->editAccept->hide();
ui->editReset->hide(); ui->editReset->hide();
editMode = NONE;
} }
#define EDIT_NOTES(what, text) \ #define EDIT_TEXT(what, text) \
QByteArray textByteArray = text.toLocal8Bit(); \ QByteArray textByteArray = text.toLocal8Bit(); \
free(currentDive->what);\ free(what);\
currentDive->what = strdup(textByteArray.data()); what = strdup(textByteArray.data());
void MainTab::on_buddy_textChanged(const QString& text) void MainTab::on_buddy_textChanged(const QString& text)
{ {
if (!currentDive) if (!currentDive)
return; return;
EDIT_NOTES(buddy, text); EDIT_TEXT(currentDive->buddy, text);
} }
void MainTab::on_divemaster_textChanged(const QString& text) void MainTab::on_divemaster_textChanged(const QString& text)
{ {
if (!currentDive) if (!currentDive)
return; return;
EDIT_NOTES(divemaster, text); EDIT_TEXT(currentDive->divemaster, text);
} }
void MainTab::on_location_textChanged(const QString& text) void MainTab::on_location_textChanged(const QString& text)
{ {
if (!currentDive) if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
return; // we are editing a trip
EDIT_NOTES(location, text); dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
EDIT_TEXT(currentTrip->location, text);
} else if (editMode == DIVE){
if (!currentDive)
return;
EDIT_TEXT(currentDive->location, text);
}
} }
void MainTab::on_suit_textChanged(const QString& text) void MainTab::on_suit_textChanged(const QString& text)
{ {
if (!currentDive) if (!currentDive)
return; return;
EDIT_NOTES(suit, text); EDIT_TEXT(currentDive->suit, text);
} }
void MainTab::on_notes_textChanged() void MainTab::on_notes_textChanged()
{ {
if (!currentDive) if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
return; // we are editing a trip
EDIT_NOTES(notes, ui->notes->toPlainText()); dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
EDIT_TEXT(currentTrip->notes, ui->notes->toPlainText());
} else if (editMode == DIVE) {
if (!currentDive)
return;
EDIT_TEXT(currentDive->notes, ui->notes->toPlainText());
}
} }
#undef EDIT_NOTES #undef EDIT_TEXT
void MainTab::on_rating_valueChanged(int value) void MainTab::on_rating_valueChanged(int value)
{ {

View file

@ -63,6 +63,7 @@ private:
struct dive* currentDive; struct dive* currentDive;
QPushButton *addCylinder; QPushButton *addCylinder;
QPushButton *addWeight; QPushButton *addWeight;
enum { NONE, DIVE, TRIP } editMode;
}; };
#endif #endif

View file

@ -6,15 +6,15 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>409</width> <width>505</width>
<height>368</height> <height>459</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>TabWidget</string> <string>TabWidget</string>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>3</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="notesTab"> <widget class="QWidget" name="notesTab">
<attribute name="title"> <attribute name="title">
@ -22,7 +22,7 @@
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="LocationLabel">
<property name="text"> <property name="text">
<string>Location</string> <string>Location</string>
</property> </property>
@ -36,14 +36,14 @@
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="label_15"> <widget class="QLabel" name="DivemasterLabel">
<property name="text"> <property name="text">
<string>Divemaster</string> <string>Divemaster</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="BuddyLabel">
<property name="text"> <property name="text">
<string>Buddy</string> <string>Buddy</string>
</property> </property>
@ -80,7 +80,7 @@
<item row="5" column="0"> <item row="5" column="0">
<layout class="QHBoxLayout" name="ratingVisibilityLabels"> <layout class="QHBoxLayout" name="ratingVisibilityLabels">
<item> <item>
<widget class="QLabel" name="label_14"> <widget class="QLabel" name="RatingLabel">
<property name="text"> <property name="text">
<string>Rating</string> <string>Rating</string>
</property> </property>
@ -96,14 +96,14 @@
</layout> </layout>
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
<widget class="QLabel" name="label_19"> <widget class="QLabel" name="SuitLabel">
<property name="text"> <property name="text">
<string>Suit</string> <string>Suit</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="0"> <item row="7" column="0">
<widget class="QLabel" name="label_16"> <widget class="QLabel" name="NotesLabel">
<property name="text"> <property name="text">
<string>Notes</string> <string>Notes</string>
</property> </property>