Undo and Redo command
This commit is contained in:
+35
-2
@@ -1,15 +1,49 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "path.h"
|
||||
|
||||
#include "Undo.h"
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QLineEdit>
|
||||
#include <QTimer>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
, undoStack(new QUndoStack(this))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
||||
connect(ui->titleEdit, &QLineEdit::editingFinished, this, [this]() {
|
||||
static QString previousText;
|
||||
QString currentText = ui->titleEdit->text();
|
||||
if(previousText != currentText) {
|
||||
undoStack->push(new LineEditCommand(ui->titleEdit, previousText, currentText));
|
||||
previousText = currentText;
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->locEdit, &QLineEdit::editingFinished, this, [this]() {
|
||||
static QString previousText;
|
||||
QString currentText = ui->locEdit->text();
|
||||
if(previousText != currentText) {
|
||||
undoStack->push(new LineEditCommand(ui->locEdit, previousText, currentText));
|
||||
previousText = currentText;
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->imagePath, &QLineEdit::editingFinished, this, [this]() {
|
||||
static QString previousText;
|
||||
QString currentText = ui->imagePath->text();
|
||||
if(previousText != currentText) {
|
||||
undoStack->push(new LineEditCommand(ui->imagePath, previousText, currentText));
|
||||
previousText = currentText;
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->actionEditUndo, &QAction::triggered, undoStack, &QUndoStack::undo);
|
||||
connect(ui->actionEditRedo, &QAction::triggered, undoStack, &QUndoStack::redo);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -136,4 +170,3 @@ void MainWindow::on_actionopenFile_triggered()
|
||||
{
|
||||
this->loadPath();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user