From 6d9206150a9d0d9496542ab6c4a12d8a41a8f596 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 31 May 2015 17:56:53 -0300 Subject: Organize the dive_sites alphabetically run std::sort on the dive_site list inside of the model. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-models/divelocationmodel.cpp | 7 ++++++- qt-ui/locationinformation.cpp | 8 ++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index 21c3127ca..c335f7039 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -1,6 +1,11 @@ #include "divelocationmodel.h" #include "dive.h" +bool dive_site_less_then(dive_site *a, dive_site *b) +{ + return QString(a->name) <= QString(b->name); +} + LocationInformationModel *LocationInformationModel::instance() { static LocationInformationModel *self = new LocationInformationModel(); @@ -33,7 +38,6 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons void LocationInformationModel::update() { - if (rowCount()) { beginRemoveRows(QModelIndex(), 0, rowCount()-1); endRemoveRows(); @@ -41,6 +45,7 @@ void LocationInformationModel::update() if (dive_site_table.nr) { beginInsertRows(QModelIndex(), 0, dive_site_table.nr); internalRowCount = dive_site_table.nr; + std::sort(dive_site_table.dive_sites, dive_site_table.dive_sites + dive_site_table.nr - 1, dive_site_less_then); endInsertRows(); } } diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 6dc77c571..699b80d47 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -45,11 +45,6 @@ void LocationInformationWidget::setCurrentDiveSite(int dive_nr) void LocationInformationWidget::setLocationId(uint32_t uuid) { - LocationInformationModel *m = (LocationInformationModel*) ui.currentLocation->model(); - if (m->rowCount() == 0) { - m->update(); - } - currentDs = get_dive_site_by_uuid(uuid); if(!currentDs) return; @@ -138,7 +133,8 @@ void LocationInformationWidget::rejectChanges() void LocationInformationWidget::showEvent(QShowEvent *ev) { - emit startFilterDiveSite(displayed_dive_site.uuid); + if (displayed_dive_site.uuid) + emit startFilterDiveSite(displayed_dive_site.uuid); ui.diveSiteMessage->setCloseButtonVisible(false); QGroupBox::showEvent(ev); } -- cgit v1.2.3-70-g09d2