Qt 4.8
abstractliveedittool.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 
42 #include "abstractliveedittool.h"
43 #include "../qdeclarativeviewinspector_p.h"
44 
45 #include <QDeclarativeEngine>
46 
47 #include <QtDebug>
48 #include <QGraphicsItem>
49 #include <QDeclarativeItem>
50 
51 namespace QmlJSDebugger {
52 
54  : AbstractTool(editorView)
55 {
56 }
57 
58 
60 {
61 }
62 
64 {
65  return static_cast<QDeclarativeViewInspector*>(AbstractTool::inspector());
66 }
67 
69 {
70  return inspector()->declarativeView();
71 }
72 
74 {
75  return view()->scene();
76 }
77 
79 {
81 }
82 
84 {
85  return inspector()->selectedItems();
86 }
87 
89 {
90  QGraphicsItem *firstSelectableItem = topMovableGraphicsItem(itemList);
91  if (firstSelectableItem == 0)
92  return false;
93  if (toQDeclarativeItem(firstSelectableItem) != 0)
94  return true;
95 
96  return false;
97 
98 }
99 
101 {
102  QList<QGraphicsItem*> selectedItems = inspector()->selectedItems();
103 
104  foreach (QGraphicsItem *item, itemList) {
105  QDeclarativeItem *declarativeItem = toQDeclarativeItem(item);
106  if (declarativeItem
107  && selectedItems.contains(declarativeItem)
108  /*&& (declarativeItem->qmlItemNode().hasShowContent() || selectNonContentItems)*/)
109  return true;
110  }
111 
112  return false;
113 
114 }
115 
117 {
118  return false;
119 }
120 
122 {
124 }
125 
127 {
128  foreach (QGraphicsItem *item, itemList) {
129  if (item->flags().testFlag(QGraphicsItem::ItemIsMovable))
130  return item;
131  }
132  return 0;
133 }
134 
136  &itemList)
137 {
138  foreach (QGraphicsItem *item, itemList) {
139  QDeclarativeItem *declarativeItem = toQDeclarativeItem(item);
140  if (declarativeItem /*&& (declarativeItem->qmlItemNode().hasShowContent())*/)
141  return declarativeItem;
142  }
143 
144  return 0;
145 }
146 
148  &itemList)
149 {
150  QList<QGraphicsObject*> gfxObjects;
151  foreach (QGraphicsItem *item, itemList) {
152  QGraphicsObject *obj = item->toGraphicsObject();
153  if (obj)
154  gfxObjects << obj;
155  }
156 
157  return gfxObjects;
158 }
159 
161 {
162  QString className(QLatin1String("QGraphicsItem"));
163  QString objectStringId;
164 
165  QString constructedName;
166 
167  QGraphicsObject *gfxObject = item->toGraphicsObject();
168  if (gfxObject) {
169  className = QLatin1String(gfxObject->metaObject()->className());
170 
171  className.remove(QRegExp(QLatin1String("_QMLTYPE_\\d+")));
172  className.remove(QRegExp(QLatin1String("_QML_\\d+")));
173  if (className.startsWith(QLatin1String("QDeclarative")))
174  className = className.remove(QLatin1String("QDeclarative"));
175 
176  QDeclarativeItem *declarativeItem = qobject_cast<QDeclarativeItem*>(gfxObject);
177  if (declarativeItem) {
178  objectStringId = inspector()->idStringForObject(declarativeItem);
179  }
180 
181  if (!objectStringId.isEmpty()) {
182  constructedName = objectStringId + QLatin1String(" (") + className + QLatin1Char(')');
183  } else {
184  if (!gfxObject->objectName().isEmpty()) {
185  constructedName = gfxObject->objectName() + QLatin1String(" (") + className + QLatin1Char(')');
186  } else {
187  constructedName = className;
188  }
189  }
190  }
191 
192  return constructedName;
193 }
194 
195 
196 } // namespace QmlJSDebugger
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QList< QGraphicsItem * > items() const
QString idStringForObject(QObject *obj) const
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
The QDeclarativeView class provides a widget for displaying a Qt Declarative user interface...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
bool topItemIsMovable(const QList< QGraphicsItem *> &itemList)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
static QDeclarativeItem * toQDeclarativeItem(QGraphicsItem *item)
const char * className
Definition: qwizard.cpp:137
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
The QDeclarativeItem class provides the most basic of all visual items in QML.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
static QDeclarativeItem * topMovableDeclarativeItem(const QList< QGraphicsItem *> &itemList)
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
static QList< QGraphicsObject * > toGraphicsObjectList(const QList< QGraphicsItem *> &itemList)
bool topSelectedItemIsMovable(const QList< QGraphicsItem *> &itemList)
AbstractViewInspector * inspector() const
Definition: abstracttool.h:64
static QGraphicsItem * topMovableGraphicsItem(const QList< QGraphicsItem *> &itemList)
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QString objectName() const
AbstractLiveEditTool(QDeclarativeViewInspector *inspector)
QDeclarativeViewInspector * inspector() const
virtual void selectedItemsChanged(const QList< QGraphicsItem *> &objectList)=0
bool topItemIsResizeHandle(const QList< QGraphicsItem *> &itemList)
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
The QGraphicsObject class provides a base class for all graphics items that require signals...
QGraphicsScene * scene() const
Returns a pointer to the scene that is currently visualized in the view.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QString titleForItem(QGraphicsItem *item)