lib

KoProperty::FactoryManager Class Reference

#include <factory.h>

Inherits QObject.

List of all members.


Detailed Description

Manages factories providing custom editors and properties.

This class is static, you don't need to create an instance of it. It's used to enable the custom property/editors system. You may want to create your own property types and/or editors to:

  • Create your own editors for some special kind of properties, not included in KProperty basic editors;

  • Create composed properties, which contain more than one value. Child items will then be created in the Editor (that's how rect, size properties are created).

Using Custom Properties

To create a custom property, create a subclass of CustomProperty class. You need to implement some virtual functions, to customize the behaviour of your property (see CustomProperty api doc).
Then, you need to register the new created type, using registerFactoryForProperty(). The second parameter is an instance of CustomPropertyFactory-derived class implementing CustomPropertyFactory::createCustomProperty() method.
To create a property of this type, just use the normal constructor, overriding the type parameter with the type you registered.

Using Custom Properties to create composed properties

Use a composed property when you need more than one editor for a property. Examples are rect, size or point properties. If you create a composed property, both parent and children properties must have custom (different) types. Child properties are created in CustomProperty constructor of the parent type, by adding CustomProperty::property() as parent in Property constructor.
Child properties should return handleValue() == true and in CustomProperty::setValue(), parent's Property::setValue() should be called, making sure that useCustomProperty argument is set to false.
Parent's handleValue() should be set to false, unless you cannot store the property in a QVariant. You just need to update children's value, making sure that useCustomProperty argument is set to false.

Using Custom Editors

First, create a subclass of Widget, and implement all the virtuals you need to tweak the property editor. You can find examples of editors in the src/editors/ directory.
Then, register it using registerFactoryForEditor(), as for properties (see test/ dir for an example of custom editor). You can also override the editor provided by KoProperty, if it doesn't fit your needs (if you have created a better editor, send us the code, and it may get included in KProperty library).
To use your new editor, just create properties with the type number you registered using registerFactoryForEditor() . Your editor will automatically appear in the Editor.

Using Custom Properties to create composed properties

You then need to set handleValue() to true. The Widget you create also have to call directly CustomProperty member to store the value. just make sure you call emitPropertyChanged() when the proerty value changes. Also make sure to avoid infinite recursion if you use children properties.

Author:
Cedric Pasteur <cedric.pasteur@free.fr>

Alexander Dymo <cloudtemple@mskat.net>

Definition at line 113 of file factory.h.


Public Member Functions

void registerFactoryForEditor (int editorType, CustomPropertyFactory *factory)
void registerFactoryForEditors (const QValueList< int > &editorTypes, CustomPropertyFactory *factory)
CustomPropertyFactoryfactoryForEditorType (int type)
WidgetcreateWidgetForProperty (Property *property)
void registerFactoryForProperty (int propertyType, CustomPropertyFactory *factory)
void registerFactoryForProperties (const QValueList< int > &propertyTypes, CustomPropertyFactory *factory)
CustomPropertycreateCustomProperty (Property *parent)

Static Public Member Functions

static FactoryManagerself ()

Friends

class KStaticDeleter< KoProperty::FactoryManager >

Member Function Documentation

void FactoryManager::registerFactoryForEditor ( int  editorType,
CustomPropertyFactory factory 
)

Registers a custom factory factory for handling property editor for editorType. This custom factory will be used before defaults when widgetForProperty() is called. creator is not owned by this Factory object, but it's good idea to instantiate CustomPropertyFactory object itself as a child of Factory parent. For example:

            MyCustomPropertyFactory *f = new MyCustomPropertyFactory(KoProperty::Factory::self());
            KoProperty::Factory::self()->registerEditor( MyCustomType, f );

Definition at line 103 of file factory.cpp.

void FactoryManager::registerFactoryForEditors ( const QValueList< int > &  editorTypes,
CustomPropertyFactory factory 
)

Registers custom factory factory for handling property editors for editorTypes.

See also:
registerFactoryForEditor().

Definition at line 114 of file factory.cpp.

CustomPropertyFactory * FactoryManager::factoryForEditorType ( int  type  ) 

Returns:
custom factory for type type or NULL if there is no such property type registered. To create a custom widget createWidgetForProperty() should be rather used.

Definition at line 122 of file factory.cpp.

Widget * FactoryManager::createWidgetForProperty ( Property property  ) 

Creates and returns the editor for given property type. Warning: editor and viewer widgets won't have parent widget. Property editor cares about reparenting and deletion of returned widgets in machines. If createWidget is false, just create child properties, not widget.

Definition at line 128 of file factory.cpp.

void FactoryManager::registerFactoryForProperty ( int  propertyType,
CustomPropertyFactory factory 
)

Registers a custom factory that handles a CustomProperty of a type type. This function will be called every time a property of type is created.

Definition at line 223 of file factory.cpp.

void FactoryManager::registerFactoryForProperties ( const QValueList< int > &  propertyTypes,
CustomPropertyFactory factory 
)

Registers a custom property factory that handles a CustomProperty for types.

See also:
registerFactoryForProperty()

Definition at line 235 of file factory.cpp.

CustomProperty * FactoryManager::createCustomProperty ( Property parent  ) 

This function is called in Property::Property() to create (optional) custom property. It creates the custom property for built-in types, or calls one of createCustomProperty function previously registered for other types.

Definition at line 244 of file factory.cpp.

FactoryManager * FactoryManager::self (  )  [static]

Returns:
a pointer to a property factory instance.

Definition at line 93 of file factory.cpp.


The documentation for this class was generated from the following files:
KDE Home | KDE Accessibility Home | Description of Access Keys