kexi
kexicustompropertyfactory.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexicustompropertyfactory.h"
00021 #include "kexicustompropertyfactory_p.h"
00022 #include <kexiutils/identifier.h>
00023
00024 #include <koproperty/customproperty.h>
00025
00026 using namespace KoProperty;
00027
00029 class PixmapIdCustomProperty : public CustomProperty
00030 {
00031 public:
00032 PixmapIdCustomProperty(Property *parent)
00033 : CustomProperty(parent) {
00034 }
00035 virtual ~PixmapIdCustomProperty() {};
00036 virtual void setValue(const QVariant &value, bool rememberOldValue) {
00037 Q_UNUSED( value );
00038 Q_UNUSED( rememberOldValue);
00039 }
00040 virtual QVariant value() const { return m_property->value(); }
00041 virtual bool handleValue() const {
00042 return false;
00043 }
00044 };
00045
00047 class IdentifierCustomProperty : public CustomProperty
00048 {
00049 public:
00050 IdentifierCustomProperty(Property *parent)
00051 : CustomProperty(parent) {
00052 }
00053 virtual ~IdentifierCustomProperty() {};
00054 virtual void setValue(const QVariant &value, bool rememberOldValue)
00055 {
00056 Q_UNUSED(rememberOldValue);
00057 if (!value.toString().isEmpty())
00058 m_value = KexiUtils::string2Identifier(value.toString());
00059 }
00060 virtual QVariant value() const { return m_value; }
00061 virtual bool handleValue() const {
00062 return true;
00063 }
00064 QString m_value;
00065 };
00066
00067
00068
00069 KexiCustomPropertyFactory::KexiCustomPropertyFactory(QObject* parent)
00070 : CustomPropertyFactory(parent)
00071 {
00072 }
00073
00074 KexiCustomPropertyFactory::~KexiCustomPropertyFactory()
00075 {
00076 }
00077
00078 CustomProperty* KexiCustomPropertyFactory::createCustomProperty(Property *parent)
00079 {
00080 const int type = parent->type();
00081 if (type==(int)KexiCustomPropertyFactory::PixmapId)
00082 return new PixmapIdCustomProperty(parent);
00083 else if (type==(int)KexiCustomPropertyFactory::Identifier)
00084 return new IdentifierCustomProperty(parent);
00085 return 0;
00086 }
00087
00088 Widget* KexiCustomPropertyFactory::createCustomWidget(Property *prop)
00089 {
00090 const int type = prop->type();
00091 if (type==(int)KexiCustomPropertyFactory::PixmapId)
00092 return new KexiImagePropertyEdit(prop);
00093 else if (type==(int)KexiCustomPropertyFactory::Identifier)
00094 return new KexiIdentifierPropertyEdit(prop);
00095
00096 return 0;
00097 }
00098
00099 void KexiCustomPropertyFactory::init()
00100 {
00101 if (KoProperty::FactoryManager::self()->factoryForEditorType(KexiCustomPropertyFactory::PixmapId))
00102 return;
00103
00104
00105 KexiCustomPropertyFactory *factory = new KexiCustomPropertyFactory(KoProperty::FactoryManager::self());
00106 QValueList<int> types;
00107 types << KexiCustomPropertyFactory::PixmapId << KexiCustomPropertyFactory::Identifier;
00108 KoProperty::FactoryManager::self()->registerFactoryForProperties(types, factory);
00109 KoProperty::FactoryManager::self()->registerFactoryForEditors(types, factory);
00110 }
|