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  * @see org::kde::kirigami::PageRoute::name
356  * @include PageRouterInitialRoute.qml
357  */
358  Q_PROPERTY(QJSValue initialRoute READ initialRoute WRITE setInitialRoute NOTIFY initialRouteChanged)
359 
360  /**
361  * @brief The ColumnView being puppeted by the PageRouter.
362  *
363  * All PageRouters should be created with a ColumnView, and creating one without
364  * a ColumnView is undefined behaviour.
365  *
366  * @warning You should **not** directly interact with a ColumnView being puppeted
367  * by a PageRouter. Instead, use a PageRouter's functions to manipulate the
368  * ColumnView.
369  *
370  * @include PageRouterColumnView.qml
371  */
372  Q_PROPERTY(ColumnView *pageStack MEMBER m_pageStack NOTIFY pageStackChanged)
373 
374  /**
375  * @brief How large the cache can be.
376  *
377  * The combined costs of cached routes will never exceed the cache capacity.
378  */
379  Q_PROPERTY(int cacheCapacity READ cacheCapacity WRITE setCacheCapacity)
380 
381  /**
382  * @brief How large the preloaded pool can be.
383  *
384  * The combined costs of preloaded routes will never exceed the pool capacity.
385  */
386  Q_PROPERTY(int preloadedPoolCapacity READ preloadedPoolCapacity WRITE setPreloadedPoolCapacity)
387 
388  /**
389  * Exposes the data of all pages on the stack, preferring pages on the top
390  * (e.g. most recently pushed) to pages pushed on the bottom (least recently
391  * pushed).
392  */
394 
395 private:
396  /**
397  * The map exposing to QML all the params of the stack. This is a
398  * QQmlPropertyMap to allow binding to param values. This *does* lack
399  * the ability to drop items, but the amount of all params in an app
400  * is overwhelmingly likely to be fixed, not dynamic.
401  */
402  QSharedPointer<QQmlPropertyMap> m_paramMap;
403 
404  /**
405  * Reevaluate the properties of the param map by going through all of the
406  * routes on the stack to determine the topmost value for every parametre.
407  *
408  * Should be called for every time a route is pushed, popped, or modified.
409  */
410  void reevaluateParamMapProperties();
411 
412  /**
413  * @brief The routes the PageRouter is aware of.
414  *
415  * Generally, this should not be mutated from C++, only read.
416  */
417  QList<PageRoute *> m_routes;
418 
419  /**
420  * @brief The PageRouter being puppeted.
421  *
422  * m_pageRow is the ColumnView this PageRouter puppets.
423  */
424  ColumnView *m_pageStack = nullptr;
425 
426  /**
427  * @brief The route that the PageRouter will load on completion.
428  *
429  * m_initialRoute is the raw QJSValue from QML that will be
430  * parsed into a ParsedRoute struct on construction.
431  * Generally, this should not be mutated from C++, only read.
432  */
433  QJSValue m_initialRoute;
434 
435  /**
436  * @brief The current routes pushed on the PageRow.
437  *
438  * Generally, the state of m_pageRow and m_currentRoutes
439  * should be kept in sync. Undesirable behaviour will result
440  * from desynchronisation of the two.
441  */
442  QList<ParsedRoute *> m_currentRoutes;
443 
444  /**
445  * @brief Cached routes.
446  *
447  * An LRU cache of ParsedRoutes with items that were previously on the stack.
448  */
449  LRU m_cache;
450 
451  /** @brief Preloaded routes.
452  *
453  * A LRU cache of ParsedRoutes with items that may be on the stack in the future,
454  * but were not on the stack before.
455  */
456  LRU m_preload;
457 
458  /**
459  * @brief Helper function to push a route.
460  *
461  * This function has the shared logic between
462  * navigateToRoute and pushRoute.
463  */
464  void push(ParsedRoute *route);
465 
466  /**
467  * @brief Helper function to access whether m_routes has a key.
468  *
469  * This function abstracts the QJSValue.
470  */
471  bool routesContainsKey(const QString &key) const;
472 
473  /**
474  * @brief Helper function to access the component of a key for m_routes.
475  *
476  * The return value will be a nullptr if @p key does not exist in
477  * m_routes.
478  */
479  QQmlComponent *routesValueForKey(const QString &key) const;
480 
481  /**
482  * @brief Helper function to access the cache status of a key for m_routes.
483  *
484  * The return value will be false if @p key does not exist in
485  * m_routes.
486  */
487  bool routesCacheForKey(const QString &key) const;
488 
489  /**
490  * @brief Helper function to access the cost of a key for m_routes.
491  *
492  * The return value will be -1 if @p key does not exist in
493  * m_routes.
494  */
495  int routesCostForKey(const QString &key) const;
496 
497  void preload(ParsedRoute *route);
498  void unpreload(ParsedRoute *route);
499 
500  void placeInCache(ParsedRoute *route);
501 
502  static void appendRoute(QQmlListProperty<PageRoute> *list, PageRoute *);
503 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
504  static int routeCount(QQmlListProperty<PageRoute> *list);
505  static PageRoute *route(QQmlListProperty<PageRoute> *list, int);
506 #else
507  static qsizetype routeCount(QQmlListProperty<PageRoute> *list);
508  static PageRoute *route(QQmlListProperty<PageRoute> *list, qsizetype);
509 #endif
510  static void clearRoutes(QQmlListProperty<PageRoute> *list);
511 
512  QVariant dataFor(QObject *object);
513  bool isActive(QObject *object);
514  void pushFromObject(QObject *object, QJSValue route, bool replace = false);
515 
516  friend class PageRouterAttached;
517  friend class PreloadRouteGroup;
518  friend class ParsedRoute;
519 
520 protected:
521  void classBegin() override;
522  void componentComplete() override;
523 
524 public:
525  PageRouter(QQuickItem *parent = nullptr);
526  ~PageRouter() override;
527 
529 
531  {
532  return m_paramMap.data();
533  }
534 
535  QJSValue initialRoute() const;
536  void setInitialRoute(QJSValue initialRoute);
537 
538  int cacheCapacity() const
539  {
540  return m_cache.size;
541  };
542  void setCacheCapacity(int size)
543  {
544  m_cache.setSize(size);
545  };
546 
547  int preloadedPoolCapacity() const
548  {
549  return m_preload.size;
550  };
551  void setPreloadedPoolCapacity(int size)
552  {
553  m_preload.setSize(size);
554  };
555 
556  /**
557  * @brief Navigate to the given route.
558  *
559  * Calling `navigateToRoute` causes the PageRouter to replace currently
560  * active pages with the new route.
561  *
562  * @param route The given route for the PageRouter to navigate to.
563  * A route is an array of variants or a single item. A string item will be interpreted
564  * as a page without associated data. An object item will be interpreted
565  * as follows:
566  * @code{.js}
567  * {
568  * "route": "/home" // The named page of the route.
569  * "data": QtObject {} // The data to pass to the page.
570  * }
571  * @endcode
572  * Navigating to a route not defined in a PageRouter's routes is undefined
573  * behavior.
574  *
575  * @code{.qml}
576  * Button {
577  * text: "Login"
578  * onClicked: {
579  * Kirigami.PageRouter.navigateToRoute(["/home", "/login"])
580  * }
581  * }
582  * @endcode
583  */
585 
586  /**
587  * @brief Check whether the current route is on the stack.
588  *
589  * `routeActive` will return true if the given route
590  * is on the stack.
591  *
592  * @param route The given route to check for.
593  *
594  * `routeActive` returns true for partial routes like
595  * the following:
596  *
597  * @code{.js}
598  * Kirigami.PageRouter.navigateToRoute(["/home", "/login", "/google"])
599  * Kirigami.PageRouter.routeActive(["/home", "/login"]) // returns true
600  * @endcode
601  *
602  * This only works from the root page, e.g. the following will return false:
603  * @code{.js}
604  * Kirigami.PageRouter.navigateToRoute(["/home", "/login", "/google"])
605  * Kirigami.PageRouter.routeActive(["/login", "/google"]) // returns false
606  * @endcode
607  */
608  Q_INVOKABLE bool routeActive(QJSValue route);
609 
610  /**
611  * @brief Appends a route to the currently navigated route.
612  *
613  * Calling `pushRoute` will append the given @p route to the currently navigated
614  * routes. See navigateToRoute() if you want to replace the items currently on
615  * the PageRouter.
616  *
617  * @param route The given route to push.
618  *
619  * @code{.js}
620  * Kirigami.PageRouter.navigateToRoute(["/home", "/login"])
621  * // The PageRouter is navigated to /home/login
622  * Kirigami.PageRouter.pushRoute("/google")
623  * // The PageRouter is navigated to /home/login/google
624  * @endcode
625  */
626  Q_INVOKABLE void pushRoute(QJSValue route);
627 
628  /**
629  * @brief Pops the last page on the router.
630  *
631  * Calling `popRoute` will result in the last page on the router getting popped.
632  * You should not call this function when there is only one page on the router.
633  *
634  * @code{.js}
635  * Kirigami.PageRouter.navigateToRoute(["/home", "/login"])
636  * // The PageRouter is navigated to /home/login
637  * Kirigami.PageRouter.popRoute()
638  * // The PageRouter is navigated to /home
639  * @endcode
640  */
641  Q_INVOKABLE void popRoute();
642 
643  /**
644  * @brief Shifts keyboard focus and view to a given index on the PageRouter's stack.
645  *
646  * @param view The view to bring to focus. If this is an integer index, the PageRouter will
647  * navigate to the given index. If it's a route specifier, the PageRouter will navigate
648  * to the first route matching it.
649  *
650  * Navigating to route by index:
651  * @code{.js}
652  * Kirigami.PageRouter.navigateToRoute(["/home", "/browse", "/apps", "/login"])
653  * Kirigami.PageRouter.bringToView(1)
654  * @endcode
655  *
656  * Navigating to route by name:
657  * @code{.js}
658  * Kirigami.PageRouter.navigateToRoute(["/home", "/browse", "/apps", "/login"])
659  * Kirigami.PageRouter.bringToView("/browse")
660  * @endcode
661  *
662  * Navigating to route by data:
663  * @code{.js}
664  * Kirigami.PageRouter.navigateToRoute([{"route": "/page", "data": "red"},
665  * {"route": "/page", "data": "blue"},
666  * {"route": "/page", "data": "green"},
667  * {"route": "/page", "data": "yellow"}])
668  * Kirigami.PageRouter.bringToView({"route": "/page", "data": "blue"})
669  * @endcode
670  */
671  Q_INVOKABLE void bringToView(QJSValue route);
672 
673  /**
674  * @brief Returns a QJSValue corresponding to the current pages on the stack.
675  *
676  * The returned value is in the same form as the input to navigateToRoute.
677  */
679 
680  static PageRouterAttached *qmlAttachedProperties(QObject *object);
681 
682 Q_SIGNALS:
683  void routesChanged();
684  void initialRouteChanged();
685  void pageStackChanged();
686  void currentIndexChanged();
687  void navigationChanged();
688 };
689 
690 /**
691  * Attached object allowing children of a PageRouter to access its functions
692  * without requiring the children to have the parent PageRouter's id.
693  *
694  * @see PageRouter
695  */
697 {
698  Q_OBJECT
699 
700  Q_PROPERTY(PageRouter *router READ router WRITE setRouter NOTIFY routerChanged)
701  /**
702  * The data for the page this item belongs to. Accessing this property
703  * outside of a PageRouter will result in undefined behavior.
704  */
705  Q_PROPERTY(QVariant data READ data MEMBER m_data NOTIFY dataChanged)
706 
707  /**
708  * Whether the page this item belongs to is the current index of the ColumnView.
709  * Accessing this property outside of a PageRouter will result in undefined behaviour.
710  */
711  Q_PROPERTY(bool isCurrent READ isCurrent NOTIFY isCurrentChanged)
712 
713  /**
714  * Which route this PageRouterAttached should watch for.
715  *
716  * @include PageRouterWatchedRoute.qml
717  */
718  Q_PROPERTY(QJSValue watchedRoute READ watchedRoute WRITE setWatchedRoute NOTIFY watchedRouteChanged)
719 
720  /**
721  * Route preloading settings.
722  */
724 
725  /**
726  * Whether the watchedRoute is currently active.
727  */
728  Q_PROPERTY(bool watchedRouteActive READ watchedRouteActive NOTIFY navigationChanged)
729 
730 private:
731  explicit PageRouterAttached(QObject *parent = nullptr);
732 
733  QPointer<PageRouter> m_router;
734  PreloadRouteGroup *m_preload;
735  QVariant m_data;
736  QJSValue m_watchedRoute;
737 
738  void findParent();
739 
740  friend class PageRouter;
741  friend class PreloadRouteGroup;
742  friend class ParsedRoute;
743 
744 public:
745  PreloadRouteGroup *preload() const
746  {
747  return m_preload;
748  };
749  PageRouter *router() const
750  {
751  return m_router;
752  };
753  void setRouter(PageRouter *router)
754  {
755  m_router = router;
756  Q_EMIT routerChanged();
757  }
758  QVariant data() const;
759  bool isCurrent() const;
760  /// @see PageRouter::navigateToRoute()
762  /// @see PageRouter::routeActive()
763  Q_INVOKABLE bool routeActive(QJSValue route);
764  /// @see PageRouter::pushRoute()
765  Q_INVOKABLE void pushRoute(QJSValue route);
766  /// @see PageRouter::popRoute()
767  Q_INVOKABLE void popRoute();
768  // @see PageRouter::bringToView()
769  Q_INVOKABLE void bringToView(QJSValue route);
770  /**
771  * @brief Push a route from this route on the stack.
772  *
773  * Replace the routes after the route this is invoked on
774  * with the provided @p route.
775  *
776  * For example, if you invoke this method on the second route
777  * in the PageRouter's stack, routes after the second
778  * route will be replaced with the provided routes.
779  */
780  Q_INVOKABLE void pushFromHere(QJSValue route);
781  /**
782  * @brief Pop routes after this route on the stack.
783  *
784  * Pop the routes after the route this is invoked on with
785  * the provided @p route.
786  *
787  * For example, if you invoke this method on the second route
788  * in the PageRouter's stack, routes after the second route
789  * will be removed from the stack.
790  */
791  Q_INVOKABLE void popFromHere();
792  /**
793  * @brief Replaces this route with the given routes on the stack.
794  *
795  * Behaves like pushFromHere, except the current route is also
796  * popped.
797  */
799  bool watchedRouteActive();
800  void setWatchedRoute(QJSValue route);
802 
803 Q_SIGNALS:
804  void routerChanged();
805  void dataChanged();
806  void isCurrentChanged();
807  void navigationChanged();
808  void watchedRouteChanged();
809 };
810 
811 QML_DECLARE_TYPEINFO(PageRouter, QML_HAS_ATTACHED_PROPERTIES)
bool watchedRouteActive
Whether the watchedRoute is currently active.
Definition: pagerouter.h:728
Q_OBJECTQ_OBJECT
QVariant data
The data for the page this item belongs to.
Definition: pagerouter.h:705
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:393
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
bool equals(const QVariant &lhs, const QVariant &rhs)
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:372
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:723
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:711
bool when
When the route should be preloaded.
Definition: pagerouter.h:167
QJSValue watchedRoute
Which route this PageRouterAttached should watch for.
Definition: pagerouter.h:718
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:386
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:358
Attached object allowing children of a PageRouter to access its functions without requiring the child...
Definition: pagerouter.h:696
T takeLast()
QObject * parent() const const
int cacheCapacity
How large the cache can be.
Definition: pagerouter.h:379
Q_INVOKABLE void navigateToRoute(QJSValue route)
Definition: pagerouter.cpp:584
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Jan 27 2023 07:54:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.