summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-03 21:49:40 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-03 21:49:40 -0300
commit7add8594a71db739d86966ea2bc1e15aa7a6674f (patch)
treeae805f95ed24703c57a48fa544118c31e0f63401
parentc385e7aae8c7ac0d381a94440e32ecb3b115e9fc (diff)
downloadsubsurface-7add8594a71db739d86966ea2bc1e15aa7a6674f.tar.gz
Added code to select / desselect a range of items
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
-rw-r--r--qt-ui/mainwindow.cpp37
-rw-r--r--qt-ui/mainwindow.h4
2 files changed, 30 insertions, 11 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index d8e786b86..3b0981d21 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -34,19 +34,12 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()),
ui->setupUi(this);
sortModel->setSourceModel(model);
ui->ListWidget->setModel(sortModel);
- connect(ui->ListWidget, SIGNAL(activated(QModelIndex)), this, SLOT(diveSelected(QModelIndex)));
setWindowIcon(QIcon(":subsurface-icon"));
- readSettings();
-}
-
-void MainWindow::diveSelected(const QModelIndex& index)
-{
- struct dive *dive = (struct dive*) index.model()->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
- if (dive)
- selected_dive = get_index_for_dive(dive);
+ connect(ui->ListWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
+ this, SLOT(dive_selection_changed(QItemSelection,QItemSelection)));
- // Here should be the code to update the other widgets.
+ readSettings();
}
void MainWindow::on_actionNew_triggered()
@@ -85,6 +78,30 @@ void MainWindow::on_actionOpen_triggered()
ui->ListWidget->sortByColumn(0, Qt::DescendingOrder);
}
+void MainWindow::dive_selection_changed(const QItemSelection& newSelection, const QItemSelection& oldSelection)
+{
+ // struct dive *dive = (struct dive*) index.model()->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
+ //if (dive)
+ // selected_dive = get_index_for_dive(dive);
+ Q_FOREACH(const QModelIndex& desselect, oldSelection.indexes()){
+ struct dive *d = (struct dive*) desselect.data(TreeItemDT::DIVE_ROLE).value<void*>();
+ if (!d)
+ continue;
+ d->selected = false;
+ }
+
+ struct dive *lastSelected = 0;
+ Q_FOREACH(const QModelIndex& select, oldSelection.indexes()){
+ struct dive *d = (struct dive*) select.data(TreeItemDT::DIVE_ROLE).value<void*>();
+ if (!d)
+ continue;
+ d->selected = true;
+ lastSelected = d;
+ }
+
+ select_dive( get_divenr(lastSelected) );
+}
+
void MainWindow::on_actionSave_triggered()
{
qDebug("actionSave");
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index e94cb5b7c..3b35d44e5 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -22,6 +22,7 @@ class DiveInfo;
class DiveNotes;
class Stats;
class Equipment;
+class QItemSelection;
class MainWindow : public QMainWindow
{
@@ -67,7 +68,8 @@ private Q_SLOTS:
void on_actionAboutSubsurface_triggered();
void on_actionUserManual_triggered();
- void diveSelected(const QModelIndex& index);
+ void dive_selection_changed(const QItemSelection& newSelection,
+ const QItemSelection& oldSelection);
protected:
void closeEvent(QCloseEvent *);