[vlc-devel] [PATCH 01/22] qml: allow to update the current history item

Pierre Lamot pierre at videolabs.io
Fri Feb 14 11:23:36 CET 2020


  this may be used for instance to save the current view position,
  like #fragment in url links
---
 modules/gui/qt/util/navigation_history.cpp | 17 ++++++++++++++++-
 modules/gui/qt/util/navigation_history.hpp | 15 +++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/modules/gui/qt/util/navigation_history.cpp b/modules/gui/qt/util/navigation_history.cpp
index 5f494d1c58..7952f7829b 100644
--- a/modules/gui/qt/util/navigation_history.cpp
+++ b/modules/gui/qt/util/navigation_history.cpp
@@ -1,5 +1,5 @@
 #include "navigation_history.hpp"
-#include <QDebug>
+#include <cassert>
 
 NavigationHistory::NavigationHistory(QObject *parent)
     : QObject(parent), m_position(-1)
@@ -67,6 +67,21 @@ void NavigationHistory::push(QVariantList itemList, NavigationHistory::PostActio
     push(itemMap, postAction);
 }
 
+
+void NavigationHistory::update(QVariantMap item)
+{
+    int length = m_history.length();
+    assert(length >= 1);
+    m_history.replace(m_position, item);
+}
+
+void NavigationHistory::update(QVariantList itemList)
+{
+    QVariantMap itemMap;
+    pushListRec(itemMap, itemList.cbegin(), itemList.cend());
+    update(itemMap);
+}
+
 void NavigationHistory::previous(PostAction postAction)
 {
     if (m_position == 0)
diff --git a/modules/gui/qt/util/navigation_history.hpp b/modules/gui/qt/util/navigation_history.hpp
index a07c0ab93a..b19d476b14 100644
--- a/modules/gui/qt/util/navigation_history.hpp
+++ b/modules/gui/qt/util/navigation_history.hpp
@@ -66,6 +66,21 @@ public slots:
      */
     Q_INVOKABLE void push(QVariantList itemList, PostAction = PostAction::Stay );
 
+
+    /**
+     * @brief same as @a push(QVariantMap) but modify the last (current) item instead of insterting a new one
+     *
+     * @see push
+     */
+    Q_INVOKABLE void update(QVariantMap itemList);
+
+    /**
+     * @brief same as @a push(QVariantList) but modify the last (current) item instead of insterting a new one
+     *
+     * @see push
+     */
+    Q_INVOKABLE void update(QVariantList itemList);
+
     // Go to previous page
     void previous( PostAction = PostAction::Stay );
 
-- 
2.17.1



More information about the vlc-devel mailing list