aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/labs/stylekit/qqstylekitcontrolproperties.cpp50
-rw-r--r--src/labs/stylekit/qqstylekitcontrolproperties_p.h3
-rw-r--r--src/labs/stylekit/qqstylekitdebug.cpp37
-rw-r--r--src/labs/stylekit/qqstylekitglobal_p.h1
4 files changed, 58 insertions, 33 deletions
diff --git a/src/labs/stylekit/qqstylekitcontrolproperties.cpp b/src/labs/stylekit/qqstylekitcontrolproperties.cpp
index d44bf6050d..d35935860f 100644
--- a/src/labs/stylekit/qqstylekitcontrolproperties.cpp
+++ b/src/labs/stylekit/qqstylekitcontrolproperties.cpp
@@ -11,6 +11,8 @@ QT_BEGIN_NAMESPACE
// ************* QQStyleKitPropertyGroup ****************
+QHash<PropertyPathId_t, QString> QQStyleKitPropertyGroup::s_pathStrings;
+
QQStyleKitPropertyGroup::QQStyleKitPropertyGroup(QQSK::PropertyGroup, QObject *parent)
: QObject(parent)
{
@@ -27,6 +29,51 @@ PropertyPathId QQStyleKitPropertyGroup::propertyPathId(QQSK::Property property,
return PropertyPathId(property, m_groupSpace.start, QQSK::PropertyGroup::DelegateSubtype0);
}
+QString QQStyleKitPropertyGroup::pathToString() const
+{
+ /* Start from the root of the path and build the path down to this group. This
+ * mirrors how the groups were originally created and avoids rounding issues
+ * that can arise if attempting to reconstruct the path “backwards”.
+ * Note: For each group, m_groupSpace.start is stored relative to the root,
+ * while m_groupSpace.size is relative to the parent group. However, when
+ * calculating the group index, the group-space start must be computed
+ * relative to the parent group.
+ * We cache the requested paths, as the same paths are typically requested
+ * repeatedly. The number of possible paths (and thus leaf groups) is well below
+ * 100, and in practice the cache usually ends up with fewer than 20 entries. */
+ if (s_pathStrings.contains(m_groupSpace.start))
+ return s_pathStrings[m_groupSpace.start];
+
+ constexpr PropertyPathId_t rootGroupsSize = nestedGroupsStartSize / nestedGroupCount;
+ const auto metaEnum = QMetaEnum::fromType<QQSK::PropertyGroup>();
+
+ PropertyPathId_t nestedGroupStart = m_groupSpace.start;
+ PropertyPathId_t nestedGroupSize = rootGroupsSize;
+ PropertyPathId_t nestedGroupIndex = nestedGroupStart / nestedGroupSize;
+ auto groupType = QQSK::PropertyGroup(nestedGroupIndex);
+ if (groupType == QQSK::PropertyGroup::Control)
+ return {};
+
+ QString groupName = QString::fromLatin1(metaEnum.valueToKey(static_cast<int>(groupType)));
+ groupName[0] = groupName[0].toLower();
+ QString pathString = groupName;
+
+ while (true) {
+ nestedGroupStart -= nestedGroupIndex * nestedGroupSize;
+ nestedGroupSize /= nestedGroupCount;
+ nestedGroupIndex = nestedGroupStart / nestedGroupSize;
+ groupType = QQSK::PropertyGroup(nestedGroupIndex);
+ if (groupType == QQSK::PropertyGroup::Control)
+ break;
+
+ QString groupName = QString::fromLatin1(metaEnum.valueToKey(static_cast<int>(groupType)));
+ groupName[0] = groupName[0].toLower();
+ pathString += '.'_L1 + groupName;
+ }
+
+ return pathString;
+}
+
QQStyleKitControlProperties *QQStyleKitPropertyGroup::controlProperties() const
{
if (isControlProperties()) {
@@ -63,9 +110,8 @@ T *QQStyleKitPropertyGroup::lazyCreateGroup(T * const &ptr, QQSK::PropertyGroup
/* Calculate the available property ID space for the nested group. This is done by
* dividing the available space inside _this_ group on the number of potential groups
* that _this_ group can potentially contain. */
- constexpr PropertyPathId_t groupCount = PropertyPathId_t(QQSK::PropertyGroup::PATH_ID_GROUP_COUNT);
const PropertyPathId_t nestedGroupIndex = PropertyPathId_t(group);
- const PropertyPathId_t nestedGroupSize = m_groupSpace.size / groupCount;
+ const PropertyPathId_t nestedGroupSize = m_groupSpace.size / nestedGroupCount;
nestedGroup->m_groupSpace.size = nestedGroupSize;
nestedGroup->m_groupSpace.start = m_groupSpace.start + (nestedGroupIndex * nestedGroupSize);
/* Ensure that we haven’t exhausted the available PropertyPathId space. There must be
diff --git a/src/labs/stylekit/qqstylekitcontrolproperties_p.h b/src/labs/stylekit/qqstylekitcontrolproperties_p.h
index f2c7f35216..fb6df9fb81 100644
--- a/src/labs/stylekit/qqstylekitcontrolproperties_p.h
+++ b/src/labs/stylekit/qqstylekitcontrolproperties_p.h
@@ -45,6 +45,7 @@ public:
QQStyleKitPropertyGroup(QQSK::PropertyGroup group, QObject *parent);
PropertyPathId propertyPathId(QQSK::Property property, PropertyPathId::Flag flag) const;
+ QString pathToString() const;
template<typename T>
inline T styleProperty(
@@ -101,6 +102,8 @@ protected:
private:
bool shouldEmitLocally();
bool shouldEmitGlobally();
+
+ static QHash<PropertyPathId_t, QString> s_pathStrings;
};
// ************* QQStyleKitImageProperties ****************
diff --git a/src/labs/stylekit/qqstylekitdebug.cpp b/src/labs/stylekit/qqstylekitdebug.cpp
index dcd191959d..4f6cd78b61 100644
--- a/src/labs/stylekit/qqstylekitdebug.cpp
+++ b/src/labs/stylekit/qqstylekitdebug.cpp
@@ -52,37 +52,12 @@ QString QQStyleKitDebug::styleReaderToString(const QQStyleKitReader *reader)
QString QQStyleKitDebug::propertyPath(const QQStyleKitPropertyGroup *group, const PropertyPathId property)
{
- QString path = enumToString(property.property());
- path[0] = path[0].toLower();
- const QQStyleKitPropertyGroup *childGroup = group;
- const int startIndex = QQStyleKitPropertyGroup::staticMetaObject.propertyOffset();
-
- while (childGroup) {
- if (childGroup->isControlProperties())
- break;
- const QQStyleKitPropertyGroup *parentGroup =
- qobject_cast<const QQStyleKitPropertyGroup *>(childGroup->parent());
- if (!parentGroup)
- break;
-
- // Resolve group name by inspecting which property in the parent group it belongs to
- const QMetaObject* parentMeta = parentGroup->metaObject();
- for (int i = startIndex; i < parentMeta->propertyCount(); ++i) {
- const QMetaProperty prop = parentMeta->property(i);
- const QMetaObject* typeMeta = QMetaType::fromName(prop.typeName()).metaObject();
- if (!typeMeta || !typeMeta->inherits(&QQStyleKitPropertyGroup::staticMetaObject))
- continue;
- QObject *propGroup = prop.read(parentGroup).value<QQStyleKitPropertyGroup *>();
- if (propGroup == childGroup) {
- path.prepend(QString::fromUtf8(prop.name()) + kDot);
- break;
- }
- }
-
- childGroup = parentGroup;
- }
-
- return path;
+ const QString path = group->pathToString();
+ QString propertyName = enumToString(property.property());
+ propertyName[0] = propertyName[0].toLower();
+ if (path.isEmpty())
+ return propertyName;
+ return path + kDot + propertyName;
}
QString QQStyleKitDebug::controlToString(const QQStyleKitControlProperties *control)
diff --git a/src/labs/stylekit/qqstylekitglobal_p.h b/src/labs/stylekit/qqstylekitglobal_p.h
index 3808def107..e4d6a151dc 100644
--- a/src/labs/stylekit/qqstylekitglobal_p.h
+++ b/src/labs/stylekit/qqstylekitglobal_p.h
@@ -171,6 +171,7 @@ using QQStyleKitExtendableControlType = quint32;
using QQStyleKitPropertyStorage = QHash<PropertyStorageId, QVariant>;
constexpr PropertyPathId_t maxPropertyStorageSpaceSize = std::numeric_limits<PropertyPathId_t>::max();
+constexpr PropertyPathId_t nestedGroupCount = PropertyPathId_t(QQSK::PropertyGroup::PATH_ID_GROUP_COUNT);
constexpr PropertyPathId_t maxStateCombinationCount = PropertyPathId_t(QQSK::StateFlag::MAX_STATE);
constexpr PropertyPathId_t stateStorageSpaceSize = maxPropertyStorageSpaceSize / maxStateCombinationCount;
constexpr PropertyPathId_t subtypeCount = PropertyPathId_t(QQSK::PropertyPathFlag::DelegateSubtype2) - PropertyPathId_t(QQSK::PropertyPathFlag::DelegateSubtype0) + 1;