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
previewactiongroup.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
// Qt-Security score:significant reason:default
4
5
#
include
"previewactiongroup.h"
6
7
#
include
<
deviceprofile_p
.
h
>
8
#
include
<
shared_settings_p
.
h
>
9
10
#
include
<
QtWidgets
/
qstylefactory
.
h
>
11
#
include
<
QtCore
/
qvariant
.
h
>
12
13
QT_BEGIN_NAMESPACE
14
15
using
namespace
Qt::StringLiterals;
16
17
enum
{
MaxDeviceActions
= 20 };
18
19
namespace
qdesigner_internal
{
20
21
PreviewActionGroup
::PreviewActionGroup(QDesignerFormEditorInterface *core, QObject *parent) :
22
QActionGroup(parent),
23
m_core(core)
24
{
25
/* Create a list of up to MaxDeviceActions invisible actions to be
26
* populated with device profiles (actiondata: index) followed by the
27
* standard style actions (actiondata: style name). */
28
connect(
this
, &PreviewActionGroup::triggered,
this
, &PreviewActionGroup::slotTriggered);
29
setExclusive(
true
);
30
31
// Create invisible actions for devices. Set index as action data.
32
for
(
int
i = 0; i <
MaxDeviceActions
; i++) {
33
QAction *a =
new
QAction(
this
);
34
a->setObjectName(QString::asprintf(
"__qt_designer_device_%d_action"
, i));
35
a->setVisible(
false
);
36
a->setData(i);
37
addAction(a);
38
}
39
// Create separator at index MaxDeviceActions
40
QAction *sep =
new
QAction(
this
);
41
sep->setObjectName(u"__qt_designer_deviceseparator"_s);
42
sep->setSeparator(
true
);
43
sep->setVisible(
false
);
44
addAction(sep);
45
// Populate devices
46
updateDeviceProfiles();
47
48
// Add style actions
49
const
QStringList styles = QStyleFactory::keys();
50
// Make sure ObjectName is unique in case toolbar solution is used.
51
// Create styles. Set style name string as action data.
52
for
(
const
auto
&s : styles) {
53
QAction *a =
new
QAction(tr(
"%1 Style"
).arg(s),
this
);
54
a->setObjectName(
"__qt_designer_style_"_L1
+ s +
"_action"_L1
);
55
a->setData(s);
56
addAction(a);
57
}
58
}
59
60
void
PreviewActionGroup
::updateDeviceProfiles()
61
{
62
const
QDesignerSharedSettings settings(m_core);
63
const
auto
profiles = settings.deviceProfiles();
64
const
auto
al = actions();
65
// Separator?
66
const
bool
hasProfiles = !profiles.isEmpty();
67
al.at(
MaxDeviceActions
)->setVisible(hasProfiles);
68
int
index = 0;
69
if
(hasProfiles) {
70
// Make actions visible
71
const
int
maxIndex = qMin(
static_cast
<
int
>(
MaxDeviceActions
), profiles.size());
72
for
(; index < maxIndex; index++) {
73
const
QString name = profiles.at(index).name();
74
al.at(index)->setText(name);
75
al.at(index)->setVisible(
true
);
76
}
77
}
78
// Hide rest
79
for
( ; index <
MaxDeviceActions
; index++)
80
al.at(index)->setVisible(
false
);
81
}
82
83
void
PreviewActionGroup
::slotTriggered(QAction *a)
84
{
85
// Device or style according to data.
86
const
QVariant data = a->data();
87
switch
(data.metaType().id()) {
88
case
QMetaType::QString:
89
emit preview(data.toString(), -1);
90
break
;
91
case
QMetaType::Int:
92
emit preview(QString(), data.toInt());
93
break
;
94
default
:
95
break
;
96
}
97
}
98
99
}
100
101
QT_END_NAMESPACE
qdesigner_internal::PreviewActionGroup
Definition
previewactiongroup.h:31
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
MaxDeviceActions
@ MaxDeviceActions
Definition
previewactiongroup.cpp:17
qttools
src
designer
src
components
formeditor
previewactiongroup.cpp
Generated on
for Qt by
1.18.0