1
/***************************************************************************
2
* Copyright (C) 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
#ifndef PROPERTYLIST_H
21
#define PROPERTYLIST_H
26
#include <qvaluelist.h>
29
namespace PropertyLib{
34
/** @file propertylist.h
35
@short Contains @ref PropertyLib::PropertyList class.
39
@short The list of properties.
41
Every object in a program should operate with properties through
42
this list in order to:
43
- be informed about property changes
44
- allow property lists intersections
45
- display properties in the property editor widget (see @ref PropertyLib::PropertyEditor).
48
PropertyList owns properties and deletes them itself. For a list that does not own
49
it's properties, look at @ref PropertyLib::PropertyBuffer class.
51
PropertyList is also capable of grouping properties.
52
You can have unsorted list of groups of properties or a plain
53
alphabetically sorted list of properties or both at the same time.
55
class PropertyList: public QObject
63
void operator ++(int);
65
MultiProperty *operator *();
67
bool operator != (Iterator it);
70
MultiProperty *data();
73
Iterator(PropertyList *list);
74
Iterator(PropertyList *list, bool end);
77
QMap<QString, MultiProperty*>::iterator current;
80
friend class PropertyList;
83
typedef Iterator iterator;
86
virtual ~PropertyList();
88
/**Accesses a property by it's name. All property modifications are allowed
89
trough this method. For example, to set a value of a property, use:
93
list["My Property"]->setValue("My Value");
95
@return @ref MultiProperty with given name.*/
96
virtual MultiProperty *operator[](const QString &name);
97
/**Accesses a property by it's name. All property modifications are allowed
98
trough this method. For example, to set a value of a property
100
MultiProperty *property( const QString &name );
102
/**Adds the property to the list to the "common" group.*/
103
virtual void addProperty(Property *property);
104
/**Adds the property to the list in group.*/
105
virtual void addProperty(const QString &group, Property *property);
106
/**Removes property from the list. Emits aboutToDeleteProperty before removing.*/
107
virtual void removeProperty(Property *property);
108
/**Removes property with the given name from the list.
109
Emits @ref aboutToDeleteProperty before removing.*/
110
virtual void removeProperty(const QString &name);
112
/**@return the list of grouped properties.*/
113
virtual const QValueList<QPair<QString, QValueList<QString> > >& propertiesOfGroup() const;
114
/**@return the map: property - group name.*/
115
virtual const QMap<MultiProperty*, QString>& groupOfProperty() const;
117
/**Clears the list of properties.*/
118
virtual void clear();
119
/**Returns true if the list of properties contains property with given name.*/
120
virtual bool contains(const QString &name);
122
/**The list of properties with given name.*/
123
QPtrList<Property> properties(const QString &name);
129
/**Emitted when the value of the property is changed.*/
130
void propertyValueChanged(Property* property);
131
/**Emitted when property is about to be deleted.*/
132
void aboutToDeleteProperty(Property* property);
135
/**Constructs a list which owns or does not own it's properties.*/
136
PropertyList(bool propertyOwner);
138
/**Adds property to a group.*/
139
void addToGroup(const QString &group, MultiProperty *property);
140
/**Removes property from a group.*/
141
void removeFromGroup(MultiProperty *property);
144
//sorted list of properties in form name: property
145
QMap<QString, MultiProperty*> m_list;
147
//groups of properties:
148
// list of group name: (list of property names)
149
QValueList<QPair<QString, QValueList<QString> > > m_propertiesOfGroup;
150
// map of property: group
151
QMap<MultiProperty*, QString> m_groupOfProperty;
153
//indicates that this list will delete properties after removeProperty()
154
//and also in destructor
155
bool m_propertyOwner;
157
friend class MultiProperty;
158
friend class PropertyBuffer;
159
friend class Iterator;
164
@short The list of properties which does not own them.
166
This class acts as @ref PropertyLib::PropertyList but it does not delete properties
167
in destructor (i.e. it does not own properties).
168
This class should be used to store results of property intersections.
172
PropertyList *list = new PropertyList();
173
PropertyList *list2 = new PropertyList();
174
PropertyList *list3 = new PropertyList();
176
PropertyBuffer *buf = new PropertyBuffer(list);
177
buf->intersect(list2);
178
buf->intersect(list3);
182
class PropertyBuffer: public PropertyList{
185
/**Constructs a buffer from given property list.*/
186
PropertyBuffer(PropertyList *list);
187
/**Constructs an empty property buffer.*/
190
/**Intersects with other @ref PropertyLib::PropertyList.*/
191
virtual void intersect(const PropertyList *list);
194
void intersectedValueChanged(Property *property);