ATLAS Offline Software
Loading...
Searching...
No Matches
VP1GraphicsItemCollection.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// Header file for class VP1GraphicsItemCollection //
8// //
9// Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10// //
11// Initial version: April 2007 //
12// //
14
15#ifndef VP1GRAPHICSITEMCOLLECTION_H
16#define VP1GRAPHICSITEMCOLLECTION_H
17
18//Policy: It is forbidden for systems/channels to install
19// eventhandlers or to set flags on QGraphicsItems!!!!!
20//
21// Each item is marked as either ACTIVE or PASSIVE [+movable]
22// (internally an ic knows whether it has any active items at all of
23// course). An IC can be in exactly one of the following modes,
24// governing how its active items respond (this state is set at
25// initialisation by the system and is not changeable later - if so,
26// warn if INACTIVE system has active elements and vice versa?):
27//
28// INERT, SINGLEPICKS, SINGLEEVENTS, SELECTIONS (+UNSET)
29//
30// It must be set BEFORE a scene is attached for the first time.
31//
32// Furthermore, each IC has a temporary ignore state, which makes it
33// temporarily work (i.e. respond to questions such as "is this item
34// presently active") just as if it was inert
35//
36//
37// In graphicsview: Any click or event gets passed to the topmost
38// active item in a non-inert system.
39//
40// If there was a previous selection:
41// If the new item is not in the same IC as the previous selection: clear selection.
42// Else: If shift was down: Add to selection. Else: Set selection to the new item.
43//
44// Future: Special selection tool which lets you draw a path and select anything inside it (needs to know which system it is selecting from)
45//
46// Any change of selection or occurrence of picks/events makes the GV ask the appropriate IC to emit a signal.
47
48#include <QObject>
49
50class VP1GraphicsView;
51class QGraphicsItem;
52
53class VP1GraphicsItemCollection : public QObject {
54
55 Q_OBJECT
56
57public:
58
59 VP1GraphicsItemCollection( QObject * parent=0 );
61
63 void setInteractionMode( const INTERACTIONMODE& ); //Can only be called while not attached to a view.
64 //Default is INERT.
66
67 void addItem( QGraphicsItem*, const bool& active = false, const bool&movable=false );
68 //Beware: All items added will be owned by this class - but if you call removeItem below, you will own them again.
69
70 //The next methods returns false if the item has not been previously added to the collection:
71 bool setActive(QGraphicsItem*, const bool& active = true);
72 bool setMovable(QGraphicsItem* item, const bool& movable=true);
73 bool removeItem(QGraphicsItem*);//Does not delete item.
74 bool hasItem(QGraphicsItem*) const;
75
76 void clear(const bool& deleteitems = true);//Removes and possibly deletes all items.
77
78 //These two can be called from e.g. the systems to avoid updates during intensive work:
79 void detachFromView();//If was not attached, do nothing
80 void reattachToView();//Only does something if it has been previously attached.
81 bool isAttachedToView();
82
83 //These three gives the same answer irrespective of the temporary ignore state
84 int nItems() const;
85 int nActiveItems() const;
86 int nMovableItems() const;
87 //These two always returns 0 if there is a temporary ignore state:
88 int nPresentlyActiveItems() const;
89 int nPresentlyMovableItems() const;
90
91 bool itemBelongsAndIsPresentlyActive(QGraphicsItem*) const;
92
93signals:
94 void itemPicked(QGraphicsItem*) const;//Emitted for active items when in SINGLEPICK mode.
95 void itemGotEvent(QGraphicsItem*,QEvent*) const;//Emitted for active items when in EVENTS mode.
96 void selectionChanged(QList<QGraphicsItem*>) const;//Emitted for active items when in SELECTIONS mode.
97
98private:
101 class Imp;
103private:
104 friend class VP1GraphicsView;
106 void real_detachFromView();
107 void setTemporaryIgnoreInteractions( const bool& );
108 void setTemporaryIgnoreMovable( const bool& );
109 void itemPickedPrivate(QGraphicsItem*) const;
110 void itemGotEventPrivate(QGraphicsItem*,QEvent*) const;
111 void selectionChangedPrivate(const QList<QGraphicsItem*>&) const;
112};
113
114#endif
void setInteractionMode(const INTERACTIONMODE &)
INTERACTIONMODE interactionMode() const
VP1GraphicsItemCollection & operator=(const VP1GraphicsItemCollection &)
void clear(const bool &deleteitems=true)
bool itemBelongsAndIsPresentlyActive(QGraphicsItem *) const
void itemPicked(QGraphicsItem *) const
void setTemporaryIgnoreInteractions(const bool &)
void selectionChangedPrivate(const QList< QGraphicsItem * > &) const
bool hasItem(QGraphicsItem *) const
void itemGotEvent(QGraphicsItem *, QEvent *) const
void selectionChanged(QList< QGraphicsItem * >) const
void itemPickedPrivate(QGraphicsItem *) const
bool setActive(QGraphicsItem *, const bool &active=true)
void itemGotEventPrivate(QGraphicsItem *, QEvent *) const
void addItem(QGraphicsItem *, const bool &active=false, const bool &movable=false)
bool setMovable(QGraphicsItem *item, const bool &movable=true)
VP1GraphicsItemCollection(const VP1GraphicsItemCollection &)