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
promotionmodel.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
"promotionmodel_p.h"
6
#
include
"widgetdatabase_p.h"
7
8
#
include
<
QtDesigner
/
abstractwidgetdatabase
.
h
>
9
#
include
<
QtDesigner
/
abstractpromotioninterface
.
h
>
10
#
include
<
QtDesigner
/
abstractformeditor
.
h
>
11
12
#
include
<
QtGui
/
qstandarditemmodel
.
h
>
13
#
include
<
QtCore
/
qcoreapplication
.
h
>
14
15
QT_BEGIN_NAMESPACE
16
17
namespace
{
18
using
StandardItemList = QList<QStandardItem *>;
19
20
// Model columns.
21
enum
{
ClassNameColumn
,
IncludeFileColumn
,
IncludeTypeColumn
,
ReferencedColumn
,
NumColumns
};
22
23
// Create a model row.
24
StandardItemList
modelRow
() {
25
StandardItemList rc;
26
for
(
int
i = 0; i <
NumColumns
; i++) {
27
rc.push_back(
new
QStandardItem());
28
}
29
return
rc;
30
}
31
32
// Create a model row for a base class (read-only, cannot be selected).
33
StandardItemList
baseModelRow
(
const
QDesignerWidgetDataBaseItemInterface
*dbItem) {
34
StandardItemList rc = modelRow();
35
36
rc[
ClassNameColumn
]->setText(dbItem->name());
37
for
(
int
i = 0; i <
NumColumns
; i++) {
38
rc[i]->setFlags(Qt::ItemIsEnabled);
39
}
40
return
rc;
41
}
42
43
// Create an editable model row for a promoted class.
44
StandardItemList
promotedModelRow
(
QDesignerWidgetDataBaseItemInterface
*baseItem,
45
QDesignerWidgetDataBaseItemInterface
*dbItem,
46
bool
referenced)
47
{
48
qdesigner_internal::PromotionModel::ModelData data;
49
data.baseItem = baseItem;
50
data.promotedItem = dbItem;
51
data.referenced = referenced;
52
53
const
QVariant userData = QVariant::fromValue(data);
54
55
StandardItemList rc = modelRow();
56
// name
57
rc[
ClassNameColumn
]->setText(dbItem->name());
58
rc[
ClassNameColumn
]->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable);
59
rc[
ClassNameColumn
]->setData(userData);
60
// header
61
const
qdesigner_internal::IncludeSpecification spec = qdesigner_internal::includeSpecification(dbItem->includeFile());
62
rc[
IncludeFileColumn
]->setText(spec.first);
63
rc[
IncludeFileColumn
]->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable);
64
rc[
IncludeFileColumn
]->setData(userData);
65
// global include
66
rc[
IncludeTypeColumn
]->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable|Qt::ItemIsUserCheckable);
67
rc[
IncludeTypeColumn
]->setData(userData);
68
rc[
IncludeTypeColumn
]->setCheckState(spec.second == qdesigner_internal::IncludeGlobal ? Qt::Checked : Qt::Unchecked);
69
// referenced
70
rc[
ReferencedColumn
]->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
71
rc[
ClassNameColumn
]->setData(userData);
72
if
(!referenced) {
73
//: Usage of promoted widgets
74
static
const
QString notUsed = QCoreApplication::translate(
"PromotionModel"
,
"Not used"
);
75
rc[
ReferencedColumn
]->setText(notUsed);
76
}
77
return
rc;
78
}
79
}
80
81
namespace
qdesigner_internal
{
82
83
PromotionModel
::
PromotionModel
(QDesignerFormEditorInterface *core) :
84
m_core(core)
85
{
86
connect(
this
, &QStandardItemModel::itemChanged,
this
, &PromotionModel::slotItemChanged);
87
}
88
89
void
PromotionModel
::initializeHeaders() {
90
setColumnCount(
NumColumns
);
91
QStringList horizontalLabels(tr(
"Name"
));
92
horizontalLabels += tr(
"Header file"
);
93
horizontalLabels += tr(
"Global include"
);
94
horizontalLabels += tr(
"Usage"
);
95
setHorizontalHeaderLabels (horizontalLabels);
96
}
97
98
void
PromotionModel
::
updateFromWidgetDatabase
() {
99
using
PromotedClasses = QDesignerPromotionInterface::PromotedClasses;
100
101
clear();
102
initializeHeaders();
103
104
// retrieve list of pairs from DB and convert into a tree structure.
105
// Set the item index as user data on the item.
106
const
PromotedClasses promotedClasses = m_core->promotion()->promotedClasses();
107
108
if
(promotedClasses.isEmpty())
109
return
;
110
111
const
QSet<QString> usedPromotedClasses = m_core->promotion()->referencedPromotedClassNames();
112
113
QDesignerWidgetDataBaseItemInterface *baseClass =
nullptr
;
114
QStandardItem *baseItem =
nullptr
;
115
116
for
(
auto
&pi : promotedClasses) {
117
// Start a new base class?
118
if
(baseClass != pi.baseItem) {
119
baseClass = pi.baseItem;
120
const
StandardItemList baseRow = baseModelRow(pi.baseItem);
121
baseItem = baseRow.constFirst();
122
appendRow(baseRow);
123
}
124
Q_ASSERT(baseItem);
125
// Append derived
126
baseItem->appendRow(promotedModelRow(pi.baseItem, pi.promotedItem,
127
usedPromotedClasses.contains(pi.promotedItem->name())));
128
}
129
}
130
131
void
PromotionModel
::slotItemChanged(QStandardItem * changedItem) {
132
// Retrieve DB item
133
const
ModelData data = modelData(changedItem);
134
Q_ASSERT(data.isValid());
135
QDesignerWidgetDataBaseItemInterface *dbItem = data.promotedItem;
136
// Change header or type
137
switch
(changedItem->column()) {
138
case
ClassNameColumn
:
139
emit classNameChanged(dbItem, changedItem->text());
140
break
;
141
case
IncludeTypeColumn
:
142
case
IncludeFileColumn
: {
143
// Get both file and type items via parent.
144
const
QStandardItem *baseClassItem = changedItem->parent();
145
const
QStandardItem *fileItem = baseClassItem->child(changedItem->row(),
IncludeFileColumn
);
146
const
QStandardItem *typeItem = baseClassItem->child(changedItem->row(),
IncludeTypeColumn
);
147
emit includeFileChanged(dbItem, buildIncludeFile(fileItem->text(), typeItem->checkState() == Qt::Checked ? IncludeGlobal : IncludeLocal));
148
}
149
break
;
150
}
151
}
152
153
PromotionModel
::
ModelData
PromotionModel
::
modelData
(
const
QStandardItem *item)
const
154
{
155
const
QVariant userData = item->data();
156
return
userData.canConvert<ModelData>() ? userData.value<ModelData>() : ModelData();
157
}
158
159
PromotionModel
::
ModelData
PromotionModel
::
modelData
(
const
QModelIndex &index)
const
160
{
161
return
index.isValid() ? modelData(itemFromIndex(index)) : ModelData();
162
}
163
164
QModelIndex
PromotionModel
::
indexOfClass
(
const
QString &className)
const
{
165
const
StandardItemList matches = findItems (className, Qt::MatchFixedString|Qt::MatchCaseSensitive|Qt::MatchRecursive);
166
return
matches.isEmpty() ? QModelIndex() : indexFromItem (matches.constFirst());
167
}
168
}
// namespace qdesigner_internal
169
170
QT_END_NAMESPACE
QDesignerWidgetDataBaseItemInterface
The QDesignerWidgetDataBaseItemInterface class provides an interface that is used to access individua...
Definition
abstractwidgetdatabase.h:21
qdesigner_internal::PromotionModel
Definition
promotionmodel_p.h:31
qdesigner_internal::PromotionModel::modelData
ModelData modelData(const QStandardItem *item) const
Definition
promotionmodel.cpp:153
qdesigner_internal::PromotionModel::indexOfClass
QModelIndex indexOfClass(const QString &className) const
Definition
promotionmodel.cpp:164
qdesigner_internal::PromotionModel::updateFromWidgetDatabase
void updateFromWidgetDatabase()
Definition
promotionmodel.cpp:98
qdesigner_internal::PromotionModel::PromotionModel
PromotionModel(QDesignerFormEditorInterface *core)
Definition
promotionmodel.cpp:83
qdesigner_internal::PromotionModel::modelData
ModelData modelData(const QModelIndex &index) const
Definition
promotionmodel.cpp:159
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QT_BEGIN_NAMESPACE::ClassNameColumn
@ ClassNameColumn
Definition
promotionmodel.cpp:21
QT_BEGIN_NAMESPACE::NumColumns
@ NumColumns
Definition
promotionmodel.cpp:21
QT_BEGIN_NAMESPACE::IncludeTypeColumn
@ IncludeTypeColumn
Definition
promotionmodel.cpp:21
QT_BEGIN_NAMESPACE::IncludeFileColumn
@ IncludeFileColumn
Definition
promotionmodel.cpp:21
QT_BEGIN_NAMESPACE::ReferencedColumn
@ ReferencedColumn
Definition
promotionmodel.cpp:21
QT_BEGIN_NAMESPACE::baseModelRow
StandardItemList baseModelRow(const QDesignerWidgetDataBaseItemInterface *dbItem)
Definition
promotionmodel.cpp:33
QT_BEGIN_NAMESPACE::promotedModelRow
StandardItemList promotedModelRow(QDesignerWidgetDataBaseItemInterface *baseItem, QDesignerWidgetDataBaseItemInterface *dbItem, bool referenced)
Definition
promotionmodel.cpp:44
QT_BEGIN_NAMESPACE::modelRow
StandardItemList modelRow()
Definition
promotionmodel.cpp:24
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
qttools
src
designer
src
lib
shared
promotionmodel.cpp
Generated on
for Qt by
1.18.0