summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/umllistview.h
blob: 2e9bf421a0a2ddfe59b434617882587054adceb8 (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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/***************************************************************************
 *                                                                         *
 *   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 UMLLISTVIEW_H
#define UMLLISTVIEW_H

#include <tqdom.h>
#include <tqpixmap.h>
#include <tdelistview.h>
#include "umlnamespace.h"
#include "umllistviewitemlist.h"

/**
 * This is one of the main classes used in this program.
 * Information is displayed here in a tree view.  No objects are created
 * here.  A call to @ref UMLDoc make any additions/deletion or updates to
 * objects.  This class will then wait for a signal before updating the tree view.
 *
 * @short  Displays the list view for the program.
 * @author Paul Hensgen    <phensgen@techie.com>
 * Bugs and comments to uml-devel@lists.sf.net or http://bugs.trinitydesktop.org
 */

class TQMouseEvent;
class TQContextMenuEvent;
class TQKeyEvent;
class IDChangeLog;
class ListPopupMenu;
class UMLClassifier;
class UMLDoc;
class UMLListViewItem;
class UMLView;
class UMLObject;
class UMLClassifierListItem;

class UMLListView : public TDEListView {
    Q_OBJECT
  
public:

    /**
     * Constructs the tree view.
     *
     * @param parent    The parent to this.
     * @param name              The internal name for this class.
     */
    UMLListView(TQWidget *parent,const char *name);

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

    /**
     * Sets the document his is associated with.  This is important as
     * this is required as to setup the callbacks.
     *
     * @param d         The document to associate with this class.
     */
    void setDocument(UMLDoc * d);

    /**
     * Carries out initalisation of attributes in class.
     */
    void init();

    /**
     * Set the current view to the given view.
     *
     * @param v         The current view.
     */
    void setView(UMLView* v);

    /**
     * Get selected items.
     *
     * @param ItemList  List of UMLListViewItems returned.
     * @return          The number of selected items.
     */
    int getSelectedItems(UMLListViewItemList &ItemList);

    /**
     * Get selected items, but only root elements selected (without children).
     *
     * @param ItemList  List of UMLListViewItems returned.
     * @return          The number of selected items.
     */
    int getSelectedItemsRoot(UMLListViewItemList &ItemList);

    /**
     * Create a listview item for an existing diagram.
     *
     * @param v         The existing diagram.
     */
    UMLListViewItem* createDiagramItem(UMLView *v);

    /**
     * CHECK - This is perhaps redundant since the
     *         UMLListViewItemData => UMLListViewItem merge.
     * Creates a new UMLListViewItem from a UMLListViewItem, if
     * parent is null the ListView Decides who is going to be the
     * parent
     */
    UMLListViewItem* createItem(UMLListViewItem& Data, IDChangeLog& IDChanges,
                                UMLListViewItem* parent = 0);

    /**
     * Find the parent folder for a diagram.
     * If the currently selected item in the list view is a folder
     * then that folder is returned as the parent.
     *
     * @param dt   The Diagram_Type of the diagram.
     *             The type will only be used if there is no currently
     *             selected item, or if the current item is not a folder.
     *             In that case the root folder which is suitable for the
     *             Diagram_Type is returned.
     * @return  Pointer to the parent UMLListViewItem for the diagram.
     */
    UMLListViewItem *findFolderForDiagram(Uml::Diagram_Type dt);

    /**
     * Determine the parent ListViewItem given an UMLObject.
     *
     * @param object   Pointer to the UMLObject for which to look up the parent.
     * @return    Pointer to the parent UMLListViewItem chosen.
     *            Returns NULL on error (no parent could be determined.)
     */
    UMLListViewItem* determineParentItem(UMLObject* object) const;

    /**
     * Determine the parent ListViewItem given a ListView_Type.
     * This parent is used for creating new UMLListViewItems.
     *
     * @param lvt       The ListView_Type for which to lookup the parent.
     * @return  Pointer to the parent UMLListViewItem chosen.
     */
    UMLListViewItem* determineParentItem(Uml::ListView_Type lvt) const;

    /**
     * Return true if the given Object_Type permits child items.
     * A "child item" is anything that qualifies as a UMLClassifierListItem,
     * e.g. operations and attributes of classifiers.
     */
    static bool mayHaveChildItems(Uml::Object_Type type);

    /**
     *  Return the amount of items selected.
     */
    int getSelectedCount();

    /**
     * Returns the correct pixmap for the given type.
     */
    TQPixmap & getPixmap( Uml::Icon_Type type );

    /**
     * Returns the document pointer.  Called by the UMLListViewItem class.
     */
    UMLDoc * getDocument() {
        return m_doc;
    }

    /**
     * Adds a new item to the tree of the given type under the given parent.
     * Method will take care of signalling anyone needed on creation of new item.
     * e.g. UMLDoc if an UMLObject is created.
     */
    void addNewItem(UMLListViewItem * parent, Uml::ListView_Type type);

    /**
     * Find an UMLObject in the listview.
     *
     * @param p         Pointer to the object to find in the list view.
     * @return  Pointer to the UMLObject found or NULL if not found.
     */
    UMLListViewItem * findUMLObject(const UMLObject *p) const;

    /**
     * Searches through the tree for the item which represents the diagram given
     * @param v  the diagram to search for
     * @return the item which represents the diagram
     */
    UMLListViewItem * findView(UMLView *v);

    /**
     * Searches through the tree for the item with the given ID.
     *
     * @param id                The ID to search for.
     * @return  The item with the given ID or NULL if not found.
     */
    UMLListViewItem * findItem(Uml::IDType id);

    /**
     * Returns the corresponding view if the listview type is one of the root views,
     * Root/Logical/UseCase/Component/Deployment/EntityRelation View.
     */
    UMLListViewItem *rootView(Uml::ListView_Type type);

    /**
     * Changes the icon for the given UMLObject to the given icon.
     */
    void changeIconOf(UMLObject *o, Uml::Icon_Type to);

    /**
     * Creates a UMLObject out of the given list view item.
     */
    UMLObject *createUMLObject( UMLListViewItem * item, Uml::Object_Type type );

    /**
     * Creates a child UMLObject out of the given list view item.
     */
    bool createChildUMLObject( UMLListViewItem * item, Uml::Object_Type type );

    /**
     * Creates a diagram out of the given list view item.
     */
    void createDiagram( UMLListViewItem * item, Uml::Diagram_Type type );

    /**
     * Returns a unique name for a diagram.
     */
    TQString getUniqueDiagramName( Uml::Diagram_Type type );

    /**
     * Returns if the given name is unique for the given items type.
     */
    bool isUnique( UMLListViewItem * item, const TQString &name );

    /**
     * Cancel rename event has occurred for the given item.
     */
    void  cancelRename( TQListViewItem * item );

    /**
     * Set the variable m_bStartedCut
     * to indicate that selection should be deleted
     * in slotCutSuccessful()
     */
    void setStartedCut(bool startedCut);

    /**
     * Set the variable m_bStartedCopy.
     * NB: While m_bStartedCut is reset as soon as the Cut operation is done,
     *     the variable m_bStartedCopy is reset much later - upon pasting.
     */
    void setStartedCopy(bool startedCopy);

    /**
     * Return the variable m_bStartedCopy.
     */
    bool startedCopy() const;

    /**
     * Moves an object given is unique ID and listview type to an
     * other listview parent item.
     * Also takes care of the corresponding move in the model.
     */
    UMLListViewItem * moveObject(Uml::IDType srcId, Uml::ListView_Type srcType,
                                 UMLListViewItem *newParent);

    /**
     * Called for informing the list view that an item was renamed.
     */
    bool itemRenamed(TQListViewItem* item , int col);

    void closeDatatypesFolder();

    UMLListViewItem *theRootView() { return m_rv; }
    UMLListViewItem *theLogicalView() { return m_lv[Uml::mt_Logical]; }
    UMLListViewItem *theUseCaseView() { return m_lv[Uml::mt_UseCase]; }
    UMLListViewItem *theComponentView() { return m_lv[Uml::mt_Component]; }
    UMLListViewItem *theDeploymentView() { return m_lv[Uml::mt_Deployment]; }
    UMLListViewItem *theDatatypeFolder() { return m_datatypeFolder; }

    /**
     * Determines the root listview type of the given UMLListViewItem.
     * Starts at the given item, compares it against each of the
     * predefined root views (Root, Logical, UseCase, Component,
     * Deployment, EntityRelationship.) Returns the ListView_Type
     * of the matching root view; if no match then continues the
     * search using the item's parent, then grandparent, and so forth.
     * Returns Uml::lvt_Unknown if no match at all is found.
     */
    Uml::ListView_Type rootViewType(UMLListViewItem *item);

    void saveToXMI( TQDomDocument & qDoc, TQDomElement & qElement);

    bool loadFromXMI( TQDomElement & element );

    bool loadChildrenFromXMI( UMLListViewItem * parent, TQDomElement & element );

protected:
    UMLListViewItem* m_rv;    // root view (home)
    UMLListViewItem* m_lv[Uml::N_MODELTYPES];    // predefined list view roots
    UMLListViewItem* m_datatypeFolder;
    ListPopupMenu * m_pMenu;
    TQString oldText, message;
    UMLDoc *m_doc;
    bool m_bStartedCut, m_bStartedCopy, m_bIgnoreCancelRename;

    /**
     * Used when creating an attribute or an operation to stop it adding a second listViewItem
     */
    bool m_bCreatingChildObject;

    TQPixmap m_Pixmaps[Uml::N_ICONTYPES];

    bool eventFilter(TQObject *o, TQEvent *e);
    void contentsMouseReleaseEvent(TQMouseEvent * me);
    void contentsMousePressEvent(TQMouseEvent *me);
    void contentsMouseDoubleClickEvent(TQMouseEvent * me);
    void focusOutEvent ( TQFocusEvent * fe);
    TQDragObject* dragObject();
    void startDrag();
    bool acceptDrag (TQDropEvent* event) const;
    void keyPressEvent(TQKeyEvent *);

    /**
     * This methods looks for a object in a folder an its subfolders recursive.
     * @param item The folder entry of the list view.
     * @param o The object to be found in the folder.
     *
     * @return The object if found else a NULL pointer.
     */
    UMLListViewItem * findUMLObjectInFolder(UMLListViewItem *item, UMLObject *o);

    /**
     * Return true if the given list view type can be expanded/collapsed.
     */
    static bool isExpandable(Uml::ListView_Type lvt);

    /**
     *  Loads the pixmaps to use in the list items.
     */
    void loadPixmaps();

    /**
     * Deletes all child-items of @p parent.
     */
    void deleteChildrenOf( TQListViewItem *parent );

    /**
     * Delete a listview item.
     * @param temp a non-null UMLListViewItem, for example:
                             (UMLListViewItem*)currentItem()
     * @return     true if correctly deleted
     */
    bool deleteItem( UMLListViewItem *temp );

    /**
     * Adds a new operation, attribute or template item to a classifier, identical to
     * childObjectAdded(obj) but with an explicit parent.
     * @param child the child object
     * @param parent the parent object
     */
    void childObjectAdded(UMLClassifierListItem* child, UMLClassifier* parent);

    /**
     * Auxiliary method for moveObject(): Adds the model object at the proper
     * new container (package if nested, UMLDoc if at global level), and
     * updates the containment relationships in the model.
     */
    void addAtContainer(UMLListViewItem *item, UMLListViewItem *parent);

public slots:

    /**
     * Creates a new item to represent a new diagram
     * @param id the id of the new diagram
     */
    void slotDiagramCreated(Uml::IDType id);

    /**
     * renames a diagram in the list view
     * @param id    the id of the renamed diagram
     */
    void slotDiagramRenamed(Uml::IDType id);

    /**
     * Creates a new list view item and connects the appropriate signals/slots
     * @param object the newly created object
     */
    void slotObjectCreated(UMLObject* object);

    /**
     * connect some signals into slots in the list view for newly created UMLObjects
     */
    void connectNewObjectsSlots(UMLObject* object);

    /**
     * Adds a new operation, attribute or template item to a classifier
     * @param obj the child object
     */
    void childObjectAdded(UMLClassifierListItem* obj);

    /**
     * disconnects signals and removes the list view item
     * @param object the object about to be removed
     */
    void slotObjectRemoved(UMLObject* object);

    /**
     * deletes the list view item
     * @param obj the object to remove
     */
    void childObjectRemoved(UMLClassifierListItem* obj);

    /**
     * calls updateObject() on the item representing the sending object
     * no parameters, uses sender() to work out which object called the slot
     */
    void slotObjectChanged();

    /**
     * removes the item representing a diagram
     * @param id the id of the diagram
     */
    void slotDiagramRemoved(Uml::IDType id);

    /**
     * Called when a right mouse button menu has an item selected
     */
    void popupMenuSel(int sel);

    /**
     * Something has been dragged and dropped onto the list view
     */
    void slotDropped(TQDropEvent* de, TQListViewItem* parent, TQListViewItem* item);

    /**
     * calls updateFolder() on the item to update the icon to open
     */
    void slotExpanded(TQListViewItem* item);

    /**
     * calls updateFolder() on the item to update the icon to closed
     */
    void slotCollapsed(TQListViewItem* item);

    /**
     * Open all items in the list view
     */
    void expandAll(TQListViewItem *item);

    /**
     * Close all items in the list view
     */
    void collapseAll(TQListViewItem *item);

    /**
     *  Connects to the signal that @ref UMLApp emits when a
     *  cut operation is successful.
     */
    void slotCutSuccessful();

private:
    /**
     * Searches the tree for a diagram (view).
     * Used by findView().
     */
    UMLListViewItem* recursiveSearchForView(UMLListViewItem* folder,
                                            Uml::ListView_Type type, Uml::IDType id);

};

#endif