Model undo stack is accessible in QML. Added Undo & Redo buttons, which are properly en-/disabled and have informative texts.
This commit is contained in:
23
ListPage.qml
23
ListPage.qml
@ -5,9 +5,13 @@ import QtQuick.Controls.Material
|
|||||||
Page {
|
Page {
|
||||||
id: page
|
id: page
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
id: listView
|
id: listView
|
||||||
anchors.fill: parent
|
Layout.fillWidth: true
|
||||||
|
Layout.fillHeight: true
|
||||||
focus: true
|
focus: true
|
||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
@ -25,6 +29,23 @@ Page {
|
|||||||
gradient: mainGradient
|
gradient: mainGradient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Button {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
text: "Undo: " + appUndoStack.undoText
|
||||||
|
enabled: appUndoStack.canUndo
|
||||||
|
onClicked: {
|
||||||
|
appUndoStack.undo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Button {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
text: "Redo: " + appUndoStack.redoText
|
||||||
|
enabled: appUndoStack.canRedo
|
||||||
|
onClicked: {
|
||||||
|
appUndoStack.redo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
//instantiated when header is processed
|
//instantiated when header is processed
|
||||||
|
|||||||
3
main.cpp
3
main.cpp
@ -1,6 +1,7 @@
|
|||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
|
#include <QUndoCommand>
|
||||||
|
|
||||||
#include <model/generalsortfiltermodel.h>
|
#include <model/generalsortfiltermodel.h>
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ int main(int argc, char* argv[]) {
|
|||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
std::unique_ptr<GenericCore> core = std::make_unique<GenericCore>();
|
std::unique_ptr<GenericCore> core = std::make_unique<GenericCore>();
|
||||||
std::shared_ptr<GeneralSortFilterModel> mainModel = core->getSortFilterModel();
|
std::shared_ptr<GeneralSortFilterModel> mainModel = core->getSortFilterModel();
|
||||||
|
QUndoStack* undoStack = core->getModelUndoStack();
|
||||||
|
|
||||||
// qInfo() << "QMLApp Version:" << QMLAPP_VERSION;
|
// qInfo() << "QMLApp Version:" << QMLAPP_VERSION;
|
||||||
qInfo() << "core->getString():" << core->toString();
|
qInfo() << "core->getString():" << core->toString();
|
||||||
@ -25,6 +27,7 @@ int main(int argc, char* argv[]) {
|
|||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
engine.rootContext()->setContextProperty(QStringLiteral("core"), core.get());
|
engine.rootContext()->setContextProperty(QStringLiteral("core"), core.get());
|
||||||
engine.rootContext()->setContextProperty(QStringLiteral("mainModel"), mainModel.get());
|
engine.rootContext()->setContextProperty(QStringLiteral("mainModel"), mainModel.get());
|
||||||
|
engine.rootContext()->setContextProperty(QStringLiteral("appUndoStack"), undoStack);
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
&engine, &QQmlApplicationEngine::objectCreationFailed, &app,
|
&engine, &QQmlApplicationEngine::objectCreationFailed, &app,
|
||||||
|
|||||||
Reference in New Issue
Block a user