KDevelop API Documentation

propertywidgetproxy.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Alexander Dymo                                  *
00003  *   cloudtemple@mskat.net                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Library General Public License as       *
00007  *   published by the Free Software Foundation; either version 2 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU Library General Public     *
00016  *   License along with this program; if not, write to the                 *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #include "propertywidgetproxy.h"
00021 
00022 #include <qlayout.h>
00023 
00024 #include "propertywidget.h"
00025 #include "propertymachinefactory.h"
00026 
00027 namespace PropertyLib{
00028 
00029 PropertyWidgetProxy::PropertyWidgetProxy(QWidget *parent, const char *name)
00030     :QWidget(parent, name), mp(0), m_propertyType(Property::Invalid), m_editor(0)
00031 {
00032     p = new Property();
00033     m_layout = new QHBoxLayout(this, 0, 0);
00034 }
00035 
00036 PropertyWidgetProxy::~PropertyWidgetProxy()
00037 {
00038     delete mp;
00039     delete p;
00040 }
00041 
00042 void PropertyWidgetProxy::setPropertyType(int propertyType)
00043 {
00044     m_propertyType = static_cast<Property::PropertyType>(propertyType);
00045     setWidget();
00046 }
00047 
00048 void PropertyWidgetProxy::setPropertyType2(PropertyType propertyType)
00049 {
00050     m_propertyType = propertyType;
00051     setWidget();
00052 }
00053 
00054 void PropertyWidgetProxy::setWidget()
00055 {
00056     if (m_editor)
00057         delete m_editor;
00058     p->setType(m_propertyType);
00059     mp = new MultiProperty(p);
00060     m_editor = PropertyMachineFactory::getInstance()->machineForProperty(mp)->propertyEditor;
00061     if (m_editor)
00062     {
00063         m_editor->reparent(this, QPoint(0,0), true);
00064         m_layout->addWidget(m_editor);
00065     }
00066 }
00067 
00068 QVariant PropertyWidgetProxy::value() const
00069 {
00070     if (m_editor)
00071         return m_editor->value();
00072     else
00073         return QVariant();
00074 }
00075 
00076 void PropertyWidgetProxy::setValue(const QVariant &value)
00077 {
00078     if (m_editor)
00079         m_editor->setValue(value, false);
00080 }
00081 
00082 bool PropertyWidgetProxy::setProperty( const char * name, const QVariant & value )
00083 {
00084     if( strcmp( name, "value") == 0 )
00085     {
00086         setPropertyType((int) value.type() );
00087         setValue( value );
00088         return true;
00089     }
00090     else
00091         return QWidget::setProperty(name, value);
00092 }
00093 
00094 QVariant PropertyWidgetProxy::property( const char * name ) const
00095 {
00096     if( strcmp( name, "value") == 0 )
00097         return value(  );
00098     else
00099         return QWidget::property(name);
00100 }
00101 
00102 }
00103 #include "propertywidgetproxy.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:37 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003