Framework change (HURRRRAAAYYYYYYYY)
Andreas Zehender <[email protected]>
| Newsgroups | gmane.comp.kde.devel.kpovmodeler |
|---|---|
| Message-ID | <[email protected]> |
Hi Luis!
I just made a huge commit: The major framework change towards object plugins
is finished (quite excited about that)
What's new:
- The PMTObjectType is obsolete. Instead PMObject::type( ) and
PMObject::className( ) both return now a QString: The class name without the
PM prefix ("Box" for the PMBox class). The class name was lower case before
but never used except in the saved scene file. The lower case version is
still used in the serialization to be compatible to the current format.
- You can now set and get properties by name. More about that later.
- The insertion possibilities are now determined by a rule based system. The
rules are defined in the file 'baseinsertrules.xml'. I added a dtd file
'pminsertrules.dtd' to validate the rules. The dtd file contains small
descriptions for all tags. But the rules are quite readable anyway.
What has to be changed for new objects (if you implemented some recently):
1) Add a copy constructor
2) The pure virtual method PMObject* PMObject::copy( ) has to be implemented
to return a deep copy of the object (simply call the copy constructor)
3) The pure virtual method PMMetaObject* PMObject::metaObject( ) has to be
implemented.
The PMMetaObject class contains class information: The class name, a pointer
to the super class meta object and a description of the available properties.
Each class contains now a static pointer s_pMetaObject.
To delete the meta object on program exit, all classes implement the
PMObject::cleanup( ) method (some already do to delete other static objects).
The properties system works as follows:
Each property is represented by an instance of the PMPropertyBase class. This
class holds method pointers to the get and set method for the property.
To make this type safe, this class has to be inherited for each object, which
would be quite painful. Instead I created a macro:
PMDefinePropertyClass( theClass, PMProperty ) that defines a property class
PMProperty for the specified class. (see pmmetaobject.h)
This defined class has constructors for all common types used in the get and
set methods.
One example (PMBox):
PMDefinePropertyClass( PMBox, PMProperty );
[...]
PMMetaObject* PMBox::metaObject( ) const
{
if( !s_pMetaObject )
{
s_pMetaObject = new PMMetaObject( "Box", Base::metaObject( ) );
s_pMetaObject->addProperty(
new PMProperty( "corner1", &PMBox::setCorner1, &PMBox::corner1 ) );
s_pMetaObject->addProperty(
new PMProperty( "corner2", &PMBox::setCorner2, &PMBox::corner2 ) );
}
return s_pMetaObject;
}
Properties can be get and set with
bool PMObject::setProperty( const QString& name, const PMVariant& value )
(returns true if sucessfull) and
PMVariant PMObject::property( const QString& name )
In the setProperty method, the property class first tries to convert the
variant to the correct type (known from the called constructor) and then
calls the correct set method.
For example you can use string variants with "true" and "false" string as
booleans (used by the insertion possibilities rule system, and maybe later by
scripts)
Special for enum types:
Enum types are stored as strings. There is an additional macro:
PMDefineEnumPropertyClass(theClass, theClass::theEnum, theEnumPropertyClass)
The PMEnumProperty class one additional method:
PMEnumProperty::addEnumValue( const QString& str, int value ).
Call this for all constants and the class will make the whole conversion.
Example (PMLight):
PMDefineEnumPropertyClass( PMLight, PMLight::PMLightType, PMTypeProperty );
[...]
PMTypeProperty* p = new PMTypeProperty( "lightType", &PMLight::setLightType,
&PMLight::lightType );
p->addEnumValue( "PointLight", PointLight );
p->addEnumValue( "SpotLight", SpotLight );
p->addEnumValue( "CylinderLight", CylinderLight );
p->addEnumValue( "ShadowlessLight", ShadowlessLight );
s_pMetaObject->addProperty( p );
You can then set the light type with
aLightInstance->setProperty( "lightType", PMVariant( "PointLight" ) );
4) These methods can now be removed:
- all canInsert methods
- all countChild(BlaBlub) methods
- the isA method
- the className and type methods
5) Special for textures: The method linkPossibilities is obsolete. The
declaration object returns now the a class name as declaration type. And this
class name has to match to the textures class name for links.
I think these changes make object plugins immediately possible!
:-))))
I hope I didn't forget anything important.
Andreas
--
--------------------------------------------------
Andreas Zehender, Dipl. Ing. (BA)
Student, 10th semester computer science
http://www.azweb.de
[email protected] | [email protected]
--------------------------------------------------
List archive and information: http://mail.kde.org/mailman/listinfo/kpovmodeler-devel