kexi

kexicustompropertyfactory.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexicustompropertyfactory.h"
21#include "kexicustompropertyfactory_p.h"
22#include <kexiutils/identifier.h>
23
24#include <koproperty/customproperty.h>
25
26using namespace KoProperty;
27
29class PixmapIdCustomProperty : public CustomProperty
30{
31 public:
32 PixmapIdCustomProperty(Property *parent)
33 : CustomProperty(parent) {
34 }
35 virtual ~PixmapIdCustomProperty() {};
36 virtual void setValue(const TQVariant &value, bool rememberOldValue) {
37 Q_UNUSED( value );
38 Q_UNUSED( rememberOldValue);
39 }
40 virtual TQVariant value() const { return m_property->value(); }
41 virtual bool handleValue() const {
42 return false; //m_property->type()==KexiCustomPropertyFactory::PixmapData;
43 }
44};
45
47class IdentifierCustomProperty : public CustomProperty
48{
49 public:
50 IdentifierCustomProperty(Property *parent)
51 : CustomProperty(parent) {
52 }
53 virtual ~IdentifierCustomProperty() {};
54 virtual void setValue(const TQVariant &value, bool rememberOldValue)
55 {
56 Q_UNUSED(rememberOldValue);
57 if (!value.toString().isEmpty())
58 m_value = KexiUtils::string2Identifier(value.toString()).lower();
59 }
60 virtual TQVariant value() const { return m_value; }
61 virtual bool handleValue() const {
62 return true;
63 }
64 TQString m_value;
65};
66
67//---------------
68
69KexiCustomPropertyFactory::KexiCustomPropertyFactory(TQObject* parent)
70: CustomPropertyFactory(parent)
71{
72}
73
74KexiCustomPropertyFactory::~KexiCustomPropertyFactory()
75{
76}
77
78CustomProperty* KexiCustomPropertyFactory::createCustomProperty(Property *parent)
79{
80 const int type = parent->type();
82 return new PixmapIdCustomProperty(parent);
83 else if (type==(int)KexiCustomPropertyFactory::Identifier)
84 return new IdentifierCustomProperty(parent);
85 return 0;
86}
87
88Widget* KexiCustomPropertyFactory::createCustomWidget(Property *prop)
89{
90 const int type = prop->type();
92 return new KexiImagePropertyEdit(prop);
93 else if (type==(int)KexiCustomPropertyFactory::Identifier)
94 return new KexiIdentifierPropertyEdit(prop);
95
96 return 0;
97}
98
100{
101 if (KoProperty::FactoryManager::self()->factoryForEditorType(KexiCustomPropertyFactory::PixmapId))
102 return; //already registered
103
104 // register custom editors and properties
105 KexiCustomPropertyFactory *factory = new KexiCustomPropertyFactory(KoProperty::FactoryManager::self());
106 TQValueList<int> types;
108 KoProperty::FactoryManager::self()->registerFactoryForProperties(types, factory);
109 KoProperty::FactoryManager::self()->registerFactoryForEditors(types, factory);
110}
Kexi-specific custom property factory for KoProperty library.
@ Identifier
string allowing nonempty identifiers
static void init()
Called once to register all propert and editor types provided by this factory.
KEXIUTILS_EXPORT TQString string2Identifier(const TQString &s)