annotate ui/certificatetablemodel.cpp @ 335:811eec4e1b99

Use a table view with the new certificate table model in administrator app.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 09 Apr 2014 12:44:44 +0200
parents 36be67070dcb
children fba80767fd7a
rev   line source
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 #include "certificatetablemodel.h"
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3 CertificateTabelModel::CertificateTabelModel(QObject *parent)
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4 : QAbstractTableModel(parent)
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6 certificates = new QList<Certificate>();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7 header = new QList<QString>();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 header->append("");
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 header->append(tr("CN"));
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 header->append(tr("issued on"));
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 header->append(tr("expires on"));
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 header->append(tr("Fingerprint"));
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 void CertificateTabelModel::addCertificate(Certificate *certificate)
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17 {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 certificates->append(*certificate);
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 QVariant CertificateTabelModel::data(const QModelIndex &index,
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 int role) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 if (index.row() > certificates->size() || index.row() < 0) {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 return QVariant();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 int row = index.row();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 Certificate cert = certificates->at(row);
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 switch(index.column()) {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 case 0: return cert.isInstallCert();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 case 1: return cert.shortDescription();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 default: ;
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 return QVariant();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 QVariant CertificateTabelModel::headerData(int section,
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 Qt::Orientation orientation, int role) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 return header->at(section);
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 return QVariant();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 int CertificateTabelModel::rowCount(const QModelIndex&) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 return certificates->size();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 int CertificateTabelModel::columnCount(const QModelIndex&) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 return header->size();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58

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