diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-14 08:18:26 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-14 08:18:26 -0300 |
commit | b0374047dd6a31d8b16c6991ee0ffc51c198569e (patch) | |
tree | cf950820fc57fdeaac6ae81f43b80b62a73e4054 | |
parent | 5868b37e6bde1eaa6da09aac5e269557d94d7641 (diff) | |
download | subsurface-b0374047dd6a31d8b16c6991ee0ffc51c198569e.tar.gz |
code to show profile again
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
-rw-r--r-- | divelist.c | 10 | ||||
-rw-r--r-- | qt-ui/divelistview.cpp | 18 | ||||
-rw-r--r-- | qt-ui/divelistview.h | 8 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 9 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 2 |
5 files changed, 39 insertions, 8 deletions
diff --git a/divelist.c b/divelist.c index deab1b05c..1398c78e8 100644 --- a/divelist.c +++ b/divelist.c @@ -144,7 +144,7 @@ int trip_has_selected_dives(dive_trip_t *trip) return 0; } -/* Get the values as we want to show them. Whole feet. But meters with one decimal for +/* Get the values as we want to show them. Whole feet. But meters with one decimal for * values less than 20m, without decimals for larger values */ void get_depth_values(int depth, int *depth_int, int *depth_decimal, int *show_decimal) { @@ -924,9 +924,11 @@ void merge_dive_index(int i, struct dive *a) void select_dive(int idx) { struct dive *dive = get_dive(idx); - if (dive && !dive->selected) { - dive->selected = 1; - amount_selected++; + if (dive) { + if (!dive->selected){ + dive->selected = 1; + amount_selected++; + } selected_dive = idx; } } diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index d192d84aa..d2354d910 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -55,6 +55,24 @@ void DiveListView::keyReleaseEvent(QKeyEvent* event) QWidget::keyReleaseEvent(event); } +void DiveListView::currentChanged(const QModelIndex& current, const QModelIndex& previous) +{ + if (!current.isValid()) + return; + const QAbstractItemModel *model = current.model(); + int selectedDive = 0; + struct dive *dive = (struct dive*) model->data(current, TreeItemDT::DIVE_ROLE).value<void*>(); + if (!dive) { // it's a trip! select first child. + dive = (struct dive*) model->data(current.child(0,0), TreeItemDT::DIVE_ROLE).value<void*>(); + selectedDive = get_divenr(dive); + }else{ + selectedDive = get_divenr(dive); + } + if (selectedDive == selected_dive) + return; + Q_EMIT currentDiveChanged(selectedDive); +} + void DiveListView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) { QList<QModelIndex> parents; diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h index 9df8b5fa1..ce6238d25 100644 --- a/qt-ui/divelistview.h +++ b/qt-ui/divelistview.h @@ -18,19 +18,19 @@ class DiveListView : public QTreeView { + Q_OBJECT public: DiveListView(QWidget *parent = 0); - void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); + void currentChanged(const QModelIndex& current, const QModelIndex& previous); void setModel(QAbstractItemModel* model); - void mousePressEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* event); void keyPressEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent*); - void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command); - +Q_SIGNALS: + void currentDiveChanged(int divenr); private: bool mouseClickSelection; }; diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 58cb86286..60a4623c7 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -42,6 +42,15 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), ui->ListWidget->setCurrentIndex(sortModel->index(0,0, firstDiveOrTrip)); else ui->ListWidget->setCurrentIndex(firstDiveOrTrip); + + connect(ui->ListWidget, SIGNAL(currentDiveChanged(int)), this, SLOT(current_dive_changed(int))); +} + +void MainWindow::current_dive_changed(int divenr) +{ + select_dive(divenr); + redrawProfile(); + ui->InfoWidget->updateDiveInfo(divenr); } void MainWindow::redrawProfile() diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 084818319..04392ada9 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -69,6 +69,8 @@ private Q_SLOTS: void on_actionAboutSubsurface_triggered(); void on_actionUserManual_triggered(); + void current_dive_changed(int divenr); + protected: void closeEvent(QCloseEvent *); |