changeset 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 12ed0b72e9f5
children d009da9cfa10
files ui/administratorwindow.cpp ui/administratorwindow.h ui/certificatetablemodel.cpp
diffstat 3 files changed, 16 insertions(+), 8 deletions(-) [+]
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();;
+        }
     }
 }
 
--- 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;
--- 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;

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