Gui: add virtual methods undoActions()/redoActions() to MDIView to simplify code in UndoDialog/RedoDialog
This commit is contained in:
@@ -29,9 +29,7 @@
|
||||
#include "DlgUndoRedo.h"
|
||||
#include "Application.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Document.h"
|
||||
#include "EditorView.h"
|
||||
#include "TextDocumentEditorView.h"
|
||||
#include "MDIView.h"
|
||||
|
||||
using namespace Gui::Dialog;
|
||||
|
||||
@@ -64,28 +62,11 @@ void UndoDialog::onFetchInfo()
|
||||
clear(); // Remove first all items
|
||||
|
||||
MDIView* mdi = getMainWindow()->activeWindow();
|
||||
EditorView* editview = qobject_cast<EditorView*>(mdi);
|
||||
TextDocumentEditorView* textedit = qobject_cast<TextDocumentEditorView*>(mdi);
|
||||
if (editview) {
|
||||
QStringList vecUndos = editview->undoActions();
|
||||
if (mdi) {
|
||||
QStringList vecUndos = mdi->undoActions();
|
||||
for (QStringList::Iterator i = vecUndos.begin(); i != vecUndos.end(); ++i)
|
||||
addAction(*i, this, SLOT(onSelected()));
|
||||
}
|
||||
else if (textedit) {
|
||||
QStringList vecUndos = textedit->undoActions();
|
||||
for (QStringList::Iterator i = vecUndos.begin(); i != vecUndos.end(); ++i)
|
||||
addAction(*i, this, SLOT(onSelected()));
|
||||
}
|
||||
else if (mdi) {
|
||||
Gui::Document* pcDoc = mdi->getGuiDocument();
|
||||
if (pcDoc) {
|
||||
std::vector<std::string> vecUndos = pcDoc->getUndoVector();
|
||||
for (std::vector<std::string>::iterator i = vecUndos.begin(); i != vecUndos.end(); ++i) {
|
||||
QString text = QCoreApplication::translate("Command", i->c_str());
|
||||
addAction(text, this, SLOT(onSelected()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Closes the dialog and sends the message 'Undo' to the currently active MDI view. */
|
||||
@@ -129,28 +110,11 @@ void RedoDialog::onFetchInfo()
|
||||
clear(); // Remove first all items
|
||||
|
||||
MDIView* mdi = getMainWindow()->activeWindow();
|
||||
EditorView* editview = qobject_cast<EditorView*>(mdi);
|
||||
TextDocumentEditorView* textedit = qobject_cast<TextDocumentEditorView*>(mdi);
|
||||
if (editview) {
|
||||
QStringList vecRedos = editview->redoActions();
|
||||
if (mdi) {
|
||||
QStringList vecRedos = mdi->redoActions();
|
||||
for (QStringList::Iterator i = vecRedos.begin(); i != vecRedos.end(); ++i)
|
||||
addAction(*i, this, SLOT(onSelected()));
|
||||
}
|
||||
else if (textedit) {
|
||||
QStringList vecRedos = textedit->redoActions();
|
||||
for (QStringList::Iterator i = vecRedos.begin(); i != vecRedos.end(); ++i)
|
||||
addAction(*i, this, SLOT(onSelected()));
|
||||
}
|
||||
else if (mdi) {
|
||||
Gui::Document* pcDoc = mdi->getGuiDocument();
|
||||
if (pcDoc) {
|
||||
std::vector<std::string> vecRedos = pcDoc->getRedoVector();
|
||||
for (std::vector<std::string>::iterator i = vecRedos.begin(); i != vecRedos.end(); ++i) {
|
||||
QString text = QCoreApplication::translate("Command", i->c_str());
|
||||
addAction(text, this, SLOT(onSelected()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Closes the dialog and sends the message 'Redo' to the currently active MDI view. */
|
||||
|
||||
@@ -241,6 +241,34 @@ void MDIView::printPreview()
|
||||
std::cerr << "Printing preview not implemented for " << this->metaObject()->className() << std::endl;
|
||||
}
|
||||
|
||||
QStringList MDIView::undoActions() const
|
||||
{
|
||||
QStringList actions;
|
||||
Gui::Document* doc = getGuiDocument();
|
||||
if (doc) {
|
||||
std::vector<std::string> vecUndos = doc->getUndoVector();
|
||||
for (std::vector<std::string>::iterator i = vecUndos.begin(); i != vecUndos.end(); ++i) {
|
||||
actions << QCoreApplication::translate("Command", i->c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
QStringList MDIView::redoActions() const
|
||||
{
|
||||
QStringList actions;
|
||||
Gui::Document* doc = getGuiDocument();
|
||||
if (doc) {
|
||||
std::vector<std::string> vecRedos = doc->getRedoVector();
|
||||
for (std::vector<std::string>::iterator i = vecRedos.begin(); i != vecRedos.end(); ++i) {
|
||||
actions << QCoreApplication::translate("Command", i->c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
QSize MDIView::minimumSizeHint () const
|
||||
{
|
||||
return QSize(400, 300);
|
||||
|
||||
@@ -95,6 +95,12 @@ public:
|
||||
virtual void printPreview();
|
||||
//@}
|
||||
|
||||
/** @name Undo/Redo actions */
|
||||
//@{
|
||||
virtual QStringList undoActions() const;
|
||||
virtual QStringList redoActions() const;
|
||||
//@}
|
||||
|
||||
QSize minimumSizeHint () const;
|
||||
|
||||
/// MDI view mode enum
|
||||
|
||||
@@ -53,8 +53,8 @@ public:
|
||||
|
||||
QPlainTextEdit* getEditor() const { return editor; }
|
||||
App::TextDocument* getTextObject() const { return textDocument; }
|
||||
QStringList undoActions() const;
|
||||
QStringList redoActions() const;
|
||||
QStringList undoActions() const override;
|
||||
QStringList redoActions() const override;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent*) override;
|
||||
|
||||
Reference in New Issue
Block a user