Correct issues with apply button

* Don't show apply button when creating new entries or groups (Fix #2191)
* Don't mark entry/group as dirty when first creating a new one (prevents unnecessary discard dialog on cancel)
* Properly enable/disable apply button when changes are made to entries and groups
* Don't show discard change warning when locking database unless their are actual changes made

NOTE: Extra pages in the group edit widget are not watched for changes yet. Requires a major refactor.
This commit is contained in:
Jonathan White 2019-04-07 09:56:25 -04:00
parent 71e375aff0
commit 4b1258f585
8 changed files with 155 additions and 89 deletions

View file

@ -30,6 +30,7 @@ EditWidget::EditWidget(QWidget* parent)
{
m_ui->setupUi(this);
setReadOnly(false);
setModified(false);
m_ui->messageWidget->setHidden(true);
@ -43,6 +44,7 @@ EditWidget::EditWidget(QWidget* parent)
connect(m_ui->buttonBox, SIGNAL(accepted()), SIGNAL(accepted()));
connect(m_ui->buttonBox, SIGNAL(rejected()), SIGNAL(rejected()));
connect(m_ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(buttonClicked(QAbstractButton*)));
}
EditWidget::~EditWidget()
@ -106,9 +108,6 @@ void EditWidget::setReadOnly(bool readOnly)
m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Close);
} else {
m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply);
// Find and connect the apply button
QPushButton* applyButton = m_ui->buttonBox->button(QDialogButtonBox::Apply);
connect(applyButton, SIGNAL(clicked()), SIGNAL(apply()));
}
}
@ -117,6 +116,17 @@ bool EditWidget::readOnly() const
return m_readOnly;
}
void EditWidget::setModified(bool state)
{
m_modified = state;
enableApplyButton(state);
}
bool EditWidget::isModified() const
{
return m_modified;
}
void EditWidget::enableApplyButton(bool enabled)
{
QPushButton* applyButton = m_ui->buttonBox->button(QDialogButtonBox::Apply);
@ -125,6 +135,27 @@ void EditWidget::enableApplyButton(bool enabled)
}
}
void EditWidget::showApplyButton(bool state)
{
if (!m_readOnly) {
auto buttons = m_ui->buttonBox->standardButtons();
if (state) {
buttons |= QDialogButtonBox::Apply;
} else {
buttons &= ~QDialogButtonBox::Apply;
}
m_ui->buttonBox->setStandardButtons(buttons);
}
}
void EditWidget::buttonClicked(QAbstractButton* button)
{
auto stdButton = m_ui->buttonBox->standardButton(button);
if (stdButton == QDialogButtonBox::Apply) {
emit apply();
}
}
void EditWidget::showMessage(const QString& text, MessageWidget::MessageType type)
{
// Show error messages for a longer time to make sure the user can read them