Files
clients/MorphereAnalyzer/ymtwodepthwidget.cpp
admin 9bca6154fd d3view 수정
git-svn-id: svn://192.168.0.12/source@177 8346c931-da38-4b9b-9d4c-e48b93cbd075
2015-08-31 06:51:47 +00:00

1761 lines
58 KiB
C++

#include "ymtwodepthwidget.h"
#include "../Json/sjson.h"
#include "../common.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 <QIntValidator>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QSet>
#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; }
YMTwoDepthWidget::YMTwoDepthWidget(QWidget *parent)
:YMorphereWidget(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";
}
m_strName = "twodepth";
QVBoxLayout *vMainLayout = new QVBoxLayout;
vMainLayout->setAlignment(Qt::AlignVCenter);
QVBoxLayout *vboxlayout = new QVBoxLayout;
QGroupBox *gBox = setMorphereList();
QGroupBox *gDate = setDate();
QGroupBox *gData = setData();
QGroupBox *gFilter = setFilter();
QGroupBox *gFilter2 = setFilter2();
QGroupBox *gOther = setOther();
QGroupBox *gSort = setSort();
QHBoxLayout *hboxlayout = new QHBoxLayout;
QGroupBox *gDictionary = setDictionary();
QGroupBox *gCenterKeyword = setCenterKeyword();
hboxlayout->addWidget(gBox,5);
vboxlayout->addWidget(gData,3);
vboxlayout->addWidget(gDate,3);
//vboxlayout->addWidget(gFilter,3);
vboxlayout->addWidget(gSort,2);
vboxlayout->addWidget(gOther,2);
vboxlayout->addWidget(gDictionary,2);
hboxlayout->addLayout(vboxlayout,5);
vMainLayout->addLayout(hboxlayout, 2);
vMainLayout->addWidget(gCenterKeyword, 1);
vMainLayout->addWidget(gFilter, 1);
vMainLayout->addWidget(gFilter2, 1);
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");
vMainLayout->addWidget(m_ptwData, 8);
setLayout(vMainLayout);
}
QGroupBox *YMTwoDepthWidget::setMorphereList()
{
QVBoxLayout *vlayout = new QVBoxLayout;
QVBoxLayout *vlayout1 = new QVBoxLayout;
QHBoxLayout *hlayout = new QHBoxLayout;
QGroupBox *groupBox = new QGroupBox(tr("Morphere List"));
m_plwMorphereList = new QListWidget;
m_plwMorphereAdd = new QListWidget;
m_plwMorphereList->setSelectionMode(QAbstractItemView::MultiSelection);
m_plwMorphereAdd->setSelectionMode(QAbstractItemView::ExtendedSelection);
for(int i=0;i<m_strlistMorphere.size();i++)
{
QListWidgetItem* pitem = new QListWidgetItem(m_strlistMorphereko.at(i), m_plwMorphereList);
pitem->setData(Qt::UserRole, QVariant(m_strlistMorphere.at(i)));
}
for(int i=0;i<m_strlistMorphere.size();i++)
{
QListWidgetItem* pitem = new QListWidgetItem(m_strlistMorphereko.at(i), m_plwMorphereAdd);
pitem->setData(Qt::UserRole, QVariant(m_strlistMorphere.at(i)));
}
for(int i=0;i<m_plwMorphereAdd->count();i++)
{
m_plwMorphereAdd->item(i)->setHidden(true);
}
QPushButton *ppbAdd = new QPushButton("Add");
QPushButton *ppbDel = new QPushButton("Del");
vlayout->addWidget(m_plwMorphereList);
vlayout->addWidget(ppbAdd);
vlayout1->addWidget(m_plwMorphereAdd);
vlayout1->addWidget(ppbDel);
connect(ppbAdd, SIGNAL(released()),this, SLOT(MorphereListAdd()));
connect(ppbDel, SIGNAL(released()),this, SLOT(MorphereListDel()));
hlayout->addLayout(vlayout);
hlayout->addLayout(vlayout1);
groupBox->setLayout(hlayout);
groupBox->setCheckable(true);
return groupBox;
}
QGroupBox *YMTwoDepthWidget::setDate()
{
QHBoxLayout *hlayout = new QHBoxLayout;
QHBoxLayout *hlayout1 = new QHBoxLayout;
QHBoxLayout *hlayout2 = new QHBoxLayout;
QVBoxLayout *vlayout = new QVBoxLayout;
QGroupBox *groupBox = new QGroupBox(tr("Date"));
m_pdeStart = new QDateEdit(QDate::currentDate());
m_pdeEnd = new QDateEdit(QDate::currentDate());
m_pdeStart->setDateRange(QDate(2003, 5, 20),QDate::currentDate());
m_pdeEnd->setDateRange(QDate(2003, 5, 20),QDate::currentDate());
QCalendarWidget *pCalender = new QCalendarWidget();
m_pdeStart->setCalendarWidget(pCalender);
m_pdeStart->setCalendarPopup(true);
m_pdeEnd->setCalendarWidget(pCalender);
m_pdeEnd->setCalendarPopup(true);
m_pcbDate = new QComboBox;
m_pcbDate->addItems(QStringList() << "ALL" << "NotAll");
m_pcbPeriod = new QComboBox;
m_pcbPeriod->addItems(QStringList() << "None" << "1 Day" << "1 Week" << "1 Month");
m_pleDates = new QLineEdit;
m_pleDates->setValidator(new QIntValidator(1, 100));
m_pcbDuring = new QComboBox;
m_pcbDuring->addItems(QStringList() << "None" << "Days" << "Weeks" << "Months" << "Years");
hlayout->addWidget(m_pcbDate);
hlayout->addWidget(new QLabel("Start:"));
hlayout->addWidget(m_pdeStart);
hlayout->addWidget(new QLabel("End:"));
hlayout->addWidget(m_pdeEnd);
hlayout1->addWidget(new QLabel("Period:"));
hlayout1->addWidget(m_pcbPeriod);
hlayout2->addWidget(new QLabel("Recent:"));
hlayout2->addWidget(m_pleDates);
hlayout2->addWidget(m_pcbDuring);
vlayout->addLayout(hlayout2);
vlayout->addLayout(hlayout);
vlayout->addLayout(hlayout1);
groupBox->setCheckable(true);
groupBox->setLayout(vlayout);
return groupBox;
}
QGroupBox *YMTwoDepthWidget::setFilter()
{
QHBoxLayout *hlayout = new QHBoxLayout;
QHBoxLayout *hlayout2 = new QHBoxLayout;
QHBoxLayout *hlayout3 = new QHBoxLayout;
QVBoxLayout *vlayout = new QVBoxLayout;
m_pleFilterRankALL = new QLineEdit;
m_pleFilterRankSeparated = new QLineEdit;
m_pleFilterKeyword = new QLineEdit;
m_pleFilterKeywordLength = new QLineEdit;
m_pleFilterExtractor = new QLineEdit;
m_pleFilterKeywordLength->setValidator(new QIntValidator(1, 10));
m_pleFilterRankALL->setValidator(new QIntValidator(1, 10000));
m_pleFilterRankSeparated->setValidator(new QIntValidator(1, 10000));
hlayout->addWidget(new QLabel("RankALL: "));
hlayout->addWidget(m_pleFilterRankALL);
hlayout->addWidget(new QLabel("RankSeparated: "));
hlayout->addWidget(m_pleFilterRankSeparated);
hlayout->addWidget(new QLabel("Keyword Length: "));
hlayout->addWidget(m_pleFilterKeywordLength);
hlayout2->addWidget(new QLabel("KeywordFilter: "));
hlayout2->addWidget(m_pleFilterKeyword);
hlayout3->addWidget(new QLabel("Extract Keyword: "));
hlayout3->addWidget(m_pleFilterExtractor);
vlayout->addLayout(hlayout3);
vlayout->addLayout(hlayout2);
vlayout->addLayout(hlayout);
QGroupBox *groupBox = new QGroupBox(tr("1Depth Filter"));
groupBox->setCheckable(true);
groupBox->setLayout(vlayout);
groupBox->setChecked(true);
return groupBox;
}
QGroupBox *YMTwoDepthWidget::setFilter2()
{
QHBoxLayout *hlayout = new QHBoxLayout;
QHBoxLayout *hlayout2 = new QHBoxLayout;
QHBoxLayout *hlayout3 = new QHBoxLayout;
QVBoxLayout *vlayout = new QVBoxLayout;
m_pleFilterRankALL2 = new QLineEdit;
m_pleFilterRankSeparated2 = new QLineEdit;
m_pleFilterKeyword2 = new QLineEdit;
m_pleFilterKeywordLength2 = new QLineEdit;
m_pleFilterExtractor2 = new QLineEdit;
m_pleFilterKeywordLength2->setValidator(new QIntValidator(1, 10));
m_pleFilterRankALL2->setValidator(new QIntValidator(1, 10000));
m_pleFilterRankSeparated2->setValidator(new QIntValidator(1, 10000));
hlayout->addWidget(new QLabel("RankALL: "));
hlayout->addWidget(m_pleFilterRankALL2);
hlayout->addWidget(new QLabel("RankSeparated: "));
hlayout->addWidget(m_pleFilterRankSeparated2);
hlayout->addWidget(new QLabel("Keyword Length: "));
hlayout->addWidget(m_pleFilterKeywordLength2);
hlayout2->addWidget(new QLabel("KeywordFilter: "));
hlayout2->addWidget(m_pleFilterKeyword2);
hlayout3->addWidget(new QLabel("Extract Keyword: "));
hlayout3->addWidget(m_pleFilterExtractor2);
vlayout->addLayout(hlayout3);
vlayout->addLayout(hlayout2);
vlayout->addLayout(hlayout);
QGroupBox *groupBox = new QGroupBox(tr("2Depth Filter"));
groupBox->setCheckable(true);
groupBox->setLayout(vlayout);
groupBox->setChecked(true);
return groupBox;
}
QGroupBox *YMTwoDepthWidget::setOther()
{
QHBoxLayout *hlayout = new QHBoxLayout;
m_pcbThread = new QComboBox;
hlayout->addWidget(new QLabel("Thread:"));
hlayout->addWidget(m_pcbThread);
m_pcbThread->addItems(QStringList() << "1" << "2" << "4" << "8");
QGroupBox *groupBox = new QGroupBox(tr("Other"));
groupBox->setCheckable(true);
groupBox->setLayout(hlayout);
return groupBox;
}
QGroupBox *YMTwoDepthWidget::setSort()
{
QHBoxLayout *hlayout = new QHBoxLayout;
m_rbDateMorphere = new QRadioButton("Date/Morphere");
m_rbMorphereDate = new QRadioButton("Morphere/Date");
m_bgRadioGroup = new QButtonGroup;
m_bgRadioGroup->addButton(m_rbMorphereDate);
m_bgRadioGroup->addButton(m_rbDateMorphere);
m_rbMorphereDate->setChecked(true);
hlayout->addWidget(m_rbMorphereDate);
hlayout->addWidget(m_rbDateMorphere);
QGroupBox *groupBox = new QGroupBox(tr("Sort"));
groupBox->setCheckable(true);
groupBox->setLayout(hlayout);
return groupBox;
}
QGroupBox *YMTwoDepthWidget::setDictionary()
{
QHBoxLayout *hlayout = new QHBoxLayout;
m_pcbDictionary = new QComboBox;
m_pcbDictionary->setEditable(true);
m_pcbDictionary->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
QPushButton* add = new QPushButton;
QPushButton* del = new QPushButton;
add->setText(tr("+"));
del->setText(tr("-"));
//hlayout->addWidget(new QLabel(tr("User-Dict: ")));
hlayout->addWidget(m_pcbDictionary);
hlayout->addWidget(add);
hlayout->addWidget(del);
connect(add, SIGNAL(released()),this, SLOT(AddDictionary()));
connect(del, SIGNAL(released()),this, SLOT(DelDictionary()));
QGroupBox *groupBox = new QGroupBox(tr("User Dictionary"));
groupBox->setCheckable(true);
groupBox->setLayout(hlayout);
return groupBox;
}
QGroupBox *YMTwoDepthWidget::setCenterKeyword()
{
QHBoxLayout *hlayout = new QHBoxLayout;
m_pleCKeyword = new QLineEdit;
m_pcbCountMethod = new QComboBox;
m_pcbCountMethod->addItems(QStringList() << "Duplicate" << "NonDuplicate");
hlayout->addWidget(new QLabel("Center Keyword: "));
hlayout->addWidget(m_pleCKeyword);
hlayout->addWidget(new QLabel("CountMethod: "));
hlayout->addWidget(m_pcbCountMethod);
QGroupBox *groupBox = new QGroupBox(tr("Center Keyword"));
groupBox->setCheckable(true);
groupBox->setLayout(hlayout);
groupBox->setChecked(true);
return groupBox;
}
void YMTwoDepthWidget::AddDictionary()
{
QStringList strFilenames = QFileDialog::getOpenFileNames(0,"Dictionary file",QDir::currentPath(),
"dic files (*.dic);;All files (*.*)",new QString("Dictionary files (*.dic)"));
foreach(QString strFilename, strFilenames)
{
QFile file(strFilename);
if (!file.open(QIODevice::ReadOnly)) return;
}
for(int i = 0; i < m_pcbDictionary->count(); i++)
{
if(strFilenames.contains(m_pcbDictionary->itemText(i)))
strFilenames.removeOne(m_pcbDictionary->itemText(i));
}
m_pcbDictionary->addItems(strFilenames);
}
QString YMTwoDepthWidget::getUserDictList()
{
QStringList strList;
for(int i = 0; i < m_pcbDictionary->count();i++)
{
strList << m_pcbDictionary->itemText(i);
}
return strList.join(",");
}
void YMTwoDepthWidget::DelDictionary()
{
m_pcbDictionary->removeItem(0);
qDebug() << getUserDictList();
}
bool YMTwoDepthWidget::isSortMorphereDateChecked()
{
return m_rbMorphereDate->isChecked();
}
bool YMTwoDepthWidget::isSortDateMorphereChecked()
{
return m_rbDateMorphere->isChecked();
}
void YMTwoDepthWidget::MorphereListAdd()
{
QList<QListWidgetItem *> listitem = m_plwMorphereList->selectedItems();
foreach(QListWidgetItem *item, listitem)
{
for(int i = 0; i < m_plwMorphereAdd->count();i++)
{
if(item->data(Qt::UserRole) == m_plwMorphereAdd->item(i)->data(Qt::UserRole))
m_plwMorphereAdd->item(i)->setHidden(false);
}
}
}
void YMTwoDepthWidget::MorphereListDel()
{
for(int i = m_plwMorphereAdd->count() - 1; i >= 0 ;i--)
{
if(m_plwMorphereAdd->item(i)->isSelected())
{
m_plwMorphereAdd->item(i)->setHidden(true);
}
}
}
QTableWidget *YMTwoDepthWidget::AddTable(QString _str)
{
STable *pTable = new STable;
m_ptwData->addTab(pTable,_str);
return (QTableWidget *)pTable;
}
void YMTwoDepthWidget::CloseTab(int index)
{
((STable*)(m_ptwData->widget(index)))->clear();
m_ptwData->removeTab(index);
}
void YMTwoDepthWidget::DoubleClickTab(int index)
{
bool ok;
if (index < 0) return;
QString text = QInputDialog::getText(this,"Tab name change","Name : ", QLineEdit::Normal,m_ptwData->tabText(index), &ok);
if (ok)
{
m_ptwData->setTabText(index,text);
}
}
void YMTwoDepthWidget::FileImport()
{
QString strFilename = QFileDialog::getOpenFileName(0,"Import file",QDir::currentPath(),
"csv files (*.csv);;All files (*.*)",new QString("Text files (*.csv)"));
QFile file(strFilename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return;
clearResult();
m_mapViewResult.clear();
//qDebug() << "clear is complete";
QTextStream in(&file);
while(!in.atEnd())
{
QString strLine = in.readLine();
strLine = strLine.replace("\"","");
//qDebug() << strLine;
QStringList strListLine = strLine.split(",");
if(strListLine.size() != 4)
continue;
//qDebug() << strListLine.at(4).trimmed().toInt();
QString strKey = strListLine.at(0).trimmed() + "~!@" + strListLine.at(1).trimmed() + "~!@" + strListLine.at(2).trimmed();
m_mapResult.insert(strKey, strListLine.at(3).trimmed().toInt());
}
file.close();
for(QMap<QString, int>::iterator iterPos = m_mapResult.begin(); iterPos != m_mapResult.end(); iterPos++)
{
QString strkey = iterPos.key();
int count = iterPos.value();
QStringList strlistKey = strkey.split("~!@");
QString strDate = strlistKey.at(0);
QString strMorphere = strlistKey.at(1);
QString strKeyword = strlistKey.at(2);
if(m_mapViewResult.contains(strDate))
{
if(m_mapViewResult.value(strDate).contains(strMorphere))
{
m_mapViewResult[(strDate)][(strMorphere)].insertMulti(count, strKeyword);
}
else
{
QMap<int, QString> qLast;
qLast.insert(count, strKeyword);
m_mapViewResult[(strDate)].insert(strMorphere, qLast);
}
}
else
{
QMap<int, QString> qLast;
qLast.insert(count , strKeyword);
QMap<QString, QMap<int, QString> > qMedium;
qMedium.insert(strMorphere, qLast);
m_mapViewResult.insert(strDate, qMedium);
}
}
ViewResult();
}
void YMTwoDepthWidget::FileExport()
{
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";
QFile file(strFilename);
if(!file.open(QFile::WriteOnly | QFile::Text)) return;
QTextStream out(&file);
for (int i = 0; i < m_ptwData->count(); i++)
{
m_ptwData->setTabEnabled(i, true);
QTabWidget* p_childWidget = (QTabWidget*)(m_ptwData->widget(i));
for (int j = 0; j < p_childWidget->count(); j++)
{
p_childWidget->setTabEnabled(j, true);
STable *stable = (STable *) (p_childWidget->widget(j));
for (int nCount = 0 ; nCount < stable->rowCount(); nCount++ )
{
QString str = stable->item(nCount,0)->text().trimmed() + "," + stable->item(nCount,1)->text().trimmed();
out << m_ptwData->tabText(i).trimmed() << "," << p_childWidget->tabText(j).trimmed() << ",";
out << str << endl;
}
}
}
file.close();
}
int YMTwoDepthWidget::getThread()
{
return m_pcbThread->currentText().toInt();
}
unsigned int YMTwoDepthWidget::getDateStart()
{
return m_pdeStart->dateTime().toString("yyyy-MM-dd").replace("-","").trimmed().toInt();
}
unsigned int YMTwoDepthWidget::getDateEnd()
{
return m_pdeEnd->dateTime().toString("yyyy-MM-dd").replace("-","").trimmed().toInt();
}
int YMTwoDepthWidget::getPeriod()
{
return m_pcbPeriod->currentIndex();
}
QStringList YMTwoDepthWidget::getMorphereList()
{
QStringList strList;
for(int i = 0; i < m_plwMorphereAdd->count();i++)
{
if(m_plwMorphereAdd->item(i)->isHidden())
continue;
else
{
strList << m_plwMorphereAdd->item(i)->data(Qt::UserRole).toString();
}
}
return strList;
}
bool YMTwoDepthWidget::getDateAll()
{
if(m_pcbDate->currentIndex() == 0)
return true;
else
return false;
}
QTabWidget* YMTwoDepthWidget::getQTabWidget()
{
return m_ptwData;
}
void YMTwoDepthWidget::MemClear()
{
m_mapResult.clear();
m_mapViewResult.clear();
}
bool YMTwoDepthWidget::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;
}
void YMTwoDepthWidget::RawFileExport()
{
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";
QFile file(strFilename);
if(!file.open(QFile::WriteOnly | QFile::Text)) return;
QTextStream out(&file);
/*
out << "#Head#,";
for (int nCount = 0;nCount < pCurrent->columnCount() ;nCount++ )
out << pCurrent->horizontalHeaderItem(nCount)->text() << ",";
m_pProgress->setRange(0,pCurrent->rowCount()-1);
*/
for( QMap<QString,QMap<QString,QMap<int, QString> > >::iterator iterPos = m_mapViewResult.begin(); iterPos != m_mapViewResult.end(); iterPos++)
{
for(QMap<QString, QMap<int, QString> >::iterator iterPos2 = iterPos.value().begin(); iterPos2 != iterPos.value().end(); iterPos2++)
{
QMapIterator<int, QString> i(m_mapViewResult[iterPos.key()][iterPos2.key()]);
i.toBack();
while(i.hasPrevious())
{
i.previous();
out << "\"" << iterPos.key() << "\"" << ",";
out << "\"" << iterPos2.key() << "\"" << ",";
out << "\"" << i.value() << "\"" << ",";
out << "\"" << i.key() << "\"" << "\n";
}
}
}
file.close();
}
YMTwoDepthWidget::~YMTwoDepthWidget()
{
}
void YMTwoDepthWidget::clearViewResult()
{
}
QGroupBox *YMTwoDepthWidget::setData()
{
QHBoxLayout *hlayout = new QHBoxLayout;
m_pcbData = new QComboBox;
m_pcbData->addItems(QStringList() << "Title" << "Body" << "Title+Body" << "PlatformTitle");
m_pcbData->setCurrentIndex(2);
hlayout->addWidget(new QLabel("Data: "));
hlayout->addWidget(m_pcbData);
QGroupBox *groupBox = new QGroupBox(tr("Data"));
groupBox->setCheckable(true);
groupBox->setLayout(hlayout);
groupBox->setChecked(true);
return groupBox;
}
void YMTwoDepthWidget::clearView()
{
m_mapViewResult.clear();
m_mapViewResult2.clear();
}
void YMTwoDepthWidget::SortViewResult()
{
if(isSortDateMorphereChecked())
{
for(QMap<QString, int>::iterator iterPos = m_mapResult.begin(); iterPos != m_mapResult.end(); iterPos++)
{
QString strkey = iterPos.key();
int count = iterPos.value();
QStringList strlistKey = strkey.split("~!@");
QString strDate = strlistKey.at(0);
QString strMorphere = strlistKey.at(1);
QString strKeyword = strlistKey.at(2);
QString strMorphere2 = strlistKey.at(3);
QString strKeyword2 = strlistKey.at(4);
m_mapViewResult[(strDate)]["ALLMORPHERE"].insertMulti(count, QString(strMorphere + "~!@" + strKeyword + "~!@" + strMorphere2 + "~!@" + strKeyword2 )); // added
if(m_mapViewResult.contains(strDate))
{
if(m_mapViewResult.value(strDate).contains(strMorphere))
{
m_mapViewResult[(strDate)][(strMorphere)].insertMulti(count, strKeyword + "~!@" + strMorphere2 + "~!@" + strKeyword2);
//m_mapViewResult[(strDate)]["ALLMORPHERE"].insertMulti(count, QString(strMorphere + "~!@" + strKeyword )); // added
}
else
{
QMap<int, QString> qLast;
qLast.insert(count, strKeyword + "~!@" + strMorphere2 + "~!@" + strKeyword2);
m_mapViewResult[(strDate)].insert(strMorphere, qLast);
/*
qLast.clear(); //added
qLast.insert(count, QString(strMorphere + "~!@" + strKeyword));//added
m_mapViewResult[(strDate)].insert("ALLMORPHERE", qLast);//added
*/
}
}
else
{
QMap<int, QString> qLast;
qLast.insert(count , strKeyword + "~!@" + strMorphere2 + "~!@" + strKeyword2);
QMap<QString, QMap<int, QString> > qMedium;
qMedium.insert(strMorphere, qLast);
m_mapViewResult.insert(strDate, qMedium);
/*
qLast.clear();
qMedium.clear();
qLast.insert(count, QString(strMorphere + "~!@" + strKeyword));
qMedium.insert("ALLMORPHERE", qLast);
m_mapViewResult.insert(strDate, qMedium);
*/
}
}
}
else
{
for(QMap<QString, int>::iterator iterPos = m_mapResult.begin(); iterPos != m_mapResult.end(); iterPos++)
{
QString strkey = iterPos.key();
int count = iterPos.value();
QStringList strlistKey = strkey.split("~!@");
QString strDate = strlistKey.at(0);
QString strMorphere = strlistKey.at(1);
QString strKeyword = strlistKey.at(2);
QString strMorphere2 = strlistKey.at(3);
QString strKeyword2 = strlistKey.at(4);
m_mapViewResult[("ALLMORPHERE")][(strDate)].insertMulti(count, QString(strMorphere + "~!@" + strKeyword + "~!@" + strMorphere2 + "~!@" + strKeyword2 ));
if(m_mapViewResult.contains(strMorphere))
{
if(m_mapViewResult.value(strMorphere).contains(strDate))
{
m_mapViewResult[(strMorphere)][(strDate)].insertMulti(count, strKeyword + "~!@" + strMorphere2 + "~!@" + strKeyword2 );
//m_mapViewResult[("ALLMORPHERE")][(strDate)].insertMulti(count, QString(strMorphere + "~!@" + strKeyword ));
}
else
{
QMap<int, QString> qLast;
qLast.insert(count, strKeyword + "~!@" + strMorphere2 + "~!@" + strKeyword2);
m_mapViewResult[(strMorphere)].insert(strDate, qLast);
/*
qLast.clear();
qLast.insert(count, QString(strMorphere + "~!@" + strKeyword) );
m_mapViewResult[("ALLMORPHERE")].insert(strDate, qLast);
*/
}
}
else
{
QMap<int, QString> qLast;
qLast.insert(count , strKeyword + "~!@" + strMorphere2 + "~!@" + strKeyword2);
QMap<QString, QMap<int, QString> > qMedium;
qMedium.insert(strDate, qLast);
m_mapViewResult.insert(strMorphere, qMedium);
/*
qLast.clear();
qMedium.clear();
qLast.insert(count,QString(strMorphere + "~!@" + strKeyword));
qMedium.insert(strDate, qLast);
m_mapViewResult.insert("ALLMORPHERE", qMedium);
*/
}
}
}
/*
for(QMap<QString, int>::iterator iterPos = m_mapResult.begin(); iterPos != m_mapResult.end(); iterPos++)
{
QString strkey = iterPos.key();
int count = iterPos.value();
QStringList strlistKey = strkey.split("~!@");
QString strDate = strlistKey.at(0);
QString strMorphere = strlistKey.at(1);
QString strKeyword = strlistKey.at(2);
if(m_mapViewResult2.contains(strDate))
{
if(m_mapViewResult2.value(strDate).contains(count))
{
m_mapViewResult2[(strDate)][(count)].insertMulti(strMorphere, strKeyword);
}
else
{
QMap<QString, QString> qLast;
qLast.insert(strMorphere, strKeyword);
m_mapViewResult2[(strDate)].insert(count, qLast);
}
}
else
{
QMap<QString, QString> qLast;
qLast.insert(strMorphere , strKeyword);
QMap<int, QMap<QString, QString> > qMedium;
qMedium.insert(count, qLast);
m_mapViewResult2.insert(strDate, qMedium);
}
}
*/
}
void YMTwoDepthWidget::ViewResult()
{
SortViewResult();
foreach(STable* ptable, m_lTable)
{
ptable->clear();
delete ptable;
}
m_lTable.clear();
foreach(QTabWidget* pwidget, m_lTabWidget)
{
pwidget->clear();
delete pwidget;
}
m_lTabWidget.clear();
m_ptwTable = getQTabWidget();
m_ptwTable->clear();
for( QMap<QString,QMap<QString,QMap<int, QString> > >::iterator iterPos = m_mapViewResult.begin(); iterPos != m_mapViewResult.end(); iterPos++)
{
QTabWidget* temp = new QTabWidget;
for(QMap<QString, QMap<int, QString> >::iterator iterPos2 = iterPos.value().begin(); iterPos2 != iterPos.value().end(); iterPos2++)
{
if( (iterPos2.key() == "ALLMORPHERE") || (iterPos.key() == "ALLMORPHERE") )
{
int ncRow = 0;
STable *pNew = new STable;
pNew->setColumnCount(5);
pNew->setRowCount(m_mapViewResult[iterPos.key()][iterPos2.key()].size());
pNew->setHorizontalHeaderItem(0 ,new QTableWidgetItem("1D Morphere"));
pNew->setHorizontalHeaderItem(1 ,new QTableWidgetItem("1D Keyword"));
pNew->setHorizontalHeaderItem(2 ,new QTableWidgetItem("2D Morphere"));
pNew->setHorizontalHeaderItem(3 ,new QTableWidgetItem("2D Keyword"));
pNew->setHorizontalHeaderItem(4 ,new QTableWidgetItem("Count"));
QMapIterator<int, QString> i(m_mapViewResult[iterPos.key()][iterPos2.key()]);
i.toBack();
while(i.hasPrevious())
{
i.previous();
pNew->setItem(ncRow,0,new QTableWidgetItem(QString(i.value().split("~!@").at(0))));
pNew->setItem(ncRow,1,new QTableWidgetItem(QString(i.value().split("~!@").at(1))));
pNew->setItem(ncRow,2,new QTableWidgetItem(QString(i.value().split("~!@").at(2))));
pNew->setItem(ncRow,3,new QTableWidgetItem(QString(i.value().split("~!@").at(3))));
pNew->setItem(ncRow,4,new QTableWidgetItem(QString::number(i.key())));
ncRow++;
}
temp->addTab(pNew, iterPos2.key());
m_lTable << pNew;
}
else
{
int ncRow = 0;
STable *pNew = new STable;
pNew->setColumnCount(4);
pNew->setRowCount(m_mapViewResult[iterPos.key()][iterPos2.key()].size());
pNew->setHorizontalHeaderItem(0 ,new QTableWidgetItem("1D Keyword"));
pNew->setHorizontalHeaderItem(1 ,new QTableWidgetItem("2D Morphere"));
pNew->setHorizontalHeaderItem(2 ,new QTableWidgetItem("2D Keyword"));
pNew->setHorizontalHeaderItem(3 ,new QTableWidgetItem("Count"));
QMapIterator<int, QString> i(m_mapViewResult[iterPos.key()][iterPos2.key()]);
i.toBack();
while(i.hasPrevious())
{
i.previous();
pNew->setItem(ncRow,0,new QTableWidgetItem(QString(i.value().split("~!@").at(0))));
pNew->setItem(ncRow,1,new QTableWidgetItem(QString(i.value().split("~!@").at(1))));
pNew->setItem(ncRow,2,new QTableWidgetItem(QString(i.value().split("~!@").at(2))));
pNew->setItem(ncRow,3,new QTableWidgetItem(QString::number(i.key())));
ncRow++;
}
temp->addTab(pNew, iterPos2.key());
m_lTable << pNew;
}
}
m_ptwTable->addTab(temp, iterPos.key());
m_lTabWidget << temp;
}
/*
QMap<QString,QMap<int,QMap<QString, QString> > >::iterator iterPosi = m_mapViewResult2.begin();
for( QMap<QString,QMap<QString,QMap<int, QString> > >::iterator iterPos = m_mapViewResult.begin(); iterPos != m_mapViewResult.end(); iterPos++, iterPosi++)
{
QTabWidget* temp = new QTabWidget;
for(QMap<QString, QMap<int, QString> >::iterator iterPos2 = iterPos.value().begin(); iterPos2 != iterPos.value().end(); iterPos2++)
{
int ncRow = 0;
STable *pNew = new STable;
pNew->setColumnCount(2);
pNew->setRowCount(m_mapViewResult[iterPos.key()][iterPos2.key()].size());
pNew->setHorizontalHeaderItem(0 ,new QTableWidgetItem("Keyword"));
pNew->setHorizontalHeaderItem(1 ,new QTableWidgetItem("Count"));
QMapIterator<int, QString> i(m_mapViewResult[iterPos.key()][iterPos2.key()]);
i.toBack();
while(i.hasPrevious())
{
i.previous();
pNew->setItem(ncRow,0,new QTableWidgetItem(QString(i.value())));
pNew->setItem(ncRow,1,new QTableWidgetItem(QString::number(i.key())));
ncRow++;
}
temp->addTab(pNew, iterPos2.key());
m_lTable << pNew;
}
{
int ncRow = 0;
STable *pNew = new STable;
pNew->setColumnCount(3);
pNew->setRowCount(m_mapViewResult2[iterPosi.key()].size());
pNew->setHorizontalHeaderItem(0 ,new QTableWidgetItem("Morphere"));
pNew->setHorizontalHeaderItem(1 ,new QTableWidgetItem("Keyword"));
pNew->setHorizontalHeaderItem(2 ,new QTableWidgetItem("Count"));
QMapIterator<int, QMap<QString,QString>> j(m_mapViewResult2[iterPosi.key()]);
j.toBack();
while(j.hasPrevious())
{
j.previous();
for(QMap<QString, QString>::iterator iterPosii = m_mapViewResult2[iterPosi.key()][j.key()].begin(); iterPosii != m_mapViewResult2[iterPosi.key()][j.key()].end(); iterPosii++)
{
pNew->setItem(ncRow,0,new QTableWidgetItem(QString(iterPosii.key())));
pNew->setItem(ncRow,1,new QTableWidgetItem(QString(iterPosii.value())));
pNew->setItem(ncRow,2,new QTableWidgetItem(QString::number(j.key())));
ncRow++;
}
}
temp->addTab(pNew, "ALL");
m_lTable << pNew;
}
m_ptwTable->addTab(temp, iterPos.key());
m_lTabWidget << temp;
}
*/
}
void YMTwoDepthWidget::SaveFile()
{
QString strFilename = QFileDialog::getSaveFileName(0,"save 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::WriteOnly | QFile::Text)) return;
QTextStream out(&file);
QMap<QString, QMap<QString, int> > mapResult;
{
STable* pTable = (STable*)((QTabWidget*)(m_ptwTable->currentWidget()))->currentWidget();
if(pTable->columnCount() < 4)
return;
int nCountIndex = pTable->columnCount() - 1;
int nTDKeywordIndex = pTable->columnCount() - 2;
int nODKeywordIndex = pTable->columnCount() - 4;
for (int i = 0; i < pTable->rowCount(); i++)
{
QString strODKeyword = pTable->item(i, nODKeywordIndex)->text().trimmed();
QString strTDKeyword = pTable->item(i, nTDKeywordIndex)->text().trimmed();
int nCount = pTable->item(i, nCountIndex)->text().trimmed().toInt();
if(mapResult.contains(strODKeyword))
{
mapResult[strODKeyword].insert(strTDKeyword, nCount);
}
else
{
QMap<QString, int> qLast;
qLast.insert(strTDKeyword, nCount);
mapResult.insert(strODKeyword, qLast);
}
}
}
QString strCKeyword = m_pleCKeyword->text().trimmed();
for(QMap<QString, QMap<QString, int> >::iterator iterPos = mapResult.begin(); iterPos != mapResult.end(); iterPos++)
{
int sum = 0;
out << iterPos.key();
for(QMap<QString, int>::iterator iterPos2 = iterPos.value().begin(); iterPos2 != iterPos.value().end() ; iterPos2++)
{
sum += iterPos2.value();
for(int i = 0; i < iterPos2.value(); i++)
{
out << ";" << iterPos2.key();
}
}
out << "\n";
out << strCKeyword;
for(int i = 0; i < sum; i++)
{
out << ";" << iterPos.key();
}
out << "\n";
}
file.close();
}
void YMTwoDepthWidget::SaveFileSimple()
{
QString strFilename = QFileDialog::getSaveFileName(0,"save file",QDir::currentPath(),
"dl files (*.dl);;All files (*.*)",new QString("Text files (*.dl)"));
if (strFilename.toLower().right(3) != QString(".dl"))
strFilename += ".dl";
QFile file(strFilename);
if(!file.open(QFile::WriteOnly | QFile::Text)) return;
QMap<QString, QMap<QString, int> > mapResult;
QTextStream out(&file);
QSet<QString> setKey;
{
STable* pTable = (STable*)((QTabWidget*)(m_ptwTable->currentWidget()))->currentWidget();
if(pTable->columnCount() < 4)
return;
int nCountIndex = pTable->columnCount() - 1;
int nTDKeywordIndex = pTable->columnCount() - 2;
int nODKeywordIndex = pTable->columnCount() - 4;
for (int i = 0; i < pTable->rowCount(); i++)
{
QString strODKeyword = pTable->item(i, nODKeywordIndex)->text().trimmed();
QString strTDKeyword = pTable->item(i, nTDKeywordIndex)->text().trimmed();
int nCount = pTable->item(i, nCountIndex)->text().trimmed().toInt();
setKey.insert(strODKeyword);
setKey.insert(strTDKeyword);
if(mapResult.contains(strODKeyword))
{
mapResult[strODKeyword].insert(strTDKeyword, nCount);
}
else
{
QMap<QString, int> qLast;
qLast.insert(strTDKeyword, nCount);
mapResult.insert(strODKeyword, qLast);
}
}
}
QString strCKeyword = m_pleCKeyword->text().trimmed();
out << "dl\nformat=edgelist1\nn=" + QString::number(setKey.size()) + "\ndata:\n";
setKey.clear();
for(QMap<QString, QMap<QString, int> >::iterator iterPos = mapResult.begin(); iterPos != mapResult.end(); iterPos++)
{
int sum = 0;
for(QMap<QString, int>::iterator iterPos2 = iterPos.value().begin(); iterPos2 != iterPos.value().end() ; iterPos2++)
{
sum += iterPos2.value();
out << iterPos.key() << " " << iterPos2.key() << " " << iterPos2.value() << "\n";
}
out << strCKeyword << " " << iterPos.key() << " " << sum << "\n";
}
file.close();
}
QMap<QString, int> YMTwoDepthWidget::getResult()
{
return m_mapResult;
}
void YMTwoDepthWidget::D3View()
{
QMap<QString, QMap<QString, int> > mapResult;
QString strCKeyword = getCenterKeyword();
//qDebug() << "executed";
{
STable* pTable = (STable*)((QTabWidget*)(m_ptwTable->currentWidget()))->currentWidget();
if(pTable->columnCount() < 4)
return;
int nCountIndex = pTable->columnCount() - 1;
int nTDKeywordIndex = pTable->columnCount() - 2;
int nODKeywordIndex = pTable->columnCount() - 4;
for (int i = 0; i < pTable->rowCount(); i++)
{
QString strODKeyword = pTable->item(i, nODKeywordIndex)->text().trimmed();
QString strTDKeyword = pTable->item(i, nTDKeywordIndex)->text().trimmed();
int nCount = pTable->item(i, nCountIndex)->text().trimmed().toInt();
if(mapResult.contains(strODKeyword))
{
mapResult[strODKeyword].insert(strTDKeyword, nCount);
}
else
{
QMap<QString, int> qLast;
qLast.insert(strTDKeyword, nCount);
mapResult.insert(strODKeyword, qLast);
}
}
}
QString strjson = "{\"name\":\" " + strCKeyword + "\",";
strjson += ("\"children\": [");
for(QMap<QString, QMap<QString, int > >::iterator iterPos1 = mapResult.begin(); iterPos1 != mapResult.end(); iterPos1++)
{
int sum = 0;
for(QMap<QString, int>::iterator iterPos2 = iterPos1.value().begin(); iterPos2 != iterPos1.value().end(); iterPos2++)
{
sum += iterPos2.value();
}
strjson += "{";
strjson += ("\"name\":\"" + iterPos1.key() + "\",\"size\":" + QString::number(sum) + ",");
strjson += "\"children\": [";
for(QMap<QString, int>::iterator iterPos2 = iterPos1.value().begin(); iterPos2 != iterPos1.value().end(); iterPos2++)
{
strjson += ("{\"name\": \"" + iterPos2.key() + "\", \"size\": " + QString::number(iterPos2.value()) + "},");
}
strjson = strjson.trimmed();
strjson = strjson.left(strjson.length() - 1);
strjson += "]},";
}
strjson = strjson.trimmed();
strjson = strjson.left(strjson.length() - 1);
strjson += "]}";
QString strHtml;
strHtml = "<html>"
"\n<meta charset=\"utf-8\">"
"\n<style>"
"\n"
"\n.node circle {"
"\n cursor: pointer;"
"\n stroke: #3182bd;"
"\n stroke-width: 1.5px;"
"\n}"
"\n"
"\n.node text {"
"\n font: 14px sans-serif;"
"\n pointer-events: none;"
"\n text-anchor: middle;"
"\n}"
"\n"
"\nline.link {"
"\n fill: none;"
"\n stroke: #9ecae1;"
"\n stroke-width: 1.5px;"
"\n}"
"\n"
"\n</style>"
"\n<body>"
"\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js\"></script>"
"\n<script>"
"\n"
"\nvar width = 1920,"
"\n height = 1080,"
"\n root;"
"\n"
"\nvar force = d3.layout.force()"
"\n .linkDistance(80)"
"\n .charge(-120)"
"\n .gravity(.05)"
"\n .size([width, height])"
"\n .on(\"tick\", tick);"
"\n"
"\nvar svg = d3.select(\"body\").append(\"svg\")"
"\n .attr(\"width\", width)"
"\n .attr(\"height\", height);"
"\n"
"\nvar link = svg.selectAll(\".link\"),"
"\n node = svg.selectAll(\".node\");"
"\n"
//"\nd3.json(\"graph.json\", function(error, json) {"
//"\n if (error) throw error;"
"\n"
"\nvar jsonparam = '" + strjson + "';"
"\n root = JSON.parse(jsonparam);"
"\n update();"
//"\n});"
"\n"
"\nfunction update() {"
"\n var nodes = flatten(root),"
"\n links = d3.layout.tree().links(nodes);"
"\n"
"\n // Restart the force layout."
"\n force"
"\n .nodes(nodes)"
"\n .links(links)"
"\n .start();"
"\n"
"\n // Update links."
"\n link = link.data(links, function(d) { return d.target.id; });"
"\n"
"\n link.exit().remove();"
"\n"
"\n link.enter().insert(\"line\", \".node\")"
"\n .attr(\"class\", \"link\");"
"\n"
"\n // Update nodes."
"\n node = node.data(nodes, function(d) { return d.id; });"
"\n"
"\n node.exit().remove();"
"\n"
"\n var nodeEnter = node.enter().append(\"g\")"
"\n .attr(\"class\", \"node\")"
"\n .on(\"click\", click)"
"\n .call(force.drag);"
"\n"
"\n nodeEnter.append(\"circle\")"
"\n .attr(\"r\", function(d) { return Math.sqrt(d.size) / 10 || 4.5; });"
"\n"
"\n nodeEnter.append(\"text\")"
"\n .attr(\"dy\", \".35em\")"
"\n .text(function(d) { return d.name; });"
"\n"
"\n node.select(\"circle\")"
"\n .style(\"fill\", color);"
"\n}"
"\n"
"\nfunction tick() {"
"\n link.attr(\"x1\", function(d) { return d.source.x; })"
"\n .attr(\"y1\", function(d) { return d.source.y; })"
"\n .attr(\"x2\", function(d) { return d.target.x; })"
"\n .attr(\"y2\", function(d) { return d.target.y; });"
"\n"
"\n node.attr(\"transform\", function(d) { return \"translate(\" + d.x + \",\" + d.y + \")\"; });"
"\n}"
"\n"
"\nfunction color(d) {"
"\n return d._children ? \"#3182bd\" // collapsed package"
"\n : d.children ? \"#c6dbef\" // expanded package"
"\n : \"#fd8d3c\"; // leaf node"
"\n}"
"\n"
"\n// Toggle children on click."
"\nfunction click(d) {"
"\n if (d3.event.defaultPrevented) return; // ignore drag"
"\n if (d.children) {"
"\n d._children = d.children;"
"\n d.children = null;"
"\n } else {"
"\n d.children = d._children;"
"\n d._children = null;"
"\n }"
"\n update();"
"\n}"
"\n"
"\n// Returns a list of all nodes under the root."
"\nfunction flatten(root) {"
"\n var nodes = [], i = 0;"
"\n"
"\n function recurse(node) {"
"\n if (node.children) node.children.forEach(recurse);"
"\n if (!node.id) node.id = ++i;"
"\n nodes.push(node);"
"\n }"
"\n"
"\n recurse(root);"
"\n return nodes;"
"\n}"
"\n"
"\n</script>"
"\n";
qDebug() << strHtml;
QFile file("c:/data/d3test.html");
if(!file.open(QFile::WriteOnly | QFile::Text)) return;
QTextStream out(&file);
out << strHtml;
file.close();
m_WVD3View.setHtml(strHtml);
m_WVD3View.settings()->setObjectCacheCapacities(0,0,0);
m_WVD3View.repaint();
m_WVD3View.show();
}
void YMTwoDepthWidget::TestUpload()
{
//QMap<QString, int> mapResult = m_mapResult;
QMap<QString, QMap<QString, int> > mapResult;
QString strCKeyword = getCenterKeyword();
//qDebug() << "executed";
{
STable* pTable = (STable*)((QTabWidget*)(m_ptwTable->currentWidget()))->currentWidget();
if(pTable->columnCount() < 4)
return;
int nCountIndex = pTable->columnCount() - 1;
int nTDKeywordIndex = pTable->columnCount() - 2;
int nODKeywordIndex = pTable->columnCount() - 4;
for (int i = 0; i < pTable->rowCount(); i++)
{
QString strODKeyword = pTable->item(i, nODKeywordIndex)->text().trimmed();
QString strTDKeyword = pTable->item(i, nTDKeywordIndex)->text().trimmed();
int nCount = pTable->item(i, nCountIndex)->text().trimmed().toInt();
if(mapResult.contains(strODKeyword))
{
mapResult[strODKeyword].insert(strTDKeyword, nCount);
}
else
{
QMap<QString, int> qLast;
qLast.insert(strTDKeyword, nCount);
mapResult.insert(strODKeyword, qLast);
}
}
}
QString strjson = "{\n\t\"name\":\" " + strCKeyword + "\",\n";
strjson += ("\t\"children\": [\n");
for(QMap<QString, QMap<QString, int > >::iterator iterPos1 = mapResult.begin(); iterPos1 != mapResult.end(); iterPos1++)
{
int sum = 0;
for(QMap<QString, int>::iterator iterPos2 = iterPos1.value().begin(); iterPos2 != iterPos1.value().end(); iterPos2++)
{
sum += iterPos2.value();
}
strjson += "\t{\n";
strjson += ("\t\t\"name\":\"" + iterPos1.key() + "\",\"size\":" + QString::number(sum) + ",\n");
strjson += "\t\t\"children\": [\n";
for(QMap<QString, int>::iterator iterPos2 = iterPos1.value().begin(); iterPos2 != iterPos1.value().end(); iterPos2++)
{
strjson += ("\t\t\t{\"name\": \"" + iterPos2.key() + "\", \"size\": " + QString::number(iterPos2.value()) + "},\n");
}
strjson = strjson.trimmed();
strjson = strjson.left(strjson.length() - 1);
strjson += "\n\t\t]\n\t},\n";
}
strjson = strjson.trimmed();
strjson = strjson.left(strjson.length() - 1);
strjson += "\n\t]\n}";
QFile file("c:/data/jsontest.txt");
if(!file.open(QFile::WriteOnly | QFile::Text)) return;
QTextStream out(&file);
out << strjson;
file.close();
/*
QSqlDatabase dbWeb = QSqlDatabase::addDatabase("QMYSQL");
dbWeb.setHostName("db.big-bird.co.kr");
dbWeb.setUserName("concepters");
dbWeb.setPassword("con97996655");
dbWeb.setDatabaseName("dbconcepters");
int nCompany = 90;
if(!dbWeb.open())
qDebug() << "DB open Failed";
QSqlQuery query(QSqlDatabase::database(dbWeb.connectionName()));
QString strquery;
strquery = "insert into stats_json (jdata, company_num) values ('" + strjson + "', " + QString::number(nCompany) + ")";
if(!query.exec(strquery.toUtf8()))
{
strquery = "update stats_json set jdata='" + strjson + "' where company_num=" + QString::number(nCompany);
if(!query.exec(strquery.toUtf8()))
{
qDebug() << query.lastError().text();
}
}
dbWeb.close();
*/
}
void YMTwoDepthWidget::setParam(QString strJson)
{
SJson json;
{
QString strMorphere = json.Get(strJson, "MorphereList");
QStringList slMorphere = strMorphere.split(" ", QString::SkipEmptyParts);
for(int i = 0; i < m_plwMorphereAdd->count(); i++)
{
m_plwMorphereAdd->item(i)->setHidden(true);
}
for(int i = 0; i < m_plwMorphereAdd->count(); i++)
{
foreach(QString morphere, slMorphere)
{
if(m_plwMorphereAdd->item(i)->data(Qt::UserRole).toString().compare(morphere, Qt::CaseInsensitive) == 0)
{
m_plwMorphereAdd->item(i)->setHidden(false);
}
}
}
}
{
int nThread = json.Get(strJson, "Thread").toInt();
for(int i = 0; i < m_pcbThread->count(); i++)
{
//qDebug() << m_pcbThread->itemData(i).toInt();
if(m_pcbThread->itemText(i).trimmed().toInt() == nThread)
{
m_pcbThread->setCurrentIndex(i);
break;
}
}
}
{
QString strCountMethod = json.Get(strJson, "CountMethod").trimmed();
for(int i = 0; i < m_pcbCountMethod->count(); i++)
{
//qDebug() << m_pcbThread->itemData(i).toInt();
if(m_pcbCountMethod->itemText(i).trimmed().compare(strCountMethod) == 0)
{
m_pcbCountMethod->setCurrentIndex(i);
break;
}
}
}
{
QString strRecentPeriod = json.Get(strJson, "RecentPeriod").trimmed();
for(int i = 0; i < m_pcbDuring->count(); i++)
{
//qDebug() << m_pcbThread->itemData(i).toInt();
if(m_pcbDuring->itemText(i).trimmed().compare(strRecentPeriod) == 0)
{
m_pcbDuring->setCurrentIndex(i);
break;
}
}
}
{
int nPeriod = json.Get(strJson, "Period").toInt();
m_pcbPeriod->setCurrentIndex(nPeriod);
}
{
int nBodyTitle = json.Get(strJson, "TitleBody").toInt();
m_pcbData->setCurrentIndex(nBodyTitle);
}
{
QString strDateAll = json.Get(strJson, "DateALL").trimmed();
if(strDateAll.compare("true",Qt::CaseInsensitive) == 0)
{
m_pcbDate->setCurrentIndex(0);
}
else
{
m_pcbDate->setCurrentIndex(1);
}
}
{
QString strRecentDate = json.Get(strJson, "RecentDate");
m_pleDates->setText(strRecentDate);
}
{
m_pdeStart->setDate(QDate::fromString(json.Get(strJson,"DateStart"),"yyyyMMdd"));
m_pdeEnd->setDate(QDate::fromString(json.Get(strJson,"DateEnd"),"yyyyMMdd"));
}
{
QString userdict = json.Get(strJson, "UserDict");
if(!userdict.isEmpty())
{
m_pcbDictionary->clear();
QStringList sluserdict = userdict.split(",");
foreach(QString dict, sluserdict)
{
m_pcbDictionary->addItem(dict);
}
}
else
{
m_pcbDictionary->clear();
}
}
{
QString extractor = json.Get(strJson, "Extractor");
m_pleFilterExtractor->setText(extractor);
}
{
QString keywordfilter = json.Get(strJson, "KeywordFilter");
m_pleFilterKeyword->setText(keywordfilter);
}
{
QString keywordlengthfilter = json.Get(strJson, "KeywordLengthFilter");
m_pleFilterKeywordLength->setText(keywordlengthfilter);
}
{
QString RankFilterAll = json.Get(strJson, "RankFilterAll");
m_pleFilterRankALL->setText(RankFilterAll);
}
{
QString RankSeparated = json.Get(strJson, "RankFilterSeparated");
m_pleFilterRankSeparated->setText(RankSeparated);
}
{
QString CenterKeyword = json.Get(strJson, "CenterKeyword");
m_pleCKeyword->setText(CenterKeyword);
}
{
QString extractor = json.Get(strJson, "Extractor2");
m_pleFilterExtractor2->setText(extractor);
}
{
QString keywordfilter = json.Get(strJson, "KeywordFilter2");
m_pleFilterKeyword2->setText(keywordfilter);
}
{
QString keywordlengthfilter = json.Get(strJson, "KeywordLengthFilter2");
m_pleFilterKeywordLength2->setText(keywordlengthfilter);
}
{
QString RankFilterAll = json.Get(strJson, "RankFilterAll2");
m_pleFilterRankALL2->setText(RankFilterAll);
}
{
QString RankSeparated = json.Get(strJson, "RankFilterSeparated2");
m_pleFilterRankSeparated2->setText(RankSeparated);
}
}
QString YMTwoDepthWidget::getCenterKeyword()
{
return m_pleCKeyword->text().trimmed();
}
QMap<QString, QString> YMTwoDepthWidget::convertToParam()
{
QMap<QString, QString> mapParam;
mapParam.insert("Algorithm", "twodepth");
{
QString strMorphereList = getMorphereList().join(" ");
mapParam.insert("MorphereList",strMorphereList);
}
{
int nThread = getThread();
mapParam.insert("Thread", QString::number(nThread));
}
{
QString strUserDict = getUserDictList();
if(strUserDict.trimmed().length() > 0)
mapParam.insert("UserDict", strUserDict);
}
{
if(getDateAll())
mapParam.insert("DateALL", "true");
else
mapParam.insert("DateALL", "false");
}
{
mapParam.insert("DateStart", QString::number(getDateStart()));
mapParam.insert("DateEnd", QString::number(getDateEnd()));
}
{
mapParam.insert("Period", QString::number(getPeriod()));
}
{
mapParam.insert("CenterKeyword", getCenterKeyword());
}
{
mapParam.insert("CountMethod", m_pcbCountMethod->currentText().trimmed());
}
{
if(!m_pleFilterExtractor->text().trimmed().isEmpty())
mapParam.insert("Extractor", m_pleFilterExtractor->text().trimmed());
}
{
if(!m_pleFilterKeyword->text().trimmed().isEmpty())
mapParam.insert("KeywordFilter",m_pleFilterKeyword->text().trimmed());
}
{
if(!m_pleFilterKeywordLength->text().trimmed().isEmpty())
mapParam.insert("KeywordLengthFilter", m_pleFilterKeywordLength->text().trimmed());
}
{
if(!m_pleFilterRankALL->text().trimmed().isEmpty())
mapParam.insert("RankFilterAll", m_pleFilterRankALL->text().trimmed());
}
{
if(!m_pleFilterRankSeparated->text().trimmed().isEmpty())
mapParam.insert("RankFilterSeparated", m_pleFilterRankSeparated->text().trimmed());
}
{
if(!m_pleFilterExtractor2->text().trimmed().isEmpty())
mapParam.insert("Extractor2", m_pleFilterExtractor2->text().trimmed());
}
{
if(!m_pleFilterKeyword2->text().trimmed().isEmpty())
mapParam.insert("KeywordFilter2",m_pleFilterKeyword2->text().trimmed());
}
{
if(!m_pleFilterKeywordLength2->text().trimmed().isEmpty())
mapParam.insert("KeywordLengthFilter2", m_pleFilterKeywordLength2->text().trimmed());
}
{
if(!m_pleFilterRankALL2->text().trimmed().isEmpty())
mapParam.insert("RankFilterAll2", m_pleFilterRankALL2->text().trimmed());
}
{
if(!m_pleFilterRankSeparated2->text().trimmed().isEmpty())
mapParam.insert("RankFilterSeparated2", m_pleFilterRankSeparated2->text().trimmed());
}
{
mapParam.insert("RecentDate", m_pleDates->text().trimmed());
mapParam.insert("RecentPeriod", m_pcbDuring->currentText().trimmed());
}
{
mapParam.insert("TitleBody", QString::number(m_pcbData->currentIndex()));
}
{
mapParam.insert("Article",QString::number(((STable*)(((Widget*)(m_pTabWidget->currentWidget()))->GetTabWidget()->currentWidget()))->getArticleSelect()));
}
return mapParam;
}