Fix crash when editing an entry in search results.

This commit is contained in:
Florian Geyer 2012-05-16 01:26:30 +02:00
parent a5eb93255b
commit fb5a5041d5
2 changed files with 23 additions and 2 deletions

View File

@ -92,6 +92,7 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
addWidget(m_databaseSettingsWidget); addWidget(m_databaseSettingsWidget);
connect(m_groupView, SIGNAL(groupChanged(Group*)), m_entryView, SLOT(setGroup(Group*))); connect(m_groupView, SIGNAL(groupChanged(Group*)), m_entryView, SLOT(setGroup(Group*)));
connect(m_groupView, SIGNAL(groupChanged(Group*)), this, SLOT(clearLastGroup(Group*)));
connect(m_entryView, SIGNAL(entryActivated(Entry*)), SLOT(switchToEntryEdit(Entry*))); connect(m_entryView, SIGNAL(entryActivated(Entry*)), SLOT(switchToEntryEdit(Entry*)));
connect(m_editEntryWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool))); connect(m_editEntryWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool)));
connect(m_editGroupWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool))); connect(m_editGroupWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool)));
@ -256,8 +257,14 @@ void DatabaseWidget::switchToEntryEdit(Entry* entry)
void DatabaseWidget::switchToEntryEdit(Entry* entry, bool create) void DatabaseWidget::switchToEntryEdit(Entry* entry, bool create)
{ {
m_editEntryWidget->loadEntry(entry, create, m_groupView->currentGroup()->name(), Group* group = m_groupView->currentGroup();
m_db); if (!group) {
Q_ASSERT(m_entryView->inSearch());
group = m_lastGroup;
}
Q_ASSERT(group);
m_editEntryWidget->loadEntry(entry, create, group->name(), m_db);
setCurrentIndex(1); setCurrentIndex(1);
} }
@ -332,6 +339,11 @@ void DatabaseWidget::search()
Group* searchGroup = m_db->rootGroup(); Group* searchGroup = m_db->rootGroup();
QList<Entry*> searchResult = searchGroup->search(m_searchEdit->text(), Qt::CaseInsensitive); QList<Entry*> searchResult = searchGroup->search(m_searchEdit->text(), Qt::CaseInsensitive);
Group* group = m_groupView->currentGroup();
if (group) {
m_lastGroup = m_groupView->currentGroup();
}
m_groupView->setCurrentIndex(QModelIndex()); m_groupView->setCurrentIndex(QModelIndex());
m_entryView->search(searchResult); m_entryView->search(searchResult);
} }
@ -355,3 +367,10 @@ void DatabaseWidget::truncateHistories()
entry->truncateHistory(); entry->truncateHistory();
} }
} }
void DatabaseWidget::clearLastGroup(Group* group)
{
if (group) {
m_lastGroup = 0;
}
}

View File

@ -77,6 +77,7 @@ private Q_SLOTS:
void updateMasterKey(bool accepted); void updateMasterKey(bool accepted);
void updateSettings(bool accepted); void updateSettings(bool accepted);
void emitCurrentModeChanged(); void emitCurrentModeChanged();
void clearLastGroup(Group* group);
private: private:
void truncateHistories(); void truncateHistories();
@ -93,6 +94,7 @@ private:
Entry* m_newEntry; Entry* m_newEntry;
Group* m_newParent; Group* m_newParent;
QLineEdit* m_searchEdit; QLineEdit* m_searchEdit;
Group* m_lastGroup;
}; };
#endif // KEEPASSX_DATABASEWIDGET_H #endif // KEEPASSX_DATABASEWIDGET_H