OpenCoverage

qquickitemgrabresult.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickitemgrabresult.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9const QEvent::Type Event_Grab_Completed = static_cast<QEvent::Type>(QEvent::User + 1);-
10-
11class QQuickItemGrabResultPrivate : public QObjectPrivate-
12{-
13public:-
14 QQuickItemGrabResultPrivate()-
15 : cacheEntry(nullptr)-
16 , qmlEngine(nullptr)-
17 , texture(nullptr)-
18 {-
19 }
executed 8 times by 2 tests: end of block
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
8
20-
21 ~QQuickItemGrabResultPrivate()-
22 {-
23 delete cacheEntry;-
24 }
executed 8 times by 2 tests: end of block
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
8
25-
26 void ensureImageInCache() const {-
27 if (url.isEmpty()
url.isEmpty()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickitem2
FALSEnever evaluated
&& !image.isNull()
!image.isNull()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickitem2
FALSEnever evaluated
) {
0-4
28 url.setScheme(QQuickPixmap::itemGrabberScheme);-
29 url.setPath(QVariant::fromValue(item.data()).toString());-
30 static uint counter = 0;-
31 url.setFragment(QString::number(++counter));-
32 cacheEntry = new QQuickPixmap(url, image);-
33 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickitem2
4
34 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickitem2
4
35-
36 static QQuickItemGrabResult *create(QQuickItem *item, const QSize &size);-
37-
38 QImage image;-
39-
40 mutable QUrl url;-
41 mutable QQuickPixmap *cacheEntry;-
42-
43 QQmlEngine *qmlEngine;-
44 QJSValue callback;-
45-
46 QPointer<QQuickItem> item;-
47 QPointer<QQuickWindow> window;-
48 QSGLayer *texture;-
49 QSizeF itemSize;-
50 QSize textureSize;-
51};-
52QQuickItemGrabResult::QQuickItemGrabResult(QObject *parent)-
53 : QObject(*new QQuickItemGrabResultPrivate, parent)-
54{-
55}
executed 8 times by 2 tests: end of block
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
8
56bool QQuickItemGrabResult::saveToFile(const QString &fileName) const-
57{-
58 const QQuickItemGrabResultPrivate * const d = d_func();-
59 return
never executed: return d->image.save(fileName);
d->image.save(fileName);
never executed: return d->image.save(fileName);
0
60}-
61-
62-
63-
64-
65-
66-
67bool QQuickItemGrabResult::saveToFile(const QString &fileName)-
68{-
69 return
never executed: return qAsConst(*this).saveToFile(fileName);
qAsConst(*this).saveToFile(fileName);
never executed: return qAsConst(*this).saveToFile(fileName);
0
70}-
71-
72-
73QUrl QQuickItemGrabResult::url() const-
74{-
75 const QQuickItemGrabResultPrivate * const d = d_func();-
76 d->ensureImageInCache();-
77 return
executed 4 times by 1 test: return d->url;
Executed by:
  • tst_qquickitem2
d->url;
executed 4 times by 1 test: return d->url;
Executed by:
  • tst_qquickitem2
4
78}-
79-
80QImage QQuickItemGrabResult::image() const-
81{-
82 const QQuickItemGrabResultPrivate * const d = d_func();-
83 return
executed 28 times by 2 tests: return d->image;
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
d->image;
executed 28 times by 2 tests: return d->image;
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
28
84}-
85-
86-
87-
88-
89bool QQuickItemGrabResult::event(QEvent *e)-
90{-
91 QQuickItemGrabResultPrivate * const d = d_func();-
92 if (e->type() == Event_Grab_Completed
e->type() == E...Grab_CompletedDescription
TRUEevaluated 6 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquicktext
FALSEnever evaluated
) {
0-6
93-
94 if (d->qmlEngine
d->qmlEngineDescription
TRUEnever evaluated
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquicktext
&& d->callback.isCallable()
d->callback.isCallable()Description
TRUEnever evaluated
FALSEnever evaluated
)
0-6
95 d->callback.call(QJSValueList() << d->qmlEngine->newQObject(this));
never executed: d->callback.call(QJSValueList() << d->qmlEngine->newQObject(this));
0
96 else-
97 ready();
executed 6 times by 2 tests: ready();
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
6
98 return
executed 6 times by 2 tests: return true;
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
true;
executed 6 times by 2 tests: return true;
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
6
99 }-
100 return
never executed: return QObject::event(e);
QObject::event(e);
never executed: return QObject::event(e);
0
101}-
102-
103void QQuickItemGrabResult::setup()-
104{-
105 QQuickItemGrabResultPrivate * const d = d_func();-
106 if (!d->item
!d->itemDescription
TRUEnever evaluated
FALSEevaluated 8 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquicktext
) {
0-8
107 disconnect(d->window.data(), &QQuickWindow::beforeSynchronizing, this, &QQuickItemGrabResult::setup);-
108 disconnect(d->window.data(), &QQuickWindow::afterRendering, this, &QQuickItemGrabResult::render);-
109 QCoreApplication::postEvent(this, new QEvent(Event_Grab_Completed));-
110 return;
never executed: return;
0
111 }-
112-
113 QSGRenderContext *rc = QQuickWindowPrivate::get(d->window.data())->context;-
114 d->texture = rc->sceneGraphContext()->createLayer(rc);-
115 d->texture->setItem(QQuickItemPrivate::get(d->item)->itemNode());-
116 d->itemSize = QSizeF(d->item->width(), d->item->height());-
117}
executed 8 times by 2 tests: end of block
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
8
118-
119void QQuickItemGrabResult::render()-
120{-
121 QQuickItemGrabResultPrivate * const d = d_func();-
122 if (!d->texture
!d->textureDescription
TRUEnever evaluated
FALSEevaluated 8 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquicktext
)
0-8
123 return;
never executed: return;
0
124-
125 d->texture->setRect(QRectF(0, d->itemSize.height(), d->itemSize.width(), -d->itemSize.height()));-
126 const QSize minSize = QQuickWindowPrivate::get(d->window.data())->context->sceneGraphContext()->minimumFBOSize();-
127 d->texture->setSize(QSize(qMax(minSize.width(), d->textureSize.width()),-
128 qMax(minSize.height(), d->textureSize.height())));-
129 d->texture->scheduleUpdate();-
130 d->texture->updateTexture();-
131 d->image = d->texture->toImage();-
132-
133 delete d->texture;-
134 d->texture = nullptr;-
135-
136 disconnect(d->window.data(), &QQuickWindow::beforeSynchronizing, this, &QQuickItemGrabResult::setup);-
137 disconnect(d->window.data(), &QQuickWindow::afterRendering, this, &QQuickItemGrabResult::render);-
138 QCoreApplication::postEvent(this, new QEvent(Event_Grab_Completed));-
139}
executed 8 times by 2 tests: end of block
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
8
140-
141QQuickItemGrabResult *QQuickItemGrabResultPrivate::create(QQuickItem *item, const QSize &targetSize)-
142{-
143 QSize size = targetSize;-
144 if (size.isEmpty()
size.isEmpty()Description
TRUEevaluated 6 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquicktext
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickitem2
)
2-6
145 size = QSize(item->width(), item->height());
executed 6 times by 2 tests: size = QSize(item->width(), item->height());
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
6
146-
147 if (size.width() < 1
size.width() < 1Description
TRUEnever evaluated
FALSEevaluated 8 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquicktext
|| size.height() < 1
size.height() < 1Description
TRUEnever evaluated
FALSEevaluated 8 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquicktext
) {
0-8
148 qmlWarning(item) << "grabToImage: item has invalid dimensions";-
149 return
never executed: return nullptr;
nullptr;
never executed: return nullptr;
0
150 }-
151-
152 if (!item->window()
!item->window()Description
TRUEnever evaluated
FALSEevaluated 8 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquicktext
) {
0-8
153 qmlWarning(item) << "grabToImage: item is not attached to a window";-
154 return
never executed: return nullptr;
nullptr;
never executed: return nullptr;
0
155 }-
156-
157 if (!item->window()->isVisible()
!item->window()->isVisible()Description
TRUEnever evaluated
FALSEevaluated 8 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquicktext
) {
0-8
158 qmlWarning(item) << "grabToImage: item's window is not visible";-
159 return
never executed: return nullptr;
nullptr;
never executed: return nullptr;
0
160 }-
161-
162 QQuickItemGrabResult *result = new QQuickItemGrabResult();-
163 QQuickItemGrabResultPrivate *d = result->d_func();-
164 d->item = item;-
165 d->window = item->window();-
166 d->textureSize = size;-
167-
168 QQuickItemPrivate::get(item)->refFromEffectItem(false);-
169-
170-
171 item->window()->update();-
172-
173 return
executed 8 times by 2 tests: return result;
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
result;
executed 8 times by 2 tests: return result;
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
8
174}-
175QSharedPointer<QQuickItemGrabResult> QQuickItem::grabToImage(const QSize &targetSize)-
176{-
177 QQuickItemGrabResult *result = QQuickItemGrabResultPrivate::create(this, targetSize);-
178 if (!result
!resultDescription
TRUEnever evaluated
FALSEevaluated 8 times by 2 tests
Evaluated by:
  • tst_qquickitem2
  • tst_qquicktext
)
0-8
179 return
never executed: return QSharedPointer<QQuickItemGrabResult>();
QSharedPointer<QQuickItemGrabResult>();
never executed: return QSharedPointer<QQuickItemGrabResult>();
0
180-
181 connect(window(), &QQuickWindow::beforeSynchronizing, result, &QQuickItemGrabResult::setup, Qt::DirectConnection);-
182 connect(window(), &QQuickWindow::afterRendering, result, &QQuickItemGrabResult::render, Qt::DirectConnection);-
183-
184 return
executed 8 times by 2 tests: return QSharedPointer<QQuickItemGrabResult>(result);
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
QSharedPointer<QQuickItemGrabResult>(result);
executed 8 times by 2 tests: return QSharedPointer<QQuickItemGrabResult>(result);
Executed by:
  • tst_qquickitem2
  • tst_qquicktext
8
185}-
186bool QQuickItem::grabToImage(const QJSValue &callback, const QSize &targetSize)-
187{-
188 QQmlEngine *engine = qmlEngine(this);-
189 if (!engine
!engineDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
190 qmlWarning(this) << "grabToImage: item has no QML engine";-
191 return
never executed: return false;
false;
never executed: return false;
0
192 }-
193-
194 if (!callback.isCallable()
!callback.isCallable()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
195 qmlWarning(this) << "grabToImage: 'callback' is not a function";-
196 return
never executed: return false;
false;
never executed: return false;
0
197 }-
198-
199 QSize size = targetSize;-
200 if (size.isEmpty()
size.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
201 size = QSize(width(), height());
never executed: size = QSize(width(), height());
0
202-
203 if (size.width() < 1
size.width() < 1Description
TRUEnever evaluated
FALSEnever evaluated
|| size.height() < 1
size.height() < 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
204 qmlWarning(this) << "grabToImage: item has invalid dimensions";-
205 return
never executed: return false;
false;
never executed: return false;
0
206 }-
207-
208 if (!window()
!window()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
209 qmlWarning(this) << "grabToImage: item is not attached to a window";-
210 return
never executed: return false;
false;
never executed: return false;
0
211 }-
212-
213 QQuickItemGrabResult *result = QQuickItemGrabResultPrivate::create(this, size);-
214 if (!result
!resultDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
215 return
never executed: return false;
false;
never executed: return false;
0
216-
217 connect(window(), &QQuickWindow::beforeSynchronizing, result, &QQuickItemGrabResult::setup, Qt::DirectConnection);-
218 connect(window(), &QQuickWindow::afterRendering, result, &QQuickItemGrabResult::render, Qt::DirectConnection);-
219-
220 QQuickItemGrabResultPrivate *d = result->d_func();-
221 d->qmlEngine = engine;-
222 d->callback = callback;-
223 return
never executed: return true;
true;
never executed: return true;
0
224}-
225-
226-
227-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.0