annotate ui/certificatetablemodel.cpp @ 353:666abcfab229

Implemented setData in certificate table model.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 10 Apr 2014 15:56:59 +0200
parents e6aa82466420
children 9ba7b4b4c1de
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 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
6 header.append("");
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
7 header.append(tr("CN"));
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
8 header.append(tr("issued on"));
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
9 header.append(tr("expires on"));
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
10 header.append(tr("Fingerprint"));
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
14 void CertificateTabelModel::addCertificate(const Certificate& certificate)
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
16 beginInsertRows(QModelIndex(), rowCount(), rowCount());
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
17 certificates.append(certificate);
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
18 endInsertRows();
334
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 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
24 if (index.row() > certificates.size() || index.row() < 0) {
334
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
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
28 if (role == Qt::DisplayRole) {
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
29 Certificate cert = certificates.at(index.row());
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
30 QVariant ret;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
31 switch(index.column()) {
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
32 case 0: ret = cert.isInstallCert(); break;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
33 case 1: ret = cert.subjectCN(); break;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
34 case 2: ret = cert.validFrom(); break;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
35 case 3: ret = cert.validTo(); break;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
36 case 4: ret = "Fingerprint"; break;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
37 default: ;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
38 }
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
39 return ret;
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 }
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 return QVariant();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
45 bool CertificateTabelModel::setData(const QModelIndex &index,
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
46 const QVariant &value, int role)
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
47 {
353
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
48 if (index.row() > certificates.size() || index.row() < 0) {
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
49 return false;
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
50 }
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
51
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
52 bool newValue = value.toBool();
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
53 Certificate &cert = certificates[index.row()];
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
54 cert.setInstallCert(newValue);
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
55
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
56 emit dataChanged(index, index);
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
57
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
58 return true;
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
59 }
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
60
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 QVariant CertificateTabelModel::headerData(int section,
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 Qt::Orientation orientation, int role) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
65 return header.at(section);
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 return QVariant();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 int CertificateTabelModel::rowCount(const QModelIndex&) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
72 return certificates.size();
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 int CertificateTabelModel::columnCount(const QModelIndex&) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
77 return header.size();
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
80 Qt::ItemFlags CertificateTabelModel::flags(const QModelIndex &index) const
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
81 {
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
82 if (!index.isValid ())
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
83 return Qt::ItemIsSelectable;
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
85 if (index.column() == 0) {
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
86 return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
87 }
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
88
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
89 return QAbstractTableModel::flags(index);
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
90 }

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