kexi

kexicustompropertyfactory.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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; //m_property->type()==KexiCustomPropertyFactory::PixmapData;
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()).lower();
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; //already registered
00103 
00104     // register custom editors and properties
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 }
KDE Home | KDE Accessibility Home | Description of Access Keys