File indexing completed on 2024-12-08 07:18:47

0001 /* This file is part of the KDE project
0002    Copyright (C) 2009-2017 Jarosław Staniek <staniek@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KPROPERTY_PROPERTY_P_H
0021 #define KPROPERTY_PROPERTY_P_H
0022 
0023 #include "KPropertySet.h"
0024 #include <QPointer>
0025 
0026 //! Default value for "step" option. Used for spin boxes, etc.
0027 #define KPROPERTY_DEFAULT_DOUBLE_VALUE_STEP 0.01
0028 
0029 //! Default value for "precision" option. Used for spin boxes, etc.
0030 #define KPROPERTY_DEFAULT_DOUBLE_VALUE_PRECISION 2
0031 
0032 //! @internal
0033 class Q_DECL_HIDDEN KProperty::Private
0034 {
0035 public:
0036     explicit Private(KProperty *prop);
0037 
0038     void setCaptionForDisplaying(const QString& captionForDisplaying);
0039 
0040     ~Private();
0041 
0042     //! @return a value for option @a name or null value if there is no such option set.
0043     inline QVariant option(const char* name, const QVariant& defaultValue) const
0044     {
0045         QVariant result = options.value(name);
0046         if (result.isNull()) {
0047             result = parent ? parent->option(name, defaultValue) : defaultValue;
0048         }
0049         return result;
0050     }
0051 
0052     //! @return true if value of this property differs from @a otherValue
0053     bool valueDiffersInternal(const QVariant &otherValue, KProperty::ValueOptions options);
0054 
0055     //! Sets value of the property to @a newValue
0056     bool setValueInternal(const QVariant &newValue, KProperty::ValueOptions valueOptions);
0057 
0058     /*! Adds @a prop as a child of this property.
0059      The children will be owned by this property. */
0060     void addChild(KProperty *prop);
0061 
0062     /*! Adds @a set to this property. */
0063     void addSet(KPropertySet *newSet);
0064 
0065     /*! Adds related property for this property. */
0066     void addRelatedProperty(KProperty *property);
0067 
0068     /*! This method emits the @a KPropertySet::propertyChanged() signal.
0069     KProperty::setValue() calls this method if the value has been changed. */
0070     void emitPropertyChanged();
0071 
0072     void childValueChanged(KProperty *child, const QVariant &value, KProperty::ValueOptions valueOptions);
0073 
0074     KProperty * const q;
0075     int type;
0076     QByteArray name;
0077     QString captionForDisplaying;
0078     QString caption;
0079     QString description;
0080     QVariant value;
0081     QVariant oldValue;
0082     /*! The string-to-value correspondence list of the property.*/
0083     KPropertyListData* listData;
0084     QString iconName;
0085 
0086     bool changed;
0087     bool storable;
0088     bool readOnly;
0089     bool visible;
0090     KProperty::ValueSyncPolicy valueSyncPolicy = KProperty::ValueSyncPolicy::Editor;
0091     QMap<QByteArray, QVariant> options;
0092 
0093     KComposedPropertyInterface *composed;
0094     //! Flag used to allow composed property to use setValue() without causing recursion
0095     bool useComposedProperty;
0096 
0097     //! Used when a single set is assigned for the property
0098     QPointer<KPropertySet> set;
0099     //! Used when multiple sets are assigned for the property
0100     QList< QPointer<KPropertySet> > *sets;
0101 
0102     KProperty  *parent;
0103     QList<KProperty*>  *children;
0104     //! List of properties with the same name (when intersecting buffers)
0105     QList<KProperty*>  *relatedProperties;
0106 };
0107 
0108 #endif