diff ui/mainwindow.cpp @ 267:89e8783866f8

Use the certificate item delegate in the mainwind list view.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 02 Apr 2014 09:27:24 +0200
parents ffd47b045d19
children 1ae15ea73850
line wrap: on
line diff
--- a/ui/mainwindow.cpp	Wed Apr 02 09:26:38 2014 +0200
+++ b/ui/mainwindow.cpp	Wed Apr 02 09:27:24 2014 +0200
@@ -32,6 +32,7 @@
 #include "helpdialog.h"
 #include "aboutdialog.h"
 #include "statusdialog.h"
+#include "certificateitemdelegate.h"
 
 MainWindow::MainWindow() {
     createActions();
@@ -246,6 +247,7 @@
     // The certificate list
     QGroupBox *certBox = new QGroupBox(tr("Managed Certificates"));
     certificateList = new QListWidget;
+    certificateList->setItemDelegate(new CertificateItemDelegate);
     connect(certificateList, SIGNAL(itemClicked(QListWidgetItem*)),
         this, SLOT(showDetails(QListWidgetItem*)));
     certLayout->addWidget(certificateList);
@@ -302,6 +304,7 @@
 {
     qDebug() << "display certificates";
     certificateList->clear();
+    int i = 0;
     foreach (const Certificate &cert, mListToInstall.getCertificates()) {
         if (!cert.isValid()) {
             qWarning() << "Invalid certificate in list";
@@ -309,10 +312,33 @@
         }
         QListWidgetItem* item = new QListWidgetItem(cert.shortDescription());
         item->setData(Qt::UserRole, cert.details());
-        QIcon *certIcon = cert.isInstallCert() ? new QIcon(":/img/list-add.png"):
-                                                 new QIcon(":/img/list-remove.png");
-        item->setIcon(*certIcon);
+        if (cert.isInstallCert()) {
+            // This if statements is for testing! @TODO Remove this!
+            if (i <= 2) {
+                item->setData(Qt::UserRole + 1, Certificate::InstallOld);
+                item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
+                item->setCheckState(Qt::Checked);
+            }
+            else {
+                item->setData(Qt::UserRole + 1, Certificate::InstallNew);
+                item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
+                item->setCheckState(Qt::Checked);
+            }
+        }
+        else {
+            // This if statements is for testing! @TODO Remove this!
+            if (i > 35) {
+                item->setData(Qt::UserRole + 1, Certificate::RemoveNew);
+                item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
+                item->setCheckState(Qt::Checked);
+            }
+            else {
+                item->setData(Qt::UserRole + 1, Certificate::RemoveOld);
+                item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
+            }
+        }
         certificateList->addItem(item);
+        i++;
     }
 }
 

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