lib/widgets/propeditor/pcombobox.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 )
00075 {
00076 emit
propertyChanged(
pname(),
value());
00077 }
00078
00079
#ifndef PURE_QT
00080
#include "pcombobox.moc"
00081
#endif
This file is part of the documentation for KDevelop Version 3.0.4.