mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 19:23:24 +00:00
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:
parent
8669de63e1
commit
a960cd2d45
5 changed files with 135 additions and 76 deletions
|
@ -42,6 +42,7 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
|
|||
searchBox->hide();
|
||||
connect(showSearchBox, SIGNAL(triggered(bool)), this, SLOT(showSearchEdit()));
|
||||
connect(searchBox, SIGNAL(textChanged(QString)), model, SLOT(setFilterFixedString(QString)));
|
||||
selectedTrips.clear();
|
||||
}
|
||||
|
||||
void DiveListView::fixMessyQtModelBehaviour()
|
||||
|
@ -253,6 +254,8 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
|
|||
if (!dive) { // it's a trip!
|
||||
if (model->rowCount(index)) {
|
||||
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) {
|
||||
deselect_dive(get_index_for_dive(child));
|
||||
child = child->next;
|
||||
|
@ -272,6 +275,8 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
|
|||
if (model->rowCount(index)) {
|
||||
QItemSelection selection;
|
||||
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) {
|
||||
select_dive(get_index_for_dive(child));
|
||||
child = child->next;
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
void unselectDives();
|
||||
void selectDive(struct dive *, bool scrollto = false, bool toggle = false);
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
QSet<dive_trip_t *> selectedTrips;
|
||||
|
||||
public slots:
|
||||
void toggleColumnVisibilityByIndex();
|
||||
|
@ -39,7 +40,7 @@ public slots:
|
|||
void deleteDive();
|
||||
void testSlot();
|
||||
void fixMessyQtModelBehaviour();
|
||||
|
||||
|
||||
Q_SIGNALS:
|
||||
void currentDiveChanged(int divenr);
|
||||
|
||||
|
|
|
@ -15,12 +15,14 @@
|
|||
|
||||
#include <QLabel>
|
||||
#include <QDebug>
|
||||
#include <QSet>
|
||||
|
||||
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
||||
ui(new Ui::MainTab()),
|
||||
weightModel(new WeightModel()),
|
||||
cylindersModel(new CylindersModel()),
|
||||
currentDive(0)
|
||||
currentDive(0),
|
||||
editMode(NONE)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->cylinders->setModel(cylindersModel);
|
||||
|
@ -159,15 +161,11 @@ void MainTab::clearStats()
|
|||
|
||||
void MainTab::updateDiveInfo(int dive)
|
||||
{
|
||||
// So, this is what happens now:
|
||||
// Every tab should be populated from this method,
|
||||
// it will be called whenever a new dive is selected
|
||||
// I'm already populating the 'notes' box
|
||||
// to show how it can be done.
|
||||
// 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.
|
||||
// This method updates ALL tabs whenever a new dive or trip is
|
||||
// selected.
|
||||
// If exactly one trip has been selected, we show the location / notes
|
||||
// for the trip in the Info tab, otherwise we show the info of the
|
||||
// selected_dive
|
||||
volume_t sacVal;
|
||||
temperature_t temp;
|
||||
struct dive *prevd;
|
||||
|
@ -181,18 +179,48 @@ void MainTab::updateDiveInfo(int dive)
|
|||
UPDATE_TEXT(d, suit);
|
||||
UPDATE_TEXT(d, divemaster);
|
||||
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);
|
||||
ui->visibility->setReadOnly(false);
|
||||
/* and fill them from the dive */
|
||||
ui->rating->setCurrentStars(d->rating);
|
||||
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
|
||||
// only use trip relevant fields
|
||||
ui->divemaster->setVisible(false);
|
||||
ui->DivemasterLabel->setVisible(false);
|
||||
ui->buddy->setVisible(false);
|
||||
ui->BuddyLabel->setVisible(false);
|
||||
ui->suit->setVisible(false);
|
||||
ui->SuitLabel->setVisible(false);
|
||||
ui->rating->setVisible(false);
|
||||
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->averageDepthText->setText(get_depth_string(d->meandepth, TRUE));
|
||||
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));
|
||||
else
|
||||
ui->airPressureText->clear();
|
||||
ui->visibility->setCurrentStars(d->visibility);
|
||||
ui->depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, TRUE));
|
||||
ui->depthLimits->setMinimum(get_depth_string(stats_selection.min_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->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()
|
||||
|
@ -312,30 +332,47 @@ void MainTab::on_editAccept_clicked(bool edit)
|
|||
mainWindow()->dive_list()->setEnabled(!edit);
|
||||
|
||||
if (edit) {
|
||||
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();
|
||||
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
|
||||
// we are editing trip location and notes
|
||||
ui->diveNotesMessage->setText(tr("This trip is being edited. Select Save or Undo when ready."));
|
||||
ui->diveNotesMessage->animatedShow();
|
||||
notesBackup.notes = ui->notes->toPlainText();
|
||||
notesBackup.location = ui->location->text();
|
||||
editMode = TRIP;
|
||||
} else {
|
||||
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 {
|
||||
ui->diveNotesMessage->animatedHide();
|
||||
ui->editAccept->hide();
|
||||
ui->editReset->hide();
|
||||
/* now figure out if things have changed */
|
||||
if (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.visibility != ui->visibility->currentStars() ||
|
||||
notesBackup.rating != ui->rating->currentStars())
|
||||
mark_divelist_changed(TRUE);
|
||||
if (notesBackup.location != ui->location->text())
|
||||
mainWindow()->globe()->reload();
|
||||
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
|
||||
if (notesBackup.notes != ui->notes->toPlainText() ||
|
||||
notesBackup.location != ui->location->text())
|
||||
mark_divelist_changed(TRUE);
|
||||
} else {
|
||||
if (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.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())
|
||||
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->visibility->setCurrentStars(notesBackup.visibility);
|
||||
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() != 1) {
|
||||
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->diveNotesMessage->animatedHide();
|
||||
|
||||
|
@ -365,49 +404,62 @@ void MainTab::on_editReset_clicked()
|
|||
|
||||
ui->editAccept->hide();
|
||||
ui->editReset->hide();
|
||||
editMode = NONE;
|
||||
}
|
||||
|
||||
#define EDIT_NOTES(what, text) \
|
||||
#define EDIT_TEXT(what, text) \
|
||||
QByteArray textByteArray = text.toLocal8Bit(); \
|
||||
free(currentDive->what);\
|
||||
currentDive->what = strdup(textByteArray.data());
|
||||
free(what);\
|
||||
what = strdup(textByteArray.data());
|
||||
|
||||
void MainTab::on_buddy_textChanged(const QString& text)
|
||||
{
|
||||
if (!currentDive)
|
||||
return;
|
||||
EDIT_NOTES(buddy, text);
|
||||
EDIT_TEXT(currentDive->buddy, text);
|
||||
}
|
||||
|
||||
void MainTab::on_divemaster_textChanged(const QString& text)
|
||||
{
|
||||
if (!currentDive)
|
||||
return;
|
||||
EDIT_NOTES(divemaster, text);
|
||||
EDIT_TEXT(currentDive->divemaster, text);
|
||||
}
|
||||
|
||||
void MainTab::on_location_textChanged(const QString& text)
|
||||
{
|
||||
if (!currentDive)
|
||||
return;
|
||||
EDIT_NOTES(location, text);
|
||||
if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
|
||||
// we are editing a trip
|
||||
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)
|
||||
{
|
||||
if (!currentDive)
|
||||
return;
|
||||
EDIT_NOTES(suit, text);
|
||||
EDIT_TEXT(currentDive->suit, text);
|
||||
}
|
||||
|
||||
void MainTab::on_notes_textChanged()
|
||||
{
|
||||
if (!currentDive)
|
||||
return;
|
||||
EDIT_NOTES(notes, ui->notes->toPlainText());
|
||||
if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
|
||||
// we are editing a trip
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -63,6 +63,7 @@ private:
|
|||
struct dive* currentDive;
|
||||
QPushButton *addCylinder;
|
||||
QPushButton *addWeight;
|
||||
enum { NONE, DIVE, TRIP } editMode;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>409</width>
|
||||
<height>368</height>
|
||||
<width>505</width>
|
||||
<height>459</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>TabWidget</string>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>3</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="notesTab">
|
||||
<attribute name="title">
|
||||
|
@ -22,7 +22,7 @@
|
|||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="LocationLabel">
|
||||
<property name="text">
|
||||
<string>Location</string>
|
||||
</property>
|
||||
|
@ -36,14 +36,14 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<widget class="QLabel" name="DivemasterLabel">
|
||||
<property name="text">
|
||||
<string>Divemaster</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<widget class="QLabel" name="BuddyLabel">
|
||||
<property name="text">
|
||||
<string>Buddy</string>
|
||||
</property>
|
||||
|
@ -80,7 +80,7 @@
|
|||
<item row="5" column="0">
|
||||
<layout class="QHBoxLayout" name="ratingVisibilityLabels">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_14">
|
||||
<widget class="QLabel" name="RatingLabel">
|
||||
<property name="text">
|
||||
<string>Rating</string>
|
||||
</property>
|
||||
|
@ -96,14 +96,14 @@
|
|||
</layout>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="label_19">
|
||||
<widget class="QLabel" name="SuitLabel">
|
||||
<property name="text">
|
||||
<string>Suit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_16">
|
||||
<widget class="QLabel" name="NotesLabel">
|
||||
<property name="text">
|
||||
<string>Notes</string>
|
||||
</property>
|
||||
|
|
Loading…
Add table
Reference in a new issue