mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Get the selected dive site from the list
Hooked up an eventFilter on the QListView that displays our dive sites so it would filter the keys enter and space, storing the current dive_site uuid when that happens. Also it stores the uuid on clicks. Now we need to get that information when processing acceptedChanges() and check if the uuid stored there == displayed_dive_site.uuid and also if text != displayed_dive_site.name, because if the user didn't click on anything but only wrote stuff on the LineEdit no dive site would be selected and so uuid == displayed_dive_site.uuid (wich would mean 'no changes') Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
e82f8ea565
commit
3b2a02dffa
4 changed files with 53 additions and 0 deletions
|
@ -324,3 +324,37 @@ void SimpleDiveSiteEditDialog::diveSiteNotes_editingFinished()
|
|||
displayed_dive_site.notes = copy_string(qPrintable(ui->diveSiteNotes->toPlainText()));
|
||||
changed_dive_site = true;
|
||||
}
|
||||
|
||||
bool LocationManagementEditHelper::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
QListView *view = qobject_cast<QListView*>(obj);
|
||||
if(!view)
|
||||
return false;
|
||||
|
||||
if(ev->type() == QEvent::Show) {
|
||||
last_uuid = displayed_dive_site.uuid;
|
||||
}
|
||||
|
||||
if(ev->type() == QEvent::KeyPress) {
|
||||
QKeyEvent *keyEv = (QKeyEvent*) ev;
|
||||
if(keyEv->key() == Qt::Key_Space || keyEv->key() == Qt::Key_Return) {
|
||||
handleActivation(view->currentIndex());
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void LocationManagementEditHelper::handleActivation(const QModelIndex& activated)
|
||||
{
|
||||
if (!activated.isValid())
|
||||
return;
|
||||
QModelIndex uuidIdx = activated.model()->index(
|
||||
activated.row(), LocationInformationModel::UUID);
|
||||
last_uuid = uuidIdx.data().toInt();
|
||||
qDebug() << "Selected dive_site: " << last_uuid;
|
||||
}
|
||||
|
||||
void LocationManagementEditHelper::resetDiveSiteUuid() {
|
||||
last_uuid = displayed_dive_site.uuid;
|
||||
}
|
||||
|
|
|
@ -63,5 +63,16 @@ protected:
|
|||
private:
|
||||
Ui::SimpleDiveSiteEditDialog *ui;
|
||||
|
||||
};
|
||||
|
||||
class LocationManagementEditHelper : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool eventFilter(QObject *obj, QEvent *ev);
|
||||
void handleActivation(const QModelIndex& activated);
|
||||
void resetDiveSiteUuid();
|
||||
private:
|
||||
uint32_t last_uuid;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -67,6 +67,11 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
|||
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
completerListview->setItemDelegate(new LocationFilterDelegate());
|
||||
|
||||
locationManagementEditHelper = new LocationManagementEditHelper();
|
||||
completerListview->installEventFilter(locationManagementEditHelper);
|
||||
connect(completerListview, &QAbstractItemView::activated,
|
||||
locationManagementEditHelper, &LocationManagementEditHelper::handleActivation);
|
||||
|
||||
ui.location->setCompleter(completer);
|
||||
connect(ui.addDiveSite, SIGNAL(clicked()), this, SLOT(showDiveSiteSimpleEdit()));
|
||||
connect(ui.geocodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode()));
|
||||
|
@ -386,6 +391,7 @@ void MainTab::enableEdition(EditMode newEditMode)
|
|||
displayMessage(tr("Multiple dives are being edited."));
|
||||
} else {
|
||||
displayMessage(tr("This dive is being edited."));
|
||||
locationManagementEditHelper->resetDiveSiteUuid();
|
||||
}
|
||||
editMode = newEditMode != NONE ? newEditMode : DIVE;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ class CylindersModel;
|
|||
class ExtraDataModel;
|
||||
class DivePictureModel;
|
||||
class QCompleter;
|
||||
class LocationManagementEditHelper;
|
||||
|
||||
struct Completers {
|
||||
QCompleter *divemaster;
|
||||
|
@ -121,6 +122,7 @@ private:
|
|||
dive_trip_t *currentTrip;
|
||||
dive_trip_t displayedTrip;
|
||||
bool acceptingEdit;
|
||||
LocationManagementEditHelper *locationManagementEditHelper;
|
||||
};
|
||||
|
||||
#endif // MAINTAB_H
|
||||
|
|
Loading…
Reference in a new issue