widgetwithsubpropertiesinterface.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "widgetwithsubpropertiesinterface.h"
21
22#include <tqmetaobject.h>
23#include <tqasciidict.h>
24
25#include <kdebug.h>
26
27using namespace KFormDesigner;
28
29WidgetWithSubpropertiesInterface::WidgetWithSubpropertiesInterface()
30{
31}
32
33WidgetWithSubpropertiesInterface::~WidgetWithSubpropertiesInterface()
34{
35}
36
38{
39 m_subwidget = widget;
40 m_subproperies.clear();
41 TQAsciiDict<char> addedSubproperies(1024);
42 if (m_subwidget) {
43 //remember properties in the subwidget that are not present in the parent
44 for( TQMetaObject *metaObject = m_subwidget->metaObject(); metaObject; metaObject = metaObject->superClass()) {
45 const int numProperties = metaObject->numProperties();
46 for (int i = 0; i < numProperties; i++) {
47 const char *propertyName = metaObject->property( i )->name();
48 if (dynamic_cast<TQObject*>(this)->metaObject()->findProperty( propertyName, true )==-1
49 && !addedSubproperies.find( propertyName ) )
50 {
51 m_subproperies.append( propertyName );
52 addedSubproperies.insert( propertyName, (char*)1 );
53 kdDebug() << propertyName << endl;
54 }
55 }
56 }
57 qHeapSort( m_subproperies );
58 }
59}
60
62{
63 return m_subwidget;
64}
65
67{
68 return m_subproperies;
69}
70
72{
73 if (!m_subwidget || m_subproperies.find(name) == m_subproperies.constEnd()) {
74 return 0;
75 }
76 const int index = m_subwidget->metaObject()->findProperty( name, true );
77 if (index==-1)
78 return 0;
79 return m_subwidget->metaObject()->property( index, true );
80}
81
82TQVariant WidgetWithSubpropertiesInterface::subproperty( const char * name, bool &ok ) const
83{
84 if (!m_subwidget || m_subproperies.find(name) == m_subproperies.constEnd()) {
85 ok = false;
86 return TQVariant();
87 }
88 ok = true;
89 return m_subwidget->property( name );
90}
91
92bool WidgetWithSubpropertiesInterface::setSubproperty( const char * name, const TQVariant & value )
93{
94 if (!m_subwidget || m_subproperies.find(name) == m_subproperies.end()) {
95 return false;
96 }
97 return m_subwidget->setProperty( name, value );
98}
void setSubwidget(TQWidget *widget)
Sets widget subwidget handling subproperties.
bool setSubproperty(const char *name, const TQVariant &value)
Sets a subproperty value value for a subproperty name.
const TQMetaProperty * findMetaSubproperty(const char *name) const
TQVariant subproperty(const char *name, bool &ok) const
type * findParent(TQObject *o, const char *className, TQObject *&prevPrev)