[PATCH 1 of 3] (issue166) Fix certificiate removal
Wald Commits
scm-commit at wald.intevation.org
Mon Oct 13 17:41:59 CEST 2014
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1413213815 -7200
# Node ID ff9cd05e861ea0e38931fe13e077477b15ce547a
# Parent 12ed0b72e9f5f1fd8734f831d5f07ca8459bd2c9
(issue166) Fix certificiate removal
The index that should be removed came from the filter proxy model
and did not map to the real index. This was broken.
diff -r 12ed0b72e9f5 -r ff9cd05e861e ui/administratorwindow.cpp
--- a/ui/administratorwindow.cpp Mon Oct 13 16:19:28 2014 +0200
+++ b/ui/administratorwindow.cpp Mon Oct 13 17:23:35 2014 +0200
@@ -86,10 +86,10 @@
tr("All managed root certificates of the certificate list: "));
certificateView = new QTableView;
certificateModel = new CertificateTabelModel();
- QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(this);
- filterModel->setSourceModel(certificateModel);
+ mFilterModel = new QSortFilterProxyModel(this);
+ mFilterModel->setSourceModel(certificateModel);
CertificateTableDelegate *delegate = new CertificateTableDelegate(certificateView);
- certificateView->setModel(filterModel);
+ certificateView->setModel(mFilterModel);
certificateView->setItemDelegate(delegate);
certificateView->horizontalHeader()->setStretchLastSection(true);
certificateView->resizeColumnsToContents();
@@ -189,8 +189,14 @@
void AdministratorWindow::removeCertificates()
{
QModelIndexList list = certificateView->selectionModel()->selectedRows();
- for (int i = list.size() -1 ; i >= 0; i--) {
- certificateModel->removeRow(list.at(i).row(), list.at(i));
+ foreach (QModelIndex idx, list) {
+ QModelIndex realidx = mFilterModel->mapToSource(idx);
+ qDebug() << "About to remove row: " << realidx.row();
+ if (certificateModel->data(idx, Qt::UserRole).toBool()) {
+ certificateModel->removeRow(realidx.row(), realidx.parent());
+ } else {
+ qDebug() << "Tried to remove old certificate at idx: " << realidx.row();;
+ }
}
}
diff -r 12ed0b72e9f5 -r ff9cd05e861e ui/administratorwindow.h
--- a/ui/administratorwindow.h Mon Oct 13 16:19:28 2014 +0200
+++ b/ui/administratorwindow.h Mon Oct 13 17:23:35 2014 +0200
@@ -24,6 +24,7 @@
class QMenu;
class QAction;
+class QSortFilterProxyModel;
/** @brief Main Window of the Administrator application
*
@@ -116,6 +117,7 @@
QTableView *certificateView;
CertificateList mCertList;
CertificateTabelModel *certificateModel;
+ QSortFilterProxyModel *mFilterModel;
QPushButton *saveButton;
QPushButton *loadButton;
QPushButton *addButton;
diff -r 12ed0b72e9f5 -r ff9cd05e861e ui/certificatetablemodel.cpp
--- a/ui/certificatetablemodel.cpp Mon Oct 13 16:19:28 2014 +0200
+++ b/ui/certificatetablemodel.cpp Mon Oct 13 17:23:35 2014 +0200
@@ -34,11 +34,11 @@
const QModelIndex &index)
{
beginRemoveRows(QModelIndex(), row, row + count - 1);
- if ((row + count - 1) > mCertificates.size()) {
+ if (count < 0 || row < 0 || (row + count) > mCertificates.size()) {
return false;
}
- for (int i = row + count - 1; i >= row; i--) {
- mCertificates.removeAt(i);
+ for (int i = 0; i < count; ++i) {
+ mCertificates.removeAt(row);
}
endRemoveRows();
return true;
More information about the Trustbridge-commits
mailing list