Mercurial > trustbridge
view ui/certificatetablemodel.cpp @ 383:5eb7ee4ee819
Look up executable name based on /proc/self/exe
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 15 Apr 2014 17:47:07 +0200 |
parents | 1220b741cd51 |
children | 26651cc0cc47 |
line wrap: on
line source
#include "certificatetablemodel.h" CertificateTabelModel::CertificateTabelModel(QObject *parent) : QAbstractTableModel(parent) { header.append(""); header.append(tr("Subject CN")); header.append(tr("Subject O")); header.append(tr("Issuer CN")); header.append(tr("Issuer O")); header.append(tr("valid from")); header.append(tr("valid to")); header.append(tr("SHA1 Fingerprint")); } void CertificateTabelModel::addCertificate(const Certificate& certificate, bool editable) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); certificates.append(certificate); certificates.last().setEditable(editable); endInsertRows(); } bool CertificateTabelModel::removeRows(int row, int count, const QModelIndex &index) { beginRemoveRows(QModelIndex(), row, row + count - 1); if ((row + count - 1) > certificates.size()) { return false; } for (int i = row + count - 1; i >= row; i--) { if (!certificates.at(i).isEditable()) { certificates.removeAt(i); } } endRemoveRows(); return true; } QVariant CertificateTabelModel::data(const QModelIndex &index, int role) const { if (index.row() > certificates.size() || index.row() < 0) { return QVariant(); } if (role == Qt::DisplayRole) { Certificate cert = certificates.at(index.row()); QVariant ret; switch(index.column()) { case 0: ret = cert.isInstallCert(); break; case 1: ret = cert.subjectCN(); break; case 2: ret = cert.subjectO(); break; case 3: ret = cert.issuerCN(); break; case 4: ret = cert.issuerO(); break; case 5: ret = cert.validFrom(); break; case 6: ret = cert.validTo(); break; case 7: ret = cert.fingerprint(); break; default: ; } return ret; } if (role == Qt::UserRole) { Certificate cert = certificates.at(index.row()); return cert.isEditable(); } return QVariant(); } bool CertificateTabelModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.row() > certificates.size() || index.row() < 0) { return false; } bool newValue = value.toBool(); Certificate &cert = certificates[index.row()]; if (!cert.isEditable()) { return false; } cert.setInstallCert(newValue); emit dataChanged(index, index); return true; } QVariant CertificateTabelModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { return header.at(section); } return QVariant(); } int CertificateTabelModel::rowCount(const QModelIndex&) const { return certificates.size(); } int CertificateTabelModel::columnCount(const QModelIndex&) const { return header.size(); } Qt::ItemFlags CertificateTabelModel::flags(const QModelIndex &index) const { if (!index.isValid ()) return Qt::ItemIsSelectable; if (index.column() == 0) { return QAbstractTableModel::flags(index) | Qt::ItemIsEditable; } return QAbstractTableModel::flags(index); }