changeset 342:fba80767fd7a

Fixed member variables in certificate table model.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 10 Apr 2014 10:05:32 +0200
parents 36c68dfb821d
children e3d6de930c90
files ui/certificatetablemodel.cpp ui/certificatetablemodel.h
diffstat 2 files changed, 28 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/ui/certificatetablemodel.cpp	Thu Apr 10 09:56:51 2014 +0200
+++ b/ui/certificatetablemodel.cpp	Thu Apr 10 10:05:32 2014 +0200
@@ -3,34 +3,40 @@
 CertificateTabelModel::CertificateTabelModel(QObject *parent)
     : QAbstractTableModel(parent)
 {
-    certificates = new QList<Certificate>();
-    header = new QList<QString>();
-    header->append("");
-    header->append(tr("CN"));
-    header->append(tr("issued  on"));
-    header->append(tr("expires on"));
-    header->append(tr("Fingerprint"));
+    header.append("");
+    header.append(tr("CN"));
+    header.append(tr("issued  on"));
+    header.append(tr("expires on"));
+    header.append(tr("Fingerprint"));
 
 }
 
-void CertificateTabelModel::addCertificate(Certificate *certificate)
+void CertificateTabelModel::addCertificate(const Certificate& certificate)
 {
-    certificates->append(*certificate);
+    beginInsertRows(QModelIndex(), rowCount(), rowCount());
+    certificates.append(certificate);
+    endInsertRows();
 }
 
 QVariant CertificateTabelModel::data(const QModelIndex &index,
         int role) const
 {
-    if (index.row() > certificates->size() || index.row() < 0) {
+    if (index.row() > certificates.size() || index.row() < 0) {
         return QVariant();
     }
 
-    int row = index.row();
-    Certificate cert = certificates->at(row);
-    switch(index.column()) {
-    case 0: return cert.isInstallCert();
-    case 1: return cert.shortDescription();
-    default: ;
+    if (role == Qt::DisplayRole) {
+        Certificate cert = certificates.at(index.row());
+        QVariant ret;
+        switch(index.column()) {
+        case 0: ret = cert.isInstallCert(); break;
+        case 1: ret = cert.subjectCN(); break;
+        case 2: ret = cert.validFrom(); break;
+        case 3: ret = cert.validTo(); break;
+        case 4: ret = "Fingerprint"; break;
+        default: ;
+        }
+        return ret;
     }
 
     return QVariant();
@@ -40,19 +46,19 @@
         Qt::Orientation orientation, int role) const
 {
     if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
-        return header->at(section);
+        return header.at(section);
     }
     return QVariant();
 }
 
 int CertificateTabelModel::rowCount(const QModelIndex&) const
 {
-    return certificates->size();
+    return certificates.size();
 }
 
 int CertificateTabelModel::columnCount(const QModelIndex&) const
 {
-    return header->size();
+    return header.size();
 }
 
 
--- a/ui/certificatetablemodel.h	Thu Apr 10 09:56:51 2014 +0200
+++ b/ui/certificatetablemodel.h	Thu Apr 10 10:05:32 2014 +0200
@@ -17,7 +17,7 @@
 public:
     CertificateTabelModel(QObject *parent = 0);
 
-    void addCertificate(Certificate *certificate);
+    void addCertificate(const Certificate &certificate);
     int rowCount(const QModelIndex &parent = QModelIndex()) const;
     int columnCount(const QModelIndex &parent = QModelIndex()) const;
 
@@ -26,8 +26,8 @@
             int role = Qt::DisplayRole) const;
 
 private:
-    QList<Certificate> *certificates;
-    QList<QString> *header;
+    QList<Certificate> certificates;
+    QList<QString> header;
 };
 
 #endif

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