Skip to content
Snippets Groups Projects
qtpropertymanager.cpp 208 KiB
Newer Older
    slot. In addition, QtDateTimePropertyManager provides the
    valueChanged() signal which is emitted whenever a property created
    by this manager changes.

    \sa QtAbstractPropertyManager, QtDateTimeEditFactory, QtDatePropertyManager
*/

/**
    \fn void QtDateTimePropertyManager::valueChanged(QtProperty *property, const
   QDateTime &value)

    This signal is emitted whenever a property created by this manager
    changes its value, passing a pointer to the \a property and the new
    \a value as parameters.
*/

/**
    Creates a manager with the given \a parent.
*/
QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent)
    : QtAbstractPropertyManager(parent) {
  d_ptr = new QtDateTimePropertyManagerPrivate;
  d_ptr->q_ptr = this;
  QLocale loc;
  d_ptr->m_format = loc.dateFormat(QLocale::ShortFormat);
  d_ptr->m_format += QLatin1Char(' ');
  d_ptr->m_format += loc.timeFormat(QLocale::ShortFormat);
}

/**
    Destroys this manager, and all the properties it has created.
*/
QtDateTimePropertyManager::~QtDateTimePropertyManager() {
  clear();
  delete d_ptr;
}

/**
    Returns the given \a property's value.

    If the given \a property is not managed by this manager, this
    function returns an invalid QDateTime object.

    \sa setValue()
*/
QDateTime QtDateTimePropertyManager::value(const QtProperty *property) const {
  return d_ptr->m_values.value(property, QDateTime());
QString QtDateTimePropertyManager::valueText(const QtProperty *property) const {
  const QtDateTimePropertyManagerPrivate::PropertyValueMap::const_iterator it =
      d_ptr->m_values.constFind(property);
  if (it == d_ptr->m_values.constEnd())
    return QString();
  return it.value().toString(d_ptr->m_format);
    \fn void QtDateTimePropertyManager::setValue(QtProperty *property, const
   QDateTime &value)

    Sets the value of the given \a property to \a value.

    \sa value(), valueChanged()
*/
void QtDateTimePropertyManager::setValue(QtProperty *property,
                                         const QDateTime &val) {
  setSimpleValue<const QDateTime &, QDateTime, QtDateTimePropertyManager>(
      d_ptr->m_values, this, &QtDateTimePropertyManager::propertyChanged,
      &QtDateTimePropertyManager::valueChanged, property, val);
void QtDateTimePropertyManager::initializeProperty(QtProperty *property) {
  d_ptr->m_values[property] = QDateTime::currentDateTime();
void QtDateTimePropertyManager::uninitializeProperty(QtProperty *property) {
  d_ptr->m_values.remove(property);
}

// QtKeySequencePropertyManager

class QtKeySequencePropertyManagerPrivate {
  QtKeySequencePropertyManager *q_ptr;
  Q_DECLARE_PUBLIC(QtKeySequencePropertyManager)
public:
  QString m_format;
  typedef QMap<const QtProperty *, QKeySequence> PropertyValueMap;
  PropertyValueMap m_values;
};

/** \class QtKeySequencePropertyManager

    \brief The QtKeySequencePropertyManager provides and manages QKeySequence
   properties.

    A key sequence's value can be retrieved using the value()
    function, and set using the setValue() slot.

    In addition, QtKeySequencePropertyManager provides the valueChanged() signal
    which is emitted whenever a property created by this manager
    changes.

    \sa QtAbstractPropertyManager
*/

/**
    \fn void QtKeySequencePropertyManager::valueChanged(QtProperty *property,
   const QKeySequence &value)

    This signal is emitted whenever a property created by this manager
    changes its value, passing a pointer to the \a property and the new
    \a value as parameters.
*/

/**
    Creates a manager with the given \a parent.
*/
QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent)
    : QtAbstractPropertyManager(parent) {
  d_ptr = new QtKeySequencePropertyManagerPrivate;
  d_ptr->q_ptr = this;
}

/**
    Destroys this manager, and all the properties it has created.
*/
QtKeySequencePropertyManager::~QtKeySequencePropertyManager() {
  clear();
  delete d_ptr;
}

/**
    Returns the given \a property's value.

    If the given \a property is not managed by this manager, this
    function returns an empty QKeySequence object.

    \sa setValue()
*/
QKeySequence
QtKeySequencePropertyManager::value(const QtProperty *property) const {
  return d_ptr->m_values.value(property, QKeySequence());
QString
QtKeySequencePropertyManager::valueText(const QtProperty *property) const {
  const QtKeySequencePropertyManagerPrivate::PropertyValueMap::const_iterator
      it = d_ptr->m_values.constFind(property);
  if (it == d_ptr->m_values.constEnd())
    return QString();
  return it.value().toString(QKeySequence::NativeText);
    \fn void QtKeySequencePropertyManager::setValue(QtProperty *property, const
   QKeySequence &value)

    Sets the value of the given \a property to \a value.

    \sa value(), valueChanged()
*/
void QtKeySequencePropertyManager::setValue(QtProperty *property,
                                            const QKeySequence &val) {
  setSimpleValue<const QKeySequence &, QKeySequence,
                 QtKeySequencePropertyManager>(
      d_ptr->m_values, this, &QtKeySequencePropertyManager::propertyChanged,
      &QtKeySequencePropertyManager::valueChanged, property, val);
void QtKeySequencePropertyManager::initializeProperty(QtProperty *property) {
  d_ptr->m_values[property] = QKeySequence();
void QtKeySequencePropertyManager::uninitializeProperty(QtProperty *property) {
  d_ptr->m_values.remove(property);
}

// QtCharPropertyManager

class QtCharPropertyManagerPrivate {
  QtCharPropertyManager *q_ptr;
  Q_DECLARE_PUBLIC(QtCharPropertyManager)
public:
  typedef QMap<const QtProperty *, QChar> PropertyValueMap;
  PropertyValueMap m_values;
};

/** \class QtCharPropertyManager

    \brief The QtCharPropertyManager provides and manages QChar properties.

    A char's value can be retrieved using the value()
    function, and set using the setValue() slot.

    In addition, QtCharPropertyManager provides the valueChanged() signal
    which is emitted whenever a property created by this manager
    changes.

    \sa QtAbstractPropertyManager
*/

/**
    \fn void QtCharPropertyManager::valueChanged(QtProperty *property, const
   QChar &value)

    This signal is emitted whenever a property created by this manager
    changes its value, passing a pointer to the \a property and the new
    \a value as parameters.
*/

/**
    Creates a manager with the given \a parent.
*/
QtCharPropertyManager::QtCharPropertyManager(QObject *parent)
    : QtAbstractPropertyManager(parent) {
  d_ptr = new QtCharPropertyManagerPrivate;
  d_ptr->q_ptr = this;
}

/**
    Destroys this manager, and all the properties it has created.
*/
QtCharPropertyManager::~QtCharPropertyManager() {
  clear();
  delete d_ptr;
}

/**
    Returns the given \a property's value.

    If the given \a property is not managed by this manager, this
    function returns an null QChar object.

    \sa setValue()
*/
QChar QtCharPropertyManager::value(const QtProperty *property) const {
  return d_ptr->m_values.value(property, QChar());
QString QtCharPropertyManager::valueText(const QtProperty *property) const {
  const QtCharPropertyManagerPrivate::PropertyValueMap::const_iterator it =
      d_ptr->m_values.constFind(property);
  if (it == d_ptr->m_values.constEnd())
    return QString();
  const QChar c = it.value();
  return c.isNull() ? QString() : QString(c);
    \fn void QtCharPropertyManager::setValue(QtProperty *property, const QChar
   &value)

    Sets the value of the given \a property to \a value.

    \sa value(), valueChanged()
*/
void QtCharPropertyManager::setValue(QtProperty *property, const QChar &val) {
  setSimpleValue<const QChar &, QChar, QtCharPropertyManager>(
      d_ptr->m_values, this, &QtCharPropertyManager::propertyChanged,
      &QtCharPropertyManager::valueChanged, property, val);
void QtCharPropertyManager::initializeProperty(QtProperty *property) {
  d_ptr->m_values[property] = QChar();
void QtCharPropertyManager::uninitializeProperty(QtProperty *property) {
  d_ptr->m_values.remove(property);
}

// QtLocalePropertyManager

class QtLocalePropertyManagerPrivate {
  QtLocalePropertyManager *q_ptr;
  Q_DECLARE_PUBLIC(QtLocalePropertyManager)
public:
  QtLocalePropertyManagerPrivate();
  void slotEnumChanged(QtProperty *property, int value);
  void slotPropertyDestroyed(QtProperty *property);
  typedef QMap<const QtProperty *, QLocale> PropertyValueMap;
  PropertyValueMap m_values;
  QtEnumPropertyManager *m_enumPropertyManager;
  QMap<const QtProperty *, QtProperty *> m_propertyToLanguage;
  QMap<const QtProperty *, QtProperty *> m_propertyToCountry;
  QMap<const QtProperty *, QtProperty *> m_languageToProperty;
  QMap<const QtProperty *, QtProperty *> m_countryToProperty;
QtLocalePropertyManagerPrivate::QtLocalePropertyManagerPrivate() {}

void QtLocalePropertyManagerPrivate::slotEnumChanged(QtProperty *property,
                                                     int value) {
  if (QtProperty *prop = m_languageToProperty.value(property, 0)) {
    const QLocale loc = m_values[prop];
    QLocale::Language newLanguage = loc.language();
    QLocale::Country newCountry = loc.country();
    metaEnumProvider()->indexToLocale(value, 0, &newLanguage, 0);
    QLocale newLoc(newLanguage, newCountry);
    q_ptr->setValue(prop, newLoc);
  } else if (QtProperty *prop = m_countryToProperty.value(property, 0)) {
    const QLocale loc = m_values[prop];
    QLocale::Language newLanguage = loc.language();
    QLocale::Country newCountry = loc.country();
    metaEnumProvider()->indexToLocale(
        m_enumPropertyManager->value(m_propertyToLanguage.value(prop)), value,
        &newLanguage, &newCountry);
    QLocale newLoc(newLanguage, newCountry);
    q_ptr->setValue(prop, newLoc);
  }
}

void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(
    QtProperty *property) {
  if (QtProperty *subProp = m_languageToProperty.value(property, 0)) {
    m_propertyToLanguage[subProp] = 0;
    m_languageToProperty.remove(property);
  } else if (QtProperty *subProp = m_countryToProperty.value(property, 0)) {
    m_propertyToCountry[subProp] = 0;
    m_countryToProperty.remove(property);
  }
}

/**
    \class QtLocalePropertyManager

    \brief The QtLocalePropertyManager provides and manages QLocale properties.

    A locale property has nested \e language and \e country
    subproperties. The top-level property's value can be retrieved
    using the value() function, and set using the setValue() slot.

    The subproperties are created by QtEnumPropertyManager object.
    These submanager can be retrieved using the subEnumPropertyManager()
    function. In order to provide editing widgets for the subproperties
    in a property browser widget, this manager must be associated with editor
   factory.

    In addition, QtLocalePropertyManager provides the valueChanged()
    signal which is emitted whenever a property created by this
    manager changes.

    \sa QtAbstractPropertyManager, QtEnumPropertyManager
*/

/**
    \fn void QtLocalePropertyManager::valueChanged(QtProperty *property, const
   QLocale &value)

    This signal is emitted whenever a property created by this manager
    changes its value, passing a pointer to the \a property and the
    new \a value as parameters.

    \sa setValue()
*/

/**
    Creates a manager with the given \a parent.
*/
QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent)
    : QtAbstractPropertyManager(parent) {
  d_ptr = new QtLocalePropertyManagerPrivate;
  d_ptr->q_ptr = this;
  d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
  connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
          this, SLOT(slotEnumChanged(QtProperty *, int)));
  connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
          this, SLOT(slotPropertyDestroyed(QtProperty *)));
}

/**
    Destroys this manager, and all the properties it has created.
*/
QtLocalePropertyManager::~QtLocalePropertyManager() {
  clear();
  delete d_ptr;
}

/**
    Returns the manager that creates the nested \e language
    and \e country subproperties.

    In order to provide editing widgets for the mentioned subproperties
    in a property browser widget, this manager must be associated with
    an editor factory.

    \sa QtAbstractPropertyBrowser::setFactoryForManager()
*/
QtEnumPropertyManager *QtLocalePropertyManager::subEnumPropertyManager() const {
  return d_ptr->m_enumPropertyManager;
}

/**
    Returns the given \a property's value.

    If the given property is not managed by this manager, this
    function returns the default locale.

    \sa setValue()
*/
QLocale QtLocalePropertyManager::value(const QtProperty *property) const {
  return d_ptr->m_values.value(property, QLocale());
QString QtLocalePropertyManager::valueText(const QtProperty *property) const {
  const QtLocalePropertyManagerPrivate::PropertyValueMap::const_iterator it =
      d_ptr->m_values.constFind(property);
  if (it == d_ptr->m_values.constEnd())
    return QString();
  QLocale loc = it.value();
  int langIdx = 0;
  int countryIdx = 0;
  metaEnumProvider()->localeToIndex(loc.language(), loc.country(), &langIdx,
                                    &countryIdx);
  QString str = tr("%1, %2")
                    .arg(metaEnumProvider()->languageEnumNames().at(langIdx))
                    .arg(metaEnumProvider()
                             ->countryEnumNames(loc.language())
                             .at(countryIdx));
  return str;
    \fn void QtLocalePropertyManager::setValue(QtProperty *property, const
   QLocale &value)

    Sets the value of the given \a property to \a value. Nested
    properties are updated automatically.

    \sa value(), valueChanged()
*/
void QtLocalePropertyManager::setValue(QtProperty *property,
                                       const QLocale &val) {
  const QtLocalePropertyManagerPrivate::PropertyValueMap::iterator it =
      d_ptr->m_values.find(property);
  if (it == d_ptr->m_values.end())
    return;

  const QLocale loc = it.value();
  if (loc == val)
    return;
  it.value() = val;

  int langIdx = 0;
  int countryIdx = 0;
  metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx,
                                    &countryIdx);
  if (loc.language() != val.language()) {
    d_ptr->m_enumPropertyManager->setValue(
        d_ptr->m_propertyToLanguage.value(property), langIdx);
    d_ptr->m_enumPropertyManager->setEnumNames(
        d_ptr->m_propertyToCountry.value(property),
        metaEnumProvider()->countryEnumNames(val.language()));
  }
  d_ptr->m_enumPropertyManager->setValue(
      d_ptr->m_propertyToCountry.value(property), countryIdx);

  emit propertyChanged(property);
  emit valueChanged(property, val);
void QtLocalePropertyManager::initializeProperty(QtProperty *property) {
  QLocale val;
  d_ptr->m_values[property] = val;
  int langIdx = 0;
  int countryIdx = 0;
  metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx,
                                    &countryIdx);
  QtProperty *languageProp = d_ptr->m_enumPropertyManager->addProperty();
  languageProp->setPropertyName(tr("Language"));
  d_ptr->m_enumPropertyManager->setEnumNames(
      languageProp, metaEnumProvider()->languageEnumNames());
  d_ptr->m_enumPropertyManager->setValue(languageProp, langIdx);
  d_ptr->m_propertyToLanguage[property] = languageProp;
  d_ptr->m_languageToProperty[languageProp] = property;
  property->addSubProperty(languageProp);
  QtProperty *countryProp = d_ptr->m_enumPropertyManager->addProperty();
  countryProp->setPropertyName(tr("Country"));
  d_ptr->m_enumPropertyManager->setEnumNames(
      countryProp, metaEnumProvider()->countryEnumNames(val.language()));
  d_ptr->m_enumPropertyManager->setValue(countryProp, countryIdx);
  d_ptr->m_propertyToCountry[property] = countryProp;
  d_ptr->m_countryToProperty[countryProp] = property;
  property->addSubProperty(countryProp);
void QtLocalePropertyManager::uninitializeProperty(QtProperty *property) {
  QtProperty *languageProp = d_ptr->m_propertyToLanguage[property];
  if (languageProp) {
    d_ptr->m_languageToProperty.remove(languageProp);
    delete languageProp;
  }
  d_ptr->m_propertyToLanguage.remove(property);
  QtProperty *countryProp = d_ptr->m_propertyToCountry[property];
  if (countryProp) {
    d_ptr->m_countryToProperty.remove(countryProp);
    delete countryProp;
  }
  d_ptr->m_propertyToCountry.remove(property);
  d_ptr->m_values.remove(property);
}

// QtPointPropertyManager

class QtPointPropertyManagerPrivate {
  QtPointPropertyManager *q_ptr;
  Q_DECLARE_PUBLIC(QtPointPropertyManager)
public:
  void slotIntChanged(QtProperty *property, int value);
  void slotPropertyDestroyed(QtProperty *property);
  typedef QMap<const QtProperty *, QPoint> PropertyValueMap;
  PropertyValueMap m_values;
  QtIntPropertyManager *m_intPropertyManager;
  QMap<const QtProperty *, QtProperty *> m_propertyToX;
  QMap<const QtProperty *, QtProperty *> m_propertyToY;
  QMap<const QtProperty *, QtProperty *> m_xToProperty;
  QMap<const QtProperty *, QtProperty *> m_yToProperty;
void QtPointPropertyManagerPrivate::slotIntChanged(QtProperty *property,
                                                   int value) {
  if (QtProperty *xprop = m_xToProperty.value(property, 0)) {
    QPoint p = m_values[xprop];
    p.setX(value);
    q_ptr->setValue(xprop, p);
  } else if (QtProperty *yprop = m_yToProperty.value(property, 0)) {
    QPoint p = m_values[yprop];
    p.setY(value);
    q_ptr->setValue(yprop, p);
  }
}

void QtPointPropertyManagerPrivate::slotPropertyDestroyed(
    QtProperty *property) {
  if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
    m_propertyToX[pointProp] = 0;
    m_xToProperty.remove(property);
  } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
    m_propertyToY[pointProp] = 0;
    m_yToProperty.remove(property);
  }
}

/** \class QtPointPropertyManager

    \brief The QtPointPropertyManager provides and manages QPoint properties.

    A point property has nested \e x and \e y subproperties. The
    top-level property's value can be retrieved using the value()
    function, and set using the setValue() slot.

    The subproperties are created by a QtIntPropertyManager object. This
    manager can be retrieved using the subIntPropertyManager() function. In
    order to provide editing widgets for the subproperties in a
    property browser widget, this manager must be associated with an
    editor factory.

    In addition, QtPointPropertyManager provides the valueChanged() signal which
    is emitted whenever a property created by this manager changes.

    \sa QtAbstractPropertyManager, QtIntPropertyManager, QtPointFPropertyManager
*/

/**
    \fn void QtPointPropertyManager::valueChanged(QtProperty *property, const
   QPoint &value)

    This signal is emitted whenever a property created by this manager
    changes its value, passing a pointer to the \a property and the
    new \a value as parameters.

    \sa setValue()
*/

/**
    Creates a manager with the given \a parent.
*/
QtPointPropertyManager::QtPointPropertyManager(QObject *parent)
    : QtAbstractPropertyManager(parent) {
  d_ptr = new QtPointPropertyManagerPrivate;
  d_ptr->q_ptr = this;
  d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
  connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
          this, SLOT(slotIntChanged(QtProperty *, int)));
  connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty *)),
          this, SLOT(slotPropertyDestroyed(QtProperty *)));
}

/**
    Destroys this manager, and all the properties it has created.
*/
QtPointPropertyManager::~QtPointPropertyManager() {
  clear();
  delete d_ptr;
}

/**
    Returns the manager that creates the nested \e x and \e y
    subproperties.

    In order to provide editing widgets for the subproperties in a
    property browser widget, this manager must be associated with an
    editor factory.

    \sa QtAbstractPropertyBrowser::setFactoryForManager()
*/
QtIntPropertyManager *QtPointPropertyManager::subIntPropertyManager() const {
  return d_ptr->m_intPropertyManager;
}

/**
    Returns the given \a property's value.

    If the given \a property is not managed by this manager, this
    function returns a point with coordinates (0, 0).

    \sa setValue()
*/
QPoint QtPointPropertyManager::value(const QtProperty *property) const {
  return d_ptr->m_values.value(property, QPoint());
QString QtPointPropertyManager::valueText(const QtProperty *property) const {
  const QtPointPropertyManagerPrivate::PropertyValueMap::const_iterator it =
      d_ptr->m_values.constFind(property);
  if (it == d_ptr->m_values.constEnd())
    return QString();
  const QPoint v = it.value();
  return QString(
      tr("(%1, %2)").arg(QString::number(v.x())).arg(QString::number(v.y())));
    \fn void QtPointPropertyManager::setValue(QtProperty *property, const QPoint
   &value)

    Sets the value of the given \a property to \a value. Nested
    properties are updated automatically.

    \sa value(), valueChanged()
*/
void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &val) {
  const QtPointPropertyManagerPrivate::PropertyValueMap::iterator it =
      d_ptr->m_values.find(property);
  if (it == d_ptr->m_values.end())
    return;
  if (it.value() == val)
    return;
  it.value() = val;
  d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property],
                                        val.x());
  d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property],
                                        val.y());
  emit propertyChanged(property);
  emit valueChanged(property, val);
void QtPointPropertyManager::initializeProperty(QtProperty *property) {
  d_ptr->m_values[property] = QPoint(0, 0);
  QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
  xProp->setPropertyName(tr("X"));
  d_ptr->m_intPropertyManager->setValue(xProp, 0);
  d_ptr->m_propertyToX[property] = xProp;
  d_ptr->m_xToProperty[xProp] = property;
  property->addSubProperty(xProp);
  QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
  yProp->setPropertyName(tr("Y"));
  d_ptr->m_intPropertyManager->setValue(yProp, 0);
  d_ptr->m_propertyToY[property] = yProp;
  d_ptr->m_yToProperty[yProp] = property;
  property->addSubProperty(yProp);
void QtPointPropertyManager::uninitializeProperty(QtProperty *property) {
  QtProperty *xProp = d_ptr->m_propertyToX[property];
  if (xProp) {
    d_ptr->m_xToProperty.remove(xProp);
    delete xProp;
  }
  d_ptr->m_propertyToX.remove(property);
  QtProperty *yProp = d_ptr->m_propertyToY[property];
  if (yProp) {
    d_ptr->m_yToProperty.remove(yProp);
    delete yProp;
  }
  d_ptr->m_propertyToY.remove(property);
  d_ptr->m_values.remove(property);
}

// QtPointFPropertyManager

class QtPointFPropertyManagerPrivate {
  QtPointFPropertyManager *q_ptr;
  Q_DECLARE_PUBLIC(QtPointFPropertyManager)
public:
  struct Data {
    Data() : decimals(2) {}
    QPointF val;
    int decimals;
  };
  void slotDoubleChanged(QtProperty *property, double value);
  void slotPropertyDestroyed(QtProperty *property);
  typedef QMap<const QtProperty *, Data> PropertyValueMap;
  PropertyValueMap m_values;
  QtDoublePropertyManager *m_doublePropertyManager;
  QMap<const QtProperty *, QtProperty *> m_propertyToX;
  QMap<const QtProperty *, QtProperty *> m_propertyToY;
  QMap<const QtProperty *, QtProperty *> m_xToProperty;
  QMap<const QtProperty *, QtProperty *> m_yToProperty;
void QtPointFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property,
                                                       double value) {
  if (QtProperty *prop = m_xToProperty.value(property, 0)) {
    QPointF p = m_values[prop].val;
    p.setX(value);
    q_ptr->setValue(prop, p);
  } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
    QPointF p = m_values[prop].val;
    p.setY(value);
    q_ptr->setValue(prop, p);
  }
}

void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(
    QtProperty *property) {
  if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
    m_propertyToX[pointProp] = 0;
    m_xToProperty.remove(property);
  } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
    m_propertyToY[pointProp] = 0;
    m_yToProperty.remove(property);
  }
}

/** \class QtPointFPropertyManager

    \brief The QtPointFPropertyManager provides and manages QPointF properties.

    A point property has nested \e x and \e y subproperties. The
    top-level property's value can be retrieved using the value()
    function, and set using the setValue() slot.

    The subproperties are created by a QtDoublePropertyManager object. This
    manager can be retrieved using the subDoublePropertyManager() function. In
    order to provide editing widgets for the subproperties in a
    property browser widget, this manager must be associated with an
    editor factory.

    In addition, QtPointFPropertyManager provides the valueChanged() signal
   which
    is emitted whenever a property created by this manager changes.

    \sa QtAbstractPropertyManager, QtDoublePropertyManager,
   QtPointPropertyManager
    \fn void QtPointFPropertyManager::valueChanged(QtProperty *property, const
   QPointF &value)

    This signal is emitted whenever a property created by this manager
    changes its value, passing a pointer to the \a property and the
    new \a value as parameters.

    \sa setValue()
*/

/**
    \fn void QtPointFPropertyManager::decimalsChanged(QtProperty *property, int
   prec)

    This signal is emitted whenever a property created by this manager
    changes its precision of value, passing a pointer to the
    \a property and the new \a prec value

    \sa setDecimals()
*/

/**
    Creates a manager with the given \a parent.
*/
QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent)
    : QtAbstractPropertyManager(parent) {
  d_ptr = new QtPointFPropertyManagerPrivate;
  d_ptr->q_ptr = this;
  d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
  connect(d_ptr->m_doublePropertyManager,
          SIGNAL(valueChanged(QtProperty *, double)), this,
          SLOT(slotDoubleChanged(QtProperty *, double)));
  connect(d_ptr->m_doublePropertyManager,
          SIGNAL(propertyDestroyed(QtProperty *)), this,
          SLOT(slotPropertyDestroyed(QtProperty *)));
}

/**
    Destroys this manager, and all the properties it has created.
*/
QtPointFPropertyManager::~QtPointFPropertyManager() {
  clear();
  delete d_ptr;
}

/**
    Returns the manager that creates the nested \e x and \e y
    subproperties.

    In order to provide editing widgets for the subproperties in a
    property browser widget, this manager must be associated with an
    editor factory.

    \sa QtAbstractPropertyBrowser::setFactoryForManager()
*/
QtDoublePropertyManager *
QtPointFPropertyManager::subDoublePropertyManager() const {
  return d_ptr->m_doublePropertyManager;
}

/**
    Returns the given \a property's value.

    If the given \a property is not managed by this manager, this
    function returns a point with coordinates (0, 0).

    \sa setValue()
*/
QPointF QtPointFPropertyManager::value(const QtProperty *property) const {
  return getValue<QPointF>(d_ptr->m_values, property);
}

/**
    Returns the given \a property's precision, in decimals.

    \sa setDecimals()
*/
int QtPointFPropertyManager::decimals(const QtProperty *property) const {
  return getData<int>(d_ptr->m_values,
                      &QtPointFPropertyManagerPrivate::Data::decimals, property,
                      0);
QString QtPointFPropertyManager::valueText(const QtProperty *property) const {
  const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it =
      d_ptr->m_values.constFind(property);
  if (it == d_ptr->m_values.constEnd())
    return QString();
  const QPointF v = it.value().val;
  const int dec = it.value().decimals;
  return QString(tr("(%1, %2)")
                     .arg(QString::number(v.x(), 'f', dec))
                     .arg(QString::number(v.y(), 'f', dec)));
    \fn void QtPointFPropertyManager::setValue(QtProperty *property, const
   QPointF &value)

    Sets the value of the given \a property to \a value. Nested
    properties are updated automatically.

    \sa value(), valueChanged()
*/
void QtPointFPropertyManager::setValue(QtProperty *property,
                                       const QPointF &val) {
  const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it =
      d_ptr->m_values.find(property);
  if (it == d_ptr->m_values.end())
    return;
  if (it.value().val == val)
    return;
  it.value().val = val;
  d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property],
                                           val.x());
  d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property],
                                           val.y());
  emit propertyChanged(property);
  emit valueChanged(property, val);
    \fn void QtPointFPropertyManager::setDecimals(QtProperty *property, int
   prec)

    Sets the precision of the given \a property to \a prec.

    The valid decimal range is 0-13. The default is 2.

    \sa decimals()
*/
void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec) {
  const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it =
      d_ptr->m_values.find(property);
  if (it == d_ptr->m_values.end())
    return;
  QtPointFPropertyManagerPrivate::Data data = it.value();
  if (prec > 13)
    prec = 13;
  else if (prec < 0)
    prec = 0;
  if (data.decimals == prec)
    return;
  data.decimals = prec;
  d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property],
                                              prec);
  d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property],
                                              prec);
  it.value() = data;
  emit decimalsChanged(property, data.decimals);