Changed: #1307 Added implementation of undo/redo framework partial

This commit is contained in:
cemycc 2011-07-12 22:02:05 +03:00
parent f8b52c2553
commit 1bade68ee0
4 changed files with 56 additions and 7 deletions

View file

@ -95,7 +95,8 @@ void CEditorWorksheet::open(QString filename)
table_editor->resizeColumnsToContents();
table_editor->resizeRowsToContents();
// set editor signals
connect(table_editor, SIGNAL(cellChanged(int,int) ), this, SLOT(worksheetEditorChanged(int,int)));
connect(table_editor, SIGNAL(itemChanged(QTableWidgetItem*) ), this, SLOT(worksheetEditorChanged(QTableWidgetItem*)));
connect(table_editor, SIGNAL(itemDoubleClicked(QTableWidgetItem*) ), this, SLOT(worksheetEditorCellEntered(QTableWidgetItem*)));
} else {
QErrorMessage error;
error.showMessage("This file is not a worksheet file.");
@ -233,8 +234,19 @@ void CEditorWorksheet::deleteRow()
return;
}
void CEditorWorksheet::worksheetEditorChanged(int row, int column)
void CEditorWorksheet::worksheetEditorCellEntered(QTableWidgetItem * item)
{
temp_content = item->text();
}
void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item)
{
if(temp_content != item->text())
{
QString i_text = item->text();
current_stack->push(new CUndoWorksheetCommand(item, temp_content, i_text));
}
if(!isWindowModified())
setWindowModified(true);
}
@ -494,6 +506,7 @@ void CEditorWorksheet::closeEvent(QCloseEvent *event)
}
}
bool CEditorWorksheet::isBotNamesTable()
{
bool status = true;

View file

@ -31,6 +31,9 @@
#include <QtGui/QMdiArea>
#include <QtGui/QTableWidget>
#include <QtGui/QMdiSubWindow>
#include <QtGui/QUndoCommand>
#include <QtGui/qundostack.h>
#include "translation_manager_editor.h"
#include "extract_new_sheet_names.h"
@ -41,10 +44,11 @@ class CEditorWorksheet : public CEditor
{
Q_OBJECT
private:
QTableWidget* table_editor;
QString temp_content;
public:
CEditorWorksheet(QMdiArea* parent) : CEditor(parent) {}
CEditorWorksheet() : CEditor() {}
QTableWidget* table_editor;
void open(QString filename);
void save();
void saveAs(QString filename);
@ -57,7 +61,8 @@ public:
bool isSheetTable(QString type);
void closeEvent(QCloseEvent *event);
private Q_SLOTS:
void worksheetEditorChanged(int,int);
void worksheetEditorCellEntered(QTableWidgetItem * item);
void worksheetEditorChanged(QTableWidgetItem * item);
void insertRow();
void deleteRow();
private:
@ -65,6 +70,28 @@ private:
};
class CUndoWorksheetCommand : public QUndoCommand
{
public:
CUndoWorksheetCommand(QTableWidgetItem* item, const QString &ocontent, QString ccontent) : QUndoCommand("Insert characters in cells"), m_item(item), m_ocontent(ocontent), m_ccontent(ccontent) { }
virtual void redo()
{
//m_ccontent = m_item->text();
m_item->setText(m_ccontent);
}
virtual void undo()
{
m_item->setText(m_ocontent);
}
private:
QTableWidgetItem* m_item;
QString m_ocontent;
QString m_ccontent;
};
}
#endif /* EDITOR_WORKSHEET_H */

View file

@ -22,12 +22,14 @@
#include <QtGui/QWidget>
#include <QtGui/QMdiArea>
#include <QtGui/QMdiSubWindow>
#include <QtGui/QUndoStack>
namespace Plugin {
class CEditor : public QMdiSubWindow {
Q_OBJECT
protected:
QUndoStack* current_stack;
QString current_file;
int editor_type;
public:
@ -42,6 +44,10 @@ public:
{
return current_file;
}
void setUndoStack(QUndoStack* stack)
{
current_stack = stack;
}
};
}

View file

@ -66,6 +66,8 @@ CMainWindow::CMainWindow(QWidget *parent)
readSettings();
createToolbar();
m_undoStack = new QUndoStack(this);
_ui.toolBar->addAction(m_undoStack->createUndoAction(this));
_ui.toolBar->addAction(m_undoStack->createRedoAction(this));
}
void CMainWindow::createToolbar()
@ -208,6 +210,7 @@ void CMainWindow::open()
if(isWorksheetEditor(file_name))
{
CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea);
new_window->setUndoStack(m_undoStack);
new_window->open(file_name);
new_window->activateWindow();
}