kexi
widgetwithsubpropertiesinterface.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "widgetwithsubpropertiesinterface.h"
00021
00022 #include <qmetaobject.h>
00023 #include <qasciidict.h>
00024
00025 #include <kdebug.h>
00026
00027 using namespace KFormDesigner;
00028
00029 WidgetWithSubpropertiesInterface::WidgetWithSubpropertiesInterface()
00030 {
00031 }
00032
00033 WidgetWithSubpropertiesInterface::~WidgetWithSubpropertiesInterface()
00034 {
00035 }
00036
00037 void WidgetWithSubpropertiesInterface::setSubwidget(QWidget *widget)
00038 {
00039 m_subwidget = widget;
00040 m_subproperies.clear();
00041 QAsciiDict<char> addedSubproperies(1024);
00042 if (m_subwidget) {
00043
00044 for( QMetaObject *metaObject = m_subwidget->metaObject(); metaObject; metaObject = metaObject->superClass()) {
00045 const int numProperties = metaObject->numProperties();
00046 for (int i = 0; i < numProperties; i++) {
00047 const char *propertyName = metaObject->property( i )->name();
00048 if (dynamic_cast<QObject*>(this)->metaObject()->findProperty( propertyName, true )==-1
00049 && !addedSubproperies.find( propertyName ) )
00050 {
00051 m_subproperies.append( propertyName );
00052 addedSubproperies.insert( propertyName, (char*)1 );
00053 kdDebug() << propertyName << endl;
00054 }
00055 }
00056 }
00057 qHeapSort( m_subproperies );
00058 }
00059 }
00060
00061 QWidget* WidgetWithSubpropertiesInterface::subwidget() const
00062 {
00063 return m_subwidget;
00064 }
00065
00066 QValueList<QCString> WidgetWithSubpropertiesInterface::subproperies() const
00067 {
00068 return m_subproperies;
00069 }
00070
00071 const QMetaProperty *WidgetWithSubpropertiesInterface::findMetaSubproperty(const char * name) const
00072 {
00073 if (!m_subwidget || m_subproperies.find(name) == m_subproperies.constEnd()) {
00074 return 0;
00075 }
00076 const int index = m_subwidget->metaObject()->findProperty( name, true );
00077 if (index==-1)
00078 return 0;
00079 return m_subwidget->metaObject()->property( index, true );
00080 }
00081
00082 QVariant WidgetWithSubpropertiesInterface::subproperty( const char * name, bool &ok ) const
00083 {
00084 if (!m_subwidget || m_subproperies.find(name) == m_subproperies.constEnd()) {
00085 ok = false;
00086 return QVariant();
00087 }
00088 ok = true;
00089 return m_subwidget->property( name );
00090 }
00091
00092 bool WidgetWithSubpropertiesInterface::setSubproperty( const char * name, const QVariant & value )
00093 {
00094 if (!m_subwidget || m_subproperies.find(name) == m_subproperies.end()) {
00095 return false;
00096 }
00097 return m_subwidget->setProperty( name, value );
00098 }
|