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
00022 #include <qcombobox.h>
00023 #include <qlayout.h>
00024
00025 namespace PropertyLib{
00026
00027 PComboBox::PComboBox(MultiProperty *property, const QMap<QString, QVariant> &list, QWidget *parent, const char *name)
00028 :PropertyWidget(property, parent, name), m_valueList(list)
00029 {
00030 init(false);
00031 }
00032
00033 PComboBox::PComboBox(MultiProperty *property, const QMap<QString, QVariant> &list, bool rw, QWidget *parent, const char *name)
00034 :PropertyWidget(property, parent, name), m_valueList(list)
00035 {
00036 init(rw);
00037 }
00038
00039 void PComboBox::init(bool rw)
00040 {
00041 QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00042 m_edit = new QComboBox(rw, this);
00043 m_edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
00044 l->addWidget(m_edit);
00045
00046 fillBox();
00047
00048 connect(m_edit, SIGNAL(activated(int)), this, SLOT(updateProperty(int)));
00049 }
00050
00051 void PComboBox::fillBox()
00052 {
00053 for (QMap<QString, QVariant>::const_iterator it = m_valueList.begin(); it != m_valueList.end(); it++)
00054 {
00055 m_edit->insertItem(it.key());
00056 }
00057 }
00058
00059 QVariant PComboBox::value() const
00060 {
00061 QMap<QString, QVariant>::const_iterator it = m_valueList.find(m_edit->currentText());
00062 if (it == m_valueList.end())
00063 return QVariant("");
00064 return QVariant(it.data());
00065 }
00066
00067 void PComboBox::setValue(const QVariant &value, bool emitChange)
00068 {
00069 #if QT_VERSION >= 0x030100
00070 if (!value.isNull())
00071 #else
00072 if (value.canCast(QVariant::String))
00073 #endif
00074 {
00075 disconnect(m_edit, SIGNAL(activated(int)), this, SLOT(updateProperty(int)));
00076 m_edit->setCurrentText(findDescription(value));
00077 connect(m_edit, SIGNAL(activated(int)), this, SLOT(updateProperty(int)));
00078 if (emitChange)
00079 emit propertyChanged(m_property, value);
00080 }
00081 }
00082
00083 void PComboBox::updateProperty(int )
00084 {
00085 emit propertyChanged(m_property, value());
00086 }
00087
00088 QString PComboBox::findDescription(const QVariant &value)
00089 {
00090 for (QMap<QString, QVariant>::const_iterator it = m_valueList.begin(); it != m_valueList.end(); ++ it)
00091 {
00092 if (it.data() == value)
00093 return it.key();
00094 }
00095 return "";
00096 }
00097
00098 void PComboBox::setValueList(const QMap<QString, QVariant> &valueList)
00099 {
00100 m_valueList = valueList;
00101 m_edit->clear();
00102 fillBox();
00103 }
00104
00105 }
00106
00107 #ifndef PURE_QT
00108 #include "pcombobox.moc"
00109 #endif
00110
This file is part of the documentation for KDevelop Version 3.1.2.