~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to lib/widgets/propeditor/pcombobox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2002-2004 by Alexander Dymo                             *
3
 
 *   cloudtemple@mskat.net                                                 *
4
 
 *                                                                         *
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.                       *
9
 
 *                                                                         *
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.                          *
14
 
 *                                                                         *
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"
21
 
 
22
 
#include <qcombobox.h>
23
 
#include <qlayout.h>
24
 
 
25
 
namespace PropertyLib{
26
 
 
27
 
PComboBox::PComboBox(MultiProperty *property, const QMap<QString, QVariant> &list, QWidget *parent, const char *name)
28
 
    :PropertyWidget(property, parent, name), m_valueList(list)
29
 
{
30
 
    init(false);
31
 
}
32
 
 
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)
35
 
{
36
 
    init(rw);
37
 
}
38
 
 
39
 
void PComboBox::init(bool rw)
40
 
{
41
 
    QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
42
 
    m_edit = new QComboBox(rw, this);
43
 
    m_edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
44
 
    l->addWidget(m_edit);
45
 
    
46
 
    fillBox();
47
 
    
48
 
    connect(m_edit, SIGNAL(activated(int)), this, SLOT(updateProperty(int)));
49
 
}
50
 
 
51
 
void PComboBox::fillBox()
52
 
{
53
 
    for (QMap<QString, QVariant>::const_iterator it = m_valueList.begin(); it != m_valueList.end(); it++)
54
 
    {
55
 
        m_edit->insertItem(it.key());
56
 
    }
57
 
}
58
 
 
59
 
QVariant PComboBox::value() const
60
 
{
61
 
    QMap<QString, QVariant>::const_iterator it = m_valueList.find(m_edit->currentText());
62
 
    if (it == m_valueList.end())
63
 
        return QVariant("");
64
 
    return QVariant(it.data());
65
 
}
66
 
 
67
 
void PComboBox::setValue(const QVariant &value, bool emitChange)
68
 
{
69
 
#if QT_VERSION >= 0x030100
70
 
    if (!value.isNull())
71
 
#else
72
 
    if (value.canCast(QVariant::String))
73
 
#endif
74
 
    {
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)));
78
 
        if (emitChange)
79
 
            emit propertyChanged(m_property, value);
80
 
    }
81
 
}
82
 
 
83
 
void PComboBox::updateProperty(int /*val*/)
84
 
{
85
 
    emit propertyChanged(m_property, value());
86
 
}
87
 
 
88
 
QString PComboBox::findDescription(const QVariant &value)
89
 
{
90
 
    for (QMap<QString, QVariant>::const_iterator it = m_valueList.begin(); it != m_valueList.end(); ++ it)
91
 
    {
92
 
        if (it.data() == value)
93
 
            return it.key();
94
 
    }
95
 
    return "";
96
 
}
97
 
 
98
 
void PComboBox::setValueList(const QMap<QString, QVariant> &valueList)
99
 
{
100
 
    m_valueList = valueList;
101
 
    m_edit->clear();
102
 
    fillBox();
103
 
}
104
 
 
105
 
}
106
 
 
107
 
#ifndef PURE_QT
108
 
#include "pcombobox.moc"
109
 
#endif
110