annotate ui/certificatetabledelegate.cpp @ 1163:e3772d2810b3

Fix tests now that portpath includes logging
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 18 Sep 2014 18:53:56 +0200
parents 0d92ab04d61c
children
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);
1054
0d92ab04d61c (issue104) Use fixed width for certificate drop box in admin window
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
51 comboBox->setFixedWidth(110);
402
bae8d4a20ef1 Added strings for add and remove in table view combobox.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
52 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
53 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
54 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
55 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
56 }
347
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 return comboBox;
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
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 void CertificateTableDelegate::setEditorData(QWidget *editor,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 if (index.column() != 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 return;
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 // Get the current value from the model.
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 QString value = index.data(Qt::DisplayRole).toString();
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 // 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
70 QComboBox *comboBox = static_cast<QComboBox*>(editor);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 int ndx = comboBox->findData(value, Qt::UserRole);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 comboBox->setCurrentIndex(ndx);
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
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 void CertificateTableDelegate::setModelData(QWidget *editor,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 QAbstractItemModel *model, const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 if (index.column() != 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 return;
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 QComboBox *comboBox = static_cast<QComboBox*>(editor);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 bool value = comboBox->currentData().toBool();
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 model->setData(index, value, Qt::EditRole);
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
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 void CertificateTableDelegate::updateEditorGeometry(QWidget *editor,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 const QStyleOptionViewItem &option, const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 if (index.column() != 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 return;
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 editor->setGeometry(option.rect);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 }

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