diff options
author | Jonathan White <support@dmapps.us> | 2020-01-11 06:28:31 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2020-01-16 18:53:41 +0300 |
commit | 0d3eb047c7e1e42482b1d37e23e4701b66bd1138 (patch) | |
tree | 6234cf391e068050bac921a87cf1930e4627aafd /src/gui | |
parent | 6cde2b83e8f35d4c402783c4727672176dad414a (diff) |
Prevent crash when all entries are deleted from a group
* Fix #4093 - The first entry in the list is selected after deleting an entry
* Prevents crashes due to dangling pointers held by the Entry Preview Widget when entries were deleted.
* Improve GUI tests to ensure this new behavior occurs.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/DatabaseWidget.cpp | 9 | ||||
-rw-r--r-- | src/gui/EntryPreviewWidget.cpp | 6 | ||||
-rw-r--r-- | src/gui/EntryPreviewWidget.h | 4 |
3 files changed, 15 insertions, 4 deletions
diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index e7b6179fb..eb33c09c0 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -154,6 +154,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> db, QWidget* parent) m_shareLabel->setVisible(false); #endif + m_previewView->setObjectName("previewWidget"); m_previewView->hide(); m_previewSplitter->addWidget(m_entryView); m_previewSplitter->addWidget(m_previewView); @@ -552,6 +553,14 @@ void DatabaseWidget::deleteEntries(QList<Entry*> selectedEntries) } refreshSearch(); + + m_entryView->setFirstEntryActive(); + auto* currentEntry = currentSelectedEntry(); + if (currentEntry) { + m_previewView->setEntry(currentEntry); + } else { + m_previewView->setGroup(groupView()->currentGroup()); + } } bool DatabaseWidget::confirmDeleteEntries(QList<Entry*> entries, bool permanent) diff --git a/src/gui/EntryPreviewWidget.cpp b/src/gui/EntryPreviewWidget.cpp index e46e3a663..2e2e37dbc 100644 --- a/src/gui/EntryPreviewWidget.cpp +++ b/src/gui/EntryPreviewWidget.cpp @@ -145,10 +145,12 @@ void EntryPreviewWidget::setDatabaseMode(DatabaseWidget::Mode mode) } if (mode == DatabaseWidget::Mode::ViewMode) { - if (m_ui->stackedWidget->currentWidget() == m_ui->pageGroup) { + if (m_currentGroup && m_ui->stackedWidget->currentWidget() == m_ui->pageGroup) { setGroup(m_currentGroup); - } else { + } else if (m_currentEntry) { setEntry(m_currentEntry); + } else { + hide(); } } } diff --git a/src/gui/EntryPreviewWidget.h b/src/gui/EntryPreviewWidget.h index e8e7d2172..e1a7aff38 100644 --- a/src/gui/EntryPreviewWidget.h +++ b/src/gui/EntryPreviewWidget.h @@ -77,8 +77,8 @@ private: const QScopedPointer<Ui::EntryPreviewWidget> m_ui; bool m_locked; - Entry* m_currentEntry; - Group* m_currentGroup; + QPointer<Entry> m_currentEntry; + QPointer<Group> m_currentGroup; QTimer m_totpTimer; quint8 m_selectedTabEntry; quint8 m_selectedTabGroup; |