Changed: #1307 Added Undo Commands for edit, insertand delete items on table and for words extraction

--HG--
branch : gsoc2011-translationovqt
This commit is contained in:
cemycc 2011-07-13 19:47:15 +03:00
parent 8ad55aae36
commit 6fbe07b6f4
6 changed files with 179 additions and 63 deletions

View file

@ -15,8 +15,6 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "editor_worksheet.h"
#include <set>
// Qt includes // Qt includes
#include <QtGui/QErrorMessage> #include <QtGui/QErrorMessage>
#include <QtGui/QTableWidgetItem> #include <QtGui/QTableWidgetItem>
@ -24,8 +22,11 @@
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include <QtGui/QCloseEvent> #include <QtGui/QCloseEvent>
// Project includes
#include "editor_worksheet.h"
#include "extract_bot_names.h" #include "extract_bot_names.h"
#include "translation_manager_constants.h" #include "translation_manager_constants.h"
#include <set>
using namespace std; using namespace std;
@ -206,12 +207,7 @@ void CEditorWorksheet::saveAs(QString filename)
void CEditorWorksheet::insertRow() void CEditorWorksheet::insertRow()
{ {
int last_row = table_editor->rowCount(); int last_row = table_editor->rowCount();
table_editor->setRowCount(last_row + 1); current_stack->push(new CUndoWorksheetNewCommand(table_editor, last_row));
for(int j = 0; j < table_editor->columnCount(); j++)
{
QTableWidgetItem* item = new QTableWidgetItem();
table_editor->setItem(last_row, j, item);
}
} }
void CEditorWorksheet::deleteRow() void CEditorWorksheet::deleteRow()
@ -223,10 +219,9 @@ void CEditorWorksheet::deleteRow()
msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes); msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
msgBox.setDefaultButton(QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec(); int ret = msgBox.exec();
if(ret == QMessageBox::Yes) if(ret == QMessageBox::Yes)
{ {
table_editor->removeRow(selected_row); current_stack->push(new CUndoWorksheetDeleteCommand(table_editor, selected_row));
} }
table_editor->clearFocus(); table_editor->clearFocus();
@ -237,6 +232,7 @@ void CEditorWorksheet::deleteRow()
void CEditorWorksheet::worksheetEditorCellEntered(QTableWidgetItem * item) void CEditorWorksheet::worksheetEditorCellEntered(QTableWidgetItem * item)
{ {
temp_content = item->text(); temp_content = item->text();
current_stack->push(new CUndoWorksheetCommand(table_editor, item, temp_content));
} }
void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item) void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item)
@ -250,9 +246,12 @@ void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item)
setWindowModified(true); setWindowModified(true);
} }
void CEditorWorksheet::extractBotNames(list<string> filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig) void CEditorWorksheet::extractBotNames(list<string> filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig)
{ {
bool modified = false; bool modified = false;
QList<CTableWidgetItemStore> new_items;
ExtractBotNames ebn; ExtractBotNames ebn;
ebn.setRequiredSettings(filters, level_design_path); ebn.setRequiredSettings(filters, level_design_path);
ebn.extractBotNamesFromPrimitives(ligoConfig); ebn.extractBotNamesFromPrimitives(ligoConfig);
@ -281,6 +280,12 @@ void CEditorWorksheet::extractBotNames(list<string> filters, string level_design
sheet_name_row->setBackgroundColor(QColor("#F75D59")); sheet_name_row->setBackgroundColor(QColor("#F75D59"));
table_editor ->setItem(currentRow, 2, sheet_name_row); table_editor ->setItem(currentRow, 2, sheet_name_row);
if(!modified) modified = true; if(!modified) modified = true;
CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0);
new_items.push_back(bot_name_row_s);
CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1);
new_items.push_back(translation_name_row_s);
CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2);
new_items.push_back(sheet_name_row_s);
} }
} }
ebn.cleanSimpleNames(); ebn.cleanSimpleNames();
@ -310,10 +315,18 @@ void CEditorWorksheet::extractBotNames(list<string> filters, string level_design
sheet_name_row->setBackgroundColor(QColor("#F75D59")); sheet_name_row->setBackgroundColor(QColor("#F75D59"));
table_editor ->setItem(currentRow, 2, sheet_name_row); table_editor ->setItem(currentRow, 2, sheet_name_row);
if(!modified) modified = true; if(!modified) modified = true;
CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0);
new_items.push_back(bot_name_row_s);
CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1);
new_items.push_back(translation_name_row_s);
CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2);
new_items.push_back(sheet_name_row_s);
} }
} }
ebn.cleanGenericNames(); ebn.cleanGenericNames();
} }
current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor));
if(modified) if(modified)
{ {
setWindowModified(true); setWindowModified(true);
@ -355,6 +368,7 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis
return; return;
} }
bool modified = false; bool modified = false;
QList<CTableWidgetItemStore> new_items;
for(i = 0; i < allWords.size(); i++) for(i = 0; i < allWords.size(); i++)
{ {
string keyName = allWords[i]; string keyName = allWords[i];
@ -384,8 +398,14 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis
name_row->setBackgroundColor(QColor("#F75D59")); name_row->setBackgroundColor(QColor("#F75D59"));
table_editor ->setItem(currentRow, nPos, name_row); table_editor ->setItem(currentRow, nPos, name_row);
if(!modified) modified = true; if(!modified) modified = true;
CTableWidgetItemStore key_name_row_s(key_name_row, currentRow, knPos);
new_items.push_back(key_name_row_s);
CTableWidgetItemStore name_row_s(name_row, currentRow, nPos);
new_items.push_back(name_row_s);
} }
} }
current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor));
if(modified) if(modified)
{ {
setWindowModified(true); setWindowModified(true);

View file

@ -32,9 +32,9 @@
#include <QtGui/QTableWidget> #include <QtGui/QTableWidget>
#include <QtGui/QMdiSubWindow> #include <QtGui/QMdiSubWindow>
#include <QtGui/QUndoCommand> #include <QtGui/QUndoCommand>
#include <QtGui/qundostack.h> #include <QtGui/QUndoStack>
// Project includes
#include "translation_manager_editor.h" #include "translation_manager_editor.h"
#include "extract_new_sheet_names.h" #include "extract_new_sheet_names.h"
@ -70,29 +70,141 @@ private:
}; };
struct CTableWidgetItemStore
{
public:
CTableWidgetItemStore(QTableWidgetItem *item, int row, int column) :
m_item(item),
m_row(row),
m_column(column) { }
QTableWidgetItem *m_item;
int m_row;
int m_column;
};
class CUndoWorksheetCommand : public QUndoCommand class CUndoWorksheetCommand : public QUndoCommand
{ {
public: public:
CUndoWorksheetCommand(QTableWidget *table, QTableWidgetItem* item, const QString &ocontent, QUndoCommand *parent = 0) : QUndoCommand("Insert characters in cells", parent), m_table(table), m_item(item), m_ocontent(ocontent) CUndoWorksheetCommand(QTableWidget *table, QTableWidgetItem* item, const QString &ocontent, QUndoCommand *parent = 0) : QUndoCommand("Insert characters in cells", parent), m_table(table), m_item(item), m_ocontent(ocontent)
{ {
m_ccontent = m_item->text(); m_ccontent = m_ocontent;
} }
void redo() void redo()
{ {
//m_item->setText(m_ccontent); if(m_item->text() == m_ocontent)
{
m_item->setText(m_ccontent);
}
} }
void undo() void undo()
{ {
//m_item->setText(m_ocontent); if(m_item->text() != m_ocontent)
{
m_ccontent = m_item->text();
}
m_item->setText(m_ocontent);
}
private:
QTableWidget* m_table;
QTableWidgetItem* m_item;
QString m_ocontent;
QString m_ccontent;
};
class CUndoWorksheetNewCommand : public QUndoCommand
{
public:
CUndoWorksheetNewCommand(QTableWidget *table, int rowID, QUndoCommand *parent = 0) : QUndoCommand("Insert a new row", parent), m_table(table), m_rowID(rowID)
{ }
void redo()
{
m_table->setRowCount(m_rowID + 1);
for(int j = 0; j < m_table->columnCount(); j++)
{
QTableWidgetItem* item = new QTableWidgetItem();
m_table->setItem(m_rowID, j, item);
}
}
void undo()
{
m_table->removeRow(m_rowID);
}
private:
QTableWidget* m_table;
int m_rowID;
};
class CUndoWorksheetExtraction : public QUndoCommand
{
public:
CUndoWorksheetExtraction(QList<CTableWidgetItemStore> items, QTableWidget *table, QUndoCommand *parent = 0) : QUndoCommand("Word extraction", parent),
m_items(items),
m_table(table)
{ }
void redo()
{
Q_FOREACH(CTableWidgetItemStore is, m_items)
{
m_table->setItem(is.m_row, is.m_column, is.m_item);
}
}
void undo()
{
Q_FOREACH(CTableWidgetItemStore is, m_items)
{
m_table->setItem(is.m_row, is.m_column, is.m_item);
m_table->takeItem(is.m_row, is.m_column);
}
} }
private: private:
QList<CTableWidgetItemStore> m_items;
QTableWidget* m_table; QTableWidget* m_table;
QTableWidgetItem* m_item; };
QString m_ccontent;
QString m_ocontent; class CUndoWorksheetDeleteCommand : public QUndoCommand
{
public:
CUndoWorksheetDeleteCommand(QTableWidget *table, int rowID, QUndoCommand *parent = 0) : QUndoCommand("Delete row", parent), m_table(table), m_rowID(rowID)
{ }
void redo()
{
for(int i = 0; i < m_table->columnCount(); i++)
{
QTableWidgetItem* item = new QTableWidgetItem();
QTableWidgetItem* table_item = m_table->item(m_rowID, i);
item->setText(table_item->text());
m_deletedItems.push_back(item);
}
m_table->removeRow(m_rowID);
}
void undo()
{
int lastRow = m_table->rowCount();
m_table->setRowCount(m_table->rowCount() + 1);
int i = 0;
Q_FOREACH(QTableWidgetItem* item, m_deletedItems)
{
m_table->setItem(lastRow, i, item);
i++;
}
m_deletedItems.clear();
}
private:
QList<QTableWidgetItem*> m_deletedItems;
QTableWidget* m_table;
int m_rowID;
}; };
} }

View file

@ -11,11 +11,10 @@ CSourceDialog::CSourceDialog(QWidget *parent): QDialog(parent)
{ {
_ui.setupUi(this); _ui.setupUi(this);
// Set signal and slot for "OK Button" // Set signal and slot for "OK Button"
connect(_ui.ok_button, SIGNAL(clicked()), this, SLOT(OkButtonClicked())); connect(_ui.ok_button, SIGNAL(clicked()), this, SLOT(OkButtonClicked()));
// Set signal and slot for "Cancel Button" // Set signal and slot for "Cancel Button"
connect(_ui.cancel_button, SIGNAL(clicked()), this, SLOT(reject())); connect(_ui.cancel_button, SIGNAL(clicked()), this, SLOT(reject()));
_ui.listWidget->setSortingEnabled(false); _ui.listWidget->setSortingEnabled(false);
} }
void CSourceDialog::setSourceOptions(map<QListWidgetItem*,int> options) void CSourceDialog::setSourceOptions(map<QListWidgetItem*,int> options)

View file

@ -14,22 +14,21 @@ using namespace std;
namespace Plugin namespace Plugin
{ {
class CSourceDialog : public QDialog
{
Q_OBJECT
private:
Ui::SourceSelectionDialog _ui;
private Q_SLOTS: class CSourceDialog : public QDialog
{
Q_OBJECT
private:
Ui::SourceSelectionDialog _ui;
QListWidgetItem *selected_item;
private Q_SLOTS:
void OkButtonClicked();
public:
CSourceDialog(QWidget *parent = 0);
~CSourceDialog(){}
void setSourceOptions(map<QListWidgetItem*, int> options);
};
void OkButtonClicked();
public:
CSourceDialog(QWidget *parent = 0);
~CSourceDialog(){}
void setSourceOptions(map<QListWidgetItem*, int> options);
QListWidgetItem *selected_item;
};
} }

View file

@ -15,29 +15,20 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "translation_manager_main_window.h"
#include "translation_manager_constants.h"
#include "ftp_selection.h"
// Project system includes // Project system includes
#include "../core/icore.h" #include "../core/icore.h"
#include "../core/core_constants.h" #include "../core/core_constants.h"
#include "../core/imenu_manager.h" #include "../core/imenu_manager.h"
#include "../../extension_system/iplugin_spec.h" #include "../../extension_system/iplugin_spec.h"
// Qt includes // Qt includes
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include <QtGui/QLabel>
#include <QtGui/QTextEdit>
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <QtGui/QErrorMessage> #include <QtGui/QErrorMessage>
#include <QtCore/QSignalMapper> #include <QtCore/QSignalMapper>
#include <QtGui/QTableWidget> #include <QtGui/QTableWidget>
#include <QtGui/QTableWidgetItem> #include <QtGui/QTableWidgetItem>
#include <QtGui/QListWidget>
#include <QtGui/QDockWidget>
#include <QtCore/QSize>
#include <QtGui/QGridLayout>
#include <QtGui/QMdiSubWindow> #include <QtGui/QMdiSubWindow>
#include <QtGui/QFileDialog> #include <QtGui/QFileDialog>
#include <QtCore/QResource> #include <QtCore/QResource>
@ -46,6 +37,11 @@
#include <QtCore/QEvent> #include <QtCore/QEvent>
#include <QtGui/QCloseEvent> #include <QtGui/QCloseEvent>
// Plugin includes
#include "translation_manager_main_window.h"
#include "translation_manager_constants.h"
#include "ftp_selection.h"
namespace Plugin namespace Plugin
{ {
@ -449,13 +445,6 @@ void CMainWindow::readSettings()
settings->endGroup(); settings->endGroup();
} }
void CMainWindow::debug(QString text)
{
QErrorMessage error_settings;
error_settings.showMessage(text);
error_settings.exec();
}
bool CMainWindow::verifySettings() bool CMainWindow::verifySettings()
{ {
bool count_errors = false; bool count_errors = false;

View file

@ -19,7 +19,7 @@
#ifndef MAIN_WINDOW_H #ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H #define MAIN_WINDOW_H
// Project includes // Project system includes
#include "../core/icore_listener.h" #include "../core/icore_listener.h"
// Nel includes // Nel includes
@ -33,14 +33,13 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtGui/QUndoStack> #include <QtGui/QUndoStack>
#include <QtGui/QMainWindow> #include <QtGui/QMainWindow>
#include <QtGui/QGridLayout>
#include <QtGui/QTableWidget> #include <QtGui/QTableWidget>
#include <QtGui/QMenu> #include <QtGui/QMenu>
#include <QtGui/QMdiSubWindow> #include <QtGui/QMdiSubWindow>
#include <QtCore/QSignalMapper> #include <QtCore/QSignalMapper>
#include <QtGui/QDialog> #include <QtGui/QDialog>
// Plugin includes
#include "translation_manager_editor.h" #include "translation_manager_editor.h"
#include "source_selection.h" #include "source_selection.h"
#include "ui_translation_manager_main_window.h" #include "ui_translation_manager_main_window.h"
@ -63,7 +62,6 @@ public:
virtual ~CMainWindow() {} virtual ~CMainWindow() {}
QUndoStack *m_undoStack; QUndoStack *m_undoStack;
private: private:
Ui::CMainWindow _ui; Ui::CMainWindow _ui;
// actions // actions
QAction *openAct; QAction *openAct;
@ -90,7 +88,6 @@ private Q_SLOTS:
void setActiveSubWindow(QWidget *window); void setActiveSubWindow(QWidget *window);
void updateWindowsList(); void updateWindowsList();
void mergeSingleFile(); void mergeSingleFile();
void debug(QString text); // TODO
private: private:
void openWorkFile(QString file); void openWorkFile(QString file);
void updateToolbar(QMdiSubWindow *window); void updateToolbar(QMdiSubWindow *window);