708 lines
22 KiB
C++
708 lines
22 KiB
C++
#include "sdictionary.h"
|
|
#include <QGroupBox>
|
|
#include <QButtonGroup>
|
|
#include <QLabel>
|
|
#include <QSqlQuery>
|
|
#include <QDebug>
|
|
#include <QFile>
|
|
#include <QFileDialog>
|
|
#include <QTextCodec>
|
|
#include <QMessageBox>
|
|
#include <QSqlError>
|
|
#include <QMenuBar>
|
|
#include <QInputDialog>
|
|
#include "../Json/sjson.h"
|
|
#include "../common.h"
|
|
#include <QProcess>
|
|
/*
|
|
QSqlDatabase dbWeb = QSqlDatabase::addDatabase("QMYSQL");
|
|
dbWeb.setHostName("db.big-bird.co.kr");
|
|
dbWeb.setUserName("concepters");
|
|
dbWeb.setPassword("con97996655");
|
|
dbWeb.setDatabaseName("dbconcepters");
|
|
*/
|
|
|
|
#define D_NOT_SELECT -1
|
|
|
|
#define SAFE_DELETE(x) if(x != NULL) { delete x; x = NULL; }
|
|
#define SAFE_DELETEARRAY(x) if(x != NULL) { delete [] x; x = NULL; }
|
|
#define SAFE_RELEASE(x) if(x != NULL) { x->Release(); x = NULL; }
|
|
|
|
SDictionary::SDictionary(QWidget *parent)
|
|
: QWidget(parent)
|
|
{
|
|
|
|
if(!setListMorphere(m_strlistMorphere, m_strlistMorphereko))
|
|
{
|
|
m_strlistMorphere << "NNG" <<"NNP"<<"NNB"<<"NNBC"<<"NR"<<"NP"<<"VV"<<"VA"<<"VX"<<"VCP"<<"VCN"<<"MM"<<"MAG"<<"MAJ"<<"IC"<<"JKS"<<"JKC"<<"JKG"<<"JKO"<<"JKB"<<"JKV"<<"JKQ"<<"JX"<<"JC"<<"EP"<<"EF"<<"EC"<<"ETN"<<"ETM"<<"XPN"<<"XSN"<<"XSV"<<"XSA"<<"XR"<<"SF"<<"SE"<<"SSO"<<"SSC"<<"SC"<<"SY"<<"SL"<<"SH"<<"SN";
|
|
m_strlistMorphereko << "NNG" <<"NNP"<<"NNB"<<"NNBC"<<"NR"<<"NP"<<"VV"<<"VA"<<"VX"<<"VCP"<<"VCN"<<"MM"<<"MAG"<<"MAJ"<<"IC"<<"JKS"<<"JKC"<<"JKG"<<"JKO"<<"JKB"<<"JKV"<<"JKQ"<<"JX"<<"JC"<<"EP"<<"EF"<<"EC"<<"ETN"<<"ETM"<<"XPN"<<"XSN"<<"XSV"<<"XSA"<<"XR"<<"SF"<<"SE"<<"SSO"<<"SSC"<<"SC"<<"SY"<<"SL"<<"SH"<<"SN";
|
|
}
|
|
|
|
// qDebug() << m_strlistMorphere.size();
|
|
// qDebug() << m_strlistMorphereko.size();
|
|
|
|
if(!setListMorphereHeader(m_strListHead))
|
|
{
|
|
m_strListHead << "Keyword" << "LeftContextID" << "RightContextID" << "Cost" << "WordClass" << "SubWordClass" << "Final Consonant" << "Keyword" << "Compound" << "etc" << "etc" << "etc";
|
|
}
|
|
QVBoxLayout *vMainLayout = new QVBoxLayout;
|
|
vMainLayout->addWidget(setMenuWidget());
|
|
vMainLayout->setAlignment(Qt::AlignVCenter);
|
|
QVBoxLayout *vboxlayout = new QVBoxLayout;
|
|
QHBoxLayout *hboxlayout = new QHBoxLayout;
|
|
|
|
/*
|
|
QGroupBox *gBox = setMorphereList();
|
|
QGroupBox *gDate = setDate();
|
|
QGroupBox *gFilter = setFilter();
|
|
QGroupBox *gOther = setOther();
|
|
QGroupBox *gSort = setSort();
|
|
QGroupBox *gDictionary = setDictionary();
|
|
*/
|
|
|
|
QGroupBox *gCostCalculator = setCostCalculatorWidgets();
|
|
QGroupBox *gCsvtoDic = setCsvToDicWidgets();
|
|
QGroupBox *gAddKeyword = setAddKeywordWidgets();
|
|
QGroupBox *gFileName = setFileNameWidgets();
|
|
|
|
hboxlayout->addWidget(gCostCalculator,3);
|
|
hboxlayout->addWidget(gCsvtoDic,3);
|
|
vboxlayout->addWidget(gAddKeyword,2);
|
|
vboxlayout->addWidget(gFileName, 0);
|
|
vMainLayout->addLayout(hboxlayout, 2);
|
|
vMainLayout->addLayout(vboxlayout, 2);
|
|
|
|
|
|
/*
|
|
m_ptwData = new QTabWidget;
|
|
m_ptwData->setTabsClosable(true);
|
|
connect(m_ptwData,SIGNAL(tabCloseRequested(int)),this,SLOT(CloseTab(int)));
|
|
connect(m_ptwData,SIGNAL(tabBarDoubleClicked(int)),this,SLOT(DoubleClickTab(int)));
|
|
AddTable("Start");
|
|
*/
|
|
m_pstTable = new STable;
|
|
|
|
|
|
vMainLayout->addWidget(m_pstTable, 13);
|
|
setLayout(vMainLayout);
|
|
FileNew();
|
|
}
|
|
|
|
|
|
QGroupBox *SDictionary::setFileNameWidgets()
|
|
{
|
|
QHBoxLayout *hlayout = new QHBoxLayout;
|
|
|
|
m_plFileName = new QLabel;
|
|
hlayout->addWidget(m_plFileName);
|
|
|
|
QGroupBox *groupBox = new QGroupBox(tr("File Name"));
|
|
|
|
groupBox->setCheckable(true);
|
|
groupBox->setLayout(hlayout);
|
|
return groupBox;
|
|
|
|
}
|
|
|
|
QGroupBox *SDictionary::setCostCalculatorWidgets()
|
|
{
|
|
QHBoxLayout *hlayout1 = new QHBoxLayout;
|
|
QHBoxLayout *hlayout2 = new QHBoxLayout;
|
|
QHBoxLayout *hlayout3 = new QHBoxLayout;
|
|
QVBoxLayout *vlayout = new QVBoxLayout;
|
|
|
|
m_pleCCOpen = new QLineEdit;
|
|
m_pleCCSave = new QLineEdit;
|
|
|
|
QPushButton *p_pbOpen = new QPushButton;
|
|
QPushButton *p_pbSave = new QPushButton;
|
|
QPushButton *p_pbCalc = new QPushButton;
|
|
|
|
p_pbOpen->setText("Open");
|
|
p_pbSave->setText("Save");
|
|
p_pbCalc->setText("Calculate");
|
|
|
|
hlayout1->addWidget(new QLabel("Open : "));
|
|
hlayout1->addWidget(m_pleCCOpen);
|
|
hlayout1->addWidget(p_pbOpen);
|
|
|
|
hlayout2->addWidget(new QLabel("Save : "));
|
|
hlayout2->addWidget(m_pleCCSave);
|
|
hlayout2->addWidget(p_pbSave);
|
|
|
|
hlayout3->addWidget(p_pbCalc);
|
|
|
|
vlayout->addLayout(hlayout1);
|
|
//vlayout->addLayout(hlayout2);
|
|
vlayout->addLayout(hlayout3);
|
|
|
|
QGroupBox *groupBox = new QGroupBox(tr("Calculate Cost"));
|
|
connect(p_pbOpen, SIGNAL(released()),this, SLOT(OpenCalc()));
|
|
connect(p_pbCalc, SIGNAL(released()),this, SLOT(ExecCalc()));
|
|
|
|
|
|
groupBox->setCheckable(true);
|
|
groupBox->setLayout(vlayout);
|
|
return groupBox;
|
|
}
|
|
|
|
|
|
|
|
QGroupBox *SDictionary::setCsvToDicWidgets()
|
|
{
|
|
QHBoxLayout *hlayout1 = new QHBoxLayout;
|
|
QHBoxLayout *hlayout2 = new QHBoxLayout;
|
|
QHBoxLayout *hlayout3 = new QHBoxLayout;
|
|
QVBoxLayout *vlayout = new QVBoxLayout;
|
|
|
|
m_pleCsvToDicOpen = new QLineEdit;
|
|
m_pleCsvToDicSave = new QLineEdit;
|
|
|
|
QPushButton *p_pbOpen = new QPushButton;
|
|
QPushButton *p_pbSave = new QPushButton;
|
|
QPushButton *p_pbCalc = new QPushButton;
|
|
|
|
p_pbOpen->setText("Open");
|
|
p_pbSave->setText("Save");
|
|
p_pbCalc->setText("Convert CSV to DIC");
|
|
|
|
hlayout1->addWidget(new QLabel("Open : "));
|
|
hlayout1->addWidget(m_pleCsvToDicOpen);
|
|
hlayout1->addWidget(p_pbOpen);
|
|
|
|
hlayout2->addWidget(new QLabel("Save : "));
|
|
hlayout2->addWidget(m_pleCsvToDicSave);
|
|
hlayout2->addWidget(p_pbSave);
|
|
|
|
hlayout3->addWidget(p_pbCalc);
|
|
|
|
vlayout->addLayout(hlayout1);
|
|
//vlayout->addLayout(hlayout2);
|
|
vlayout->addLayout(hlayout3);
|
|
|
|
QGroupBox *groupBox = new QGroupBox(tr("Convert CSV to DIC"));
|
|
connect(p_pbOpen, SIGNAL(released()),this, SLOT(OpenCsv()));
|
|
connect(p_pbCalc, SIGNAL(released()),this, SLOT(ExecCsv()));
|
|
|
|
|
|
groupBox->setCheckable(true);
|
|
|
|
groupBox->setLayout(vlayout);
|
|
return groupBox;
|
|
}
|
|
|
|
|
|
void SDictionary::ExecCalc()
|
|
{
|
|
QString strFilename = QFileDialog::getSaveFileName(0,"Exoprt file",QDir::currentPath(),
|
|
"csv files (*.csv);;All files (*.*)",new QString("Text files (*.csv)"));
|
|
if (strFilename.toLower().right(4) != QString(".csv"))
|
|
strFilename += ".csv";
|
|
|
|
QProcess::startDetached("mecab-dict-index",QStringList() << "-m" << "dic/model.def" << "-d" << "dic" << "-u" << strFilename << "-f" << "utf-8" << "-t" << "utf-8" << "-a" << m_pleCCOpen->text());
|
|
|
|
}
|
|
|
|
|
|
void SDictionary::ExecCsv()
|
|
{
|
|
QString strFilename = QFileDialog::getSaveFileName(0,"Exoprt file",QDir::currentPath(),
|
|
"Dic files (*.dic);;All files (*.*)",new QString("Dic files (*.dic)"));
|
|
if (strFilename.toLower().right(4) != QString(".dic"))
|
|
strFilename += ".dic";
|
|
|
|
QProcess::startDetached("mecab-dict-index",QStringList() << "-d" << "dic" << "-u" << strFilename << "-f" << "utf-8" << "-t" << "utf-8" << m_pleCsvToDicOpen->text());
|
|
}
|
|
|
|
|
|
|
|
void SDictionary::OpenCsv()
|
|
{
|
|
QString strFilename = QFileDialog::getOpenFileName(0,"Exoprt file",QDir::currentPath(),
|
|
"csv files (*.csv);;All files (*.*)",new QString("Text files (*.csv)"));
|
|
if (strFilename.toLower().right(4) != QString(".csv"))
|
|
strFilename += ".csv";
|
|
QFile file(strFilename);
|
|
if(!file.open(QFile::ReadOnly | QFile::Text)) return;
|
|
m_pleCsvToDicOpen->setText(strFilename) ;
|
|
file.close();
|
|
}
|
|
|
|
void SDictionary::OpenCalc()
|
|
{
|
|
QString strFilename = QFileDialog::getOpenFileName(0,"Exoprt file",QDir::currentPath(),
|
|
"csv files (*.csv);;All files (*.*)",new QString("Text files (*.csv)"));
|
|
if (strFilename.toLower().right(4) != QString(".csv"))
|
|
strFilename += ".csv";
|
|
QFile file(strFilename);
|
|
if(!file.open(QFile::ReadOnly | QFile::Text)) return;
|
|
m_pleCCOpen->setText(strFilename) ;
|
|
file.close();
|
|
}
|
|
|
|
QGroupBox *SDictionary::setAddKeywordWidgets()
|
|
{
|
|
QHBoxLayout *hlayout = new QHBoxLayout;
|
|
|
|
m_pleAddKeyword = new QLineEdit;
|
|
m_pleAddMorphere = new QLineEdit;
|
|
m_pleAddPriority = new QLineEdit;
|
|
m_cbAddMorphere = new QComboBox;
|
|
m_cbAddFinalConsonant = new QComboBox;
|
|
|
|
|
|
for(int i = 0; i < m_strlistMorphere.count(); i++)
|
|
{
|
|
m_cbAddMorphere->addItem(m_strlistMorphereko[i], m_strlistMorphere[i]);
|
|
}
|
|
|
|
m_cbAddFinalConsonant->addItem("True","T");
|
|
m_cbAddFinalConsonant->addItem("False","F");
|
|
m_pleAddMorphere->setText(m_cbAddMorphere->currentData(Qt::UserRole).toString());
|
|
hlayout->addWidget(new QLabel("Keyword:"));
|
|
hlayout->addWidget(m_pleAddKeyword);
|
|
hlayout->addWidget(new QLabel("Morphere:"));
|
|
hlayout->addWidget(m_cbAddMorphere);
|
|
hlayout->addWidget(m_pleAddMorphere);
|
|
hlayout->addWidget(new QLabel("Last Consonant:"));
|
|
hlayout->addWidget(m_cbAddFinalConsonant);
|
|
hlayout->addWidget(new QLabel("Cost:"));
|
|
hlayout->addWidget(m_pleAddPriority);
|
|
|
|
|
|
connect(m_cbAddMorphere, SIGNAL(currentIndexChanged(int)),this, SLOT(MorphereChanged()));
|
|
|
|
|
|
QVBoxLayout *vlayout = new QVBoxLayout;
|
|
|
|
QPushButton *ppbAdd = new QPushButton;
|
|
ppbAdd->setText("Add");
|
|
|
|
|
|
connect(ppbAdd, SIGNAL(released()),this, SLOT(AddKeyword()));
|
|
|
|
|
|
vlayout->addLayout(hlayout);
|
|
vlayout->addWidget(ppbAdd);
|
|
|
|
QGroupBox *groupBox = new QGroupBox(tr("ADD Keyword"));
|
|
|
|
groupBox->setCheckable(true);
|
|
|
|
groupBox->setLayout(vlayout);
|
|
groupBox->setChecked(true);
|
|
return groupBox;
|
|
}
|
|
|
|
|
|
void SDictionary::AddKeyword()
|
|
{
|
|
if(m_pleAddKeyword->text().length() < 1)
|
|
return;
|
|
|
|
|
|
m_pstTable->setRowCount(m_pstTable->rowCount() + 1);
|
|
|
|
QStringList strList;
|
|
|
|
strList << m_pleAddKeyword->text() << "" << "";
|
|
if(m_pleAddPriority->text().length() < 1)
|
|
strList << "";
|
|
else
|
|
strList << m_pleAddPriority->text();
|
|
|
|
strList << m_pleAddMorphere->text();
|
|
strList << "*";
|
|
strList << m_cbAddFinalConsonant->currentData(Qt::UserRole).toString();
|
|
strList << m_pleAddKeyword->text();
|
|
strList << "*" << "*" << "*" << "*";
|
|
|
|
|
|
for(int i = 0; i < strList.length(); i++)
|
|
{
|
|
m_pstTable->setItem(m_pstTable->rowCount()-1,i,new QTableWidgetItem(strList.at(i)));
|
|
}
|
|
m_pleAddKeyword->clear();
|
|
m_pleAddPriority->clear();
|
|
|
|
}
|
|
|
|
void SDictionary::MorphereChanged()
|
|
{
|
|
m_pleAddMorphere->setText(m_cbAddMorphere->currentData(Qt::UserRole).toString());
|
|
}
|
|
|
|
SDictionary::~SDictionary()
|
|
{
|
|
}
|
|
QMenuBar *SDictionary::setMenuWidget()
|
|
{
|
|
QMenuBar *pMenuBar = new QMenuBar();
|
|
{
|
|
QMenu *pFile = pMenuBar->addMenu("File");
|
|
connect(pFile->addAction("New"), SIGNAL(triggered()), this, SLOT(FileNew()));
|
|
pFile->addSeparator();
|
|
connect(pFile->addAction("Open"),SIGNAL(triggered()), this, SLOT(FileOpen()));
|
|
pFile->addSeparator();
|
|
connect(pFile->addAction("Save"),SIGNAL(triggered()), this, SLOT(FileSave()));
|
|
connect(pFile->addAction("Save As"),SIGNAL(triggered()), this, SLOT(FileSaveAs()));
|
|
pFile->addSeparator();
|
|
connect(pFile->addAction("Close"),SIGNAL(triggered()), this, SLOT(FileClose()));
|
|
pFile->addSeparator();
|
|
//connect(pFile->addAction("Close"),SIGNAL(triggered()), this, SLOT(FileClose()));
|
|
//connect(pFile->addAction("CSV Import"), SIGNAL(triggered()), this, SLOT(FileImport()));
|
|
//connect(pFile->addAction("CSV Export"), SIGNAL(triggered()), this, SLOT(FileExport()));
|
|
//pFile->addSeparator();
|
|
connect(pFile->addAction("Exit"), SIGNAL(triggered()), this, SLOT(FileExit()));
|
|
}
|
|
return pMenuBar;
|
|
}
|
|
|
|
void SDictionary::FileNew()
|
|
{
|
|
if(m_strFileName.isEmpty())
|
|
{
|
|
if(m_pstTable->rowCount() > 0)
|
|
{
|
|
QMessageBox msg;
|
|
msg.setText("Please choose...");
|
|
msg.setModal(true);
|
|
QPushButton *pbNew = msg.addButton("New",QMessageBox::ActionRole);
|
|
QPushButton *pbSave = msg.addButton("Save",QMessageBox::ActionRole);
|
|
QPushButton *pbCancel = msg.addButton("Cancel",QMessageBox::ActionRole);
|
|
msg.exec();
|
|
if (msg.clickedButton() == pbNew){ }
|
|
else if (msg.clickedButton() == pbSave){ if(!FileSave()) return; }
|
|
else if (msg.clickedButton() == pbCancel) return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QMessageBox msg;
|
|
msg.setText("Please choose...");
|
|
msg.setModal(true);
|
|
QPushButton *pbNew = msg.addButton("New",QMessageBox::ActionRole);
|
|
QPushButton *pbSave = msg.addButton("Save",QMessageBox::ActionRole);
|
|
QPushButton *pbSaveAs = msg.addButton("Save As",QMessageBox::ActionRole);
|
|
QPushButton *pbCancel = msg.addButton("Cancel",QMessageBox::ActionRole);
|
|
msg.exec();
|
|
if (msg.clickedButton() == pbNew){ }
|
|
else if (msg.clickedButton() == pbSave) { if(!FileSave()) return; }
|
|
else if (msg.clickedButton() == pbSaveAs) { if(!FileSaveAs()) return; }
|
|
else if (msg.clickedButton() == pbCancel) return;
|
|
}
|
|
|
|
m_pstTable->clear();
|
|
m_pstTable->setRowCount(0);
|
|
m_pstTable->setColumnCount(m_strListHead.size());
|
|
int i = 0;
|
|
foreach(QString str, m_strListHead)
|
|
m_pstTable->setHorizontalHeaderItem(i++,new QTableWidgetItem(str));
|
|
|
|
m_strFileName.clear();
|
|
m_plFileName->setText(m_strFileName);
|
|
}
|
|
|
|
/*
|
|
void SDictionary::MSGBox()
|
|
{
|
|
if(!m_strFileName.isEmpty())
|
|
{
|
|
QMessageBox msg;
|
|
msg.setText("Please choose...");
|
|
msg.setModal(true);
|
|
QPushButton *pbAll = msg.addButton("All",QMessageBox::ActionRole);
|
|
QPushButton *pbBody = msg.addButton("Body",QMessageBox::ActionRole);
|
|
QPushButton *pbReply = msg.addButton("Reply",QMessageBox::ActionRole);
|
|
msg.exec();
|
|
if (msg.clickedButton() == pbAll) DataReload("data_" + item->data(Qt::UserRole).toString(),STable::E_ARTICLE_ALL);
|
|
else if (msg.clickedButton() == pbBody) DataReload("data_" + item->data(Qt::UserRole).toString(),STable::E_ARTICLE_BODY);
|
|
else if (msg.clickedButton() == pbReply) DataReload("data_" + item->data(Qt::UserRole).toString(),STable::E_ARTICLE_REPLY);
|
|
}
|
|
}
|
|
|
|
*/
|
|
|
|
void SDictionary::FileOpen()
|
|
{
|
|
if(m_strFileName.isEmpty())
|
|
{
|
|
if(m_pstTable->rowCount() > 0)
|
|
{
|
|
QMessageBox msg;
|
|
msg.setText("Please choose...");
|
|
msg.setModal(true);
|
|
QPushButton *pbOpen = msg.addButton("Open",QMessageBox::ActionRole);
|
|
QPushButton *pbSave = msg.addButton("Save",QMessageBox::ActionRole);
|
|
QPushButton *pbCancel = msg.addButton("Cancel",QMessageBox::ActionRole);
|
|
msg.exec();
|
|
if (msg.clickedButton() == pbOpen){ }
|
|
else if (msg.clickedButton() == pbSave) { if(!FileSave()) return; }
|
|
else if (msg.clickedButton() == pbCancel) return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QMessageBox msg;
|
|
msg.setText("Please choose...");
|
|
msg.setModal(true);
|
|
QPushButton *pbOpen = msg.addButton("Open",QMessageBox::ActionRole);
|
|
QPushButton *pbSave = msg.addButton("Save",QMessageBox::ActionRole);
|
|
QPushButton *pbSaveAs = msg.addButton("Save As",QMessageBox::ActionRole);
|
|
QPushButton *pbCancel = msg.addButton("Cancel",QMessageBox::ActionRole);
|
|
msg.exec();
|
|
if (msg.clickedButton() == pbOpen){ }
|
|
else if (msg.clickedButton() == pbSave) { if(!FileSave()) return; }
|
|
else if (msg.clickedButton() == pbSaveAs) { if(!FileSaveAs()) return; }
|
|
else if (msg.clickedButton() == pbCancel) return;
|
|
}
|
|
|
|
QString strFilename = QFileDialog::getOpenFileName(0,"CSV file",QDir::currentPath(),
|
|
"csv files (*.csv);;All files (*.*)",new QString("CSV files (*.csv)"));
|
|
|
|
QFile file(strFilename);
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return;
|
|
FileNew();
|
|
|
|
QTextStream in(&file);
|
|
|
|
in.setCodec("utf-8");
|
|
int nLine = 0;
|
|
while(!in.atEnd())
|
|
{
|
|
in.readLine();
|
|
nLine++;
|
|
}
|
|
in.seek(0);
|
|
|
|
m_pstTable->setRowCount(nLine);
|
|
|
|
int j = 0;
|
|
while(!in.atEnd())
|
|
{
|
|
QString str = in.readLine();
|
|
QStringList strlist = str.split(",");
|
|
|
|
for(int i = 0; i < strlist.length(); i++)
|
|
{
|
|
m_pstTable->setItem(j,i,new QTableWidgetItem(strlist.at(i)));
|
|
}
|
|
j++;
|
|
}
|
|
file.close();
|
|
m_strFileName = strFilename;
|
|
m_plFileName->setText(m_strFileName);
|
|
}
|
|
|
|
|
|
|
|
bool SDictionary::FileSave()
|
|
{
|
|
if(m_strFileName.isEmpty())
|
|
{
|
|
return FileSaveAs();
|
|
}
|
|
else
|
|
{
|
|
QFile file(m_strFileName);
|
|
if(!file.open(QFile::WriteOnly | QFile::Text)) return false;
|
|
|
|
QTextStream out(&file);
|
|
|
|
out.setCodec("utf-8");
|
|
|
|
for (int nCount = 0 ; nCount < m_pstTable->rowCount(); nCount++ )
|
|
{
|
|
QString str;
|
|
for (int nColumnCount = 0;nColumnCount < m_pstTable->columnCount() ;nColumnCount++ )
|
|
{
|
|
QString strtemp = m_pstTable->item(nCount,nColumnCount)->text().trimmed();
|
|
str.append(strtemp);
|
|
str.append(",");
|
|
}
|
|
str = str.left(str.length() - 1);
|
|
out << str << endl;
|
|
}
|
|
file.close();
|
|
m_plFileName->setText(m_strFileName);
|
|
return true;
|
|
}
|
|
m_plFileName->setText(m_strFileName);
|
|
return false;
|
|
}
|
|
|
|
|
|
bool SDictionary::FileSaveAs()
|
|
{
|
|
|
|
QString strFilename = QFileDialog::getSaveFileName(0,"Exoprt file",QDir::currentPath(),
|
|
"csv files (*.csv);;All files (*.*)",new QString("Text files (*.csv)"));
|
|
if(strFilename.isEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
if (strFilename.toLower().right(4) != QString(".csv"))
|
|
strFilename += ".csv";
|
|
QFile file(strFilename);
|
|
if(!file.open(QFile::WriteOnly | QFile::Text)) return false;
|
|
|
|
QTextStream out(&file);
|
|
|
|
out.setCodec("utf-8");
|
|
|
|
for (int nCount = 0 ; nCount < m_pstTable->rowCount(); nCount++ )
|
|
{
|
|
QString str;
|
|
for (int nColumnCount = 0;nColumnCount < m_pstTable->columnCount() ;nColumnCount++ )
|
|
{
|
|
QString strtemp = m_pstTable->item(nCount,nColumnCount)->text().trimmed();
|
|
str.append(strtemp);
|
|
str.append(",");
|
|
}
|
|
str = str.left(str.length() - 1);
|
|
out << str << endl;
|
|
}
|
|
|
|
file.close();
|
|
m_strFileName = strFilename;
|
|
m_plFileName->setText(m_strFileName);
|
|
return true;
|
|
}
|
|
|
|
|
|
void SDictionary::FileClose()
|
|
{
|
|
if(m_strFileName.isEmpty())
|
|
{
|
|
if(m_pstTable->rowCount() > 0)
|
|
{
|
|
QMessageBox msg;
|
|
msg.setText("Please choose...");
|
|
msg.setModal(true);
|
|
QPushButton *pbNew = msg.addButton("Close",QMessageBox::ActionRole);
|
|
QPushButton *pbSave = msg.addButton("Save",QMessageBox::ActionRole);
|
|
QPushButton *pbCancel = msg.addButton("Cancel",QMessageBox::ActionRole);
|
|
msg.exec();
|
|
if (msg.clickedButton() == pbNew){ }
|
|
else if (msg.clickedButton() == pbSave) { if(!FileSave()) return; }
|
|
else if (msg.clickedButton() == pbCancel) return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QMessageBox msg;
|
|
msg.setText("Please choose...");
|
|
msg.setModal(true);
|
|
QPushButton *pbNew = msg.addButton("Close",QMessageBox::ActionRole);
|
|
QPushButton *pbSave = msg.addButton("Save",QMessageBox::ActionRole);
|
|
QPushButton *pbSaveAs = msg.addButton("Save As",QMessageBox::ActionRole);
|
|
QPushButton *pbCancel = msg.addButton("Cancel",QMessageBox::ActionRole);
|
|
msg.exec();
|
|
if (msg.clickedButton() == pbNew){ }
|
|
else if (msg.clickedButton() == pbSave) { if(!FileSave()) return; }
|
|
else if (msg.clickedButton() == pbSaveAs) { if(!FileSaveAs()) return; }
|
|
else if (msg.clickedButton() == pbCancel) return;
|
|
}
|
|
|
|
m_pstTable->clear();
|
|
m_pstTable->setRowCount(0);
|
|
m_pstTable->setColumnCount(m_strListHead.size());
|
|
int i = 0;
|
|
foreach(QString str, m_strListHead)
|
|
m_pstTable->setHorizontalHeaderItem(i++,new QTableWidgetItem(str));
|
|
|
|
m_strFileName.clear();
|
|
m_plFileName->setText(m_strFileName);
|
|
}
|
|
|
|
void SDictionary::FileExit()
|
|
{
|
|
this->hide();
|
|
}
|
|
|
|
struct SCount
|
|
{
|
|
SCount()
|
|
{
|
|
m_str.clear();
|
|
m_nCount = 0;
|
|
}
|
|
|
|
SCount(QString _str)
|
|
{
|
|
m_str = _str;
|
|
m_nCount = 1;
|
|
}
|
|
QString m_str;
|
|
int m_nCount;
|
|
};
|
|
|
|
|
|
|
|
|
|
bool SDictionary::setListMorphere(QStringList& MorphereEN, QStringList& MorphereKO)
|
|
{
|
|
QFile fHeader("morpherelist.txt");
|
|
if (!fHeader.open(QIODevice::ReadOnly | QIODevice::Text)) return false;
|
|
|
|
QTextStream in(&fHeader);
|
|
|
|
QString str = in.readLine();
|
|
|
|
if(str.at(0) == '#')
|
|
{
|
|
}
|
|
else
|
|
{
|
|
qDebug() << "The wrong file is read";
|
|
return false;
|
|
}
|
|
|
|
while(!in.atEnd())
|
|
{
|
|
str = in.readLine();
|
|
QStringList strList = str.trimmed().split("@",QString::SkipEmptyParts);
|
|
if(strList.isEmpty())
|
|
break;
|
|
if(strList.size() < 2)
|
|
return false;
|
|
MorphereEN << strList.at(0).trimmed().replace("\"","").trimmed();
|
|
MorphereKO << strList.at(1).trimmed().replace("\"","").trimmed();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool SDictionary::setListMorphereHeader(QStringList& MHeader)
|
|
{
|
|
QFile fHeader("mcolumn.txt");
|
|
if (!fHeader.open(QIODevice::ReadOnly | QIODevice::Text)) return false;
|
|
|
|
QTextStream in(&fHeader);
|
|
|
|
QString str = in.readLine();
|
|
|
|
if(str.at(0) == '#')
|
|
{
|
|
}
|
|
else
|
|
{
|
|
qDebug() << "The wrong file is";
|
|
return false;
|
|
}
|
|
|
|
while(!in.atEnd())
|
|
{
|
|
str = in.readLine();
|
|
QStringList strList = str.trimmed().split("@",QString::SkipEmptyParts);
|
|
if(strList.isEmpty())
|
|
break;
|
|
if(strList.size() < 1)
|
|
return false;
|
|
MHeader << strList.at(0).trimmed().replace("\"","").trimmed();
|
|
}
|
|
|
|
return true;
|
|
}
|