summaryrefslogtreecommitdiffstats
path: root/lib/koproperty/set.h
blob: 90c7534f66db5296c22a449759d55f9af592dfa7 (plain)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/* This file is part of the KDE project
   Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
   Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
   Copyright (C) 2004-2006 Jaroslaw Staniek <js@iidea.pl>

   This library 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 library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef KPROPERTY_SET_H
#define KPROPERTY_SET_H

#include "koproperty_global.h"
#include <tqobject.h>
#include <tqasciidict.h>

namespace KoProperty {

class Property;
class SetPrivate;

/*! \brief Lists holding properties in groups

   \author Cedric Pasteur <cedric.pasteur@free.fr>
   \author Alexander Dymo <cloudtemple@mskat.net>
   \author Jaroslaw Staniek <js@iidea.pl>
 */
class KOPROPERTY_EXPORT Set : public TQObject
{
	TQ_OBJECT
  

	public:
		/*! \brief A class to iterate over a Set.
		It behaves like a TQDictIterator. To use it:
		\code  for(Set::Iterator it(set); it.current(); ++it) { .... }
		\endcode
		  \author Cedric Pasteur <cedric.pasteur@free.fr>
		  \author Alexander Dymo <cloudtemple@mskat.net> */
		class KOPROPERTY_EXPORT Iterator {
			public:
				Iterator(const Set &set);
				~Iterator();

				void operator ++();
				Property*  operator *() const;

				TQCString  currentKey() const;
				Property*  current() const;

			private:
				TQAsciiDictIterator<Property> *iterator;
				friend class Set;
		};

		explicit Set(TQObject *parent=0, const TQString &typeName=TQString());

		/*! Constructs a deep copy of \a set. 
		 The new object will not have a TQObject parent even if \a set has such parent. */
		explicit Set(const Set& set);

		virtual ~Set();

		/*! Adds the property to the set, in the group. You can use any group name, except "common"
		  (which is already used for basic group). */
		void addProperty(Property *property, TQCString group = "common");

		/*! Removes property from the set. Emits aboutToDeleteProperty before removing.*/
		void removeProperty(Property *property);

		/*! Removes property with the given name from the set.
		Emits aboutToDeleteProperty() before removing.*/
		void removeProperty(const TQCString &name);

		/*! Removes all properties from the property set and destroys them. */
		virtual void clear();

		/*! \return the number of items in the set. */
		uint count() const;

		/*! \return true if the set is empty, i.e. count() == 0; otherwise returns false. */
		bool isEmpty() const;

		/*! \return true if the set is read-only. 
		 In read-only property set, 
		 no property can be modified regardless of read-only flag of any 
		 property (see Property::isReadOnly()). On the other hand, if Property::isReadOnly()
		 is true of a property and Set::isReadOnly() is false, the property is still read-only.
		 Read-only property set prevents editing in the property editor. 
		 By default the set is read-write. */
		bool isReadOnly() const;

		/*! Sets this set to be read-only. 
		 @see isReadOnly */
		void setReadOnly(bool readOnly);

		/*! \return true if the set contains property names \a name. */
		bool contains(const TQCString &name) const;

		/*! \return property named with \a name. If no such property is found,
		 null property (Property::null) is returned. */
		Property& property( const TQCString &name) const;

		/*! Accesses a property by it's name. 
		Property reference is returned, so all property modifications are allowed.
		If there is no such property, null property is returned, 
		so it's good practice to use contains() is you're unsure if the property exists. 
		For example, to set a value of a property, use:
		/code
		Set set;
		...
		if (!set.contains("myProperty")) {
			dosomething;
		}
		set["myProperty"].setValue("My Value");
		/endcode
		\return \ref Property with given name. */
		Property& operator[](const TQCString &name) const;

		/*! Creates a deep copy of \a set and assigns it to this property set. */
		const Set& operator= (const Set &set);

		/*! Change the value of property whose key is \a property to \a value.
		By default, it only calls Property::setValue(). */
		void changeProperty(const TQCString &property, const TQVariant &value);

		/*! Sets the i18n'ed string that will be shown in Editor to represent 
		 \a group. */
		void setGroupDescription(const TQCString &group, const TQString& desc);

		/*! \return the i18n'ed description string for \a group that will 
		 be shown in Editor to represent \a group. If there is no special 
		 description set for the group, \a group is just returned. */
		TQString groupDescription(const TQCString &group) const;

		/*! Sets the icon name \a icon to be displayed for \a group. */
		void setGroupIcon(const TQCString &group, const TQString& icon);

		/*! \return the icons name for \a group. */
		TQString groupIcon(const TQCString &group) const;

		/*! \return a list of all group names. The order is the same as the order 
		 of creation. */
		const TQValueList<TQCString>& groupNames() const;

		/*! \return a list of all property names. The order is the same as the order 
		 of creation. */
		const TQValueList<TQCString>& propertyNamesForGroup(const TQCString &group) const;

		/*! Used by property editor to preserve previous selection when this set 
		 is assigned again. */
		TQCString prevSelection() const;

		void setPrevSelection(const TQCString& prevSelection);

		/*! A name of this property set type, that is usable when
		 we want to know if two property set objects have the same type.
		 This avoids e.g. reloading of all Editor's contents.
		 Also, this allows to know if two property set objects are compatible
		 by their property sets.
		 For comparing purposes, type names are case insensitive.*/
		TQString typeName() const;

		/*! Prints debug output for this set. */
		void debug();

	protected:
		/*! Constructs a set which owns or does not own it's properties.*/
		Set(bool propertyOwner);

		/*! Adds property to a group.*/
		void addToGroup(const TQCString &group, Property *property);

		/*! Removes property from a group.*/
		void removeFromGroup(Property *property);

		/*! Adds the property to the set, in the group. You can use any group name, except "common"
		  (which is already used for basic group). If \a updateSortingKey is true, the sorting key
			will be set automatically to count(). 
			@internal */
		void addPropertyInternal(Property *property, TQCString group, bool updateSortingKey);

		/*! @internal used to declare that \a property wants to be informed 
		 that the set has been cleared (all properties are deleted) */
		void informAboutClearing(bool& cleared);

	signals:
		/*! Emitted when the value of the property is changed.*/
		void propertyChanged(KoProperty::Set& set, KoProperty::Property& property);

		/*! @internal Exists to be sure that we emitted it before propertyChanged(), 
		 so Editor object can handle this. */
		void propertyChangedInternal(KoProperty::Set& set, KoProperty::Property& property);

		/*! Emitted when the value of the property is reset.*/
		void propertyReset(KoProperty::Set& set, KoProperty::Property& property);

		/*! Emitted when property is about to be deleted.*/
		void aboutToDeleteProperty(KoProperty::Set& set, KoProperty::Property& property);

		/*! Emitted when property set object is about to be cleared (using clear()). 
		 This signal is also emmited from destructor before emitting aboutToBeDeleted(). */
		void aboutToBeCleared();

		/*! Emitted when property set object is about to be deleted.*/
		void aboutToBeDeleted();

	protected:
		SetPrivate *d;

	friend class Iterator;
	friend class Property;
	friend class Buffer;
};

/*! \brief
	\todo find a better name to show it's a set that doesn't own property
   \author Cedric Pasteur <cedric.pasteur@free.fr>
   \author Alexander Dymo <cloudtemple@mskat.net>
   \author Adam Treat <treat@kde.org>
 */
class KOPROPERTY_EXPORT Buffer : public Set
{
	TQ_OBJECT
  

	public:
		Buffer();
		Buffer(const Set *set);

		/*! Intersects with other Set.*/
		virtual void intersect(const Set *set);

	protected slots:
		void intersectedChanged(KoProperty::Set& set, KoProperty::Property& prop);
		void intersectedReset(KoProperty::Set& set, KoProperty::Property& prop);

	private:
		void initialSet(const Set *set);
};

}

#endif