1
/***************************************************************************
2
* Copyright (C) 2002-2004 by Alexander Dymo *
3
* cloudtemple@mskat.net *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU Library General Public License as *
7
* published by the Free Software Foundation; either version 2 of the *
8
* License, or (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU Library General Public *
16
* License along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
20
#include "pcombobox.h"
22
#include <qcombobox.h>
25
namespace PropertyLib{
27
PComboBox::PComboBox(MultiProperty *property, const QMap<QString, QVariant> &list, QWidget *parent, const char *name)
28
:PropertyWidget(property, parent, name), m_valueList(list)
33
PComboBox::PComboBox(MultiProperty *property, const QMap<QString, QVariant> &list, bool rw, QWidget *parent, const char *name)
34
:PropertyWidget(property, parent, name), m_valueList(list)
39
void PComboBox::init(bool rw)
41
QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
42
m_edit = new QComboBox(rw, this);
43
m_edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
48
connect(m_edit, SIGNAL(activated(int)), this, SLOT(updateProperty(int)));
51
void PComboBox::fillBox()
53
for (QMap<QString, QVariant>::const_iterator it = m_valueList.begin(); it != m_valueList.end(); it++)
55
m_edit->insertItem(it.key());
59
QVariant PComboBox::value() const
61
QMap<QString, QVariant>::const_iterator it = m_valueList.find(m_edit->currentText());
62
if (it == m_valueList.end())
64
return QVariant(it.data());
67
void PComboBox::setValue(const QVariant &value, bool emitChange)
69
#if QT_VERSION >= 0x030100
72
if (value.canCast(QVariant::String))
75
disconnect(m_edit, SIGNAL(activated(int)), this, SLOT(updateProperty(int)));
76
m_edit->setCurrentText(findDescription(value));
77
connect(m_edit, SIGNAL(activated(int)), this, SLOT(updateProperty(int)));
79
emit propertyChanged(m_property, value);
83
void PComboBox::updateProperty(int /*val*/)
85
emit propertyChanged(m_property, value());
88
QString PComboBox::findDescription(const QVariant &value)
90
for (QMap<QString, QVariant>::const_iterator it = m_valueList.begin(); it != m_valueList.end(); ++ it)
92
if (it.data() == value)
98
void PComboBox::setValueList(const QMap<QString, QVariant> &valueList)
100
m_valueList = valueList;
108
#include "pcombobox.moc"