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

This commit is contained in:
cemycc 2011-07-13 19:47:15 +03:00
parent 65d3ff8966
commit c2737cbd21
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
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "editor_worksheet.h"
#include <set>
// Qt includes
#include <QtGui/QErrorMessage>
#include <QtGui/QTableWidgetItem>
@ -24,8 +22,11 @@
#include <QtGui/QMessageBox>
#include <QtGui/QCloseEvent>
// Project includes
#include "editor_worksheet.h"
#include "extract_bot_names.h"
#include "translation_manager_constants.h"
#include <set>
using namespace std;
@ -206,12 +207,7 @@ void CEditorWorksheet::saveAs(QString filename)
void CEditorWorksheet::insertRow()
{
int last_row = table_editor->rowCount();
table_editor->setRowCount(last_row + 1);
for(int j = 0; j < table_editor->columnCount(); j++)
{
QTableWidgetItem* item = new QTableWidgetItem();
table_editor->setItem(last_row, j, item);
}
current_stack->push(new CUndoWorksheetNewCommand(table_editor, last_row));
}
void CEditorWorksheet::deleteRow()
@ -223,10 +219,9 @@ void CEditorWorksheet::deleteRow()
msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec();
if(ret == QMessageBox::Yes)
{
table_editor->removeRow(selected_row);
current_stack->push(new CUndoWorksheetDeleteCommand(table_editor, selected_row));
}
table_editor->clearFocus();
@ -237,6 +232,7 @@ void CEditorWorksheet::deleteRow()
void CEditorWorksheet::worksheetEditorCellEntered(QTableWidgetItem * item)
{
temp_content = item->text();
current_stack->push(new CUndoWorksheetCommand(table_editor, item, temp_content));
}
void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item)
@ -250,9 +246,12 @@ void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item)
setWindowModified(true);
}
void CEditorWorksheet::extractBotNames(list<string> filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig)
{
bool modified = false;
QList<CTableWidgetItemStore> new_items;
ExtractBotNames ebn;
ebn.setRequiredSettings(filters, level_design_path);
ebn.extractBotNamesFromPrimitives(ligoConfig);
@ -281,6 +280,12 @@ void CEditorWorksheet::extractBotNames(list<string> filters, string level_design
sheet_name_row->setBackgroundColor(QColor("#F75D59"));
table_editor ->setItem(currentRow, 2, sheet_name_row);
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();
@ -310,10 +315,18 @@ void CEditorWorksheet::extractBotNames(list<string> filters, string level_design
sheet_name_row->setBackgroundColor(QColor("#F75D59"));
table_editor ->setItem(currentRow, 2, sheet_name_row);
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();
}
current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor));
if(modified)
{
setWindowModified(true);
@ -355,6 +368,7 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis
return;
}
bool modified = false;
QList<CTableWidgetItemStore> new_items;
for(i = 0; i < allWords.size(); i++)
{
string keyName = allWords[i];
@ -384,8 +398,14 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis
name_row->setBackgroundColor(QColor("#F75D59"));
table_editor ->setItem(currentRow, nPos, name_row);
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)
{
setWindowModified(true);

View file

@ -32,9 +32,9 @@
#include <QtGui/QTableWidget>
#include <QtGui/QMdiSubWindow>
#include <QtGui/QUndoCommand>
#include <QtGui/qundostack.h>
#include <QtGui/QUndoStack>
// Project includes
#include "translation_manager_editor.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
{
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)
{
m_ccontent = m_item->text();
m_ccontent = m_ocontent;
}
void redo()
{
//m_item->setText(m_ccontent);
if(m_item->text() == m_ocontent)
{
m_item->setText(m_ccontent);
}
}
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:
QList<CTableWidgetItemStore> m_items;
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);
// Set signal and slot for "OK Button"
connect(_ui.ok_button, SIGNAL(clicked()), this, SLOT(OkButtonClicked()));
// Set signal and slot for "Cancel Button"
connect(_ui.cancel_button, SIGNAL(clicked()), this, SLOT(reject()));
_ui.listWidget->setSortingEnabled(false);
// Set signal and slot for "Cancel Button"
connect(_ui.cancel_button, SIGNAL(clicked()), this, SLOT(reject()));
_ui.listWidget->setSortingEnabled(false);
}
void CSourceDialog::setSourceOptions(map<QListWidgetItem*,int> options)

View file

@ -14,22 +14,21 @@ using namespace std;
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
// 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
#include "../core/icore.h"
#include "../core/core_constants.h"
#include "../core/imenu_manager.h"
#include "../../extension_system/iplugin_spec.h"
// Qt includes
#include <QtGui/QWidget>
#include <QtGui/QMessageBox>
#include <QtGui/QLabel>
#include <QtGui/QTextEdit>
#include <QtCore/QSettings>
#include <QtGui/QErrorMessage>
#include <QtCore/QSignalMapper>
#include <QtGui/QTableWidget>
#include <QtGui/QTableWidgetItem>
#include <QtGui/QListWidget>
#include <QtGui/QDockWidget>
#include <QtCore/QSize>
#include <QtGui/QGridLayout>
#include <QtGui/QMdiSubWindow>
#include <QtGui/QFileDialog>
#include <QtCore/QResource>
@ -46,6 +37,11 @@
#include <QtCore/QEvent>
#include <QtGui/QCloseEvent>
// Plugin includes
#include "translation_manager_main_window.h"
#include "translation_manager_constants.h"
#include "ftp_selection.h"
namespace Plugin
{
@ -449,13 +445,6 @@ void CMainWindow::readSettings()
settings->endGroup();
}
void CMainWindow::debug(QString text)
{
QErrorMessage error_settings;
error_settings.showMessage(text);
error_settings.exec();
}
bool CMainWindow::verifySettings()
{
bool count_errors = false;

View file

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