kexi

widgetwithsubpropertiesinterface.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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         //remember properties in the subwidget that are not present in the parent
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 }
KDE Home | KDE Accessibility Home | Description of Access Keys