From b83fb39a9431172a60db1af01439cb83bc89bb21 Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 17 Aug 2011 11:54:00 +0300 Subject: [PATCH] Changed: #1307 Added support for unicode format on editors --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_phrase.cpp | 10 ++++++++-- .../translation_manager/editor_worksheet.cpp | 16 +++++++++------- .../translation_manager_main_window.cpp | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp index 6033ecb38..696bd41b1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp @@ -27,7 +27,8 @@ #include #include #include - +#include +#include // Project includes #include "editor_phrase.h" @@ -51,8 +52,9 @@ void CEditorPhrase::open(QString filename) // read the file content QFile file(filename); file.open(QIODevice::ReadOnly | QIODevice::Text); + QTextStream in(&file); // set the file content to the text edit - QByteArray data = file.readAll(); + QString data = in.readAll(); text_edit->append(data); // window settings setCurrentFile(filename); @@ -111,6 +113,8 @@ void CEditorPhrase::save() QFile file(current_file); file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); + out.setCodec("UTF-8"); + out.setGenerateByteOrderMark(true); out<toPlainText(); setCurrentFile(current_file); } @@ -120,6 +124,8 @@ void CEditorPhrase::saveAs(QString filename) QFile file(filename); file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); + out.setCodec("UTF-8"); + out.setGenerateByteOrderMark(true); out<toPlainText(); current_file = filename; setCurrentFile(current_file); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp index ce02837c8..6e71a9290 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp @@ -1,4 +1,4 @@ -// Translation Manager Plugin - OVQT Plugin +// Translation Manager Plugin - OVQT Plugin // Copyright (C) 2010 Winch Gate Property Limited // Copyright (C) 2011 Emanuel Costea // @@ -82,7 +82,7 @@ void CEditorWorksheet::open(QString filename) } else { QTableWidgetItem *row = new QTableWidgetItem(); ucstring row_value = wk_file.getData(i, j); - row->setText(tr(row_value.toString().c_str())); + row->setText(QString::fromUtf8(row_value.toUtf8().c_str())); if(hasHashValue) { table_editor->setItem(i - 1, j - 1, row); @@ -157,8 +157,8 @@ void CEditorWorksheet::save() ucstring tvalue; ucstring colname; uint rowIdf; - QString tvalueQt = table_editor->item(i, j)->text(); - tvalue = ucstring(tvalueQt.toStdString()); + QString tvalueQt = table_editor->item(i, j)->text(); + tvalue.fromUtf8(std::string(tvalueQt.toUtf8())); colname = wk_file.getData(0, j + colIdx); rowIdf = uint(i + 1); @@ -166,10 +166,10 @@ void CEditorWorksheet::save() { if(wk_file.getData(i + 1, j + colIdx) != tvalue) // verify the current value { - wk_file.setData(i + 1, j + colIdx, tvalue); // change the value + wk_file.setData(i + 1, j + colIdx, tvalue); // change the value } } else { - wk_file.setData(i + 1, j + colIdx, tvalue); // insert the value + wk_file.setData(i + 1, j + colIdx, tvalue); // insert the value } } } @@ -209,10 +209,12 @@ void CEditorWorksheet::saveAs(QString filename) { rowIdx = new_file.size(); new_file.resize(new_file.size() + 1); + ucstring tvalue; for(int j = 0; j < table_editor->columnCount(); j++) { QTableWidgetItem* item = table_editor->item(i, j); - new_file.setData(rowIdx, j + colIdx, ucstring(item->text().toStdString())); + tvalue.fromUtf8(std::string(item->text().toUtf8())); + new_file.setData(rowIdx, j + colIdx, tvalue); } } if(hasHashValue) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp index 5856f9c7d..365304c5b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp @@ -37,7 +37,7 @@ #include #include #include - +#include // Plugin includes #include "translation_manager_main_window.h" #include "translation_manager_constants.h"