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

« back to all changes in this revision

Viewing changes to lib/widgets/propeditor/propertylist.h

  • 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                                  *
3
 
 *   cloudtemple@mskat.net                                                 *
4
 
 *                                                                         *
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.                       *
9
 
 *                                                                         *
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.                          *
14
 
 *                                                                         *
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
22
 
 
23
 
#include <qobject.h>
24
 
#include <qmap.h>
25
 
#include <qptrlist.h>
26
 
#include <qvaluelist.h>
27
 
#include <qpair.h>
28
 
 
29
 
namespace PropertyLib{
30
 
 
31
 
class Property;
32
 
class MultiProperty;
33
 
 
34
 
/** @file propertylist.h
35
 
@short Contains @ref PropertyLib::PropertyList class.
36
 
*/
37
 
 
38
 
/**
39
 
@short The list of properties.
40
 
 
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).
46
 
.
47
 
 
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.
50
 
 
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.
54
 
*/
55
 
class PropertyList: public QObject
56
 
{
57
 
    Q_OBJECT
58
 
 
59
 
public:
60
 
    class Iterator {
61
 
    public:
62
 
        void operator ++();
63
 
        void operator ++(int);
64
 
        
65
 
        MultiProperty *operator *();
66
 
        
67
 
        bool operator != (Iterator it);
68
 
        
69
 
        QString key();
70
 
        MultiProperty *data();
71
 
        
72
 
    private:
73
 
        Iterator(PropertyList *list);
74
 
        Iterator(PropertyList *list, bool end);
75
 
        
76
 
        void next();
77
 
        QMap<QString, MultiProperty*>::iterator current;
78
 
        
79
 
        PropertyList *m_list;
80
 
        friend class PropertyList;
81
 
    };
82
 
    
83
 
    typedef Iterator iterator;
84
 
    
85
 
    PropertyList();
86
 
    virtual ~PropertyList();
87
 
 
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:
90
 
    /code
91
 
    PropertyList list;
92
 
    ...
93
 
    list["My Property"]->setValue("My Value");
94
 
    /endcode
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
99
 
    */
100
 
    MultiProperty *property( const QString &name );
101
 
 
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);
111
 
    
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;
116
 
    
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);
121
 
    
122
 
    /**The list of properties with given name.*/
123
 
    QPtrList<Property> properties(const QString &name);
124
 
    
125
 
    Iterator begin();
126
 
    Iterator end();
127
 
 
128
 
signals:
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);
133
 
    
134
 
protected:
135
 
    /**Constructs a list which owns or does not own it's properties.*/
136
 
    PropertyList(bool propertyOwner);
137
 
 
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);
142
 
        
143
 
private:
144
 
    //sorted list of properties in form name: property
145
 
    QMap<QString, MultiProperty*> m_list;
146
 
    
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;
152
 
 
153
 
    //indicates that this list will delete properties after removeProperty()
154
 
    //and also in destructor
155
 
    bool m_propertyOwner;
156
 
    
157
 
friend class MultiProperty;
158
 
friend class PropertyBuffer;
159
 
friend class Iterator;
160
 
};
161
 
 
162
 
 
163
 
/**
164
 
@short The list of properties which does not own them.
165
 
 
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.
169
 
 
170
 
Example:
171
 
/code
172
 
PropertyList *list = new PropertyList();
173
 
PropertyList *list2 = new PropertyList();
174
 
PropertyList *list3 = new PropertyList();
175
 
...
176
 
PropertyBuffer *buf = new PropertyBuffer(list);
177
 
buf->intersect(list2);
178
 
buf->intersect(list3);
179
 
...
180
 
/endcode
181
 
*/
182
 
class PropertyBuffer: public PropertyList{
183
 
    Q_OBJECT
184
 
public:
185
 
    /**Constructs a buffer from given property list.*/
186
 
    PropertyBuffer(PropertyList *list);
187
 
    /**Constructs an empty property buffer.*/
188
 
    PropertyBuffer();
189
 
 
190
 
    /**Intersects with other @ref PropertyLib::PropertyList.*/
191
 
    virtual void intersect(const PropertyList *list);
192
 
 
193
 
protected slots:
194
 
    void intersectedValueChanged(Property *property);
195
 
    
196
 
};
197
 
 
198
 
}
199
 
 
200
 
#endif