summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmenumproperty.h
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit47d455dd55be855e4cc691c32f687f723d9247ee (patch)
tree52e236aaa2576bdb3840ebede26619692fed6d7d /kpovmodeler/pmenumproperty.h
downloadtdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz
tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpovmodeler/pmenumproperty.h')
-rw-r--r--kpovmodeler/pmenumproperty.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/kpovmodeler/pmenumproperty.h b/kpovmodeler/pmenumproperty.h
new file mode 100644
index 00000000..a8d6085e
--- /dev/null
+++ b/kpovmodeler/pmenumproperty.h
@@ -0,0 +1,110 @@
+//-*-C++-*-
+/*
+**************************************************************************
+ description
+ --------------------
+ copyright : (C) 2002 by Andreas Zehender
+**************************************************************************
+
+**************************************************************************
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+**************************************************************************/
+
+#ifndef PMENUMPROPERTY_H
+#define PMENUMPROPERTY_H
+
+#include "pmmetaobject.h"
+#include <qmap.h>
+
+typedef QMap<int, QString> PMEnumValueStringMap;
+typedef QMap<QString, int> PMEnumStringValueMap;
+
+/**
+ * Base class for enum properties
+ */
+class PMEnumProperty : public PMPropertyBase
+{
+public:
+ /**
+ * Default constructor
+ */
+ PMEnumProperty( const char* name, bool readOnly = false,
+ bool writeOnly = false );
+
+ /**
+ * Adds the string to the list of enum values and sets the enum flag
+ * to true
+ */
+ void addEnumValue( const QString& str, int value );
+
+ /**
+ * Returns true if the property is an enum
+ */
+ virtual bool isEnum( ) const { return true; }
+ /**
+ * Returns the list of enum values
+ */
+ virtual QStringList enumValues( ) const;
+
+protected:
+ /**
+ * Do not reimplement this method in a sub class
+ */
+ virtual bool setProtected( PMObject* obj, const PMVariant& v );
+ /**
+ * Do not reimplement this method in a sub class
+ */
+ virtual PMVariant getProtected( const PMObject* obj );
+
+ /**
+ * Reimplement this method in sub classes. You can safetly
+ * cast the integer to the enum type
+ */
+ virtual void setEnum( PMObject* obj, int value ) = 0;
+ /**
+ * Reimplement this method in sub classes.
+ */
+ virtual int getEnum( const PMObject* obj ) = 0;
+
+private:
+ PMEnumValueStringMap m_valueMap;
+ PMEnumStringValueMap m_stringMap;
+};
+
+#define PMDefineEnumPropertyClass( ObjectClass, EnumType, PropertyClass ) \
+class PropertyClass : public PMEnumProperty \
+{ \
+public: \
+ typedef void ( ObjectClass::*SetPtr ) ( EnumType ); \
+ typedef EnumType ( ObjectClass::*GetPtr ) ( void ) const; \
+ \
+ PropertyClass( const char* name, SetPtr setFktn, GetPtr getFktn ) \
+ : PMEnumProperty( name, setFktn == 0, getFktn == 0 ) \
+ { \
+ m_setFunktion = setFktn; \
+ m_getFunktion = getFktn; \
+ } \
+protected: \
+ virtual void setEnum( PMObject* obj, int value ) \
+ { \
+ ObjectClass* o = ( ObjectClass* ) obj; \
+ ( o->*m_setFunktion )( ( EnumType ) value ); \
+ } \
+ virtual int getEnum( const PMObject* obj ) \
+ { \
+ const ObjectClass* o = ( const ObjectClass* ) obj; \
+ return ( o->*m_getFunktion )( ); \
+ } \
+private: \
+ SetPtr m_setFunktion; \
+ GetPtr m_getFunktion; \
+}
+// no semicolon, put a semicolon after the macro!
+
+#endif