From 28bfd39bcaac1b6a62d427940f2f18de40efded5 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Fri, 25 May 2012 13:25:46 +0200 Subject: [PATCH] Allow selecting multiple rows in entry view. --- src/gui/MainWindow.cpp | 4 ++-- src/gui/entry/EntryView.cpp | 10 ++++++++-- src/gui/entry/EntryView.h | 8 ++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index add612b82..0e65da6ac 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -121,14 +121,14 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) m_ui->actionEntryNew->setEnabled(true); } if (dbWidget->entryView()->inSearch() || - !dbWidget->entryView()->currentIndex().isValid()) { + !dbWidget->entryView()->isSingleEntrySelected()) { m_ui->actionEntryClone->setEnabled(false); } else { m_ui->actionEntryClone->setEnabled(true); } - if (dbWidget->entryView()->currentIndex().isValid()) { + if (dbWidget->entryView()->isSingleEntrySelected()) { m_ui->actionEntryEdit->setEnabled(true); m_ui->actionEntryDelete->setEnabled(true); } diff --git a/src/gui/entry/EntryView.cpp b/src/gui/entry/EntryView.cpp index 7c83e97a7..e2fb97bfe 100644 --- a/src/gui/entry/EntryView.cpp +++ b/src/gui/entry/EntryView.cpp @@ -39,6 +39,7 @@ EntryView::EntryView(QWidget* parent) setAlternatingRowColors(true); setDragEnabled(true); setSortingEnabled(true); + setSelectionMode(QAbstractItemView::ExtendedSelection); connect(this, SIGNAL(activated(QModelIndex)), SLOT(emitEntryActivated(QModelIndex))); connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(entrySelectionChanged())); @@ -78,8 +79,13 @@ void EntryView::setModel(QAbstractItemModel* model) Entry* EntryView::currentEntry() { - // TODO: use selection instead of current? - return m_model->entryFromIndex(m_sortModel->mapToSource(currentIndex())); + QModelIndexList list = selectionModel()->selectedRows(); + if (list.size() == 1) { + return m_model->entryFromIndex(m_sortModel->mapToSource(list.first())); + } + else { + return 0; + } } bool EntryView::isSingleEntrySelected() diff --git a/src/gui/entry/EntryView.h b/src/gui/entry/EntryView.h index d1ac97cfa..02b66cb1a 100644 --- a/src/gui/entry/EntryView.h +++ b/src/gui/entry/EntryView.h @@ -42,15 +42,15 @@ public: public Q_SLOTS: void setGroup(Group* group); +Q_SIGNALS: + void entryActivated(Entry* entry); + void entrySelectionChanged(); + private Q_SLOTS: void emitEntryActivated(const QModelIndex& index); void switchToSearch(); void switchToView(); -Q_SIGNALS: - void entryActivated(Entry* entry); - void entrySelectionChanged(); - private: EntryModel* const m_model; QSortFilterProxyModel* const m_sortModel;