comparison ui/certificatetablemodel.cpp @ 463:5200b8e9b2ae

Rename tablemodel certificates and add accessors
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 23 Apr 2014 15:33:09 +0000
parents 847fdfd33a22
children 320a64d58e62
comparison
equal deleted inserted replaced
462:091ad56c2715 463:5200b8e9b2ae
25 25
26 void CertificateTabelModel::addCertificate(const Certificate& certificate, 26 void CertificateTabelModel::addCertificate(const Certificate& certificate,
27 bool editable) 27 bool editable)
28 { 28 {
29 beginInsertRows(QModelIndex(), rowCount(), rowCount()); 29 beginInsertRows(QModelIndex(), rowCount(), rowCount());
30 certificates.append(certificate); 30 mCertificates.append(certificate);
31 certificates.last().setEditable(editable); 31 mCertificates.last().setEditable(editable);
32 endInsertRows(); 32 endInsertRows();
33 } 33 }
34 34
35 bool CertificateTabelModel::removeRows(int row, int count, 35 bool CertificateTabelModel::removeRows(int row, int count,
36 const QModelIndex &index) 36 const QModelIndex &index)
37 { 37 {
38 beginRemoveRows(QModelIndex(), row, row + count - 1); 38 beginRemoveRows(QModelIndex(), row, row + count - 1);
39 if ((row + count - 1) > certificates.size()) { 39 if ((row + count - 1) > mCertificates.size()) {
40 return false; 40 return false;
41 } 41 }
42 for (int i = row + count - 1; i >= row; i--) { 42 for (int i = row + count - 1; i >= row; i--) {
43 certificates.removeAt(i); 43 mCertificates.removeAt(i);
44 } 44 }
45 endRemoveRows(); 45 endRemoveRows();
46 return true; 46 return true;
47 } 47 }
48 48
49 bool CertificateTabelModel::removeAll() 49 bool CertificateTabelModel::removeAll()
50 { 50 {
51 return removeRows(0, certificates.size(), QModelIndex()); 51 return removeRows(0, mCertificates.size(), QModelIndex());
52 } 52 }
53 53
54 QVariant CertificateTabelModel::data(const QModelIndex &index, 54 QVariant CertificateTabelModel::data(const QModelIndex &index,
55 int role) const 55 int role) const
56 { 56 {
57 if (index.row() > certificates.size() || index.row() < 0) { 57 if (index.row() > mCertificates.size() || index.row() < 0) {
58 return QVariant(); 58 return QVariant();
59 } 59 }
60 60
61 if (role == Qt::DisplayRole) { 61 if (role == Qt::DisplayRole) {
62 Certificate cert = certificates.at(index.row()); 62 Certificate cert = mCertificates.at(index.row());
63 QVariant ret; 63 QVariant ret;
64 switch(index.column()) { 64 switch(index.column()) {
65 case 0: ret = cert.isInstallCert(); break; 65 case 0: ret = cert.isInstallCert(); break;
66 case 1: ret = cert.subjectCN(); break; 66 case 1: ret = cert.subjectCN(); break;
67 case 2: ret = cert.subjectO(); break; 67 case 2: ret = cert.subjectO(); break;
73 default: ; 73 default: ;
74 } 74 }
75 return ret; 75 return ret;
76 } 76 }
77 if (role == Qt::UserRole) { 77 if (role == Qt::UserRole) {
78 Certificate cert = certificates.at(index.row()); 78 Certificate cert = mCertificates.at(index.row());
79 return cert.isEditable(); 79 return cert.isEditable();
80 } 80 }
81 if (role == Qt::FontRole && index.column() == 7) { 81 if (role == Qt::FontRole && index.column() == 7) {
82 QFont block("DejaVu Sans Mono"); 82 QFont block("DejaVu Sans Mono");
83 return block; 83 return block;
87 } 87 }
88 88
89 bool CertificateTabelModel::setData(const QModelIndex &index, 89 bool CertificateTabelModel::setData(const QModelIndex &index,
90 const QVariant &value, int role) 90 const QVariant &value, int role)
91 { 91 {
92 if (index.row() > certificates.size() || index.row() < 0) { 92 if (index.row() > mCertificates.size() || index.row() < 0) {
93 return false; 93 return false;
94 } 94 }
95 95
96 bool newValue = value.toBool(); 96 bool newValue = value.toBool();
97 Certificate &cert = certificates[index.row()]; 97 Certificate &cert = mCertificates[index.row()];
98 if (!cert.isEditable()) { 98 if (!cert.isEditable()) {
99 return false; 99 return false;
100 } 100 }
101 cert.setInstallCert(newValue); 101 cert.setInstallCert(newValue);
102 102
114 return QVariant(); 114 return QVariant();
115 } 115 }
116 116
117 int CertificateTabelModel::rowCount(const QModelIndex&) const 117 int CertificateTabelModel::rowCount(const QModelIndex&) const
118 { 118 {
119 return certificates.size(); 119 return mCertificates.size();
120 } 120 }
121 121
122 int CertificateTabelModel::columnCount(const QModelIndex&) const 122 int CertificateTabelModel::columnCount(const QModelIndex&) const
123 { 123 {
124 return header.size(); 124 return header.size();

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