From 8e6cc9b8d0dd5d312440b3329ee0dc4c5a133f4e Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 11 Jan 2020 15:26:13 -0800 Subject: [PATCH] mobile UI: make the text of the undo/redo action available to QML Signed-off-by: Dirk Hohndel --- mobile-widgets/qmlmanager.cpp | 25 ++++++++++++++++++++++++- mobile-widgets/qmlmanager.h | 8 ++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index f9fdb3a87..81806ddea 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -269,6 +270,10 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false), // careful - changing verbose at runtime isn't enough (of course that could be added if we want it) if (verbose) connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &QMLManager::divesChanged); + + // get updates to the undo/redo texts + connect(Command::getUndoStack(), &QUndoStack::undoTextChanged, this, &QMLManager::undoTextChanged); + connect(Command::getUndoStack(), &QUndoStack::redoTextChanged, this, &QMLManager::redoTextChanged); } void QMLManager::applicationStateChanged(Qt::ApplicationState state) @@ -1392,7 +1397,13 @@ void QMLManager::saveChangesCloud(bool forceRemoteSync) void QMLManager::undoDelete(int) { - undoAction->activate(QAction::Trigger); + Command::getUndoStack()->undo(); + changesNeedSaving(); +} + +void QMLManager::redo() +{ + Command::getUndoStack()->redo(); changesNeedSaving(); } @@ -2199,3 +2210,15 @@ void QMLManager::divesChanged(const QVector &dives, DiveField field) // invalidate_dive_cache(d); } } + +QString QMLManager::getUndoText() const +{ + QString undoText = Command::getUndoStack()->undoText(); + return undoText; +} + +QString QMLManager::getRedoText() const +{ + QString redoText = Command::getUndoStack()->redoText(); + return redoText; +} diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index 0ab1ff981..c0a5c65c4 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -51,6 +51,8 @@ class QMLManager : public QObject { Q_PROPERTY(QString pluggedInDeviceName MEMBER m_pluggedInDeviceName NOTIFY pluggedInDeviceNameChanged) Q_PROPERTY(bool showNonDiveComputers MEMBER m_showNonDiveComputers WRITE setShowNonDiveComputers NOTIFY showNonDiveComputersChanged) Q_PROPERTY(qPrefCloudStorage::cloud_status oldStatus MEMBER m_oldStatus WRITE setOldStatus NOTIFY oldStatusChanged) + Q_PROPERTY(QString undoText READ getUndoText NOTIFY undoTextChanged) // this is a read-only property + Q_PROPERTY(QString redoText READ getRedoText NOTIFY redoTextChanged) // this is a read-only property public: QMLManager(); @@ -98,6 +100,9 @@ public: int DC_deviceId() const; void DC_setDeviceId(int deviceId); + QString getUndoText() const; + QString getRedoText() const; + Q_INVOKABLE QStringList getProductListFromVendor(const QString& vendor); Q_INVOKABLE int getMatchingAddress(const QString &vendor, const QString &product); Q_INVOKABLE int getDetectedVendorIndex(); @@ -191,6 +196,7 @@ public slots: bool toggleCylinders(bool toggle); bool toggleWeights(bool toggle); void undoDelete(int id); + void redo(); int addDive(); void applyGpsData(); void populateGpsData(); @@ -286,6 +292,8 @@ signals: void showNonDiveComputersChanged(); void DC_ForceDownloadChanged(); void oldStatusChanged(); + void undoTextChanged(); + void redoTextChanged(); // From upload process void uploadFinish(bool success, const QString &text);