Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
metadatabase.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
7
8// sdk
9#include <QtDesigner/abstractformeditor.h>
10
11// Qt
12#include <QtWidgets/qwidget.h>
13#include <QtCore/qalgorithms.h>
14#include <QtCore/qdebug.h>
15
17
18namespace {
19 const bool debugMetaDatabase = false;
20}
21
22namespace qdesigner_internal {
23
29
31
33{
35 return m_object->objectName();
36}
37
43
52
53
55{
56 return m_tabOrder;
57}
58
63
65{
66 return m_enabled;
67}
68
70{
71 m_enabled = b;
72}
73
78
83
88
93
94// -----------------------------------------------------
100
105
107{
109 if (i == nullptr || !i->enabled())
110 return nullptr;
111 return i;
112}
113
115{
117 if (item != nullptr) {
118 item->setEnabled(true);
119 if (debugMetaDatabase) {
120 qDebug() << "MetaDataBase::add: Existing item for " << object->metaObject()->className() << item->name();
121 }
122 return;
123 }
124
127 if (debugMetaDatabase) {
128 qDebug() << "MetaDataBase::add: New item " << object->metaObject()->className() << item->name();
129 }
131
132 emit changed();
133}
134
136{
138
140 item->setEnabled(false);
141 emit changed();
142 }
143}
144
146{
148
149 for (auto it = m_items.cbegin(), cend = m_items.cend(); it != cend; ++it) {
150 if (it.value()->enabled())
151 result.append(it.key());
152 }
153
154 return result;
155}
156
158{
159 return m_core;
160}
161
163{
164 if (m_items.contains(object)) {
166 delete item;
168 }
169}
170
171// promotion convenience
172QDESIGNER_SHARED_EXPORT bool promoteWidget(QDesignerFormEditorInterface *core,QWidget *widget,const QString &customClassName)
173{
174
175 MetaDataBase *db = qobject_cast<MetaDataBase *>(core->metaDataBase());
176 if (!db)
177 return false;
178 MetaDataBaseItem *item = db->metaDataBaseItem(widget);
179 if (!item) {
180 db ->add(widget);
181 item = db->metaDataBaseItem(widget);
182 }
183 // Recursive promotion occurs if there is a plugin missing.
184 const QString oldCustomClassName = item->customClassName();
185 if (!oldCustomClassName.isEmpty()) {
186 qDebug() << "WARNING: Recursive promotion of " << oldCustomClassName << " to " << customClassName
187 << ". A plugin is missing.";
188 }
189 item->setCustomClassName(customClassName);
190 if (debugMetaDatabase) {
191 qDebug() << "Promoting " << widget->metaObject()->className() << " to " << customClassName;
192 }
193 return true;
194}
195
196QDESIGNER_SHARED_EXPORT void demoteWidget(QDesignerFormEditorInterface *core,QWidget *widget)
197{
198 MetaDataBase *db = qobject_cast<MetaDataBase *>(core->metaDataBase());
199 if (!db)
200 return;
201 MetaDataBaseItem *item = db->metaDataBaseItem(widget);
202 item->setCustomClassName(QString());
203 if (debugMetaDatabase) {
204 qDebug() << "Demoting " << widget;
205 }
206}
207
208QDESIGNER_SHARED_EXPORT bool isPromoted(QDesignerFormEditorInterface *core, QWidget* widget)
209{
210 const MetaDataBase *db = qobject_cast<const MetaDataBase *>(core->metaDataBase());
211 if (!db)
212 return false;
213 const MetaDataBaseItem *item = db->metaDataBaseItem(widget);
214 if (!item)
215 return false;
216 return !item->customClassName().isEmpty();
217}
218
229
240
241
242} // namespace qdesigner_internal
243
244QT_END_NAMESPACE
Combined button and popup list for selecting options.
const bool debugMetaDatabase
Auxiliary methods to store/retrieve settings.
#define QDESIGNER_SHARED_EXPORT