annotate ui/certificatetablemodel.cpp @ 375:9e38a4bcd44e

Move certificateitem role into the certificateitemdelagate where it belongs.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 15 Apr 2014 12:06:03 +0200
parents 9ba7b4b4c1de
children 9731d28b95af
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
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
14 void CertificateTabelModel::addCertificate(const Certificate& certificate,
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
15 bool editable)
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
17 beginInsertRows(QModelIndex(), rowCount(), rowCount());
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
18 certificates.append(certificate);
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
19 certificates.last().setEditable(editable);
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
20 endInsertRows();
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 QVariant CertificateTabelModel::data(const QModelIndex &index,
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 int role) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
26 if (index.row() > certificates.size() || index.row() < 0) {
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 return QVariant();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
30 if (role == Qt::DisplayRole) {
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
31 Certificate cert = certificates.at(index.row());
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
32 QVariant ret;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
33 switch(index.column()) {
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
34 case 0: ret = cert.isInstallCert(); break;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
35 case 1: ret = cert.subjectCN(); break;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
36 case 2: ret = cert.validFrom(); break;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
37 case 3: ret = cert.validTo(); break;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
38 case 4: ret = "Fingerprint"; break;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
39 default: ;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
40 }
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
41 return ret;
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 }
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
43 if (role == Qt::UserRole) {
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
44 Certificate cert = certificates.at(index.row());
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
45 return cert.isEditable();
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
46 }
334
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 return QVariant();
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
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
51 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
52 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
53 {
353
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
54 if (index.row() > certificates.size() || index.row() < 0) {
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
55 return false;
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
56 }
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
57
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
58 bool newValue = value.toBool();
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
59 Certificate &cert = certificates[index.row()];
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
60 if (!cert.isEditable()) {
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
61 return false;
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
62 }
353
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
63 cert.setInstallCert(newValue);
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
64
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
65 emit dataChanged(index, index);
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
66
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
67 return true;
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
68 }
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
69
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 QVariant CertificateTabelModel::headerData(int section,
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 Qt::Orientation orientation, int role) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 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
74 return header.at(section);
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 return QVariant();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 }
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 int CertificateTabelModel::rowCount(const QModelIndex&) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
81 return certificates.size();
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 int CertificateTabelModel::columnCount(const QModelIndex&) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
86 return header.size();
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
89 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
90 {
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
91 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
92 return Qt::ItemIsSelectable;
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
94 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
95 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
96 }
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
97
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
98 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
99 }

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