Kirigami2

pagerouter.h
1 /*
2  * SPDX-FileCopyrightText: 2020 Carson Black <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 #pragma once
8 
9 #include "columnview.h"
10 #include <QCache>
11 #include <QQmlPropertyMap>
12 #include <QQuickItem>
13 #include <QRandomGenerator>
14 
15 static std::map<quint32, QVariant> s_knownVariants;
16 class PageRouter;
17 
18 class ParsedRoute : public QObject
19 {
20  Q_OBJECT
21 
22 public:
23  QString name;
24  QVariant data;
25  QVariantMap properties;
26  bool cache;
27  QQuickItem *item = nullptr;
28  void itemDestroyed()
29  {
30  item = nullptr;
31  }
32  QQuickItem *setItem(QQuickItem *newItem)
33  {
34  auto ret = item;
35  if (ret != nullptr) {
36  disconnect(ret, &QObject::destroyed, this, &ParsedRoute::itemDestroyed);
37  }
38  item = newItem;
39  if (newItem != nullptr) {
40  connect(newItem, &QObject::destroyed, this, &ParsedRoute::itemDestroyed);
41  }
42  return ret;
43  }
44  explicit ParsedRoute(const QString &name = QString(),
45  QVariant data = QVariant(),
46  QVariantMap properties = QVariantMap(),
47  bool cache = false,
48  QQuickItem *item = nullptr)
49  : name(name)
50  , data(data)
52  , cache(cache)
53  {
54  setItem(item);
55  }
56  ~ParsedRoute() override
57  {
58  if (item) {
59  item->deleteLater();
60  }
61  }
62  quint32 hash()
63  {
64  for (auto i = s_knownVariants.begin(); i != s_knownVariants.end(); i++) {
65  if (i->second == data) {
66  return i->first;
67  }
68  }
70  while (s_knownVariants.count(number) > 0) {
72  }
73  s_knownVariants[number] = data;
74  return number;
75  }
76  bool equals(const ParsedRoute *rhs, bool countItem = false)
77  {
78  /* clang-format off */
79  return name == rhs->name
80  && data == rhs->data
81  && (!countItem || item == rhs->item)
82  && cache == rhs->cache;
83  /* clang-format on */
84  }
85 };
86 
87 struct LRU {
88  int size = 10;
89  QList<QPair<QString, quint32>> evictionList;
90  QMap<QPair<QString, quint32>, int> costs;
91  QMap<QPair<QString, quint32>, ParsedRoute *> items;
92 
93  ParsedRoute *take(QPair<QString, quint32> key)
94  {
95  auto ret = items.take(key);
96  evictionList.removeAll(key);
97  return ret;
98  }
99  int totalCosts()
100  {
101  int ret = 0;
102  for (auto cost : std::as_const(costs)) {
103  ret += cost;
104  }
105  return ret;
106  }
107  void setSize(int size = 10)
108  {
109  this->size = size;
110  prune();
111  }
112  void prune()
113  {
114  while (size < totalCosts()) {
115  auto key = evictionList.last();
116  auto item = items.take(key);
117  delete item;
118  costs.take(key);
119  evictionList.takeLast();
120  }
121  }
122  void insert(QPair<QString, quint32> key, ParsedRoute *newItem, int cost)
123  {
124  if (items.contains(key)) {
125  auto item = items.take(key);
126  evictionList.removeAll(key);
127  if (item != newItem) {
128  delete item;
129  }
130  }
131  costs[key] = cost;
132  items[key] = newItem;
133  evictionList.prepend(key);
134  prune();
135  }
136 };
137 
138 class PageRouterAttached;
139 
140 /**
141  * Item holding data about when to preload a route.
142  *
143  * @code{.qml}
144  * preload {
145  * route: "updates-page"
146  * when: updatesCount > 0
147  * }
148  * @endcode
149  */
151 {
152  Q_OBJECT
153 
154  /**
155  * @brief The route to preload.
156  *
157  * When the condition is false, the route will not be preloaded.
158  */
159  Q_PROPERTY(QJSValue route MEMBER m_route WRITE setRoute NOTIFY changed)
160  QJSValue m_route;
161 
162  /**
163  * @brief When the route should be preloaded.
164  *
165  * When the condition is false, the route will not be preloaded.
166  */
167  Q_PROPERTY(bool when MEMBER m_when NOTIFY changed)
168  bool m_when;
169 
170  void handleChange();
171  PageRouterAttached *m_parent;
172 
173 public:
174  ~PreloadRouteGroup() override;
175  void setRoute(QJSValue route)
176  {
177  m_route = route;
178  Q_EMIT changed();
179  }
181  : QObject(parent)
182  {
183  m_parent = qobject_cast<PageRouterAttached *>(parent);
184  Q_ASSERT(m_parent);
185  connect(this, &PreloadRouteGroup::changed, this, &PreloadRouteGroup::handleChange);
186  }
187  Q_SIGNAL void changed();
188 };
189 
190 /**
191  * Item representing a route the PageRouter can navigate to.
192  *
193  * @include PageRoute.qml
194  *
195  * @see PageRouter
196  */
197 class PageRoute : public QObject
198 {
199  Q_OBJECT
200 
201  /**
202  * @brief The name of this route.
203  *
204  * This name should be unique per PageRoute in a PageRouter.
205  * When two PageRoutes have the same name, the one listed first
206  * in the PageRouter will be used.
207  */
208  Q_PROPERTY(QString name MEMBER m_name READ name)
209 
210  /**
211  * @brief The page component of this route.
212  *
213  * This should be an instance of Component with a Kirigami::Page inside
214  * of it.
215  */
216  Q_PROPERTY(QQmlComponent *component MEMBER m_component READ component)
217 
218  /**
219  * @brief Whether pages generated by this route should be cached or not.
220  *
221  * This should be an instance of Component with a Kirigami::Page inside
222  * of it.
223  *
224  * This will not work:
225  *
226  * @include PageRouterCachePagesDont.qml
227  *
228  * This will work:
229  *
230  * @include PageRouterCachePagesDo.qml
231  *
232  */
233  Q_PROPERTY(bool cache MEMBER m_cache READ cache)
234 
235  /**
236  * @brief How expensive this route is on memory.
237  *
238  * This affects caching, as the sum of costs of routes in the cache
239  * can never exceed the cache's cap.
240  */
241  Q_PROPERTY(int cost MEMBER m_cost)
242 
243  Q_CLASSINFO("DefaultProperty", "component")
244 
245 Q_SIGNALS:
246  void preloadDataChanged();
247  void preloadChanged();
248 
249 private:
250  QString m_name;
251  QQmlComponent *m_component = nullptr;
252  bool m_cache = false;
253  int m_cost = 1;
254 
255 public:
257  {
258  return m_component;
259  };
260  QString name()
261  {
262  return m_name;
263  };
264  bool cache()
265  {
266  return m_cache;
267  };
268  int cost()
269  {
270  return m_cost;
271  };
272 };
273 
274 /**
275  * An item managing pages and data of a ColumnView using named routes.
276  *
277  * <br> <br>
278  *
279  * ## Using a PageRouter
280  *
281  * Applications typically manage their contents via elements called "pages" or "screens."
282  * In Kirigami, these are called @link org::kde::kirigami::Page Pages @endlink and are
283  * arranged in @link PageRoute routes @endlink using a PageRouter to manage them. The PageRouter
284  * manages a stack of @link org::kde::kirigami::Page Pages @endlink created from a pool of potential
285  * @link PageRoute PageRoutes @endlink.
286  *
287  * Unlike most traditional stacks, a PageRouter provides functions for random access to its pages
288  * with navigateToRoute and routeActive.
289  *
290  * When your user interface fits the stack paradigm and is likely to use random access navigation,
291  * using the PageRouter is appropriate. For simpler navigation, it is more appropriate to avoid
292  * the overhead of a PageRouter by using a @link org::kde::kirigami::PageRow PageRow @endlink
293  * instead.
294  *
295  * <br> <br>
296  *
297  * ## Navigation Model
298  *
299  * A PageRouter draws from a pool of @link PageRoute PageRoutes @endlink in order to construct
300  * its stack.
301  *
302  * @image html PageRouterModel.svg width=50%
303  *
304  * <br> <br>
305  *
306  * You can push pages onto this stack...
307  *
308  * @image html PageRouterPush.svg width=50%
309  *
310  * ...or pop them off...
311  *
312  * @image html PageRouterPop.svg width=50%
313  *
314  * ...or navigate to an arbitrary collection of pages.
315  *
316  * @image html PageRouterNavigate.svg width=50%
317  *
318  * <br> <br>
319  *
320  * Components are able to query the PageRouter about the currently active routes
321  * on the stack. This is useful for e.g. a card indicating that the page it takes
322  * the user to is currently active.
323  *
324  * <br> <br>
325  *
326  * ## Example
327  *
328  * @include PageRouter.qml
329  *
330  * @see PageRouterAttached
331  * @see PageRoute
332  */
333 class PageRouter : public QObject, public QQmlParserStatus
334 {
335  Q_OBJECT
337 
338  /**
339  * @brief The named routes a PageRouter can navigate to.
340  *
341  * @include PageRouterRoutes.qml
342  */
344 
345  Q_CLASSINFO("DefaultProperty", "routes")
346 
347  /**
348  * @brief The initial route.
349  *
350  * `initialRoute` is the page that the PageRouter will push upon
351  * creation. Changing it after creation will cause the PageRouter to reset
352  * its state. Not providing an `initialRoute` will result in undefined
353  * behavior.
354  *
355  * @include PageRouterInitialRoute.qml
356  */
357  Q_PROPERTY(QJSValue initialRoute READ initialRoute WRITE setInitialRoute NOTIFY initialRouteChanged)
358 
359  /**
360  * @brief The ColumnView being puppeted by the PageRouter.
361  *
362  * All PageRouters should be created with a ColumnView, and creating one without
363  * a ColumnView is undefined behaviour.
364  *
365  * @warning You should **not** directly interact with a ColumnView being puppeted
366  * by a PageRouter. Instead, use a PageRouter's functions to manipulate the
367  * ColumnView.
368  *
369  * @include PageRouterColumnView.qml
370  */
371  Q_PROPERTY(ColumnView *pageStack MEMBER m_pageStack NOTIFY pageStackChanged)
372 
373  /**
374  * @brief How large the cache can be.
375  *
376  * The combined costs of cached routes will never exceed the cache capacity.
377  */
378  Q_PROPERTY(int cacheCapacity READ cacheCapacity WRITE setCacheCapacity)
379 
380  /**
381  * @brief How large the preloaded pool can be.
382  *
383  * The combined costs of preloaded routes will never exceed the pool capacity.
384  */
385  Q_PROPERTY(int preloadedPoolCapacity READ preloadedPoolCapacity WRITE setPreloadedPoolCapacity)
386 
387  /**
388  * Exposes the data of all pages on the stack, preferring pages on the top
389  * (e.g. most recently pushed) to pages pushed on the bottom (least recently
390  * pushed).
391  */
393 
394 private:
395  /**
396  * The map exposing to QML all the params of the stack. This is a
397  * QQmlPropertyMap to allow binding to param values. This *does* lack
398  * the ability to drop items, but the amount of all params in an app
399  * is overwhelmingly likely to be fixed, not dynamic.
400  */
401  QSharedPointer<QQmlPropertyMap> m_paramMap;
402 
403  /**
404  * Reevaluate the properties of the param map by going through all of the
405  * routes on the stack to determine the topmost value for every parametre.
406  *
407  * Should be called for every time a route is pushed, popped, or modified.
408  */
409  void reevaluateParamMapProperties();
410 
411  /**
412  * @brief The routes the PageRouter is aware of.
413  *
414  * Generally, this should not be mutated from C++, only read.
415  */
416  QList<PageRoute *> m_routes;
417 
418  /**
419  * @brief The PageRouter being puppeted.
420  *
421  * m_pageRow is the ColumnView this PageRouter puppets.
422  */
423  ColumnView *m_pageStack = nullptr;
424 
425  /**
426  * @brief The route that the PageRouter will load on completion.
427  *
428  * m_initialRoute is the raw QJSValue from QML that will be
429  * parsed into a ParsedRoute struct on construction.
430  * Generally, this should not be mutated from C++, only read.
431  */
432  QJSValue m_initialRoute;
433 
434  /**
435  * @brief The current routes pushed on the PageRow.
436  *
437  * Generally, the state of m_pageRow and m_currentRoutes
438  * should be kept in sync. Undesirable behaviour will result
439  * from desynchronisation of the two.
440  */
441  QList<ParsedRoute *> m_currentRoutes;
442 
443  /**
444  * @brief Cached routes.
445  *
446  * An LRU cache of ParsedRoutes with items that were previously on the stack.
447  */
448  LRU m_cache;
449 
450  /** @brief Preloaded routes.
451  *
452  * A LRU cache of ParsedRoutes with items that may be on the stack in the future,
453  * but were not on the stack before.
454  */
455  LRU m_preload;
456 
457  /**
458  * @brief Helper function to push a route.
459  *
460  * This function has the shared logic between
461  * navigateToRoute and pushRoute.
462  */
463  void push(ParsedRoute *route);
464 
465  /**
466  * @brief Helper function to access whether m_routes has a key.
467  *
468  * This function abstracts the QJSValue.
469  */
470  bool routesContainsKey(const QString &key) const;
471 
472  /**
473  * @brief Helper function to access the component of a key for m_routes.
474  *
475  * The return value will be a nullptr if @p key does not exist in
476  * m_routes.
477  */
478  QQmlComponent *routesValueForKey(const QString &key) const;
479 
480  /**
481  * @brief Helper function to access the cache status of a key for m_routes.
482  *
483  * The return value will be false if @p key does not exist in
484  * m_routes.
485  */
486  bool routesCacheForKey(const QString &key) const;
487 
488  /**
489  * @brief Helper function to access the cost of a key for m_routes.
490  *
491  * The return value will be -1 if @p key does not exist in
492  * m_routes.
493  */
494  int routesCostForKey(const QString &key) const;
495 
496  void preload(ParsedRoute *route);
497  void unpreload(ParsedRoute *route);
498 
499  void placeInCache(ParsedRoute *route);
500 
501  static void appendRoute(QQmlListProperty<PageRoute> *list, PageRoute *);
502 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
503  static int routeCount(QQmlListProperty<PageRoute> *list);
504  static PageRoute *route(QQmlListProperty<PageRoute> *list, int);
505 #else
506  static qsizetype routeCount(QQmlListProperty<PageRoute> *list);
507  static PageRoute *route(QQmlListProperty<PageRoute> *list, qsizetype);
508 #endif
509  static void clearRoutes(QQmlListProperty<PageRoute> *list);
510 
511  QVariant dataFor(QObject *object);
512  bool isActive(QObject *object);
513  void pushFromObject(QObject *object, QJSValue route, bool replace = false);
514 
515  friend class PageRouterAttached;
516  friend class PreloadRouteGroup;
517  friend class ParsedRoute;
518 
519 protected:
520  void classBegin() override;
521  void componentComplete() override;
522 
523 public:
524  PageRouter(QQuickItem *parent = nullptr);
525  ~PageRouter() override;
526 
528 
530  {
531  return m_paramMap.data();
532  }
533 
534  QJSValue initialRoute() const;
535  void setInitialRoute(QJSValue initialRoute);
536 
537  int cacheCapacity() const
538  {
539  return m_cache.size;
540  };
541  void setCacheCapacity(int size)
542  {
543  m_cache.setSize(size);
544  };
545 
546  int preloadedPoolCapacity() const
547  {
548  return m_preload.size;
549  };
550  void setPreloadedPoolCapacity(int size)
551  {
552  m_preload.setSize(size);
553  };
554 
555  /**
556  * @brief Navigate to the given route.
557  *
558  * Calling `navigateToRoute` causes the PageRouter to replace currently
559  * active pages with the new route.
560  *
561  * @param route The given route for the PageRouter to navigate to.
562  * A route is an array of variants or a single item. A string item will be interpreted
563  * as a page without associated data. An object item will be interpreted
564  * as follows:
565  * @code{.js}
566  * {
567  * "route": "/home" // The named page of the route.
568  * "data": QtObject {} // The data to pass to the page.
569  * }
570  * @endcode
571  * Navigating to a route not defined in a PageRouter's routes is undefined
572  * behavior.
573  *
574  * @code{.qml}
575  * Button {
576  * text: "Login"
577  * onClicked: {
578  * Kirigami.PageRouter.navigateToRoute(["/home", "/login"])
579  * }
580  * }
581  * @endcode
582  */
584 
585  /**
586  * @brief Check whether the current route is on the stack.
587  *
588  * `routeActive` will return true if the given route
589  * is on the stack.
590  *
591  * @param route The given route to check for.
592  *
593  * `routeActive` returns true for partial routes like
594  * the following:
595  *
596  * @code{.js}
597  * Kirigami.PageRouter.navigateToRoute(["/home", "/login", "/google"])
598  * Kirigami.PageRouter.routeActive(["/home", "/login"]) // returns true
599  * @endcode
600  *
601  * This only works from the root page, e.g. the following will return false:
602  * @code{.js}
603  * Kirigami.PageRouter.navigateToRoute(["/home", "/login", "/google"])
604  * Kirigami.PageRouter.routeActive(["/login", "/google"]) // returns false
605  * @endcode
606  */
607  Q_INVOKABLE bool routeActive(QJSValue route);
608 
609  /**
610  * @brief Appends a route to the currently navigated route.
611  *
612  * Calling `pushRoute` will append the given @p route to the currently navigated
613  * routes. See navigateToRoute() if you want to replace the items currently on
614  * the PageRouter.
615  *
616  * @param route The given route to push.
617  *
618  * @code{.js}
619  * Kirigami.PageRouter.navigateToRoute(["/home", "/login"])
620  * // The PageRouter is navigated to /home/login
621  * Kirigami.PageRouter.pushRoute("/google")
622  * // The PageRouter is navigated to /home/login/google
623  * @endcode
624  */
625  Q_INVOKABLE void pushRoute(QJSValue route);
626 
627  /**
628  * @brief Pops the last page on the router.
629  *
630  * Calling `popRoute` will result in the last page on the router getting popped.
631  * You should not call this function when there is only one page on the router.
632  *
633  * @code{.js}
634  * Kirigami.PageRouter.navigateToRoute(["/home", "/login"])
635  * // The PageRouter is navigated to /home/login
636  * Kirigami.PageRouter.popRoute()
637  * // The PageRouter is navigated to /home
638  * @endcode
639  */
640  Q_INVOKABLE void popRoute();
641 
642  /**
643  * @brief Shifts keyboard focus and view to a given index on the PageRouter's stack.
644  *
645  * @param view The view to bring to focus. If this is an integer index, the PageRouter will
646  * navigate to the given index. If it's a route specifier, the PageRouter will navigate
647  * to the first route matching it.
648  *
649  * Navigating to route by index:
650  * @code{.js}
651  * Kirigami.PageRouter.navigateToRoute(["/home", "/browse", "/apps", "/login"])
652  * Kirigami.PageRouter.bringToView(1)
653  * @endcode
654  *
655  * Navigating to route by name:
656  * @code{.js}
657  * Kirigami.PageRouter.navigateToRoute(["/home", "/browse", "/apps", "/login"])
658  * Kirigami.PageRouter.bringToView("/browse")
659  * @endcode
660  *
661  * Navigating to route by data:
662  * @code{.js}
663  * Kirigami.PageRouter.navigateToRoute([{"route": "/page", "data": "red"},
664  * {"route": "/page", "data": "blue"},
665  * {"route": "/page", "data": "green"},
666  * {"route": "/page", "data": "yellow"}])
667  * Kirigami.PageRouter.bringToView({"route": "/page", "data": "blue"})
668  * @endcode
669  */
670  Q_INVOKABLE void bringToView(QJSValue route);
671 
672  /**
673  * @brief Returns a QJSValue corresponding to the current pages on the stack.
674  *
675  * The returned value is in the same form as the input to navigateToRoute.
676  */
678 
679  static PageRouterAttached *qmlAttachedProperties(QObject *object);
680 
681 Q_SIGNALS:
682  void routesChanged();
683  void initialRouteChanged();
684  void pageStackChanged();
685  void currentIndexChanged();
686  void navigationChanged();
687 };
688 
689 /**
690  * Attached object allowing children of a PageRouter to access its functions
691  * without requiring the children to have the parent PageRouter's id.
692  *
693  * @see PageRouter
694  */
696 {
697  Q_OBJECT
698 
699  Q_PROPERTY(PageRouter *router READ router WRITE setRouter NOTIFY routerChanged)
700  /**
701  * The data for the page this item belongs to. Accessing this property
702  * outside of a PageRouter will result in undefined behavior.
703  */
704  Q_PROPERTY(QVariant data READ data MEMBER m_data NOTIFY dataChanged)
705 
706  /**
707  * Whether the page this item belongs to is the current index of the ColumnView.
708  * Accessing this property outside of a PageRouter will result in undefined behaviour.
709  */
710  Q_PROPERTY(bool isCurrent READ isCurrent NOTIFY isCurrentChanged)
711 
712  /**
713  * Which route this PageRouterAttached should watch for.
714  *
715  * @include PageRouterWatchedRoute.qml
716  */
717  Q_PROPERTY(QJSValue watchedRoute READ watchedRoute WRITE setWatchedRoute NOTIFY watchedRouteChanged)
718 
719  /**
720  * Route preloading settings.
721  */
723 
724  /**
725  * Whether the watchedRoute is currently active.
726  */
727  Q_PROPERTY(bool watchedRouteActive READ watchedRouteActive NOTIFY navigationChanged)
728 
729 private:
730  explicit PageRouterAttached(QObject *parent = nullptr);
731 
732  QPointer<PageRouter> m_router;
733  PreloadRouteGroup *m_preload;
734  QVariant m_data;
735  QJSValue m_watchedRoute;
736 
737  void findParent();
738 
739  friend class PageRouter;
740  friend class PreloadRouteGroup;
741  friend class ParsedRoute;
742 
743 public:
744  PreloadRouteGroup *preload() const
745  {
746  return m_preload;
747  };
748  PageRouter *router() const
749  {
750  return m_router;
751  };
752  void setRouter(PageRouter *router)
753  {
754  m_router = router;
755  Q_EMIT routerChanged();
756  }
757  QVariant data() const;
758  bool isCurrent() const;
759  /// @see PageRouter::navigateToRoute()
761  /// @see PageRouter::routeActive()
762  Q_INVOKABLE bool routeActive(QJSValue route);
763  /// @see PageRouter::pushRoute()
764  Q_INVOKABLE void pushRoute(QJSValue route);
765  /// @see PageRouter::popRoute()
766  Q_INVOKABLE void popRoute();
767  // @see PageRouter::bringToView()
768  Q_INVOKABLE void bringToView(QJSValue route);
769  /**
770  * @brief Push a route from this route on the stack.
771  *
772  * Replace the routes after the route this is invoked on
773  * with the provided @p route.
774  *
775  * For example, if you invoke this method on the second route
776  * in the PageRouter's stack, routes after the second
777  * route will be replaced with the provided routes.
778  */
779  Q_INVOKABLE void pushFromHere(QJSValue route);
780  /**
781  * @brief Pop routes after this route on the stack.
782  *
783  * Pop the routes after the route this is invoked on with
784  * the provided @p route.
785  *
786  * For example, if you invoke this method on the second route
787  * in the PageRouter's stack, routes after the second route
788  * will be removed from the stack.
789  */
790  Q_INVOKABLE void popFromHere();
791  /**
792  * @brief Replaces this route with the given routes on the stack.
793  *
794  * Behaves like pushFromHere, except the current route is also
795  * popped.
796  */
798  bool watchedRouteActive();
799  void setWatchedRoute(QJSValue route);
801 
802 Q_SIGNALS:
803  void routerChanged();
804  void dataChanged();
805  void isCurrentChanged();
806  void navigationChanged();
807  void watchedRouteChanged();
808 };
809 
810 QML_DECLARE_TYPEINFO(PageRouter, QML_HAS_ATTACHED_PROPERTIES)
bool watchedRouteActive
Whether the watchedRoute is currently active.
Definition: pagerouter.h:727
Q_OBJECTQ_OBJECT
QVariant data
The data for the page this item belongs to.
Definition: pagerouter.h:704
Q_PROPERTY(...)
Q_INVOKABLE bool routeActive(QJSValue route)
Check whether the current route is on the stack.
Definition: pagerouter.cpp:342
Q_INVOKABLE void pushRoute(QJSValue route)
Appends a route to the currently navigated route.
Definition: pagerouter.cpp:361
bool contains(const Key &key) const const
QQmlPropertyMap params
Exposes the data of all pages on the stack, preferring pages on the top (e.g.
Definition: pagerouter.h:392
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
T take(const Key &key)
Q_INVOKABLE void replaceFromHere(QJSValue route)
Replaces this route with the given routes on the stack.
Definition: pagerouter.cpp:684
Q_EMITQ_EMIT
ColumnView pageStack
The ColumnView being puppeted by the PageRouter.
Definition: pagerouter.h:371
int removeAll(const T &value)
Q_CLASSINFO(Name, Value)
Q_INVOKABLE void navigateToRoute(QJSValue route)
Navigate to the given route.
Definition: pagerouter.cpp:277
Item holding data about when to preload a route.
Definition: pagerouter.h:150
KGuiItem properties()
Q_SIGNALQ_SIGNAL
PreloadRouteGroup preload
Route preloading settings.
Definition: pagerouter.h:722
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString name
The name of this route.
Definition: pagerouter.h:208
ColumnView is a container that lays out items horizontally in a row, when not all items fit in the Co...
Definition: columnview.h:147
void destroyed(QObject *obj)
void deleteLater()
void prepend(const T &value)
Item representing a route the PageRouter can navigate to.
Definition: pagerouter.h:197
QQmlComponent component
The page component of this route.
Definition: pagerouter.h:216
bool isCurrent
Whether the page this item belongs to is the current index of the ColumnView.
Definition: pagerouter.h:710
bool when
When the route should be preloaded.
Definition: pagerouter.h:167
QJSValue watchedRoute
Which route this PageRouterAttached should watch for.
Definition: pagerouter.h:717
Q_INVOKABLE void pushRoute(QJSValue route)
Definition: pagerouter.cpp:604
Q_INVOKABLE void pushFromHere(QJSValue route)
Push a route from this route on the stack.
Definition: pagerouter.cpp:675
Q_INVOKABLE void popRoute()
Definition: pagerouter.cpp:614
int preloadedPoolCapacity
How large the preloaded pool can be.
Definition: pagerouter.h:385
bool cache
Whether pages generated by this route should be cached or not.
Definition: pagerouter.h:233
Q_INVOKABLE bool routeActive(QJSValue route)
Definition: pagerouter.cpp:594
Q_INVOKABLEQ_INVOKABLE
Q_INVOKABLE void bringToView(QJSValue route)
Shifts keyboard focus and view to a given index on the PageRouter's stack.
Definition: pagerouter.cpp:323
Q_INVOKABLE QJSValue currentRoutes() const
Returns a QJSValue corresponding to the current pages on the stack.
Definition: pagerouter.cpp:751
QQmlListProperty< PageRoute > routes
The named routes a PageRouter can navigate to.
Definition: pagerouter.h:343
T & last()
Q_SIGNALSQ_SIGNALS
KGuiItem insert()
Q_INTERFACES(...)
quint32 generate()
An item managing pages and data of a ColumnView using named routes.
Definition: pagerouter.h:333
QString name(StandardShortcut id)
QRandomGenerator * system()
QJSValue route
The route to preload.
Definition: pagerouter.h:159
KIOCORE_EXPORT QString number(KIO::filesize_t size)
int cost
How expensive this route is on memory.
Definition: pagerouter.h:241
Q_INVOKABLE void popFromHere()
Pop routes after this route on the stack.
Definition: pagerouter.cpp:693
Q_INVOKABLE void popRoute()
Pops the last page on the router.
Definition: pagerouter.cpp:367
QJSValue initialRoute
The initial route.
Definition: pagerouter.h:357
Attached object allowing children of a PageRouter to access its functions without requiring the child...
Definition: pagerouter.h:695
T takeLast()
QObject * parent() const const
int cacheCapacity
How large the cache can be.
Definition: pagerouter.h:378
Q_INVOKABLE void navigateToRoute(QJSValue route)
Definition: pagerouter.cpp:584
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 04:10:27 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.