Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickdesignersupport.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <private/qquickitem_p.h>
6
7#if QT_CONFIG(quick_shadereffect)
8#include <QtQuick/private/qquickshadereffectsource_p.h>
9#endif
10#include <QtQuick/private/qquickrectangle_p.h>
11#include <QtQml/private/qabstractanimationjob_p.h>
12#include <private/qqmlengine_p.h>
13#include <private/qquickview_p.h>
14#include <QtQuick/private/qquickstategroup_p.h>
15#include <QtGui/QImage>
16#include <private/qqmlvme_p.h>
17#include <private/qqmlcomponentattached_p.h>
18#include <private/qqmldata_p.h>
19#include <private/qsgadaptationlayer_p.h>
20
22
26
28{
29 typedef QHash<QQuickItem*, QSGLayer*>::iterator ItemTextureHashIt;
30
31 for (ItemTextureHashIt iterator = m_itemTextureHash.begin(), end = m_itemTextureHash.end(); iterator != end; ++iterator) {
32 QSGLayer *texture = iterator.value();
33 QQuickItem *item = iterator.key();
34 QQuickItemPrivate::get(item)->derefFromEffectItem(true);
35 delete texture;
36 }
37}
38
40{
41 if (referencedItem == nullptr)
42 return;
43
44 QQuickItemPrivate::get(referencedItem)->refFromEffectItem(hide);
45 QQuickWindowPrivate::get(referencedItem->window())->updateDirtyNode(referencedItem);
46
47 Q_ASSERT(QQuickItemPrivate::get(referencedItem)->rootNode());
48
49 if (!m_itemTextureHash.contains(referencedItem)) {
50 QSGRenderContext *rc = QQuickWindowPrivate::get(referencedItem->window())->context;
52
53 QSizeF itemSize = referencedItem->size();
54 texture->setLive(true);
55 texture->setItem(QQuickItemPrivate::get(referencedItem)->rootNode());
56 texture->setRect(QRectF(QPointF(0, 0), itemSize));
57 texture->setSize(itemSize.toSize());
58 texture->setRecursive(true);
59 texture->setFormat(QSGLayer::RGBA8);
60 texture->setHasMipmaps(false);
61
62 m_itemTextureHash.insert(referencedItem, texture);
63 }
64}
65
67{
68 if (referencedItem == nullptr)
69 return;
70
71 delete m_itemTextureHash.take(referencedItem);
72 QQuickItemPrivate::get(referencedItem)->derefFromEffectItem(unhide);
73}
74
76{
77 if (referencedItem == nullptr || referencedItem->parentItem() == nullptr) {
78 qDebug() << __FILE__ << __LINE__ << "Warning: Item can be rendered.";
79 return QImage();
80 }
81
82 QSGLayer *renderTexture = m_itemTextureHash.value(referencedItem);
83
84 Q_ASSERT(renderTexture);
85 if (renderTexture == nullptr)
86 return QImage();
87 renderTexture->setRect(boundingRect);
88 renderTexture->setSize(imageSize);
89 renderTexture->setItem(QQuickItemPrivate::get(referencedItem)->rootNode());
90 renderTexture->markDirtyTexture();
91 renderTexture->updateTexture();
92
93 QImage renderImage = renderTexture->toImage();
94 renderImage = renderImage.mirrored(false, true);
95
96 if (renderImage.size().isEmpty())
97 qDebug() << __FILE__ << __LINE__ << "Warning: Image is empty.";
98
99 return renderImage;
100}
101
103{
104 if (referencedItem == nullptr)
105 return false;
106
107 return QQuickItemPrivate::get(referencedItem)->dirtyAttributes & dirtyType;
108}
109
111{
112 if (referencedItem == nullptr)
113 return;
114
115 QQuickItemPrivate::get(referencedItem)->dirtyAttributes |= dirtyType;
116}
117
119{
120 if (referencedItem == nullptr)
121 return;
122
123 QQuickItemPrivate::get(referencedItem)->dirtyAttributes = 0x0;
124 QQuickItemPrivate::get(referencedItem)->removeFromDirtyList();
125}
126
128{
129 if (referencedItem == nullptr)
130 return QTransform();
131
132 return QQuickItemPrivate::get(referencedItem)->itemToWindowTransform();
133}
134
136{
137 if (referencedItem == nullptr)
138 return QTransform();
139
141
142 QQuickItemPrivate::get(referencedItem)->itemToParentTransform(&parentTransform);
143
144 return parentTransform;
145}
146
148{
149 switch (anchorLine) {
150 case QQuickAnchors::LeftAnchor: return QLatin1String("left");
151 case QQuickAnchors::RightAnchor: return QLatin1String("right");
152 case QQuickAnchors::TopAnchor: return QLatin1String("top");
153 case QQuickAnchors::BottomAnchor: return QLatin1String("bottom");
154 case QQuickAnchors::HCenterAnchor: return QLatin1String("horizontalCenter");
155 case QQuickAnchors::VCenterAnchor: return QLatin1String("verticalCenter");
156 case QQuickAnchors::BaselineAnchor: return QLatin1String("baseline");
157 case QQuickAnchors::InvalidAnchor: // fallthrough:
158 default: return QString();
159 }
160}
161
163{
164 static QStringList anchorNameList(QStringList() << QLatin1String("anchors.top")
165 << QLatin1String("anchors.left")
166 << QLatin1String("anchors.right")
167 << QLatin1String("anchors.bottom")
168 << QLatin1String("anchors.verticalCenter")
169 << QLatin1String("anchors.horizontalCenter")
170 << QLatin1String("anchors.fill")
171 << QLatin1String("anchors.centerIn")
172 << QLatin1String("anchors.baseline"));
173
174 return anchorNameList.contains(name);
175}
176
178{
179 QQuickItemPrivate *fromItemPrivate = QQuickItemPrivate::get(fromItem);
180 QQuickAnchors *anchors = fromItemPrivate->anchors();
181 return anchors->fill() == toItem
182 || anchors->centerIn() == toItem
183 || anchors->bottom().item == toItem
184 || anchors->top().item == toItem
185 || anchors->left().item == toItem
186 || anchors->right().item == toItem
187 || anchors->verticalCenter().item == toItem
188 || anchors->horizontalCenter().item == toItem
189 || anchors->baseline().item == toItem;
190}
191
193{
194 const auto childItems = fromItem->childItems();
195 for (QQuickItem *childItem : childItems) {
196 if (childItem) {
197 if (isAnchoredTo(childItem, toItem))
198 return true;
199
200 if (areChildrenAnchoredTo(childItem, toItem))
201 return true;
202 }
203 }
204
205 return false;
206}
207
209{
211 return itemPrivate->anchors();
212}
213
215{
216 if (name == QLatin1String("anchors.top"))
218
219 if (name == QLatin1String("anchors.left"))
221
222 if (name == QLatin1String("anchors.bottom"))
224
225 if (name == QLatin1String("anchors.right"))
227
228 if (name == QLatin1String("anchors.horizontalCenter"))
230
231 if (name == QLatin1String("anchors.verticalCenter"))
233
234 if (name == QLatin1String("anchors.baseline"))
236
237
238 Q_ASSERT_X(false, Q_FUNC_INFO, "wrong anchor name - this should never happen");
240}
241
243{
245 return false;
246
247 if (name == QLatin1String("anchors.fill"))
248 return anchors(item)->fill() != nullptr;
249
250 if (name == QLatin1String("anchors.centerIn"))
251 return anchors(item)->centerIn() != nullptr;
252
253 if (name == QLatin1String("anchors.right"))
254 return anchors(item)->right().item != nullptr;
255
256 if (name == QLatin1String("anchors.top"))
257 return anchors(item)->top().item != nullptr;
258
259 if (name == QLatin1String("anchors.left"))
260 return anchors(item)->left().item != nullptr;
261
262 if (name == QLatin1String("anchors.bottom"))
263 return anchors(item)->bottom().item != nullptr;
264
265 if (name == QLatin1String("anchors.horizontalCenter"))
266 return anchors(item)->horizontalCenter().item != nullptr;
267
268 if (name == QLatin1String("anchors.verticalCenter"))
269 return anchors(item)->verticalCenter().item != nullptr;
270
271 if (name == QLatin1String("anchors.baseline"))
272 return anchors(item)->baseline().item != nullptr;
273
274 return anchors(item)->usedAnchors().testFlag(anchorLineFlagForName(name));
275}
276
281
286
287
288
290{
291 QObject *targetObject = nullptr;
292 QString targetName;
293
294 if (name == QLatin1String("anchors.fill")) {
295 targetObject = anchors(item)->fill();
296 } else if (name == QLatin1String("anchors.centerIn")) {
297 targetObject = anchors(item)->centerIn();
298 } else {
299 QQmlProperty metaProperty(item, name, context);
300 if (!metaProperty.isValid())
301 return QPair<QString, QObject*>();
302
303 QQuickAnchorLine anchorLine = metaProperty.read().value<QQuickAnchorLine>();
304 if (anchorLine.anchorLine != QQuickAnchors::InvalidAnchor) {
305 targetObject = anchorLine.item;
306 targetName = propertyNameForAnchorLine(anchorLine.anchorLine);
307 }
308
309 }
310
311 return QPair<QString, QObject*>(targetName, targetObject);
312}
313
315{
316 if (name == QLatin1String("anchors.fill")) {
318 } else if (name == QLatin1String("anchors.centerIn")) {
320 } else if (name == QLatin1String("anchors.top")) {
322 } else if (name == QLatin1String("anchors.left")) {
324 } else if (name == QLatin1String("anchors.right")) {
326 } else if (name == QLatin1String("anchors.bottom")) {
328 } else if (name == QLatin1String("anchors.horizontalCenter")) {
330 } else if (name == QLatin1String("anchors.verticalCenter")) {
332 } else if (name == QLatin1String("anchors.baseline")) {
334 }
335}
336
338{
339 if (!object)
340 return;
341
342 QQmlData *data = QQmlData::get(object);
343 if (data && data->context) {
344 QQmlComponentAttached *componentAttached = data->context->componentAttacheds();
345 while (componentAttached) {
346 if (componentAttached->parent())
347 if (componentAttached->parent() == object)
348 emit componentAttached->completed();
349
350 componentAttached = componentAttached->next();
351 }
352 }
353}
354
356{
357 QList<QObject*> objectList;
358 const QList<QQuickState *> stateList = QQuickItemPrivate::get(item)->_states()->states();
359
360 objectList.reserve(stateList.size());
361 for (QQuickState* state : stateList)
362 objectList.append(state);
363
364 return objectList;
365}
366
371
373{
374 QQuickRectangle *rectangle = qobject_cast<QQuickRectangle*>(item);
375 if (rectangle)
376 return rectangle->border()->width();
377
378 return 0;
379}
380
385
390
395
400
406
411
416
421
426
431
436
437
QGraphicsWidget * window() const
\inmodule QtCore
Definition qhash.h:1103
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
Definition qhash.h:1212
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it.
Definition qhash.h:985
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
Definition qhash.h:1007
T value(const Key &key) const noexcept
Definition qhash.h:1054
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
Definition qhash.h:1216
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1303
\inmodule QtGui
Definition qimage.h:37
QImage mirrored(bool horizontally=false, bool vertically=true) const &
Definition qimage.h:219
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore\reentrant
Definition qpoint.h:217
QQmlComponentAttached * next() const
static QQmlRefPointer< QQmlContextData > get(QQmlContext *context)
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
static QQmlData * get(QObjectPrivate *priv, bool create)
Definition qqmldata_p.h:199
static void activateDesignerMode()
The QQmlProperty class abstracts accessing properties on objects created from QML.
bool isValid() const
Returns true if the QQmlProperty refers to a valid property, otherwise false.
QVariant read() const
Returns the property value.
static void disableComponentComplete()
Definition qqmlvme.cpp:31
static void enableComponentComplete()
Definition qqmlvme.cpp:26
QQuickAnchors::Anchor anchorLine
void resetVerticalCenter()
QQuickAnchorLine top
QQuickAnchorLine left
QQuickItem * fill
QQuickAnchorLine right
QQuickItem * centerIn
QQuickAnchorLine horizontalCenter
Anchors usedAnchors() const
QQuickAnchorLine baseline
QQuickAnchorLine verticalCenter
void resetHorizontalCenter()
QQuickAnchorLine bottom
static QTransform parentTransform(QQuickItem *referencedItem)
static QPair< QString, QObject * > anchorLineTarget(QQuickItem *item, const QString &name, QQmlContext *context)
void refFromEffectItem(QQuickItem *referencedItem, bool hide=true)
static QTransform windowTransform(QQuickItem *referencedItem)
static bool hasAnchor(QQuickItem *item, const QString &name)
static bool isDirty(QQuickItem *referencedItem, DirtyType dirtyType)
static bool isValidHeight(QQuickItem *item)
static void emitComponentCompleteSignalForAttachedProperty(QObject *item)
static void updateDirtyNode(QQuickItem *item)
static void polishItems(QQuickWindow *window)
static bool isComponentComplete(QQuickItem *item)
static void resetDirty(QQuickItem *referencedItem)
QImage renderImageForItem(QQuickItem *referencedItem, const QRectF &boundingRect, const QSize &imageSize)
static QQuickItem * anchorFillTargetItem(QQuickItem *item)
static void setRootItem(QQuickView *view, QQuickItem *item)
static void addDirty(QQuickItem *referencedItem, DirtyType dirtyType)
static bool isValidWidth(QQuickItem *item)
static bool isAnchoredTo(QQuickItem *fromItem, QQuickItem *toItem)
static bool areChildrenAnchoredTo(QQuickItem *fromItem, QQuickItem *toItem)
static QQuickItem * anchorCenterInTargetItem(QQuickItem *item)
static void refreshExpressions(QQmlContext *context)
static void resetAnchor(QQuickItem *item, const QString &name)
static QList< QObject * > statesForItem(QQuickItem *item)
static int borderWidth(QQuickItem *item)
void derefFromEffectItem(QQuickItem *referencedItem, bool unhide=true)
QQuickAnchors * anchors() const
\qmlpropertygroup QtQuick::Item::anchors \qmlproperty AnchorLine QtQuick::Item::anchors....
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
QQuickPen * border
\qmlproperty bool QtQuick::Rectangle::antialiasing
static QQuickViewPrivate * get(QQuickView *view)
The QQuickView class provides a window for displaying a Qt Quick user interface.
Definition qquickview.h:20
static QQuickWindowPrivate * get(QQuickWindow *c)
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtCore\reentrant
Definition qrect.h:484
virtual QSGLayer * createLayer(QSGRenderContext *renderContext)=0
QSGContext * sceneGraphContext() const
\inmodule QtCore
Definition qsize.h:208
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
Definition qsize.h:401
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
T value() const &
Definition qvariant.h:516
else opt state
[0]
Combined button and popup list for selecting options.
static void * context
#define Q_FUNC_INFO
QList< QString > QStringList
Constructs a string list that contains the given string, str.
#define qDebug
[1]
Definition qlogging.h:164
GLuint GLuint end
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint texture
GLuint name
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei imageSize
static const QRectF boundingRect(const QPointF *points, int pointCount)
QString propertyNameForAnchorLine(const QQuickAnchors::Anchor &anchorLine)
bool isValidAnchorName(const QString &name)
QQuickAnchors * anchors(QQuickItem *item)
QQuickAnchors::Anchor anchorLineFlagForName(const QString &name)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define emit
QGraphicsItem * item
edit hide()
aWidget window() -> setWindowTitle("New Window Title")
[2]
QQuickView * view
[0]