PDA

View Full Version : Usage of QtDesignerPropertySheetExtension



SamFredericks
4th May 2011, 16:14
Hello,

I wrote my own ButtonPlugin for the QtDesigner. In addition I implemented for this ButtonPlugin an own ButtonPropertySheetExtension.

I used the template from QtCreator for creating QtDesigner-Plugins and only changed the following function in ButtonPlugin.cpp:


void ButtonPlugin::initialize(QDesignerFormEditorInterf ace * core)
{
if (m_initialized)
return;

QExtensionManager *manager = core->extensionManager();
Q_ASSERT(manager != 0);

manager->registerExtensions(new ButtonPropertyFactory(manager), Q_TYPEID(QDesignerPropertySheetExtension));

m_initialized = true;
}

In addition I created ButtonPropertySheetExtension.h:


#include <QObject>
#include <QMap>
#include <QString>
#include <QDesignerPropertySheetExtension>
#include <QExtensionFactory>

#include "button.h"

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertyFactory
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
class ButtonPropertyFactory : public QExtensionFactory
{
Q_OBJECT

public:
ButtonPropertyFactory(QExtensionManager *parent = 0);

protected:
QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const;
};

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertySheetExtension
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
class ButtonPropertySheetExtension : public QObject, QDesignerPropertySheetExtension
{
Q_OBJECT
Q_INTERFACES(QDesignerPropertySheetExtension)

public:
ButtonPropertySheetExtension(Button* p, QObject *parent);


int count (void) const;
bool hasReset ( int index ) const;
int indexOf ( const QString & name ) const;
bool isAttribute ( int index ) const;
bool isChanged ( int index ) const;
bool isVisible ( int index ) const;
QVariant property ( int index ) const;
QString propertyGroup ( int index ) const;
QString propertyName ( int index ) const;
bool reset ( int index );
void setAttribute ( int index, bool attribute );
void setChanged ( int index, bool changed );
void setProperty ( int index, const QVariant & value );
void setPropertyGroup ( int index, const QString & group );
void setVisible ( int index, bool visible );

protected:

Button* _powner;
const QMetaObject* _p_metaobject;

QMap<int, QString> _PropertyGroups;
};


And I created ButtonPropertySheetExtension.cpp:


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertyFactory
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
ButtonPropertyFactory::ButtonPropertyFactory(QExte nsionManager *parent)
: QExtensionFactory(parent)
{
}


QObject *ButtonPropertyFactory::createExtension(QObject *object,
const QString &iid,
QObject *parent) const
{
if (iid != Q_TYPEID(QDesignerPropertySheetExtension))
return 0;

if (Button* pbutton = qobject_cast<Button*>(object))
return new ButtonPropertySheetExtension(pbutton, parent);

return 0;
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ButtonPropertySheetExtension
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/


ButtonPropertySheetExtension::ButtonPropertySheetE xtension(Button* p, QObject *parent) :
QObject(parent),
_powner(p),
_p_metaobject(_powner->metaObject()),
_PropertyGroups()
{
const int i_object_index = indexOf("objectName");
setPropertyGroup(i_object_index, "QObject");

const int i_widget_index = indexOf("modal");
setPropertyGroup(i_widget_index, "QWidget");

const int i_abstractbutton_index = indexOf("text");
setPropertyGroup(i_abstractbutton_index, "QAbstractButton");

const int i_pushbutton_index = indexOf("autoDefault");
setPropertyGroup(i_pushbutton_index, "QPushButton");
}

int ButtonPropertySheetExtension::count () const
{
return _p_metaobject->propertyCount();
}

bool ButtonPropertySheetExtension::hasReset ( int index ) const
{
return _p_metaobject->property(index).isResettable();
}

int ButtonPropertySheetExtension::indexOf ( const QString & name ) const
{
return _p_metaobject->indexOfProperty( name.toLatin1().constData() );
}

bool ButtonPropertySheetExtension::isAttribute ( int index ) const
{
Q_UNUSED(index)
return false;
}

bool ButtonPropertySheetExtension::isChanged ( int index ) const
{
Q_UNUSED(index)
return false;
}

bool ButtonPropertySheetExtension::isVisible ( int index ) const
{
Q_UNUSED(index)
return true;
}

QVariant ButtonPropertySheetExtension::property ( int index ) const
{
return _p_metaobject->property(index).read(_powner);
}

QString ButtonPropertySheetExtension::propertyGroup ( int index ) const
{
QMap<int, QString>::const_iterator it = _PropertyGroups.begin();
if (index > 0){
while (it.key() <= index){
it++;
}
it--;
}
return it.value();
}

QString ButtonPropertySheetExtension::propertyName ( int index ) const
{
return QString(_p_metaobject->property(index).name());
}

bool ButtonPropertySheetExtension::reset ( int index )
{
return _p_metaobject->property(index).reset(_powner);
}

void ButtonPropertySheetExtension::setAttribute ( int index, bool attribute )
{
Q_UNUSED(index)
Q_UNUSED(attribute)
}

void ButtonPropertySheetExtension::setChanged ( int index, bool changed )
{
Q_UNUSED(index)
Q_UNUSED(changed)
}

void ButtonPropertySheetExtension::setProperty ( int index, const QVariant & value )
{
QMetaProperty metaproperty = _p_metaobject->property(index);
metaproperty.write(_powner, value);
}

void ButtonPropertySheetExtension::setPropertyGroup ( int index, const QString & group )
{
_PropertyGroups.insert(index, group);
}

void ButtonPropertySheetExtension::setVisible ( int index, bool visible )
{
Q_UNUSED(index)
Q_UNUSED(visible)
}


So my question, why is the attribute "icon" of QAbstractButton not shown in QtDesigner?

The same behaviour occurs by implementing - for example LabelPlugin (QLabel). Here the "pixmap" Property will be not shown.

I would be very happy aboput any good advice.
Thanks

tbscope
4th May 2011, 16:22
So my question, why is the attribute "icon" of QAbstractButton not shown in QtDesigner?
Where in the code above do you use QAbstractButton?

Edit:


Warning: Qt Designer uses the QDesignerPropertySheetExtension to feed its property editor. Whenever a widget is selected in its workspace, Qt Designer will query for the widget's property sheet extension. If the selected widget has an implemented property sheet extension, this extension will override the default property sheet.

You need to add the icon property manually?

SamFredericks
4th May 2011, 16:27
Mm. Sorry. Perhaps it was the wrong question.

My Button class owns the Properties from QAbstractButton, even "icon".
In the function isVisible(), I always return true. Because of this all properties should be visible. (You can Debug here, icon is visible)

But icon is not shown.....:confused:

SamFredericks
5th May 2011, 08:07
You need to add the icon property manually?

Reallly? Why is the - for example - PaletteEditorButton by a Property of the type QVariant::Palette shown, but not the PixmapEditor by a Property of the type QVariant::Pixmap/Icon?

If I have to implement the PixmapEditor/"QFileDialog to choose a pixmap for the icon" by myself, I won't see any interface for configuring the appearance; to dock - for example - a QFileDialog into the Value-Column of the PropertyEditor. I don't know how. Do you have any examples/ideas?

....:( The whole mechanism is a big mysterium, and you can't find a good documentation in web...

SamFredericks
12th May 2011, 12:52
If I have to implement the PixmapEditor/"QFileDialog to choose a pixmap for the icon" by myself, I won't see any interface for configuring the appearance; to dock - for example - a QFileDialog into the Value-Column of the PropertyEditor.

If you create your own CustomWidget class with a property of a new metatype, there will be no possibility to show/edit this property in the QDesignerPropertyEditor. Even special types of QVariant are not supported.
There is no interface to update the functionality of the QDesignerPropertyEditor.:(

If you are interested in a workaround of the QDesignerPropertyEditor, please vote for this topic:
http://bugreports.qt.nokia.com/browse/QTBUG-2074