Mercurial > trustbridge
annotate ui/certificatetablemodel.cpp @ 397:8752aae8aad8
Set DejaVu Sans Mono as font for fingerprint column.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 15 Apr 2014 16:46:13 +0200 |
parents | 26651cc0cc47 |
children | 17e1c8f37d72 |
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 |
397
8752aae8aad8
Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents:
396
diff
changeset
|
3 #include <QFont> |
8752aae8aad8
Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents:
396
diff
changeset
|
4 |
334
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
5 CertificateTabelModel::CertificateTabelModel(QObject *parent) |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
6 : QAbstractTableModel(parent) |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
7 { |
342
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
8 header.append(""); |
380
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
9 header.append(tr("Subject CN")); |
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
10 header.append(tr("Subject O")); |
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
11 header.append(tr("Issuer CN")); |
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
12 header.append(tr("Issuer O")); |
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
13 header.append(tr("valid from")); |
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
14 header.append(tr("valid to")); |
378
31079bd54036
Add fingerprint to certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
376
diff
changeset
|
15 header.append(tr("SHA1 Fingerprint")); |
334
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
16 |
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 |
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 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
|
20 bool editable) |
334
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
21 { |
342
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
22 beginInsertRows(QModelIndex(), rowCount(), rowCount()); |
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
23 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
|
24 certificates.last().setEditable(editable); |
342
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
25 endInsertRows(); |
334
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 |
376
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
28 bool CertificateTabelModel::removeRows(int row, int count, |
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
29 const QModelIndex &index) |
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
30 { |
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
31 beginRemoveRows(QModelIndex(), row, row + count - 1); |
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
32 if ((row + count - 1) > certificates.size()) { |
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
33 return false; |
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
34 } |
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
35 for (int i = row + count - 1; i >= row; i--) { |
396
26651cc0cc47
Remove all certificates if a new list is loaded from file.
Raimund Renkert <rrenkert@intevation.de>
parents:
380
diff
changeset
|
36 certificates.removeAt(i); |
376
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
37 } |
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
38 endRemoveRows(); |
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
39 return true; |
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
40 } |
9731d28b95af
Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents:
358
diff
changeset
|
41 |
396
26651cc0cc47
Remove all certificates if a new list is loaded from file.
Raimund Renkert <rrenkert@intevation.de>
parents:
380
diff
changeset
|
42 bool CertificateTabelModel::removeAll() |
26651cc0cc47
Remove all certificates if a new list is loaded from file.
Raimund Renkert <rrenkert@intevation.de>
parents:
380
diff
changeset
|
43 { |
26651cc0cc47
Remove all certificates if a new list is loaded from file.
Raimund Renkert <rrenkert@intevation.de>
parents:
380
diff
changeset
|
44 return removeRows(0, certificates.size(), QModelIndex()); |
26651cc0cc47
Remove all certificates if a new list is loaded from file.
Raimund Renkert <rrenkert@intevation.de>
parents:
380
diff
changeset
|
45 } |
26651cc0cc47
Remove all certificates if a new list is loaded from file.
Raimund Renkert <rrenkert@intevation.de>
parents:
380
diff
changeset
|
46 |
334
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 QVariant CertificateTabelModel::data(const QModelIndex &index, |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
48 int role) const |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 { |
342
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
50 if (index.row() > certificates.size() || index.row() < 0) { |
334
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
51 return QVariant(); |
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 |
342
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
54 if (role == Qt::DisplayRole) { |
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
55 Certificate cert = certificates.at(index.row()); |
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
56 QVariant ret; |
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
57 switch(index.column()) { |
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
58 case 0: ret = cert.isInstallCert(); break; |
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
59 case 1: ret = cert.subjectCN(); break; |
380
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
60 case 2: ret = cert.subjectO(); break; |
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
61 case 3: ret = cert.issuerCN(); break; |
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
62 case 4: ret = cert.issuerO(); break; |
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
63 case 5: ret = cert.validFrom(); break; |
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
64 case 6: ret = cert.validTo(); break; |
1220b741cd51
Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents:
378
diff
changeset
|
65 case 7: ret = cert.fingerprint(); break; |
342
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
66 default: ; |
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
67 } |
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
68 return ret; |
334
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
69 } |
358
9ba7b4b4c1de
Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
353
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 } |
397
8752aae8aad8
Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents:
396
diff
changeset
|
74 if (role == Qt::FontRole && index.column() == 7) { |
8752aae8aad8
Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents:
396
diff
changeset
|
75 QFont block("DejaVu Sans Mono"); |
8752aae8aad8
Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents:
396
diff
changeset
|
76 return block; |
8752aae8aad8
Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents:
396
diff
changeset
|
77 } |
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 return QVariant(); |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
80 } |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
81 |
348
e6aa82466420
Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents:
342
diff
changeset
|
82 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
|
83 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
|
84 { |
353
666abcfab229
Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
348
diff
changeset
|
85 if (index.row() > certificates.size() || index.row() < 0) { |
666abcfab229
Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
348
diff
changeset
|
86 return false; |
666abcfab229
Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
348
diff
changeset
|
87 } |
666abcfab229
Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
348
diff
changeset
|
88 |
666abcfab229
Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
348
diff
changeset
|
89 bool newValue = value.toBool(); |
666abcfab229
Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
348
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 } |
353
666abcfab229
Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
348
diff
changeset
|
94 cert.setInstallCert(newValue); |
666abcfab229
Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
348
diff
changeset
|
95 |
666abcfab229
Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
348
diff
changeset
|
96 emit dataChanged(index, index); |
666abcfab229
Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
348
diff
changeset
|
97 |
348
e6aa82466420
Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents:
342
diff
changeset
|
98 return true; |
e6aa82466420
Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents:
342
diff
changeset
|
99 } |
e6aa82466420
Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents:
342
diff
changeset
|
100 |
334
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
101 QVariant CertificateTabelModel::headerData(int section, |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
102 Qt::Orientation orientation, int role) const |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
103 { |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
104 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
|
105 return header.at(section); |
334
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
106 } |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
107 return QVariant(); |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
108 } |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
109 |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
110 int CertificateTabelModel::rowCount(const QModelIndex&) const |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
111 { |
342
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
112 return certificates.size(); |
334
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
113 } |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
114 |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
115 int CertificateTabelModel::columnCount(const QModelIndex&) const |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
116 { |
342
fba80767fd7a
Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents:
334
diff
changeset
|
117 return header.size(); |
334
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
118 } |
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
119 |
348
e6aa82466420
Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents:
342
diff
changeset
|
120 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
|
121 { |
e6aa82466420
Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents:
342
diff
changeset
|
122 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
|
123 return Qt::ItemIsSelectable; |
334
36be67070dcb
Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
124 |
348
e6aa82466420
Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents:
342
diff
changeset
|
125 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
|
126 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
|
127 } |
e6aa82466420
Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents:
342
diff
changeset
|
128 |
e6aa82466420
Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents:
342
diff
changeset
|
129 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
|
130 } |