1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
/***************************************************************************
* Copyright (C) 2004 by Alexander Dymo *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef PROPERTYLIST_H
#define PROPERTYLIST_H
#include <tqobject.h>
#include <tqmap.h>
#include <tqptrlist.h>
#include <tqvaluelist.h>
#include <tqpair.h>
namespace PropertyLib{
class Property;
class MultiProperty;
/** @file propertylist.h
@short Contains @ref PropertyLib::PropertyList class.
*/
/**
@short The list of properties.
Every object in a program should operate with properties through
this list in order to:
- be informed about property changes
- allow property lists intersections
- display properties in the property editor widget (see @ref PropertyLib::PropertyEditor).
.
PropertyList owns properties and deletes them itself. For a list that does not own
it's properties, look at @ref PropertyLib::PropertyBuffer class.
PropertyList is also capable of grouping properties.
You can have unsorted list of groups of properties or a plain
alphabetically sorted list of properties or both at the same time.
*/
class PropertyList: public TQObject
{
TQ_OBJECT
public:
class Iterator {
public:
void operator ++();
void operator ++(int);
MultiProperty *operator *();
bool operator != (Iterator it);
TQString key();
MultiProperty *data();
private:
Iterator(PropertyList *list);
Iterator(PropertyList *list, bool end);
void next();
TQMap<TQString, MultiProperty*>::iterator current;
PropertyList *m_list;
friend class PropertyList;
};
typedef Iterator iterator;
PropertyList();
virtual ~PropertyList();
/**Accesses a property by it's name. All property modifications are allowed
trough this method. For example, to set a value of a property, use:
/code
PropertyList list;
...
list["My Property"]->setValue("My Value");
/endcode
@return @ref MultiProperty with given name.*/
virtual MultiProperty *operator[](const TQString &name);
/**Accesses a property by it's name. All property modifications are allowed
trough this method. For example, to set a value of a property
*/
MultiProperty *property( const TQString &name );
/**Adds the property to the list to the "common" group.*/
virtual void addProperty(Property *property);
/**Adds the property to the list in group.*/
virtual void addProperty(const TQString &group, Property *property);
/**Removes property from the list. Emits aboutToDeleteProperty before removing.*/
virtual void removeProperty(Property *property);
/**Removes property with the given name from the list.
Emits @ref aboutToDeleteProperty before removing.*/
virtual void removeProperty(const TQString &name);
/**@return the list of grouped properties.*/
virtual const TQValueList<TQPair<TQString, TQValueList<TQString> > >& propertiesOfGroup() const;
/**@return the map: property - group name.*/
virtual const TQMap<MultiProperty*, TQString>& groupOfProperty() const;
/**Clears the list of properties.*/
virtual void clear();
/**Returns true if the list of properties contains property with given name.*/
virtual bool contains(const TQString &name);
/**The list of properties with given name.*/
TQPtrList<Property> properties(const TQString &name);
Iterator begin();
Iterator end();
signals:
/**Emitted when the value of the property is changed.*/
void propertyValueChanged(Property* property);
/**Emitted when property is about to be deleted.*/
void aboutToDeleteProperty(Property* property);
protected:
/**Constructs a list which owns or does not own it's properties.*/
PropertyList(bool propertyOwner);
/**Adds property to a group.*/
void addToGroup(const TQString &group, MultiProperty *property);
/**Removes property from a group.*/
void removeFromGroup(MultiProperty *property);
private:
//sorted list of properties in form name: property
TQMap<TQString, MultiProperty*> m_list;
//groups of properties:
// list of group name: (list of property names)
TQValueList<TQPair<TQString, TQValueList<TQString> > > m_propertiesOfGroup;
// map of property: group
TQMap<MultiProperty*, TQString> m_groupOfProperty;
//indicates that this list will delete properties after removeProperty()
//and also in destructor
bool m_propertyOwner;
friend class MultiProperty;
friend class PropertyBuffer;
friend class Iterator;
};
/**
@short The list of properties which does not own them.
This class acts as @ref PropertyLib::PropertyList but it does not delete properties
in destructor (i.e. it does not own properties).
This class should be used to store results of property intersections.
Example:
/code
PropertyList *list = new PropertyList();
PropertyList *list2 = new PropertyList();
PropertyList *list3 = new PropertyList();
...
PropertyBuffer *buf = new PropertyBuffer(list);
buf->intersect(list2);
buf->intersect(list3);
...
/endcode
*/
class PropertyBuffer: public PropertyList{
TQ_OBJECT
public:
/**Constructs a buffer from given property list.*/
PropertyBuffer(PropertyList *list);
/**Constructs an empty property buffer.*/
PropertyBuffer();
/**Intersects with other @ref PropertyLib::PropertyList.*/
virtual void intersect(const PropertyList *list);
protected slots:
void intersectedValueChanged(Property *property);
};
}
#endif
|