summaryrefslogtreecommitdiffstats
path: root/src/designer/src/lib/shared/qdesigner_propertysheet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/designer/src/lib/shared/qdesigner_propertysheet.cpp')
-rw-r--r--src/designer/src/lib/shared/qdesigner_propertysheet.cpp312
1 files changed, 139 insertions, 173 deletions
diff --git a/src/designer/src/lib/shared/qdesigner_propertysheet.cpp b/src/designer/src/lib/shared/qdesigner_propertysheet.cpp
index 209582b1e..573cfed4a 100644
--- a/src/designer/src/lib/shared/qdesigner_propertysheet.cpp
+++ b/src/designer/src/lib/shared/qdesigner_propertysheet.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Designer of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qdesigner_propertysheet_p.h"
#include "qdesigner_utils_p.h"
@@ -56,9 +31,12 @@
#include <QtGui/qaction.h>
#include <QtCore/qdebug.h>
+#include <QtCore/qhash.h>
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
#define USE_LAYOUT_SIZE_CONSTRAINT
static const QDesignerMetaObjectInterface *propertyIntroducedBy(const QDesignerMetaObjectInterface *meta, int index)
@@ -81,40 +59,26 @@ static const QDesignerMetaObjectInterface *propertyIntroducedBy(const QDesignerM
// old forms, QLayoutWidget will show up as ''; however, the uic code will
// still use 'verticalLayout' (in case someone accesses it). New Layouts get autogenerated names,
// legacy forms will keep their empty names (unless someone types in a new name).
-static const char *layoutObjectNameC = "layoutName";
-static const char *layoutLeftMarginC = "layoutLeftMargin";
-static const char *layoutTopMarginC = "layoutTopMargin";
-static const char *layoutRightMarginC = "layoutRightMargin";
-static const char *layoutBottomMarginC = "layoutBottomMargin";
-static const char *layoutSpacingC = "layoutSpacing";
-static const char *layoutHorizontalSpacingC = "layoutHorizontalSpacing";
-static const char *layoutVerticalSpacingC = "layoutVerticalSpacing";
-static const char *layoutSizeConstraintC = "layoutSizeConstraint";
+static constexpr auto layoutObjectNameC = "layoutName"_L1;
+static constexpr auto layoutLeftMarginC = "layoutLeftMargin"_L1;
+static constexpr auto layoutTopMarginC = "layoutTopMargin"_L1;
+static constexpr auto layoutRightMarginC = "layoutRightMargin"_L1;
+static constexpr auto layoutBottomMarginC = "layoutBottomMargin"_L1;
+static constexpr auto layoutSpacingC = "layoutSpacing"_L1;
+static constexpr auto layoutHorizontalSpacingC = "layoutHorizontalSpacing"_L1;
+static constexpr auto layoutVerticalSpacingC = "layoutVerticalSpacing"_L1;
+static constexpr auto layoutSizeConstraintC = "layoutSizeConstraint"_L1;
// form layout
-static const char *layoutFieldGrowthPolicyC = "layoutFieldGrowthPolicy";
-static const char *layoutRowWrapPolicyC = "layoutRowWrapPolicy";
-static const char *layoutLabelAlignmentC = "layoutLabelAlignment";
-static const char *layoutFormAlignmentC = "layoutFormAlignment";
+static constexpr auto layoutFieldGrowthPolicyC = "layoutFieldGrowthPolicy"_L1;
+static constexpr auto layoutRowWrapPolicyC = "layoutRowWrapPolicy"_L1;
+static constexpr auto layoutLabelAlignmentC = "layoutLabelAlignment"_L1;
+static constexpr auto layoutFormAlignmentC = "layoutFormAlignment"_L1;
// stretches
-static const char *layoutboxStretchPropertyC = "layoutStretch";
-static const char *layoutGridRowStretchPropertyC = "layoutRowStretch";
-static const char *layoutGridColumnStretchPropertyC = "layoutColumnStretch";
-static const char *layoutGridRowMinimumHeightC = "layoutRowMinimumHeight";
-static const char *layoutGridColumnMinimumWidthC = "layoutColumnMinimumWidth";
-
-// Find the form editor in the hierarchy.
-// We know that the parent of the sheet is the extension manager
-// whose parent is the core.
-
-static QDesignerFormEditorInterface *formEditorForObject(QObject *o) {
- do {
- if (QDesignerFormEditorInterface* core = qobject_cast<QDesignerFormEditorInterface*>(o))
- return core;
- o = o->parent();
- } while(o);
- Q_ASSERT(o);
- return nullptr;
-}
+static constexpr auto layoutboxStretchPropertyC = "layoutStretch"_L1;
+static constexpr auto layoutGridRowStretchPropertyC = "layoutRowStretch"_L1;
+static constexpr auto layoutGridColumnStretchPropertyC = "layoutColumnStretch"_L1;
+static constexpr auto layoutGridRowMinimumHeightC = "layoutRowMinimumHeight"_L1;
+static constexpr auto layoutGridColumnMinimumWidthC = "layoutColumnMinimumWidth"_L1;
static bool hasLayoutAttributes(QDesignerFormEditorInterface *core, QObject *object)
{
@@ -132,15 +96,14 @@ static bool hasLayoutAttributes(QDesignerFormEditorInterface *core, QObject *obj
// Cache DesignerMetaEnum by scope/name of a QMetaEnum
static const qdesigner_internal::DesignerMetaEnum &designerMetaEnumFor(const QDesignerMetaEnumInterface *me)
{
- using ScopeNameKey = QPair<QString, QString>;
- using DesignerMetaEnumCache = QMap<ScopeNameKey, qdesigner_internal::DesignerMetaEnum>;
- static DesignerMetaEnumCache cache;
+ using ScopeNameKey = std::pair<QString, QString>;
+ static QMap<ScopeNameKey, qdesigner_internal::DesignerMetaEnum> cache;
const QString name = me->name();
const QString scope = me->scope();
const ScopeNameKey key = ScopeNameKey(scope, name);
- DesignerMetaEnumCache::iterator it = cache.find(key);
+ auto it = cache.find(key);
if (it == cache.end()) {
qdesigner_internal::DesignerMetaEnum dme = qdesigner_internal::DesignerMetaEnum(name, scope, me->separator());
const int keyCount = me->keyCount();
@@ -154,17 +117,16 @@ static const qdesigner_internal::DesignerMetaEnum &designerMetaEnumFor(const QDe
// Cache DesignerMetaFlags by scope/name of a QMetaEnum
static const qdesigner_internal::DesignerMetaFlags &designerMetaFlagsFor(const QDesignerMetaEnumInterface *me)
{
- using ScopeNameKey = QPair<QString, QString>;
- using DesignerMetaFlagsCache = QMap<ScopeNameKey, qdesigner_internal::DesignerMetaFlags>;
- static DesignerMetaFlagsCache cache;
+ using ScopeNameKey = std::pair<QString, QString>;
+ static QMap<ScopeNameKey, qdesigner_internal::DesignerMetaFlags> cache;
const QString name = me->name();
const QString scope = me->scope();
const ScopeNameKey key = ScopeNameKey(scope, name);
- DesignerMetaFlagsCache::iterator it = cache.find(key);
+ auto it = cache.find(key);
if (it == cache.end()) {
- qdesigner_internal::DesignerMetaFlags dme = qdesigner_internal::DesignerMetaFlags(name, scope, me->separator());
+ auto dme = qdesigner_internal::DesignerMetaFlags(me->enumName(), scope, me->separator());
const int keyCount = me->keyCount();
for (int i=0; i < keyCount; ++i)
dme.addKey(me->value(i), me->key(i));
@@ -183,7 +145,7 @@ public:
explicit QDesignerPropertySheetPrivate(QDesignerPropertySheet *sheetPublic, QObject *object, QObject *sheetParent);
bool invalidIndex(const char *functionName, int index) const;
- inline int count() const { return m_meta->propertyCount() + m_addProperties.count(); }
+ inline int count() const { return m_meta->propertyCount() + m_addProperties.size(); }
PropertyType propertyType(int index) const;
QString transformLayoutPropertyName(int index) const;
@@ -235,8 +197,7 @@ public:
const ObjectType m_objectType;
const ObjectFlags m_objectFlags;
- using InfoHash = QHash<int, Info>;
- InfoHash m_info;
+ QHash<int, Info> m_info;
QHash<int, QVariant> m_fakeProperties;
QHash<int, QVariant> m_addProperties;
QHash<QString, int> m_addIndex;
@@ -392,7 +353,7 @@ void QDesignerPropertySheetPrivate::setKeySequenceProperty(int index, const qdes
QDesignerPropertySheetPrivate::QDesignerPropertySheetPrivate(QDesignerPropertySheet *sheetPublic, QObject *object, QObject *sheetParent) :
q(sheetPublic),
- m_core(formEditorForObject(sheetParent)),
+ m_core(QDesignerPropertySheet::formEditorForObject(sheetParent)),
m_meta(m_core->introspection()->metaObject(object)),
m_objectType(QDesignerPropertySheet::objectTypeFromObject(object)),
m_objectFlags(QDesignerPropertySheet::objectFlagsFromObject(object)),
@@ -460,7 +421,7 @@ QLayout* QDesignerPropertySheetPrivate::layout(QDesignerPropertySheetExtension *
QDesignerPropertySheetPrivate::Info &QDesignerPropertySheetPrivate::ensureInfo(int index)
{
- InfoHash::iterator it = m_info.find(index);
+ auto it = m_info.find(index);
if (it == m_info.end())
it = m_info.insert(index, Info());
return it.value();
@@ -468,7 +429,7 @@ QDesignerPropertySheetPrivate::Info &QDesignerPropertySheetPrivate::ensureInfo(i
QDesignerPropertySheet::PropertyType QDesignerPropertySheetPrivate::propertyType(int index) const
{
- const InfoHash::const_iterator it = m_info.constFind(index);
+ const auto it = m_info.constFind(index);
if (it == m_info.constEnd())
return QDesignerPropertySheet::PropertyNone;
return it.value().propertyType;
@@ -477,28 +438,27 @@ QDesignerPropertySheet::PropertyType QDesignerPropertySheetPrivate::propertyType
QString QDesignerPropertySheetPrivate::transformLayoutPropertyName(int index) const
{
using TypeNameMap = QMap<QDesignerPropertySheet::PropertyType, QString>;
- static TypeNameMap typeNameMap;
- if (typeNameMap.isEmpty()) {
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutObjectName, QStringLiteral("objectName"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutLeftMargin, QStringLiteral("leftMargin"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutTopMargin, QStringLiteral("topMargin"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutRightMargin, QStringLiteral("rightMargin"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutBottomMargin, QStringLiteral("bottomMargin"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutSpacing, QStringLiteral("spacing"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutHorizontalSpacing, QStringLiteral("horizontalSpacing"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutVerticalSpacing, QStringLiteral("verticalSpacing"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutSizeConstraint, QStringLiteral("sizeConstraint"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutFieldGrowthPolicy, QStringLiteral("fieldGrowthPolicy"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutRowWrapPolicy, QStringLiteral("rowWrapPolicy"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutLabelAlignment, QStringLiteral("labelAlignment"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutFormAlignment, QStringLiteral("formAlignment"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutBoxStretch, QStringLiteral("stretch"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridRowStretch, QStringLiteral("rowStretch"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridColumnStretch, QStringLiteral("columnStretch"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridRowMinimumHeight, QStringLiteral("rowMinimumHeight"));
- typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridColumnMinimumWidth, QStringLiteral("columnMinimumWidth"));
- }
- const TypeNameMap::const_iterator it = typeNameMap.constFind(propertyType(index));
+ static const TypeNameMap typeNameMap = {
+ {QDesignerPropertySheet::PropertyLayoutObjectName, u"objectName"_s},
+ {QDesignerPropertySheet::PropertyLayoutLeftMargin, u"leftMargin"_s},
+ {QDesignerPropertySheet::PropertyLayoutTopMargin, u"topMargin"_s},
+ {QDesignerPropertySheet::PropertyLayoutRightMargin, u"rightMargin"_s},
+ {QDesignerPropertySheet::PropertyLayoutBottomMargin, u"bottomMargin"_s},
+ {QDesignerPropertySheet::PropertyLayoutSpacing, u"spacing"_s},
+ {QDesignerPropertySheet::PropertyLayoutHorizontalSpacing, u"horizontalSpacing"_s},
+ {QDesignerPropertySheet::PropertyLayoutVerticalSpacing, u"verticalSpacing"_s},
+ {QDesignerPropertySheet::PropertyLayoutSizeConstraint, u"sizeConstraint"_s},
+ {QDesignerPropertySheet::PropertyLayoutFieldGrowthPolicy, u"fieldGrowthPolicy"_s},
+ {QDesignerPropertySheet::PropertyLayoutRowWrapPolicy, u"rowWrapPolicy"_s},
+ {QDesignerPropertySheet::PropertyLayoutLabelAlignment, u"labelAlignment"_s},
+ {QDesignerPropertySheet::PropertyLayoutFormAlignment, u"formAlignment"_s},
+ {QDesignerPropertySheet::PropertyLayoutBoxStretch, u"stretch"_s},
+ {QDesignerPropertySheet::PropertyLayoutGridRowStretch, u"rowStretch"_s},
+ {QDesignerPropertySheet::PropertyLayoutGridColumnStretch, u"columnStretch"_s},
+ {QDesignerPropertySheet::PropertyLayoutGridRowMinimumHeight, u"rowMinimumHeight"_s},
+ {QDesignerPropertySheet::PropertyLayoutGridColumnMinimumWidth, u"columnMinimumWidth"_s}
+ };
+ const auto it = typeNameMap.constFind(propertyType(index));
if (it != typeNameMap.constEnd())
return it.value();
return QString();
@@ -536,44 +496,42 @@ QDesignerPropertySheet::ObjectFlags QDesignerPropertySheet::objectFlagsFromObjec
QDesignerPropertySheet::PropertyType QDesignerPropertySheet::propertyTypeFromName(const QString &name)
{
- typedef QHash<QString, PropertyType> PropertyTypeHash;
- static PropertyTypeHash propertyTypeHash;
- if (propertyTypeHash.isEmpty()) {
- propertyTypeHash.insert(QLatin1String(layoutObjectNameC), PropertyLayoutObjectName);
- propertyTypeHash.insert(QLatin1String(layoutLeftMarginC), PropertyLayoutLeftMargin);
- propertyTypeHash.insert(QLatin1String(layoutTopMarginC), PropertyLayoutTopMargin);
- propertyTypeHash.insert(QLatin1String(layoutRightMarginC), PropertyLayoutRightMargin);
- propertyTypeHash.insert(QLatin1String(layoutBottomMarginC), PropertyLayoutBottomMargin);
- propertyTypeHash.insert(QLatin1String(layoutSpacingC), PropertyLayoutSpacing);
- propertyTypeHash.insert(QLatin1String(layoutHorizontalSpacingC), PropertyLayoutHorizontalSpacing);
- propertyTypeHash.insert(QLatin1String(layoutVerticalSpacingC), PropertyLayoutVerticalSpacing);
- propertyTypeHash.insert(QLatin1String(layoutSizeConstraintC), PropertyLayoutSizeConstraint);
- propertyTypeHash.insert(QLatin1String(layoutFieldGrowthPolicyC), PropertyLayoutFieldGrowthPolicy);
- propertyTypeHash.insert(QLatin1String(layoutRowWrapPolicyC), PropertyLayoutRowWrapPolicy);
- propertyTypeHash.insert(QLatin1String(layoutLabelAlignmentC), PropertyLayoutLabelAlignment);
- propertyTypeHash.insert(QLatin1String(layoutFormAlignmentC), PropertyLayoutFormAlignment);
- propertyTypeHash.insert(QLatin1String(layoutboxStretchPropertyC), PropertyLayoutBoxStretch);
- propertyTypeHash.insert(QLatin1String(layoutGridRowStretchPropertyC), PropertyLayoutGridRowStretch);
- propertyTypeHash.insert(QLatin1String(layoutGridColumnStretchPropertyC), PropertyLayoutGridColumnStretch);
- propertyTypeHash.insert(QLatin1String(layoutGridRowMinimumHeightC), PropertyLayoutGridRowMinimumHeight);
- propertyTypeHash.insert(QLatin1String(layoutGridColumnMinimumWidthC), PropertyLayoutGridColumnMinimumWidth);
- propertyTypeHash.insert(QStringLiteral("buddy"), PropertyBuddy);
- propertyTypeHash.insert(QStringLiteral("geometry"), PropertyGeometry);
- propertyTypeHash.insert(QStringLiteral("checked"), PropertyChecked);
- propertyTypeHash.insert(QStringLiteral("checkable"), PropertyCheckable);
- propertyTypeHash.insert(QStringLiteral("accessibleName"), PropertyAccessibility);
- propertyTypeHash.insert(QStringLiteral("accessibleDescription"), PropertyAccessibility);
- propertyTypeHash.insert(QStringLiteral("visible"), PropertyVisible);
- propertyTypeHash.insert(QStringLiteral("windowTitle"), PropertyWindowTitle);
- propertyTypeHash.insert(QStringLiteral("windowIcon"), PropertyWindowIcon);
- propertyTypeHash.insert(QStringLiteral("windowFilePath"), PropertyWindowFilePath);
- propertyTypeHash.insert(QStringLiteral("windowOpacity"), PropertyWindowOpacity);
- propertyTypeHash.insert(QStringLiteral("windowIconText"), PropertyWindowIconText);
- propertyTypeHash.insert(QStringLiteral("windowModality"), PropertyWindowModality);
- propertyTypeHash.insert(QStringLiteral("windowModified"), PropertyWindowModified);
- propertyTypeHash.insert(QStringLiteral("styleSheet"), PropertyStyleSheet);
- propertyTypeHash.insert(QStringLiteral("text"), PropertyText);
- }
+ static const QHash<QString, PropertyType> propertyTypeHash = {
+ {layoutObjectNameC, PropertyLayoutObjectName},
+ {layoutLeftMarginC, PropertyLayoutLeftMargin},
+ {layoutTopMarginC, PropertyLayoutTopMargin},
+ {layoutRightMarginC, PropertyLayoutRightMargin},
+ {layoutBottomMarginC, PropertyLayoutBottomMargin},
+ {layoutSpacingC, PropertyLayoutSpacing},
+ {layoutHorizontalSpacingC, PropertyLayoutHorizontalSpacing},
+ {layoutVerticalSpacingC, PropertyLayoutVerticalSpacing},
+ {layoutSizeConstraintC, PropertyLayoutSizeConstraint},
+ {layoutFieldGrowthPolicyC, PropertyLayoutFieldGrowthPolicy},
+ {layoutRowWrapPolicyC, PropertyLayoutRowWrapPolicy},
+ {layoutLabelAlignmentC, PropertyLayoutLabelAlignment},
+ {layoutFormAlignmentC, PropertyLayoutFormAlignment},
+ {layoutboxStretchPropertyC, PropertyLayoutBoxStretch},
+ {layoutGridRowStretchPropertyC, PropertyLayoutGridRowStretch},
+ {layoutGridColumnStretchPropertyC, PropertyLayoutGridColumnStretch},
+ {layoutGridRowMinimumHeightC, PropertyLayoutGridRowMinimumHeight},
+ {layoutGridColumnMinimumWidthC, PropertyLayoutGridColumnMinimumWidth},
+ {u"buddy"_s, PropertyBuddy},
+ {u"geometry"_s, PropertyGeometry},
+ {u"checked"_s, PropertyChecked},
+ {u"checkable"_s, PropertyCheckable},
+ {u"accessibleName"_s, PropertyAccessibility},
+ {u"accessibleDescription"_s, PropertyAccessibility},
+ {u"visible"_s, PropertyVisible},
+ {u"windowTitle"_s, PropertyWindowTitle},
+ {u"windowIcon"_s, PropertyWindowIcon},
+ {u"windowFilePath"_s, PropertyWindowFilePath},
+ {u"windowOpacity"_s, PropertyWindowOpacity},
+ {u"windowIconText"_s, PropertyWindowIconText},
+ {u"windowModality"_s, PropertyWindowModality},
+ {u"windowModified"_s, PropertyWindowModified},
+ {u"styleSheet"_s, PropertyStyleSheet},
+ {u"text"_s, PropertyText}
+ };
return propertyTypeHash.value(name, PropertyNone);
}
@@ -584,7 +542,7 @@ QDesignerPropertySheet::QDesignerPropertySheet(QObject *object, QObject *parent)
using Info = QDesignerPropertySheetPrivate::Info;
const QDesignerMetaObjectInterface *baseMeta = d->m_meta;
- while (baseMeta &&baseMeta->className().startsWith(QStringLiteral("QDesigner"))) {
+ while (baseMeta &&baseMeta->className().startsWith("QDesigner"_L1)) {
baseMeta = baseMeta->superClass();
}
Q_ASSERT(baseMeta != nullptr);
@@ -640,28 +598,28 @@ QDesignerPropertySheet::QDesignerPropertySheet(QObject *object, QObject *parent)
}
if (object->isWidgetType()) {
- createFakeProperty(QStringLiteral("focusPolicy"));
- createFakeProperty(QStringLiteral("cursor"));
- createFakeProperty(QStringLiteral("toolTip"));
- createFakeProperty(QStringLiteral("whatsThis"));
- createFakeProperty(QStringLiteral("acceptDrops"));
- createFakeProperty(QStringLiteral("dragEnabled"));
+ createFakeProperty(u"focusPolicy"_s);
+ createFakeProperty(u"cursor"_s);
+ createFakeProperty(u"toolTip"_s);
+ createFakeProperty(u"whatsThis"_s);
+ createFakeProperty(u"acceptDrops"_s);
+ createFakeProperty(u"dragEnabled"_s);
// windowModality/Opacity is visible only for the main container, in which case the form windows enables it on loading
- setVisible(createFakeProperty(QStringLiteral("windowModality")), false);
- setVisible(createFakeProperty(QStringLiteral("windowOpacity"), double(1.0)), false);
+ setVisible(createFakeProperty(u"windowModality"_s), false);
+ setVisible(createFakeProperty(u"windowOpacity"_s, double(1.0)), false);
if (qobject_cast<const QToolBar *>(d->m_object)) { // prevent toolbars from being dragged off
- createFakeProperty(QStringLiteral("floatable"), QVariant(true));
+ createFakeProperty(u"floatable"_s, QVariant(true));
} else {
if (qobject_cast<const QMenuBar *>(d->m_object)) {
// Keep the menu bar editable in the form even if a native menu bar is used.
const bool nativeMenuBarDefault =
!QCoreApplication::testAttribute(Qt::AA_DontUseNativeMenuBar);
- createFakeProperty(QStringLiteral("nativeMenuBar"), QVariant(nativeMenuBarDefault));
+ createFakeProperty(u"nativeMenuBar"_s, QVariant(nativeMenuBarDefault));
}
}
if (d->m_canHaveLayoutAttributes) {
- static const QString layoutGroup = QStringLiteral("Layout");
- const char* fakeLayoutProperties[] = {
+ const QString layoutGroup = u"Layout"_s;
+ static constexpr QLatin1StringView fakeLayoutProperties[] = {
layoutObjectNameC, layoutLeftMarginC, layoutTopMarginC, layoutRightMarginC, layoutBottomMarginC, layoutSpacingC, layoutHorizontalSpacingC, layoutVerticalSpacingC,
layoutFieldGrowthPolicyC, layoutRowWrapPolicyC, layoutLabelAlignmentC, layoutFormAlignmentC,
layoutboxStretchPropertyC, layoutGridRowStretchPropertyC, layoutGridColumnStretchPropertyC,
@@ -670,42 +628,37 @@ QDesignerPropertySheet::QDesignerPropertySheet(QObject *object, QObject *parent)
, layoutSizeConstraintC
#endif
};
- const int fakeLayoutPropertyCount = sizeof(fakeLayoutProperties)/sizeof(const char*);
+ static constexpr int fakeLayoutPropertyCount = sizeof(fakeLayoutProperties)/sizeof(fakeLayoutProperties[0]);
const int size = count();
for (int i = 0; i < fakeLayoutPropertyCount; i++) {
- createFakeProperty(QLatin1String(fakeLayoutProperties[i]), 0);
+ createFakeProperty(fakeLayoutProperties[i], 0);
setAttribute(size + i, true);
setPropertyGroup(size + i, layoutGroup);
}
}
if (d->m_objectType == ObjectLabel)
- createFakeProperty(QStringLiteral("buddy"), QVariant(QByteArray()));
+ createFakeProperty(u"buddy"_s, QVariant(QByteArray()));
/* We need to create a fake property since the property does not work
* for non-toplevel windows or on other systems than Mac and only if
* it is above a certain Mac OS version. */
if (qobject_cast<const QMainWindow *>(d->m_object))
- createFakeProperty(QStringLiteral("unifiedTitleAndToolBarOnMac"), false);
+ createFakeProperty(u"unifiedTitleAndToolBarOnMac"_s, false);
}
if (qobject_cast<const QDialog*>(object)) {
- createFakeProperty(QStringLiteral("modal"));
+ createFakeProperty(u"modal"_s);
}
if (qobject_cast<const QDockWidget*>(object)) {
- createFakeProperty(QStringLiteral("floating"));
+ createFakeProperty(u"floating"_s);
}
- using ByteArrayList = QList<QByteArray>;
- const ByteArrayList names = object->dynamicPropertyNames();
- if (!names.isEmpty()) {
- const ByteArrayList::const_iterator cend = names.constEnd();
- for (ByteArrayList::const_iterator it = names.constBegin(); it != cend; ++it) {
- const char* cName = it->constData();
- const QString name = QString::fromLatin1(cName);
- const int idx = addDynamicProperty(name, object->property(cName));
- if (idx != -1)
- d->ensureInfo(idx).kind = QDesignerPropertySheetPrivate::DefaultDynamicProperty;
- }
+ const QByteArrayList names = object->dynamicPropertyNames();
+ for (const auto &nameB : names) {
+ const QString name = QString::fromLatin1(nameB);
+ const int idx = addDynamicProperty(name, object->property(nameB.constData()));
+ if (idx != -1)
+ d->ensureInfo(idx).kind = QDesignerPropertySheetPrivate::DefaultDynamicProperty;
}
}
@@ -727,8 +680,7 @@ bool QDesignerPropertySheet::dynamicPropertiesAllowed() const
bool QDesignerPropertySheet::canAddDynamicProperty(const QString &propName) const
{
// used internally
- if (propName == QStringLiteral("database") ||
- propName == QStringLiteral("buttonGroupId"))
+ if (propName == "database"_L1 || propName == "buttonGroupId"_L1)
return false;
const int index = d->m_meta->indexOfProperty(propName);
if (index != -1)
@@ -738,7 +690,7 @@ bool QDesignerPropertySheet::canAddDynamicProperty(const QString &propName) cons
return !isVisible(idx); // dynamic property already exists
}
return QDesignerPropertySheet::internalDynamicPropertiesEnabled()
- || !propName.startsWith(QStringLiteral("_q_"));
+ || !propName.startsWith("_q_"_L1);
}
int QDesignerPropertySheet::addDynamicProperty(const QString &propName, const QVariant &value)
@@ -863,6 +815,7 @@ bool QDesignerPropertySheet::isDynamic(int index) const
case PropertyLayoutGridColumnMinimumWidth:
if (d->m_object->isWidgetType() && d->m_canHaveLayoutAttributes)
return false;
+ break;
default:
break;
}
@@ -1015,7 +968,7 @@ QString QDesignerPropertySheet::propertyGroup(int index) const
return g;
if (propertyType(index) == PropertyAccessibility)
- return QString::fromUtf8("Accessibility");
+ return u"Accessibility"_s;
if (isAdditionalProperty(index))
return d->m_meta->className();
@@ -1255,7 +1208,7 @@ void QDesignerPropertySheet::setProperty(int index, const QVariant &value)
const QDesignerMetaPropertyInterface *p = d->m_meta->property(index);
p->write(d->m_object, resolvePropertyValue(index, value));
if (qobject_cast<QGroupBox *>(d->m_object) && propertyType(index) == PropertyCheckable) {
- const int idx = indexOf(QStringLiteral("focusPolicy"));
+ const int idx = indexOf(u"focusPolicy"_s);
if (!isChanged(idx)) {
qdesigner_internal::PropertySheetEnumValue e = qvariant_cast<qdesigner_internal::PropertySheetEnumValue>(property(idx));
if (value.toBool()) {
@@ -1292,7 +1245,7 @@ bool QDesignerPropertySheet::reset(int index)
if (d->isStringProperty(index)) {
qdesigner_internal::PropertySheetStringValue value;
// Main container: Reset to stored class name as not to change the file names generated by uic.
- if (propertyName(index) == QStringLiteral("objectName")) {
+ if (propertyName(index) == "objectName"_L1) {
const QVariant classNameDefaultV = d->m_object->property("_q_classname");
if (classNameDefaultV.isValid())
value.setValue(classNameDefaultV.toString());
@@ -1495,7 +1448,7 @@ bool QDesignerPropertySheet::isFakeLayoutProperty(int index) const
}
// Visible vs. Enabled: In Qt 5, it was possible to define a boolean function
-// for the DESIGNABLE attribute of Q_PROPERTY. Qt Designer would use that to
+// for the DESIGNABLE attribute of Q_PROPERTY. Qt Widgets Designer would use that to
// determine isEnabled() for the property and return isVisible() = false
// for properties that specified 'false' for DESIGNABLE.
// This was used for example for the "checked" property of QAbstractButton,
@@ -1657,6 +1610,20 @@ void QDesignerPropertySheet::setInternalDynamicPropertiesEnabled(bool v)
QDesignerPropertySheetPrivate::m_internalDynamicPropertiesEnabled = v;
}
+// Find the form editor in the hierarchy.
+// We know that the parent of the sheet is the extension manager
+// whose parent is the core.
+QDesignerFormEditorInterface *QDesignerPropertySheet::formEditorForObject(QObject *o)
+{
+ do {
+ if (auto *core = qobject_cast<QDesignerFormEditorInterface*>(o))
+ return core;
+ o = o->parent();
+ } while (o);
+ Q_ASSERT(o);
+ return nullptr;
+}
+
// ---------- QDesignerAbstractPropertySheetFactory
struct QDesignerAbstractPropertySheetFactory::PropertySheetFactoryPrivate {
@@ -1664,8 +1631,7 @@ struct QDesignerAbstractPropertySheetFactory::PropertySheetFactoryPrivate {
const QString m_propertySheetId;
const QString m_dynamicPropertySheetId;
- using ExtensionMap = QMap<QObject*, QObject*>;
- ExtensionMap m_extensions;
+ QHash<QObject *, QObject *> m_extensions;
};
QDesignerAbstractPropertySheetFactory::PropertySheetFactoryPrivate::PropertySheetFactoryPrivate() :