diff ui/administratorwindow.cpp @ 1316:ff9cd05e861e

(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.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 13 Oct 2014 17:23:35 +0200
parents 38d3dce323b4
children d009da9cfa10
line wrap: on
line diff
--- 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();;
+        }
     }
 }
 

http://wald.intevation.org/projects/trustbridge/