fix: resolve Q_CLASSINFO metadata for child properties by matching all path segments

resloveMetaData() only matched Q_CLASSINFO against the first segment of
  the property path (e.g. "ptPosition" from "ptPosition.x"), so child
  handles like x/y under a QPointF tree never picked up Min/Max/Step
  metadata declared with Q_CLASSINFO("x", ...). This caused the x/y
  NumberBox editors to fall back to numeric_limits min/max, clamping
  negative values to ~0.

  Now iterates path segments from most specific (last) to least specific
  (first), so child property names correctly match their Q_CLASSINFO
  annotations.

  Also add Q_CLASSINFO("x"/"y", "Min=-1000,Max=1000,Step=1") on
  GraphicsTextItem to constrain position editing to a reasonable range.
This commit is contained in:
jessequ 2026-07-31 16:39:24 +08:00
parent e63fae92c8
commit e1671fdbe3
2 changed files with 25 additions and 15 deletions

View File

@ -42,10 +42,15 @@ QPropertyHandle::QPropertyHandle(QObject* inParent, QMetaType inType, QString in
void QPropertyHandle::resloveMetaData()
{
auto metaObj = parent()->metaObject();
auto firstField = getPropertyPath().split(".").first();
const QStringList pathSegments = getPropertyPath().split(".");
// Try each segment from most specific (last) to least specific (first)
for (int seg = pathSegments.size() - 1; seg >= 0; --seg) {
const QString& fieldName = pathSegments[seg];
if (fieldName.isEmpty()) continue;
for (int i = 0; i < metaObj->classInfoCount(); i++) {
auto metaClassInfo = metaObj->classInfo(i);
if (metaClassInfo.name() == firstField) {
if (metaClassInfo.name() == fieldName) {
QStringList fields = QString(metaClassInfo.value()).split(",", Qt::SplitBehaviorFlags::SkipEmptyParts);
for (auto field : fields) {
QStringList pair = field.split("=");
@ -62,6 +67,7 @@ void QPropertyHandle::resloveMetaData()
}
}
}
}
QPropertyHandle* QPropertyHandle::Find(const QObject* inParent, const QString& inPropertyPath)
{

View File

@ -12,6 +12,10 @@ class GraphicsTextItem : public AbstractShapeType<QGraphicsTextItem>,
public IPropertyGroupProvider
{
Q_OBJECT
Q_CLASSINFO("x", "Min=-1000,Max=1000,Step=1,Group=ptPosition")
Q_CLASSINFO("y", "Min=-1000,Max=1000,Step=1,Group=ptPosition")
Q_PROPERTY(QString text READ toPlainText WRITE setPlainText)
Q_PROPERTY(QPointF ptPosition READ pos WRITE setPos FINAL)
Q_PROPERTY(QFont textFont READ textFont WRITE setTextFont)