From 138ca8d3a3ff1450811c4d6947fe9f5c6eb65d67 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sun, 5 Aug 2012 18:51:19 +0200 Subject: [PATCH] Select the first entry when the model has been reset. This avoids overriding setEntryList(). --- src/autotype/AutoTypeSelectView.cpp | 16 ++++++++++------ src/autotype/AutoTypeSelectView.h | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/autotype/AutoTypeSelectView.cpp b/src/autotype/AutoTypeSelectView.cpp index 95c5c406..9bdf9d92 100644 --- a/src/autotype/AutoTypeSelectView.cpp +++ b/src/autotype/AutoTypeSelectView.cpp @@ -26,13 +26,8 @@ AutoTypeSelectView::AutoTypeSelectView(QWidget* parent) setMouseTracking(true); setAllColumnsShowFocus(true); setDragEnabled(false); -} -void AutoTypeSelectView::setEntryList(const QList& entries) -{ - EntryView::setEntryList(entries); - - setCurrentIndex(model()->index(0, 0)); + connect(model(), SIGNAL(modelReset()), SLOT(selectFirstEntry())); } void AutoTypeSelectView::mouseMoveEvent(QMouseEvent* event) @@ -49,3 +44,12 @@ void AutoTypeSelectView::mouseMoveEvent(QMouseEvent* event) EntryView::mouseMoveEvent(event); } + +void AutoTypeSelectView::selectFirstEntry() +{ + QModelIndex index = model()->index(0, 0); + + if (index.isValid()) { + setCurrentIndex(index); + } +} diff --git a/src/autotype/AutoTypeSelectView.h b/src/autotype/AutoTypeSelectView.h index ee3aa574..bcbb2627 100644 --- a/src/autotype/AutoTypeSelectView.h +++ b/src/autotype/AutoTypeSelectView.h @@ -29,10 +29,12 @@ class AutoTypeSelectView : public EntryView public: explicit AutoTypeSelectView(QWidget* parent = Q_NULLPTR); - void setEntryList(const QList& entries) Q_DECL_OVERRIDE; protected: void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE; + +private Q_SLOTS: + void selectFirstEntry(); }; #endif // KEEPASSX_AUTOTYPESELECTVIEW_H