1
/***************************************************************************
2
* Copyright (C) 2004 by Alexander Dymo <cloudtemple@mskat.net> *
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. *
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. *
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"
21
#include "propertylist.h"
23
namespace PropertyLib{
25
MultiProperty::MultiProperty(Property *prop)
31
MultiProperty::MultiProperty(PropertyList *propertyList)
32
:m_propertyList(propertyList)
36
MultiProperty::MultiProperty(PropertyList *propertyList, Property *prop)
37
:m_propertyList(propertyList)
42
MultiProperty::~MultiProperty()
46
QString MultiProperty::name() const
48
if (list.count() >= 1)
49
return list.getFirst()->name();
53
int MultiProperty::type() const
55
if (list.count() >= 1)
56
return list.getFirst()->type();
57
return QVariant::Invalid;
60
QVariant MultiProperty::value() const
63
if (list.count() >= 1)
64
value = list.getFirst()->value();
66
QPtrListIterator<Property> it(list);
68
while ((property = it.current()) != 0)
70
if (property->value() != value)
71
return QVariant::Invalid;
78
QString MultiProperty::description() const
81
if (list.count() >= 1)
82
description = list.getFirst()->description();
84
QPtrListIterator<Property> it(list);
86
while ((property = it.current()) != 0)
88
if (property->description() != description)
96
bool MultiProperty::readOnly() const
99
if (list.count() >= 1)
100
v = list.getFirst()->readOnly();
102
QPtrListIterator<Property> it(list);
104
while ((property = it.current()) != 0)
106
if (property->readOnly() != v)
114
bool MultiProperty::visible() const
117
if (list.count() >= 1)
118
v = list.getFirst()->readOnly();
120
QPtrListIterator<Property> it(list);
122
while ((property = it.current()) != 0)
124
if (property->visible() != v)
132
QMap<QString, QVariant> MultiProperty::valueList() const
134
if (list.count() >= 1)
135
return list.getFirst()->valueList;
136
return QMap<QString, QVariant>();
139
void MultiProperty::setDescription(const QString &description)
142
for (property = list.first(); property; property = list.next())
143
property->setDescription(description);
146
/*void MultiProperty::setName(const QString &name)
150
void MultiProperty::setType(int type)
154
void MultiProperty::setValue(const QVariant &value)
157
for (property = list.first(); property; property = list.next())
159
property->setValue(value);
162
// qWarning("emit change");
163
emit m_propertyList->propertyValueChanged(property);
168
void MultiProperty::setValue(const QVariant &value, bool emitChange)
171
for (property = list.first(); property; property = list.next())
173
property->setValue(value);
174
if (emitChange && m_propertyList)
175
emit m_propertyList->propertyValueChanged(property);
179
void MultiProperty::setValueList(const QMap<QString, QVariant> &valueList)
182
for (property = list.first(); property; property = list.next())
183
property->setValueList(valueList);
186
void MultiProperty::addProperty(Property *prop)
191
void MultiProperty::removeProperty(Property *prop)
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"); */
200
bool MultiProperty::operator ==(const MultiProperty &prop) const
202
if ( (type() == prop.type()) && (name() == prop.name()) )
207
bool MultiProperty::operator ==(const Property &prop) const
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()) )
216
void MultiProperty::addProperty( MultiProperty *prop)
219
for (property = prop->list.first(); property; property = prop->list.next())
220
addProperty(property);
223
void MultiProperty::removeProperty( MultiProperty *prop)
226
for (property = prop->list.first(); property; property = prop->list.next())
227
removeProperty(property);
230
QVariant MultiProperty::findValueDescription() const
232
QVariant val = value();
233
if (type() != Property::ValueFromList)
235
QMap<QString, QVariant> vl = valueList();
236
for (QMap<QString, QVariant>::const_iterator it = vl.begin(); it != vl.end(); ++ it)
238
if (it.data() == val)
244
QVariant MultiProperty::findValueDescription(QVariant val) const
246
if (type() != Property::ValueFromList)
248
QMap<QString, QVariant> vl = valueList();
249
for (QMap<QString, QVariant>::const_iterator it = vl.begin(); it != vl.end(); ++ it)
251
if (it.data() == val)
257
bool MultiProperty::valid() const
259
return list.count() != 0;
262
void MultiProperty::undo()
265
for (property = list.first(); property; property = list.next())
267
property->setValue(property->oldValue(), false);
269
emit m_propertyList->propertyValueChanged(property);