From 06353fef5a63cede334f0e1e6223b6a6fb7ac16f Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Feb 2015 05:10:12 +0000 Subject: [PATCH] git-svn-id: svn://192.168.0.12/source@22 8346c931-da38-4b9b-9d4c-e48b93cbd075 --- DataAnalyzer/DataAnalyzer.pro | 6 +- DataAnalyzer/stable.cpp | 1 + DataAnalyzer/stable.h | 13 +++- DataAnalyzer/widget.cpp | 132 +++++++++++++++++++++++++++++----- DataAnalyzer/widget.h | 13 ++-- 5 files changed, 137 insertions(+), 28 deletions(-) diff --git a/DataAnalyzer/DataAnalyzer.pro b/DataAnalyzer/DataAnalyzer.pro index d117bcc..57e2b55 100644 --- a/DataAnalyzer/DataAnalyzer.pro +++ b/DataAnalyzer/DataAnalyzer.pro @@ -13,7 +13,9 @@ TEMPLATE = app SOURCES += main.cpp\ widget.cpp \ - stable.cpp + stable.cpp \ + ../Json/sjson.cpp HEADERS += widget.h \ - stable.h + stable.h \ + ../Json/sjson.h diff --git a/DataAnalyzer/stable.cpp b/DataAnalyzer/stable.cpp index d9ff66f..3e5fb40 100644 --- a/DataAnalyzer/stable.cpp +++ b/DataAnalyzer/stable.cpp @@ -14,6 +14,7 @@ STable::STable(QWidget *parent): connect(verticalHeader(),SIGNAL(customContextMenuRequested(QPoint)),SLOT(HeaderContextMenuShow(QPoint))); connect(this,SIGNAL(cellClicked(int,int)),SLOT(CellClick(int,int))); setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); + m_nArticle = E_ARTICLE_NONE; } void STable::SetHeaderList(QVector * _pvecHead,int _nColumn) diff --git a/DataAnalyzer/stable.h b/DataAnalyzer/stable.h index adcf186..968ae9d 100644 --- a/DataAnalyzer/stable.h +++ b/DataAnalyzer/stable.h @@ -6,11 +6,22 @@ class STable : public QTableWidget { - Q_OBJECT + Q_OBJECT public: + enum E_ARTICLE + { + E_ARTICLE_NONE = -1, + E_ARTICLE_ALL = 0, + E_ARTICLE_BODY = 1, + E_ARTICLE_REPLY = 2, + }; explicit STable(QWidget *parent = 0); void keyPressEvent(QKeyEvent* event); void SetHeaderList(QVector *_vecColumn,int _nColumn); + void setArticleSelect(int _nArticle){m_nArticle = _nArticle;} + int getArticleSelect(){return m_nArticle;} +private: + int m_nArticle; public: QStringList m_strListHeader; signals: diff --git a/DataAnalyzer/widget.cpp b/DataAnalyzer/widget.cpp index 303299e..53f7a77 100644 --- a/DataAnalyzer/widget.cpp +++ b/DataAnalyzer/widget.cpp @@ -10,6 +10,7 @@ #include #include #include +#include /* QSqlDatabase dbWeb = QSqlDatabase::addDatabase("QMYSQL"); @@ -62,7 +63,7 @@ Widget::Widget(QWidget *parent) vMainLayout->addWidget(m_ptwData,8); m_ptwData->setTabsClosable(true); connect(m_ptwData,SIGNAL(tabCloseRequested(int)),this,SLOT(CloseTab(int))); - + connect(m_ptwData,SIGNAL(tabBarDoubleClicked(int)),this,SLOT(DoubleClickTab(int))); m_pProgress = new QProgressBar; vMainLayout->addWidget(m_pProgress,1); } @@ -88,11 +89,23 @@ void Widget::CloseTab(int index) m_ptwData->removeTab(index); } +void Widget::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); + } +} + QMenuBar *Widget::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(); @@ -101,6 +114,20 @@ QMenuBar *Widget::setMenuWidget() return pMenuBar; } +void Widget::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 *Widget::setDataWidgets() { QVBoxLayout *vlayout = new QVBoxLayout; @@ -163,7 +190,7 @@ QGroupBox *Widget::setCountWidgets() { QPushButton *pbInsert = new QPushButton("Save"); - //connect(pbInsert , SIGNAL(released()),this, SLOT(SearchLengthInsert())); + connect(pbInsert , SIGNAL(released()),this, SLOT(CountSave())); hlayout->addWidget(pbInsert); } QGroupBox *groupBox = new QGroupBox(tr("Count")); @@ -458,6 +485,7 @@ void Widget::SearchKeyword() } m_ptwData->addTab(pNew,m_ptwData->tabText(m_ptwData->currentIndex())+" k"); m_ptwData->setCurrentIndex(m_ptwData->count()-1); + if (nCurrentFilterGroupID != D_NOT_SELECT) RefreshFilter(nCurrentFilterGroupID); } @@ -472,19 +500,19 @@ void Widget::SearchLengthInsert() int nComp = m_pcbLengthComp->currentData().toInt(); int nFlag = m_pcbLengthInsDel->currentData().toInt(); int nLength = m_pleLength->text().toInt(); - /* + int nCurrentFilterGroupID = D_NOT_SELECT; foreach (QListWidgetItem *item,m_plwFilterGroup->selectedItems()) { nCurrentFilterGroupID = item->data(Qt::UserRole).toInt(); - InsertTimeFilter(m_nColumn,m_pdeStart->date(),m_pdeEnd->date(),nCurrentFilterGroupID); + //InsertTimeFilter(m_nColumn,m_pdeStart->date(),m_pdeEnd->date(),nCurrentFilterGroupID); } - */ + for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ ) { bool bFlag = false; - int nCurrentLength = pCurrent->item(nCount,nCatalog)->text().trimmed().length(); + int nCurrentLength = pCurrent->item(nCount,nCatalog)->text().trimmed().length(); switch(nComp) { case E_LENGTH_COMP_GREATER: @@ -507,8 +535,8 @@ void Widget::SearchLengthInsert() } m_ptwData->addTab(pNew,m_ptwData->tabText(m_ptwData->currentIndex())+" c"); m_ptwData->setCurrentIndex(m_ptwData->count()-1); - //if (nCurrentFilterGroupID != D_NOT_SELECT) - // RefreshFilter(nCurrentFilterGroupID); + if (nCurrentFilterGroupID != D_NOT_SELECT) + RefreshFilter(nCurrentFilterGroupID); } void Widget::SearchReplaceInsert() @@ -527,6 +555,12 @@ void Widget::SearchReplaceInsert() strListKeyword = m_pleReplaceFind->text().split(" "); } + foreach (QListWidgetItem *item,m_plwFilterGroup->selectedItems()) + { + nCurrentFilterGroupID = item->data(Qt::UserRole).toInt(); + InsertFilter(m_nColumn,nCurrentFilterGroupID); + } + pNew->setRowCount(pCurrent->rowCount()); for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ ) { @@ -553,10 +587,9 @@ void Widget::SearchReplaceInsert() } m_ptwData->addTab(pNew,m_ptwData->tabText(m_ptwData->currentIndex())+" r"); m_ptwData->setCurrentIndex(m_ptwData->count()-1); - /* + if (nCurrentFilterGroupID != D_NOT_SELECT) - RefreshFilter(nCurrentFilterGroupID); - */ + RefreshFilter(nCurrentFilterGroupID); } void Widget::DataGroupItemChanged( QListWidgetItem *item) @@ -568,9 +601,9 @@ void Widget::DataGroupItemChanged( QListWidgetItem *item) 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(),E_ARTICLE_ALL); - else if (msg.clickedButton() == pbBody) DataReload("data_" + item->data(Qt::UserRole).toString(),E_ARTICLE_BODY); - else if (msg.clickedButton() == pbReply) DataReload("data_" + item->data(Qt::UserRole).toString(),E_ARTICLE_REPLY); + 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 Widget::DataReload(QString _strTableName,int _nSelect) @@ -593,13 +626,14 @@ void Widget::DataReload(QString _strTableName,int _nSelect) strSelect += " from "; strSelect += _strTableName; - if (_nSelect == E_ARTICLE_BODY) + if (_nSelect == STable::E_ARTICLE_BODY) strSelect += " WHERE article_form = 'body'"; - if (_nSelect == E_ARTICLE_REPLY) + 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()); @@ -983,3 +1017,69 @@ void Widget::FileExit() { exit(1); } + +struct SCount +{ + SCount() + { + m_str.clear(); + m_nCount = 0; + } + + SCount(QString _str) + { + m_str = _str; + m_nCount = 1; + } + QString m_str; + int m_nCount; +}; + +void Widget::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(); +} diff --git a/DataAnalyzer/widget.h b/DataAnalyzer/widget.h index 731025f..f481448 100644 --- a/DataAnalyzer/widget.h +++ b/DataAnalyzer/widget.h @@ -29,14 +29,6 @@ class Widget : public QWidget E_COLUMN_COUNT, }; - enum E_ARTICLE - { - E_ARTICLE_NONE = -1, - E_ARTICLE_ALL = 0, - E_ARTICLE_BODY = 1, - E_ARTICLE_REPLY = 2, - }; - enum E_LENGTH_COMP { E_LENGTH_COMP_GREATER = 0, @@ -113,8 +105,10 @@ private: bool ReloadColumn(); public slots: - void SearchDate(); void CloseTab(int index); + void DoubleClickTab(int index); + void SearchDate(); + void CountSave(); void SearchKeyword(); void DataGroupRefresh(); void DataGroupItemChanged ( QListWidgetItem * item ); @@ -127,6 +121,7 @@ public slots: void currentFilterItemChanged(QListWidgetItem *_pCurrent, QListWidgetItem *_pPrev=0); void SearchLengthInsert(); void SearchReplaceInsert(); + void FileNew(); void FileImport(); void FileExport(); void FileExit();