summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/locationinformation.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-25 08:02:06 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-29 00:09:31 +0000
commitb9b1b3146b3a0a05efcb11c50a953f3e8f2e023c (patch)
treea40397ddd9d370deb5ae66920d0bf2e98bf27868 /desktop-widgets/locationinformation.cpp
parent6f98dca26e342dff90c5dba81bf81cbeab5f6e63 (diff)
downloadsubsurface-b9b1b3146b3a0a05efcb11c50a953f3e8f2e023c.tar.gz
Dive site: remove UUIDs from LocationInformationModel
Replace UUIDs from LocationInformationModel and fix the fallout. Notably, replace the UUID "column" by a DIVESITE "column". Getting pointers through Qt's QVariant is horrible, we'll have to think about a better solution. RECENTLY_ADDED_DIVESITE now defines to a special pointer to struct dive_site (defined as ~0). This fixes an interesting logic bug: The old code checked the uuid of the LocationInformationModel (currUuid) for the value "1", which corresponded to RECENTLY_ADDED_DIVESITE. If equal, currType would be set to NEW_DIVE_SITE. Later, _currType_ was compared against _RECENTLY_ADDED_DIVESITE_. This would only work because NEW_DIVE_SITE and RECENTLY_ADDED_DIVESITE both were defined as 1. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/locationinformation.cpp')
-rw-r--r--desktop-widgets/locationinformation.cpp40
1 files changed, 18 insertions, 22 deletions
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp
index 6cdd5c809..6c3c2ccac 100644
--- a/desktop-widgets/locationinformation.cpp
+++ b/desktop-widgets/locationinformation.cpp
@@ -225,7 +225,7 @@ void LocationInformationWidget::initFields(dive_site *ds)
diveSite = ds;
if (ds) {
copy_taxonomy(&ds->taxonomy, &taxonomy);
- filter_model.set(ds->uuid, ds->location);
+ filter_model.set(ds, ds->location);
updateLabels();
enableLocationButtons(dive_site_has_gps_location(ds));
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(ui.diveSiteListView->model());
@@ -382,9 +382,8 @@ QVariant DiveLocationModel::data(const QModelIndex &index, int role) const
static const QIcon geoCode(":geotag-icon");
if (index.row() <= 1) { // two special cases.
- if (index.column() == LocationInformationModel::UUID) {
- return RECENTLY_ADDED_DIVESITE;
- }
+ if (index.column() == LocationInformationModel::DIVESITE)
+ return QVariant::fromValue<void *>(RECENTLY_ADDED_DIVESITE);
switch (role) {
case Qt::DisplayRole:
return new_ds_value[index.row()];
@@ -429,9 +428,9 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) : QLineEdit(parent),
proxy(new DiveLocationFilterProxyModel()),
model(new DiveLocationModel()),
view(new DiveLocationListView()),
- currType(NO_DIVE_SITE)
+ currType(NO_DIVE_SITE),
+ currDs(nullptr)
{
- currUuid = 0;
location_line_edit = this;
proxy->setSourceModel(model);
@@ -507,15 +506,14 @@ void DiveLocationLineEdit::focusOutEvent(QFocusEvent *ev)
void DiveLocationLineEdit::itemActivated(const QModelIndex &index)
{
QModelIndex idx = index;
- if (index.column() == LocationInformationModel::UUID)
+ if (index.column() == LocationInformationModel::DIVESITE)
idx = index.model()->index(index.row(), LocationInformationModel::NAME);
- QModelIndex uuidIndex = index.model()->index(index.row(), LocationInformationModel::UUID);
- uint32_t uuid = uuidIndex.data().toInt();
- currType = uuid == 1 ? NEW_DIVE_SITE : EXISTING_DIVE_SITE;
- currUuid = uuid;
+ dive_site *ds = (dive_site *)index.model()->index(index.row(), LocationInformationModel::DIVESITE).data().value<void *>();
+ currType = ds == RECENTLY_ADDED_DIVESITE ? NEW_DIVE_SITE : EXISTING_DIVE_SITE;
+ currDs = ds;
setText(idx.data().toString());
- if (currUuid == NEW_DIVE_SITE)
+ if (currType == NEW_DIVE_SITE)
qDebug() << "Setting a New dive site";
else
qDebug() << "Setting a Existing dive site";
@@ -580,7 +578,7 @@ void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev)
if (ev->key() != Qt::Key_Up && ev->key() != Qt::Key_Down) {
currType = NEW_DIVE_SITE;
- currUuid = RECENTLY_ADDED_DIVESITE;
+ currDs = RECENTLY_ADDED_DIVESITE;
} else {
showPopup();
}
@@ -626,17 +624,15 @@ void DiveLocationLineEdit::fixPopupPosition()
}
}
-void DiveLocationLineEdit::setCurrentDiveSiteUuid(uint32_t uuid)
+void DiveLocationLineEdit::setCurrentDiveSite(struct dive_site *ds)
{
- currUuid = uuid;
- if (uuid == 0) {
+ currDs = ds;
+ if (!currDs) {
currType = NO_DIVE_SITE;
- }
- struct dive_site *ds = get_dive_site_by_uuid(uuid);
- if (!ds)
clear();
- else
+ } else {
setText(ds->name);
+ }
}
void DiveLocationLineEdit::showPopup()
@@ -654,9 +650,9 @@ DiveLocationLineEdit::DiveSiteType DiveLocationLineEdit::currDiveSiteType() cons
return currType;
}
-uint32_t DiveLocationLineEdit::currDiveSiteUuid() const
+struct dive_site *DiveLocationLineEdit::currDiveSite() const
{
- return currUuid;
+ return currDs;
}
DiveLocationListView::DiveLocationListView(QWidget*)