diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-16 16:00:33 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-05-16 12:23:38 -0700 |
commit | d39b1aedcd9dedecfca54c91661a81406b80c6ec (patch) | |
tree | 722d67b585e200cd298058308563aeca78c85a29 /qt-ui/divelistview.cpp | |
parent | e3cb36498d97750a9a961be21f5adb9073fa6863 (diff) | |
download | subsurface-d39b1aedcd9dedecfca54c91661a81406b80c6ec.tar.gz |
Fix loading a second dive, after the first file was loaded.
This patch fixes loading a second dive-file after the first
one had been loaded. it simply clears some information and
makes sure that the current selected dive is invalid when
the file closes. I also did a bit of code cleanup on this one
to make things simpler in the future.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r-- | qt-ui/divelistview.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index d2354d910..bed0599b0 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -11,12 +11,31 @@ #include <QHeaderView> #include <QDebug> #include <QKeyEvent> +#include <QSortFilterProxyModel> DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false) { setUniformRowHeights(true); setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate()); + QSortFilterProxyModel *model = new QSortFilterProxyModel(this); + setModel(model); +} + +void DiveListView::reload() +{ + QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model()); + QAbstractItemModel *oldModel = m->sourceModel(); + oldModel->deleteLater(); + m->setSourceModel(new DiveTripModel(this)); + sortByColumn(0, Qt::DescendingOrder); + QModelIndex firstDiveOrTrip = m->index(0,0); + if (firstDiveOrTrip.isValid()){ + if (m->index(0,0, firstDiveOrTrip).isValid()) + setCurrentIndex(m->index(0,0, firstDiveOrTrip)); + else + setCurrentIndex(firstDiveOrTrip); + } } void DiveListView::setModel(QAbstractItemModel* model) |