changeset 377:e3f825a7257e

merged.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 15 Apr 2014 12:34:04 +0200
parents 9731d28b95af (diff) 9e38a4bcd44e (current diff)
children 31079bd54036
files
diffstat 4 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ui/administratorwindow.cpp	Tue Apr 15 12:06:03 2014 +0200
+++ b/ui/administratorwindow.cpp	Tue Apr 15 12:34:04 2014 +0200
@@ -73,6 +73,8 @@
     certificateView->setColumnWidth(3, 130);
     certificateView->setColumnWidth(4, 200);
     certificateView->setSelectionBehavior(QAbstractItemView::SelectRows);
+    connect(certificateView, SIGNAL(clicked(const QModelIndex&)), this,
+        SLOT(clickedCertificate(const QModelIndex&)));
     certificateView->verticalHeader()->setVisible(false);
     certLayout->addWidget(certificateView);
     certBox->setLayout(certLayout);
@@ -100,6 +102,8 @@
     addButton = new QPushButton(tr("Add"));
     connect(addButton, SIGNAL(clicked()), this, SLOT(addCertificates()));
     removeButton = new QPushButton(tr("Remove"));
+    removeButton->setEnabled(false);
+    connect(removeButton, SIGNAL(clicked()), this, SLOT(removeCertificates()));
     bottomLayout->addWidget(saveButton);
     bottomLayout->addWidget(loadButton);
     bottomLayout->addWidget(addButton);
@@ -147,6 +151,14 @@
     addToCertificateTable(certs);
 }
 
+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));
+    }
+}
+
 void AdministratorWindow::loadCertificateTable() {
     foreach(const Certificate &cert, certList.getCertificates()) {
         certificateModel->addCertificate(cert, true);
@@ -182,3 +194,12 @@
     dialog->show();
 }
 
+void AdministratorWindow::clickedCertificate(const QModelIndex &index)
+{
+    if (index.data(Qt::UserRole).toBool()) {
+        removeButton->setEnabled(false);
+    }
+    else {
+        removeButton->setEnabled(true);
+    }
+}
--- a/ui/administratorwindow.h	Tue Apr 15 12:06:03 2014 +0200
+++ b/ui/administratorwindow.h	Tue Apr 15 12:34:04 2014 +0200
@@ -33,6 +33,8 @@
     void loadCertificateFile();
     void saveCertificateFile();
     void addCertificates();
+    void removeCertificates();
+    void clickedCertificate(const QModelIndex&);
 
 private:
     void createActions();
--- a/ui/certificatetablemodel.cpp	Tue Apr 15 12:06:03 2014 +0200
+++ b/ui/certificatetablemodel.cpp	Tue Apr 15 12:34:04 2014 +0200
@@ -20,6 +20,22 @@
     endInsertRows();
 }
 
+bool CertificateTabelModel::removeRows(int row, int count,
+    const QModelIndex &index)
+{
+    beginRemoveRows(QModelIndex(), row, row + count - 1);
+    if ((row + count - 1) > certificates.size()) {
+        return false;
+    }
+    for (int i = row + count - 1; i >= row; i--) {
+        if (!certificates.at(i).isEditable()) {
+            certificates.removeAt(i);
+        }
+    }
+    endRemoveRows();
+    return true;
+}
+
 QVariant CertificateTabelModel::data(const QModelIndex &index,
         int role) const
 {
--- a/ui/certificatetablemodel.h	Tue Apr 15 12:06:03 2014 +0200
+++ b/ui/certificatetablemodel.h	Tue Apr 15 12:34:04 2014 +0200
@@ -18,6 +18,7 @@
     CertificateTabelModel(QObject *parent = 0);
 
     void addCertificate(const Certificate &certificate, bool editable);
+    bool removeRows(int row, int count, const QModelIndex&);
     int rowCount(const QModelIndex &parent = QModelIndex()) const;
     int columnCount(const QModelIndex &parent = QModelIndex()) const;
 

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