summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/umllistviewitem.h
blob: 97594c61243a8cc1a745e0360e13aa27736a1552 (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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   copyright (C) 2002-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 *                                                                         *
 ***************************************************************************/

#ifndef UMLLISTVIEWITEM_H
#define UMLLISTVIEWITEM_H

#include <tqlistview.h>
#include <tqmap.h>
#include <tqdom.h>
#include "umlnamespace.h"

// forward declarations
class UMLListView;
class UMLObject;
class UMLClassifierListItem;

/**
 * Items used by the class @ref UMLListView.  This is needed as the type
 * and object information is required to be stored.
 *
 * @short  Items used by @ref UMLListView.
 * @author Paul Hensgen <phensgen@techie.com>
 * @see    UMLListView
 * Bugs and comments to uml-devel@lists.sf.net or http://bugs.trinitydesktop.org
 */

class UMLListViewItem : public TQListViewItem {
public:
    /**
     * Sets up an instance.
     *
     * @param parent    The parent to this instance.
     * @param name              The name of this instance.
     * @param t         The type of this instance.
     * @param o         The object it represents.
     */
    UMLListViewItem(UMLListView * parent, const TQString &name, Uml::ListView_Type t, UMLObject*o=0);

    /**
     * Sets up an instance for subsequent loadFromXMI().
     *
     * @param parent    The parent to this instance.
     */
    UMLListViewItem(UMLListView * parent);

    /**
     * Sets up an instance for subsequent loadFromXMI().
     *
     * @param parent    The parent to this instance.
     */
    UMLListViewItem(UMLListViewItem * parent);

    /**
     * Sets up an instance.
     *
     * @param parent    The parent to this instance.
     * @param name              The name of this instance.
     * @param t         The type of this instance.
     * @param o         The object it represents.
     */
    UMLListViewItem(UMLListViewItem * parent, const TQString &name, Uml::ListView_Type t, UMLObject*o=0);

    /**
     * Sets up an instance.
     *
     * @param parent    The parent to this instance.
     * @param name              The name of this instance.
     * @param t         The type of this instance.
     * @param id                The id of this instance.
     */
    UMLListViewItem(UMLListViewItem * parent, const TQString &name, Uml::ListView_Type t, Uml::IDType id);

    /**
     * Standard deconstructor.
     */
    ~UMLListViewItem();

    /**
     * Returns the type this instance represents.
     *
     * @return  The type this instance represents.
     */
    Uml::ListView_Type getType() const;

    /**
     * Sets the id this class represents.
     * This only sets the ID locally, not at the UMLObject that is perhaps
     * associated to this UMLListViewItem.
     *
     * @return  The id this class represents.
     */
    void setID(Uml::IDType id);

    /**
     * Returns the id this class represents.
     *
     * @return  The id this class represents.
     */
    Uml::IDType getID() const;

    /**
     * Set the UMLObject associated with this instance.
     *
     * @param obj  The object this class represents.
     */
    void setUMLObject(UMLObject * obj) {
        m_pObject = obj;
    }

    /**
     * Return the UMLObject associated with this instance.
     *
     * @return  The object this class represents.
     */
    UMLObject * getUMLObject() {
        return m_pObject;
    }

    /**
     * Returns true if the UMLListViewItem of the given ID is a parent of
     * this UMLListViewItem.
     */
    bool isOwnParent(Uml::IDType listViewItemID);

    /**
     * Updates the representation of the object.
     */
    void updateObject();

    /**
     * Updates the icon on a folder.
     */
    void updateFolder();

    /**
     * Overrides default method.
     * Will call default method but also makes sure correct icon is shown.
     */
    void setOpen( bool open );

    /**
     * Changes the current text and updates the tooltip.
     */
    void setText( const TQString &text );

    /**
     * Returns the current text.
     */
    TQString getText() const;

    /**
     * Sets if the item is in the middle of being created.
     */
    void setCreating( bool creating ) {
        m_bCreating = creating;
    }

    /**
     * Set the pixmap corresponding to the given Icon_Type.
     */
    void setIcon(Uml::Icon_Type iconType);

    /**
     * Overrides default method to make public.
     */
    void cancelRename( int col );

    /**
     * Adds the child listview item representing the given UMLClassifierListItem.
     */
    void addClassifierListItem(UMLClassifierListItem *child, UMLListViewItem *childItem);

    /**
     * Deletes the child listview item representing the given UMLClassifierListItem.
     */
    void deleteChildItem(UMLClassifierListItem *child);

    /**
     * Overrides the default sorting to sort by item type.
     */
    virtual int compare(TQListViewItem *other, int col, bool ascending) const;

    /**
     * Returns the number of children of the UMLListViewItem
     * containing this object
     */
    int childCount() const {
        return m_nChildren;
    }

    /**
     * Create a deep copy of this UMLListViewItem, but using the
     * given parent instead of the parent of this UMLListViewItem.
     * Return the new UMLListViewItem created.
     */
    UMLListViewItem* deepCopy(UMLListViewItem *newParent);

    /**
     * Find the UMLListViewItem that is related to the given UMLObject
     * in the tree rooted at the current UMLListViewItem.
     * Return a pointer to the item or NULL if not found.
     */
    UMLListViewItem* findUMLObject(const UMLObject *o);

    /**
     * Find the UMLListViewItem that represents the given UMLClassifierListItem
     * in the children of the current UMLListViewItem.  (Only makes sense if
     * the current UMLListViewItem represents a UMLClassifier.)
     * Return a pointer to the item or NULL if not found.
     */
    UMLListViewItem* findChildObject(UMLClassifierListItem *cli);

    /**
     * Find the UMLListViewItem of the given ID in the tree rooted at
     * the current UMLListViewItem.
     * Return a pointer to the item or NULL if not found.
     *
     * @param id                The ID to search for.
     * @return  The item with the given ID or NULL if not found.
     */
    UMLListViewItem * findItem(Uml::IDType id);

    /**
     * saves the listview item to a "listitem" tag
     */
    void saveToXMI( TQDomDocument& qDoc, TQDomElement& qElement);

    /**
     * Loads a "listitem" tag, this is only used by the clipboard currently
     */
    bool loadFromXMI(TQDomElement& qElement);

protected:
    /**
     * Initializes key variables of the class.
     */
    void init(UMLListView * parent = 0);

    /**
     * This function is called if the user presses Enter during in-place renaming
     * of the item in column col, reimplemented from QlistViewItem
     */
    void okRename( int col );

    /**
     * Auxiliary method for okRename().
     */
    void cancelRenameWithMsg();

    /**
     * This list view all the instance of this class are displayed on.
     */
    static UMLListView * s_pListView;

    /**
     * Flag used to set the state of creating.
     */
    bool m_bCreating;

    /**
     * Auxiliary map of child UMLLisViewItems keyed by UMLClassifierListItem.
     * Used by findChildObject() for efficiency instead of looping using
     * firstChild()/nextSibling() because the latter incur enforceItemVisible()
     * and thus expensive sorting.
     */
    typedef TQMap<UMLClassifierListItem*, UMLListViewItem*> ChildObjectMap;

    Uml::ListView_Type m_Type;
    Uml::IDType m_nId;
    int m_nChildren;
    UMLObject * m_pObject;
    TQString m_Label;
    ChildObjectMap m_comap;
};

#endif