7#if QT_CONFIG(quick_viewtransitions)
8#include "qquickstacktransition_p_p.h"
11#include <QtCore/qscopedvaluerollback.h>
12#include <QtQml/qjsvalue.h>
13#include <QtQml/qqmlengine.h>
14#include <QtQml/qqmlinfo.h>
15#include <QtQml/qqmlcomponent.h>
17#include <private/qv4qobjectwrapper_p.h>
18#include <private/qqmlengine_p.h>
27QQuickStackViewArg::QQuickStackViewArg(
const QUrl &url)
33 : mComponent(component)
38 : mProperties(properties)
42#ifndef QT_NO_DEBUG_STREAM
45 QDebugStateSaver saver(debug);
46 debug.nospace() <<
"QQuickStackViewArg("
47 <<
"mItem=" << arg.mItem
48 <<
" mComponent=" << arg.mComponent
49 <<
" mUrl=" << arg.mUrl
56
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
384QQuickStackView::QQuickStackView(QQuickItem *parent)
385 : QQuickControl(*(
new QQuickStackViewPrivate), parent)
387 setFlag(ItemIsFocusScope);
389 Q_D(QQuickStackView);
390 d->setSizePolicy(QLayoutPolicy::Preferred, QLayoutPolicy::Preferred);
393QQuickStackView::~QQuickStackView()
395 Q_D(QQuickStackView);
396#if QT_CONFIG(quick_viewtransitions)
397 if (d->transitioner) {
398 d->transitioner->setChangeListener(
nullptr);
399 delete d->transitioner;
402 qDeleteAll(d->removing);
403 qDeleteAll(d->removed);
404 qDeleteAll(d->elements);
407QQuickStackViewAttached *QQuickStackView::qmlAttachedProperties(QObject *object)
409 return new QQuickStackViewAttached(object);
413
414
415
416
417bool QQuickStackView::isBusy()
const
419 Q_D(
const QQuickStackView);
424
425
426
427
428int QQuickStackView::depth()
const
430 Q_D(
const QQuickStackView);
431 return d->elements.size();
435
436
437
438
439QQuickItem *QQuickStackView::currentItem()
const
441 Q_D(
const QQuickStackView);
442 return d->currentItem;
446
447
448
449
450
451
452
453
454
455QQuickItem *QQuickStackView::get(
int index, LoadBehavior behavior)
457 Q_D(QQuickStackView);
458 QQuickStackElement *element = d->elements.value(index);
460 if (behavior == ForceLoad)
462 return element->item;
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484QQuickItem *QQuickStackView::find(
const QJSValue &callback, LoadBehavior behavior)
486 Q_D(QQuickStackView);
487 QJSValue func(callback);
488 QQmlEngine *engine = qmlEngine(
this);
489 if (!engine || !func.isCallable())
492 for (
int i = d->elements.size() - 1; i >= 0; --i) {
493 QQuickStackElement *element = d->elements.at(i);
494 if (behavior == ForceLoad)
497 QJSValue rv = func.call(QJSValueList() << engine->newQObject(element->item) << i);
499 return element->item;
507
508
509
510
511
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
571void QQuickStackView::push(QQmlV4FunctionPtr args)
573 Q_D(QQuickStackView);
574 const QString operationName = QStringLiteral(
"push");
575 if (d->modifyingElements) {
576 d->warnOfInterruption(operationName);
580 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
581 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
582 if (args->length() <= 0) {
583 d->warn(QStringLiteral(
"missing arguments"));
584 args->setReturnValue(QV4::Encode::null());
588 QV4::ExecutionEngine *v4 = args->v4engine();
589 QV4::Scope scope(v4);
591#if QT_CONFIG(quick_viewtransitions)
592 Operation operation = d->elements.isEmpty() ? Immediate : PushTransition;
593 QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
594 if (lastArg->isInt32())
595 operation =
static_cast<Operation>(lastArg->toInt32());
599 QList<QQuickStackElement *> elements = d->parseElements(0, args, &errors);
602 auto removeIt = std::remove_if(elements.begin(), elements.end(), [&](QQuickStackElement *element) {
603 return element->item && d->findElement(element->item);
605 for (
auto it = removeIt, end = elements.end(); it != end; ++it)
607 elements.erase(removeIt, elements.end());
609 if (!errors.isEmpty() || elements.isEmpty()) {
610 if (!errors.isEmpty()) {
611 for (
const QString &error : std::as_const(errors))
614 d->warn(QStringLiteral(
"nothing to push"));
616 args->setReturnValue(QV4::Encode::null());
620#if QT_CONFIG(quick_viewtransitions)
621 QQuickStackElement *exit =
nullptr;
622 if (!d->elements.isEmpty())
623 exit = d->elements.top();
626 int oldDepth = d->elements.size();
627 if (d->pushElements(elements)) {
628 d->depthChange(d->elements.size(), oldDepth);
629 QQuickStackElement *enter = d->elements.top();
630#if QT_CONFIG(quick_viewtransitions)
631 d->startTransition(QQuickStackTransition::pushEnter(operation, enter,
this),
632 QQuickStackTransition::pushExit(operation, exit,
this),
633 operation == Immediate);
635 d->setCurrentItem(enter);
638 if (d->currentItem) {
639 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem));
640 args->setReturnValue(rv->asReturnedValue());
642 args->setReturnValue(QV4::Encode::null());
647
648
649
650
651
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
685void QQuickStackView::pop(QQmlV4FunctionPtr args)
687 Q_D(QQuickStackView);
688 const QString operationName = QStringLiteral(
"pop");
689 if (d->modifyingElements) {
690 d->warnOfInterruption(operationName);
691 args->setReturnValue(QV4::Encode::null());
695 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
696 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
697 int argc = args->length();
698 if (d->elements.size() <= 1 || argc > 2) {
700 d->warn(QStringLiteral(
"too many arguments"));
701 args->setReturnValue(QV4::Encode::null());
705 int oldDepth = d->elements.size();
706 QQuickStackElement *exit = d->elements.pop();
707 QQuickStackElement *enter = d->elements.top();
709 QV4::ExecutionEngine *v4 = args->v4engine();
710 QV4::Scope scope(v4);
713 QV4::ScopedValue value(scope, (*args)[0]);
714 if (value->isNull()) {
715 enter = d->elements.value(0);
716 }
else if (
const QV4::QObjectWrapper *o = value->as<QV4::QObjectWrapper>()) {
717 QQuickItem *item = qobject_cast<QQuickItem *>(o->object());
718 enter = d->findElement(item);
720 if (item != d->currentItem)
721 d->warn(QStringLiteral(
"can't find item to pop: ") + value->toQString());
722 args->setReturnValue(QV4::Encode::null());
723 d->elements.push(exit);
729#if QT_CONFIG(quick_viewtransitions)
730 Operation operation = PopTransition;
732 QV4::ScopedValue lastArg(scope, (*args)[argc - 1]);
733 if (lastArg->isInt32())
734 operation =
static_cast<Operation>(lastArg->toInt32());
738 QPointer<QQuickItem> previousItem;
740 if (d->popElements(enter)) {
742 exit->removal =
true;
743 d->removing.insert(exit);
744 previousItem = exit->item;
746 d->depthChange(d->elements.size(), oldDepth);
747#if QT_CONFIG(quick_viewtransitions)
748 d->startTransition(QQuickStackTransition::popExit(operation, exit,
this),
749 QQuickStackTransition::popEnter(operation, enter,
this),
750 operation == Immediate);
752 d->setCurrentItem(enter);
756 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, previousItem));
757 args->setReturnValue(rv->asReturnedValue());
759 args->setReturnValue(QV4::Encode::null());
764
765
766
767
768
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
857void QQuickStackView::replace(QQmlV4FunctionPtr args)
859 Q_D(QQuickStackView);
860 const QString operationName = QStringLiteral(
"replace");
861 if (d->modifyingElements) {
862 d->warnOfInterruption(operationName);
863 args->setReturnValue(QV4::Encode::null());
867 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
868 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
869 if (args->length() <= 0) {
870 d->warn(QStringLiteral(
"missing arguments"));
871 args->setReturnValue(QV4::Encode::null());
875 QV4::ExecutionEngine *v4 = args->v4engine();
876 QV4::Scope scope(v4);
878#if QT_CONFIG(quick_viewtransitions)
879 Operation operation = d->elements.isEmpty() ? Immediate : ReplaceTransition;
880 QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
881 if (lastArg->isInt32())
882 operation =
static_cast<Operation>(lastArg->toInt32());
885 QQuickStackElement *target =
nullptr;
886 QV4::ScopedValue firstArg(scope, (*args)[0]);
887 if (firstArg->isNull())
888 target = d->elements.value(0);
889 else if (!firstArg->isInt32())
890 target = d->findElement(firstArg);
893 QList<QQuickStackElement *> elements = d->parseElements(target ? 1 : 0, args, &errors);
894 if (!errors.isEmpty() || elements.isEmpty()) {
895 if (!errors.isEmpty()) {
896 for (
const QString &error : std::as_const(errors))
899 d->warn(QStringLiteral(
"nothing to push"));
901 args->setReturnValue(QV4::Encode::null());
905 int oldDepth = d->elements.size();
906 QQuickStackElement* exit =
nullptr;
907 if (!d->elements.isEmpty())
908 exit = d->elements.pop();
910 if (exit != target ? d->replaceElements(target, elements) : d->pushElements(elements)) {
911 d->depthChange(d->elements.size(), oldDepth);
913 exit->removal =
true;
914 d->removing.insert(exit);
916 QQuickStackElement *enter = d->elements.top();
917#if QT_CONFIG(quick_viewtransitions)
918 d->startTransition(QQuickStackTransition::replaceExit(operation, exit,
this),
919 QQuickStackTransition::replaceEnter(operation, enter,
this),
920 operation == Immediate);
922 d->setCurrentItem(enter);
925 if (d->currentItem) {
926 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem));
927 args->setReturnValue(rv->asReturnedValue());
929 args->setReturnValue(QV4::Encode::null());
934
935
936
937
938
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
985QQuickItem *QQuickStackView::pushItems(QList<QQuickStackViewArg> args, Operation operation)
987 Q_D(QQuickStackView);
988 const QString operationName = QStringLiteral(
"pushItem");
989 if (d->modifyingElements) {
990 d->warnOfInterruption(operationName);
994 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
995 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
997 const QList<QQuickStackElement *> stackElements = d->parseElements(args);
999#if QT_CONFIG(quick_viewtransitions)
1000 QQuickStackElement *exit =
nullptr;
1001 if (!d->elements.isEmpty())
1002 exit = d->elements.top();
1005 const int oldDepth = d->elements.size();
1006 if (d->pushElements(stackElements)) {
1007 d->depthChange(d->elements.size(), oldDepth);
1008 QQuickStackElement *enter = d->elements.top();
1009#if QT_CONFIG(quick_viewtransitions)
1010 d->startTransition(QQuickStackTransition::pushEnter(operation, enter,
this),
1011 QQuickStackTransition::pushExit(operation, exit,
this),
1012 operation == Immediate);
1014 d->setCurrentItem(enter);
1017 return d->currentItem;
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037QQuickItem *QQuickStackView::pushItem(QQuickItem *item,
const QVariantMap &properties, Operation operation)
1039 return pushItems({ item, properties }, operation);
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060QQuickItem *QQuickStackView::pushItem(QQmlComponent *component,
const QVariantMap &properties, Operation operation)
1062 return pushItems({ component, properties }, operation);
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083QQuickItem *QQuickStackView::pushItem(
const QUrl &url,
const QVariantMap &properties, Operation operation)
1085 return pushItems({ url, properties }, operation);
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109QQuickItem *QQuickStackView::popToItem(QQuickItem *item, Operation operation)
1111 Q_D(QQuickStackView);
1112 return d->popToItem(item, operation, QQuickStackViewPrivate::CurrentItemPolicy::DoNotPop);
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137QQuickItem *QQuickStackView::popToIndex(
int index, Operation operation)
1139 Q_D(QQuickStackView);
1140 if (index < 0 || index >= d->elements.size()) {
1141 d->warn(QString::fromLatin1(
"popToIndex: index %1 is out of bounds (%2 item(s))")
1142 .arg(index).arg(d->elements.size()));
1146 if (index == d->elements.size() - 1) {
1151 QQuickStackElement *element = d->elements.at(index);
1152 element->load(
this);
1153 return d->popToItem(element->item, operation, QQuickStackViewPrivate::CurrentItemPolicy::Pop);
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173QQuickItem *QQuickStackView::popCurrentItem(Operation operation)
1175 Q_D(QQuickStackView);
1176 if (d->elements.size() == 1) {
1177 auto lastItemRemoved = d->elements.last()->item;
1179 return lastItemRemoved;
1181 return d->popToItem(d->currentItem, operation, QQuickStackViewPrivate::CurrentItemPolicy::Pop);
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225QQuickItem *QQuickStackView::replaceCurrentItem(
const QList<QQuickStackViewArg> &args,
1226 Operation operation)
1228 Q_D(QQuickStackView);
1229 const QString operationName = QStringLiteral(
"replace");
1230 if (d->modifyingElements) {
1231 d->warnOfInterruption(operationName);
1235 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
1236 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1238 QQuickStackElement *currentElement = !d->elements.isEmpty() ? d->elements.top() :
nullptr;
1240 const QList<QQuickStackElement *> stackElements = d->parseElements(args);
1242 int oldDepth = d->elements.size();
1243 QQuickStackElement* exit =
nullptr;
1244 if (!d->elements.isEmpty())
1245 exit = d->elements.pop();
1247 const bool successfullyReplaced = exit != currentElement
1248 ? d->replaceElements(currentElement, stackElements)
1249 : d->pushElements(stackElements);
1250 if (successfullyReplaced) {
1251 d->depthChange(d->elements.size(), oldDepth);
1253 exit->removal =
true;
1254 d->removing.insert(exit);
1256 QQuickStackElement *enter = d->elements.top();
1257#if QT_CONFIG(quick_viewtransitions)
1258 d->startTransition(QQuickStackTransition::replaceExit(operation, exit,
this),
1259 QQuickStackTransition::replaceEnter(operation, enter,
this),
1260 operation == Immediate);
1262 d->setCurrentItem(enter);
1265 return d->currentItem;
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288QQuickItem *QQuickStackView::replaceCurrentItem(QQuickItem *item,
const QVariantMap &properties,
1289 Operation operation)
1291 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(item), QQuickStackViewArg(properties) };
1292 return replaceCurrentItem(args, operation);
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315QQuickItem *QQuickStackView::replaceCurrentItem(QQmlComponent *component,
const QVariantMap &properties,
1316 Operation operation)
1318 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(component), QQuickStackViewArg(properties) };
1319 return replaceCurrentItem(args, operation);
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342QQuickItem *QQuickStackView::replaceCurrentItem(
const QUrl &url,
const QVariantMap &properties,
1343 Operation operation)
1345 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(url), QQuickStackViewArg(properties) };
1346 return replaceCurrentItem(args, operation);
1350
1351
1352
1353
1354
1355
1356
1357
1358bool QQuickStackView::isEmpty()
const
1360 Q_D(
const QQuickStackView);
1361 return d->elements.isEmpty();
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378void QQuickStackView::clear(Operation operation)
1380#if !QT_CONFIG(quick_viewtransitions)
1383 Q_D(QQuickStackView);
1384 if (d->elements.isEmpty())
1387 const QString operationName = QStringLiteral(
"clear");
1388 if (d->modifyingElements) {
1389 d->warnOfInterruption(operationName);
1393 const int oldDepth = d->elements.size();
1395 QScopedValueRollback<
bool> modifyingElements(d->modifyingElements,
true);
1396 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1397#if QT_CONFIG(quick_viewtransitions)
1398 if (operation != Immediate) {
1399 QQuickStackElement *exit = d->elements.pop();
1400 exit->removal =
true;
1401 d->removing.insert(exit);
1402 d->startTransition(QQuickStackTransition::popExit(operation, exit,
this),
1403 QQuickStackTransition::popEnter(operation,
nullptr,
this),
false);
1407 d->setCurrentItem(
nullptr);
1408 qDeleteAll(d->elements);
1409 d->elements.clear();
1410 d->depthChange(0, oldDepth);
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425QJSValue QQuickStackView::initialItem()
const
1427 Q_D(
const QQuickStackView);
1428 return d->initialItem;
1431void QQuickStackView::setInitialItem(
const QJSValue &item)
1433 Q_D(QQuickStackView);
1434 d->initialItem = item;
1437#if QT_CONFIG(quick_viewtransitions)
1439
1440
1441
1442
1443
1444
1445
1446QQuickTransition *QQuickStackView::popEnter()
const
1448 Q_D(
const QQuickStackView);
1449 if (d->transitioner)
1450 return d->transitioner->removeDisplacedTransition;
1454void QQuickStackView::setPopEnter(QQuickTransition *enter)
1456 Q_D(QQuickStackView);
1457 d->ensureTransitioner();
1458 if (d->transitioner->removeDisplacedTransition == enter)
1461 d->transitioner->removeDisplacedTransition = enter;
1462 emit popEnterChanged();
1466
1467
1468
1469
1470
1471
1472
1473QQuickTransition *QQuickStackView::popExit()
const
1475 Q_D(
const QQuickStackView);
1476 if (d->transitioner)
1477 return d->transitioner->removeTransition;
1481void QQuickStackView::setPopExit(QQuickTransition *exit)
1483 Q_D(QQuickStackView);
1484 d->ensureTransitioner();
1485 if (d->transitioner->removeTransition == exit)
1488 d->transitioner->removeTransition = exit;
1489 emit popExitChanged();
1493
1494
1495
1496
1497
1498
1499
1500QQuickTransition *QQuickStackView::pushEnter()
const
1502 Q_D(
const QQuickStackView);
1503 if (d->transitioner)
1504 return d->transitioner->addTransition;
1508void QQuickStackView::setPushEnter(QQuickTransition *enter)
1510 Q_D(QQuickStackView);
1511 d->ensureTransitioner();
1512 if (d->transitioner->addTransition == enter)
1515 d->transitioner->addTransition = enter;
1516 emit pushEnterChanged();
1520
1521
1522
1523
1524
1525
1526
1527QQuickTransition *QQuickStackView::pushExit()
const
1529 Q_D(
const QQuickStackView);
1530 if (d->transitioner)
1531 return d->transitioner->addDisplacedTransition;
1535void QQuickStackView::setPushExit(QQuickTransition *exit)
1537 Q_D(QQuickStackView);
1538 d->ensureTransitioner();
1539 if (d->transitioner->addDisplacedTransition == exit)
1542 d->transitioner->addDisplacedTransition = exit;
1543 emit pushExitChanged();
1547
1548
1549
1550
1551
1552
1553
1554QQuickTransition *QQuickStackView::replaceEnter()
const
1556 Q_D(
const QQuickStackView);
1557 if (d->transitioner)
1558 return d->transitioner->moveTransition;
1562void QQuickStackView::setReplaceEnter(QQuickTransition *enter)
1564 Q_D(QQuickStackView);
1565 d->ensureTransitioner();
1566 if (d->transitioner->moveTransition == enter)
1569 d->transitioner->moveTransition = enter;
1570 emit replaceEnterChanged();
1574
1575
1576
1577
1578
1579
1580
1581QQuickTransition *QQuickStackView::replaceExit()
const
1583 Q_D(
const QQuickStackView);
1584 if (d->transitioner)
1585 return d->transitioner->moveDisplacedTransition;
1589void QQuickStackView::setReplaceExit(QQuickTransition *exit)
1591 Q_D(QQuickStackView);
1592 d->ensureTransitioner();
1593 if (d->transitioner->moveDisplacedTransition == exit)
1596 d->transitioner->moveDisplacedTransition = exit;
1597 emit replaceExitChanged();
1601void QQuickStackView::componentComplete()
1603 QQuickControl::componentComplete();
1605 Q_D(QQuickStackView);
1606 QScopedValueRollback<QString> operationNameRollback(d->operation, QStringLiteral(
"initialItem"));
1607 QQuickStackElement *element =
nullptr;
1609 int oldDepth = d->elements.size();
1610 if (QObject *o = d->initialItem.toQObject())
1611 element = QQuickStackElement::fromObject(o,
this, &error);
1612 else if (d->initialItem.isString())
1613 element = QQuickStackElement::fromString(d->initialItem.toString(),
this, &error);
1614 if (!error.isEmpty()) {
1617 }
else if (d->pushElement(element)) {
1618 d->depthChange(d->elements.size(), oldDepth);
1619 d->setCurrentItem(element);
1620 element->setStatus(QQuickStackView::Active);
1624void QQuickStackView::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
1626 QQuickControl::geometryChange(newGeometry, oldGeometry);
1628 Q_D(QQuickStackView);
1629 for (QQuickStackElement *element : std::as_const(d->elements)) {
1630 if (element->item) {
1631 if (!element->widthValid)
1632 element->item->setWidth(newGeometry.width());
1633 if (!element->heightValid)
1634 element->item->setHeight(newGeometry.height());
1639bool QQuickStackView::childMouseEventFilter(QQuickItem *item, QEvent *event)
1647 if (event->type() == QEvent::MouseButtonPress)
1649 if (event->type() == QEvent::UngrabMouse)
1651 QQuickWindow *window = item->window();
1652 return window && !window->mouseGrabberItem();
1655#if QT_CONFIG(quicktemplates2_multitouch)
1656void QQuickStackView::touchEvent(QTouchEvent *event)
1662#if QT_CONFIG(accessibility)
1663QAccessible::Role QQuickStackView::accessibleRole()
const
1665 return QAccessible::LayeredPane;
1671 Q_Q(QQuickStackViewAttached);
1672 int oldIndex = element ? element->index : -1;
1673 QQuickStackView *oldView = element ? element->view :
nullptr;
1674 QQuickStackView::Status oldStatus = element ? element->status : QQuickStackView::Inactive;
1676 QQuickStackView *newView = qobject_cast<QQuickStackView *>(parent);
1677 element = newView ? QQuickStackViewPrivate::get(newView)->findElement(item) :
nullptr;
1679 int newIndex = element ? element->index : -1;
1680 QQuickStackView::Status newStatus = element ? element->status : QQuickStackView::Inactive;
1682 if (oldIndex != newIndex)
1683 emit q->indexChanged();
1684 if (oldView != newView)
1685 emit q->viewChanged();
1686 if (oldStatus != newStatus)
1687 emit q->statusChanged();
1690QQuickStackViewAttached::QQuickStackViewAttached(QObject *parent)
1691 : QObject(*(
new QQuickStackViewAttachedPrivate), parent)
1693 Q_D(QQuickStackViewAttached);
1694 QQuickItem *item = qobject_cast<QQuickItem *>(parent);
1696 connect(item, &QQuickItem::visibleChanged,
this, &QQuickStackViewAttached::visibleChanged);
1697 QQuickItemPrivate::get(item)->addItemChangeListener(d, QQuickItemPrivate::Parent);
1698 d->itemParentChanged(item, item->parentItem());
1699 }
else if (parent) {
1700 qmlWarning(parent) <<
"StackView attached property must be attached to an object deriving from Item";
1704QQuickStackViewAttached::~QQuickStackViewAttached()
1706 Q_D(QQuickStackViewAttached);
1707 QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1709 QQuickItemPrivate::get(parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Parent);
1713
1714
1715
1716
1717
1718
1719int QQuickStackViewAttached::index()
const
1721 Q_D(
const QQuickStackViewAttached);
1722 return d->element ? d->element->index : -1;
1726
1727
1728
1729
1730
1731
1732QQuickStackView *QQuickStackViewAttached::view()
const
1734 Q_D(
const QQuickStackViewAttached);
1735 return d->element ? d->element->view :
nullptr;
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751QQuickStackView::Status QQuickStackViewAttached::status()
const
1753 Q_D(
const QQuickStackViewAttached);
1754 return d->element ? d->element->status : QQuickStackView::Inactive;
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778bool QQuickStackViewAttached::isVisible()
const
1780 const QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1781 return parentItem && parentItem->isVisible();
1784void QQuickStackViewAttached::setVisible(
bool visible)
1786 Q_D(QQuickStackViewAttached);
1787 d->explicitVisible =
true;
1788 QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1790 parentItem->setVisible(visible);
1793void QQuickStackViewAttached::resetVisible()
1795 Q_D(QQuickStackViewAttached);
1796 d->explicitVisible =
false;
1797 if (!d->element || !d->element->view)
1800 QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1802 parentItem->setVisible(parentItem == d->element->view->currentItem());
1806
1807
1808
1809
1810
1811
1812
1815
1816
1817
1818
1819
1820
1821
1824
1825
1826
1827
1828
1829
1830
1831
1834
1835
1836
1837
1838
1839
1840
1841
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1862#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.