summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <aheinecke@intevation.de>2016-08-11 12:43:12 (GMT)
committerAndre Heinecke <aheinecke@intevation.de>2016-08-11 12:43:12 (GMT)
commit2c20f98c198364862e1340e3fa5076c1f8edd3c2 (patch)
tree03eb34211c9eeae4bc07eb66e190700ff741a72f
parent63dd0498e69580931ba5d601c0d21ea08301d615 (diff)
Fix certificatelineedit removal in sigencwidget
With the switch to a gridlayout removing takes a bit more effort as we manually have to update the positions of the items below the removed line. This also fixes a problem that removed items were not deleted.
-rw-r--r--src/crypto/gui/certificatelineedit.cpp5
-rw-r--r--src/crypto/gui/signencryptwidget.cpp24
-rw-r--r--src/crypto/gui/signencryptwidget.h1
3 files changed, 25 insertions, 5 deletions
diff --git a/src/crypto/gui/certificatelineedit.cpp b/src/crypto/gui/certificatelineedit.cpp
index 0a82760..83f9eb2 100644
--- a/src/crypto/gui/certificatelineedit.cpp
+++ b/src/crypto/gui/certificatelineedit.cpp
@@ -125,7 +125,6 @@ void CertificateLineEdit::updateKey()
const auto mailText = text();
auto newKey = Key();
if (mailText.isEmpty()) {
- Q_EMIT wantsRemoval(this);
mLineAction->setIcon(QIcon::fromTheme(QStringLiteral("question")));
mLineAction->setToolTip(i18n("Please select a certificate."));
} else {
@@ -155,6 +154,10 @@ void CertificateLineEdit::updateKey()
}
Q_EMIT keyChanged();
+
+ if (mailText.isEmpty()) {
+ Q_EMIT wantsRemoval(this);
+ }
}
Key CertificateLineEdit::key() const
diff --git a/src/crypto/gui/signencryptwidget.cpp b/src/crypto/gui/signencryptwidget.cpp
index f667a05..2a657f6 100644
--- a/src/crypto/gui/signencryptwidget.cpp
+++ b/src/crypto/gui/signencryptwidget.cpp
@@ -92,7 +92,8 @@ public:
SignEncryptWidget::SignEncryptWidget(QWidget *parent)
: QWidget(parent),
- mModel(AbstractKeyListModel::createFlatKeyListModel(this))
+ mModel(AbstractKeyListModel::createFlatKeyListModel(this)),
+ mRecpRowCount(2)
{
QVBoxLayout *lay = new QVBoxLayout;
lay->setMargin(0);
@@ -199,12 +200,12 @@ void SignEncryptWidget::addRecipient(const Key &key)
new EncryptCertificateFilter());
mRecpWidgets << certSel;
- if (!mRecpLayout->itemAtPosition(mRecpLayout->rowCount() - 1, 1)) {
+ if (!mRecpLayout->itemAtPosition(mRecpRowCount - 1, 1)) {
// First widget. Should align with the row above that
// contians the encrypt for others checkbox.
- mRecpLayout->addWidget(certSel, mRecpLayout->rowCount() - 1, 1);
+ mRecpLayout->addWidget(certSel, mRecpRowCount - 1, 1);
} else {
- mRecpLayout->addWidget(certSel, mRecpLayout->rowCount(), 1);
+ mRecpLayout->addWidget(certSel, mRecpRowCount++, 1);
}
connect(certSel, &CertificateLineEdit::keyChanged,
@@ -310,8 +311,23 @@ void SignEncryptWidget::recpRemovalRequested(CertificateLineEdit *w)
emptyEdits++;
}
if (emptyEdits > 1) {
+ int row, col, rspan, cspan;
+ mRecpLayout->getItemPosition(mRecpLayout->indexOf(w), &row, &col, &rspan, &cspan);
mRecpLayout->removeWidget(w);
mRecpWidgets.removeAll(w);
+ // The row count of the grid layout does not reflect the actual
+ // items so we keep our internal count.
+ mRecpRowCount--;
+ for (int i = row + 1; i <= mRecpRowCount; i++) {
+ // move widgets one up
+ auto item = mRecpLayout->itemAtPosition(i, 1);
+ if (!item) {
+ break;
+ }
+ mRecpLayout->removeItem(item);
+ mRecpLayout->addItem(item, i - 1, 1);
+ }
+ w->deleteLater();
return;
}
}
diff --git a/src/crypto/gui/signencryptwidget.h b/src/crypto/gui/signencryptwidget.h
index 7f2e5c5..d60c397 100644
--- a/src/crypto/gui/signencryptwidget.h
+++ b/src/crypto/gui/signencryptwidget.h
@@ -100,6 +100,7 @@ private:
QString mOp;
AbstractKeyListModel *mModel;
QCheckBox *mSymmetric;
+ int mRecpRowCount;
};
} // namespace Kleo
#endif // CRYPTO_GUI_SIGNENCRYPTWIDGET_H