KDevelop API Documentation

lib/widgets/propeditor/pcombobox.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2002 Alexander Dymo <cloudtemple@mksat.net> 00003 00004 This library 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 library 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 library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include "pcombobox.h" 00021 #include "propertyeditor.h" 00022 00023 PComboBox::PComboBox ( const PropertyEditor *editor, const QString pname, const QVariant value, QMap<QString, QString> *v_corresp, QWidget * parent, const char * name): 00024 QComboBox(parent, name), corresp(v_corresp) 00025 { 00026 init(editor, pname, value); 00027 } 00028 00029 PComboBox::PComboBox ( const PropertyEditor *editor, const QString pname, const QVariant value, QMap<QString, QString> *v_corresp, bool rw, QWidget * parent, const char * name): 00030 QComboBox(rw, parent, name), corresp(v_corresp) 00031 { 00032 init(editor, pname, value); 00033 } 00034 00035 void PComboBox::init( const PropertyEditor *editor, const QString & pname, const QVariant & value ) 00036 { 00037 fillBox(); 00038 setValue(value, false); 00039 setPName(pname); 00040 connect(this, SIGNAL(activated(int)), this, SLOT(updateProperty(int))); 00041 connect(this, SIGNAL(propertyChanged(QString, QString)), editor, SLOT(emitPropertyChange(QString, QString))); 00042 } 00043 00044 void PComboBox::fillBox() 00045 { 00046 for (QMap<QString, QString>::const_iterator it = corresp->begin(); it != corresp->end(); it++) 00047 { 00048 insertItem(it.key()); 00049 r_corresp[it.data()] = it.key(); 00050 } 00051 } 00052 00053 QVariant PComboBox::value() const 00054 { 00055 QMap<QString, QString>::const_iterator it = corresp->find(currentText()); 00056 if (it==corresp->end()) return QVariant(""); 00057 return QVariant(it.data()); 00058 } 00059 00060 void PComboBox::setValue(const QVariant value, bool emitChange) 00061 { 00062 #if QT_VERSION >= 0x030100 00063 if (!value.isNull()) 00064 #else 00065 if (value.canCast(QVariant::String)) 00066 #endif 00067 { 00068 setCurrentText(r_corresp[value.toString()]); 00069 if (emitChange) 00070 emit propertyChanged(pname(), value); 00071 } 00072 } 00073 00074 void PComboBox::updateProperty(int /*val*/) 00075 { 00076 emit propertyChanged(pname(), value()); 00077 } 00078 00079 #ifndef PURE_QT 00080 #include "pcombobox.moc" 00081 #endif
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:08 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003