Qt 4.8
livesingleselectionmanipulator.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 <QtDebug>
47 
48 namespace QmlJSDebugger {
49 
51  : m_editorView(editorView),
52  m_isActive(false)
53 {
54 }
55 
56 
58 {
60  m_isActive = true;
62 }
63 
64 void LiveSingleSelectionManipulator::update(const QPointF &/*updatePoint*/)
65 {
67 }
68 
70 {
73 }
74 
75 
76 void LiveSingleSelectionManipulator::end(const QPointF &/*updatePoint*/)
77 {
79  m_isActive = false;
80 }
81 
83  const QList<QGraphicsItem*> &items,
84  bool /*selectOnlyContentItems*/)
85 {
86  QGraphicsItem *selectedItem = 0;
87 
88  foreach (QGraphicsItem* item, items)
89  {
90  //FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
91  if (item
92  /*&& !formEditorItem->qmlItemNode().isRootNode()
93  && (formEditorItem->qmlItemNode().hasShowContent() || !selectOnlyContentItems)*/)
94  {
95  selectedItem = item;
96  break;
97  }
98  }
99 
100  QList<QGraphicsItem*> resultList;
101 
102  switch (selectionType) {
103  case AddToSelection: {
104  resultList.append(m_oldSelectionList);
105  if (selectedItem && !m_oldSelectionList.contains(selectedItem))
106  resultList.append(selectedItem);
107  }
108  break;
109  case ReplaceSelection: {
110  if (selectedItem)
111  resultList.append(selectedItem);
112  }
113  break;
114  case RemoveFromSelection: {
115  resultList.append(m_oldSelectionList);
116  if (selectedItem)
117  resultList.removeAll(selectedItem);
118  }
119  break;
120  case InvertSelection: {
121  if (selectedItem
122  && !m_oldSelectionList.contains(selectedItem))
123  {
124  resultList.append(selectedItem);
125  }
126  }
127  }
128 
129  m_editorView->setSelectedItems(resultList);
130 }
131 
132 void LiveSingleSelectionManipulator::select(SelectionType selectionType, bool selectOnlyContentItems)
133 {
134  QDeclarativeViewInspectorPrivate *inspectorPrivate =
136  QList<QGraphicsItem*> itemList = inspectorPrivate->selectableItems(m_beginPoint);
137  select(selectionType, itemList, selectOnlyContentItems);
138 }
139 
140 
142 {
143  return m_isActive;
144 }
145 
147 {
148  return m_beginPoint;
149 }
150 
151 } // namespace QmlJSDebugger
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
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
LiveSingleSelectionManipulator(QDeclarativeViewInspector *editorView)
void clear()
Removes all items from the list.
Definition: qlist.h:764
QList< QGraphicsItem * > selectableItems(const QPoint &pos) const
void setSelectedItems(QList< QGraphicsItem *> items)
void select(SelectionType selectionType, const QList< QGraphicsItem *> &items, bool selectOnlyContentItems)
static QDeclarativeViewInspectorPrivate * get(QDeclarativeViewInspector *v)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770