8#if QT_CONFIG(quick_viewtransitions)
9#include "qquickstacktransition_p_p.h"
12#include <QtCore/qscopedvaluerollback.h>
13#include <QtQml/qjsvalue.h>
14#include <QtQml/qqmlengine.h>
15#include <QtQml/qqmlinfo.h>
16#include <QtQml/qqmlcomponent.h>
18#include <private/qv4qobjectwrapper_p.h>
19#include <private/qqmlengine_p.h>
28QQuickStackViewArg::QQuickStackViewArg(
const QUrl &url)
34 : mComponent(component)
39 : mProperties(properties)
43#ifndef QT_NO_DEBUG_STREAM
46 QDebugStateSaver saver(debug);
47 debug.nospace() <<
"QQuickStackViewArg("
48 <<
"mItem=" << arg.mItem
49 <<
" mComponent=" << arg.mComponent
50 <<
" mUrl=" << arg.mUrl
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
385QQuickStackView::QQuickStackView(QQuickItem *parent)
386 : QQuickControl(*(
new QQuickStackViewPrivate), parent)
388 setFlag(ItemIsFocusScope);
390 Q_D(QQuickStackView);
391 d->setSizePolicy(QLayoutPolicy::Preferred, QLayoutPolicy::Preferred);
394QQuickStackView::~QQuickStackView()
396 Q_D(QQuickStackView);
397#if QT_CONFIG(quick_viewtransitions)
398 if (d->transitioner) {
399 d->transitioner->setChangeListener(
nullptr);
400 delete d->transitioner;
403 qDeleteAll(d->removing);
404 qDeleteAll(d->removed);
405 qDeleteAll(d->elements);
408QQuickStackViewAttached *QQuickStackView::qmlAttachedProperties(QObject *object)
410 return new QQuickStackViewAttached(object);
414
415
416
417
418bool QQuickStackView::isBusy()
const
420 Q_D(
const QQuickStackView);
425
426
427
428
429int QQuickStackView::depth()
const
431 Q_D(
const QQuickStackView);
432 return d->elements.size();
436
437
438
439
440QQuickItem *QQuickStackView::currentItem()
const
442 Q_D(
const QQuickStackView);
443 return d->currentItem;
447
448
449
450
451
452
453
454
455
456QQuickItem *QQuickStackView::get(
int index, LoadBehavior behavior)
458 Q_D(QQuickStackView);
459 QQuickStackElement *element = d->elements.value(index);
461 if (behavior == ForceLoad) {
464 if (QQmlEngine *engine = qmlEngine(
this))
465 element->load(engine->handle(),
this);
467 return element->item;
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489QQuickItem *QQuickStackView::find(
const QJSValue &callback, LoadBehavior behavior)
491 Q_D(QQuickStackView);
492 QJSValue func(callback);
493 QQmlEngine *engine = qmlEngine(
this);
494 if (!engine || !func.isCallable())
497 for (
int i = d->elements.size() - 1; i >= 0; --i) {
498 QQuickStackElement *element = d->elements.at(i);
499 if (behavior == ForceLoad)
500 element->load(engine->handle(),
this);
502 QJSValue rv = func.call(QJSValueList() << engine->newQObject(element->item) << i);
504 return element->item;
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576void QQuickStackView::push(QQmlV4FunctionPtr args)
578 Q_D(QQuickStackView);
579 const QString operationName = QStringLiteral(
"push");
580 if (d->modifyingElements) {
581 d->warnOfInterruption(operationName);
585 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
586 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
587 if (args->length() <= 0) {
588 d->warn(QStringLiteral(
"missing arguments"));
589 args->setReturnValue(QV4::Encode::null());
593 QV4::ExecutionEngine *v4 = args->v4engine();
594 QV4::Scope scope(v4);
596#if QT_CONFIG(quick_viewtransitions)
597 Operation operation = d->elements.isEmpty() ? Immediate : PushTransition;
598 QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
599 if (lastArg->isInt32())
600 operation =
static_cast<Operation>(lastArg->toInt32());
604 QList<QQuickStackElement *> elements = d->parseElements(0, args, &errors);
607 auto removeIt = std::remove_if(elements.begin(), elements.end(), [&](QQuickStackElement *element) {
608 return element->item && d->findElement(element->item);
610 for (
auto it = removeIt, end = elements.end(); it != end; ++it)
612 elements.erase(removeIt, elements.end());
614 if (!errors.isEmpty() || elements.isEmpty()) {
615 if (!errors.isEmpty()) {
616 for (
const QString &error : std::as_const(errors))
619 d->warn(QStringLiteral(
"nothing to push"));
621 args->setReturnValue(QV4::Encode::null());
625#if QT_CONFIG(quick_viewtransitions)
626 QQuickStackElement *exit =
nullptr;
627 if (!d->elements.isEmpty())
628 exit = d->elements.top();
631 int oldDepth = d->elements.size();
632 if (d->pushElements(v4, elements)) {
633 d->depthChange(d->elements.size(), oldDepth);
634 QQuickStackElement *enter = d->elements.top();
635#if QT_CONFIG(quick_viewtransitions)
636 d->startTransition(QQuickStackTransition::pushEnter(operation, enter,
this),
637 QQuickStackTransition::pushExit(operation, exit,
this),
638 operation == Immediate);
640 d->setCurrentItem(enter);
643 if (d->currentItem) {
644 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem));
645 args->setReturnValue(rv->asReturnedValue());
647 args->setReturnValue(QV4::Encode::null());
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690void QQuickStackView::pop(QQmlV4FunctionPtr args)
692 Q_D(QQuickStackView);
693 const QString operationName = QStringLiteral(
"pop");
694 if (d->modifyingElements) {
695 d->warnOfInterruption(operationName);
696 args->setReturnValue(QV4::Encode::null());
700 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
701 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
702 int argc = args->length();
703 if (d->elements.size() <= 1 || argc > 2) {
705 d->warn(QStringLiteral(
"too many arguments"));
706 args->setReturnValue(QV4::Encode::null());
710 int oldDepth = d->elements.size();
711 QQuickStackElement *exit = d->elements.pop();
712 QQuickStackElement *enter = d->elements.top();
714 QV4::ExecutionEngine *v4 = args->v4engine();
715 QV4::Scope scope(v4);
718 QV4::ScopedValue value(scope, (*args)[0]);
719 if (value->isNull()) {
720 enter = d->elements.value(0);
721 }
else if (
const QV4::QObjectWrapper *o = value->as<QV4::QObjectWrapper>()) {
722 QQuickItem *item = qobject_cast<QQuickItem *>(o->object());
723 enter = d->findElement(item);
725 if (item != d->currentItem)
726 d->warn(QStringLiteral(
"can't find item to pop: ") + value->toQString());
727 args->setReturnValue(QV4::Encode::null());
728 d->elements.push(exit);
734#if QT_CONFIG(quick_viewtransitions)
735 Operation operation = PopTransition;
737 QV4::ScopedValue lastArg(scope, (*args)[argc - 1]);
738 if (lastArg->isInt32())
739 operation =
static_cast<Operation>(lastArg->toInt32());
743 QPointer<QQuickItem> previousItem;
745 if (d->popElements(v4, enter)) {
747 exit->removal =
true;
748 d->removing.insert(exit);
749 previousItem = exit->item;
751 d->depthChange(d->elements.size(), oldDepth);
752#if QT_CONFIG(quick_viewtransitions)
753 d->startTransition(QQuickStackTransition::popExit(operation, exit,
this),
754 QQuickStackTransition::popEnter(operation, enter,
this),
755 operation == Immediate);
757 d->setCurrentItem(enter);
761 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, previousItem));
762 args->setReturnValue(rv->asReturnedValue());
764 args->setReturnValue(QV4::Encode::null());
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862void QQuickStackView::replace(QQmlV4FunctionPtr args)
864 Q_D(QQuickStackView);
865 const QString operationName = QStringLiteral(
"replace");
866 if (d->modifyingElements) {
867 d->warnOfInterruption(operationName);
868 args->setReturnValue(QV4::Encode::null());
872 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
873 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
874 if (args->length() <= 0) {
875 d->warn(QStringLiteral(
"missing arguments"));
876 args->setReturnValue(QV4::Encode::null());
880 QV4::ExecutionEngine *v4 = args->v4engine();
881 QV4::Scope scope(v4);
883#if QT_CONFIG(quick_viewtransitions)
884 Operation operation = d->elements.isEmpty() ? Immediate : ReplaceTransition;
885 QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
886 if (lastArg->isInt32())
887 operation =
static_cast<Operation>(lastArg->toInt32());
890 QQuickStackElement *target =
nullptr;
891 QV4::ScopedValue firstArg(scope, (*args)[0]);
892 if (firstArg->isNull())
893 target = d->elements.value(0);
894 else if (!firstArg->isInt32())
895 target = d->findElement(firstArg);
898 QList<QQuickStackElement *> elements = d->parseElements(target ? 1 : 0, args, &errors);
899 if (!errors.isEmpty() || elements.isEmpty()) {
900 if (!errors.isEmpty()) {
901 for (
const QString &error : std::as_const(errors))
904 d->warn(QStringLiteral(
"nothing to push"));
906 args->setReturnValue(QV4::Encode::null());
910 int oldDepth = d->elements.size();
911 QQuickStackElement* exit =
nullptr;
912 if (!d->elements.isEmpty())
913 exit = d->elements.pop();
915 if (exit != target ? d->replaceElements(v4, target, elements) : d->pushElements(v4, elements)) {
916 d->depthChange(d->elements.size(), oldDepth);
918 exit->removal =
true;
919 d->removing.insert(exit);
921 QQuickStackElement *enter = d->elements.top();
922#if QT_CONFIG(quick_viewtransitions)
923 d->startTransition(QQuickStackTransition::replaceExit(operation, exit,
this),
924 QQuickStackTransition::replaceEnter(operation, enter,
this),
925 operation == Immediate);
927 d->setCurrentItem(enter);
930 if (d->currentItem) {
931 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem));
932 args->setReturnValue(rv->asReturnedValue());
934 args->setReturnValue(QV4::Encode::null());
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990QQuickItem *QQuickStackView::pushItems(QList<QQuickStackViewArg> args, Operation operation)
992 Q_D(QQuickStackView);
993 const QString operationName = QStringLiteral(
"pushItem");
994 if (d->modifyingElements) {
995 d->warnOfInterruption(operationName);
999 QQmlEngine *engine = qmlEngine(
this);
1003 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
1004 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1006 const QList<QQuickStackElement *> stackElements = d->parseElements(engine, args);
1008#if QT_CONFIG(quick_viewtransitions)
1009 QQuickStackElement *exit =
nullptr;
1010 if (!d->elements.isEmpty())
1011 exit = d->elements.top();
1014 const int oldDepth = d->elements.size();
1015 if (d->pushElements(engine->handle(), stackElements)) {
1016 d->depthChange(d->elements.size(), oldDepth);
1017 QQuickStackElement *enter = d->elements.top();
1018#if QT_CONFIG(quick_viewtransitions)
1019 d->startTransition(QQuickStackTransition::pushEnter(operation, enter,
this),
1020 QQuickStackTransition::pushExit(operation, exit,
this),
1021 operation == Immediate);
1023 d->setCurrentItem(enter);
1026 return d->currentItem;
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046QQuickItem *QQuickStackView::pushItem(QQuickItem *item,
const QVariantMap &properties, Operation operation)
1048 return pushItems({ item, properties }, operation);
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069QQuickItem *QQuickStackView::pushItem(QQmlComponent *component,
const QVariantMap &properties, Operation operation)
1071 return pushItems({ component, properties }, operation);
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092QQuickItem *QQuickStackView::pushItem(
const QUrl &url,
const QVariantMap &properties, Operation operation)
1094 return pushItems({ url, properties }, operation);
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118QQuickItem *QQuickStackView::popToItem(QQuickItem *item, Operation operation)
1120 Q_D(QQuickStackView);
1121 QQmlEngine *engine = qmlEngine(
this);
1124 return d->popToItem(
1125 engine->handle(), item, operation, QQuickStackViewPrivate::CurrentItemPolicy::DoNotPop);
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150QQuickItem *QQuickStackView::popToIndex(
int index, Operation operation)
1152 Q_D(QQuickStackView);
1153 if (index < 0 || index >= d->elements.size()) {
1154 d->warn(QString::fromLatin1(
"popToIndex: index %1 is out of bounds (%2 item(s))")
1155 .arg(index).arg(d->elements.size()));
1159 if (index == d->elements.size() - 1) {
1164 QQuickStackElement *element = d->elements.at(index);
1165 QQmlEngine *engine = qmlEngine(
this);
1168 QV4::ExecutionEngine *v4 = engine->handle();
1169 element->load(v4,
this);
1170 return d->popToItem(
1171 v4, element->item, operation, QQuickStackViewPrivate::CurrentItemPolicy::Pop);
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191QQuickItem *QQuickStackView::popCurrentItem(Operation operation)
1193 Q_D(QQuickStackView);
1194 if (d->elements.size() == 1) {
1195 auto lastItemRemoved = d->elements.last()->item;
1197 return lastItemRemoved;
1200 QQmlEngine *engine = qmlEngine(
this);
1203 return d->popToItem(
1204 engine->handle(), d->currentItem, operation,
1205 QQuickStackViewPrivate::CurrentItemPolicy::Pop);
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249QQuickItem *QQuickStackView::replaceCurrentItem(
const QList<QQuickStackViewArg> &args,
1250 Operation operation)
1252 Q_D(QQuickStackView);
1253 const QString operationName = QStringLiteral(
"replace");
1254 if (d->modifyingElements) {
1255 d->warnOfInterruption(operationName);
1259 QQmlEngine *engine = qmlEngine(
this);
1263 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
1264 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1266 QQuickStackElement *currentElement = !d->elements.isEmpty() ? d->elements.top() :
nullptr;
1268 const QList<QQuickStackElement *> stackElements = d->parseElements(engine, args);
1270 int oldDepth = d->elements.size();
1271 QQuickStackElement* exit =
nullptr;
1272 if (!d->elements.isEmpty())
1273 exit = d->elements.pop();
1275 const bool successfullyReplaced = exit != currentElement
1276 ? d->replaceElements(engine->handle(), currentElement, stackElements)
1277 : d->pushElements(engine->handle(), stackElements);
1278 if (successfullyReplaced) {
1279 d->depthChange(d->elements.size(), oldDepth);
1281 exit->removal =
true;
1282 d->removing.insert(exit);
1284 QQuickStackElement *enter = d->elements.top();
1285#if QT_CONFIG(quick_viewtransitions)
1286 d->startTransition(QQuickStackTransition::replaceExit(operation, exit,
this),
1287 QQuickStackTransition::replaceEnter(operation, enter,
this),
1288 operation == Immediate);
1290 d->setCurrentItem(enter);
1293 return d->currentItem;
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316QQuickItem *QQuickStackView::replaceCurrentItem(QQuickItem *item,
const QVariantMap &properties,
1317 Operation operation)
1319 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(item), QQuickStackViewArg(properties) };
1320 return replaceCurrentItem(args, operation);
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343QQuickItem *QQuickStackView::replaceCurrentItem(QQmlComponent *component,
const QVariantMap &properties,
1344 Operation operation)
1346 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(component), QQuickStackViewArg(properties) };
1347 return replaceCurrentItem(args, operation);
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370QQuickItem *QQuickStackView::replaceCurrentItem(
const QUrl &url,
const QVariantMap &properties,
1371 Operation operation)
1373 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(url), QQuickStackViewArg(properties) };
1374 return replaceCurrentItem(args, operation);
1378
1379
1380
1381
1382
1383
1384
1385
1386bool QQuickStackView::isEmpty()
const
1388 Q_D(
const QQuickStackView);
1389 return d->elements.isEmpty();
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406void QQuickStackView::clear(Operation operation)
1408#if !QT_CONFIG(quick_viewtransitions)
1411 Q_D(QQuickStackView);
1412 if (d->elements.isEmpty())
1415 const QString operationName = QStringLiteral(
"clear");
1416 if (d->modifyingElements) {
1417 d->warnOfInterruption(operationName);
1421 const int oldDepth = d->elements.size();
1423 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
1424 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1425#if QT_CONFIG(quick_viewtransitions)
1426 if (operation != Immediate) {
1427 QQuickStackElement *exit = d->elements.pop();
1428 exit->removal =
true;
1429 d->removing.insert(exit);
1430 d->startTransition(QQuickStackTransition::popExit(operation, exit,
this),
1431 QQuickStackTransition::popEnter(operation,
nullptr,
this),
false);
1435 d->setCurrentItem(
nullptr);
1436 qDeleteAll(d->elements);
1437 d->elements.clear();
1438 d->depthChange(0, oldDepth);
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453QJSValue QQuickStackView::initialItem()
const
1455 Q_D(
const QQuickStackView);
1456 return d->initialItem;
1459void QQuickStackView::setInitialItem(
const QJSValue &item)
1461 Q_D(QQuickStackView);
1462 d->initialItem = item;
1465#if QT_CONFIG(quick_viewtransitions)
1467
1468
1469
1470
1471
1472
1473
1474QQuickTransition *QQuickStackView::popEnter()
const
1476 Q_D(
const QQuickStackView);
1477 if (d->transitioner)
1478 return d->transitioner->removeDisplacedTransition;
1482void QQuickStackView::setPopEnter(QQuickTransition *enter)
1484 Q_D(QQuickStackView);
1485 d->ensureTransitioner();
1486 if (d->transitioner->removeDisplacedTransition == enter)
1489 d->transitioner->removeDisplacedTransition = enter;
1490 emit popEnterChanged();
1494
1495
1496
1497
1498
1499
1500
1501QQuickTransition *QQuickStackView::popExit()
const
1503 Q_D(
const QQuickStackView);
1504 if (d->transitioner)
1505 return d->transitioner->removeTransition;
1509void QQuickStackView::setPopExit(QQuickTransition *exit)
1511 Q_D(QQuickStackView);
1512 d->ensureTransitioner();
1513 if (d->transitioner->removeTransition == exit)
1516 d->transitioner->removeTransition = exit;
1517 emit popExitChanged();
1521
1522
1523
1524
1525
1526
1527
1528QQuickTransition *QQuickStackView::pushEnter()
const
1530 Q_D(
const QQuickStackView);
1531 if (d->transitioner)
1532 return d->transitioner->addTransition;
1536void QQuickStackView::setPushEnter(QQuickTransition *enter)
1538 Q_D(QQuickStackView);
1539 d->ensureTransitioner();
1540 if (d->transitioner->addTransition == enter)
1543 d->transitioner->addTransition = enter;
1544 emit pushEnterChanged();
1548
1549
1550
1551
1552
1553
1554
1555QQuickTransition *QQuickStackView::pushExit()
const
1557 Q_D(
const QQuickStackView);
1558 if (d->transitioner)
1559 return d->transitioner->addDisplacedTransition;
1563void QQuickStackView::setPushExit(QQuickTransition *exit)
1565 Q_D(QQuickStackView);
1566 d->ensureTransitioner();
1567 if (d->transitioner->addDisplacedTransition == exit)
1570 d->transitioner->addDisplacedTransition = exit;
1571 emit pushExitChanged();
1575
1576
1577
1578
1579
1580
1581
1582QQuickTransition *QQuickStackView::replaceEnter()
const
1584 Q_D(
const QQuickStackView);
1585 if (d->transitioner)
1586 return d->transitioner->moveTransition;
1590void QQuickStackView::setReplaceEnter(QQuickTransition *enter)
1592 Q_D(QQuickStackView);
1593 d->ensureTransitioner();
1594 if (d->transitioner->moveTransition == enter)
1597 d->transitioner->moveTransition = enter;
1598 emit replaceEnterChanged();
1602
1603
1604
1605
1606
1607
1608
1609QQuickTransition *QQuickStackView::replaceExit()
const
1611 Q_D(
const QQuickStackView);
1612 if (d->transitioner)
1613 return d->transitioner->moveDisplacedTransition;
1617void QQuickStackView::setReplaceExit(QQuickTransition *exit)
1619 Q_D(QQuickStackView);
1620 d->ensureTransitioner();
1621 if (d->transitioner->moveDisplacedTransition == exit)
1624 d->transitioner->moveDisplacedTransition = exit;
1625 emit replaceExitChanged();
1629void QQuickStackView::componentComplete()
1631 QQuickControl::componentComplete();
1633 Q_D(QQuickStackView);
1634 QScopedValueRollback<QString> operationNameRollback(d->operation, QStringLiteral(
"initialItem"));
1635 QQuickStackElement *element =
nullptr;
1637 int oldDepth = d->elements.size();
1639 QQmlEngine *engine = qmlEngine(
this);
1643 if (QObject *o = d->initialItem.toQObject())
1644 element = QQuickStackElement::fromObject(o,
this, &error);
1645 else if (d->initialItem.isString())
1646 element = QQuickStackElement::fromString(engine, d->initialItem.toString(),
this, &error);
1647 if (!error.isEmpty()) {
1650 }
else if (d->pushElement(engine->handle(), element)) {
1651 d->depthChange(d->elements.size(), oldDepth);
1652 d->setCurrentItem(element);
1653 element->setStatus(QQuickStackView::Active);
1657void QQuickStackView::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
1659 QQuickControl::geometryChange(newGeometry, oldGeometry);
1661 Q_D(QQuickStackView);
1662 for (QQuickStackElement *element : std::as_const(d->elements)) {
1663 if (element->item) {
1664 if (!element->widthValid)
1665 element->item->setWidth(newGeometry.width());
1666 if (!element->heightValid)
1667 element->item->setHeight(newGeometry.height());
1672bool QQuickStackView::childMouseEventFilter(QQuickItem *item, QEvent *event)
1680 if (event->type() == QEvent::MouseButtonPress)
1682 if (event->type() == QEvent::UngrabMouse)
1684 QQuickWindow *window = item->window();
1685 return window && !window->mouseGrabberItem();
1688#if QT_CONFIG(quicktemplates2_multitouch)
1689void QQuickStackView::touchEvent(QTouchEvent *event)
1695#if QT_CONFIG(accessibility)
1696QAccessible::Role QQuickStackView::accessibleRole()
const
1698 return QAccessible::LayeredPane;
1704 Q_Q(QQuickStackViewAttached);
1705 int oldIndex = element ? element->index : -1;
1706 QQuickStackView *oldView = element ? element->view :
nullptr;
1707 QQuickStackView::Status oldStatus = element ? element->status : QQuickStackView::Inactive;
1709 QQuickStackView *newView = qobject_cast<QQuickStackView *>(parent);
1710 element = newView ? QQuickStackViewPrivate::get(newView)->findElement(item) :
nullptr;
1712 int newIndex = element ? element->index : -1;
1713 QQuickStackView::Status newStatus = element ? element->status : QQuickStackView::Inactive;
1715 if (oldIndex != newIndex)
1716 emit q->indexChanged();
1717 if (oldView != newView)
1718 emit q->viewChanged();
1719 if (oldStatus != newStatus)
1720 emit q->statusChanged();
1723QQuickStackViewAttached::QQuickStackViewAttached(QObject *parent)
1724 : QObject(*(
new QQuickStackViewAttachedPrivate), parent)
1726 Q_D(QQuickStackViewAttached);
1727 QQuickItem *item = qobject_cast<QQuickItem *>(parent);
1729 connect(item, &QQuickItem::visibleChanged,
this, &QQuickStackViewAttached::visibleChanged);
1730 QQuickItemPrivate::get(item)->addItemChangeListener(d, QQuickItemPrivate::Parent);
1731 d->itemParentChanged(item, item->parentItem());
1732 }
else if (parent) {
1733 qmlWarning(parent) <<
"StackView attached property must be attached to an object deriving from Item";
1737QQuickStackViewAttached::~QQuickStackViewAttached()
1739 Q_D(QQuickStackViewAttached);
1740 QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1742 QQuickItemPrivate::get(parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Parent);
1746
1747
1748
1749
1750
1751
1752int QQuickStackViewAttached::index()
const
1754 Q_D(
const QQuickStackViewAttached);
1755 return d->element ? d->element->index : -1;
1759
1760
1761
1762
1763
1764
1765QQuickStackView *QQuickStackViewAttached::view()
const
1767 Q_D(
const QQuickStackViewAttached);
1768 return d->element ? d->element->view :
nullptr;
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784QQuickStackView::Status QQuickStackViewAttached::status()
const
1786 Q_D(
const QQuickStackViewAttached);
1787 return d->element ? d->element->status : QQuickStackView::Inactive;
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811bool QQuickStackViewAttached::isVisible()
const
1813 const QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1814 return parentItem && parentItem->isVisible();
1817void QQuickStackViewAttached::setVisible(
bool visible)
1819 Q_D(QQuickStackViewAttached);
1820 d->explicitVisible =
true;
1821 QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1823 parentItem->setVisible(visible);
1826void QQuickStackViewAttached::resetVisible()
1828 Q_D(QQuickStackViewAttached);
1829 d->explicitVisible =
false;
1830 if (!d->element || !d->element->view)
1833 QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1835 parentItem->setVisible(parentItem == d->element->view->currentItem());
1839
1840
1841
1842
1843
1844
1845
1848
1849
1850
1851
1852
1853
1854
1857
1858
1859
1860
1861
1862
1863
1864
1867
1868
1869
1870
1871
1872
1873
1874
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1895#include "moc_qquickstackview_p.cpp"
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
friend QDebug operator<<(QDebug debug, const QQuickStackViewArg &arg)