annotate ui/certificatetabledelegate.cpp @ 471:dd54c02fc28a

Hex != base64
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 23 Apr 2014 16:34:46 +0000
parents 17e1c8f37d72
children 0d92ab04d61c
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 402
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 402
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 402
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 402
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 402
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 402
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 402
diff changeset
7 */
347
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 #include <QtWidgets>
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 #include <QComboBox>
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 #include "certificatetabledelegate.h"
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 void CertificateTableDelegate::paint(QPainter *painter,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 const QStyleOptionViewItem &option, const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 painter->save();
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 if (index.column() == 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 if (option.state & QStyle::State_Selected) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 painter->fillRect(option.rect, option.palette.highlight());
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 bool value = index.data(Qt::DisplayRole).toBool();
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 QIcon icon = value ? QIcon(":/img/list-add.png"):QIcon(":/img/list-remove.png") ;
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 icon.paint(painter, option.rect, Qt::AlignVCenter|Qt::AlignHCenter);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 else {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 QStyledItemDelegate::paint(painter, option, index);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 painter->restore();
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 QWidget *CertificateTableDelegate::createEditor(QWidget *parent,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 const QStyleOptionViewItem &option, const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 if (index.column() == 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 // Draw a combobox in the first column for install/remove certificate
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 // selection.
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 return drawComboBox(parent, option, index);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 else {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 return QStyledItemDelegate::createEditor(parent, option, index);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 QWidget *CertificateTableDelegate::drawComboBox(QWidget *parent,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 const QStyleOptionViewItem &option, const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 {
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 354
diff changeset
48 bool editable = index.data(Qt::UserRole).toBool();
347
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 // Create a combobox and add two items for install/remove.
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 QComboBox *comboBox = new QComboBox(parent);
402
bae8d4a20ef1 Added strings for add and remove in table view combobox.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
51 comboBox->addItem(QIcon(":/img/list-add.png"), tr("add"), QVariant("true"));
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 354
diff changeset
52 if (editable) {
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 354
diff changeset
53 comboBox->addItem(QIcon(":/img/list-remove.png"),
402
bae8d4a20ef1 Added strings for add and remove in table view combobox.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
54 tr("remove"), QVariant("false"));
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 354
diff changeset
55 }
347
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 return comboBox;
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 void CertificateTableDelegate::setEditorData(QWidget *editor,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 if (index.column() != 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 return;
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 // Get the current value from the model.
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 QString value = index.data(Qt::DisplayRole).toString();
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 // Find the index in comboxbox items and set the current index.
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 QComboBox *comboBox = static_cast<QComboBox*>(editor);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 int ndx = comboBox->findData(value, Qt::UserRole);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 comboBox->setCurrentIndex(ndx);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 void CertificateTableDelegate::setModelData(QWidget *editor,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 QAbstractItemModel *model, const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 if (index.column() != 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 return;
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 QComboBox *comboBox = static_cast<QComboBox*>(editor);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 bool value = comboBox->currentData().toBool();
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 model->setData(index, value, Qt::EditRole);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 void CertificateTableDelegate::updateEditorGeometry(QWidget *editor,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 const QStyleOptionViewItem &option, const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 if (index.column() != 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 return;
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 editor->setGeometry(option.rect);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 }

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