mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Update edit entry widget when backing entry changes
* Fixes #4060 * Also fix not emitting entryModified() when history is truncated. This possibly fixes other crashes with apply button when the history is truncated and then the history page is shown with a deleted entry.
This commit is contained in:
parent
2073f2ddc3
commit
9d10792640
@ -663,6 +663,7 @@ void Entry::truncateHistory()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool changed = false;
|
||||||
int histMaxItems = db->metadata()->historyMaxItems();
|
int histMaxItems = db->metadata()->historyMaxItems();
|
||||||
if (histMaxItems > -1) {
|
if (histMaxItems > -1) {
|
||||||
int historyCount = 0;
|
int historyCount = 0;
|
||||||
@ -674,6 +675,7 @@ void Entry::truncateHistory()
|
|||||||
if (historyCount > histMaxItems) {
|
if (historyCount > histMaxItems) {
|
||||||
delete entry;
|
delete entry;
|
||||||
i.remove();
|
i.remove();
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -697,9 +699,14 @@ void Entry::truncateHistory()
|
|||||||
if (size > histMaxSize) {
|
if (size > histMaxSize) {
|
||||||
delete historyItem;
|
delete historyItem;
|
||||||
i.remove();
|
i.remove();
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
emit entryModified();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Entry::equals(const Entry* other, CompareItemOptions options) const
|
bool Entry::equals(const Entry* other, CompareItemOptions options) const
|
||||||
|
@ -118,6 +118,14 @@ EditEntryWidget::EditEntryWidget(QWidget* parent)
|
|||||||
setupHistory();
|
setupHistory();
|
||||||
setupEntryUpdate();
|
setupEntryUpdate();
|
||||||
|
|
||||||
|
m_entryModifiedTimer.setSingleShot(true);
|
||||||
|
m_entryModifiedTimer.setInterval(0);
|
||||||
|
connect(&m_entryModifiedTimer, &QTimer::timeout, this, [this] {
|
||||||
|
if (isVisible() && m_entry) {
|
||||||
|
setForms(m_entry);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
connect(this, SIGNAL(accepted()), SLOT(acceptEntry()));
|
connect(this, SIGNAL(accepted()), SLOT(acceptEntry()));
|
||||||
connect(this, SIGNAL(rejected()), SLOT(cancel()));
|
connect(this, SIGNAL(rejected()), SLOT(cancel()));
|
||||||
connect(this, SIGNAL(apply()), SLOT(commitEntry()));
|
connect(this, SIGNAL(apply()), SLOT(commitEntry()));
|
||||||
@ -785,6 +793,8 @@ void EditEntryWidget::loadEntry(Entry* entry,
|
|||||||
m_create = create;
|
m_create = create;
|
||||||
m_history = history;
|
m_history = history;
|
||||||
|
|
||||||
|
connect(m_entry, &Entry::entryModified, this, [this] { m_entryModifiedTimer.start(); });
|
||||||
|
|
||||||
if (history) {
|
if (history) {
|
||||||
setHeadline(QString("%1 \u2B29 %2").arg(parentName, tr("Entry history")));
|
setHeadline(QString("%1 \u2B29 %2").arg(parentName, tr("Entry history")));
|
||||||
} else {
|
} else {
|
||||||
@ -1130,6 +1140,10 @@ void EditEntryWidget::cancel()
|
|||||||
|
|
||||||
void EditEntryWidget::clear()
|
void EditEntryWidget::clear()
|
||||||
{
|
{
|
||||||
|
if (m_entry) {
|
||||||
|
m_entry->disconnect(this);
|
||||||
|
}
|
||||||
|
|
||||||
m_entry = nullptr;
|
m_entry = nullptr;
|
||||||
m_db.reset();
|
m_db.reset();
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "config-keepassx.h"
|
#include "config-keepassx.h"
|
||||||
#include "gui/EditWidget.h"
|
#include "gui/EditWidget.h"
|
||||||
@ -198,6 +199,7 @@ private:
|
|||||||
QButtonGroup* const m_autoTypeWindowSequenceGroup;
|
QButtonGroup* const m_autoTypeWindowSequenceGroup;
|
||||||
QCompleter* const m_usernameCompleter;
|
QCompleter* const m_usernameCompleter;
|
||||||
QStringListModel* const m_usernameCompleterModel;
|
QStringListModel* const m_usernameCompleterModel;
|
||||||
|
QTimer m_entryModifiedTimer;
|
||||||
|
|
||||||
Q_DISABLE_COPY(EditEntryWidget)
|
Q_DISABLE_COPY(EditEntryWidget)
|
||||||
};
|
};
|
||||||
|
@ -499,9 +499,9 @@ void TestGui::testEditEntry()
|
|||||||
// Confirm edit was made
|
// Confirm edit was made
|
||||||
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
||||||
QCOMPARE(entry->title(), QString("Sample Entry_test"));
|
QCOMPARE(entry->title(), QString("Sample Entry_test"));
|
||||||
QCOMPARE(entry->foregroundColor(), fgColor);
|
QCOMPARE(entry->foregroundColor().toUpper(), fgColor.toUpper());
|
||||||
QCOMPARE(entryItem.data(Qt::ForegroundRole), QVariant(fgColor));
|
QCOMPARE(entryItem.data(Qt::ForegroundRole), QVariant(fgColor));
|
||||||
QCOMPARE(entry->backgroundColor(), bgColor);
|
QCOMPARE(entry->backgroundColor().toUpper(), bgColor.toUpper());
|
||||||
QCOMPARE(entryItem.data(Qt::BackgroundRole), QVariant(bgColor));
|
QCOMPARE(entryItem.data(Qt::BackgroundRole), QVariant(bgColor));
|
||||||
QCOMPARE(entry->historyItems().size(), ++editCount);
|
QCOMPARE(entry->historyItems().size(), ++editCount);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user