mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-07 14:02:37 -04:00
Fix assert hit when viewing entry history
* Fixes #11371 * Adds test for showing entry history * Improved page switching capabilities for entry edit widget
This commit is contained in:
parent
5d24495704
commit
2738a72b43
6 changed files with 110 additions and 23 deletions
|
@ -183,6 +183,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> db, QWidget* parent)
|
|||
m_previewSplitter->setSizes({1, 1});
|
||||
|
||||
m_editEntryWidget->setObjectName("editEntryWidget");
|
||||
m_historyEditEntryWidget->setObjectName("editEntryHistoryWidget");
|
||||
m_editGroupWidget->setObjectName("editGroupWidget");
|
||||
m_reportsDialog->setObjectName("reportsDialog");
|
||||
m_databaseSettingDialog->setObjectName("databaseSettingsDialog");
|
||||
|
@ -277,7 +278,7 @@ DatabaseWidget::Mode DatabaseWidget::currentMode() const
|
|||
mode = Mode::ReportsMode;
|
||||
} else if (widget == m_databaseSettingDialog) {
|
||||
mode = Mode::DatabaseSettingsMode;
|
||||
} else if (widget == m_editEntryWidget) {
|
||||
} else if (widget == m_editEntryWidget || widget == m_historyEditEntryWidget) {
|
||||
mode = Mode::EditEntryMode;
|
||||
} else if (widget == m_editGroupWidget) {
|
||||
mode = Mode::EditGroupMode;
|
||||
|
|
|
@ -71,16 +71,25 @@ void EditWidget::addPage(const QString& labelText, const QIcon& icon, QWidget* w
|
|||
m_ui->categoryList->addCategory(labelText, icon);
|
||||
}
|
||||
|
||||
bool EditWidget::hasPage(QWidget* widget)
|
||||
bool EditWidget::hasPage(const QWidget* widget) const
|
||||
{
|
||||
return pageIndex(widget) >= 0;
|
||||
}
|
||||
|
||||
int EditWidget::pageIndex(const QWidget* widget) const
|
||||
{
|
||||
if (!widget) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_ui->stackedWidget->count(); i++) {
|
||||
auto* scrollArea = qobject_cast<QScrollArea*>(m_ui->stackedWidget->widget(i));
|
||||
if (scrollArea && scrollArea->widget() == widget) {
|
||||
return true;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void EditWidget::setPageHidden(QWidget* widget, bool hidden)
|
||||
|
|
|
@ -42,7 +42,8 @@ public:
|
|||
~EditWidget() override;
|
||||
|
||||
void addPage(const QString& labelText, const QIcon& icon, QWidget* widget);
|
||||
bool hasPage(QWidget* widget);
|
||||
bool hasPage(const QWidget* widget) const;
|
||||
int pageIndex(const QWidget* widget) const;
|
||||
void setPageHidden(QWidget* widget, bool hidden);
|
||||
void setCurrentPage(int index);
|
||||
void setHeadline(const QString& text);
|
||||
|
|
|
@ -139,6 +139,47 @@ EditEntryWidget::EditEntryWidget(QWidget* parent)
|
|||
|
||||
EditEntryWidget::~EditEntryWidget() = default;
|
||||
|
||||
bool EditEntryWidget::switchToPage(Page page)
|
||||
{
|
||||
auto index = pageIndex(widgetForPage(page));
|
||||
if (index >= 0) {
|
||||
setCurrentPage(index);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QWidget* EditEntryWidget::widgetForPage(Page page) const
|
||||
{
|
||||
switch (page) {
|
||||
case Page::Main:
|
||||
return m_mainWidget;
|
||||
case Page::Advanced:
|
||||
return m_advancedWidget;
|
||||
case Page::Icon:
|
||||
return m_iconsWidget;
|
||||
case Page::AutoType:
|
||||
return m_autoTypeWidget;
|
||||
case Page::Browser:
|
||||
#ifdef WITH_XC_BROWSER
|
||||
return m_browserWidget;
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
case Page::SSHAgent:
|
||||
#ifdef WITH_XC_SSHAGENT
|
||||
return m_sshAgentWidget;
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
case Page::Properties:
|
||||
return m_editWidgetProperties;
|
||||
case Page::History:
|
||||
return m_historyWidget;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void EditEntryWidget::setupMain()
|
||||
{
|
||||
m_mainUi->setupUi(m_mainWidget);
|
||||
|
@ -886,7 +927,7 @@ void EditEntryWidget::loadEntry(Entry* entry,
|
|||
setForms(entry);
|
||||
setReadOnly(m_history);
|
||||
|
||||
setCurrentPage(0);
|
||||
switchToPage(Page::Main);
|
||||
setPageHidden(m_historyWidget, m_history || m_entry->historyItems().count() < 1);
|
||||
#ifdef WITH_XC_SSHAGENT
|
||||
setPageHidden(m_sshAgentWidget, !sshAgent()->isEnabled());
|
||||
|
@ -1131,7 +1172,7 @@ bool EditEntryWidget::commitEntry()
|
|||
MessageBox::Yes | MessageBox::No,
|
||||
MessageBox::Yes);
|
||||
if (res == MessageBox::Yes) {
|
||||
setCurrentPage(3);
|
||||
switchToPage(Page::AutoType);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1146,7 +1187,7 @@ bool EditEntryWidget::commitEntry()
|
|||
MessageBox::Yes | MessageBox::No,
|
||||
MessageBox::Yes);
|
||||
if (res == MessageBox::Yes) {
|
||||
setCurrentPage(3);
|
||||
switchToPage(Page::AutoType);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,19 @@ public:
|
|||
Entry* currentEntry() const;
|
||||
void clear();
|
||||
|
||||
enum class Page
|
||||
{
|
||||
Main,
|
||||
Advanced,
|
||||
Icon,
|
||||
AutoType,
|
||||
Browser,
|
||||
SSHAgent,
|
||||
Properties,
|
||||
History
|
||||
};
|
||||
bool switchToPage(Page page);
|
||||
|
||||
signals:
|
||||
void editFinished(bool accepted);
|
||||
void historyEntryActivated(Entry* entry);
|
||||
|
@ -162,6 +175,8 @@ private:
|
|||
|
||||
void displayAttribute(QModelIndex index, bool showProtected);
|
||||
|
||||
QWidget* widgetForPage(Page page) const;
|
||||
|
||||
QPointer<Entry> m_entry;
|
||||
QSharedPointer<Database> m_db;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue