Stellarium  0.90.0
StelPropertyMgr.hpp
1 /*
2  * Copyright (C) 2015-2016 Florian Schaukowitsch
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17  */
18 
19 #ifndef _STELPROPERTYMGR_HPP_
20 #define _STELPROPERTYMGR_HPP_
21 
22 #include <QObject>
23 #include <QSet>
24 #include <QMetaProperty>
25 
26 class StelProperty;
27 
33 class StelPropertyProxy : public QObject
34 {
35  Q_OBJECT
36 public:
37  StelPropertyProxy(StelProperty* prop,QObject* parent);
38 
39 protected slots:
42  virtual void onPropertyChanged(const QVariant& value) = 0;
43 
44 protected:
47 };
48 
51 {
52  Q_OBJECT
53 public:
54  StelPropertyIntProxy(StelProperty* prop,QObject* parent);
55 protected slots:
56  void onPropertyChanged(const QVariant &value) Q_DECL_OVERRIDE;
57 signals:
59  void propertyChanged(int value);
60 };
61 
64 {
65  Q_OBJECT
66 public:
67  StelPropertyBoolProxy(StelProperty* prop,QObject* parent);
68 protected slots:
69  void onPropertyChanged(const QVariant &value) Q_DECL_OVERRIDE;
70 signals:
72  void propertyChanged(bool value);
73 };
74 
77 {
78  Q_OBJECT
79 public:
80  StelPropertyDoubleProxy(StelProperty* prop,QObject* parent);
81 protected slots:
82  void onPropertyChanged(const QVariant &value) Q_DECL_OVERRIDE;
83 signals:
85  void propertyChanged(double value);
86 };
87 
88 
206 class StelProperty : public QObject
207 {
208  friend class StelPropertyMgr;
209  Q_OBJECT
210 
211 public slots:
213  QString getId() const { return id; }
214 
216  QVariant getValue() const;
217 
224  bool setValue(const QVariant& value) const;
225 
227  bool isReadOnly() const;
228 
231  bool isSynchronizable() const;
232 
234  bool canNotify() const;
235 
237  QMetaType::Type getType() const;
238 
240  QMetaProperty getMetaProp() const { return prop; }
241 
243  QObject* getTarget() const { return target; }
244 signals:
246  void changed(const QVariant& newValue);
247 protected slots:
249  void propertyChanged();
250 protected:
251  StelProperty(const QString& id,QObject* target, const QMetaProperty& prop);
252 
253  QString id;
254  QObject* target;
255  QMetaProperty prop;
256 };
257 
261 class StelPropertyMgr : public QObject
262 {
263  Q_OBJECT
264 public:
265  typedef QMap<QString,StelProperty*> StelPropertyMap;
266 
268  StelPropertyMgr();
269  ~StelPropertyMgr();
270 
277  StelProperty* registerProperty(const QString& id, QObject* target, const char* propertyName);
278 
283  void registerObject(QObject *obj);
284 
286  QStringList getPropertyList() const;
288  QList<StelProperty*> getAllProperties() const;
290  const StelPropertyMap& getPropertyMap() const { return propMap; }
291 
293  StelProperty* getProperty(const QString& id) const;
294 
299  QVariant getStelPropertyValue(const QString& id) const;
305  bool setStelPropertyValue(const QString& id, const QVariant &value) const;
307  QMetaProperty getMetaProperty(const QString& id) const;
308 signals:
312  void stelPropertyChanged(StelProperty* prop, const QVariant& value);
313 private slots:
314  void onStelPropChanged(const QVariant& val);
315 private:
316  StelProperty* registerProperty(const QString &id, QObject *target, const QMetaProperty& prop);
317 
318  QMap<QString,QObject*> registeredObjects;
319  StelPropertyMap propMap;
320 };
321 
322 #endif
A StelPropertyProxy for bool-based properties.
Wrapper around a Q_PROPERTY (see the Qt property system for more information) of a specific object...
QMetaProperty getMetaProp() const
Returns the actual Q_PROPERTY wrapped by this instance.
StelProperty * prop
The connected property, set by the constructor.
const StelPropertyMap & getPropertyMap() const
Returns a map from property IDs to StelProperty objects.
A StelPropertyProxy for double-based properties.
Manages the registration of specific object properties with the StelProperty system.
Abstract base class for a StelProperty proxy implementation, which allow reacting to the StelProperty...
QObject * getTarget() const
Returns the object to which this property belongs.
A StelPropertyProxy for int-based properties.
QString getId() const
Returns the unique ID which is used to identify this property.
virtual void onPropertyChanged(const QVariant &value)=0
This is connected by the constructor to the StelProperty::changed event of the connected property...