libTransmittableProperty 2.0(r200)
Serializeable Parameter Objects
|
00001 /*************************************************************************** 00002 * Copyright (C) 2008 by Matthias Nagl * 00003 * mnagl@uni-goettingen.de * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 #ifndef TRANSMITTABLEPROPERTY_H 00021 #define TRANSMITTABLEPROPERTY_H 00022 00033 #include <QtCore/QtGlobal> 00034 #include <QString> 00035 #include <QByteArray> 00036 #include <QVariant> 00037 #include <QStringList> 00038 00039 #if defined(TRANSMITTABLEPROPERTIES_LIBRARY) 00040 # define TP_EXPORT Q_DECL_EXPORT 00041 #else 00042 # define TP_EXPORT Q_DECL_IMPORT 00043 #endif 00044 00045 class QtVariantPropertyManager; 00046 class QtVariantProperty; 00047 class PropertyBranchInterface; 00048 class TransmittablePropertyData; 00049 00053 class TP_EXPORT TransmittableProperty // : public TransmittablePropertyInterface 00054 { 00055 public: 00056 enum TransmittableDataType { 00057 Invalid, 00058 Group, 00059 Enum, 00060 Flag, 00061 Int, 00062 Double, 00063 Bool, 00064 String, 00065 00066 Size // helper to determine enums max value 00067 }; 00068 00069 TransmittableProperty(); 00070 TransmittableProperty(QString name, TransmittableDataType type); 00071 TransmittableProperty(QByteArray &serialized); 00073 // TransmittableProperty(const TransmittableProperty *original); 00074 ~TransmittableProperty(); 00075 00076 virtual void setName(const QString &name) { n = name; } 00077 virtual QString name() const { return n; } 00078 virtual void setValue(const QVariant &value); 00079 virtual void setValue(const QVariant &value, TransmittableDataType type); 00081 virtual void updateValue(const QVariant &value); 00083 virtual bool updateValue(const TransmittablePropertyData &u); 00084 virtual bool updated() const { return valueupdated; } 00086 virtual QVariant value(bool sendconfirmation = true) const; 00087 virtual void setAttribute(const QString &name, const QVariant & value); 00088 virtual QVariant attribute(const QString &name) const { return attr[name]; } 00089 static QStringList allowedAttributes(TransmittableDataType type); 00091 virtual void setDisplayMagnitude(qreal divider) { div = divider; } 00092 virtual void setToolTip(const QString &tt) { tooltip = tt; } 00093 virtual QString toolTip() const { return tooltip; } 00094 virtual void setDataType(TransmittableDataType type); 00095 virtual TransmittableDataType dataType() const { return t; } 00096 virtual void setQSettingsKey(const QString &key) { qskey = key; } 00097 virtual QString qSettingsKey() const { return qskey; } 00098 00099 virtual void setDefaultValue(const QVariant &def) { defaultval = def; } 00100 virtual void loadFromQSettings(); 00101 virtual void saveToQSettings() const; 00102 00103 virtual QByteArray serialize() const; 00104 virtual TransmittablePropertyData transmittablePropertyUpdate() const; 00105 virtual QtVariantProperty * addToPropertyManager(QtVariantPropertyManager *manager); 00106 virtual QtVariantProperty * qtProperty() const { return p; } 00107 00108 virtual void setParentBranch(PropertyBranchInterface *p); 00109 virtual const PropertyBranchInterface * parentBranch() { return pb; } 00110 virtual quint64 parentPropertyHash() const { return parentprophash; } 00111 virtual quint64 hash() const { return ownhash; } 00112 00113 virtual void addDependentProperty(TransmittableProperty *dependent); 00114 virtual QList<quint64> dependentPropertyHashes() const { return dephashes; } 00115 00116 virtual operator double() const; 00117 virtual operator int() const; 00118 virtual operator unsigned int() const; 00119 virtual operator bool() const; 00120 virtual operator QString() const; 00121 00122 private: 00123 static QVariant::Type dataTypeToVariantType(TransmittableDataType type); 00124 static int dataTypeToPropertyType(TransmittableDataType type, QtVariantPropertyManager *manager); 00125 static int variantTypeToDataType(QVariant::Type type); 00126 void sendConfirmation() const; 00127 QString n; 00128 TransmittableDataType t; 00129 QVariant val; 00130 QVariant defaultval; 00131 QMap<QString, QVariant> attr; 00132 QString qskey; 00133 mutable QString qspath; 00134 quint64 ownhash; 00135 mutable quint64 parentprophash; 00136 QtVariantProperty *p; 00137 mutable const PropertyBranchInterface *pb; 00138 qreal div; 00139 QString tooltip; 00140 mutable bool valueupdated; 00142 QList<TransmittableProperty*> dependents; 00143 QList<quint64> dephashes; 00145 QList<TransmittableProperty*> determinatives; 00146 }; 00147 00148 class TP_EXPORT TransmittablePropertyData 00149 { 00150 public: 00151 TransmittablePropertyData(QByteArray &d); 00152 TransmittablePropertyData(quint64 hash, const QVariant &value); 00153 ~TransmittablePropertyData() {} 00154 virtual quint64 hash() const { return ownhash; } 00155 virtual QVariant value() const { return val; } 00156 virtual operator QByteArray() const { return d; } 00157 private: 00158 QByteArray d; 00159 quint64 ownhash; 00160 QVariant val; 00161 }; 00162 00163 #endif