1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332 |
- /****************************************************************************
- **
- ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
- ** Contact: http://www.qt-project.org/legal
- **
- ** This file is part of the Qt Solutions component.
- **
- ** $QT_BEGIN_LICENSE:BSD$
- ** You may use this file under the terms of the BSD license as follows:
- **
- ** "Redistribution and use in source and binary forms, with or without
- ** modification, are permitted provided that the following conditions are
- ** met:
- ** * Redistributions of source code must retain the above copyright
- ** notice, this list of conditions and the following disclaimer.
- ** * Redistributions in binary form must reproduce the above copyright
- ** notice, this list of conditions and the following disclaimer in
- ** the documentation and/or other materials provided with the
- ** distribution.
- ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
- ** of its contributors may be used to endorse or promote products derived
- ** from this software without specific prior written permission.
- **
- **
- ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
- #pragma execution_character_set("utf-8")
- #include "qtvariantproperty.h"
- #include "qtpropertymanager.h"
- #include "qteditorfactory.h"
- #include <QVariant>
- #include <QIcon>
- #include <QDate>
- #include <QLocale>
- #if defined(Q_CC_MSVC)
- # pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
- #endif
- #if QT_VERSION >= 0x040400
- QT_BEGIN_NAMESPACE
- #endif
- class QtEnumPropertyType
- {
- };
- class QtFlagPropertyType
- {
- };
- class QtGroupPropertyType
- {
- };
- #if QT_VERSION >= 0x040400
- QT_END_NAMESPACE
- #endif
- Q_DECLARE_METATYPE(QtEnumPropertyType)
- Q_DECLARE_METATYPE(QtFlagPropertyType)
- Q_DECLARE_METATYPE(QtGroupPropertyType)
- #if QT_VERSION >= 0x040400
- QT_BEGIN_NAMESPACE
- #endif
- /*!
- Returns the type id for an enum property.
- Note that the property's value type can be retrieved using the
- valueType() function (which is QVariant::Int for the enum property
- type).
- \sa propertyType(), valueType()
- */
- int QtVariantPropertyManager::enumTypeId()
- {
- return qMetaTypeId<QtEnumPropertyType>();
- }
- /*!
- Returns the type id for a flag property.
- Note that the property's value type can be retrieved using the
- valueType() function (which is QVariant::Int for the flag property
- type).
- \sa propertyType(), valueType()
- */
- int QtVariantPropertyManager::flagTypeId()
- {
- return qMetaTypeId<QtFlagPropertyType>();
- }
- /*!
- Returns the type id for a group property.
- Note that the property's value type can be retrieved using the
- valueType() function (which is QVariant::Invalid for the group
- property type, since it doesn't provide any value).
- \sa propertyType(), valueType()
- */
- int QtVariantPropertyManager::groupTypeId()
- {
- return qMetaTypeId<QtGroupPropertyType>();
- }
- /*!
- Returns the type id for a icon map attribute.
- Note that the property's attribute type can be retrieved using the
- attributeType() function.
- \sa attributeType(), QtEnumPropertyManager::enumIcons()
- */
- int QtVariantPropertyManager::iconMapTypeId()
- {
- return qMetaTypeId<QtIconMap>();
- }
- typedef QMap<const QtProperty *, QtProperty *> PropertyMap;
- Q_GLOBAL_STATIC(PropertyMap, propertyToWrappedProperty)
- static QtProperty *wrappedProperty(QtProperty *property)
- {
- return propertyToWrappedProperty()->value(property, 0);
- }
- class QtVariantPropertyPrivate
- {
- QtVariantProperty *q_ptr = nullptr;
- public:
- QtVariantPropertyPrivate(QtVariantPropertyManager *m) : manager(m) {}
- QtVariantPropertyManager *manager;
- };
- /*!
- \class QtVariantProperty
- \brief The QtVariantProperty class is a convenience class handling
- QVariant based properties.
- QtVariantProperty provides additional API: A property's type,
- value type, attribute values and current value can easily be
- retrieved using the propertyType(), valueType(), attributeValue()
- and value() functions respectively. In addition, the attribute
- values and the current value can be set using the corresponding
- setValue() and setAttribute() functions.
- For example, instead of writing:
- \code
- QtVariantPropertyManager *variantPropertyManager;
- QtProperty *property;
- variantPropertyManager->setValue(property, 10);
- \endcode
- you can write:
- \code
- QtVariantPropertyManager *variantPropertyManager;
- QtVariantProperty *property;
- property->setValue(10);
- \endcode
- QtVariantProperty instances can only be created by the
- QtVariantPropertyManager class.
- \sa QtProperty, QtVariantPropertyManager, QtVariantEditorFactory
- */
- /*!
- Creates a variant property using the given \a manager.
- Do not use this constructor to create variant property instances;
- use the QtVariantPropertyManager::addProperty() function
- instead. This constructor is used internally by the
- QtVariantPropertyManager::createProperty() function.
- \sa QtVariantPropertyManager
- */
- QtVariantProperty::QtVariantProperty(QtVariantPropertyManager *manager)
- : QtProperty(manager), d_ptr(new QtVariantPropertyPrivate(manager))
- {
- }
- /*!
- Destroys this property.
- \sa QtProperty::~QtProperty()
- */
- QtVariantProperty::~QtVariantProperty()
- {
- delete d_ptr;
- }
- /*!
- Returns the property's current value.
- \sa valueType(), setValue()
- */
- QVariant QtVariantProperty::value() const
- {
- return d_ptr->manager->value(this);
- }
- /*!
- Returns this property's value for the specified \a attribute.
- QtVariantPropertyManager provides a couple of related functions:
- \l{QtVariantPropertyManager::attributes()}{attributes()} and
- \l{QtVariantPropertyManager::attributeType()}{attributeType()}.
- \sa setAttribute()
- */
- QVariant QtVariantProperty::attributeValue(const QString &attribute) const
- {
- return d_ptr->manager->attributeValue(this, attribute);
- }
- /*!
- Returns the type of this property's value.
- \sa propertyType()
- */
- int QtVariantProperty::valueType() const
- {
- return d_ptr->manager->valueType(this);
- }
- /*!
- Returns this property's type.
- QtVariantPropertyManager provides several related functions:
- \l{QtVariantPropertyManager::enumTypeId()}{enumTypeId()},
- \l{QtVariantPropertyManager::flagTypeId()}{flagTypeId()} and
- \l{QtVariantPropertyManager::groupTypeId()}{groupTypeId()}.
- \sa valueType()
- */
- int QtVariantProperty::propertyType() const
- {
- return d_ptr->manager->propertyType(this);
- }
- /*!
- Sets the value of this property to \a value.
- The specified \a value must be of the type returned by
- valueType(), or of a type that can be converted to valueType()
- using the QVariant::canConvert() function; otherwise this function
- does nothing.
- \sa value()
- */
- #include <QDebug>
- void QtVariantProperty::setValue(const QVariant &value)
- {
- d_ptr->manager->setValue(this, value);
- }
- /*!
- Sets the \a attribute of property to \a value.
- QtVariantPropertyManager provides the related
- \l{QtVariantPropertyManager::setAttribute()}{setAttribute()}
- function.
- \sa attributeValue()
- */
- void QtVariantProperty::setAttribute(const QString &attribute, const QVariant &value)
- {
- d_ptr->manager->setAttribute(this, attribute, value);
- }
- class QtVariantPropertyManagerPrivate
- {
- QtVariantPropertyManager *q_ptr = nullptr;
- Q_DECLARE_PUBLIC(QtVariantPropertyManager)
- public:
- QtVariantPropertyManagerPrivate();
- bool m_creatingProperty = false;
- bool m_creatingSubProperties = false;
- bool m_destroyingSubProperties = false;
- int m_propertyType = 0;
- void slotValueChanged(QtProperty *property, int val);
- void slotRangeChanged(QtProperty *property, int min, int max);
- void slotSingleStepChanged(QtProperty *property, int step);
- void slotValueChanged(QtProperty *property, double val);
- void slotRangeChanged(QtProperty *property, double min, double max);
- void slotSingleStepChanged(QtProperty *property, double step);
- void slotDecimalsChanged(QtProperty *property, int prec);
- void slotValueChanged(QtProperty *property, bool val);
- void slotValueChanged(QtProperty *property, const QString &val);
- void slotRegExpChanged(QtProperty *property, const QRegExp ®Exp);
- void slotEchoModeChanged(QtProperty *property, int);
- void slotValueChanged(QtProperty *property, const QDate &val);
- void slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max);
- void slotValueChanged(QtProperty *property, const QTime &val);
- void slotValueChanged(QtProperty *property, const QDateTime &val);
- void slotValueChanged(QtProperty *property, const QKeySequence &val);
- void slotValueChanged(QtProperty *property, const QChar &val);
- void slotValueChanged(QtProperty *property, const QLocale &val);
- void slotValueChanged(QtProperty *property, const QPoint &val);
- void slotValueChanged(QtProperty *property, const QPointF &val);
- void slotValueChanged(QtProperty *property, const QSize &val);
- void slotRangeChanged(QtProperty *property, const QSize &min, const QSize &max);
- void slotValueChanged(QtProperty *property, const QSizeF &val);
- void slotRangeChanged(QtProperty *property, const QSizeF &min, const QSizeF &max);
- void slotValueChanged(QtProperty *property, const QRect &val);
- void slotConstraintChanged(QtProperty *property, const QRect &val);
- void slotValueChanged(QtProperty *property, const QRectF &val);
- void slotConstraintChanged(QtProperty *property, const QRectF &val);
- void slotValueChanged(QtProperty *property, const QColor &val);
- void slotEnumChanged(QtProperty *property, int val);
- void slotEnumNamesChanged(QtProperty *property, const QStringList &enumNames);
- void slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &enumIcons);
- void slotValueChanged(QtProperty *property, const QSizePolicy &val);
- void slotValueChanged(QtProperty *property, const QFont &val);
- void slotValueChanged(QtProperty *property, const QCursor &val);
- void slotFlagChanged(QtProperty *property, int val);
- void slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames);
- void slotReadOnlyChanged(QtProperty *property, bool readOnly);
- void slotTextVisibleChanged(QtProperty *property, bool textVisible);
- void slotPropertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after);
- void slotPropertyRemoved(QtProperty *property, QtProperty *parent);
- void valueChanged(QtProperty *property, const QVariant &val);
- int internalPropertyToType(QtProperty *property) const;
- QtVariantProperty *createSubProperty(QtVariantProperty *parent, QtVariantProperty *after,
- QtProperty *internal);
- void removeSubProperty(QtVariantProperty *property);
- QMap<int, QtAbstractPropertyManager *> m_typeToPropertyManager;
- QMap<int, QMap<QString, int> > m_typeToAttributeToAttributeType;
- QMap<const QtProperty *, QPair<QtVariantProperty *, int> > m_propertyToType;
- QMap<int, int> m_typeToValueType;
- QMap<QtProperty *, QtVariantProperty *> m_internalToProperty;
- const QString m_constraintAttribute;
- const QString m_singleStepAttribute;
- const QString m_decimalsAttribute;
- const QString m_enumIconsAttribute;
- const QString m_enumNamesAttribute;
- const QString m_flagNamesAttribute;
- const QString m_maximumAttribute;
- const QString m_minimumAttribute;
- const QString m_regExpAttribute;
- const QString m_echoModeAttribute;
- const QString m_readOnlyAttribute;
- const QString m_textVisibleAttribute;
- };
- QtVariantPropertyManagerPrivate::QtVariantPropertyManagerPrivate() :
- m_constraintAttribute(QLatin1String("constraint")),
- m_singleStepAttribute(QLatin1String("singleStep")),
- m_decimalsAttribute(QLatin1String("decimals")),
- m_enumIconsAttribute(QLatin1String("enumIcons")),
- m_enumNamesAttribute(QLatin1String("enumNames")),
- m_flagNamesAttribute(QLatin1String("flagNames")),
- m_maximumAttribute(QLatin1String("maximum")),
- m_minimumAttribute(QLatin1String("minimum")),
- m_regExpAttribute(QLatin1String("regExp")),
- m_echoModeAttribute(QLatin1String("echoMode")),
- m_readOnlyAttribute(QLatin1String("readOnly")),
- m_textVisibleAttribute(QLatin1String("textVisible"))
- {
- }
- int QtVariantPropertyManagerPrivate::internalPropertyToType(QtProperty *property) const
- {
- int type = 0;
- QtAbstractPropertyManager *internPropertyManager = property->propertyManager();
- if (qobject_cast<QtIntPropertyManager *>(internPropertyManager))
- type = QVariant::Int;
- else if (qobject_cast<QtEnumPropertyManager *>(internPropertyManager))
- type = QtVariantPropertyManager::enumTypeId();
- else if (qobject_cast<QtBoolPropertyManager *>(internPropertyManager))
- type = QVariant::Bool;
- else if (qobject_cast<QtDoublePropertyManager *>(internPropertyManager))
- type = QVariant::Double;
- return type;
- }
- QtVariantProperty *QtVariantPropertyManagerPrivate::createSubProperty(QtVariantProperty *parent,
- QtVariantProperty *after, QtProperty *internal)
- {
- int type = internalPropertyToType(internal);
- if (!type)
- return 0;
- bool wasCreatingSubProperties = m_creatingSubProperties;
- m_creatingSubProperties = true;
- QtVariantProperty *varChild = q_ptr->addProperty(type, internal->propertyName());
- m_creatingSubProperties = wasCreatingSubProperties;
- varChild->setPropertyName(internal->propertyName());
- varChild->setToolTip(internal->toolTip());
- varChild->setStatusTip(internal->statusTip());
- varChild->setWhatsThis(internal->whatsThis());
- parent->insertSubProperty(varChild, after);
- m_internalToProperty[internal] = varChild;
- propertyToWrappedProperty()->insert(varChild, internal);
- return varChild;
- }
- void QtVariantPropertyManagerPrivate::removeSubProperty(QtVariantProperty *property)
- {
- QtProperty *internChild = wrappedProperty(property);
- bool wasDestroyingSubProperties = m_destroyingSubProperties;
- m_destroyingSubProperties = true;
- delete property;
- m_destroyingSubProperties = wasDestroyingSubProperties;
- m_internalToProperty.remove(internChild);
- propertyToWrappedProperty()->remove(property);
- }
- void QtVariantPropertyManagerPrivate::slotPropertyInserted(QtProperty *property,
- QtProperty *parent, QtProperty *after)
- {
- if (m_creatingProperty)
- return;
- QtVariantProperty *varParent = m_internalToProperty.value(parent, 0);
- if (!varParent)
- return;
- QtVariantProperty *varAfter = 0;
- if (after) {
- varAfter = m_internalToProperty.value(after, 0);
- if (!varAfter)
- return;
- }
- createSubProperty(varParent, varAfter, property);
- }
- void QtVariantPropertyManagerPrivate::slotPropertyRemoved(QtProperty *property, QtProperty *parent)
- {
- Q_UNUSED(parent)
- QtVariantProperty *varProperty = m_internalToProperty.value(property, 0);
- if (!varProperty)
- return;
- removeSubProperty(varProperty);
- }
- void QtVariantPropertyManagerPrivate::valueChanged(QtProperty *property, const QVariant &val)
- {
- QtVariantProperty *varProp = m_internalToProperty.value(property, 0);
- if (!varProp)
- return;
- emit q_ptr->valueChanged(varProp, val);
- emit q_ptr->propertyChanged(varProp);
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, int val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, int min, int max)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
- emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
- emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
- }
- }
- void QtVariantPropertyManagerPrivate::slotSingleStepChanged(QtProperty *property, int step)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
- emit q_ptr->attributeChanged(varProp, m_singleStepAttribute, QVariant(step));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, double val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, double min, double max)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
- emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
- emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
- }
- }
- void QtVariantPropertyManagerPrivate::slotSingleStepChanged(QtProperty *property, double step)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
- emit q_ptr->attributeChanged(varProp, m_singleStepAttribute, QVariant(step));
- }
- void QtVariantPropertyManagerPrivate::slotDecimalsChanged(QtProperty *property, int prec)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
- emit q_ptr->attributeChanged(varProp, m_decimalsAttribute, QVariant(prec));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, bool val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QString &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotRegExpChanged(QtProperty *property, const QRegExp ®Exp)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
- emit q_ptr->attributeChanged(varProp, m_regExpAttribute, QVariant(regExp));
- }
- void QtVariantPropertyManagerPrivate::slotEchoModeChanged(QtProperty *property, int mode)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
- emit q_ptr->attributeChanged(varProp, m_echoModeAttribute, QVariant(mode));
- }
- void QtVariantPropertyManagerPrivate::slotReadOnlyChanged(QtProperty *property, bool readOnly)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
- emit q_ptr->attributeChanged(varProp, m_readOnlyAttribute, QVariant(readOnly));
- }
- void QtVariantPropertyManagerPrivate::slotTextVisibleChanged(QtProperty *property, bool textVisible)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
- emit q_ptr->attributeChanged(varProp, m_textVisibleAttribute, QVariant(textVisible));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDate &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
- emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
- emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
- }
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QTime &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDateTime &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QKeySequence &val)
- {
- QVariant v;
- qVariantSetValue(v, val);
- valueChanged(property, v);
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QChar &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QLocale &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QPoint &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QPointF &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSize &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QSize &min, const QSize &max)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
- emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
- emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
- }
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSizeF &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QSizeF &min, const QSizeF &max)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
- emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
- emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
- }
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QRect &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotConstraintChanged(QtProperty *property, const QRect &constraint)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
- emit q_ptr->attributeChanged(varProp, m_constraintAttribute, QVariant(constraint));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QRectF &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotConstraintChanged(QtProperty *property, const QRectF &constraint)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
- emit q_ptr->attributeChanged(varProp, m_constraintAttribute, QVariant(constraint));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QColor &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotEnumNamesChanged(QtProperty *property, const QStringList &enumNames)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
- emit q_ptr->attributeChanged(varProp, m_enumNamesAttribute, QVariant(enumNames));
- }
- void QtVariantPropertyManagerPrivate::slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &enumIcons)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
- QVariant v;
- qVariantSetValue(v, enumIcons);
- emit q_ptr->attributeChanged(varProp, m_enumIconsAttribute, v);
- }
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSizePolicy &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QFont &val)
- {
- valueChanged(property, QVariant(val));
- }
- void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QCursor &val)
- {
- #ifndef QT_NO_CURSOR
- valueChanged(property, QVariant(val));
- #endif
- }
- void QtVariantPropertyManagerPrivate::slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames)
- {
- if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
- emit q_ptr->attributeChanged(varProp, m_flagNamesAttribute, QVariant(flagNames));
- }
- /*!
- \class QtVariantPropertyManager
- \brief The QtVariantPropertyManager class provides and manages QVariant based properties.
- QtVariantPropertyManager provides the addProperty() function which
- creates QtVariantProperty objects. The QtVariantProperty class is
- a convenience class handling QVariant based properties inheriting
- QtProperty. A QtProperty object created by a
- QtVariantPropertyManager instance can be converted into a
- QtVariantProperty object using the variantProperty() function.
- The property's value can be retrieved using the value(), and set
- using the setValue() slot. In addition the property's type, and
- the type of its value, can be retrieved using the propertyType()
- and valueType() functions respectively.
- A property's type is a QVariant::Type enumerator value, and
- usually a property's type is the same as its value type. But for
- some properties the types differ, for example for enums, flags and
- group types in which case QtVariantPropertyManager provides the
- enumTypeId(), flagTypeId() and groupTypeId() functions,
- respectively, to identify their property type (the value types are
- QVariant::Int for the enum and flag types, and QVariant::Invalid
- for the group type).
- Use the isPropertyTypeSupported() function to check if a particular
- property type is supported. The currently supported property types
- are:
- \table
- \header
- \o Property Type
- \o Property Type Id
- \row
- \o int
- \o QVariant::Int
- \row
- \o double
- \o QVariant::Double
- \row
- \o bool
- \o QVariant::Bool
- \row
- \o QString
- \o QVariant::String
- \row
- \o QDate
- \o QVariant::Date
- \row
- \o QTime
- \o QVariant::Time
- \row
- \o QDateTime
- \o QVariant::DateTime
- \row
- \o QKeySequence
- \o QVariant::KeySequence
- \row
- \o QChar
- \o QVariant::Char
- \row
- \o QLocale
- \o QVariant::Locale
- \row
- \o QPoint
- \o QVariant::Point
- \row
- \o QPointF
- \o QVariant::PointF
- \row
- \o QSize
- \o QVariant::Size
- \row
- \o QSizeF
- \o QVariant::SizeF
- \row
- \o QRect
- \o QVariant::Rect
- \row
- \o QRectF
- \o QVariant::RectF
- \row
- \o QColor
- \o QVariant::Color
- \row
- \o QSizePolicy
- \o QVariant::SizePolicy
- \row
- \o QFont
- \o QVariant::Font
- \row
- \o QCursor
- \o QVariant::Cursor
- \row
- \o enum
- \o enumTypeId()
- \row
- \o flag
- \o flagTypeId()
- \row
- \o group
- \o groupTypeId()
- \endtable
- Each property type can provide additional attributes,
- e.g. QVariant::Int and QVariant::Double provides minimum and
- maximum values. The currently supported attributes are:
- \table
- \header
- \o Property Type
- \o Attribute Name
- \o Attribute Type
- \row
- \o \c int
- \o minimum
- \o QVariant::Int
- \row
- \o
- \o maximum
- \o QVariant::Int
- \row
- \o
- \o singleStep
- \o QVariant::Int
- \row
- \o \c double
- \o minimum
- \o QVariant::Double
- \row
- \o
- \o maximum
- \o QVariant::Double
- \row
- \o
- \o singleStep
- \o QVariant::Double
- \row
- \o
- \o decimals
- \o QVariant::Int
- \row
- \o \c bool
- \o textVisible
- \o QVariant::Bool
- \row
- \o QString
- \o regExp
- \o QVariant::RegExp
- \row
- \o
- \o echoMode
- \o QVariant::Int
- \row
- \o QDate
- \o minimum
- \o QVariant::Date
- \row
- \o
- \o maximum
- \o QVariant::Date
- \row
- \o QPointF
- \o decimals
- \o QVariant::Int
- \row
- \o QSize
- \o minimum
- \o QVariant::Size
- \row
- \o
- \o maximum
- \o QVariant::Size
- \row
- \o QSizeF
- \o minimum
- \o QVariant::SizeF
- \row
- \o
- \o maximum
- \o QVariant::SizeF
- \row
- \o
- \o decimals
- \o QVariant::Int
- \row
- \o QRect
- \o constraint
- \o QVariant::Rect
- \row
- \o QRectF
- \o constraint
- \o QVariant::RectF
- \row
- \o
- \o decimals
- \o QVariant::Int
- \row
- \o \c enum
- \o enumNames
- \o QVariant::StringList
- \row
- \o
- \o enumIcons
- \o iconMapTypeId()
- \row
- \o \c flag
- \o flagNames
- \o QVariant::StringList
- \endtable
- The attributes for a given property type can be retrieved using
- the attributes() function. Each attribute has a value type which
- can be retrieved using the attributeType() function, and a value
- accessible through the attributeValue() function. In addition, the
- value can be set using the setAttribute() slot.
- QtVariantManager also provides the valueChanged() signal which is
- emitted whenever a property created by this manager change, and
- the attributeChanged() signal which is emitted whenever an
- attribute of such a property changes.
- \sa QtVariantProperty, QtVariantEditorFactory
- */
- /*!
- \fn void QtVariantPropertyManager::valueChanged(QtProperty *property, const QVariant &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 QtVariantPropertyManager::attributeChanged(QtProperty *property,
- const QString &attribute, const QVariant &value)
- This signal is emitted whenever an attribute of a property created
- by this manager changes its value, passing a pointer to the \a
- property, the \a attribute and the new \a value as parameters.
- \sa setAttribute()
- */
- /*!
- Creates a manager with the given \a parent.
- */
- QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent)
- : QtAbstractPropertyManager(parent)
- {
- d_ptr = new QtVariantPropertyManagerPrivate;
- d_ptr->q_ptr = this;
- d_ptr->m_creatingProperty = false;
- d_ptr->m_creatingSubProperties = false;
- d_ptr->m_destroyingSubProperties = false;
- d_ptr->m_propertyType = 0;
- // IntPropertyManager
- QtIntPropertyManager *intPropertyManager = new QtIntPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Int] = intPropertyManager;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_minimumAttribute] = QVariant::Int;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_maximumAttribute] = QVariant::Int;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_singleStepAttribute] = QVariant::Int;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_readOnlyAttribute] = QVariant::Bool;
- d_ptr->m_typeToValueType[QVariant::Int] = QVariant::Int;
- connect(intPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(intPropertyManager, SIGNAL(rangeChanged(QtProperty *, int, int)),
- this, SLOT(slotRangeChanged(QtProperty *, int, int)));
- connect(intPropertyManager, SIGNAL(singleStepChanged(QtProperty *, int)),
- this, SLOT(slotSingleStepChanged(QtProperty *, int)));
- // DoublePropertyManager
- QtDoublePropertyManager *doublePropertyManager = new QtDoublePropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Double] = doublePropertyManager;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_minimumAttribute] =
- QVariant::Double;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_maximumAttribute] =
- QVariant::Double;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_singleStepAttribute] =
- QVariant::Double;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_decimalsAttribute] =
- QVariant::Int;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_readOnlyAttribute] =
- QVariant::Bool;
- d_ptr->m_typeToValueType[QVariant::Double] = QVariant::Double;
- connect(doublePropertyManager, SIGNAL(valueChanged(QtProperty *, double)),
- this, SLOT(slotValueChanged(QtProperty *, double)));
- connect(doublePropertyManager, SIGNAL(rangeChanged(QtProperty *, double, double)),
- this, SLOT(slotRangeChanged(QtProperty *, double, double)));
- connect(doublePropertyManager, SIGNAL(singleStepChanged(QtProperty *, double)),
- this, SLOT(slotSingleStepChanged(QtProperty *, double)));
- connect(doublePropertyManager, SIGNAL(decimalsChanged(QtProperty *, int)),
- this, SLOT(slotDecimalsChanged(QtProperty *, int)));
- // BoolPropertyManager
- QtBoolPropertyManager *boolPropertyManager = new QtBoolPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Bool] = boolPropertyManager;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Bool][d_ptr->m_textVisibleAttribute] = QVariant::Bool;
- d_ptr->m_typeToValueType[QVariant::Bool] = QVariant::Bool;
- connect(boolPropertyManager, SIGNAL(valueChanged(QtProperty *, bool)),
- this, SLOT(slotValueChanged(QtProperty *, bool)));
- connect(boolPropertyManager, SIGNAL(textVisibleChanged(QtProperty*, bool)),
- this, SLOT(slotTextVisibleChanged(QtProperty*, bool)));
- // StringPropertyManager
- QtStringPropertyManager *stringPropertyManager = new QtStringPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::String] = stringPropertyManager;
- d_ptr->m_typeToValueType[QVariant::String] = QVariant::String;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_regExpAttribute] =
- QVariant::RegExp;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_echoModeAttribute] =
- QVariant::Int;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_readOnlyAttribute] =
- QVariant::Bool;
- connect(stringPropertyManager, SIGNAL(valueChanged(QtProperty *, const QString &)),
- this, SLOT(slotValueChanged(QtProperty *, const QString &)));
- connect(stringPropertyManager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)),
- this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &)));
- connect(stringPropertyManager, SIGNAL(echoModeChanged(QtProperty*,int)),
- this, SLOT(slotEchoModeChanged(QtProperty*, int)));
- connect(stringPropertyManager, SIGNAL(readOnlyChanged(QtProperty*, bool)),
- this, SLOT(slotReadOnlyChanged(QtProperty*, bool)));
- // DatePropertyManager
- QtDatePropertyManager *datePropertyManager = new QtDatePropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Date] = datePropertyManager;
- d_ptr->m_typeToValueType[QVariant::Date] = QVariant::Date;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Date][d_ptr->m_minimumAttribute] =
- QVariant::Date;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Date][d_ptr->m_maximumAttribute] =
- QVariant::Date;
- connect(datePropertyManager, SIGNAL(valueChanged(QtProperty *, const QDate &)),
- this, SLOT(slotValueChanged(QtProperty *, const QDate &)));
- connect(datePropertyManager, SIGNAL(rangeChanged(QtProperty *, const QDate &, const QDate &)),
- this, SLOT(slotRangeChanged(QtProperty *, const QDate &, const QDate &)));
- // TimePropertyManager
- QtTimePropertyManager *timePropertyManager = new QtTimePropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Time] = timePropertyManager;
- d_ptr->m_typeToValueType[QVariant::Time] = QVariant::Time;
- connect(timePropertyManager, SIGNAL(valueChanged(QtProperty *, const QTime &)),
- this, SLOT(slotValueChanged(QtProperty *, const QTime &)));
- // DateTimePropertyManager
- QtDateTimePropertyManager *dateTimePropertyManager = new QtDateTimePropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::DateTime] = dateTimePropertyManager;
- d_ptr->m_typeToValueType[QVariant::DateTime] = QVariant::DateTime;
- connect(dateTimePropertyManager, SIGNAL(valueChanged(QtProperty *, const QDateTime &)),
- this, SLOT(slotValueChanged(QtProperty *, const QDateTime &)));
- // KeySequencePropertyManager
- QtKeySequencePropertyManager *keySequencePropertyManager = new QtKeySequencePropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::KeySequence] = keySequencePropertyManager;
- d_ptr->m_typeToValueType[QVariant::KeySequence] = QVariant::KeySequence;
- connect(keySequencePropertyManager, SIGNAL(valueChanged(QtProperty *, const QKeySequence &)),
- this, SLOT(slotValueChanged(QtProperty *, const QKeySequence &)));
- // CharPropertyManager
- QtCharPropertyManager *charPropertyManager = new QtCharPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Char] = charPropertyManager;
- d_ptr->m_typeToValueType[QVariant::Char] = QVariant::Char;
- connect(charPropertyManager, SIGNAL(valueChanged(QtProperty *, const QChar &)),
- this, SLOT(slotValueChanged(QtProperty *, const QChar &)));
- // LocalePropertyManager
- QtLocalePropertyManager *localePropertyManager = new QtLocalePropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Locale] = localePropertyManager;
- d_ptr->m_typeToValueType[QVariant::Locale] = QVariant::Locale;
- connect(localePropertyManager, SIGNAL(valueChanged(QtProperty *, const QLocale &)),
- this, SLOT(slotValueChanged(QtProperty *, const QLocale &)));
- connect(localePropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(localePropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)));
- connect(localePropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *)));
- // PointPropertyManager
- QtPointPropertyManager *pointPropertyManager = new QtPointPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Point] = pointPropertyManager;
- d_ptr->m_typeToValueType[QVariant::Point] = QVariant::Point;
- connect(pointPropertyManager, SIGNAL(valueChanged(QtProperty *, const QPoint &)),
- this, SLOT(slotValueChanged(QtProperty *, const QPoint &)));
- connect(pointPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(pointPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)));
- connect(pointPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *)));
- // PointFPropertyManager
- QtPointFPropertyManager *pointFPropertyManager = new QtPointFPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::PointF] = pointFPropertyManager;
- d_ptr->m_typeToValueType[QVariant::PointF] = QVariant::PointF;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::PointF][d_ptr->m_decimalsAttribute] =
- QVariant::Int;
- connect(pointFPropertyManager, SIGNAL(valueChanged(QtProperty *, const QPointF &)),
- this, SLOT(slotValueChanged(QtProperty *, const QPointF &)));
- connect(pointFPropertyManager, SIGNAL(decimalsChanged(QtProperty *, int)),
- this, SLOT(slotDecimalsChanged(QtProperty *, int)));
- connect(pointFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty *, double)),
- this, SLOT(slotValueChanged(QtProperty *, double)));
- connect(pointFPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)));
- connect(pointFPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *)));
- // SizePropertyManager
- QtSizePropertyManager *sizePropertyManager = new QtSizePropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Size] = sizePropertyManager;
- d_ptr->m_typeToValueType[QVariant::Size] = QVariant::Size;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Size][d_ptr->m_minimumAttribute] =
- QVariant::Size;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Size][d_ptr->m_maximumAttribute] =
- QVariant::Size;
- connect(sizePropertyManager, SIGNAL(valueChanged(QtProperty *, const QSize &)),
- this, SLOT(slotValueChanged(QtProperty *, const QSize &)));
- connect(sizePropertyManager, SIGNAL(rangeChanged(QtProperty *, const QSize &, const QSize &)),
- this, SLOT(slotRangeChanged(QtProperty *, const QSize &, const QSize &)));
- connect(sizePropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(sizePropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty *, int, int)),
- this, SLOT(slotRangeChanged(QtProperty *, int, int)));
- connect(sizePropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)));
- connect(sizePropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *)));
- // SizeFPropertyManager
- QtSizeFPropertyManager *sizeFPropertyManager = new QtSizeFPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::SizeF] = sizeFPropertyManager;
- d_ptr->m_typeToValueType[QVariant::SizeF] = QVariant::SizeF;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_minimumAttribute] =
- QVariant::SizeF;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_maximumAttribute] =
- QVariant::SizeF;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_decimalsAttribute] =
- QVariant::Int;
- connect(sizeFPropertyManager, SIGNAL(valueChanged(QtProperty *, const QSizeF &)),
- this, SLOT(slotValueChanged(QtProperty *, const QSizeF &)));
- connect(sizeFPropertyManager, SIGNAL(rangeChanged(QtProperty *, const QSizeF &, const QSizeF &)),
- this, SLOT(slotRangeChanged(QtProperty *, const QSizeF &, const QSizeF &)));
- connect(sizeFPropertyManager, SIGNAL(decimalsChanged(QtProperty *, int)),
- this, SLOT(slotDecimalsChanged(QtProperty *, int)));
- connect(sizeFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty *, double)),
- this, SLOT(slotValueChanged(QtProperty *, double)));
- connect(sizeFPropertyManager->subDoublePropertyManager(), SIGNAL(rangeChanged(QtProperty *, double, double)),
- this, SLOT(slotRangeChanged(QtProperty *, double, double)));
- connect(sizeFPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)));
- connect(sizeFPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *)));
- // RectPropertyManager
- QtRectPropertyManager *rectPropertyManager = new QtRectPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Rect] = rectPropertyManager;
- d_ptr->m_typeToValueType[QVariant::Rect] = QVariant::Rect;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::Rect][d_ptr->m_constraintAttribute] =
- QVariant::Rect;
- connect(rectPropertyManager, SIGNAL(valueChanged(QtProperty *, const QRect &)),
- this, SLOT(slotValueChanged(QtProperty *, const QRect &)));
- connect(rectPropertyManager, SIGNAL(constraintChanged(QtProperty *, const QRect &)),
- this, SLOT(slotConstraintChanged(QtProperty *, const QRect &)));
- connect(rectPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(rectPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty *, int, int)),
- this, SLOT(slotRangeChanged(QtProperty *, int, int)));
- connect(rectPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)));
- connect(rectPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *)));
- // RectFPropertyManager
- QtRectFPropertyManager *rectFPropertyManager = new QtRectFPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::RectF] = rectFPropertyManager;
- d_ptr->m_typeToValueType[QVariant::RectF] = QVariant::RectF;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::RectF][d_ptr->m_constraintAttribute] =
- QVariant::RectF;
- d_ptr->m_typeToAttributeToAttributeType[QVariant::RectF][d_ptr->m_decimalsAttribute] =
- QVariant::Int;
- connect(rectFPropertyManager, SIGNAL(valueChanged(QtProperty *, const QRectF &)),
- this, SLOT(slotValueChanged(QtProperty *, const QRectF &)));
- connect(rectFPropertyManager, SIGNAL(constraintChanged(QtProperty *, const QRectF &)),
- this, SLOT(slotConstraintChanged(QtProperty *, const QRectF &)));
- connect(rectFPropertyManager, SIGNAL(decimalsChanged(QtProperty *, int)),
- this, SLOT(slotDecimalsChanged(QtProperty *, int)));
- connect(rectFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty *, double)),
- this, SLOT(slotValueChanged(QtProperty *, double)));
- connect(rectFPropertyManager->subDoublePropertyManager(), SIGNAL(rangeChanged(QtProperty *, double, double)),
- this, SLOT(slotRangeChanged(QtProperty *, double, double)));
- connect(rectFPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)));
- connect(rectFPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *)));
- // ColorPropertyManager
- QtColorPropertyManager *colorPropertyManager = new QtColorPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Color] = colorPropertyManager;
- d_ptr->m_typeToValueType[QVariant::Color] = QVariant::Color;
- connect(colorPropertyManager, SIGNAL(valueChanged(QtProperty *, const QColor &)),
- this, SLOT(slotValueChanged(QtProperty *, const QColor &)));
- connect(colorPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(colorPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)));
- connect(colorPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *)));
- // EnumPropertyManager
- int enumId = enumTypeId();
- QtEnumPropertyManager *enumPropertyManager = new QtEnumPropertyManager(this);
- d_ptr->m_typeToPropertyManager[enumId] = enumPropertyManager;
- d_ptr->m_typeToValueType[enumId] = QVariant::Int;
- d_ptr->m_typeToAttributeToAttributeType[enumId][d_ptr->m_enumNamesAttribute] =
- QVariant::StringList;
- d_ptr->m_typeToAttributeToAttributeType[enumId][d_ptr->m_enumIconsAttribute] =
- iconMapTypeId();
- connect(enumPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(enumPropertyManager, SIGNAL(enumNamesChanged(QtProperty *, const QStringList &)),
- this, SLOT(slotEnumNamesChanged(QtProperty *, const QStringList &)));
- connect(enumPropertyManager, SIGNAL(enumIconsChanged(QtProperty *, const QMap<int, QIcon> &)),
- this, SLOT(slotEnumIconsChanged(QtProperty *, const QMap<int, QIcon> &)));
- // SizePolicyPropertyManager
- QtSizePolicyPropertyManager *sizePolicyPropertyManager = new QtSizePolicyPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::SizePolicy] = sizePolicyPropertyManager;
- d_ptr->m_typeToValueType[QVariant::SizePolicy] = QVariant::SizePolicy;
- connect(sizePolicyPropertyManager, SIGNAL(valueChanged(QtProperty *, const QSizePolicy &)),
- this, SLOT(slotValueChanged(QtProperty *, const QSizePolicy &)));
- connect(sizePolicyPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(sizePolicyPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty *, int, int)),
- this, SLOT(slotRangeChanged(QtProperty *, int, int)));
- connect(sizePolicyPropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(sizePolicyPropertyManager->subEnumPropertyManager(),
- SIGNAL(enumNamesChanged(QtProperty *, const QStringList &)),
- this, SLOT(slotEnumNamesChanged(QtProperty *, const QStringList &)));
- connect(sizePolicyPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)));
- connect(sizePolicyPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *)));
- // FontPropertyManager
- QtFontPropertyManager *fontPropertyManager = new QtFontPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Font] = fontPropertyManager;
- d_ptr->m_typeToValueType[QVariant::Font] = QVariant::Font;
- connect(fontPropertyManager, SIGNAL(valueChanged(QtProperty *, const QFont &)),
- this, SLOT(slotValueChanged(QtProperty *, const QFont &)));
- connect(fontPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(fontPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty *, int, int)),
- this, SLOT(slotRangeChanged(QtProperty *, int, int)));
- connect(fontPropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(fontPropertyManager->subEnumPropertyManager(),
- SIGNAL(enumNamesChanged(QtProperty *, const QStringList &)),
- this, SLOT(slotEnumNamesChanged(QtProperty *, const QStringList &)));
- connect(fontPropertyManager->subBoolPropertyManager(), SIGNAL(valueChanged(QtProperty *, bool)),
- this, SLOT(slotValueChanged(QtProperty *, bool)));
- connect(fontPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)));
- connect(fontPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *)));
- // CursorPropertyManager
- QtCursorPropertyManager *cursorPropertyManager = new QtCursorPropertyManager(this);
- d_ptr->m_typeToPropertyManager[QVariant::Cursor] = cursorPropertyManager;
- d_ptr->m_typeToValueType[QVariant::Cursor] = QVariant::Cursor;
- connect(cursorPropertyManager, SIGNAL(valueChanged(QtProperty *, const QCursor &)),
- this, SLOT(slotValueChanged(QtProperty *, const QCursor &)));
- // FlagPropertyManager
- int flagId = flagTypeId();
- QtFlagPropertyManager *flagPropertyManager = new QtFlagPropertyManager(this);
- d_ptr->m_typeToPropertyManager[flagId] = flagPropertyManager;
- d_ptr->m_typeToValueType[flagId] = QVariant::Int;
- d_ptr->m_typeToAttributeToAttributeType[flagId][d_ptr->m_flagNamesAttribute] =
- QVariant::StringList;
- connect(flagPropertyManager, SIGNAL(valueChanged(QtProperty *, int)),
- this, SLOT(slotValueChanged(QtProperty *, int)));
- connect(flagPropertyManager, SIGNAL(flagNamesChanged(QtProperty *, const QStringList &)),
- this, SLOT(slotFlagNamesChanged(QtProperty *, const QStringList &)));
- connect(flagPropertyManager->subBoolPropertyManager(), SIGNAL(valueChanged(QtProperty *, bool)),
- this, SLOT(slotValueChanged(QtProperty *, bool)));
- connect(flagPropertyManager, SIGNAL(propertyInserted(QtProperty *, QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)));
- connect(flagPropertyManager, SIGNAL(propertyRemoved(QtProperty *, QtProperty *)),
- this, SLOT(slotPropertyRemoved(QtProperty *, QtProperty *)));
- // FlagPropertyManager
- int groupId = groupTypeId();
- QtGroupPropertyManager *groupPropertyManager = new QtGroupPropertyManager(this);
- d_ptr->m_typeToPropertyManager[groupId] = groupPropertyManager;
- d_ptr->m_typeToValueType[groupId] = QVariant::Invalid;
- }
- /*!
- Destroys this manager, and all the properties it has created.
- */
- QtVariantPropertyManager::~QtVariantPropertyManager()
- {
- clear();
- delete d_ptr;
- }
- /*!
- Returns the given \a property converted into a QtVariantProperty.
- If the \a property was not created by this variant manager, the
- function returns 0.
- \sa createProperty()
- */
- QtVariantProperty *QtVariantPropertyManager::variantProperty(const QtProperty *property) const
- {
- // 通过 QtProperty 找到对应的 QtVariantProperty
- const QMap<const QtProperty *, QPair<QtVariantProperty *, int> >::const_iterator it = d_ptr->m_propertyToType.constFind(property);
- if (it == d_ptr->m_propertyToType.constEnd())
- return 0;
- return it.value().first;
- }
- /*!
- Returns true if the given \a propertyType is supported by this
- variant manager; otherwise false.
- \sa propertyType()
- */
- bool QtVariantPropertyManager::isPropertyTypeSupported(int propertyType) const
- {
- if (d_ptr->m_typeToValueType.contains(propertyType))
- return true;
- return false;
- }
- /*!
- Creates and returns a variant property of the given \a propertyType
- with the given \a name.
- If the specified \a propertyType is not supported by this variant
- manager, this function returns 0.
- Do not use the inherited
- QtAbstractPropertyManager::addProperty() function to create a
- variant property (that function will always return 0 since it will
- not be clear what type the property should have).
- \sa isPropertyTypeSupported()
- */
- /// <summary>
- /// 根据属性类型创建属性相关数据结构
- /// </summary>
- /// <param name="propertyType"></param>
- /// <param name="name"></param>
- /// <returns></returns>
- QtVariantProperty *QtVariantPropertyManager::addProperty(int propertyType, const QString &name)
- {
- // 如果是不支持的属性则不予建立
- if (!isPropertyTypeSupported(propertyType))
- return 0;
- bool wasCreating = d_ptr->m_creatingProperty;
- d_ptr->m_creatingProperty = true;
- // 保存属性Type
- d_ptr->m_propertyType = propertyType;
- // 首先通过基类创建并且初始化本属性
- QtProperty *property = QtAbstractPropertyManager::addProperty(name);
- d_ptr->m_creatingProperty = wasCreating;
- d_ptr->m_propertyType = 0;
- if (!property)
- return 0;
- // 通过 QtProperty 转换为 QtVariantProperty 并返回
- return variantProperty(property);
- }
- /*!
- Returns the given \a property's value.
- If the given \a property is not managed by this manager, this
- function returns an invalid variant.
- \sa setValue()
- */
- QVariant QtVariantPropertyManager::value(const QtProperty *property) const
- {
- QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
- if (internProp == 0)
- return QVariant();
- QtAbstractPropertyManager *manager = internProp->propertyManager();
- if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
- return intManager->value(internProp);
- } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
- return doubleManager->value(internProp);
- } else if (QtBoolPropertyManager *boolManager = qobject_cast<QtBoolPropertyManager *>(manager)) {
- return boolManager->value(internProp);
- } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
- return stringManager->value(internProp);
- } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
- return dateManager->value(internProp);
- } else if (QtTimePropertyManager *timeManager = qobject_cast<QtTimePropertyManager *>(manager)) {
- return timeManager->value(internProp);
- } else if (QtDateTimePropertyManager *dateTimeManager = qobject_cast<QtDateTimePropertyManager *>(manager)) {
- return dateTimeManager->value(internProp);
- } else if (QtKeySequencePropertyManager *keySequenceManager = qobject_cast<QtKeySequencePropertyManager *>(manager)) {
- #if QT_VERSION < 0x050000
- return keySequenceManager->value(internProp);
- #else
- return QVariant::fromValue(keySequenceManager->value(internProp));
- #endif
- } else if (QtCharPropertyManager *charManager = qobject_cast<QtCharPropertyManager *>(manager)) {
- return charManager->value(internProp);
- } else if (QtLocalePropertyManager *localeManager = qobject_cast<QtLocalePropertyManager *>(manager)) {
- return localeManager->value(internProp);
- } else if (QtPointPropertyManager *pointManager = qobject_cast<QtPointPropertyManager *>(manager)) {
- return pointManager->value(internProp);
- } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
- return pointFManager->value(internProp);
- } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
- return sizeManager->value(internProp);
- } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
- return sizeFManager->value(internProp);
- } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
- return rectManager->value(internProp);
- } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
- return rectFManager->value(internProp);
- } else if (QtColorPropertyManager *colorManager = qobject_cast<QtColorPropertyManager *>(manager)) {
- return colorManager->value(internProp);
- } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
- return enumManager->value(internProp);
- } else if (QtSizePolicyPropertyManager *sizePolicyManager =
- qobject_cast<QtSizePolicyPropertyManager *>(manager)) {
- return sizePolicyManager->value(internProp);
- } else if (QtFontPropertyManager *fontManager = qobject_cast<QtFontPropertyManager *>(manager)) {
- return fontManager->value(internProp);
- #ifndef QT_NO_CURSOR
- } else if (QtCursorPropertyManager *cursorManager = qobject_cast<QtCursorPropertyManager *>(manager)) {
- return cursorManager->value(internProp);
- #endif
- } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
- return flagManager->value(internProp);
- }
- return QVariant();
- }
- /*!
- Returns the given \a property's value type.
- \sa propertyType()
- */
- int QtVariantPropertyManager::valueType(const QtProperty *property) const
- {
- int propType = propertyType(property);
- return valueType(propType);
- }
- /*!
- \overload
- Returns the value type associated with the given \a propertyType.
- */
- int QtVariantPropertyManager::valueType(int propertyType) const
- {
- if (d_ptr->m_typeToValueType.contains(propertyType))
- return d_ptr->m_typeToValueType[propertyType];
- return 0;
- }
- /*!
- Returns the given \a property's type.
- \sa valueType()
- */
- int QtVariantPropertyManager::propertyType(const QtProperty *property) const
- {
- const QMap<const QtProperty *, QPair<QtVariantProperty *, int> >::const_iterator it = d_ptr->m_propertyToType.constFind(property);
- if (it == d_ptr->m_propertyToType.constEnd())
- return 0;
- return it.value().second;
- }
- /*!
- Returns the given \a property's value for the specified \a
- attribute
- If the given \a property was not created by \e this manager, or if
- the specified \a attribute does not exist, this function returns
- an invalid variant.
- \sa attributes(), attributeType(), setAttribute()
- */
- QVariant QtVariantPropertyManager::attributeValue(const QtProperty *property, const QString &attribute) const
- {
- int propType = propertyType(property);
- if (!propType)
- return QVariant();
- QMap<int, QMap<QString, int> >::ConstIterator it =
- d_ptr->m_typeToAttributeToAttributeType.find(propType);
- if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd())
- return QVariant();
- QMap<QString, int> attributes = it.value();
- QMap<QString, int>::ConstIterator itAttr = attributes.find(attribute);
- if (itAttr == attributes.constEnd())
- return QVariant();
- QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
- if (internProp == 0)
- return QVariant();
- QtAbstractPropertyManager *manager = internProp->propertyManager();
- if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_maximumAttribute)
- return intManager->maximum(internProp);
- if (attribute == d_ptr->m_minimumAttribute)
- return intManager->minimum(internProp);
- if (attribute == d_ptr->m_singleStepAttribute)
- return intManager->singleStep(internProp);
- if (attribute == d_ptr->m_readOnlyAttribute)
- return intManager->isReadOnly(internProp);
- return QVariant();
- } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
- if (attribute == d_ptr->m_maximumAttribute)
- return doubleManager->maximum(internProp);
- if (attribute == d_ptr->m_minimumAttribute)
- return doubleManager->minimum(internProp);
- if (attribute == d_ptr->m_singleStepAttribute)
- return doubleManager->singleStep(internProp);
- if (attribute == d_ptr->m_decimalsAttribute)
- return doubleManager->decimals(internProp);
- if (attribute == d_ptr->m_readOnlyAttribute)
- return doubleManager->isReadOnly(internProp);
- return QVariant();
- } else if (QtBoolPropertyManager *boolManager = qobject_cast<QtBoolPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_textVisibleAttribute)
- return boolManager->textVisible(internProp);
- return QVariant();
- } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_regExpAttribute)
- return stringManager->regExp(internProp);
- if (attribute == d_ptr->m_echoModeAttribute)
- return stringManager->echoMode(internProp);
- if (attribute == d_ptr->m_readOnlyAttribute)
- return stringManager->isReadOnly(internProp);
- return QVariant();
- } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
- if (attribute == d_ptr->m_maximumAttribute)
- return dateManager->maximum(internProp);
- if (attribute == d_ptr->m_minimumAttribute)
- return dateManager->minimum(internProp);
- return QVariant();
- } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_decimalsAttribute)
- return pointFManager->decimals(internProp);
- return QVariant();
- } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
- if (attribute == d_ptr->m_maximumAttribute)
- return sizeManager->maximum(internProp);
- if (attribute == d_ptr->m_minimumAttribute)
- return sizeManager->minimum(internProp);
- return QVariant();
- } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_maximumAttribute)
- return sizeFManager->maximum(internProp);
- if (attribute == d_ptr->m_minimumAttribute)
- return sizeFManager->minimum(internProp);
- if (attribute == d_ptr->m_decimalsAttribute)
- return sizeFManager->decimals(internProp);
- return QVariant();
- } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_constraintAttribute)
- return rectManager->constraint(internProp);
- return QVariant();
- } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_constraintAttribute)
- return rectFManager->constraint(internProp);
- if (attribute == d_ptr->m_decimalsAttribute)
- return rectFManager->decimals(internProp);
- return QVariant();
- } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_enumNamesAttribute)
- return enumManager->enumNames(internProp);
- if (attribute == d_ptr->m_enumIconsAttribute) {
- QVariant v;
- qVariantSetValue(v, enumManager->enumIcons(internProp));
- return v;
- }
- return QVariant();
- } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_flagNamesAttribute)
- return flagManager->flagNames(internProp);
- return QVariant();
- }
- return QVariant();
- }
- /*!
- Returns a list of the given \a propertyType 's attributes.
- \sa attributeValue(), attributeType()
- */
- QStringList QtVariantPropertyManager::attributes(int propertyType) const
- {
- QMap<int, QMap<QString, int> >::ConstIterator it =
- d_ptr->m_typeToAttributeToAttributeType.find(propertyType);
- if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd())
- return QStringList();
- return it.value().keys();
- }
- /*!
- Returns the type of the specified \a attribute of the given \a
- propertyType.
- If the given \a propertyType is not supported by \e this manager,
- or if the given \a propertyType does not possess the specified \a
- attribute, this function returns QVariant::Invalid.
- \sa attributes(), valueType()
- */
- int QtVariantPropertyManager::attributeType(int propertyType, const QString &attribute) const
- {
- QMap<int, QMap<QString, int> >::ConstIterator it =
- d_ptr->m_typeToAttributeToAttributeType.find(propertyType);
- if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd())
- return 0;
- QMap<QString, int> attributes = it.value();
- QMap<QString, int>::ConstIterator itAttr = attributes.find(attribute);
- if (itAttr == attributes.constEnd())
- return 0;
- return itAttr.value();
- }
- /*!
- \fn void QtVariantPropertyManager::setValue(QtProperty *property, const QVariant &value)
- Sets the value of the given \a property to \a value.
- The specified \a value must be of a type returned by valueType(),
- or of type that can be converted to valueType() using the
- QVariant::canConvert() function, otherwise this function does
- nothing.
- \sa value(), QtVariantProperty::setValue(), valueChanged()
- */
- // 根据属性的数据类型,调用不同的属性管理器来设置值
- void QtVariantPropertyManager::setValue(QtProperty *property, const QVariant &val)
- {
- int propType = val.userType();
- if (!propType)
- return;
- int valType = valueType(property);
- if (propType != valType && !val.canConvert(static_cast<QVariant::Type>(valType)))
- return;
- QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
- if (internProp == 0)
- return;
- QtAbstractPropertyManager *manager = internProp->propertyManager();
- if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
- intManager->setValue(internProp, qvariant_cast<int>(val));
- return;
- } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
- doubleManager->setValue(internProp, qvariant_cast<double>(val));
- return;
- } else if (QtBoolPropertyManager *boolManager = qobject_cast<QtBoolPropertyManager *>(manager)) {
- boolManager->setValue(internProp, qvariant_cast<bool>(val));
- return;
- } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
- stringManager->setValue(internProp, qvariant_cast<QString>(val));
- return;
- } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
- dateManager->setValue(internProp, qvariant_cast<QDate>(val));
- return;
- } else if (QtTimePropertyManager *timeManager = qobject_cast<QtTimePropertyManager *>(manager)) {
- timeManager->setValue(internProp, qvariant_cast<QTime>(val));
- return;
- } else if (QtDateTimePropertyManager *dateTimeManager = qobject_cast<QtDateTimePropertyManager *>(manager)) {
- dateTimeManager->setValue(internProp, qvariant_cast<QDateTime>(val));
- return;
- } else if (QtKeySequencePropertyManager *keySequenceManager = qobject_cast<QtKeySequencePropertyManager *>(manager)) {
- keySequenceManager->setValue(internProp, qvariant_cast<QKeySequence>(val));
- return;
- } else if (QtCharPropertyManager *charManager = qobject_cast<QtCharPropertyManager *>(manager)) {
- charManager->setValue(internProp, qvariant_cast<QChar>(val));
- return;
- } else if (QtLocalePropertyManager *localeManager = qobject_cast<QtLocalePropertyManager *>(manager)) {
- localeManager->setValue(internProp, qvariant_cast<QLocale>(val));
- return;
- } else if (QtPointPropertyManager *pointManager = qobject_cast<QtPointPropertyManager *>(manager)) {
- pointManager->setValue(internProp, qvariant_cast<QPoint>(val));
- return;
- } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
- pointFManager->setValue(internProp, qvariant_cast<QPointF>(val));
- return;
- } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
- sizeManager->setValue(internProp, qvariant_cast<QSize>(val));
- return;
- } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
- sizeFManager->setValue(internProp, qvariant_cast<QSizeF>(val));
- return;
- } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
- rectManager->setValue(internProp, qvariant_cast<QRect>(val));
- return;
- } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
- rectFManager->setValue(internProp, qvariant_cast<QRectF>(val));
- return;
- } else if (QtColorPropertyManager *colorManager = qobject_cast<QtColorPropertyManager *>(manager)) {
- colorManager->setValue(internProp, qvariant_cast<QColor>(val));
- return;
- } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
- enumManager->setValue(internProp, qvariant_cast<int>(val));
- return;
- } else if (QtSizePolicyPropertyManager *sizePolicyManager =
- qobject_cast<QtSizePolicyPropertyManager *>(manager)) {
- sizePolicyManager->setValue(internProp, qvariant_cast<QSizePolicy>(val));
- return;
- } else if (QtFontPropertyManager *fontManager = qobject_cast<QtFontPropertyManager *>(manager)) {
- fontManager->setValue(internProp, qvariant_cast<QFont>(val));
- return;
- #ifndef QT_NO_CURSOR
- } else if (QtCursorPropertyManager *cursorManager = qobject_cast<QtCursorPropertyManager *>(manager)) {
- cursorManager->setValue(internProp, qvariant_cast<QCursor>(val));
- return;
- #endif
- } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
- flagManager->setValue(internProp, qvariant_cast<int>(val));
- return;
- }
- }
- /*!
- Sets the value of the specified \a attribute of the given \a
- property, to \a value.
- The new \a value's type must be of the type returned by
- attributeType(), or of a type that can be converted to
- attributeType() using the QVariant::canConvert() function,
- otherwise this function does nothing.
- \sa attributeValue(), QtVariantProperty::setAttribute(), attributeChanged()
- */
- void QtVariantPropertyManager::setAttribute(QtProperty *property,
- const QString &attribute, const QVariant &value)
- {
- QVariant oldAttr = attributeValue(property, attribute);
- if (!oldAttr.isValid())
- return;
- int attrType = value.userType();
- if (!attrType)
- return;
- if (attrType != attributeType(propertyType(property), attribute) &&
- !value.canConvert((QVariant::Type)attrType))
- return;
- QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
- if (internProp == 0)
- return;
- QtAbstractPropertyManager *manager = internProp->propertyManager();
- if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_maximumAttribute)
- intManager->setMaximum(internProp, qvariant_cast<int>(value));
- else if (attribute == d_ptr->m_minimumAttribute)
- intManager->setMinimum(internProp, qvariant_cast<int>(value));
- else if (attribute == d_ptr->m_singleStepAttribute)
- intManager->setSingleStep(internProp, qvariant_cast<int>(value));
- return;
- } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
- if (attribute == d_ptr->m_maximumAttribute)
- doubleManager->setMaximum(internProp, qvariant_cast<double>(value));
- if (attribute == d_ptr->m_minimumAttribute)
- doubleManager->setMinimum(internProp, qvariant_cast<double>(value));
- if (attribute == d_ptr->m_singleStepAttribute)
- doubleManager->setSingleStep(internProp, qvariant_cast<double>(value));
- if (attribute == d_ptr->m_decimalsAttribute)
- doubleManager->setDecimals(internProp, qvariant_cast<int>(value));
- return;
- } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_regExpAttribute)
- stringManager->setRegExp(internProp, qvariant_cast<QRegExp>(value));
- return;
- } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
- if (attribute == d_ptr->m_maximumAttribute)
- dateManager->setMaximum(internProp, qvariant_cast<QDate>(value));
- if (attribute == d_ptr->m_minimumAttribute)
- dateManager->setMinimum(internProp, qvariant_cast<QDate>(value));
- return;
- } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_decimalsAttribute)
- pointFManager->setDecimals(internProp, qvariant_cast<int>(value));
- return;
- } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
- if (attribute == d_ptr->m_maximumAttribute)
- sizeManager->setMaximum(internProp, qvariant_cast<QSize>(value));
- if (attribute == d_ptr->m_minimumAttribute)
- sizeManager->setMinimum(internProp, qvariant_cast<QSize>(value));
- return;
- } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_maximumAttribute)
- sizeFManager->setMaximum(internProp, qvariant_cast<QSizeF>(value));
- if (attribute == d_ptr->m_minimumAttribute)
- sizeFManager->setMinimum(internProp, qvariant_cast<QSizeF>(value));
- if (attribute == d_ptr->m_decimalsAttribute)
- sizeFManager->setDecimals(internProp, qvariant_cast<int>(value));
- return;
- } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_constraintAttribute)
- rectManager->setConstraint(internProp, qvariant_cast<QRect>(value));
- return;
- } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_constraintAttribute)
- rectFManager->setConstraint(internProp, qvariant_cast<QRectF>(value));
- if (attribute == d_ptr->m_decimalsAttribute)
- rectFManager->setDecimals(internProp, qvariant_cast<int>(value));
- return;
- } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_enumNamesAttribute)
- enumManager->setEnumNames(internProp, qvariant_cast<QStringList>(value));
- if (attribute == d_ptr->m_enumIconsAttribute)
- enumManager->setEnumIcons(internProp, qvariant_cast<QtIconMap>(value));
- return;
- } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
- if (attribute == d_ptr->m_flagNamesAttribute)
- flagManager->setFlagNames(internProp, qvariant_cast<QStringList>(value));
- return;
- }
- }
- /*!
- \reimp
- */
- bool QtVariantPropertyManager::hasValue(const QtProperty *property) const
- {
- if (propertyType(property) == groupTypeId())
- return false;
- return true;
- }
- /*!
- \reimp
- */
- QString QtVariantPropertyManager::valueText(const QtProperty *property) const
- {
- const QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
- return internProp ? !internProp->displayText().isEmpty() ? internProp->displayText() : internProp->valueText() : QString();
- }
- /*!
- \reimp
- */
- QIcon QtVariantPropertyManager::valueIcon(const QtProperty *property) const
- {
- const QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
- return internProp ? internProp->valueIcon() : QIcon();
- }
- /*!
- \reimp
- */
- // 属性初始化
- void QtVariantPropertyManager::initializeProperty(QtProperty *property)
- {
- QtVariantProperty *varProp = variantProperty(property);
- if (!varProp)
- return;
- QMap<int, QtAbstractPropertyManager *>::ConstIterator it =
- d_ptr->m_typeToPropertyManager.find(d_ptr->m_propertyType);
- if (it != d_ptr->m_typeToPropertyManager.constEnd()) {
- QtProperty *internProp = 0;
- if (!d_ptr->m_creatingSubProperties) {
- QtAbstractPropertyManager *manager = it.value();
- internProp = manager->addProperty();
- d_ptr->m_internalToProperty[internProp] = varProp;
- }
- // 添加此属性
- propertyToWrappedProperty()->insert(varProp, internProp);
- // 属性是否带有内部属性值
- if (internProp)
- {
- // 遍历所有的内部属性值
- QList<QtProperty *> children = internProp->subProperties();
- QListIterator<QtProperty *> itChild(children);
- QtVariantProperty *lastProperty = 0;
- // 逐一将内部子属性值添加到列表中
- while (itChild.hasNext()) {
- QtVariantProperty *prop = d_ptr->createSubProperty(varProp, lastProperty, itChild.next());
- lastProperty = prop ? prop : lastProperty;
- }
- }
- }
- }
- /*!
- \reimp
- */
- void QtVariantPropertyManager::uninitializeProperty(QtProperty *property)
- {
- const QMap<const QtProperty *, QPair<QtVariantProperty *, int> >::iterator type_it = d_ptr->m_propertyToType.find(property);
- if (type_it == d_ptr->m_propertyToType.end())
- return;
- PropertyMap::iterator it = propertyToWrappedProperty()->find(property);
- if (it != propertyToWrappedProperty()->end()) {
- QtProperty *internProp = it.value();
- if (internProp) {
- d_ptr->m_internalToProperty.remove(internProp);
- if (!d_ptr->m_destroyingSubProperties) {
- delete internProp;
- }
- }
- propertyToWrappedProperty()->erase(it);
- }
- d_ptr->m_propertyToType.erase(type_it);
- }
- /*!
- \reimp
- */
- QtProperty *QtVariantPropertyManager::createProperty()
- {
- if (!d_ptr->m_creatingProperty)
- return 0;
- QtVariantProperty *property = new QtVariantProperty(this);
- d_ptr->m_propertyToType.insert(property, qMakePair(property, d_ptr->m_propertyType));
- return property;
- }
- /////////////////////////////
- class QtVariantEditorFactoryPrivate
- {
- QtVariantEditorFactory *q_ptr = nullptr;
- Q_DECLARE_PUBLIC(QtVariantEditorFactory)
- public:
- QtSpinBoxFactory *m_spinBoxFactory = nullptr;
- QtDoubleSpinBoxFactory *m_doubleSpinBoxFactory = nullptr;
- QtCheckBoxFactory *m_checkBoxFactory = nullptr;
- QtLineEditFactory *m_lineEditFactory = nullptr;
- QtDateEditFactory *m_dateEditFactory = nullptr;
- QtTimeEditFactory *m_timeEditFactory = nullptr;
- QtDateTimeEditFactory *m_dateTimeEditFactory = nullptr;
- QtKeySequenceEditorFactory *m_keySequenceEditorFactory = nullptr;
- QtCharEditorFactory *m_charEditorFactory = nullptr;
- QtEnumEditorFactory *m_comboBoxFactory = nullptr;
- QtCursorEditorFactory *m_cursorEditorFactory = nullptr;
- QtColorEditorFactory *m_colorEditorFactory = nullptr;
- QtFontEditorFactory *m_fontEditorFactory = nullptr;
- QMap<QtAbstractEditorFactoryBase *, int> m_factoryToType;
- QMap<int, QtAbstractEditorFactoryBase *> m_typeToFactory;
- };
- /*!
- \class QtVariantEditorFactory
- \brief The QtVariantEditorFactory class provides widgets for properties
- created by QtVariantPropertyManager objects.
- The variant factory provides the following widgets for the
- specified property types:
- \table
- \header
- \o Property Type
- \o Widget
- \row
- \o \c int
- \o QSpinBox
- \row
- \o \c double
- \o QDoubleSpinBox
- \row
- \o \c bool
- \o QCheckBox
- \row
- \o QString
- \o QLineEdit
- \row
- \o QDate
- \o QDateEdit
- \row
- \o QTime
- \o QTimeEdit
- \row
- \o QDateTime
- \o QDateTimeEdit
- \row
- \o QKeySequence
- \o customized editor
- \row
- \o QChar
- \o customized editor
- \row
- \o \c enum
- \o QComboBox
- \row
- \o QCursor
- \o QComboBox
- \endtable
- Note that QtVariantPropertyManager supports several additional property
- types for which the QtVariantEditorFactory class does not provide
- editing widgets, e.g. QPoint and QSize. To provide widgets for other
- types using the variant approach, derive from the QtVariantEditorFactory
- class.
- \sa QtAbstractEditorFactory, QtVariantPropertyManager
- */
- /*!
- Creates a factory with the given \a parent.
- */
- QtVariantEditorFactory::QtVariantEditorFactory(QObject *parent)
- : QtAbstractEditorFactory<QtVariantPropertyManager>(parent)
- {
- d_ptr = new QtVariantEditorFactoryPrivate();
- d_ptr->q_ptr = this;
- d_ptr->m_spinBoxFactory = new QtSpinBoxFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_spinBoxFactory] = QVariant::Int;
- d_ptr->m_typeToFactory[QVariant::Int] = d_ptr->m_spinBoxFactory;
- d_ptr->m_doubleSpinBoxFactory = new QtDoubleSpinBoxFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_doubleSpinBoxFactory] = QVariant::Double;
- d_ptr->m_typeToFactory[QVariant::Double] = d_ptr->m_doubleSpinBoxFactory;
- d_ptr->m_checkBoxFactory = new QtCheckBoxFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_checkBoxFactory] = QVariant::Bool;
- d_ptr->m_typeToFactory[QVariant::Bool] = d_ptr->m_checkBoxFactory;
- d_ptr->m_lineEditFactory = new QtLineEditFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_lineEditFactory] = QVariant::String;
- d_ptr->m_typeToFactory[QVariant::String] = d_ptr->m_lineEditFactory;
- d_ptr->m_dateEditFactory = new QtDateEditFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_dateEditFactory] = QVariant::Date;
- d_ptr->m_typeToFactory[QVariant::Date] = d_ptr->m_dateEditFactory;
- d_ptr->m_timeEditFactory = new QtTimeEditFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_timeEditFactory] = QVariant::Time;
- d_ptr->m_typeToFactory[QVariant::Time] = d_ptr->m_timeEditFactory;
- d_ptr->m_dateTimeEditFactory = new QtDateTimeEditFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_dateTimeEditFactory] = QVariant::DateTime;
- d_ptr->m_typeToFactory[QVariant::DateTime] = d_ptr->m_dateTimeEditFactory;
- d_ptr->m_keySequenceEditorFactory = new QtKeySequenceEditorFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_keySequenceEditorFactory] = QVariant::KeySequence;
- d_ptr->m_typeToFactory[QVariant::KeySequence] = d_ptr->m_keySequenceEditorFactory;
- d_ptr->m_charEditorFactory = new QtCharEditorFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_charEditorFactory] = QVariant::Char;
- d_ptr->m_typeToFactory[QVariant::Char] = d_ptr->m_charEditorFactory;
- d_ptr->m_cursorEditorFactory = new QtCursorEditorFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_cursorEditorFactory] = QVariant::Cursor;
- d_ptr->m_typeToFactory[QVariant::Cursor] = d_ptr->m_cursorEditorFactory;
- d_ptr->m_colorEditorFactory = new QtColorEditorFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_colorEditorFactory] = QVariant::Color;
- d_ptr->m_typeToFactory[QVariant::Color] = d_ptr->m_colorEditorFactory;
- d_ptr->m_fontEditorFactory = new QtFontEditorFactory(this);
- d_ptr->m_factoryToType[d_ptr->m_fontEditorFactory] = QVariant::Font;
- d_ptr->m_typeToFactory[QVariant::Font] = d_ptr->m_fontEditorFactory;
- d_ptr->m_comboBoxFactory = new QtEnumEditorFactory(this);
- const int enumId = QtVariantPropertyManager::enumTypeId();
- d_ptr->m_factoryToType[d_ptr->m_comboBoxFactory] = enumId;
- d_ptr->m_typeToFactory[enumId] = d_ptr->m_comboBoxFactory;
- }
- /*!
- Destroys this factory, and all the widgets it has created.
- */
- QtVariantEditorFactory::~QtVariantEditorFactory()
- {
- delete d_ptr;
- }
- /*!
- \internal
- Reimplemented from the QtAbstractEditorFactory class.
- */
- void QtVariantEditorFactory::connectPropertyManager(QtVariantPropertyManager *manager)
- {
- const QList<QtIntPropertyManager *> intPropertyManagers = manager->findChildren<QtIntPropertyManager *>();
- for (QtIntPropertyManager *manager : intPropertyManagers)
- d_ptr->m_spinBoxFactory->addPropertyManager(manager);
- const QList<QtDoublePropertyManager *> doublePropertyManagers = manager->findChildren<QtDoublePropertyManager *>();
- for (QtDoublePropertyManager *manager : doublePropertyManagers)
- d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager);
- const QList<QtBoolPropertyManager *> boolPropertyManagers = manager->findChildren<QtBoolPropertyManager *>();
- for (QtBoolPropertyManager *manager : boolPropertyManagers)
- d_ptr->m_checkBoxFactory->addPropertyManager(manager);
- const QList<QtStringPropertyManager *> stringPropertyManagers = manager->findChildren<QtStringPropertyManager *>();
- for (QtStringPropertyManager *manager : stringPropertyManagers)
- d_ptr->m_lineEditFactory->addPropertyManager(manager);
- const QList<QtDatePropertyManager *> datePropertyManagers = manager->findChildren<QtDatePropertyManager *>();
- for (QtDatePropertyManager *manager : datePropertyManagers)
- d_ptr->m_dateEditFactory->addPropertyManager(manager);
- const QList<QtTimePropertyManager *> timePropertyManagers = manager->findChildren<QtTimePropertyManager *>();
- for (QtTimePropertyManager *manager : timePropertyManagers)
- d_ptr->m_timeEditFactory->addPropertyManager(manager);
- const QList<QtDateTimePropertyManager *> dateTimePropertyManagers = manager->findChildren<QtDateTimePropertyManager *>();
- for (QtDateTimePropertyManager *manager : dateTimePropertyManagers)
- d_ptr->m_dateTimeEditFactory->addPropertyManager(manager);
- const QList<QtKeySequencePropertyManager *> keySequencePropertyManagers = manager->findChildren<QtKeySequencePropertyManager *>();
- for (QtKeySequencePropertyManager *manager : keySequencePropertyManagers)
- d_ptr->m_keySequenceEditorFactory->addPropertyManager(manager);
- const QList<QtCharPropertyManager *> charPropertyManagers = manager->findChildren<QtCharPropertyManager *>();
- for (QtCharPropertyManager *manager : charPropertyManagers)
- d_ptr->m_charEditorFactory->addPropertyManager(manager);
- const QList<QtLocalePropertyManager *> localePropertyManagers = manager->findChildren<QtLocalePropertyManager *>();
- for (QtLocalePropertyManager *manager : localePropertyManagers)
- d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager());
- const QList<QtPointPropertyManager *> pointPropertyManagers = manager->findChildren<QtPointPropertyManager *>();
- for (QtPointPropertyManager *manager : pointPropertyManagers)
- d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
- const QList<QtPointFPropertyManager *> pointFPropertyManagers = manager->findChildren<QtPointFPropertyManager *>();
- for (QtPointFPropertyManager *manager : pointFPropertyManagers)
- d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager());
- const QList<QtSizePropertyManager *> sizePropertyManagers = manager->findChildren<QtSizePropertyManager *>();
- for (QtSizePropertyManager *manager : sizePropertyManagers)
- d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
- const QList<QtSizeFPropertyManager *> sizeFPropertyManagers = manager->findChildren<QtSizeFPropertyManager *>();
- for (QtSizeFPropertyManager *manager : sizeFPropertyManagers)
- d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager());
- const QList<QtRectPropertyManager *> rectPropertyManagers = manager->findChildren<QtRectPropertyManager *>();
- for (QtRectPropertyManager *manager : rectPropertyManagers)
- d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
- const QList<QtRectFPropertyManager *> rectFPropertyManagers = manager->findChildren<QtRectFPropertyManager *>();
- for (QtRectFPropertyManager *manager : rectFPropertyManagers)
- d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager());
- const QList<QtColorPropertyManager *> colorPropertyManagers = manager->findChildren<QtColorPropertyManager *>();
- for (QtColorPropertyManager *manager : colorPropertyManagers) {
- d_ptr->m_colorEditorFactory->addPropertyManager(manager);
- d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
- }
- const QList<QtEnumPropertyManager *> enumPropertyManagers = manager->findChildren<QtEnumPropertyManager *>();
- for (QtEnumPropertyManager *manager : enumPropertyManagers)
- d_ptr->m_comboBoxFactory->addPropertyManager(manager);
- const QList<QtSizePolicyPropertyManager *> sizePolicyPropertyManagers = manager->findChildren<QtSizePolicyPropertyManager *>();
- for (QtSizePolicyPropertyManager *manager : sizePolicyPropertyManagers) {
- d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
- d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager());
- }
- const QList<QtFontPropertyManager *> fontPropertyManagers = manager->findChildren<QtFontPropertyManager *>();
- for (QtFontPropertyManager *manager : fontPropertyManagers) {
- d_ptr->m_fontEditorFactory->addPropertyManager(manager);
- d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
- d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager());
- d_ptr->m_checkBoxFactory->addPropertyManager(manager->subBoolPropertyManager());
- }
- const QList<QtCursorPropertyManager *> cursorPropertyManagers = manager->findChildren<QtCursorPropertyManager *>();
- for (QtCursorPropertyManager *manager : cursorPropertyManagers)
- d_ptr->m_cursorEditorFactory->addPropertyManager(manager);
- const QList<QtFlagPropertyManager *> flagPropertyManagers = manager->findChildren<QtFlagPropertyManager *>();
- for (QtFlagPropertyManager *manager : flagPropertyManagers)
- d_ptr->m_checkBoxFactory->addPropertyManager(manager->subBoolPropertyManager());
- }
- /*!
- \internal
- Reimplemented from the QtAbstractEditorFactory class.
- */
- QWidget *QtVariantEditorFactory::createEditor(QtVariantPropertyManager *manager, QtProperty *property,
- QWidget *parent)
- {
- const int propType = manager->propertyType(property);
- QtAbstractEditorFactoryBase *factory = d_ptr->m_typeToFactory.value(propType, 0);
- if (!factory)
- return 0;
- return factory->createEditor(wrappedProperty(property), parent);
- }
- /*!
- \internal
- Reimplemented from the QtAbstractEditorFactory class.
- */
- void QtVariantEditorFactory::disconnectPropertyManager(QtVariantPropertyManager *manager)
- {
- const QList<QtIntPropertyManager *> intPropertyManagers = manager->findChildren<QtIntPropertyManager *>();
- for (QtIntPropertyManager *manager : intPropertyManagers)
- d_ptr->m_spinBoxFactory->removePropertyManager(manager);
- const QList<QtDoublePropertyManager *> doublePropertyManagers = manager->findChildren<QtDoublePropertyManager *>();
- for (QtDoublePropertyManager *manager : doublePropertyManagers)
- d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager);
- const QList<QtBoolPropertyManager *> boolPropertyManagers = manager->findChildren<QtBoolPropertyManager *>();
- for (QtBoolPropertyManager *manager : boolPropertyManagers)
- d_ptr->m_checkBoxFactory->removePropertyManager(manager);
- const QList<QtStringPropertyManager *> stringPropertyManagers = manager->findChildren<QtStringPropertyManager *>();
- for (QtStringPropertyManager *manager : stringPropertyManagers)
- d_ptr->m_lineEditFactory->removePropertyManager(manager);
- const QList<QtDatePropertyManager *> datePropertyManagers = manager->findChildren<QtDatePropertyManager *>();
- for (QtDatePropertyManager *manager : datePropertyManagers)
- d_ptr->m_dateEditFactory->removePropertyManager(manager);
- const QList<QtTimePropertyManager *> timePropertyManagers = manager->findChildren<QtTimePropertyManager *>();
- for (QtTimePropertyManager *manager : timePropertyManagers)
- d_ptr->m_timeEditFactory->removePropertyManager(manager);
- const QList<QtDateTimePropertyManager *> dateTimePropertyManagers = manager->findChildren<QtDateTimePropertyManager *>();
- for (QtDateTimePropertyManager *manager : dateTimePropertyManagers)
- d_ptr->m_dateTimeEditFactory->removePropertyManager(manager);
- const QList<QtKeySequencePropertyManager *> keySequencePropertyManagers = manager->findChildren<QtKeySequencePropertyManager *>();
- for (QtKeySequencePropertyManager *manager : keySequencePropertyManagers)
- d_ptr->m_keySequenceEditorFactory->removePropertyManager(manager);
- const QList<QtCharPropertyManager *> charPropertyManagers = manager->findChildren<QtCharPropertyManager *>();
- for (QtCharPropertyManager *manager : charPropertyManagers)
- d_ptr->m_charEditorFactory->removePropertyManager(manager);
- const QList<QtLocalePropertyManager *> localePropertyManagers = manager->findChildren<QtLocalePropertyManager *>();
- for (QtLocalePropertyManager *manager : localePropertyManagers)
- d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager());
- const QList<QtPointPropertyManager *> pointPropertyManagers = manager->findChildren<QtPointPropertyManager *>();
- for (QtPointPropertyManager *manager : pointPropertyManagers)
- d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
- const QList<QtPointFPropertyManager *> pointFPropertyManagers = manager->findChildren<QtPointFPropertyManager *>();
- for (QtPointFPropertyManager *manager : pointFPropertyManagers)
- d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager());
- const QList<QtSizePropertyManager *> sizePropertyManagers = manager->findChildren<QtSizePropertyManager *>();
- for (QtSizePropertyManager *manager : sizePropertyManagers)
- d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
- const QList<QtSizeFPropertyManager *> sizeFPropertyManagers = manager->findChildren<QtSizeFPropertyManager *>();
- for (QtSizeFPropertyManager *manager : sizeFPropertyManagers)
- d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager());
- const QList<QtRectPropertyManager *> rectPropertyManagers = manager->findChildren<QtRectPropertyManager *>();
- for (QtRectPropertyManager *manager : rectPropertyManagers)
- d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
- const QList<QtRectFPropertyManager *> rectFPropertyManagers = manager->findChildren<QtRectFPropertyManager *>();
- for (QtRectFPropertyManager *manager : rectFPropertyManagers)
- d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager());
- const QList<QtColorPropertyManager *> colorPropertyManagers = manager->findChildren<QtColorPropertyManager *>();
- for (QtColorPropertyManager *manager : colorPropertyManagers) {
- d_ptr->m_colorEditorFactory->removePropertyManager(manager);
- d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
- }
- const QList<QtEnumPropertyManager *> enumPropertyManagers = manager->findChildren<QtEnumPropertyManager *>();
- for (QtEnumPropertyManager *manager : enumPropertyManagers)
- d_ptr->m_comboBoxFactory->removePropertyManager(manager);
- const QList<QtSizePolicyPropertyManager *> sizePolicyPropertyManagers = manager->findChildren<QtSizePolicyPropertyManager *>();
- for (QtSizePolicyPropertyManager *manager : sizePolicyPropertyManagers) {
- d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
- d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager());
- }
- const QList<QtFontPropertyManager *> fontPropertyManagers = manager->findChildren<QtFontPropertyManager *>();
- for (QtFontPropertyManager *manager : fontPropertyManagers) {
- d_ptr->m_fontEditorFactory->removePropertyManager(manager);
- d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
- d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager());
- d_ptr->m_checkBoxFactory->removePropertyManager(manager->subBoolPropertyManager());
- }
- const QList<QtCursorPropertyManager *> cursorPropertyManagers = manager->findChildren<QtCursorPropertyManager *>();
- for (QtCursorPropertyManager *manager : cursorPropertyManagers)
- d_ptr->m_cursorEditorFactory->removePropertyManager(manager);
- const QList<QtFlagPropertyManager *> flagPropertyManagers = manager->findChildren<QtFlagPropertyManager *>();
- for (QtFlagPropertyManager *manager : flagPropertyManagers)
- d_ptr->m_checkBoxFactory->removePropertyManager(manager->subBoolPropertyManager());
- }
- #if QT_VERSION >= 0x040400
- QT_END_NAMESPACE
- #endif
- #include "moc_qtvariantproperty.cpp"
|