diff --git a/MorphereAnalyzer/MorphereAnalyzer.pro b/MorphereAnalyzer/MorphereAnalyzer.pro index 58e7d89..ec44941 100644 --- a/MorphereAnalyzer/MorphereAnalyzer.pro +++ b/MorphereAnalyzer/MorphereAnalyzer.pro @@ -19,8 +19,12 @@ SOURCES += main.cpp\ stable.cpp \ ../Json/sjson.cpp \ sanaly1.cpp \ + sanaly2.cpp \ sanalyzer.cpp \ - sdictionary.cpp + sdictionary.cpp \ + keywordthread.cpp \ + tablealgorithm_interface.cpp + HEADERS += mainwindow.h \ widget.h \ @@ -28,6 +32,7 @@ HEADERS += mainwindow.h \ ../Json/sjson.h \ ../common.h \ sanaly1.h \ + sanaly2.h \ char_property.h \ common.h \ connector.h \ @@ -57,6 +62,10 @@ HEADERS += mainwindow.h \ winmain.h \ writer.h \ sanalyzer.h \ - sdictionary.h + sdictionary.h \ + keywordthread.h \ + dataalgorithm_interface.h \ + tablealgorithm_interface.h + FORMS += mainwindow.ui diff --git a/MorphereAnalyzer/dataalgorithm_interface.h b/MorphereAnalyzer/dataalgorithm_interface.h new file mode 100644 index 0000000..50759cf --- /dev/null +++ b/MorphereAnalyzer/dataalgorithm_interface.h @@ -0,0 +1,65 @@ +#ifndef DATAALGORITHM_INTERFACE +#define DATAALGORITHM_INTERFACE +#include + +class DataAlgorithmInterface{ + +public: + virtual QString getArticleID() = 0; + virtual QString getKeywordID() = 0; + virtual QString getPlatformName() = 0; + virtual QString getPlatformForm() = 0; + virtual QString getArticleForm() = 0; + virtual QString getArticleNickname() = 0; + virtual QString getArticleDate() = 0; + virtual QString getArticleTitle() = 0; + virtual QString getArticleData() = 0; + virtual QString getArticleUrl() = 0; + virtual QString getArticleParent() = 0; + virtual QString getArticleOrder() = 0; + virtual QString getReplyUrl() = 0; + virtual QString getArticleHit() = 0; + virtual QString getArticleProfileUrl() = 0; + virtual QString getArticleProfile() = 0; + virtual QString getEtc() = 0; + virtual QString getPlatformTitle() = 0; + virtual QString getPlatformID() = 0; + virtual void next() = 0; + virtual bool hasNext() = 0; + virtual int currentIndex() = 0; + virtual void seek(int n) = 0; + virtual int length() = 0; + virtual void reset() = 0; + virtual void moveFirst() = 0; + virtual void moveLast() = 0; + +public: + enum E_DATA + { + E_DATA_platform_title = 0, + E_DATA_article_form, + E_DATA_article_parent, + E_DATA_article_id, + E_DATA_article_nickname, + E_DATA_article_title, + E_DATA_article_data, + E_DATA_article_url, + E_DATA_article_hit, + E_DATA_article_date, + E_DATA_article_order, + E_DATA_platform_id, + E_DATA_platform_name, + E_DATA_platform_form, + E_DATA_reply_url, + E_DATA_keyword_id, + E_DATA_article_profileurl, + E_DATA_article_profile, + E_DATA_etc, + E_DATA_MAX, + }; + + +}; + + +#endif // DATAALGORITHM_INTERFACE diff --git a/MorphereAnalyzer/keywordthread.cpp b/MorphereAnalyzer/keywordthread.cpp new file mode 100644 index 0000000..db58b82 --- /dev/null +++ b/MorphereAnalyzer/keywordthread.cpp @@ -0,0 +1,448 @@ +#include "keywordthread.h" +#include "sanaly2.h" +#include +KeywordThread::KeywordThread(QObject *parent) : QThread(parent), m_nThread(1), m_pWidget(NULL), m_nSource(0), m_bPeriod(false), m_nPeriod(0) +{ +} +KeywordThread::KeywordThread(int number) +{ +} + +KeywordThread::KeywordThread(QMutex &_mutex, int _number, int &_nCount) +{ + KeywordThread(); + num = _number; + mutex = &_mutex; + nCount = &_nCount; +} + +void KeywordThread::setThreadNumber(int _nThread) +{ + m_nThread = _nThread; +} + +int KeywordThread::getThreadNumber() +{ + return m_nThread; +} + +void KeywordThread::setWidget(QWidget *_pWidget) +{ + m_pWidget = (Widget*)_pWidget; + m_pTabWidget = m_pWidget->GetTabWidget(); +} + +QWidget* KeywordThread::getWidget() +{ + return m_pQWidget; +} + +void KeywordThread::setMorphereList(const QStringList morpherelist) +{ + m_slMorphereList.append(morpherelist); +} + + +void KeywordThread::setMorphereList(const QString morphere) +{ + m_slMorphereList.append(morphere); +} + +void KeywordThread::resetMorphereList() +{ + m_slMorphereList.clear(); +} + +void KeywordThread::setParametersfromWidget(QWidget *_pWidget, int _nSource) +{ + resetMorphereList(); + if(_nSource == 0) + { + pWidget = (SAnaly2*)_pWidget; + setThreadNumber(pWidget->getThread()); + setPeriod(pWidget->getPeriod()); + m_bDateAll = pWidget->getDateAll(); + m_nDateStart = pWidget->getDateStart(); + m_nDateEnd = pWidget->getDateEnd(); + setMorphereList(pWidget->getMorphereList()); + } +} + +QStringList KeywordThread::getMorphereList() +{ + return m_slMorphereList; +} + +void KeywordThread::setPeriod(const int _nPeriod) +{ + m_nPeriod = _nPeriod; +} + +int KeywordThread::getPeriod() +{ + return m_nPeriod; +} + +void KeywordThread::setDate(const QDateTime _dtStart, const QDateTime _dtEnd) +{ + m_nDateStart = _dtStart.toString("yyyy-MM-dd").replace("-","").toInt(); + m_nDateEnd = _dtEnd.toString("yyyy-MM-dd").replace("-","").toInt(); +} +void KeywordThread::setDate(const QString _strStart, const QString _strEnd) +{ + m_nDateStart = _strStart.toInt(); + m_nDateEnd = _strEnd.toInt(); +} + +unsigned int KeywordThread::getDateStart() +{ + return m_nDateStart; +} + +unsigned int KeywordThread::getDateEnd() +{ + return m_nDateEnd; +} + +void KeywordThread::setTitleBody(const int _n) +{ + m_nTitleBody = _n; +} + +void KeywordThread::setPosDate(const int _nPos) +{ + m_nPosDate = _nPos; +} + +void KeywordThread::setPosBody(const int _nPos) +{ + m_nPosBody = _nPos; +} + +void KeywordThread::setPosTitle(const int _nPos) +{ + m_nPosTitle = _nPos; +} + +void KeywordThread::setPosPlatformTitle(const int _nPos) +{ + m_nPosPlatformTitle = _nPos; +} + +void KeywordThread::run() +{ + + typedef mecab_t* (*mecab_new_fun)(int,char**); + typedef const char* (*mecab_sparse_tostr_fun)(mecab_t *mecab, const char *str); + typedef void (*mecab_destroy_fun)(mecab_t *mecab); + + mecab_t *mecab; + mecab_new_fun mecab_new = (mecab_new_fun)QLibrary::resolve("libmecab.dll","mecab_new"); + mecab_sparse_tostr_fun mecab_sparse_tostr = (mecab_sparse_tostr_fun)QLibrary::resolve("libmecab.dll","mecab_sparse_tostr"); + + QString userdict = pWidget->getUserDictList(); + + if(userdict.length() < 1) + { + /* + char *t[] = {"RRR","-d","dic"}; + int int_t = 3; + */ + + char a[] = "RRR"; + char b[] = "-d"; + char c[] = "dic"; + char *t[3]; + t[0] = a; + t[1] = b; + t[2] = c; + int int_t = 3; + + mecab = mecab_new(int_t, t); + } + else + { + char *cstr = new char[userdict.toStdString().length() + 1]; + strcpy(cstr, userdict.toStdString().c_str()); + /* + char **t = {"RRR","-d","dic","-u",cstr}; + int int_t = 5; + */ + char a[] = "RRR"; + char b[] = "-d"; + char c[] = "dic"; + char d[] = "-u"; + + char *t[5]; + t[0] = a; + t[1] = b; + t[2] = c; + t[3] = d; + t[4] = cstr; + int int_t = 5; + + mecab = mecab_new(int_t, t); + delete[] cstr; + } + mecab_destroy_fun mecab_destroy = (mecab_destroy_fun)QLibrary::resolve("libmecab.dll","mecab_destroy"); + + + + //qDebug() << num; + + STable *pCurrent = (STable *)m_pTabWidget->currentWidget(); + int nDate = 0; + while(true) + { + QString strTitle; + QString strBody; + QString strDate; + QString strData; + QString strPlatformTitle; + { + mutex->lock(); + if(*nCount >= pCurrent->rowCount()) + { + mutex->unlock(); + break; + } + strTitle = pCurrent->item((*nCount),m_nPosTitle)->text(); + strDate = pCurrent->item((*nCount),m_nPosDate)->text(); + strPlatformTitle = pCurrent->item((*nCount),m_nPosPlatformTitle)->text(); + strBody = pCurrent->item((*nCount)++,m_nPosBody)->text(); + + mutex->unlock(); + } + + { + switch(m_nTitleBody) + { + case 0: + { + strData = strTitle; + break; + } + case 1: + { + strData = strBody; + break; + } + case 2: + { + strData = strTitle + "\n" + strBody; + break; + } + case 3: + strData = strPlatformTitle; + break; + } + strTitle.clear(); + strBody.clear(); + strPlatformTitle.clear(); + } + + if(!strData.contains(m_strCKeyword, Qt::CaseInsensitive)) + continue; + + if(strDate.length() < 11) + continue; + + strDate = strDate.left(11); + if(strDate.trimmed().length()<10) + { + nDate = 0; + } + else + { + strDate = strDate.replace("-","").trimmed(); + if(strDate.length() < 8) + { + nDate = 0; + } + else + nDate = strDate.toInt(); + } + + if(!m_bDateAll) + { + if(nDate < m_nDateStart || m_nDateEnd < nDate) + continue; + } + + + SAnaly2::m_mapKey mapkey; + + switch(m_nPeriod) + { + case 0: + { + mapkey.strDate = "ALL"; + break; + } + case 1: + { + mapkey.strDate = "D" + QString::number(nDate); + break; + } + case 2: + { + /* + QDate tempdate = QDate(nDate/10000, (nDate%10000)/100, nDate%100); + mapkey.strDate = "W" + QString::number(nDate/10000); + if(tempdate.weekNumber() < 10) + mapkey.strDate += "0"; + mapkey.strDate += QString::number(tempdate.weekNumber()); + */ + mapkey.strDate = getWeeksInMonth(nDate); + break; + } + case 3: + { + mapkey.strDate = "M"; + if((nDate/100) < 10) + mapkey.strDate += "0"; + mapkey.strDate += QString::number(nDate/100); + break; + } + } + + QString strAnalyzedLine = QString::fromStdString(mecab_sparse_tostr(mecab, strData.toStdString().c_str())) + "\n"; + QStringList strListAll = strAnalyzedLine.split("\n",QString::SkipEmptyParts); + + foreach(QString strLine, strListAll) + { + QStringList strListLine = strLine.split("\t"); + if(strListLine.size() < 2) + continue; + QStringList strpumsa = strListLine.at(1).trimmed().split(","); + foreach(QString strMorphere, m_slMorphereList) + { + if(strpumsa.at(0).trimmed().contains(strMorphere,Qt::CaseInsensitive)) + { + mapkey.strKeyword = strListLine.at(0); + mapkey.strMorphere = strMorphere; + QString strkey = mapkey.strDate + "~!@" + mapkey.strMorphere + "~!@" + mapkey.strKeyword; + if(pWidget->m_HashResult[num].contains(strkey)) + { + (pWidget->m_HashResult[num])[strkey]++; + } + + else + { + pWidget->m_HashResult[num].insert(strkey,1); + } + } + } + } + + //if(m_bDateAll) + + //qDebug() << num << " : " << strData; + } + + mecab_destroy(mecab); + /* + for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ ) + { + QString strData = pCurrent->item(nCount,m_nPosBody)->text(); + qDebug() << strData; + } + + for(QHash::iterator iterPos = pWidget->m_HashResult[num].begin(); iterPos != pWidget->m_HashResult[num].end(); iterPos++) + { + qDebug() << num << " : " << iterPos.key() << " ===== " << iterPos.value(); + } + + foreach(QString str, m_slMorphereList) + { + qDebug() << num << " : " << str; + } + qDebug() << num << " : " << m_bDateAll; + qDebug() << num << " : " << m_bPeriod; + qDebug() << num << " : " << m_nDateStart; + qDebug() << num << " : " << m_nDateEnd; + qDebug() << num << " : " << pWidget->m_HashResult[num].isEmpty(); + */ +} + +QString KeywordThread::getWeeksInMonth(unsigned int _nDate) +{ + QDate qToday(_nDate/10000, (_nDate/100)%100, _nDate%100); + if(!qToday.isValid()) + return "inVaildDate"; + + QDate qTodayFirstDay = QDate(qToday.year(), qToday.month(), 1); + QDate qTodayLastDay = QDate(qToday.year(), qToday.month(), qToday.daysInMonth()); + + int thisFirstDayofWeek = qTodayFirstDay.dayOfWeek(); + int thisLastDayofWeek = qTodayLastDay.dayOfWeek(); + int thisLastDay = qTodayLastDay.daysInMonth(); + int week = 0; + int firstWeekDays = (WEEK - thisFirstDayofWeek) + 1; + QString strWeek = "W"; + + if(thisFirstDayofWeek < FRIDAY) + { + week = 1; + } + else + { + week = 0; + } + + if((firstWeekDays < qToday.day()) && (qToday.day() <= (thisLastDay - thisLastDayofWeek))) + { + week = week + ((qToday.day() - firstWeekDays + WEEK - 1)/WEEK); + } + else if((firstWeekDays >= qToday.day())) + { + if(thisFirstDayofWeek >= FRIDAY) + { + + const int DAYS_IN_WEEK = 7; + qToday = qToday.addMonths(-1); + int DaysInMonth = qToday.daysInMonth(); + QDate FirstDayOfMonth = qToday; + FirstDayOfMonth.setDate(qToday.year(), qToday.month(), 1); + + int WeekCount = DaysInMonth / DAYS_IN_WEEK; + int DaysLeft = DaysInMonth % DAYS_IN_WEEK; + if (DaysLeft > 0) { + WeekCount++; + // Check if the remaining days are split on two weeks + if (FirstDayOfMonth.dayOfWeek() + DaysLeft - 1 > DAYS_IN_WEEK) + WeekCount++; + } + week = WeekCount; + } + } + else + { + if(thisLastDayofWeek < THURSDAY) + { + week = 1; + qToday = qToday.addMonths(1); + } + else + { + week = week + ((qToday.day() - firstWeekDays + WEEK - 1)/WEEK); + } + } + + strWeek += qToday.toString("yyyyMM"); + strWeek += QString::number(week); + return strWeek; + +} + +void KeywordThread::setKeywordThread(QMutex &_mutex, int number, int &_nCount) +{ + num = number; + mutex = &_mutex; + nCount = &_nCount; +} + +void KeywordThread::setCenterKeyword(QString strCKeyword) +{ + m_strCKeyword = strCKeyword; +} diff --git a/MorphereAnalyzer/keywordthread.h b/MorphereAnalyzer/keywordthread.h new file mode 100644 index 0000000..30c8d21 --- /dev/null +++ b/MorphereAnalyzer/keywordthread.h @@ -0,0 +1,98 @@ +#ifndef KEYWORDTHREAD +#define KEYWORDTHREAD + +#include +#include +#include "widget.h" +#include +#include +#include "mecab.h" +#include + +class SAnaly2; +class KeywordThread : public QThread +{ + + Q_OBJECT +public: + + KeywordThread(QObject *parent = NULL); + KeywordThread(int number); + KeywordThread(QMutex &_mutex, int number, int &_nCount); + +private: + + enum { + MONDAY = 1, + TUESDAY, + WEDNESDAY, + THURSDAY, + FRIDAY, + SATURDAY, + SUNDAY + }; + + enum + { + WEEK = 7 + }; + int num; + QWidget *m_pQWidget; + int m_nThread; + QStringList m_slMorphereList; + int m_nSource; + bool m_bPeriod; + bool m_bDateAll; + int m_nPeriod; // 0 none, 1 1day, 2 1week, 3 1month; + unsigned int m_nDateStart; + unsigned int m_nDateEnd; + int m_nTitleBody; + Widget *m_pWidget; + int m_nPosDate; + int m_nPosBody; + int m_nPosTitle; + int m_nPosPlatformTitle; + QMutex *mutex; + SAnaly2 *pWidget; + QTabWidget *m_pTabWidget; + int *nCount; + QString m_strCKeyword; + +protected: + void run(); + +public: + void setThreadNumber(int _nThread = 1); + int getThreadNumber(); + void setWidget(QWidget *_pWidget); + QWidget* getWidget(); + void setMorphereList(const QStringList morpherelist); + void setMorphereList(const QString morphere); + QStringList getMorphereList(); + void resetMorphereList(); + void setParametersfromWidget(QWidget *_pWidget, int _nSource); + void setPeriod(const int _nPeriod); + int getPeriod(); + void setDate(const QString _strStart, const QString _strEnd); + void setDate(const QDateTime _dtStart, const QDateTime _dtEnd); + void setDateStart(const QString _strStart); + void setDateStart(const QDateTime _dtStart); + void setDateEnd(const QString _strEnd); + void setDateEnd(const QDateTime _dtStart); + unsigned int getDateStart(); + unsigned int getDateEnd(); + void setTitleBody(const int _n); + void setSource(QWidget* _qwidget); + void setPosDate(const int _nPos); + void setPosBody(const int _nPos); + void setPosTitle(const int _nPos); + void setPosPlatformTitle(const int _nPos); + QString getWeeksInMonth(unsigned int _nDate); + void setKeywordThread(QMutex &_mutex, int number, int &_nCount); + void setCenterKeyword(QString strCKeyword); + +}; + + +#endif // KEYWORDTHREAD + diff --git a/MorphereAnalyzer/mainwindow.cpp b/MorphereAnalyzer/mainwindow.cpp index 5db97eb..60e4793 100644 --- a/MorphereAnalyzer/mainwindow.cpp +++ b/MorphereAnalyzer/mainwindow.cpp @@ -39,12 +39,11 @@ ****************************************************************************/ #include - #include "mainwindow.h" #include "widget.h" #include "stable.h" -#include "sanaly1.h" #include "sdictionary.h" +#include "tablealgorithm_interface.h" //! [0] MainWindow::MainWindow() { @@ -55,9 +54,12 @@ MainWindow::MainWindow() //p_qwAnalyzed1 = new QWidget; //p_qwText = new QWidget; p_qwAnalyzer1 = new SAnaly1; - //p_qwAnalyzer2 = new QWidget; + p_qwAnalyzer2 = new SAnaly2; + p_qwDict = new SDictionary; + p_qwAnalyzer1->setWidget(p_qwDB); + p_qwAnalyzer2->setWidget(p_qwDB); m_ptwSource = new QTabWidget; m_ptwSource->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -70,7 +72,7 @@ MainWindow::MainWindow() m_ptwResult = new QTabWidget; m_ptwResult->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_ptwResult->addTab(p_qwAnalyzer1, "Analysis1"); - //m_ptwResult->addTab(p_qwAnalyzer2, "Analysis2"); + m_ptwResult->addTab(p_qwAnalyzer2, "Analysis2"); QHBoxLayout *layout = new QHBoxLayout; @@ -88,118 +90,11 @@ MainWindow::MainWindow() QString message = tr("A context menu is available by right-clicking"); statusBar()->showMessage(message); + setWindowTitle(tr("Morphere Analyzer")); setMinimumSize(800, 600); resize(800, 600); - //(STable*)(p_qwDB->GetTabWidget()->widget(1)); } -//! [2] - -//! [3] -/* -void MainWindow::contextMenuEvent(QContextMenuEvent *event) -{ - QMenu menu(this); - menu.addAction(cutAct); - menu.addAction(copyAct); - menu.addAction(pasteAct); - menu.exec(event->globalPos()); -} -*/ -//! [3] -/* -void MainWindow::newFile() -{ -} - -void MainWindow::open() -{ -} - -void MainWindow::save() -{ -} - -void MainWindow::print() -{ -} - -void MainWindow::undo() -{ -} - -void MainWindow::redo() -{ -} - -void MainWindow::cut() -{ -} - -void MainWindow::copy() -{ - -} - -void MainWindow::paste() -{ - -} - -void MainWindow::bold() -{ - -} - -void MainWindow::italic() -{ - -} - -void MainWindow::leftAlign() -{ - -} - -void MainWindow::rightAlign() -{ - -} - -void MainWindow::justify() -{ - -} - -void MainWindow::center() -{ - -} - -void MainWindow::setLineSpacing() -{ - -} - -void MainWindow::setParagraphSpacing() -{ - -} - -void MainWindow::about() -{ - - QMessageBox::about(this, tr("About Menu"), - tr("The Menu example shows how to create " - "menu-bar menus and context menus.")); -} - -void MainWindow::aboutQt() -{ - -} -*/ -//! [4] void MainWindow::createActions() { //! [5] @@ -228,8 +123,6 @@ void MainWindow::createActions() actMorphereImport->setStatusTip(tr("Import Morphere as a csv file")); connect(actMorphereImport, SIGNAL(triggered()), this, SLOT(importMorphere())); - - actExit = new QAction(tr("Exit"), this); actExit->setStatusTip(tr("Exit the application")); connect(actExit, SIGNAL(triggered()), this, SLOT(close())); @@ -241,140 +134,8 @@ void MainWindow::createActions() actDictionary = new QAction(tr("Dictionary"), this); actAnalyze->setStatusTip(tr("Execute Dictionary Widget")); connect(actDictionary, SIGNAL(triggered()), this, SLOT(slotDictionary())); -/* -//! - newAct = new QAction(tr("&New"), this); - newAct->setShortcuts(QKeySequence::New); - newAct->setStatusTip(tr("Create a new file")); - connect(newAct, SIGNAL(triggered()), this, SLOT(newFile())); -//! [4] - - openAct = new QAction(tr("&Open..."), this); - openAct->setShortcuts(QKeySequence::Open); - openAct->setStatusTip(tr("Open an existing file")); - connect(openAct, SIGNAL(triggered()), this, SLOT(open())); -//! [5] - - saveAct = new QAction(tr("&Save"), this); - saveAct->setShortcuts(QKeySequence::Save); - saveAct->setStatusTip(tr("Save the document to disk")); - connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); - - printAct = new QAction(tr("&Print..."), this); - printAct->setShortcuts(QKeySequence::Print); - printAct->setStatusTip(tr("Print the document")); - connect(printAct, SIGNAL(triggered()), this, SLOT(print())); - - exitAct = new QAction(tr("E&xit"), this); - exitAct->setShortcuts(QKeySequence::Quit); - exitAct->setStatusTip(tr("Exit the application")); - connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); - - undoAct = new QAction(tr("&Undo"), this); - undoAct->setShortcuts(QKeySequence::Undo); - undoAct->setStatusTip(tr("Undo the last operation")); - connect(undoAct, SIGNAL(triggered()), this, SLOT(undo())); - - redoAct = new QAction(tr("&Redo"), this); - redoAct->setShortcuts(QKeySequence::Redo); - redoAct->setStatusTip(tr("Redo the last operation")); - connect(redoAct, SIGNAL(triggered()), this, SLOT(redo())); - - cutAct = new QAction(tr("Cu&t"), this); - cutAct->setShortcuts(QKeySequence::Cut); - cutAct->setStatusTip(tr("Cut the current selection's contents to the " - "clipboard")); - connect(cutAct, SIGNAL(triggered()), this, SLOT(cut())); - - copyAct = new QAction(tr("&Copy"), this); - copyAct->setShortcuts(QKeySequence::Copy); - copyAct->setStatusTip(tr("Copy the current selection's contents to the " - "clipboard")); - connect(copyAct, SIGNAL(triggered()), this, SLOT(copy())); - - pasteAct = new QAction(tr("&Paste"), this); - pasteAct->setShortcuts(QKeySequence::Paste); - pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current " - "selection")); - connect(pasteAct, SIGNAL(triggered()), this, SLOT(paste())); - - boldAct = new QAction(tr("&Bold"), this); - boldAct->setCheckable(true); - boldAct->setShortcut(QKeySequence::Bold); - boldAct->setStatusTip(tr("Make the text bold")); - connect(boldAct, SIGNAL(triggered()), this, SLOT(bold())); - - QFont boldFont = boldAct->font(); - boldFont.setBold(true); - boldAct->setFont(boldFont); - - italicAct = new QAction(tr("&Italic"), this); - italicAct->setCheckable(true); - italicAct->setShortcut(QKeySequence::Italic); - italicAct->setStatusTip(tr("Make the text italic")); - connect(italicAct, SIGNAL(triggered()), this, SLOT(italic())); - - QFont italicFont = italicAct->font(); - italicFont.setItalic(true); - italicAct->setFont(italicFont); - - setLineSpacingAct = new QAction(tr("Set &Line Spacing..."), this); - setLineSpacingAct->setStatusTip(tr("Change the gap between the lines of a " - "paragraph")); - connect(setLineSpacingAct, SIGNAL(triggered()), this, SLOT(setLineSpacing())); - - setParagraphSpacingAct = new QAction(tr("Set &Paragraph Spacing..."), this); - setParagraphSpacingAct->setStatusTip(tr("Change the gap between paragraphs")); - connect(setParagraphSpacingAct, SIGNAL(triggered()), - this, SLOT(setParagraphSpacing())); - - aboutAct = new QAction(tr("&About"), this); - aboutAct->setStatusTip(tr("Show the application's About box")); - connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); - - aboutQtAct = new QAction(tr("About &Qt"), this); - aboutQtAct->setStatusTip(tr("Show the Qt library's About box")); - connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); - connect(aboutQtAct, SIGNAL(triggered()), this, SLOT(aboutQt())); - - leftAlignAct = new QAction(tr("&Left Align"), this); - leftAlignAct->setCheckable(true); - leftAlignAct->setShortcut(tr("Ctrl+L")); - leftAlignAct->setStatusTip(tr("Left align the selected text")); - connect(leftAlignAct, SIGNAL(triggered()), this, SLOT(leftAlign())); - - rightAlignAct = new QAction(tr("&Right Align"), this); - rightAlignAct->setCheckable(true); - rightAlignAct->setShortcut(tr("Ctrl+R")); - rightAlignAct->setStatusTip(tr("Right align the selected text")); - connect(rightAlignAct, SIGNAL(triggered()), this, SLOT(rightAlign())); - - justifyAct = new QAction(tr("&Justify"), this); - justifyAct->setCheckable(true); - justifyAct->setShortcut(tr("Ctrl+J")); - justifyAct->setStatusTip(tr("Justify the selected text")); - connect(justifyAct, SIGNAL(triggered()), this, SLOT(justify())); - - centerAct = new QAction(tr("&Center"), this); - centerAct->setCheckable(true); - centerAct->setShortcut(tr("Ctrl+E")); - centerAct->setStatusTip(tr("Center the selected text")); - connect(centerAct, SIGNAL(triggered()), this, SLOT(center())); - -//! [6] //! [7] - alignmentGroup = new QActionGroup(this); - alignmentGroup->addAction(leftAlignAct); - alignmentGroup->addAction(rightAlignAct); - alignmentGroup->addAction(justifyAct); - alignmentGroup->addAction(centerAct); - leftAlignAct->setChecked(true); -//! [6] -//! */ } -//! [7] -//! [8] -//! void MainWindow::createMenus() { //! [9] //! [10] @@ -403,34 +164,6 @@ void MainWindow::createMenus() menuAnalyze->addAction(actAnalyze); - /* - editMenu = menuBar()->addMenu(tr("&Edit")); - editMenu->addAction(undoAct); - editMenu->addAction(redoAct); - editMenu->addSeparator(); - editMenu->addAction(cutAct); - editMenu->addAction(copyAct); - editMenu->addAction(pasteAct); - editMenu->addSeparator(); - - helpMenu = menuBar()->addMenu(tr("&Help")); - helpMenu->addAction(aboutAct); - helpMenu->addAction(aboutQtAct); -//! [8] - -//! [12] - formatMenu = editMenu->addMenu(tr("&Format")); - formatMenu->addAction(boldAct); - formatMenu->addAction(italicAct); - formatMenu->addSeparator()->setText(tr("Alignment")); - formatMenu->addAction(leftAlignAct); - formatMenu->addAction(rightAlignAct); - formatMenu->addAction(justifyAct); - formatMenu->addAction(centerAct); - formatMenu->addSeparator(); - formatMenu->addAction(setLineSpacingAct); - formatMenu->addAction(setParagraphSpacingAct); - */ } //! [12] @@ -452,9 +185,7 @@ void MainWindow::exportDB() void MainWindow::importMorphere() { - qDebug() << "import is executed"; p_qwAnalyzer1->FileImport(); - ViewResult(); } void MainWindow::exportMorphere() @@ -464,96 +195,7 @@ void MainWindow::exportMorphere() void MainWindow::exportOriginalMorphere() { - - 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 > >::iterator iterPos = p_qwAnalyzer1->m_mapViewResult.begin(); iterPos != p_qwAnalyzer1->m_mapViewResult.end(); iterPos++) - { - for(QMap >::iterator iterPos2 = iterPos.value().begin(); iterPos2 != iterPos.value().end(); iterPos2++) - { - QMapIterator i(p_qwAnalyzer1->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(); - -/* - for( QMap > >::iterator iterPos = p_qwAnalyzer1->m_mapViewResult.begin(); iterPos != p_qwAnalyzer1->m_mapViewResult.end(); iterPos++) - { - for(QMap >::iterator iterPos2 = iterPos.value().begin(); iterPos2 != iterPos.value().end(); iterPos2++) - { - for(QMap::iterator iterPos3 = iterPos2.value().begin();iterPos3 != iterPos2.value().end(); iterPos3++) - { - out2 << iterPos.key() << "," << iterPos2.key() << "," << iterPos3.key() << "," << iterPos3.value() << "\n"; - - } - } - } - - - for( QMap > >::iterator iterPos = p_qwAnalyzer1->m_mapViewResult.begin(); iterPos != p_qwAnalyzer1->m_mapViewResult.end(); iterPos++) - { - for(QMap >::iterator iterPos2 = iterPos.value().begin(); iterPos2 != iterPos.value().end(); iterPos2++) - { - QMapIterator i(p_qwAnalyzer1->m_mapViewResult[iterPos.key()][iterPos2.key()]); - i.toBack(); - while(i.hasPrevious()) - { - i.previous(); - out2 << iterPos.key() << "," << iterPos2.key() << "," << i.key() << "," << i.value() << "\n"; - } - } - } - - - QFile file("result.txt"); - - if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - qDebug() << "File read error"; - - return ; - } - QTextStream out(&file); - - for(QMap::iterator iterPos = p_qwAnalyzer1->m_TotalResult.begin(); iterPos != p_qwAnalyzer1->m_TotalResult.end(); iterPos++) - { - QString strkey = iterPos.key(); - QStringList strlistKey = strkey.split("~!@"); - foreach(QString str, strlistKey) - { - out << str << ","; - } - out << iterPos.value() << "\n"; - } - - file.close(); - -*/ - + p_qwAnalyzer1->RawFileExport(); } void MainWindow::slotAnalyze() @@ -561,6 +203,7 @@ void MainWindow::slotAnalyze() QMessageBox msg; msg.setText("Please choose..."); msg.setModal(true); + QPushButton *pbTitle = msg.addButton("Title",QMessageBox::ActionRole); QPushButton *pbBody = msg.addButton("Body",QMessageBox::ActionRole); QPushButton *pbAll = msg.addButton("ALL",QMessageBox::ActionRole); @@ -572,25 +215,20 @@ void MainWindow::slotAnalyze() else if (msg.clickedButton() == pbAll) { setbody = 2; } else if (msg.clickedButton() == pbPlatformTitle) { setbody = 3; } + QMessageBox msg2; msg2.setText("Please wait..."); msg2.setVisible(true); - for(int i = 0; i < 16;i++) - { - p_qwAnalyzer1->m_HashResult[i].clear(); - } - //p_qwAnalyzer1->MemClear(); - p_qwAnalyzer1->m_mapViewResult.clear(); - p_qwAnalyzer1->m_TotalResult.clear(); - if(m_ptwResult->currentIndex() == 0) { - ExecThread(setbody); - EmergeThreadResult(); - SortViewResult(); - ViewResult(); + p_qwAnalyzer1->Exec(setbody); } + else if(m_ptwResult->currentIndex() == 1) + { + p_qwAnalyzer2->Exec(setbody); + } + msg2.setVisible(false); } @@ -599,179 +237,3 @@ void MainWindow::slotDictionary() p_qwDict->show(); p_qwDict->repaint(); } - -void MainWindow::ExecThread(int _setBodyTitle) -{ - int nCount = 0; - m_pThread = new AnalyzerThread*[p_qwAnalyzer1->getThread()]; - for(int i=0;igetThread();i++) - { - m_pThread[i] = new AnalyzerThread(mutex, i, nCount); - m_pThread[i]->setParametersfromWidget(p_qwAnalyzer1,m_ptwResult->currentIndex()); - m_pThread[i]->setWidget(p_qwDB); - m_pThread[i]->setPosBody(p_qwDB->getBodyPosition()); - m_pThread[i]->setPosDate(p_qwDB->getDatePosition()); - m_pThread[i]->setPosTitle(p_qwDB->getTitlePosition()); - m_pThread[i]->setPosPlatformTitle(p_qwDB->getPlatformTitlePosition()); - m_pThread[i]->setTitleBody(_setBodyTitle); - } - for(int i=0;igetThread();i++) - { - m_pThread[i]->start(); - } - for(int i=0;igetThread();i++) - { - m_pThread[i]->wait(); - } - - for(int i=0;igetThread();i++) - { - delete m_pThread[i]; - } - delete[] m_pThread; - -} - - -void MainWindow::EmergeThreadResult() -{ - for(int i=0;igetThread();i++) - { - for(QHash::iterator iterPos = p_qwAnalyzer1->m_HashResult[i].begin(); iterPos != p_qwAnalyzer1->m_HashResult[i].end();iterPos++) - { - if(p_qwAnalyzer1->m_TotalResult.contains(iterPos.key())) - { - p_qwAnalyzer1->m_TotalResult[iterPos.key()] += iterPos.value(); - } - else - { - p_qwAnalyzer1->m_TotalResult.insert(iterPos.key(), iterPos.value()); - } - } - p_qwAnalyzer1->m_HashResult[i].clear(); - } -} - -void MainWindow::SortViewResult() -{ - - if(p_qwAnalyzer1->isSortDateMorphereChecked()) - { - for(QMap::iterator iterPos = p_qwAnalyzer1->m_TotalResult.begin(); iterPos != p_qwAnalyzer1->m_TotalResult.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(p_qwAnalyzer1->m_mapViewResult.contains(strDate)) - { - if(p_qwAnalyzer1->m_mapViewResult.value(strDate).contains(strMorphere)) - { - p_qwAnalyzer1->m_mapViewResult[(strDate)][(strMorphere)].insertMulti(count, strKeyword); - } - else - { - QMap qLast; - qLast.insert(count, strKeyword); - p_qwAnalyzer1->m_mapViewResult[(strDate)].insert(strMorphere, qLast); - } - } - else - { - QMap qLast; - qLast.insert(count , strKeyword); - QMap > qMedium; - qMedium.insert(strMorphere, qLast); - p_qwAnalyzer1->m_mapViewResult.insert(strDate, qMedium); - } - } - } - else - { - for(QMap::iterator iterPos = p_qwAnalyzer1->m_TotalResult.begin(); iterPos != p_qwAnalyzer1->m_TotalResult.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(p_qwAnalyzer1->m_mapViewResult.contains(strMorphere)) - { - if(p_qwAnalyzer1->m_mapViewResult.value(strMorphere).contains(strDate)) - { - p_qwAnalyzer1->m_mapViewResult[(strMorphere)][(strDate)].insertMulti(count, strKeyword); - } - else - { - QMap qLast; - qLast.insert(count, strKeyword); - p_qwAnalyzer1->m_mapViewResult[(strMorphere)].insert(strDate, qLast); - } - } - else - { - QMap qLast; - qLast.insert(count , strKeyword); - QMap > qMedium; - qMedium.insert(strDate, qLast); - p_qwAnalyzer1->m_mapViewResult.insert(strMorphere, qMedium); - } - } - } -} - -void MainWindow::ViewResult() -{ - - 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 = p_qwAnalyzer1->getQTabWidget(); - m_ptwTable->clear(); - - for( QMap > >::iterator iterPos = p_qwAnalyzer1->m_mapViewResult.begin(); iterPos != p_qwAnalyzer1->m_mapViewResult.end(); iterPos++) - { - QTabWidget* temp = new QTabWidget; - for(QMap >::iterator iterPos2 = iterPos.value().begin(); iterPos2 != iterPos.value().end(); iterPos2++) - { - int ncRow = 0; - - STable *pNew = new STable; - pNew->setColumnCount(2); - pNew->setRowCount(p_qwAnalyzer1->m_mapViewResult[iterPos.key()][iterPos2.key()].size()); - pNew->setHorizontalHeaderItem(0 ,new QTableWidgetItem("Keyword")); - pNew->setHorizontalHeaderItem(1 ,new QTableWidgetItem("Count")); - - QMapIterator i(p_qwAnalyzer1->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; - } - m_ptwTable->addTab(temp, iterPos.key()); - m_lTabWidget << temp; - } -} diff --git a/MorphereAnalyzer/mainwindow.h b/MorphereAnalyzer/mainwindow.h index ce248ba..0d9658f 100644 --- a/MorphereAnalyzer/mainwindow.h +++ b/MorphereAnalyzer/mainwindow.h @@ -43,9 +43,10 @@ #include #include -#include "sanalyzer.h" #include "widget.h" #include "sanaly1.h" +#include "sanaly2.h" + #include #include "sdictionary.h" @@ -63,37 +64,12 @@ class MainWindow : public QMainWindow public: MainWindow(); - void ExecThread(int _setBodyTitle); - void EmergeThreadResult(); - void SortViewResult(); - void ViewResult(); protected: //void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE; //! [0] //! [1] private slots: - /* - void newFile(); - void open(); - void save(); - void print(); - void undo(); - void redo(); - void cut(); - void copy(); - void paste(); - void bold(); - void italic(); - void leftAlign(); - void rightAlign(); - void justify(); - void center(); - void setLineSpacing(); - void setParagraphSpacing(); - void about(); - void aboutQt(); -*/ void newDB(); void importDB(); void exportDB(); @@ -117,34 +93,7 @@ private: //! [3] //! //! - /* - * QMenu *fileMenu; - QMenu *editMenu; - QMenu *formatMenu; - QMenu *helpMenu; - QActionGroup *alignmentGroup; - QAction *newAct; - QAction *openAct; - QAction *saveAct; - QAction *printAct; - QAction *exitAct; - QAction *undoAct; - QAction *redoAct; - QAction *cutAct; - QAction *copyAct; - QAction *pasteAct; - QAction *boldAct; - QAction *italicAct; - QAction *leftAlignAct; - QAction *rightAlignAct; - QAction *justifyAct; - QAction *centerAct; - QAction *setLineSpacingAct; - QAction *setParagraphSpacingAct; - QAction *aboutAct; - QAction *aboutQtAct; - QLabel *infoLabel; - */ + QTabWidget *m_ptwSource; QTabWidget *m_ptwResult; QWidget *m_qwMain; @@ -156,7 +105,7 @@ private: SDictionary *p_qwDict; SAnaly1 *p_qwAnalyzer1; - QWidget *p_qwAnalyzer2; + SAnaly2 *p_qwAnalyzer2; QAction *actDBNew; @@ -173,12 +122,14 @@ private: QMenu *menuFile; QMenu *menuAnalyze; QMenu *menuDictionary; + + //AnalyzerThread m_pThread[16]; + /* QMutex mutex; AnalyzerThread **m_pThread; - //AnalyzerThread m_pThread[16]; QList m_lTable; QList m_lTabWidget; - + */ QTabWidget* m_ptwTable; }; //! [3] diff --git a/MorphereAnalyzer/sanaly1.cpp b/MorphereAnalyzer/sanaly1.cpp index 3a5dd15..d6724b4 100644 --- a/MorphereAnalyzer/sanaly1.cpp +++ b/MorphereAnalyzer/sanaly1.cpp @@ -13,7 +13,7 @@ #include #include "../Json/sjson.h" #include "../common.h" - +#include "tablealgorithm_interface.h" /* QSqlDatabase dbWeb = QSqlDatabase::addDatabase("QMYSQL"); @@ -372,941 +372,6 @@ void SAnaly1::DoubleClickTab(int index) } } -QMenuBar *SAnaly1::setMenuWidget() -{ - QMenuBar *pMenuBar = new QMenuBar(); - { - QMenu *pFile = pMenuBar->addMenu("File"); - connect(pFile->addAction("New"), SIGNAL(triggered()), this, SLOT(FileNew())); - 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 SAnaly1::FileNew() -{ - bool ok; - QString text = QInputDialog::getText(this,"New Row Count","Count :", QLineEdit::Normal,"0", &ok); - - if (ok) - { - STable *pTable = (STable*)AddTable("new"); - pTable->SetHeaderList(&m_vecColumn,E_COLUMN_NAME); - m_ptwData->setCurrentIndex(m_ptwData->count()-1); - pTable->setRowCount(text.toInt()); - } -} - -QGroupBox *SAnaly1::setDataWidgets() -{ - QVBoxLayout *vlayout = new QVBoxLayout; - - QGroupBox *groupBox = new QGroupBox(tr("Data Group")); - m_plwData = new QListWidget; - vlayout->addWidget(m_plwData); - m_plwData->setSelectionMode(QAbstractItemView::SingleSelection); - QPushButton *ppbRefresh = new QPushButton("Refresh"); - vlayout->addWidget(ppbRefresh); - connect(ppbRefresh, SIGNAL(released()),this, SLOT(DataGroupRefresh())); - groupBox->setLayout(vlayout); - connect(m_plwData,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(DataGroupItemChanged(QListWidgetItem*))); - return groupBox; -} - -QGroupBox *SAnaly1::setDateWidgets() -{ - //m_pcbDateCatalog = new QComboBox; - 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()); - - m_pcw = new QCalendarWidget(); - m_pdeStart->setCalendarWidget(m_pcw); - m_pdeStart->setCalendarPopup(true); - - m_pdeEnd->setCalendarWidget(m_pcw); - m_pdeEnd->setCalendarPopup(true); - - QHBoxLayout *hlayout = new QHBoxLayout(); - //hlayout->addWidget(new QLabel("Catalog:")); - //hlayout->addWidget(m_pcbDateCatalog); - hlayout->addWidget(new QLabel("Start:")); - hlayout->addWidget(m_pdeStart); - hlayout->addWidget(new QLabel("End:")); - hlayout->addWidget(m_pdeEnd); - - { - QPushButton *pbInsert = new QPushButton("Insert"); - connect(pbInsert , SIGNAL(released()),this, SLOT(SearchDate())); - hlayout->addWidget(pbInsert); - } - - hlayout->setAlignment(Qt::AlignLeft|Qt::AlignTop); - QGroupBox *groupBox = new QGroupBox(tr("Term")); - groupBox->setAlignment(Qt::AlignLeft|Qt::AlignTop); - groupBox->setLayout(hlayout); - //m_pcbDateCatalog->addItems(QStringList() << "body + reply" << "body" << "reply"); - - return groupBox; -} - -QGroupBox *SAnaly1::setCountWidgets() -{ - QHBoxLayout *hlayout = new QHBoxLayout(); - m_pcbCountCatalog = new QComboBox; - - hlayout->addWidget(m_pcbCountCatalog); - - foreach(QStringList strList,m_vecColumn) - m_pcbCountCatalog->addItem(strList.at(E_COLUMN_NAME)); - - { - QPushButton *pbInsert = new QPushButton("Save"); - connect(pbInsert , SIGNAL(released()),this, SLOT(CountSave())); - hlayout->addWidget(pbInsert); - } - QGroupBox *groupBox = new QGroupBox(tr("Count")); - groupBox->setLayout(hlayout); - return groupBox; -} - -QGroupBox *SAnaly1::setSearchWidgets() -{ - m_pcbCatalog = new QComboBox; - m_pcbKeyword = new QComboBox; - m_pcbMethod = new QComboBox; - m_pleString = new QLineEdit; - - m_pcbKeyword->addItem(QString("Or"));// or - m_pcbKeyword->addItem(QString("And"));// and - m_pcbKeyword->addItem(QString("Cell Delete")); - m_pcbKeyword->addItem(QString("Word Delete")); - - m_pcbMethod->addItem(QString("Sentence")); - m_pcbMethod->addItem(QString("Space")); - - foreach(QStringList strList,m_vecColumn) - m_pcbCatalog->addItem(strList.at(E_COLUMN_NAME)); - - QVBoxLayout *vlayout = new QVBoxLayout(); - { - QHBoxLayout *hlayout = new QHBoxLayout(); - hlayout->addWidget(new QLabel("Item:")); - hlayout->addWidget(m_pcbCatalog); - hlayout->addWidget(new QLabel("Method:")); - hlayout->addWidget(m_pcbMethod); - hlayout->addWidget(new QLabel("keyword:")); - hlayout->addWidget(m_pcbKeyword); - vlayout->addLayout(hlayout); - } - - { - QHBoxLayout *hlayout = new QHBoxLayout(); - hlayout->addWidget(new QLabel("Search:")); - hlayout->addWidget(m_pleString); - vlayout->addLayout(hlayout); - } - - QHBoxLayout *hlayout = new QHBoxLayout(); - hlayout->addLayout(vlayout); - - { - QPushButton *pbInsert = new QPushButton("Insert"); - hlayout->addWidget(pbInsert); - connect(pbInsert, SIGNAL(released()),this, SLOT(SearchKeyword())); - } - - QGroupBox *groupBox = new QGroupBox(tr("Search")); - groupBox->setLayout(hlayout); - return groupBox; -} - -QGroupBox *SAnaly1::setLengthWidgets() -{ - QHBoxLayout *hlayout = new QHBoxLayout(); - m_pcbLengthCatalog = new QComboBox; - m_pcbLengthComp = new QComboBox; - m_pcbLengthInsDel = new QComboBox; - m_pleLength = new QLineEdit; - - foreach(QStringList strList,m_vecColumn) - m_pcbLengthCatalog->addItem(strList.at(E_COLUMN_NAME)); - - m_pcbLengthComp->addItem(">",QVariant(E_LENGTH_COMP_GREATER)); - m_pcbLengthComp->addItem("<",QVariant(E_LENGTH_COMP_LESS)); - m_pcbLengthComp->addItem("=",QVariant(E_LENGTH_COMP_EQUAL)); - - m_pcbLengthInsDel->addItem("Add",QVariant(0)); - m_pcbLengthInsDel->addItem("Del",QVariant(1)); - - hlayout->addWidget(new QLabel("Item:")); - hlayout->addWidget(m_pcbLengthCatalog); - hlayout->addWidget(m_pcbLengthComp); - hlayout->addWidget(new QLabel("Length:")); - hlayout->addWidget(m_pleLength); - hlayout->addWidget(m_pcbLengthInsDel); - { - QPushButton *pbInsert = new QPushButton("Insert"); - connect(pbInsert , SIGNAL(released()),this, SLOT(SearchLengthInsert())); - hlayout->addWidget(pbInsert); - } - QGroupBox *groupBox = new QGroupBox(tr("Length")); - groupBox->setLayout(hlayout); - return groupBox; -} - -QGroupBox *SAnaly1::setReplaceWidgets() -{ - QHBoxLayout *hlayout = new QHBoxLayout(); - m_pcbReplaceCatalog = new QComboBox; - m_pcbReplaceFind = new QComboBox; - m_pleReplaceFind = new QLineEdit; - m_pleReplace = new QLineEdit; - - foreach(QStringList strList,m_vecColumn) - m_pcbReplaceCatalog->addItem(strList.at(E_COLUMN_NAME)); - - m_pcbReplaceFind->addItem("Sentence",QVariant(E_REPLACE_SENTENCE)); - m_pcbReplaceFind->addItem("Space",QVariant(E_REPLACE_SPACE)); - - hlayout->addWidget(m_pcbReplaceCatalog); - hlayout->addWidget(new QLabel("Find:")); - hlayout->addWidget(m_pcbReplaceFind); - hlayout->addWidget(m_pleReplaceFind); - hlayout->addWidget(new QLabel("Replace:")); - hlayout->addWidget(m_pleReplace); - { - QPushButton *pbInsert = new QPushButton("Insert"); - connect(pbInsert , SIGNAL(released()),this, SLOT(SearchReplaceInsert())); - hlayout->addWidget(pbInsert); - } - QGroupBox *groupBox = new QGroupBox(tr("Replace")); - groupBox->setLayout(hlayout); - return groupBox; -} - -QGroupBox *SAnaly1::setFilterWidgets() -{ - QHBoxLayout *hMainlayout = new QHBoxLayout(); - { - QVBoxLayout *vlayout = new QVBoxLayout(); - m_plwFilterGroup = new QListWidget; - m_pleFilterGroup = new QLineEdit; - vlayout->addWidget(m_plwFilterGroup); - vlayout->addWidget(m_pleFilterGroup); - { - QHBoxLayout *hlayout = new QHBoxLayout(); - QPushButton *pbInsert = new QPushButton("Insert"); - connect(pbInsert, SIGNAL(released()),this, SLOT(FilterGroupInsert())); - QPushButton *pbDelete = new QPushButton("Delete"); - connect(pbDelete, SIGNAL(released()),this, SLOT(FilterGroupDelete())); - QPushButton *pbModify = new QPushButton("Modfiy"); - connect(pbModify, SIGNAL(released()),this, SLOT(FilterGroupModify())); - QPushButton *pbRefresh = new QPushButton("Refresh"); - connect(pbRefresh, SIGNAL(released()),this, SLOT(FilterGroupRefresh())); - - hlayout->addWidget(pbInsert); - hlayout->addWidget(pbDelete); - hlayout->addWidget(pbRefresh); - vlayout->addLayout(hlayout); - } - hMainlayout->addLayout(vlayout); - } - { - QVBoxLayout *vlayout = new QVBoxLayout(); - m_plwFilter = new QListWidget; - vlayout->addWidget(m_plwFilter); - connect(m_plwFilter,SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),this,SLOT(currentFilterItemChanged(QListWidgetItem*,QListWidgetItem*))); - QPushButton *pbDelete = new QPushButton("Delete"); - vlayout->addWidget(pbDelete); - connect(pbDelete, SIGNAL(released()),this, SLOT(FilterDelete())); - hMainlayout->addLayout(vlayout); - } - m_pgbFilter = new QGroupBox(tr("Filter")); - m_pgbFilter->setCheckable(true); - m_pgbFilter->setChecked(false); - m_pgbFilter->setLayout(hMainlayout); - - connect(m_plwFilterGroup,SIGNAL(currentItemChanged(QListWidgetItem *,QListWidgetItem *)),this,SLOT(currentGroupItemChanged(QListWidgetItem *, QListWidgetItem *))); - return m_pgbFilter; -} - - -void SAnaly1::DataGroupRefresh() -{ - QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); - db.setHostName("bigbird.iptime.org"); - db.setUserName("admin"); - db.setPassword("admin123"); - db.setDatabaseName("concepters"); - if (db.open() == false) - { - qDebug() << db.lastError().text(); - return; - } - m_plwData->clear(); - QSqlQuery query("select id,name from datagroup"); - while (query.next()) - { - QListWidgetItem *pItem = new QListWidgetItem(query.value(1).toString(),m_plwData); - pItem->setData(Qt::UserRole, QVariant(query.value(0))); - } - db.close(); -} - -void SAnaly1::InsertCopyRow(int _nRow,QTableWidget *_pCurrent,QTableWidget *_pNew) -{ - _pNew->setRowCount(_pNew->rowCount()+1); - for (int nCount = 0;nCount < _pCurrent->columnCount() ;nCount++ ) - { - _pNew->setItem(_pNew->rowCount()-1,nCount,new QTableWidgetItem(*_pCurrent->item(_nRow,nCount))); - } -} - -void SAnaly1::SearchDate() -{ - STable *pNew = new STable; - STable *pCurrent = (STable *)m_ptwData->currentWidget(); - pNew->setArticleSelect(pCurrent->getArticleSelect()); - pNew->SetHeaderList(&m_vecColumn,E_COLUMN_NAME); - m_pProgress->setRange(0,pCurrent->rowCount()-1); - - int nCurrentFilterGroupID = D_NOT_SELECT; - - if (m_pgbFilter->isChecked()) - { - foreach (QListWidgetItem *item,m_plwFilterGroup->selectedItems()) - { - nCurrentFilterGroupID = item->data(Qt::UserRole).toInt(); - InsertTimeFilter(pNew->getArticleSelect(),m_pdeStart->date(),m_pdeEnd->date(),nCurrentFilterGroupID); - } - } - - for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ ) - { - bool bFlag = false; - QString strTime = pCurrent->item(nCount,m_nColumn)->text().trimmed(); - if (strTime.size() >= 10) - { - QChar ch = strTime.at(4); - QString strFormat = QString("yyyy")+ch+QString("MM")+ch+QString("dd"); - QDate date = QDate::fromString(strTime.left(10),strFormat); - if (m_pdeStart->date() <= date && m_pdeEnd->date() >= date) - bFlag = true; - } - if (bFlag) - InsertCopyRow(nCount,pCurrent,pNew); - m_pProgress->setValue(nCount); - m_pProgress->repaint(); - } - //m_ptwData->addTab(pNew,m_ptwData->tabText(m_ptwData->currentIndex())+" d"); - m_ptwData->addTab(pNew,STable::GetArticleType(pCurrent->getArticleSelect())); - m_ptwData->setCurrentIndex(m_ptwData->count()-1); - if (nCurrentFilterGroupID != D_NOT_SELECT) - RefreshFilter(nCurrentFilterGroupID); -} - -void SAnaly1::SearchKeyword() -{ - STable *pNew = new STable; - STable *pCurrent = (STable *)m_ptwData->currentWidget(); - pNew->setArticleSelect(pCurrent->getArticleSelect()); - pNew->SetHeaderList(&m_vecColumn,E_COLUMN_NAME); - int nCurrentFilterGroupID = D_NOT_SELECT; - - QString strKey = m_pleString->text().replace("\r\n"," "); - - strKey = strKey.replace("\n"," "); - strKey = strKey.replace("\t"," "); - - QString strTemp; - foreach(QString str, strKey.split(" ")) - { - if (str.trimmed().isEmpty() == false) - strTemp += str.trimmed() + " "; - } - - strTemp = strTemp.trimmed(); - m_pleString->setText(strTemp); - strKey = strTemp; - - if (m_pgbFilter->isChecked()) - { - foreach (QListWidgetItem *item,m_plwFilterGroup->selectedItems()) - { - nCurrentFilterGroupID = item->data(Qt::UserRole).toInt(); - InsertSearchFilter(pNew->getArticleSelect(),m_pcbCatalog->currentIndex(),m_pcbMethod->currentIndex(),m_pcbKeyword->currentIndex(),strKey,nCurrentFilterGroupID); - } - } - - QStringList strListKeyword = strKey.split(" "); - if (m_pcbMethod->currentIndex() == 1) - { - for (int i = 0 ; i < strListKeyword.size(); i++ ) - { - strListKeyword[i] = " " + strListKeyword[i] + " "; - } - } - m_pProgress->setRange(0,pCurrent->rowCount()-1); - for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ ) - { - bool bFlag = false; - //if (m_pcbCatalog->currentText() == "ALL") - QString strData = pCurrent->item(nCount,m_pcbCatalog->currentIndex())->text(); - switch(m_pcbKeyword->currentIndex()) - { - case 0: - { - foreach(QString strKey , strListKeyword) - if (strData.contains(strKey)){bFlag = true;break;} - break; - } - case 1: - { - int nKeyCount = 0; - foreach(QString strKey , strListKeyword) - if (strData.contains(strKey)) nKeyCount++; - if (nKeyCount == strListKeyword.size()) - bFlag = true; - break; - } - case 2: - { - bFlag = true; - foreach(QString strKey , strListKeyword) - if (strData.contains(strKey)){bFlag = false;break;} - break; - } - case 3: bFlag = true;break; - } - if (bFlag) InsertCopyRow(nCount,pCurrent,pNew); - if (m_pcbKeyword->currentIndex() == 3) - { - foreach(QString strKey , strListKeyword) - { - strData.replace(strKey,""); - } - pNew->item(nCount,m_pcbCatalog->currentIndex())->setText(strData); - } - m_pProgress->setValue(nCount); - m_pProgress->repaint(); - } - //m_ptwData->addTab(pNew,m_ptwData->tabText(m_ptwData->currentIndex())+" k"); - m_ptwData->addTab(pNew,STable::GetArticleType(pCurrent->getArticleSelect())); - m_ptwData->setCurrentIndex(m_ptwData->count()-1); - - if (nCurrentFilterGroupID != D_NOT_SELECT) - RefreshFilter(nCurrentFilterGroupID); -} - -void SAnaly1::SearchLengthInsert() -{ - STable *pNew = new STable; - STable *pCurrent = (STable *)m_ptwData->currentWidget(); - pNew->setArticleSelect(pCurrent->getArticleSelect()); - pNew->SetHeaderList(&m_vecColumn,E_COLUMN_NAME); - m_pProgress->setRange(0,pCurrent->rowCount()-1); - int nCatalog = m_pcbLengthCatalog->currentIndex(); - int nComp = m_pcbLengthComp->currentData().toInt(); - int nFlag = m_pcbLengthInsDel->currentData().toInt(); - int nLength = m_pleLength->text().toInt(); - - int nCurrentFilterGroupID = D_NOT_SELECT; - - if (m_pgbFilter->isChecked()) - { - foreach (QListWidgetItem *item,m_plwFilterGroup->selectedItems()) - { - nCurrentFilterGroupID = item->data(Qt::UserRole).toInt(); - InsertLengthFilter(pCurrent->getArticleSelect(),nCatalog,nComp,nFlag,m_pleLength->text(),nCurrentFilterGroupID); - } - } - - for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ ) - { - bool bFlag = false; - int nCurrentLength = pCurrent->item(nCount,nCatalog)->text().trimmed().length(); - switch(nComp) - { - case E_LENGTH_COMP_GREATER: - if (nCurrentLength > nLength) - bFlag = true; - break; - case E_LENGTH_COMP_LESS: - if (nCurrentLength < nLength) - bFlag = true; - break; - case E_LENGTH_COMP_EQUAL: - if (nLength == nCurrentLength) - bFlag = true; - break; - } - if (nFlag == 1) bFlag = !bFlag; - if (bFlag) InsertCopyRow(nCount,pCurrent,pNew); - m_pProgress->setValue(nCount); - m_pProgress->repaint(); - } - //m_ptwData->addTab(pNew,m_ptwData->tabText(m_ptwData->currentIndex())+" c"); - m_ptwData->addTab(pNew,STable::GetArticleType(pCurrent->getArticleSelect())); - m_ptwData->setCurrentIndex(m_ptwData->count()-1); - if (nCurrentFilterGroupID != D_NOT_SELECT) - RefreshFilter(nCurrentFilterGroupID); -} - -void SAnaly1::SearchReplaceInsert() -{ - STable *pNew = new STable; - STable *pCurrent = (STable *)m_ptwData->currentWidget(); - pNew->setArticleSelect(pCurrent->getArticleSelect()); - pNew->SetHeaderList(&m_vecColumn,E_COLUMN_NAME); - m_pProgress->setRange(0,pCurrent->rowCount()-1); - int nCatalog = m_pcbReplaceCatalog->currentIndex(); - - bool bFlag = false; - QStringList strListKeyword; - if (m_pcbReplaceFind->currentData().toInt() == E_REPLACE_SPACE) - { - bFlag = true; - strListKeyword = m_pleReplaceFind->text().split(" "); - } - int nCurrentFilterGroupID = D_NOT_SELECT; - - if (m_pgbFilter->isChecked()) - { - foreach (QListWidgetItem *item,m_plwFilterGroup->selectedItems()) - { - nCurrentFilterGroupID = item->data(Qt::UserRole).toInt(); - InsertReplaceFilter(pNew->getArticleSelect(),nCatalog, - m_pcbReplaceFind->currentData().toInt(), - m_pleReplaceFind->text(),m_pleReplace->text(), - nCurrentFilterGroupID); - } - } - pNew->setRowCount(pCurrent->rowCount()); - for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ ) - { - for (int nColumnCount = 0;nColumnCount < pCurrent->columnCount() ;nColumnCount++ ) - { - if (nCatalog == nColumnCount) - { - QString strOut = pCurrent->item(nCount,nColumnCount)->text(); - if (bFlag) - { - foreach(QString str,strListKeyword) - strOut = strOut.replace(str,m_pleReplace->text()); - } - else - strOut = strOut.replace(m_pleReplaceFind->text(),m_pleReplace->text()); - - pNew->setItem(nCount,nColumnCount,new QTableWidgetItem(strOut)); - } - else - pNew->setItem(nCount,nColumnCount,new QTableWidgetItem(*pCurrent->item(nCount,nColumnCount))); - } - m_pProgress->setValue(nCount); - m_pProgress->repaint(); - } - //m_ptwData->addTab(pNew,m_ptwData->tabText(m_ptwData->currentIndex())+" r"); - m_ptwData->addTab(pNew,STable::GetArticleType(pCurrent->getArticleSelect())); - m_ptwData->setCurrentIndex(m_ptwData->count()-1); - - if (nCurrentFilterGroupID != D_NOT_SELECT) - RefreshFilter(nCurrentFilterGroupID); -} - -void SAnaly1::DataGroupItemChanged( QListWidgetItem *item) -{ - 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 SAnaly1::DataReload(QString _strTableName,int _nSelect) -{ - QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); - db.setHostName("bigbird.iptime.org"); - db.setUserName("admin"); - db.setPassword("admin123"); - db.setDatabaseName("concepters"); - if (db.open() == false) - { - qDebug() << db.lastError().text(); - return; - } - QString strSelect; - strSelect = "select "; - foreach(QStringList strlist,m_vecColumn) - strSelect += "CONVERT(" + strlist.at(E_COLUMN_DATABASE) + " USING utf8),"; - strSelect = strSelect.left(strSelect.size()-1); - strSelect += " from "; - strSelect += _strTableName; - - if (_nSelect == STable::E_ARTICLE_BODY) - strSelect += " WHERE article_form = 'body'"; - if (_nSelect == STable::E_ARTICLE_REPLY) - strSelect += " WHERE article_form = 'reply'"; - - QSqlQuery query(strSelect); - STable *pTable = (STable *)m_ptwData->currentWidget(); - pTable->setArticleSelect(_nSelect); - pTable->clear(); - pTable->SetHeaderList(&m_vecColumn,E_COLUMN_NAME); - pTable->setRowCount(query.size()); - m_pProgress->setRange(0,query.size()); - int nCount = 0; - while (query.next()) - { - for (int i = 0; i < pTable->columnCount() ; i++) - { - QString str = query.value(i).toString().replace("\n"," "); - pTable->setItem(nCount,i,new QTableWidgetItem(" "+str.replace("\t"," ")+" ")); - } - nCount++; - m_pProgress->setValue(nCount); - m_pProgress->repaint(); - } - db.close(); -} - -void SAnaly1::FilterGroupInsert() -{ - QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); - db.setHostName("bigbird.iptime.org"); - db.setUserName("admin"); - db.setPassword("admin123"); - db.setDatabaseName("concepters"); - if (db.open() == false) - { - qDebug() << db.lastError().text(); - return; - } - - QString strQuery = QString("insert into filtergroup set " - "name = '" + m_pleFilterGroup->text() + "'"); - db.exec(strQuery.toUtf8()); - db.close(); - FilterGroupRefresh(); -} - -void SAnaly1::FilterGroupDelete() -{ - QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); - db.setHostName("bigbird.iptime.org"); - db.setUserName("admin"); - db.setPassword("admin123"); - db.setDatabaseName("concepters"); - if (db.open() == false) - { - qDebug() << db.lastError().text(); - return; - } - foreach (QListWidgetItem *item,m_plwFilterGroup->selectedItems()) - { - QString strQuery = QString("delete from filtergroup where id = " + item->data(Qt::UserRole).toString()); - db.exec(strQuery.toUtf8()); - strQuery = QString("delete from filter where filtergroup_id = " + item->data(Qt::UserRole).toString()); - db.exec(strQuery.toUtf8()); - RefreshFilter(item->data(Qt::UserRole).toInt()); - } - db.close(); - FilterGroupRefresh(); -} - -void SAnaly1::FilterGroupModify() -{ - QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); - db.setHostName("bigbird.iptime.org"); - db.setUserName("admin"); - db.setPassword("admin123"); - db.setDatabaseName("concepters"); - if (db.open() == false) - { - qDebug() << db.lastError().text(); - return; - } - db.close(); -} - -void SAnaly1::FilterGroupRefresh() -{ - QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); - db.setHostName("bigbird.iptime.org"); - db.setUserName("admin"); - db.setPassword("admin123"); - db.setDatabaseName("concepters"); - if (db.open() == false) - { - qDebug() << db.lastError().text(); - return; - } - m_plwFilterGroup->clear(); - QSqlQuery query("select id,name from filtergroup"); - while (query.next()) - { - QListWidgetItem *pItem = new QListWidgetItem(query.value(1).toString(),m_plwFilterGroup); - pItem->setData(Qt::UserRole, QVariant(query.value(0))); - } - db.close(); -} - -void SAnaly1::InsertFilter(int _nType,QString _strJson,int _nGroup) -{ - QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); - db.setHostName("bigbird.iptime.org"); - db.setUserName("admin"); - db.setPassword("admin123"); - db.setDatabaseName("concepters"); - if (db.open() == false) - { - qDebug() << db.lastError().text(); - return; - } - - QString sql = "insert into filter (type,data,filtergroup_id) value ("; - sql += QString::number(_nType); - sql += ",'" + _strJson + "',"; - sql += QString::number(_nGroup) + ")"; - QSqlQuery query; - if (query.exec(sql.toUtf8()) == false) - { - qDebug() << sql; - qDebug() << query.lastError().text(); - } - db.close(); -} - -void SAnaly1::InsertTimeFilter(int _nArticle ,QDate _dateStart ,QDate _dateEnd ,int _nGroup) -{ - QString strJson; - SJson json; - strJson = json.Set(strJson,"Article",QString::number(_nArticle)); - strJson = json.Set(strJson,"Start",_dateStart.toString("yyyy-MM-dd")); - strJson = json.Set(strJson,"End",_dateEnd.toString("yyyy-MM-dd")); - InsertFilter(E_FILTER_TYPE_DATE,json.Sql(strJson),_nGroup); -} - -void SAnaly1::InsertSearchFilter(int _nArticle,int _nCategory,int _nMethod,int _nKeyword, QString _str,int _nGroup) -{ - QString strJson; - SJson json; - strJson = json.Set(strJson,"Article",QString::number(_nArticle)); - strJson = json.Set(strJson,"Category",_nCategory); - strJson = json.Set(strJson,"Method",_nMethod); - strJson = json.Set(strJson,"Keyword",_nKeyword); - strJson = json.Set(strJson,"String",_str); - InsertFilter(E_FILTER_TYPE_SEARCH,json.Sql(strJson),_nGroup); -} - -void SAnaly1::InsertLengthFilter(int _nArticle,int _nCategory,int _nComp,int _nInsDel,QString _str,int _nGroup) -{ - QString strJson; - SJson json; - strJson = json.Set(strJson,"Article",QString::number(_nArticle)); - strJson = json.Set(strJson,"Category",_nCategory); - strJson = json.Set(strJson,"Comp",_nComp); - strJson = json.Set(strJson,"InsDel",_nInsDel); - strJson = json.Set(strJson,"String",_str); - InsertFilter(E_FILTER_TYPE_LENGTH,json.Sql(strJson),_nGroup); -} - -void SAnaly1::InsertReplaceFilter(int _nArticle,int _nCategory,int _nFind,QString _strFind,QString _strReplace,int _nGroup) -{ - QString strJson; - SJson json; - strJson = json.Set(strJson,"Article",QString::number(_nArticle)); - strJson = json.Set(strJson,"Category",_nCategory); - strJson = json.Set(strJson,"Find",_nFind); - strJson = json.Set(strJson,"String_Find",_strFind); - strJson = json.Set(strJson,"String_Replace",_strReplace); - InsertFilter(E_FILTER_TYPE_REPLACE,json.Sql(strJson),_nGroup); -} - -void SAnaly1::RefreshFilter(int _nGroup) -{ - QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); - db.setHostName("bigbird.iptime.org"); - db.setUserName("admin"); - db.setPassword("admin123"); - db.setDatabaseName("concepters"); - if (db.open() == false) - { - qDebug() << db.lastError().text(); - return; - } - QSqlQuery query("select id,type,data from filter where filtergroup_id = " + QString::number(_nGroup)); - - SJson json; - m_plwFilter->clear(); - while (query.next()) - { - QString str; - QString strJson = query.value(2).toString(); - str = STable::GetArticleType(json.Get(strJson,"Article").toInt()); - switch(query.value(1).toInt()) - { - case E_FILTER_TYPE_DATE: - str += " Start : "; - str += json.Get(strJson,"Start"); - str += " End : "; - str += json.Get(strJson,"End"); - break; - case E_FILTER_TYPE_SEARCH: - str += " "; - str += m_pcbCatalog->itemText(json.GetNumber(strJson,"Category")) + " , "; - str += m_pcbMethod->itemText(json.GetNumber(strJson,"Method")) + " , "; - str += m_pcbKeyword->itemText(json.GetNumber(strJson,"Keyword")) + " , "; - str += json.Get(strJson,"String"); - break; - case E_FILTER_TYPE_LENGTH: - str += " "; - str += m_pcbLengthCatalog->itemText(json.GetNumber(strJson,"Category")) + " "; - str += m_pcbLengthComp->itemText(json.GetNumber(strJson,"Comp")) + " "; - str += json.Get(strJson,"String") + " , "; - str += m_pcbLengthInsDel->itemText(json.GetNumber(strJson,"InsDel")); - break; - case E_FILTER_TYPE_REPLACE: - str += " "; - str += m_pcbReplaceCatalog->itemText(json.GetNumber(strJson,"Category")) + " , "; - str += m_pcbReplaceFind->itemText(json.GetNumber(strJson,"Find")) + " "; - str += json.Get(strJson,"String_Find") + " --> "; - str += json.Get(strJson,"String_Replace"); - break; - } - QListWidgetItem *pItem = new QListWidgetItem(str,m_plwFilter); - pItem->setData(Qt::UserRole, QVariant(query.value(0))); - } - db.close(); -} - -void SAnaly1::currentGroupItemChanged(QListWidgetItem *_pCurrent, QListWidgetItem *_pPrev) -{ - Q_UNUSED(_pPrev); - if (_pCurrent == 0) return; - RefreshFilter(_pCurrent->data(Qt::UserRole).toInt()); - m_pleFilterGroup->setText(_pCurrent->text()); - m_pleFilterGroup->repaint(); -} - -void SAnaly1::FilterDelete() -{ - QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); - db.setHostName("bigbird.iptime.org"); - db.setUserName("admin"); - db.setPassword("admin123"); - db.setDatabaseName("concepters"); - if (db.open() == false) - { - qDebug() << db.lastError().text(); - return; - } - foreach (QListWidgetItem *item,m_plwFilter->selectedItems()) - { - QString strQuery = QString("delete from filter where id = '" + item->data(Qt::UserRole).toString() + "'"); - db.exec(strQuery.toUtf8()); - } - db.close(); - foreach (QListWidgetItem *item,m_plwFilterGroup->selectedItems()) - RefreshFilter(item->data(Qt::UserRole).toInt()); -} - -void SAnaly1::currentFilterItemChanged(QListWidgetItem *_pCurrent, QListWidgetItem *_pPrev) -{ - Q_UNUSED(_pPrev); - if (_pCurrent == 0) return; - QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); - db.setHostName("bigbird.iptime.org"); - db.setUserName("admin"); - db.setPassword("admin123"); - db.setDatabaseName("concepters"); - if (db.open() == false) - { - qDebug() << db.lastError().text(); - return; - } - QSqlQuery query("select id,type,data from filter where id = " + _pCurrent->data(Qt::UserRole).toString()); - if (!query.next()) return; - SJson json; - QString strJson = query.value(2).toString(); - switch(query.value(1).toInt()) - { - case E_FILTER_TYPE_DATE: - m_pdeStart->setDate(QDate::fromString(json.Get(strJson,"Start"),"yyyy-MM-dd")); - m_pdeEnd->setDate(QDate::fromString(json.Get(strJson,"End"),"yyyy-MM-dd")); - m_pleString->setText(""); - m_pleLength->setText(""); - m_pleReplaceFind->setText(""); - m_pleReplace->setText(""); - break; - case E_FILTER_TYPE_SEARCH: - m_pcbCatalog->setCurrentIndex(json.GetNumber(strJson,"Category")); - m_pcbMethod->setCurrentIndex(json.GetNumber(strJson,"Method")); - m_pcbKeyword->setCurrentIndex(json.GetNumber(strJson,"Keyword")); - m_pleString->setText(json.Get(strJson,"String")); - m_pleLength->setText(""); - m_pleReplaceFind->setText(""); - m_pleReplace->setText(""); - - break; - case E_FILTER_TYPE_LENGTH: - m_pcbLengthCatalog->setCurrentIndex(json.GetNumber(strJson,"Category")); - m_pcbLengthComp->setCurrentIndex(json.GetNumber(strJson,"Comp")); - m_pcbLengthInsDel->setCurrentIndex(json.GetNumber(strJson,"InsDel")); - m_pleLength->setText(json.Get(strJson,"String")); - m_pleReplaceFind->setText(""); - m_pleReplace->setText(""); - m_pleString->setText(""); - break; - case E_FILTER_TYPE_REPLACE: - m_pcbReplaceCatalog->setCurrentIndex(json.GetNumber(strJson,"Category")); - m_pcbReplaceFind->setCurrentIndex(json.GetNumber(strJson,"Find")); - m_pleReplaceFind->setText(json.Get(strJson,"String_Find")); - m_pleReplace->setText(json.Get(strJson,"String_Replace")); - m_pleString->setText(""); - m_pleLength->setText(""); - break; - } -} - -bool SAnaly1::ReloadColumn() -{ - m_vecColumn.clear(); - QFile file("column.txt"); - if (file.open(QIODevice::ReadOnly | QIODevice::Text) == false) return false; - { - while (!file.atEnd()) - { - QString str = QString(file.readLine()); - if (str.at(0) == QChar('#')) continue; - if (str.trimmed().isEmpty()) continue; - m_vecColumn.push_back(str.split(",")); - } - } - if (m_vecColumn.size() <= 0) return false; - - m_nColumn = -1; - foreach(QStringList strList,m_vecColumn) - { - if (strList.at(E_COLUMN_DATE).trimmed() == QString("o") ) - break; - else - m_nColumn++; - } - m_nColumn++; - return true; -} - void SAnaly1::FileImport() { QString strFilename = QFileDialog::getOpenFileName(0,"Import file",QDir::currentPath(), @@ -1371,7 +436,7 @@ void SAnaly1::FileImport() m_mapViewResult.insert(strDate, qMedium); } } - + ViewResult(); } void SAnaly1::FileExport() @@ -1407,12 +472,7 @@ void SAnaly1::FileExport() file.close(); } - -void SAnaly1::FileExit() -{ - exit(1); -} - +/* struct SCount { SCount() @@ -1429,56 +489,7 @@ struct SCount QString m_str; int m_nCount; }; - -void SAnaly1::CountSave() -{ - QTableWidget *pCurrent = (QTableWidget *)m_ptwData->currentWidget(); - int nCatalog = m_pcbCountCatalog->currentIndex(); - QString strFilename = QFileDialog::getSaveFileName(0,"Count file",QDir::currentPath(), - "csv files (*.csv);;All files (*.*)",new QString("csv files (*.csv)")); - if (strFilename.toLower().right(4) != QString(".csv")) - strFilename += ".csv"; - m_pProgress->setRange(0,pCurrent->rowCount()-1); - - QVector vecData; - for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ ) - { - QString str; - if (nCatalog == m_nColumn) - { - QDateTime date; - str = date.fromString(pCurrent->item(nCount,nCatalog)->text().trimmed(),"yyyy-MM-dd hh:mm:ss").date().toString("yyyy-MM-dd"); - } - else - str = pCurrent->item(nCount,nCatalog)->text().trimmed(); - bool bInsert = true; - for (int i = 0; i < vecData.size(); i++) - { - if(vecData[i].m_str.compare(str) == 0) - { - vecData[i].m_nCount++; - bInsert = false; - break; - } - } - if (bInsert) - vecData.push_back(SCount(str)); - m_pProgress->setValue(nCount); - m_pProgress->repaint(); - } - QFile file(strFilename); - if(!file.open(QFile::WriteOnly | QFile::Text)) return; - QTextStream out(&file); - out << pCurrent->horizontalHeaderItem(nCatalog)->text() << "," << vecData.size() << endl << endl; - foreach(SCount stCount,vecData) - { - QString str = stCount.m_str.replace(",","."); - str = str.replace("\n",""); - out << "\"" << str << "\"" << "," << stCount.m_nCount << endl; - } - file.close(); -} - +*/ int SAnaly1::getThread() { @@ -1572,3 +583,234 @@ bool SAnaly1::setListMorphere(QStringList& MorphereEN, QStringList& MorphereKO) return true; } + + +void SAnaly1::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 > >::iterator iterPos = m_mapViewResult.begin(); iterPos != m_mapViewResult.end(); iterPos++) + { + for(QMap >::iterator iterPos2 = iterPos.value().begin(); iterPos2 != iterPos.value().end(); iterPos2++) + { + QMapIterator 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(); +} + + +void SAnaly1::setWidget(Widget *widget) +{ + m_pwidget = widget; +} + +void SAnaly1::ExecThread(int _setBodyTitle) +{ + int nCount = 0; + m_pThread = new AnalyzerThread*[getThread()]; + + for(int i=0;isetParametersfromWidget(this,0); + m_pThread[i]->setWidget(m_pwidget); + m_pThread[i]->setPosBody(m_pwidget->getBodyPosition()); + m_pThread[i]->setPosDate(m_pwidget->getDatePosition()); + m_pThread[i]->setPosTitle(m_pwidget->getTitlePosition()); + m_pThread[i]->setPosPlatformTitle(m_pwidget->getPlatformTitlePosition()); + m_pThread[i]->setTitleBody(_setBodyTitle); + } + for(int i=0;istart(); + } + for(int i=0;iwait(); + } + + for(int i=0;i::iterator iterPos = m_HashResult[i].begin(); iterPos != m_HashResult[i].end();iterPos++) + { + if(m_TotalResult.contains(iterPos.key())) + { + m_TotalResult[iterPos.key()] += iterPos.value(); + } + else + { + m_TotalResult.insert(iterPos.key(), iterPos.value()); + } + } + m_HashResult[i].clear(); + } +} + +void SAnaly1::SortViewResult() +{ + + if(isSortDateMorphereChecked()) + { + for(QMap::iterator iterPos = m_TotalResult.begin(); iterPos != m_TotalResult.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 qLast; + qLast.insert(count, strKeyword); + m_mapViewResult[(strDate)].insert(strMorphere, qLast); + } + } + else + { + QMap qLast; + qLast.insert(count , strKeyword); + QMap > qMedium; + qMedium.insert(strMorphere, qLast); + m_mapViewResult.insert(strDate, qMedium); + } + } + } + else + { + for(QMap::iterator iterPos = m_TotalResult.begin(); iterPos != m_TotalResult.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(strMorphere)) + { + if(m_mapViewResult.value(strMorphere).contains(strDate)) + { + m_mapViewResult[(strMorphere)][(strDate)].insertMulti(count, strKeyword); + } + else + { + QMap qLast; + qLast.insert(count, strKeyword); + m_mapViewResult[(strMorphere)].insert(strDate, qLast); + } + } + else + { + QMap qLast; + qLast.insert(count , strKeyword); + QMap > qMedium; + qMedium.insert(strDate, qLast); + m_mapViewResult.insert(strMorphere, qMedium); + } + } + } +} + + +void SAnaly1::ViewResult() +{ + + 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 > >::iterator iterPos = m_mapViewResult.begin(); iterPos != m_mapViewResult.end(); iterPos++) + { + QTabWidget* temp = new QTabWidget; + for(QMap >::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 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; + } + m_ptwTable->addTab(temp, iterPos.key()); + m_lTabWidget << temp; + } +} + +void SAnaly1::Exec(int setBodyTitle) +{ + MemClear(); + ExecThread(setBodyTitle); + EmergeThreadResult(); + SortViewResult(); + ViewResult(); +} diff --git a/MorphereAnalyzer/sanaly1.h b/MorphereAnalyzer/sanaly1.h index 484d682..3098966 100644 --- a/MorphereAnalyzer/sanaly1.h +++ b/MorphereAnalyzer/sanaly1.h @@ -1,8 +1,5 @@ #ifndef SANALY1 #define SANALY1 - - - #include #include #include @@ -21,7 +18,9 @@ #include #include #include "stable.h" - +#include "widget.h" +#include "sanalyzer.h" +#include class SAnaly1 : public QWidget { enum E_COLUMN @@ -49,7 +48,7 @@ public: QStringList getMorphereList(); bool getDateAll(); QString getUserDictList(); - + void Exec(int setBodyTitle); private: // Data @@ -60,40 +59,13 @@ private: QDateEdit *m_pdeEnd; //QPushButton *m_ppbInsertCalc; //QComboBox *m_pcbDateCatalog; - int m_nColumn; - // Keyword - QComboBox *m_pcbCatalog; - QComboBox *m_pcbKeyword; - QComboBox *m_pcbMethod; - QLineEdit *m_pleString; - //QPushButton *m_ppbInsertSearch; - // Length - QComboBox *m_pcbLengthCatalog; - QComboBox *m_pcbLengthComp; - QComboBox *m_pcbLengthInsDel; - QLineEdit *m_pleLength; - // Filter - QListWidget *m_plwFilterGroup; - - QListWidget *m_plwFilter; - QLineEdit *m_pleFilterGroup; - QGroupBox *m_pgbFilter; - // Replace - QComboBox *m_pcbReplaceCatalog; - QComboBox *m_pcbReplaceFind; - QLineEdit *m_pleReplaceFind; - QLineEdit *m_pleReplace; - - // Count - QComboBox *m_pcbCountCatalog; - // QTabWidget *m_ptwData; // QProgressBar *m_pProgress; // Column QVector m_vecColumn; - + AnalyzerThread **m_pThread; // MorphereList QListWidget *m_plwMorphereList; QListWidget *m_plwMorphereAdd; @@ -110,12 +82,16 @@ private: QListWidgetItem **m_plwiMorphere; QStringList m_strlistMorphere; QStringList m_strlistMorphereko; - + Widget *m_pwidget; QRadioButton *m_rbDateMorphere; QRadioButton *m_rbMorphereDate; QButtonGroup *m_bgRadioGroup; QComboBox *m_pcbDictionary; + QList m_lTable; + QList m_lTabWidget; + QTabWidget* m_ptwTable; + QMutex mutex; public: struct m_mapKey { @@ -130,15 +106,6 @@ public: QMap > > m_mapViewResult; private: - QMenuBar *setMenuWidget(); - QGroupBox *setDataWidgets(); - QGroupBox *setDateWidgets(); - QGroupBox *setCountWidgets(); - QGroupBox *setSearchWidgets(); - QGroupBox *setLengthWidgets(); - QGroupBox *setFilterWidgets(); - QGroupBox *setReplaceWidgets(); - QGroupBox *setMorphereList(); QGroupBox *setDate(); QGroupBox *setFilter(); @@ -146,41 +113,18 @@ private: QGroupBox *setSort(); QGroupBox *setDictionary(); + void ExecThread(int _setBodyTitle); + void EmergeThreadResult(); + void SortViewResult(); + void ViewResult(); QTableWidget *AddTable(QString _str); - void SetTableHead(); - void InsertCopyRow(int _nRow,QTableWidget *_pCurrent,QTableWidget *_pNew); - void DataReload(QString _strTableName,int _nSelect); - void InsertFilter(int _nType,QString _strJson,int _nGroup); - void InsertTimeFilter(int _nTimeCategory ,QDate _dateStart ,QDate _dateEnd ,int _nGroup); - void InsertSearchFilter(int _nArticle,int _nCategory,int _nMethod,int _nKeyword, QString _str,int _nGroup); - void InsertLengthFilter(int _nArticle,int _nCategory,int _nComp,int _nInsDel,QString _str,int _nGroup); - void InsertReplaceFilter(int _nArticle,int _nCategory,int _nFind,QString _strFind,QString _strReplace,int _nGroup); - void RefreshFilter(int _nGroup); - - bool ReloadColumn(); - QString GetArticleType(int _nSelect); public slots: void CloseTab(int index); void DoubleClickTab(int index); - void SearchDate(); - void CountSave(); - void SearchKeyword(); - void DataGroupRefresh(); - void DataGroupItemChanged ( QListWidgetItem * item ); - void FilterGroupInsert(); - void FilterGroupDelete(); - void FilterGroupModify(); - void FilterGroupRefresh(); - void currentGroupItemChanged(QListWidgetItem *_pCurrent, QListWidgetItem *_pPrev=0); - void FilterDelete(); - void currentFilterItemChanged(QListWidgetItem *_pCurrent, QListWidgetItem *_pPrev=0); - void SearchLengthInsert(); - void SearchReplaceInsert(); - void FileNew(); void FileImport(); void FileExport(); - void FileExit(); + void RawFileExport(); void MemClear(); void MorphereListAdd(); void MorphereListDel(); @@ -188,12 +132,9 @@ public slots: void DelDictionary(); bool setListMorphere(QStringList& MorphereEN, QStringList& MorphereKO); QTabWidget* getQTabWidget(); - - + void setWidget(Widget *widget); bool isSortMorphereDateChecked(); - bool isSortDateMorphereChecked(); - }; #endif // SANALY1 diff --git a/MorphereAnalyzer/sanalyzer.cpp b/MorphereAnalyzer/sanalyzer.cpp index 78af813..74b9824 100644 --- a/MorphereAnalyzer/sanalyzer.cpp +++ b/MorphereAnalyzer/sanalyzer.cpp @@ -1,5 +1,6 @@ #include "sanalyzer.h" +#include "sanaly1.h" #include AnalyzerThread::AnalyzerThread(QObject *parent) : QThread(parent), m_nThread(1), m_pWidget(NULL), m_nSource(0), m_bPeriod(false), m_nPeriod(0) { @@ -16,7 +17,6 @@ AnalyzerThread::AnalyzerThread(QMutex &_mutex, int _number, int &_nCount) nCount = &_nCount; } - void AnalyzerThread::setThreadNumber(int _nThread) { m_nThread = _nThread; @@ -68,6 +68,7 @@ void AnalyzerThread::setParametersfromWidget(QWidget *_pWidget, int _nSource) setMorphereList(pWidget->getMorphereList()); } } + QStringList AnalyzerThread::getMorphereList() { return m_slMorphereList; diff --git a/MorphereAnalyzer/sanalyzer.h b/MorphereAnalyzer/sanalyzer.h index aa063af..abc083f 100644 --- a/MorphereAnalyzer/sanalyzer.h +++ b/MorphereAnalyzer/sanalyzer.h @@ -1,19 +1,17 @@ #ifndef SANALYZER #define SANALYZER -#endif // SANALYZER #include #include #include "widget.h" #include #include -#include "sanaly1.h" #include "mecab.h" #include - +class SAnaly1; class AnalyzerThread : public QThread { @@ -93,3 +91,4 @@ public: QString getWeeksInMonth(unsigned int _nDate); void setAnalyzerThread(QMutex &_mutex, int number, int &_nCount); }; +#endif // SANALYZER