mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-10 09:19:01 +00:00
Changed: #1307 Added implementation of undo/redo framework partial
--HG-- branch : gsoc2011-translationovqt
This commit is contained in:
parent
4c01411840
commit
03e08b730a
4 changed files with 56 additions and 7 deletions
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
@ -40,11 +43,12 @@ namespace Plugin {
|
|||
class CEditorWorksheet : public CEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QTableWidget* table_editor;
|
||||
private:
|
||||
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 */
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -65,7 +65,9 @@ CMainWindow::CMainWindow(QWidget *parent)
|
|||
initialize_settings["ligo"] = false;
|
||||
readSettings();
|
||||
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()
|
||||
|
@ -207,7 +209,8 @@ void CMainWindow::open()
|
|||
}
|
||||
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->activateWindow();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue