KProperty

KProperty.h
1 /* This file is part of the KDE project
2  Copyright (C) 2004 Cedric Pasteur <[email protected]>
3  Copyright (C) 2004 Alexander Dymo <[email protected]>
4  Copyright (C) 2004-2017 Jarosław Staniek <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20 */
21 
22 #ifndef KPROPERTY_PROPERTY_H
23 #define KPROPERTY_PROPERTY_H
24 
25 #include <QVariant>
26 #include <QStringList>
27 #include <QByteArray>
28 #include <QDebug>
29 
30 #include <cmath>
31 #include <limits>
32 
33 #include "kpropertycore_export.h"
34 
36 class KPropertyListData;
37 class KPropertySet;
38 class KPropertySetPrivate;
39 
45 #define KPROPERTY_MIN_PRECISE_DOUBLE (-pow(2, std::numeric_limits<double>::digits))
46 
56 #define KPROPERTY_MAX_PRECISE_DOUBLE (pow(2, std::numeric_limits<double>::digits))
57 
95 class KPROPERTYCORE_EXPORT KProperty
96 {
97 public:
100  enum Type {
101  //standard supported QVariant types
102  Auto = 0x00ffffff,
103  Invalid = QVariant::Invalid,
104  BitArray = QVariant::BitArray,
105  Bitmap = QVariant::Bitmap,
106  Bool = QVariant::Bool,
107  Brush = QVariant::Brush,
108  ByteArray = QVariant::ByteArray,
109  Char = QVariant::Char,
110  Color = QVariant::Color,
111  Cursor = QVariant::Cursor,
112  Date = QVariant::Date,
113  DateTime = QVariant::DateTime,
114  Double = QVariant::Double,
115  Font = QVariant::Font,
117  Image = QVariant::Image,
118  Int = QVariant::Int,
119  KeySequence = QVariant::KeySequence,
120  Line = QVariant::Line,
121  LineF = QVariant::LineF,
122  List = QVariant::List,
123  Locale = QVariant::Locale,
124  LongLong = QVariant::LongLong,
125  Map = QVariant::Map,
126  Matrix = QVariant::Matrix,
127  Transform = QVariant::Transform,
128  Palette = QVariant::Palette,
129  Pen = QVariant::Pen,
130  Pixmap = QVariant::Pixmap,
131  Point = QVariant::Point,
132  PointF = QVariant::PointF,
133  Polygon = QVariant::Polygon,
134  Rect = QVariant::Rect,
135  RectF = QVariant::RectF,
136  RegExp = QVariant::RegExp,
137  Region = QVariant::Region,
138  Size = QVariant::Size,
139  SizeF = QVariant::SizeF,
140  SizePolicy = QVariant::SizePolicy,
141  String = QVariant::String,
142  StringList = QVariant::StringList,
143  TextFormat = QVariant::TextFormat,
144  TextLength = QVariant::TextLength,
145  Time = QVariant::Time,
146  UInt = QVariant::UInt,
147  ULongLong = QVariant::ULongLong,
148  Url = QVariant::Url,
149 
150  //predefined custom types
151  ValueFromList = 1000,
155  ComposedUrl ,
156 
157  UserDefined = 4000
158  };
159 
164  KProperty();
165 
167  explicit KProperty(const QByteArray &name, const QVariant &value = QVariant(),
168  const QString &caption = QString(), const QString &description = QString(),
169  int type = Auto, KProperty* parent = nullptr);
170 
176  KProperty(const QByteArray &name, KPropertyListData *listData,
177  const QVariant &value = QVariant(),
178  const QString &caption = QString(), const QString &description = QString(),
179  int type = ValueFromList, KProperty* parent = nullptr);
180 
182  KProperty(const KProperty &prop);
183 
184  ~KProperty();
185 
190  QByteArray name() const;
191 
196  void setName(const QByteArray &name);
197 
199  QString caption() const;
200 
202  inline QString captionOrName() const
203  {
204  return caption().isEmpty() ? QString::fromLatin1(name()) : caption();
205  }
206 
210  QString captionForDisplaying() const;
211 
216  void setCaption(const QString &caption);
217 
219  QString description() const;
220 
222  void setDescription(const QString &description);
223 
225  int type() const;
226 
228  void setType(int type);
229 
231  QVariant value() const;
232 
234  QVariant oldValue() const;
235 
238  enum class ValueOption {
239  None = 0,
240  IgnoreOld = 1,
242  IgnoreComposedProperty = 2
243  };
244  Q_DECLARE_FLAGS(ValueOptions, ValueOption)
245 
246 
253  bool setValue(const QVariant &value, ValueOptions options = ValueOptions());
254 
264  bool valueEqualsTo(const QVariant &value, ValueOptions valueOptions = ValueOptions()) const;
265 
268  void resetValue();
269 
272  KPropertyListData* listData() const;
273 
276  void setListData(KPropertyListData* list);
277 
281  void setListData(const QStringList &keys, const QStringList &names);
282 
285  void setIconName(const QString &name);
286 
288  QString iconName() const;
289 
292  const QList<KProperty*>* children() const;
293 
295  KProperty* child(const QByteArray &name);
296 
298  KProperty* parent() const;
299 
302  KComposedPropertyInterface* composedProperty() const;
303 
305  void setComposedProperty(KComposedPropertyInterface *prop);
306 
308  bool isNull() const;
309 
315  bool isModified() const;
316 
325  void clearModifiedFlag();
326 
332  bool isReadOnly() const;
333 
336  void setReadOnly(bool readOnly);
337 
340  bool isVisible() const;
341 
343  void setVisible(bool visible);
344 
348  bool isStorable() const;
349 
351  void setStorable(bool storable);
352 
355  enum class ValueSyncPolicy {
356  Editor,
357  FocusOut,
358  Auto
360  };
363 
366  ValueSyncPolicy valueSyncPolicy() const;
367 
371  void setValueSyncPolicy(ValueSyncPolicy policy);
372 
463  void setOption(const char* name, const QVariant& val);
464 
474  QVariant option(const char* name, const QVariant& defaultValue = QVariant()) const;
475 
482  bool hasOptions() const;
483 
485  KProperty& operator= (const QVariant& val);
486 
488  KProperty& operator= (const KProperty &property);
489 
496  bool operator==(const KProperty &prop) const;
497 
503  bool operator!=(const KProperty &prop) const;
504 
505 #if 0
506 
510  int sortingKey() const;
511 #endif
512 
513 private:
515  void setValue(const QVariant &value, bool a1, bool a2 = true);
516 
517  class Private;
518  Private * const d;
519 
520  friend class KPropertySet;
521  friend class KPropertySetPrivate;
522  friend class KPropertySetBuffer;
523  friend KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KProperty &p);
524 };
525 
527 KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KProperty &p);
528 
529 Q_DECLARE_OPERATORS_FOR_FLAGS(KProperty::ValueOptions)
530 
531 #endif
QString captionOrName() const
Definition: KProperty.h:202
unicode symbol code
Definition: KProperty.h:152
ValueSyncPolicy
Synchronization policy for property values.
Definition: KProperty.h:355
An interface for for composed property handlers.
font name, e.g.
Definition: KProperty.h:153
bool isEmpty() const const
A property set&#39;s buffer.
Set of properties.
Definition: KPropertySet.h:119
The base class representing a single property.
Definition: KProperty.h:95
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
QString fromLatin1(const char *str, int size)
ValueOption
Options that influence how values are handled in setValue() and valueEqualsTo()
Definition: KProperty.h:238
A data container for properties of list type.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Sep 30 2020 23:11:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.