diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index a4f014bf6..ebec29b46 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -100,7 +100,7 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent) m_entryView = new EntryView(rightHandSideWidget); m_entryView->setObjectName("entryView"); m_entryView->setContextMenuPolicy(Qt::CustomContextMenu); - m_entryView->setGroup(db->rootGroup()); + m_entryView->displayGroup(db->rootGroup()); connect(m_entryView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(emitEntryContextMenuRequested(QPoint))); // Add a notification for when we are searching @@ -291,7 +291,7 @@ bool DatabaseWidget::isUsernamesHidden() const /** * Set state of entry view 'Hide Usernames' setting */ -void DatabaseWidget::setUsernamesHidden(const bool hide) +void DatabaseWidget::setUsernamesHidden(bool hide) { m_entryView->setUsernamesHidden(hide); } @@ -307,7 +307,7 @@ bool DatabaseWidget::isPasswordsHidden() const /** * Set state of entry view 'Hide Passwords' setting */ -void DatabaseWidget::setPasswordsHidden(const bool hide) +void DatabaseWidget::setPasswordsHidden(bool hide) { m_entryView->setPasswordsHidden(hide); } @@ -1018,7 +1018,7 @@ void DatabaseWidget::search(const QString& searchtext) QList searchResult = EntrySearcher().search(searchtext, searchGroup, caseSensitive); - m_entryView->setEntryList(searchResult); + m_entryView->displaySearch(searchResult); m_lastSearchText = searchtext; // Display a label detailing our search results @@ -1054,7 +1054,7 @@ void DatabaseWidget::onGroupChanged(Group* group) // Otherwise cancel search emit clearSearch(); } else { - m_entryView->setGroup(group); + m_entryView->displayGroup(group); } } @@ -1069,7 +1069,7 @@ void DatabaseWidget::endSearch() emit listModeAboutToActivate(); // Show the normal entry view of the current group - m_entryView->setGroup(currentGroup()); + m_entryView->displayGroup(currentGroup()); emit listModeActivated(); } diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 8f268c94a..a5d881ff9 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -93,9 +93,9 @@ public: QList previewSplitterSizes() const; void setPreviewSplitterSizes(const QList& sizes); bool isUsernamesHidden() const; - void setUsernamesHidden(const bool hide); + void setUsernamesHidden(bool hide); bool isPasswordsHidden() const; - void setPasswordsHidden(const bool hide); + void setPasswordsHidden(bool hide); QByteArray entryViewState() const; bool setEntryViewState(const QByteArray& state) const; void clearAllWidgets(); diff --git a/src/gui/entry/EntryModel.cpp b/src/gui/entry/EntryModel.cpp index 2edc49b25..194c4b571 100644 --- a/src/gui/entry/EntryModel.cpp +++ b/src/gui/entry/EntryModel.cpp @@ -72,10 +72,9 @@ void EntryModel::setGroup(Group* group) makeConnections(group); endResetModel(); - emit switchedToListMode(); } -void EntryModel::setEntryList(const QList& entries) +void EntryModel::setEntries(const QList& entries) { beginResetModel(); @@ -109,7 +108,6 @@ void EntryModel::setEntryList(const QList& entries) } endResetModel(); - emit switchedToSearchMode(); } int EntryModel::rowCount(const QModelIndex& parent) const diff --git a/src/gui/entry/EntryModel.h b/src/gui/entry/EntryModel.h index 3e9f2824a..5f405bd41 100644 --- a/src/gui/entry/EntryModel.h +++ b/src/gui/entry/EntryModel.h @@ -60,22 +60,20 @@ public: QStringList mimeTypes() const override; QMimeData* mimeData(const QModelIndexList& indexes) const override; - void setEntryList(const QList& entries); - void setPaperClipPixmap(const QPixmap& paperclip); + void setGroup(Group* group); + void setEntries(const QList& entries); + bool isUsernamesHidden() const; + void setUsernamesHidden(bool hide); bool isPasswordsHidden() const; + void setPasswordsHidden(bool hide); + + void setPaperClipPixmap(const QPixmap& paperclip); signals: - void switchedToListMode(); - void switchedToSearchMode(); void usernamesHiddenChanged(); void passwordsHiddenChanged(); -public slots: - void setGroup(Group* group); - void setUsernamesHidden(bool hide); - void setPasswordsHidden(bool hide); - private slots: void entryAboutToAdd(Entry* entry); void entryAdded(Entry* entry); diff --git a/src/gui/entry/EntryView.cpp b/src/gui/entry/EntryView.cpp index ecdccd7bb..28d5ec2bb 100644 --- a/src/gui/entry/EntryView.cpp +++ b/src/gui/entry/EntryView.cpp @@ -50,11 +50,7 @@ EntryView::EntryView(QWidget* parent) setDefaultDropAction(Qt::MoveAction); connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(emitEntryActivated(QModelIndex))); - connect(selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(entrySelectionChanged())); - - connect(m_model, SIGNAL(switchedToListMode()), SLOT(switchToListMode())); - connect(m_model, SIGNAL(switchedToSearchMode()), SLOT(switchToSearchMode())); + connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(entrySelectionChanged())); connect(m_model, SIGNAL(usernamesHiddenChanged()), SIGNAL(viewStateChanged())); connect(m_model, SIGNAL(passwordsHiddenChanged()), SIGNAL(viewStateChanged())); @@ -158,16 +154,25 @@ void EntryView::focusOutEvent(QFocusEvent* event) QTreeView::focusOutEvent(event); } -void EntryView::setGroup(Group* group) +void EntryView::displayGroup(Group* group) { m_model->setGroup(group); + header()->hideSection(EntryModel::ParentGroup); setFirstEntryActive(); + m_inSearchMode = false; } -void EntryView::setEntryList(const QList& entries) +void EntryView::displaySearch(const QList& entries) { - m_model->setEntryList(entries); + m_model->setEntries(entries); + header()->showSection(EntryModel::ParentGroup); + + // Reset sort column to 'Group', overrides DatabaseWidgetStateSync + m_sortModel->sort(EntryModel::ParentGroup, Qt::AscendingOrder); + sortByColumn(EntryModel::ParentGroup, Qt::AscendingOrder); + setFirstEntryActive(); + m_inSearchMode = true; } void EntryView::setFirstEntryActive() @@ -227,39 +232,6 @@ Entry* EntryView::entryFromIndex(const QModelIndex& index) } } -/** - * Switch to list mode, i.e. list entries of group - */ -void EntryView::switchToListMode() -{ - if (!m_inSearchMode) { - return; - } - - header()->hideSection(EntryModel::ParentGroup); - m_inSearchMode = false; -} - -/** - * Switch to search mode, i.e. list search results - */ -void EntryView::switchToSearchMode() -{ - if (m_inSearchMode) { - return; - } - - header()->showSection(EntryModel::ParentGroup); - - // Always set sorting to column 'Group', as it does not feel right to - // have the last known sort configuration of search view restored by - // 'DatabaseWidgetStateSync', which is what happens without this - m_sortModel->sort(EntryModel::ParentGroup, Qt::AscendingOrder); - sortByColumn(EntryModel::ParentGroup, Qt::AscendingOrder); - - m_inSearchMode = true; -} - /** * Get current state of 'Hide Usernames' setting (NOTE: just pass-through for * m_model) @@ -272,7 +244,7 @@ bool EntryView::isUsernamesHidden() const /** * Set state of 'Hide Usernames' setting (NOTE: just pass-through for m_model) */ -void EntryView::setUsernamesHidden(const bool hide) +void EntryView::setUsernamesHidden(bool hide) { bool block = m_hideUsernamesAction->signalsBlocked(); m_hideUsernamesAction->blockSignals(true); @@ -294,7 +266,7 @@ bool EntryView::isPasswordsHidden() const /** * Set state of 'Hide Passwords' setting (NOTE: just pass-through for m_model) */ -void EntryView::setPasswordsHidden(const bool hide) +void EntryView::setPasswordsHidden(bool hide) { bool block = m_hidePasswordsAction->signalsBlocked(); m_hidePasswordsAction->blockSignals(true); diff --git a/src/gui/entry/EntryView.h b/src/gui/entry/EntryView.h index 2030f0ec7..fa002c717 100644 --- a/src/gui/entry/EntryView.h +++ b/src/gui/entry/EntryView.h @@ -39,19 +39,18 @@ public: Entry* currentEntry(); void setCurrentEntry(Entry* entry); Entry* entryFromIndex(const QModelIndex& index); - void setEntryList(const QList& entries); bool inSearchMode(); int numberOfSelectedEntries(); void setFirstEntryActive(); bool isUsernamesHidden() const; - void setUsernamesHidden(const bool hide); + void setUsernamesHidden(bool hide); bool isPasswordsHidden() const; - void setPasswordsHidden(const bool hide); + void setPasswordsHidden(bool hide); QByteArray viewState() const; bool setViewState(const QByteArray& state); -public slots: - void setGroup(Group* group); + void displayGroup(Group* group); + void displaySearch(const QList& entries); signals: void entryActivated(Entry* entry, EntryModel::ModelColumn column); @@ -65,8 +64,6 @@ protected: private slots: void emitEntryActivated(const QModelIndex& index); - void switchToListMode(); - void switchToSearchMode(); void showHeaderMenu(const QPoint& position); void toggleColumnVisibility(QAction* action); void fitColumnsToWindow(); diff --git a/tests/TestEntryModel.cpp b/tests/TestEntryModel.cpp index 49939e256..e32de2466 100644 --- a/tests/TestEntryModel.cpp +++ b/tests/TestEntryModel.cpp @@ -307,7 +307,7 @@ void TestEntryModel::testProxyModel() QList entryList; entryList << entry; - modelSource->setEntryList(entryList); + modelSource->setEntries(entryList); /** * @author Fonic @@ -346,7 +346,7 @@ void TestEntryModel::testDatabaseDelete() Entry* entry2 = new Entry(); entry2->setGroup(db2->rootGroup()); - model->setEntryList(QList() << entry1 << entry2); + model->setEntries(QList() << entry1 << entry2); QCOMPARE(model->rowCount(), 2);