Added a undo view and react to change of the cleanness of the undo stack.
This commit is contained in:
@ -4,6 +4,7 @@
|
|||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QUndoStack>
|
#include <QUndoStack>
|
||||||
|
#include <QUndoView>
|
||||||
|
|
||||||
#include "../../ApplicationConfig.h"
|
#include "../../ApplicationConfig.h"
|
||||||
#include "Dialogs/newitemdialog.h"
|
#include "Dialogs/newitemdialog.h"
|
||||||
@ -20,6 +21,7 @@ MainWindow::MainWindow(QWidget* parent)
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
m_core = std::make_unique<GenericCore>();
|
m_core = std::make_unique<GenericCore>();
|
||||||
|
setWindowTitle(windowTitle() + " [*]");
|
||||||
|
|
||||||
/// application icon
|
/// application icon
|
||||||
const QString iconString = "://feature.png";
|
const QString iconString = "://feature.png";
|
||||||
@ -173,9 +175,33 @@ void MainWindow::deleteSelectedtItems() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onCleanStateChanged(bool clean) {
|
||||||
|
qInfo() << "Slot onCleanStateChanged triggered: clean:" << clean;
|
||||||
|
setWindowModified(!clean);
|
||||||
|
if (!clean) {
|
||||||
|
ui->statusbar->clearMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onShowUndoViewToggled(bool checked) {
|
||||||
|
// qInfo() << "Slot onShowUndoViewToggled toggled: checked:" << checked;
|
||||||
|
// m_undoView->setVisible(checked);
|
||||||
|
|
||||||
|
/// workaround until m_showUndoViewAction is checkable
|
||||||
|
qInfo() << "Slot onShowUndoViewToggled triggered, toggleing undo view...";
|
||||||
|
Q_UNUSED(checked);
|
||||||
|
if (m_modelUndoView->isVisible()) {
|
||||||
|
m_modelUndoView->setVisible(false);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
m_modelUndoView->setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::createActions() {
|
void MainWindow::createActions() {
|
||||||
// TODO add generic menu actions (file/new, edit/cut, ...)
|
// TODO add generic menu actions (file/new, edit/cut, ...)
|
||||||
createFileActions();
|
createFileActions();
|
||||||
|
createUndoActions();
|
||||||
createEditActions();
|
createEditActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,11 +259,15 @@ void MainWindow::createFileActions() {
|
|||||||
ui->menu_File->addAction(m_exitAct.get());
|
ui->menu_File->addAction(m_exitAct.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createEditActions() {
|
void MainWindow::createUndoActions() {
|
||||||
m_modelUndoStack = m_core->getModUndoStack();
|
if (!m_core) {
|
||||||
|
qCritical() << "No core instance set, aborting...";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_modelUndoStack = m_core->getModelUndoStack();
|
||||||
|
|
||||||
|
connect(m_modelUndoStack, &QUndoStack::cleanChanged, this, &MainWindow::onCleanStateChanged);
|
||||||
|
|
||||||
connect(m_modelUndoStack.get(), SIGNAL(cleanChanged(bool)), this,
|
|
||||||
SLOT(onCleanStateChanged(bool)));
|
|
||||||
m_undoAct.reset(m_modelUndoStack->createUndoAction(this, tr("&Undo")));
|
m_undoAct.reset(m_modelUndoStack->createUndoAction(this, tr("&Undo")));
|
||||||
m_undoAct->setShortcuts(QKeySequence::Undo);
|
m_undoAct->setShortcuts(QKeySequence::Undo);
|
||||||
m_undoAct->setStatusTip(tr("Undo the last operation"));
|
m_undoAct->setStatusTip(tr("Undo the last operation"));
|
||||||
@ -248,6 +278,26 @@ void MainWindow::createEditActions() {
|
|||||||
m_redoAct->setStatusTip(tr("Redo the last operation"));
|
m_redoAct->setStatusTip(tr("Redo the last operation"));
|
||||||
ui->menu_Edit->addAction(m_redoAct.get());
|
ui->menu_Edit->addAction(m_redoAct.get());
|
||||||
|
|
||||||
|
m_modelUndoView = make_unique<QUndoView>(m_modelUndoStack);
|
||||||
|
m_modelUndoView->setWindowTitle(tr("Undo list"));
|
||||||
|
m_modelUndoView->setAttribute(Qt::WA_QuitOnClose, false);
|
||||||
|
m_modelUndoView->setMinimumSize(450, 600);
|
||||||
|
m_showModelUndoViewAct = make_unique<QAction>(tr("Show undo/redo window"), this);
|
||||||
|
m_showModelUndoViewAct->setStatusTip(tr("Opens a window displaying the items on the undo stack"));
|
||||||
|
|
||||||
|
// TODO showUndoViewAction should be checkable
|
||||||
|
// m_showUndoViewAction->setCheckable(true);
|
||||||
|
// connect(m_showUndoViewAction, &QAction::toggled, this, &MainWindow::onShowUndoViewToggled);
|
||||||
|
connect(m_showModelUndoViewAct.get(), &QAction::triggered, this,
|
||||||
|
&MainWindow::onShowUndoViewToggled);
|
||||||
|
|
||||||
|
// TODO ? add a keyboard short cut?
|
||||||
|
// m_showUndoViewAction->setShortcuts(QKeySequence::Copy);
|
||||||
|
|
||||||
|
ui->menu_View->addAction(m_showModelUndoViewAct.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::createEditActions() {
|
||||||
m_cutAct = make_unique<QAction>(tr("Cu&t"), this);
|
m_cutAct = make_unique<QAction>(tr("Cu&t"), this);
|
||||||
m_cutAct->setShortcuts(QKeySequence::Cut);
|
m_cutAct->setShortcuts(QKeySequence::Cut);
|
||||||
m_cutAct->setStatusTip(
|
m_cutAct->setStatusTip(
|
||||||
|
|||||||
11
mainwindow.h
11
mainwindow.h
@ -10,6 +10,8 @@ class TableModel;
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QUndoStack;
|
class QUndoStack;
|
||||||
|
|
||||||
|
class QUndoView;
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
@ -46,13 +48,17 @@ class MainWindow : public QMainWindow {
|
|||||||
void openNewItemDialog();
|
void openNewItemDialog();
|
||||||
void deleteSelectedtItems();
|
void deleteSelectedtItems();
|
||||||
|
|
||||||
|
void onCleanStateChanged(bool clean);
|
||||||
|
void onShowUndoViewToggled(bool checked);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow* ui;
|
||||||
|
|
||||||
// GenericCore* m_core;
|
// GenericCore* m_core;
|
||||||
unique_ptr<GenericCore> m_core;
|
unique_ptr<GenericCore> m_core;
|
||||||
shared_ptr<TableModel> m_tableModel;
|
shared_ptr<TableModel> m_tableModel;
|
||||||
shared_ptr<QUndoStack> m_modelUndoStack;
|
QUndoStack* m_modelUndoStack;
|
||||||
|
unique_ptr<QUndoView> m_modelUndoView;
|
||||||
|
|
||||||
/// File actions
|
/// File actions
|
||||||
unique_ptr<QAction> m_newFileAct;
|
unique_ptr<QAction> m_newFileAct;
|
||||||
@ -72,6 +78,8 @@ class MainWindow : public QMainWindow {
|
|||||||
unique_ptr<QAction> m_openEditItemDialogAct;
|
unique_ptr<QAction> m_openEditItemDialogAct;
|
||||||
unique_ptr<QAction> m_deleteItemAct;
|
unique_ptr<QAction> m_deleteItemAct;
|
||||||
unique_ptr<QAction> m_findItemAct;
|
unique_ptr<QAction> m_findItemAct;
|
||||||
|
/// View actions
|
||||||
|
unique_ptr<QAction> m_showModelUndoViewAct;
|
||||||
|
|
||||||
/// Dialogs
|
/// Dialogs
|
||||||
unique_ptr<NewItemDialog> m_newItemDialog;
|
unique_ptr<NewItemDialog> m_newItemDialog;
|
||||||
@ -79,6 +87,7 @@ class MainWindow : public QMainWindow {
|
|||||||
/// Setup functions
|
/// Setup functions
|
||||||
void createActions();
|
void createActions();
|
||||||
void createFileActions();
|
void createFileActions();
|
||||||
|
void createUndoActions();
|
||||||
void createEditActions();
|
void createEditActions();
|
||||||
void createHelpMenu();
|
void createHelpMenu();
|
||||||
void createGuiDialogs();
|
void createGuiDialogs();
|
||||||
|
|||||||
Reference in New Issue
Block a user