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

« back to all changes in this revision

Viewing changes to lib/widgets/propeditor/multiproperty.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) 2004 by Alexander Dymo  <cloudtemple@mskat.net>         *
3
 
 *                                                                         *
4
 
 *   This program is free software; you can redistribute it and/or modify  *
5
 
 *   it under the terms of the GNU Library General Public License as       *
6
 
 *   published by the Free Software Foundation; either version 2 of the    *
7
 
 *   License, or (at your option) any later version.                       *
8
 
 *                                                                         *
9
 
 *   This program is distributed in the hope that it will be useful,       *
10
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 
 *   GNU General Public License for more details.                          *
13
 
 *                                                                         *
14
 
 *   You should have received a copy of the GNU Library General Public     *
15
 
 *   License along with this program; if not, write to the                 *
16
 
 *   Free Software Foundation, Inc.,                                       *
17
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 
 ***************************************************************************/
19
 
#include "multiproperty.h"
20
 
 
21
 
#include "propertylist.h"
22
 
 
23
 
namespace PropertyLib{
24
 
 
25
 
MultiProperty::MultiProperty(Property *prop)
26
 
    :m_propertyList(0)
27
 
{
28
 
    list.append(prop);
29
 
}
30
 
 
31
 
MultiProperty::MultiProperty(PropertyList *propertyList)
32
 
    :m_propertyList(propertyList)
33
 
{
34
 
}
35
 
 
36
 
MultiProperty::MultiProperty(PropertyList *propertyList, Property *prop)
37
 
    :m_propertyList(propertyList)
38
 
{
39
 
    list.append(prop);
40
 
}
41
 
 
42
 
MultiProperty::~MultiProperty()
43
 
{
44
 
}
45
 
 
46
 
QString MultiProperty::name() const
47
 
{
48
 
    if (list.count() >= 1)
49
 
        return list.getFirst()->name();
50
 
    return QString::null;   
51
 
}
52
 
 
53
 
int MultiProperty::type() const
54
 
{
55
 
    if (list.count() >= 1)
56
 
        return list.getFirst()->type();
57
 
    return QVariant::Invalid;   
58
 
}
59
 
 
60
 
QVariant MultiProperty::value() const
61
 
{
62
 
    QVariant value;
63
 
    if (list.count() >= 1)
64
 
        value = list.getFirst()->value();
65
 
 
66
 
    QPtrListIterator<Property> it(list);
67
 
    Property *property;
68
 
    while ((property = it.current()) != 0)
69
 
    {
70
 
        if (property->value() != value)
71
 
            return QVariant::Invalid;
72
 
        ++it;
73
 
    }
74
 
 
75
 
    return value;
76
 
}
77
 
 
78
 
QString MultiProperty::description() const
79
 
{
80
 
    QString description;
81
 
    if (list.count() >= 1)
82
 
        description = list.getFirst()->description();
83
 
 
84
 
    QPtrListIterator<Property> it(list);
85
 
    Property *property;
86
 
    while ((property = it.current()) != 0)
87
 
    {
88
 
        if (property->description() != description)
89
 
            return QString::null;
90
 
        ++it;
91
 
    }
92
 
 
93
 
    return description;
94
 
}
95
 
 
96
 
bool MultiProperty::readOnly() const
97
 
{
98
 
    bool v = true;
99
 
    if (list.count() >= 1)
100
 
        v = list.getFirst()->readOnly();
101
 
 
102
 
    QPtrListIterator<Property> it(list);
103
 
    Property *property;
104
 
    while ((property = it.current()) != 0)
105
 
    {
106
 
        if (property->readOnly() != v)
107
 
            return false;
108
 
        ++it;
109
 
    }
110
 
 
111
 
    return v;
112
 
}
113
 
 
114
 
bool MultiProperty::visible() const
115
 
{
116
 
    bool v = true;
117
 
    if (list.count() >= 1)
118
 
        v = list.getFirst()->readOnly();
119
 
 
120
 
    QPtrListIterator<Property> it(list);
121
 
    Property *property;
122
 
    while ((property = it.current()) != 0)
123
 
    {
124
 
        if (property->visible() != v)
125
 
            return false;
126
 
        ++it;
127
 
    }
128
 
 
129
 
    return v;
130
 
}
131
 
 
132
 
QMap<QString, QVariant> MultiProperty::valueList() const
133
 
{
134
 
    if (list.count() >= 1)
135
 
        return list.getFirst()->valueList;
136
 
    return QMap<QString, QVariant>();
137
 
}
138
 
 
139
 
void MultiProperty::setDescription(const QString &description)
140
 
{
141
 
    Property *property;
142
 
    for (property = list.first(); property; property = list.next())
143
 
        property->setDescription(description);
144
 
}
145
 
 
146
 
/*void MultiProperty::setName(const QString &name)
147
 
{
148
 
}
149
 
 
150
 
void MultiProperty::setType(int type)
151
 
{
152
 
}
153
 
*/
154
 
void MultiProperty::setValue(const QVariant &value)
155
 
{
156
 
    Property *property;
157
 
    for (property = list.first(); property; property = list.next())
158
 
    {
159
 
        property->setValue(value);
160
 
        if (m_propertyList)
161
 
        {
162
 
//             qWarning("emit change");
163
 
            emit m_propertyList->propertyValueChanged(property);
164
 
        }
165
 
    }
166
 
}
167
 
 
168
 
void MultiProperty::setValue(const QVariant &value, bool emitChange)
169
 
{
170
 
    Property *property;
171
 
    for (property = list.first(); property; property = list.next())
172
 
    {
173
 
        property->setValue(value);
174
 
        if (emitChange && m_propertyList)
175
 
            emit m_propertyList->propertyValueChanged(property);
176
 
    }
177
 
}
178
 
 
179
 
void MultiProperty::setValueList(const QMap<QString, QVariant> &valueList)
180
 
{
181
 
    Property *property;
182
 
    for (property = list.first(); property; property = list.next())
183
 
        property->setValueList(valueList);
184
 
}
185
 
 
186
 
void MultiProperty::addProperty(Property *prop)
187
 
{
188
 
    list.append(prop);
189
 
}
190
 
 
191
 
void MultiProperty::removeProperty(Property *prop)
192
 
{
193
 
/*    qWarning("op >>            removing %s", prop->name().ascii());
194
 
    qWarning("op >>            list is %d", list.count());*/
195
 
    /*bool b = */list.remove(prop);
196
 
/*    qWarning("op >>            list is %d", list.count());
197
 
    qWarning("op >>            removal is %s", b?"true":"false");    */
198
 
}
199
 
 
200
 
bool MultiProperty::operator ==(const MultiProperty &prop) const
201
 
{
202
 
    if ( (type() == prop.type()) && (name() == prop.name()) )
203
 
        return true;
204
 
    return false;
205
 
}
206
 
 
207
 
bool MultiProperty::operator ==(const Property &prop) const
208
 
{
209
 
/*    qWarning("MultiProperty::operator == for %s = %s", name().ascii(), prop.name().ascii());
210
 
    qWarning("MultiProperty::operator == for %d = %d", type(), prop.type());*/
211
 
    if ( (type() == prop.type()) && (name() == prop.name()) )
212
 
        return true;
213
 
    return false;
214
 
}
215
 
 
216
 
void MultiProperty::addProperty( MultiProperty *prop)
217
 
{
218
 
    Property *property;
219
 
    for (property = prop->list.first(); property; property = prop->list.next())
220
 
        addProperty(property);
221
 
}
222
 
 
223
 
void MultiProperty::removeProperty( MultiProperty *prop)
224
 
{
225
 
    Property *property;
226
 
    for (property = prop->list.first(); property; property = prop->list.next())
227
 
        removeProperty(property);
228
 
}
229
 
 
230
 
QVariant MultiProperty::findValueDescription() const
231
 
{
232
 
    QVariant val = value();
233
 
    if (type() != Property::ValueFromList)
234
 
        return val;
235
 
    QMap<QString, QVariant> vl = valueList();
236
 
    for (QMap<QString, QVariant>::const_iterator it = vl.begin(); it != vl.end(); ++ it)
237
 
    {
238
 
        if (it.data() == val)
239
 
            return it.key();
240
 
    }
241
 
    return "";
242
 
}
243
 
 
244
 
QVariant MultiProperty::findValueDescription(QVariant val) const
245
 
{
246
 
    if (type() != Property::ValueFromList)
247
 
        return val;
248
 
    QMap<QString, QVariant> vl = valueList();
249
 
    for (QMap<QString, QVariant>::const_iterator it = vl.begin(); it != vl.end(); ++ it)
250
 
    {
251
 
        if (it.data() == val)
252
 
            return it.key();
253
 
    }
254
 
    return "";
255
 
}
256
 
 
257
 
bool MultiProperty::valid() const
258
 
{
259
 
    return list.count() != 0;
260
 
}
261
 
 
262
 
void MultiProperty::undo()
263
 
{
264
 
    Property *property;
265
 
    for (property = list.first(); property; property = list.next())
266
 
    {
267
 
        property->setValue(property->oldValue(), false);
268
 
        if (m_propertyList)
269
 
            emit m_propertyList->propertyValueChanged(property);
270
 
    }
271
 
}
272
 
 
273
 
}