Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
propertydialog.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4
#
include
"propertydialog.h"
5
6
#
include
<
QHeaderView
>
7
#
include
<
QLayout
>
8
#
include
<
QDebug
>
9
10
using
namespace
Qt::StringLiterals;
11
12
PropertyDialog
::PropertyDialog(QWidget *parent, Qt::WindowFlags f)
13
: QDialog(parent, f)
14
{
15
buttonBox =
new
QDialogButtonBox;
16
propertyTable =
new
QTableWidget;
17
label =
new
QLabel;
18
19
buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
20
propertyTable->setColumnCount(2);
21
const
QStringList labels = QStringList() << tr(
"Name"
) << tr(
"Value"
);
22
propertyTable->setHorizontalHeaderLabels(labels);
23
propertyTable->horizontalHeader()->setStretchLastSection(
true
);
24
propertyTable->setEditTriggers(QAbstractItemView::AllEditTriggers);
25
26
connect(buttonBox, &QDialogButtonBox::accepted,
this
, &QDialog::accept, Qt::QueuedConnection);
27
connect(buttonBox, &QDialogButtonBox::rejected,
this
, &QDialog::reject, Qt::QueuedConnection);
28
29
QVBoxLayout *layout =
new
QVBoxLayout(
this
);
30
layout->addWidget(label);
31
layout->addWidget(propertyTable);
32
layout->addWidget(buttonBox);
33
}
34
35
void
PropertyDialog
::
setInfo
(
const
QString &caption)
36
{
37
label->setText(caption);
38
}
39
40
void
PropertyDialog
::
addProperty
(
const
QString &aname,
int
type)
41
{
42
int
rowCount = propertyTable->rowCount();
43
propertyTable->setRowCount(rowCount + 1);
44
45
QString name = aname;
46
if
(name.isEmpty())
47
name = tr(
"argument %1"
).arg(rowCount + 1);
48
name +=
" ("_L1
;
49
name += QLatin1String(QMetaType(type).name());
50
name +=
")"_L1
;
51
QTableWidgetItem *nameItem =
new
QTableWidgetItem(name);
52
nameItem->setFlags(nameItem->flags() &
53
~(Qt::ItemIsEditable | Qt::ItemIsSelectable));
54
propertyTable->setItem(rowCount, 0, nameItem);
55
56
QTableWidgetItem *valueItem =
new
QTableWidgetItem;
57
valueItem->setData(Qt::DisplayRole, QVariant(QMetaType(type),
/* copy */
0));
58
propertyTable->setItem(rowCount, 1, valueItem);
59
}
60
61
int
PropertyDialog
::
exec
()
62
{
63
propertyTable->resizeColumnToContents(0);
64
propertyTable->setFocus();
65
propertyTable->setCurrentCell(0, 1);
66
return
QDialog::exec();
67
}
68
69
QList
<
QVariant
>
PropertyDialog
::
values
()
const
70
{
71
QList<QVariant> result;
72
73
for
(
int
i = 0; i < propertyTable->rowCount(); ++i)
74
result << propertyTable->item(i, 1)->data(Qt::EditRole);
75
76
return
result;
77
}
PropertyDialog
Definition
propertydialog.h:13
PropertyDialog::setInfo
void setInfo(const QString &caption)
Definition
propertydialog.cpp:35
PropertyDialog::exec
int exec() override
Shows the dialog as a \l{QDialog::Modal Dialogs}{modal dialog}, blocking until the user closes it.
Definition
propertydialog.cpp:61
PropertyDialog::values
QList< QVariant > values() const
Definition
propertydialog.cpp:69
PropertyDialog::addProperty
void addProperty(const QString &name, int type)
Definition
propertydialog.cpp:40
qttools
src
qdbus
qdbusviewer
propertydialog.cpp
Generated on
for Qt by
1.18.0