Qt 4.8
liverubberbandselectionmanipulator.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
43 
44 #include "../qdeclarativeviewinspector_p.h"
45 
46 #include <QtGui/QGraphicsItem>
47 
48 #include <QtCore/QDebug>
49 
50 namespace QmlJSDebugger {
51 
53  QDeclarativeViewInspector *editorView)
54  : m_selectionRectangleElement(layerItem),
55  m_editorView(editorView),
56  m_beginFormEditorItem(0),
57  m_isActive(false)
58 {
60 }
61 
63 {
65  m_isActive = false;
67  m_itemList.clear();
69 }
70 
72  &itemList)
73 {
74  if (itemList.isEmpty())
75  return 0;
76 
77  return itemList.first();
78 }
79 
81 {
85  m_isActive = true;
86  QDeclarativeViewInspectorPrivate *inspectorPrivate
88  m_beginFormEditorItem = topFormEditorItem(inspectorPrivate->selectableItems(beginPoint));
90 }
91 
93 {
95 }
96 
98 {
101  m_isActive = false;
102 }
103 
105 {
106  QDeclarativeViewInspectorPrivate *inspectorPrivate
108  QList<QGraphicsItem*> itemList
109  = inspectorPrivate->selectableItems(m_selectionRectangleElement.rect(),
111  QList<QGraphicsItem*> newSelectionList;
112 
113  foreach (QGraphicsItem* item, itemList) {
114  if (item
115  && item->parentItem()
116  && !newSelectionList.contains(item)
117  //&& m_beginFormEditorItem->childItems().contains(item) // TODO activate this test
118  )
119  {
120  newSelectionList.append(item);
121  }
122  }
123 
124  if (newSelectionList.isEmpty() && m_beginFormEditorItem)
125  newSelectionList.append(m_beginFormEditorItem);
126 
127  QList<QGraphicsItem*> resultList;
128 
129  switch (selectionType) {
130  case AddToSelection: {
131  resultList.append(m_oldSelectionList);
132  resultList.append(newSelectionList);
133  }
134  break;
135  case ReplaceSelection: {
136  resultList.append(newSelectionList);
137  }
138  break;
139  case RemoveFromSelection: {
140  QSet<QGraphicsItem*> oldSelectionSet(m_oldSelectionList.toSet());
141  QSet<QGraphicsItem*> newSelectionSet(newSelectionList.toSet());
142  resultList.append(oldSelectionSet.subtract(newSelectionSet).toList());
143  }
144  }
145 
146  m_editorView->setSelectedItems(resultList);
147 }
148 
149 
151 {
152  m_itemList = itemList;
153 }
154 
156 {
157  return m_beginPoint;
158 }
159 
161 {
162  return m_isActive;
163 }
164 
165 } // namespace QmlJSDebugger
LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem, QDeclarativeViewInspector *editorView)
QSet< T > toSet() const
Returns a QSet object with the data contained in this QList.
Definition: qset.h:309
void setRect(const QPointF &firstPoint, const QPointF &secondPoint)
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
QGraphicsItem * topFormEditorItem(const QList< QGraphicsItem *> &itemList)
void clear()
Removes all items from the list.
Definition: qlist.h:764
QList< QGraphicsItem * > selectableItems(const QPoint &pos) const
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
void setSelectedItems(QList< QGraphicsItem *> items)
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
The QGraphicsObject class provides a base class for all graphics items that require signals...
static QDeclarativeViewInspectorPrivate * get(QDeclarativeViewInspector *v)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62