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
6
7// sdk
8#include <QtDesigner/abstractformeditor.h>
9
10// Qt
11#include <QtWidgets/qwidget.h>
12#include <QtCore/qalgorithms.h>
13#include <QtCore/qdebug.h>
14
16
17namespace {
18 const bool debugMetaDatabase = false;
19}
20
21namespace qdesigner_internal {
22
28
30
32{
34 return m_object->objectName();
35}
36
42
51
52
54{
55 return m_tabOrder;
56}
57
62
64{
65 return m_enabled;
66}
67
69{
70 m_enabled = b;
71}
72
77
82
87
92
93// -----------------------------------------------------
99
104
106{
108 if (i == nullptr || !i->enabled())
109 return nullptr;
110 return i;
111}
112
114{
116 if (item != nullptr) {
117 item->setEnabled(true);
118 if (debugMetaDatabase) {
119 qDebug() << "MetaDataBase::add: Existing item for " << object->metaObject()->className() << item->name();
120 }
121 return;
122 }
123
126 if (debugMetaDatabase) {
127 qDebug() << "MetaDataBase::add: New item " << object->metaObject()->className() << item->name();
128 }
130
131 emit changed();
132}
133
135{
137
139 item->setEnabled(false);
140 emit changed();
141 }
142}
143
145{
147
148 for (auto it = m_items.cbegin(), cend = m_items.cend(); it != cend; ++it) {
149 if (it.value()->enabled())
150 result.append(it.key());
151 }
152
153 return result;
154}
155
157{
158 return m_core;
159}
160
162{
163 if (m_items.contains(object)) {
165 delete item;
167 }
168}
169
170// promotion convenience
171QDESIGNER_SHARED_EXPORT bool promoteWidget(QDesignerFormEditorInterface *core,QWidget *widget,const QString &customClassName)
172{
173
174 MetaDataBase *db = qobject_cast<MetaDataBase *>(core->metaDataBase());
175 if (!db)
176 return false;
177 MetaDataBaseItem *item = db->metaDataBaseItem(widget);
178 if (!item) {
179 db ->add(widget);
180 item = db->metaDataBaseItem(widget);
181 }
182 // Recursive promotion occurs if there is a plugin missing.
183 const QString oldCustomClassName = item->customClassName();
184 if (!oldCustomClassName.isEmpty()) {
185 qDebug() << "WARNING: Recursive promotion of " << oldCustomClassName << " to " << customClassName
186 << ". A plugin is missing.";
187 }
188 item->setCustomClassName(customClassName);
189 if (debugMetaDatabase) {
190 qDebug() << "Promoting " << widget->metaObject()->className() << " to " << customClassName;
191 }
192 return true;
193}
194
195QDESIGNER_SHARED_EXPORT void demoteWidget(QDesignerFormEditorInterface *core,QWidget *widget)
196{
197 MetaDataBase *db = qobject_cast<MetaDataBase *>(core->metaDataBase());
198 if (!db)
199 return;
200 MetaDataBaseItem *item = db->metaDataBaseItem(widget);
201 item->setCustomClassName(QString());
202 if (debugMetaDatabase) {
203 qDebug() << "Demoting " << widget;
204 }
205}
206
207QDESIGNER_SHARED_EXPORT bool isPromoted(QDesignerFormEditorInterface *core, QWidget* widget)
208{
209 const MetaDataBase *db = qobject_cast<const MetaDataBase *>(core->metaDataBase());
210 if (!db)
211 return false;
212 const MetaDataBaseItem *item = db->metaDataBaseItem(widget);
213 if (!item)
214 return false;
215 return !item->customClassName().isEmpty();
216}
217
228
239
240
241} // namespace qdesigner_internal
242
243QT_END_NAMESPACE
Combined button and popup list for selecting options.
const bool debugMetaDatabase
Auxiliary methods to store/retrieve settings.
#define QDESIGNER_SHARED_EXPORT