feat: add QPointF tree-expandable type editor to PropertyEditor
Add PropertyTypeCustomization_PointF that renders QPointF as an expandable tree row: collapsed header shows formatted "(x, y)" text, expanded children provide NumberBox editing for x and y coordinates. Registered in mMetaTypeCustomizationMap alongside the existing QFont customization, reusing the RawType branch of getCustomPropertyType().
This commit is contained in:
parent
fda709c0e2
commit
94c48e7de8
|
|
@ -0,0 +1,71 @@
|
||||||
|
#include "PropertyTypeCustomization_PointF.h"
|
||||||
|
#include "QQuickDetailsViewLayoutBuilder.h"
|
||||||
|
#include "QQuickDetailsViewMananger.h"
|
||||||
|
#include "QPropertyHandle.h"
|
||||||
|
#include <QPointF>
|
||||||
|
#include <QQmlEngine>
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
|
void PropertyTypeCustomization_PointF::customizeHeaderRow(QPropertyHandle* inPropertyHandle, QQuickDetailsViewRowBuilder* inBuilder)
|
||||||
|
{
|
||||||
|
auto slotPair = inBuilder->makeNameValueSlot();
|
||||||
|
|
||||||
|
QQuickItem* nameEditor = inPropertyHandle->setupNameEditor(slotPair.first);
|
||||||
|
|
||||||
|
QQuickItem* valueLabel = inBuilder->setupItem(slotPair.second, R"(
|
||||||
|
import QtQuick;
|
||||||
|
import QtQuick.Controls;
|
||||||
|
import ColorPalette;
|
||||||
|
Item{
|
||||||
|
property string pointText
|
||||||
|
implicitHeight: 25
|
||||||
|
width: parent.width
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
Text {
|
||||||
|
anchors.fill: parent
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
text: pointText
|
||||||
|
color: ColorPalette.theme.textPrimary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)");
|
||||||
|
|
||||||
|
auto updateLabel = [valueLabel](const QVariant& var) {
|
||||||
|
QPointF pt = var.value<QPointF>();
|
||||||
|
valueLabel->setProperty("pointText", QString("(%1, %2)").arg(pt.x(), 0, 'f', 3).arg(pt.y(), 0, 'f', 3));
|
||||||
|
};
|
||||||
|
updateLabel(inPropertyHandle->getVar());
|
||||||
|
|
||||||
|
QObject::connect(inPropertyHandle, &QPropertyHandle::asVarChanged, valueLabel, updateLabel);
|
||||||
|
|
||||||
|
QQmlEngine* engine = qmlEngine(inBuilder->rootItem());
|
||||||
|
QQmlContext* context = qmlContext(inBuilder->rootItem());
|
||||||
|
context->parentContext()->setContextProperty("heightProxy", valueLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertyTypeCustomization_PointF::customizeChildren(QPropertyHandle* inPropertyHandle, QQuickDetailsViewLayoutBuilder* inBuilder)
|
||||||
|
{
|
||||||
|
auto makeChild = [&](const QString& name, std::function<QVariant(const QPointF&)> getter) {
|
||||||
|
inBuilder->addProperty(
|
||||||
|
inPropertyHandle->findOrCreateChild(
|
||||||
|
QMetaType::fromType<double>(),
|
||||||
|
name,
|
||||||
|
[inPropertyHandle, getter]() -> QVariant {
|
||||||
|
return getter(inPropertyHandle->getVar().value<QPointF>());
|
||||||
|
},
|
||||||
|
[inPropertyHandle, name](const QVariant& var) {
|
||||||
|
QPointF pt = inPropertyHandle->getVar().value<QPointF>();
|
||||||
|
if (name == "x")
|
||||||
|
pt.setX(var.toDouble());
|
||||||
|
else
|
||||||
|
pt.setY(var.toDouble());
|
||||||
|
inPropertyHandle->setVar(pt);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
makeChild("x", [](const QPointF& pt) { return pt.x(); });
|
||||||
|
makeChild("y", [](const QPointF& pt) { return pt.y(); });
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef PropertyTypeCustomization_PointF_h__
|
||||||
|
#define PropertyTypeCustomization_PointF_h__
|
||||||
|
|
||||||
|
#include "IPropertyTypeCustomization.h"
|
||||||
|
|
||||||
|
class PropertyTypeCustomization_PointF : public IPropertyTypeCustomization {
|
||||||
|
protected:
|
||||||
|
virtual void customizeHeaderRow(QPropertyHandle* inPropertyHandle, QQuickDetailsViewRowBuilder* inBuilder) override;
|
||||||
|
virtual void customizeChildren(QPropertyHandle* inPropertyHandle, QQuickDetailsViewLayoutBuilder* inBuilder) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PropertyTypeCustomization_PointF_h__
|
||||||
|
|
@ -8,9 +8,11 @@
|
||||||
#include "Customization/PropertyTypeCustomization_ObjectDefault.h"
|
#include "Customization/PropertyTypeCustomization_ObjectDefault.h"
|
||||||
#include "Customization/PropertyTypeCustomization_Matrix4x4.h"
|
#include "Customization/PropertyTypeCustomization_Matrix4x4.h"
|
||||||
#include "Customization/PropertyTypeCustomization_Font.h"
|
#include "Customization/PropertyTypeCustomization_Font.h"
|
||||||
|
#include "Customization/PropertyTypeCustomization_PointF.h"
|
||||||
#include <QtQuickControls2/QQuickStyle>
|
#include <QtQuickControls2/QQuickStyle>
|
||||||
#include <QMatrix4x4>
|
#include <QMatrix4x4>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QPointF>
|
||||||
|
|
||||||
QQuickDetailsViewManager* QQuickDetailsViewManager::Get()
|
QQuickDetailsViewManager* QQuickDetailsViewManager::Get()
|
||||||
{
|
{
|
||||||
|
|
@ -144,5 +146,9 @@ QQuickDetailsViewManager::QQuickDetailsViewManager()
|
||||||
mMetaTypeCustomizationMap.insert(QMetaType::fromType<QFont>(), []() {
|
mMetaTypeCustomizationMap.insert(QMetaType::fromType<QFont>(), []() {
|
||||||
return QSharedPointer<PropertyTypeCustomization_Font>::create();
|
return QSharedPointer<PropertyTypeCustomization_Font>::create();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mMetaTypeCustomizationMap.insert(QMetaType::fromType<QPointF>(), []() {
|
||||||
|
return QSharedPointer<PropertyTypeCustomization_PointF>::create();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue