Changed: #1307 Added support for unicode format on editors

This commit is contained in:
cemycc 2011-08-17 11:54:00 +03:00
parent cd410ce586
commit 3825c9f553
3 changed files with 18 additions and 10 deletions

View file

@ -27,7 +27,8 @@
#include <QtCore/QByteArray> #include <QtCore/QByteArray>
#include <QtCore/qtextcodec.h> #include <QtCore/qtextcodec.h>
#include <QtGui/QTextCursor> #include <QtGui/QTextCursor>
#include <QtCore/qtextstream.h>
#include <QtCore/qtextcodec.h>
// Project includes // Project includes
#include "editor_phrase.h" #include "editor_phrase.h"
@ -51,8 +52,9 @@ void CEditorPhrase::open(QString filename)
// read the file content // read the file content
QFile file(filename); QFile file(filename);
file.open(QIODevice::ReadOnly | QIODevice::Text); file.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&file);
// set the file content to the text edit // set the file content to the text edit
QByteArray data = file.readAll(); QString data = in.readAll();
text_edit->append(data); text_edit->append(data);
// window settings // window settings
setCurrentFile(filename); setCurrentFile(filename);
@ -111,6 +113,8 @@ void CEditorPhrase::save()
QFile file(current_file); QFile file(current_file);
file.open(QIODevice::WriteOnly | QIODevice::Text); file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file); QTextStream out(&file);
out.setCodec("UTF-8");
out.setGenerateByteOrderMark(true);
out<<text_edit->toPlainText(); out<<text_edit->toPlainText();
setCurrentFile(current_file); setCurrentFile(current_file);
} }
@ -120,6 +124,8 @@ void CEditorPhrase::saveAs(QString filename)
QFile file(filename); QFile file(filename);
file.open(QIODevice::WriteOnly | QIODevice::Text); file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file); QTextStream out(&file);
out.setCodec("UTF-8");
out.setGenerateByteOrderMark(true);
out<<text_edit->toPlainText(); out<<text_edit->toPlainText();
current_file = filename; current_file = filename;
setCurrentFile(current_file); setCurrentFile(current_file);

View file

@ -1,4 +1,4 @@
// Translation Manager Plugin - OVQT Plugin <http://dev.ryzom.com/projects/nel/> // Translation Manager Plugin - OVQT Plugin <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited // Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Emanuel Costea <cemycc@gmail.com> // Copyright (C) 2011 Emanuel Costea <cemycc@gmail.com>
// //
@ -82,7 +82,7 @@ void CEditorWorksheet::open(QString filename)
} else { } else {
QTableWidgetItem *row = new QTableWidgetItem(); QTableWidgetItem *row = new QTableWidgetItem();
ucstring row_value = wk_file.getData(i, j); 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) if(hasHashValue)
{ {
table_editor->setItem(i - 1, j - 1, row); table_editor->setItem(i - 1, j - 1, row);
@ -158,7 +158,7 @@ void CEditorWorksheet::save()
ucstring colname; ucstring colname;
uint rowIdf; uint rowIdf;
QString tvalueQt = table_editor->item(i, j)->text(); QString tvalueQt = table_editor->item(i, j)->text();
tvalue = ucstring(tvalueQt.toStdString()); tvalue.fromUtf8(std::string(tvalueQt.toUtf8()));
colname = wk_file.getData(0, j + colIdx); colname = wk_file.getData(0, j + colIdx);
rowIdf = uint(i + 1); rowIdf = uint(i + 1);
@ -166,10 +166,10 @@ void CEditorWorksheet::save()
{ {
if(wk_file.getData(i + 1, j + colIdx) != tvalue) // verify the current value 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 { } 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(); rowIdx = new_file.size();
new_file.resize(new_file.size() + 1); new_file.resize(new_file.size() + 1);
ucstring tvalue;
for(int j = 0; j < table_editor->columnCount(); j++) for(int j = 0; j < table_editor->columnCount(); j++)
{ {
QTableWidgetItem* item = table_editor->item(i, 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) if(hasHashValue)

View file

@ -37,7 +37,7 @@
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QEvent> #include <QtCore/QEvent>
#include <QtGui/QCloseEvent> #include <QtGui/QCloseEvent>
#include <QtGui/qfont.h>
// Plugin includes // Plugin includes
#include "translation_manager_main_window.h" #include "translation_manager_main_window.h"
#include "translation_manager_constants.h" #include "translation_manager_constants.h"