annotate ui/certificatetabledelegate.cpp @ 401:e11409381e16

Changed path for load certificatelist and add certificate.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 16 Apr 2014 11:03:18 +0200
parents 9ba7b4b4c1de
children bae8d4a20ef1
rev   line source
347
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 #include <QtWidgets>
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2 #include <QComboBox>
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4 #include "certificatetabledelegate.h"
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6 void CertificateTableDelegate::paint(QPainter *painter,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7 const QStyleOptionViewItem &option, const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 painter->save();
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 if (index.column() == 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 if (option.state & QStyle::State_Selected) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 painter->fillRect(option.rect, option.palette.highlight());
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 bool value = index.data(Qt::DisplayRole).toBool();
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 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
17 icon.paint(painter, option.rect, Qt::AlignVCenter|Qt::AlignHCenter);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 else {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 QStyledItemDelegate::paint(painter, option, index);
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 painter->restore();
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 QWidget *CertificateTableDelegate::createEditor(QWidget *parent,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 const QStyleOptionViewItem &option, const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 if (index.column() == 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 // 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
30 // selection.
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 return drawComboBox(parent, option, index);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 else {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 return QStyledItemDelegate::createEditor(parent, option, index);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 QWidget *CertificateTableDelegate::drawComboBox(QWidget *parent,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 const QStyleOptionViewItem &option, const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 {
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 354
diff changeset
41 bool editable = index.data(Qt::UserRole).toBool();
347
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 // 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
43 QComboBox *comboBox = new QComboBox(parent);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 comboBox->addItem(QIcon(":/img/list-add.png"), QString(""), 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
45 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
46 comboBox->addItem(QIcon(":/img/list-remove.png"),
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 354
diff changeset
47 QString(""), QVariant("false"));
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 354
diff changeset
48 }
347
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 return comboBox;
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 }
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 void CertificateTableDelegate::setEditorData(QWidget *editor,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 if (index.column() != 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 return;
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 // Get the current value from the model.
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 QString value = index.data(Qt::DisplayRole).toString();
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 // 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
62 QComboBox *comboBox = static_cast<QComboBox*>(editor);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 int ndx = comboBox->findData(value, Qt::UserRole);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 comboBox->setCurrentIndex(ndx);
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
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 void CertificateTableDelegate::setModelData(QWidget *editor,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 QAbstractItemModel *model, const QModelIndex &index) const
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 if (index.column() != 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 return;
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 QComboBox *comboBox = static_cast<QComboBox*>(editor);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 bool value = comboBox->currentData().toBool();
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 model->setData(index, value, Qt::EditRole);
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
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 void CertificateTableDelegate::updateEditorGeometry(QWidget *editor,
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 const QStyleOptionViewItem &option, const QModelIndex &index) const
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 if (index.column() != 0) {
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 return;
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 editor->setGeometry(option.rect);
dde533ba4fcc Added table item delegate for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 }

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