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
384
385
386
387
388
390QQuickStackView::QQuickStackView(QQuickItem *parent)
391 : QQuickControl(*(
new QQuickStackViewPrivate), parent)
393 setFlag(ItemIsFocusScope);
395 Q_D(QQuickStackView);
396 d->setSizePolicy(QLayoutPolicy::Preferred, QLayoutPolicy::Preferred);
399QQuickStackView::~QQuickStackView()
401 Q_D(QQuickStackView);
402#if QT_CONFIG(quick_viewtransitions)
403 if (d->transitioner) {
404 d->transitioner->setChangeListener(
nullptr);
405 delete d->transitioner;
408 qDeleteAll(d->removing);
409 qDeleteAll(d->removed);
410 qDeleteAll(d->elements);
413QQuickStackViewAttached *QQuickStackView::qmlAttachedProperties(QObject *object)
415 return new QQuickStackViewAttached(object);
419
420
421
422
423bool QQuickStackView::isBusy()
const
425 Q_D(
const QQuickStackView);
430
431
432
433
434int QQuickStackView::depth()
const
436 Q_D(
const QQuickStackView);
437 return d->elements.size();
441
442
443
444
445QQuickItem *QQuickStackView::currentItem()
const
447 Q_D(
const QQuickStackView);
448 return d->currentItem;
452
453
454
455
456
457
458
459
460
461QQuickItem *QQuickStackView::get(
int index, LoadBehavior behavior)
463 Q_D(QQuickStackView);
464 QQuickStackElement *element = d->elements.value(index);
466 if (behavior == ForceLoad) {
469 if (QQmlEngine *engine = qmlEngine(
this))
470 element->load(engine->handle(),
this);
472 return element->item;
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494QQuickItem *QQuickStackView::find(
const QJSValue &callback, LoadBehavior behavior)
496 Q_D(QQuickStackView);
497 QJSValue func(callback);
498 QQmlEngine *engine = qmlEngine(
this);
499 if (!engine || !func.isCallable())
502 for (
int i = d->elements.size() - 1; i >= 0; --i) {
503 QQuickStackElement *element = d->elements.at(i);
504 if (behavior == ForceLoad)
505 element->load(engine->handle(),
this);
507 QJSValue rv = func.call(QJSValueList() << engine->newQObject(element->item) << i);
509 return element->item;
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
576
577
578
579
580
581void QQuickStackView::push(QQmlV4FunctionPtr args)
583 Q_D(QQuickStackView);
584 const QString operationName = QStringLiteral(
"push");
585 if (d->modifyingElements) {
586 d->warnOfInterruption(operationName);
590 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
591 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
592 if (args->length() <= 0) {
593 d->warn(QStringLiteral(
"missing arguments"));
594 args->setReturnValue(QV4::Encode::null());
598 QV4::ExecutionEngine *v4 = args->v4engine();
599 QV4::Scope scope(v4);
601#if QT_CONFIG(quick_viewtransitions)
602 Operation operation = d->elements.isEmpty() ? Immediate : PushTransition;
603 QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
604 if (lastArg->isInt32())
605 operation =
static_cast<Operation>(lastArg->toInt32());
609 QList<QQuickStackElement *> elements = d->parseElements(0, args, &errors);
612 auto removeIt = std::remove_if(elements.begin(), elements.end(), [&](QQuickStackElement *element) {
613 return element->item && d->findElement(element->item);
615 for (
auto it = removeIt, end = elements.end(); it != end; ++it)
617 elements.erase(removeIt, elements.end());
619 if (!errors.isEmpty() || elements.isEmpty()) {
620 if (!errors.isEmpty()) {
621 for (
const QString &error : std::as_const(errors))
624 d->warn(QStringLiteral(
"nothing to push"));
626 args->setReturnValue(QV4::Encode::null());
630#if QT_CONFIG(quick_viewtransitions)
631 QQuickStackElement *exit =
nullptr;
632 if (!d->elements.isEmpty())
633 exit = d->elements.top();
636 int oldDepth = d->elements.size();
637 if (d->pushElements(v4, elements)) {
638 d->depthChange(d->elements.size(), oldDepth);
639 QQuickStackElement *enter = d->elements.top();
640#if QT_CONFIG(quick_viewtransitions)
641 d->startTransition(QQuickStackTransition::pushEnter(operation, enter,
this),
642 QQuickStackTransition::pushExit(operation, exit,
this),
643 operation == Immediate);
645 d->setCurrentItem(enter);
648 if (d->currentItem) {
649 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem));
650 args->setReturnValue(rv->asReturnedValue());
652 args->setReturnValue(QV4::Encode::null());
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
690
691
692
693
694
695void QQuickStackView::pop(QQmlV4FunctionPtr args)
697 Q_D(QQuickStackView);
698 const QString operationName = QStringLiteral(
"pop");
699 if (d->modifyingElements) {
700 d->warnOfInterruption(operationName);
701 args->setReturnValue(QV4::Encode::null());
705 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
706 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
707 int argc = args->length();
708 if (d->elements.size() <= 1 || argc > 2) {
710 d->warn(QStringLiteral(
"too many arguments"));
711 args->setReturnValue(QV4::Encode::null());
715 int oldDepth = d->elements.size();
716 QQuickStackElement *exit = d->elements.pop();
717 QQuickStackElement *enter = d->elements.top();
719 QV4::ExecutionEngine *v4 = args->v4engine();
720 QV4::Scope scope(v4);
723 QV4::ScopedValue value(scope, (*args)[0]);
724 if (value->isNull()) {
725 enter = d->elements.value(0);
726 }
else if (
const QV4::QObjectWrapper *o = value->as<QV4::QObjectWrapper>()) {
727 QQuickItem *item = qobject_cast<QQuickItem *>(o->object());
728 enter = d->findElement(item);
730 if (item != d->currentItem)
731 d->warn(QStringLiteral(
"can't find item to pop: ") + value->toQString());
732 args->setReturnValue(QV4::Encode::null());
733 d->elements.push(exit);
739#if QT_CONFIG(quick_viewtransitions)
740 Operation operation = PopTransition;
742 QV4::ScopedValue lastArg(scope, (*args)[argc - 1]);
743 if (lastArg->isInt32())
744 operation =
static_cast<Operation>(lastArg->toInt32());
748 QPointer<QQuickItem> previousItem;
750 if (d->popElements(v4, enter)) {
752 exit->removal =
true;
753 d->removing.insert(exit);
754 previousItem = exit->item;
756 d->depthChange(d->elements.size(), oldDepth);
757#if QT_CONFIG(quick_viewtransitions)
758 d->startTransition(QQuickStackTransition::popExit(operation, exit,
this),
759 QQuickStackTransition::popEnter(operation, enter,
this),
760 operation == Immediate);
762 d->setCurrentItem(enter);
766 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, previousItem));
767 args->setReturnValue(rv->asReturnedValue());
769 args->setReturnValue(QV4::Encode::null());
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
862
863
864
865
866
867void QQuickStackView::replace(QQmlV4FunctionPtr args)
869 Q_D(QQuickStackView);
870 const QString operationName = QStringLiteral(
"replace");
871 if (d->modifyingElements) {
872 d->warnOfInterruption(operationName);
873 args->setReturnValue(QV4::Encode::null());
877 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
878 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
879 if (args->length() <= 0) {
880 d->warn(QStringLiteral(
"missing arguments"));
881 args->setReturnValue(QV4::Encode::null());
885 QV4::ExecutionEngine *v4 = args->v4engine();
886 QV4::Scope scope(v4);
888#if QT_CONFIG(quick_viewtransitions)
889 Operation operation = d->elements.isEmpty() ? Immediate : ReplaceTransition;
890 QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
891 if (lastArg->isInt32())
892 operation =
static_cast<Operation>(lastArg->toInt32());
895 QQuickStackElement *target =
nullptr;
896 QV4::ScopedValue firstArg(scope, (*args)[0]);
897 if (firstArg->isNull())
898 target = d->elements.value(0);
899 else if (!firstArg->isInt32())
900 target = d->findElement(firstArg);
903 QList<QQuickStackElement *> elements = d->parseElements(target ? 1 : 0, args, &errors);
904 if (!errors.isEmpty() || elements.isEmpty()) {
905 if (!errors.isEmpty()) {
906 for (
const QString &error : std::as_const(errors))
909 d->warn(QStringLiteral(
"nothing to push"));
911 args->setReturnValue(QV4::Encode::null());
915 int oldDepth = d->elements.size();
916 QQuickStackElement* exit =
nullptr;
917 if (!d->elements.isEmpty())
918 exit = d->elements.pop();
920 if (exit != target ? d->replaceElements(v4, target, elements) : d->pushElements(v4, elements)) {
921 d->depthChange(d->elements.size(), oldDepth);
923 exit->removal =
true;
924 d->removing.insert(exit);
926 QQuickStackElement *enter = d->elements.top();
927#if QT_CONFIG(quick_viewtransitions)
928 d->startTransition(QQuickStackTransition::replaceExit(operation, exit,
this),
929 QQuickStackTransition::replaceEnter(operation, enter,
this),
930 operation == Immediate);
932 d->setCurrentItem(enter);
935 if (d->currentItem) {
936 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem));
937 args->setReturnValue(rv->asReturnedValue());
939 args->setReturnValue(QV4::Encode::null());
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
990
991
992
993
994
995QQuickItem *QQuickStackView::pushItems(QList<QQuickStackViewArg> args, Operation operation)
997 Q_D(QQuickStackView);
998 const QString operationName = QStringLiteral(
"pushItem");
999 if (d->modifyingElements) {
1000 d->warnOfInterruption(operationName);
1004 QQmlEngine *engine = qmlEngine(
this);
1008 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
1009 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1011 const QList<QQuickStackElement *> stackElements = d->parseElements(engine, args);
1013#if QT_CONFIG(quick_viewtransitions)
1014 QQuickStackElement *exit =
nullptr;
1015 if (!d->elements.isEmpty())
1016 exit = d->elements.top();
1019 const int oldDepth = d->elements.size();
1020 if (d->pushElements(engine->handle(), stackElements)) {
1021 d->depthChange(d->elements.size(), oldDepth);
1022 QQuickStackElement *enter = d->elements.top();
1023#if QT_CONFIG(quick_viewtransitions)
1024 d->startTransition(QQuickStackTransition::pushEnter(operation, enter,
this),
1025 QQuickStackTransition::pushExit(operation, exit,
this),
1026 operation == Immediate);
1028 d->setCurrentItem(enter);
1031 return d->currentItem;
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051QQuickItem *QQuickStackView::pushItem(QQuickItem *item,
const QVariantMap &properties, Operation operation)
1053 return pushItems({ item, properties }, operation);
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074QQuickItem *QQuickStackView::pushItem(QQmlComponent *component,
const QVariantMap &properties, Operation operation)
1076 return pushItems({ component, properties }, operation);
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097QQuickItem *QQuickStackView::pushItem(
const QUrl &url,
const QVariantMap &properties, Operation operation)
1099 return pushItems({ url, properties }, operation);
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123QQuickItem *QQuickStackView::popToItem(QQuickItem *item, Operation operation)
1125 Q_D(QQuickStackView);
1126 QQmlEngine *engine = qmlEngine(
this);
1129 return d->popToItem(
1130 engine->handle(), item, operation, QQuickStackViewPrivate::CurrentItemPolicy::DoNotPop);
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155QQuickItem *QQuickStackView::popToIndex(
int index, Operation operation)
1157 Q_D(QQuickStackView);
1158 if (index < 0 || index >= d->elements.size()) {
1159 d->warn(QString::fromLatin1(
"popToIndex: index %1 is out of bounds (%2 item(s))")
1160 .arg(index).arg(d->elements.size()));
1164 if (index == d->elements.size() - 1) {
1169 QQuickStackElement *element = d->elements.at(index);
1170 QQmlEngine *engine = qmlEngine(
this);
1173 QV4::ExecutionEngine *v4 = engine->handle();
1174 element->load(v4,
this);
1175 return d->popToItem(
1176 v4, element->item, operation, QQuickStackViewPrivate::CurrentItemPolicy::Pop);
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196QQuickItem *QQuickStackView::popCurrentItem(Operation operation)
1198 Q_D(QQuickStackView);
1199 if (d->elements.size() == 1) {
1200 auto lastItemRemoved = d->elements.last()->item;
1202 return lastItemRemoved;
1205 QQmlEngine *engine = qmlEngine(
this);
1208 return d->popToItem(
1209 engine->handle(), d->currentItem, operation,
1210 QQuickStackViewPrivate::CurrentItemPolicy::Pop);
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
1249
1250
1251
1252
1253
1254QQuickItem *QQuickStackView::replaceCurrentItem(
const QList<QQuickStackViewArg> &args,
1255 Operation operation)
1257 Q_D(QQuickStackView);
1258 const QString operationName = QStringLiteral(
"replace");
1259 if (d->modifyingElements) {
1260 d->warnOfInterruption(operationName);
1264 QQmlEngine *engine = qmlEngine(
this);
1268 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
1269 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1271 QQuickStackElement *currentElement = !d->elements.isEmpty() ? d->elements.top() :
nullptr;
1273 const QList<QQuickStackElement *> stackElements = d->parseElements(engine, args);
1275 int oldDepth = d->elements.size();
1276 QQuickStackElement* exit =
nullptr;
1277 if (!d->elements.isEmpty())
1278 exit = d->elements.pop();
1280 const bool successfullyReplaced = exit != currentElement
1281 ? d->replaceElements(engine->handle(), currentElement, stackElements)
1282 : d->pushElements(engine->handle(), stackElements);
1283 if (successfullyReplaced) {
1284 d->depthChange(d->elements.size(), oldDepth);
1286 exit->removal =
true;
1287 d->removing.insert(exit);
1289 QQuickStackElement *enter = d->elements.top();
1290#if QT_CONFIG(quick_viewtransitions)
1291 d->startTransition(QQuickStackTransition::replaceExit(operation, exit,
this),
1292 QQuickStackTransition::replaceEnter(operation, enter,
this),
1293 operation == Immediate);
1295 d->setCurrentItem(enter);
1298 return d->currentItem;
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321QQuickItem *QQuickStackView::replaceCurrentItem(QQuickItem *item,
const QVariantMap &properties,
1322 Operation operation)
1324 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(item), QQuickStackViewArg(properties) };
1325 return replaceCurrentItem(args, operation);
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348QQuickItem *QQuickStackView::replaceCurrentItem(QQmlComponent *component,
const QVariantMap &properties,
1349 Operation operation)
1351 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(component), QQuickStackViewArg(properties) };
1352 return replaceCurrentItem(args, operation);
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375QQuickItem *QQuickStackView::replaceCurrentItem(
const QUrl &url,
const QVariantMap &properties,
1376 Operation operation)
1378 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(url), QQuickStackViewArg(properties) };
1379 return replaceCurrentItem(args, operation);
1383
1384
1385
1386
1387
1388
1389
1390
1391bool QQuickStackView::isEmpty()
const
1393 Q_D(
const QQuickStackView);
1394 return d->elements.isEmpty();
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411void QQuickStackView::clear(Operation operation)
1413#if !QT_CONFIG(quick_viewtransitions)
1416 Q_D(QQuickStackView);
1417 if (d->elements.isEmpty())
1420 const QString operationName = QStringLiteral(
"clear");
1421 if (d->modifyingElements) {
1422 d->warnOfInterruption(operationName);
1426 const int oldDepth = d->elements.size();
1428 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
1429 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1430#if QT_CONFIG(quick_viewtransitions)
1431 if (operation != Immediate) {
1432 QQuickStackElement *exit = d->elements.pop();
1433 exit->removal =
true;
1434 d->removing.insert(exit);
1435 d->startTransition(QQuickStackTransition::popExit(operation, exit,
this),
1436 QQuickStackTransition::popEnter(operation,
nullptr,
this),
false);
1440 d->setCurrentItem(
nullptr);
1441 qDeleteAll(d->elements);
1442 d->elements.clear();
1443 d->depthChange(0, oldDepth);
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458QJSValue QQuickStackView::initialItem()
const
1460 Q_D(
const QQuickStackView);
1461 return d->initialItem;
1464void QQuickStackView::setInitialItem(
const QJSValue &item)
1466 Q_D(QQuickStackView);
1467 d->initialItem = item;
1470#if QT_CONFIG(quick_viewtransitions)
1472
1473
1474
1475
1476
1477
1478
1479QQuickTransition *QQuickStackView::popEnter()
const
1481 Q_D(
const QQuickStackView);
1482 if (d->transitioner)
1483 return d->transitioner->removeDisplacedTransition;
1487void QQuickStackView::setPopEnter(QQuickTransition *enter)
1489 Q_D(QQuickStackView);
1490 d->ensureTransitioner();
1491 if (d->transitioner->removeDisplacedTransition == enter)
1494 d->transitioner->removeDisplacedTransition = enter;
1495 emit popEnterChanged();
1499
1500
1501
1502
1503
1504
1505
1506QQuickTransition *QQuickStackView::popExit()
const
1508 Q_D(
const QQuickStackView);
1509 if (d->transitioner)
1510 return d->transitioner->removeTransition;
1514void QQuickStackView::setPopExit(QQuickTransition *exit)
1516 Q_D(QQuickStackView);
1517 d->ensureTransitioner();
1518 if (d->transitioner->removeTransition == exit)
1521 d->transitioner->removeTransition = exit;
1522 emit popExitChanged();
1526
1527
1528
1529
1530
1531
1532
1533QQuickTransition *QQuickStackView::pushEnter()
const
1535 Q_D(
const QQuickStackView);
1536 if (d->transitioner)
1537 return d->transitioner->addTransition;
1541void QQuickStackView::setPushEnter(QQuickTransition *enter)
1543 Q_D(QQuickStackView);
1544 d->ensureTransitioner();
1545 if (d->transitioner->addTransition == enter)
1548 d->transitioner->addTransition = enter;
1549 emit pushEnterChanged();
1553
1554
1555
1556
1557
1558
1559
1560QQuickTransition *QQuickStackView::pushExit()
const
1562 Q_D(
const QQuickStackView);
1563 if (d->transitioner)
1564 return d->transitioner->addDisplacedTransition;
1568void QQuickStackView::setPushExit(QQuickTransition *exit)
1570 Q_D(QQuickStackView);
1571 d->ensureTransitioner();
1572 if (d->transitioner->addDisplacedTransition == exit)
1575 d->transitioner->addDisplacedTransition = exit;
1576 emit pushExitChanged();
1580
1581
1582
1583
1584
1585
1586
1587QQuickTransition *QQuickStackView::replaceEnter()
const
1589 Q_D(
const QQuickStackView);
1590 if (d->transitioner)
1591 return d->transitioner->moveTransition;
1595void QQuickStackView::setReplaceEnter(QQuickTransition *enter)
1597 Q_D(QQuickStackView);
1598 d->ensureTransitioner();
1599 if (d->transitioner->moveTransition == enter)
1602 d->transitioner->moveTransition = enter;
1603 emit replaceEnterChanged();
1607
1608
1609
1610
1611
1612
1613
1614QQuickTransition *QQuickStackView::replaceExit()
const
1616 Q_D(
const QQuickStackView);
1617 if (d->transitioner)
1618 return d->transitioner->moveDisplacedTransition;
1622void QQuickStackView::setReplaceExit(QQuickTransition *exit)
1624 Q_D(QQuickStackView);
1625 d->ensureTransitioner();
1626 if (d->transitioner->moveDisplacedTransition == exit)
1629 d->transitioner->moveDisplacedTransition = exit;
1630 emit replaceExitChanged();
1634void QQuickStackView::componentComplete()
1636 QQuickControl::componentComplete();
1638 Q_D(QQuickStackView);
1639 QScopedValueRollback<QString> operationNameRollback(d->operation, QStringLiteral(
"initialItem"));
1640 QQuickStackElement *element =
nullptr;
1642 int oldDepth = d->elements.size();
1644 QQmlEngine *engine = qmlEngine(
this);
1648 if (QObject *o = d->initialItem.toQObject())
1649 element = QQuickStackElement::fromObject(o,
this, &error);
1650 else if (d->initialItem.isString())
1651 element = QQuickStackElement::fromString(engine, d->initialItem.toString(),
this, &error);
1652 if (!error.isEmpty()) {
1655 }
else if (d->pushElement(engine->handle(), element)) {
1656 d->depthChange(d->elements.size(), oldDepth);
1657 d->setCurrentItem(element);
1658 element->setStatus(QQuickStackView::Active);
1662void QQuickStackView::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
1664 QQuickControl::geometryChange(newGeometry, oldGeometry);
1666 Q_D(QQuickStackView);
1667 for (QQuickStackElement *element : std::as_const(d->elements)) {
1668 if (element->item) {
1669 if (!element->widthValid)
1670 element->item->setWidth(newGeometry.width());
1671 if (!element->heightValid)
1672 element->item->setHeight(newGeometry.height());
1677bool QQuickStackView::childMouseEventFilter(QQuickItem *item, QEvent *event)
1685 if (event->type() == QEvent::MouseButtonPress)
1687 if (event->type() == QEvent::UngrabMouse)
1689 QQuickWindow *window = item->window();
1690 return window && !window->mouseGrabberItem();
1693#if QT_CONFIG(quicktemplates2_multitouch)
1694void QQuickStackView::touchEvent(QTouchEvent *event)
1700#if QT_CONFIG(accessibility)
1701QAccessible::Role QQuickStackView::accessibleRole()
const
1703 return QAccessible::LayeredPane;
1709 Q_Q(QQuickStackViewAttached);
1710 int oldIndex = element ? element->index : -1;
1711 QQuickStackView *oldView = element ? element->view :
nullptr;
1712 QQuickStackView::Status oldStatus = element ? element->status : QQuickStackView::Inactive;
1714 QQuickStackView *newView = qobject_cast<QQuickStackView *>(parent);
1715 element = newView ? QQuickStackViewPrivate::get(newView)->findElement(item) :
nullptr;
1717 int newIndex = element ? element->index : -1;
1718 QQuickStackView::Status newStatus = element ? element->status : QQuickStackView::Inactive;
1720 if (oldIndex != newIndex)
1721 emit q->indexChanged();
1722 if (oldView != newView)
1723 emit q->viewChanged();
1724 if (oldStatus != newStatus)
1725 emit q->statusChanged();
1728QQuickStackViewAttached::QQuickStackViewAttached(QObject *parent)
1729 : QObject(*(
new QQuickStackViewAttachedPrivate), parent)
1731 Q_D(QQuickStackViewAttached);
1732 QQuickItem *item = qobject_cast<QQuickItem *>(parent);
1734 connect(item, &QQuickItem::visibleChanged,
this, &QQuickStackViewAttached::visibleChanged);
1735 QQuickItemPrivate::get(item)->addItemChangeListener(d, QQuickItemPrivate::Parent);
1736 d->itemParentChanged(item, item->parentItem());
1737 }
else if (parent) {
1738 qmlWarning(parent) <<
"StackView attached property must be attached to an object deriving from Item";
1742QQuickStackViewAttached::~QQuickStackViewAttached()
1744 Q_D(QQuickStackViewAttached);
1745 QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1747 QQuickItemPrivate::get(parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Parent);
1751
1752
1753
1754
1755
1756
1757int QQuickStackViewAttached::index()
const
1759 Q_D(
const QQuickStackViewAttached);
1760 return d->element ? d->element->index : -1;
1764
1765
1766
1767
1768
1769
1770QQuickStackView *QQuickStackViewAttached::view()
const
1772 Q_D(
const QQuickStackViewAttached);
1773 return d->element ? d->element->view :
nullptr;
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789QQuickStackView::Status QQuickStackViewAttached::status()
const
1791 Q_D(
const QQuickStackViewAttached);
1792 return d->element ? d->element->status : QQuickStackView::Inactive;
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817bool QQuickStackViewAttached::isVisible()
const
1819 const QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1820 return parentItem && parentItem->isVisible();
1823void QQuickStackViewAttached::setVisible(
bool visible)
1825 Q_D(QQuickStackViewAttached);
1826 d->explicitVisible =
true;
1827 QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1829 parentItem->setVisible(visible);
1832void QQuickStackViewAttached::resetVisible()
1834 Q_D(QQuickStackViewAttached);
1835 d->explicitVisible =
false;
1836 if (!d->element || !d->element->view)
1839 QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1841 parentItem->setVisible(parentItem == d->element->view->currentItem());
1845
1846
1847
1848
1849
1850
1851
1854
1855
1856
1857
1858
1859
1860
1863
1864
1865
1866
1867
1868
1869
1870
1873
1874
1875
1876
1877
1878
1879
1880
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1901#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)
Combined button and popup list for selecting options.