21#include "KPropertyFactory.h" 
   26class Q_DECL_HIDDEN KPropertyFactoryManager::Private
 
   34        qDeleteAll(factories);
 
   37    QSet<KPropertyFactory*> factories;
 
   38    QHash<int, KComposedPropertyCreatorInterface*> composedPropertyCreators;
 
   39    QHash<int, KPropertyValueDisplayInterface*> valueDisplays;
 
   42Q_GLOBAL_STATIC(KPropertyFactoryManager, _self)
 
   45class Q_DECL_HIDDEN KPropertyFactory::Private
 
   53        qDeleteAll(valueDisplaysSet);
 
   56    QHash<int, KComposedPropertyCreatorInterface*> composedPropertyCreators;
 
   57    QSet<KComposedPropertyCreatorInterface*> composedPropertyCreatorsSet;
 
   58    QHash<int, KPropertyValueDisplayInterface*> valueDisplays;
 
   59    QSet<KPropertyValueDisplayInterface*> valueDisplaysSet;
 
   62typedef QList<void (*)()> InitFunctions;
 
   64Q_GLOBAL_STATIC(InitFunctions, _initFunctions)
 
   66KPropertyFactory::KPropertyFactory()
 
   71KPropertyFactory::~KPropertyFactory()
 
   78    return d->composedPropertyCreators;
 
   83    return d->valueDisplays;
 
   86void KPropertyFactory::addComposedPropertyCreator( 
int type, KComposedPropertyCreatorInterface* creator )
 
   88    addComposedPropertyCreatorInternal( type, creator, 
true );
 
   91void KPropertyFactory::addComposedPropertyCreatorInternal(
int type, KComposedPropertyCreatorInterface* creator, 
bool own)
 
   94        d->composedPropertyCreatorsSet.insert(creator);
 
   95    d->composedPropertyCreators.insert(type, creator);
 
  100    addDisplayInternal(type, display, 
true);
 
  101    if (
dynamic_cast<KComposedPropertyCreatorInterface*
>(display)) {
 
  102        addComposedPropertyCreatorInternal( type,
 
  103        dynamic_cast<KComposedPropertyCreatorInterface*
>(display), 
false );
 
  105    if (
dynamic_cast<KPropertyValueDisplayInterface*
>(display)) {
 
  106        addDisplayInternal( type, 
dynamic_cast<KPropertyValueDisplayInterface*
>(display), 
false );
 
  113        d->valueDisplaysSet.insert(display);
 
  115    d->valueDisplays.insert(type, display);
 
  126KPropertyValueDisplayInterface::KPropertyValueDisplayInterface()
 
  131KPropertyValueDisplayInterface::~KPropertyValueDisplayInterface()
 
  155KPropertyFactoryManager::KPropertyFactoryManager()
 
  162KPropertyFactoryManager::~KPropertyFactoryManager()
 
  167KPropertyFactoryManager* KPropertyFactoryManager::self()
 
  169    if (_self.exists()) { 
 
  173    foreach(
void (*initFunction)(), *_initFunctions) {
 
  176    _initFunctions->clear();
 
  180void KPropertyFactoryManager::registerFactory(KPropertyFactory *factory)
 
  182    d->factories.insert(factory);
 
  184        = factory->composedPropertyCreators().
constEnd();
 
  186        it != composedPropertyCreatorsItEnd; ++it)
 
  188        d->composedPropertyCreators.insert(it.key(), it.value());
 
  191        = factory->valueDisplays().
constEnd();
 
  193        it != valueDisplaysItEnd; ++it)
 
  195        d->valueDisplays.insert(it.key(), it.value());
 
  201    const KComposedPropertyCreatorInterface *creator = d->composedPropertyCreators.value( 
parent->type() );
 
  202    return creator ? creator->createComposedProperty(
parent) : 
nullptr;
 
  206void KPropertyFactoryManager::addInitFunction(
void (*initFunction)())
 
  208    _initFunctions->append(initFunction);
 
  211bool KPropertyFactoryManager::canConvertValueToText(
int type)
 const 
  213    return d->valueDisplays.value(type) != 
nullptr;
 
  216bool KPropertyFactoryManager::canConvertValueToText(
const KProperty* property)
 const 
  218    return canConvertValueToText(
property->type());
 
  221QString KPropertyFactoryManager::propertyValueToString(
const KProperty* property)
 const 
  223    const KPropertyValueDisplayInterface *display = d->valueDisplays.value(
property->type());
 
  224    return display ? display->propertyValueToString(
property, 
QLocale::c()) : 
property->value().toString();
 
  227QString KPropertyFactoryManager::valueToString(
int type, 
const QVariant &value)
 const 
  229    const KPropertyValueDisplayInterface *display = d->valueDisplays.value(type);
 
  233QString KPropertyFactoryManager::propertyValueToLocalizedString(
const KProperty* property)
 const 
  235    const KPropertyValueDisplayInterface *display = d->valueDisplays.value(
property->type());
 
  239QString KPropertyFactoryManager::valueToLocalizedString(
int type, 
const QVariant &value)
 const 
  241    const KPropertyValueDisplayInterface *display = d->valueDisplays.value(type);
 
  257        return new SizeCustomProperty(parent);
 
  261        return new PointCustomProperty(parent);
 
  267        return new RectCustomProperty(parent);
 
  273        return new SizePolicyCustomProperty(parent);
 
  283    bool childValueChangedEnabled = 
true;
 
  286KComposedPropertyInterface::KComposedPropertyInterface(
KProperty *parent)
 
  292KComposedPropertyInterface::~KComposedPropertyInterface()
 
  297void KComposedPropertyInterface::childValueChangedInternal(
KProperty *child, 
const QVariant &value,
 
  298                                                           KProperty::ValueOptions valueOptions)
 
  300    if (d->childValueChangedEnabled) {
 
  301        childValueChanged(child, value, valueOptions);
 
  305void KComposedPropertyInterface::setChildValueChangedEnabled(
bool set)
 
  307    d->childValueChangedEnabled = set;
 
  310bool KComposedPropertyInterface::childValueChangedEnabled()
 const 
  312    return d->childValueChangedEnabled;
 
  317class Q_DECL_HIDDEN KComposedPropertyCreatorInterface::Private
 
  323KComposedPropertyCreatorInterface::KComposedPropertyCreatorInterface()
 
  328KComposedPropertyCreatorInterface::~KComposedPropertyCreatorInterface()
 
An interface for for composed property handlers.
 
Provides a specialized conversion of value to string depending on type.
 
static QString valueToLocalizedString(const QVariant &value)
 
static int maxStringValueLength()
Maximum length of strings to display in valueToString(), propertyValueToString() and KPropertyValuePa...
 
The base class representing a single property.
 
Type type(const QSqlDatabase &db)
 
const_iterator constBegin() const const
 
const_iterator constEnd() const const
 
QObject * parent() const const
 
QVariant property(const char *name) const const
 
QString tr(const char *sourceText, const char *disambiguation, int n)
 
QString arg(Args &&... args) const const
 
qsizetype length() const const
 
void truncate(qsizetype position)
 
QString toString() const const