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 | |
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')
-rw-r--r-- | qt-ui/divelistview.cpp | 19 | ||||
-rw-r--r-- | qt-ui/divelistview.h | 2 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 33 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 2 | ||||
-rw-r--r-- | qt-ui/profilegraphics.cpp | 19 | ||||
-rw-r--r-- | qt-ui/profilegraphics.h | 1 |
6 files changed, 41 insertions, 35 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) diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h index ce6238d25..09830b7b5 100644 --- a/qt-ui/divelistview.h +++ b/qt-ui/divelistview.h @@ -29,6 +29,8 @@ public: void keyPressEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent*); void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command); + void reload(); + Q_SIGNALS: void currentDiveChanged(int divenr); private: diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index d676549d1..e555473ca 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -11,7 +11,6 @@ #include <QMessageBox> #include <QtDebug> #include <QDateTime> -#include <QSortFilterProxyModel> #include <QSettings> #include <QCloseEvent> #include <QApplication> @@ -27,24 +26,14 @@ #include "modeldelegates.h" #include "models.h" -MainWindow::MainWindow() : ui(new Ui::MainWindow()), - model(new DiveTripModel(this)), - sortModel(new QSortFilterProxyModel()) +MainWindow::MainWindow() : ui(new Ui::MainWindow()) { ui->setupUi(this); readSettings(); - sortModel->setSourceModel(model); - ui->ListWidget->setModel(sortModel); setWindowIcon(QIcon(":subsurface-icon")); connect(ui->ListWidget, SIGNAL(currentDiveChanged(int)), this, SLOT(current_dive_changed(int))); ui->ProfileWidget->setFocusProxy(ui->ListWidget); - - QModelIndex firstDiveOrTrip = sortModel->index(0,0); - if (sortModel->index(0,0, firstDiveOrTrip).isValid()) - ui->ListWidget->setCurrentIndex(sortModel->index(0,0, firstDiveOrTrip)); - else - ui->ListWidget->setCurrentIndex(firstDiveOrTrip); - + ui->ListWidget->reload(); ui->ListWidget->setFocus(); } @@ -89,16 +78,7 @@ void MainWindow::on_actionOpen_triggered() ui->InfoWidget->reload(); - model->deleteLater(); - model = new DiveTripModel(this); - sortModel->setSourceModel(model); - ui->ListWidget->sortByColumn(0, Qt::DescendingOrder); - - QModelIndex firstDiveOrTrip = sortModel->index(0,0); - if (sortModel->index(0,0, firstDiveOrTrip).isValid()) - ui->ListWidget->setCurrentIndex(sortModel->index(0,0, firstDiveOrTrip)); - else - ui->ListWidget->setCurrentIndex(firstDiveOrTrip); + ui->ListWidget->reload(); ui->ListWidget->setFocus(); } @@ -120,8 +100,6 @@ void MainWindow::on_actionClose_triggered() while (dive_table.nr) delete_single_dive(0); - mark_divelist_changed(FALSE); - /* clear the selection and the statistics */ selected_dive = -1; @@ -131,6 +109,8 @@ void MainWindow::on_actionClose_triggered() ui->InfoWidget->clearStats(); ui->InfoWidget->clearInfo(); ui->InfoWidget->clearEquipment(); + ui->ProfileWidget->clear(); + ui->ListWidget->reload(); clear_events(); #if USE_GTK_UI @@ -349,7 +329,8 @@ void MainWindow::readSettings() ui->ListWidget->resizeColumnToContents(i); } ui->ListWidget->collapseAll(); - ui->ListWidget->scrollTo(sortModel->index(0,0), QAbstractItemView::PositionAtCenter); + ui->ListWidget->scrollTo(ui->ListWidget->model()->index(0,0), QAbstractItemView::PositionAtCenter); + settings.endGroup(); settings.beginGroup("Units"); GET_UNIT(v, "feet", length, units::METERS, units::FEET); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 04392ada9..60f0d4609 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -76,8 +76,6 @@ protected: private: Ui::MainWindow *ui; - DiveTripModel *model; - QSortFilterProxyModel *sortModel; QAction *actionNextDive; QAction *actionPreviousDive; diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index e5212be1e..8ab4aa845 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -206,16 +206,21 @@ void ProfileGraphicsView::showEvent(QShowEvent* event) plot(dive); } +void ProfileGraphicsView::clear() +{ + scene()->clear(); + resetTransform(); + zoomLevel = 0; + toolTip = 0; +} + void ProfileGraphicsView::plot(struct dive *d) { + if (dive == d) + return; - scene()->clear(); - if (dive != d){ - resetTransform(); - zoomLevel = 0; - dive = d; - toolTip = 0; - } + clear(); + dive = d; if(!isVisible() || !dive){ return; diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h index 7cf88cbc3..453b8cf03 100644 --- a/qt-ui/profilegraphics.h +++ b/qt-ui/profilegraphics.h @@ -64,6 +64,7 @@ public: ProfileGraphicsView(QWidget* parent = 0); void plot(struct dive *d); bool eventFilter(QObject* obj, QEvent* event); + void clear(); protected: void resizeEvent(QResizeEvent *event); |