mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-20 06:06:13 +00:00
Changed: #1307 Added implementation of undo/redo framework partial
This commit is contained in:
parent
88efab3b60
commit
5b234330aa
4 changed files with 56 additions and 7 deletions
|
@ -95,7 +95,8 @@ void CEditorWorksheet::open(QString filename)
|
||||||
table_editor->resizeColumnsToContents();
|
table_editor->resizeColumnsToContents();
|
||||||
table_editor->resizeRowsToContents();
|
table_editor->resizeRowsToContents();
|
||||||
// set editor signals
|
// 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 {
|
} else {
|
||||||
QErrorMessage error;
|
QErrorMessage error;
|
||||||
error.showMessage("This file is not a worksheet file.");
|
error.showMessage("This file is not a worksheet file.");
|
||||||
|
@ -233,8 +234,19 @@ void CEditorWorksheet::deleteRow()
|
||||||
return;
|
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())
|
if(!isWindowModified())
|
||||||
setWindowModified(true);
|
setWindowModified(true);
|
||||||
}
|
}
|
||||||
|
@ -494,6 +506,7 @@ void CEditorWorksheet::closeEvent(QCloseEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CEditorWorksheet::isBotNamesTable()
|
bool CEditorWorksheet::isBotNamesTable()
|
||||||
{
|
{
|
||||||
bool status = true;
|
bool status = true;
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
#include <QtGui/QMdiArea>
|
#include <QtGui/QMdiArea>
|
||||||
#include <QtGui/QTableWidget>
|
#include <QtGui/QTableWidget>
|
||||||
#include <QtGui/QMdiSubWindow>
|
#include <QtGui/QMdiSubWindow>
|
||||||
|
#include <QtGui/QUndoCommand>
|
||||||
|
#include <QtGui/qundostack.h>
|
||||||
|
|
||||||
|
|
||||||
#include "translation_manager_editor.h"
|
#include "translation_manager_editor.h"
|
||||||
#include "extract_new_sheet_names.h"
|
#include "extract_new_sheet_names.h"
|
||||||
|
@ -41,10 +44,11 @@ class CEditorWorksheet : public CEditor
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QTableWidget* table_editor;
|
QString temp_content;
|
||||||
public:
|
public:
|
||||||
CEditorWorksheet(QMdiArea* parent) : CEditor(parent) {}
|
CEditorWorksheet(QMdiArea* parent) : CEditor(parent) {}
|
||||||
CEditorWorksheet() : CEditor() {}
|
CEditorWorksheet() : CEditor() {}
|
||||||
|
QTableWidget* table_editor;
|
||||||
void open(QString filename);
|
void open(QString filename);
|
||||||
void save();
|
void save();
|
||||||
void saveAs(QString filename);
|
void saveAs(QString filename);
|
||||||
|
@ -57,7 +61,8 @@ public:
|
||||||
bool isSheetTable(QString type);
|
bool isSheetTable(QString type);
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void worksheetEditorChanged(int,int);
|
void worksheetEditorCellEntered(QTableWidgetItem * item);
|
||||||
|
void worksheetEditorChanged(QTableWidgetItem * item);
|
||||||
void insertRow();
|
void insertRow();
|
||||||
void deleteRow();
|
void deleteRow();
|
||||||
private:
|
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 */
|
#endif /* EDITOR_WORKSHEET_H */
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,14 @@
|
||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
#include <QtGui/QMdiArea>
|
#include <QtGui/QMdiArea>
|
||||||
#include <QtGui/QMdiSubWindow>
|
#include <QtGui/QMdiSubWindow>
|
||||||
|
#include <QtGui/QUndoStack>
|
||||||
|
|
||||||
namespace Plugin {
|
namespace Plugin {
|
||||||
|
|
||||||
class CEditor : public QMdiSubWindow {
|
class CEditor : public QMdiSubWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
|
QUndoStack* current_stack;
|
||||||
QString current_file;
|
QString current_file;
|
||||||
int editor_type;
|
int editor_type;
|
||||||
public:
|
public:
|
||||||
|
@ -42,6 +44,10 @@ public:
|
||||||
{
|
{
|
||||||
return current_file;
|
return current_file;
|
||||||
}
|
}
|
||||||
|
void setUndoStack(QUndoStack* stack)
|
||||||
|
{
|
||||||
|
current_stack = stack;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,9 @@ CMainWindow::CMainWindow(QWidget *parent)
|
||||||
initialize_settings["ligo"] = false;
|
initialize_settings["ligo"] = false;
|
||||||
readSettings();
|
readSettings();
|
||||||
createToolbar();
|
createToolbar();
|
||||||
m_undoStack = new QUndoStack(this);
|
m_undoStack = new QUndoStack(this);
|
||||||
|
_ui.toolBar->addAction(m_undoStack->createUndoAction(this));
|
||||||
|
_ui.toolBar->addAction(m_undoStack->createRedoAction(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainWindow::createToolbar()
|
void CMainWindow::createToolbar()
|
||||||
|
@ -208,6 +210,7 @@ void CMainWindow::open()
|
||||||
if(isWorksheetEditor(file_name))
|
if(isWorksheetEditor(file_name))
|
||||||
{
|
{
|
||||||
CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea);
|
CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea);
|
||||||
|
new_window->setUndoStack(m_undoStack);
|
||||||
new_window->open(file_name);
|
new_window->open(file_name);
|
||||||
new_window->activateWindow();
|
new_window->activateWindow();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue