Added code to select / desselect a range of items

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-05-03 21:49:40 -03:00
parent c385e7aae8
commit 7add8594a7
2 changed files with 31 additions and 12 deletions

View file

@ -34,21 +34,14 @@ 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"));
connect(ui->ListWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(dive_selection_changed(QItemSelection,QItemSelection)));
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);
// Here should be the code to update the other widgets.
}
void MainWindow::on_actionNew_triggered()
{
qDebug("actionNew");
@ -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");

View file

@ -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 *);