Files
clients/DataAnalyzer/widget.cpp
admin c6db89c4e4 count 통한 분석 추가
csv import export
replace 기능 추가

git-svn-id: svn://192.168.0.12/source@20 8346c931-da38-4b9b-9d4c-e48b93cbd075
2015-02-11 02:02:48 +00:00

986 lines
34 KiB
C++

#include "widget.h"
#include <QGroupBox>
#include <QButtonGroup>
#include <QLabel>
#include <QSqlQuery>
#include <QDebug>
#include <QFile>
#include <QFileDialog>
#include <QTextCodec>
#include <QMessageBox>
#include <QSqlError>
#include <QMenuBar>
/*
QSqlDatabase dbWeb = QSqlDatabase::addDatabase("QMYSQL");
dbWeb.setHostName("db.big-bird.co.kr");
dbWeb.setUserName("concepters");
dbWeb.setPassword("con97996655");
dbWeb.setDatabaseName("dbconcepters");
*/
#define D_NOT_SELECT -1
#define SAFE_DELETE(x) if(x != NULL) { delete x; x = NULL; }
#define SAFE_DELETEARRAY(x) if(x != NULL) { delete [] x; x = NULL; }
#define SAFE_RELEASE(x) if(x != NULL) { x->Release(); x = NULL; }
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
if (ReloadColumn() == false)
return;
QVBoxLayout *vMainLayout = new QVBoxLayout;
vMainLayout->setAlignment(Qt::AlignVCenter);
vMainLayout->addWidget(setMenuWidget());
{
QVBoxLayout *vlayout = new QVBoxLayout;
{
QHBoxLayout *hlayout = new QHBoxLayout;
if (m_nColumn != -1)
hlayout->addWidget(setDateWidgets());
hlayout->addWidget(setCountWidgets());
vlayout->addLayout(hlayout);
}
vlayout->addWidget(setSearchWidgets());
vlayout->addWidget(setLengthWidgets());
vlayout->addWidget(setReplaceWidgets());
vlayout->setAlignment(Qt::AlignTop);
{
QHBoxLayout *hlayout = new QHBoxLayout;
hlayout->addWidget(setDataWidgets());
hlayout->addLayout(vlayout);
hlayout->addWidget(setFilterWidgets());
vMainLayout->addLayout(hlayout,1);
}
m_ptwData = new QTabWidget;
vMainLayout->addWidget(m_ptwData,8);
m_ptwData->setTabsClosable(true);
connect(m_ptwData,SIGNAL(tabCloseRequested(int)),this,SLOT(CloseTab(int)));
m_pProgress = new QProgressBar;
vMainLayout->addWidget(m_pProgress,1);
}
setLayout(vMainLayout);
DataGroupRefresh();
FilterGroupRefresh();
AddTable("1");
}
Widget::~Widget()
{
}
QTableWidget *Widget::AddTable(QString _str)
{
STable *pTable = new STable;
m_ptwData->addTab(pTable,_str);
return (QTableWidget *)pTable;
}
void Widget::CloseTab(int index)
{
m_ptwData->removeTab(index);
}
QMenuBar *Widget::setMenuWidget()
{
QMenuBar *pMenuBar = new QMenuBar();
{
QMenu *pFile = pMenuBar->addMenu("File");
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;
}
QGroupBox *Widget::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 *Widget::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);
m_ppbInsertCalc = new QPushButton("Insert");
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);
hlayout->addWidget(m_ppbInsertCalc);
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");
connect(m_ppbInsertCalc, SIGNAL(released()),this, SLOT(SearchDate()));
return groupBox;
}
QGroupBox *Widget::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(SearchLengthInsert()));
hlayout->addWidget(pbInsert);
}
QGroupBox *groupBox = new QGroupBox(tr("Count"));
groupBox->setLayout(hlayout);
return groupBox;
}
QGroupBox *Widget::setSearchWidgets()
{
m_pcbCatalog = new QComboBox;
m_pcbKeyword = new QComboBox;
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 = new QComboBox;
m_pcbMethod->addItem(QString("Sentence"));
m_pcbMethod->addItem(QString("Space"));
m_pleString = new QLineEdit;
m_ppbInsertSearch = new QPushButton("Insert");
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);
hlayout->addWidget(m_ppbInsertSearch);
QGroupBox *groupBox = new QGroupBox(tr("Search"));
groupBox->setLayout(hlayout);
connect(m_ppbInsertSearch, SIGNAL(released()),this, SLOT(SearchKeyword()));
return groupBox;
}
QGroupBox *Widget::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);
}
QGroupBox *groupBox = new QGroupBox(tr("Filter"));
groupBox->setLayout(hMainlayout);
connect(m_plwFilterGroup,SIGNAL(currentItemChanged(QListWidgetItem *,QListWidgetItem *)),this,SLOT(currentGroupItemChanged(QListWidgetItem *, QListWidgetItem *)));
return groupBox;
}
QGroupBox *Widget::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 *Widget::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;
}
void Widget::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 Widget::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 Widget::SearchDate()
{
STable *pNew = new STable;
QTableWidget *pCurrent = (QTableWidget *)m_ptwData->currentWidget();
pNew->SetHeaderList(&m_vecColumn,E_COLUMN_NAME);
m_pProgress->setRange(0,pCurrent->rowCount()-1);
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);
}
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->setCurrentIndex(m_ptwData->count()-1);
if (nCurrentFilterGroupID != D_NOT_SELECT)
RefreshFilter(nCurrentFilterGroupID);
}
void Widget::SearchKeyword()
{
STable *pNew = new STable;
QTableWidget *pCurrent = (QTableWidget *)m_ptwData->currentWidget();
pNew->SetHeaderList(&m_vecColumn,E_COLUMN_NAME);
int nCurrentFilterGroupID = D_NOT_SELECT;
foreach (QListWidgetItem *item,m_plwFilterGroup->selectedItems())
{
nCurrentFilterGroupID = item->data(Qt::UserRole).toInt();
InsertSearchFilter(m_pcbCatalog->currentIndex(),m_pcbMethod->currentIndex(),m_pcbKeyword->currentIndex(),m_pleString->text(),nCurrentFilterGroupID);
}
QStringList strListKeyword = m_pleString->text().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->setCurrentIndex(m_ptwData->count()-1);
if (nCurrentFilterGroupID != D_NOT_SELECT)
RefreshFilter(nCurrentFilterGroupID);
}
void Widget::SearchLengthInsert()
{
STable *pNew = new STable;
QTableWidget *pCurrent = (QTableWidget *)m_ptwData->currentWidget();
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;
foreach (QListWidgetItem *item,m_plwFilterGroup->selectedItems())
{
nCurrentFilterGroupID = item->data(Qt::UserRole).toInt();
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();
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->setCurrentIndex(m_ptwData->count()-1);
//if (nCurrentFilterGroupID != D_NOT_SELECT)
// RefreshFilter(nCurrentFilterGroupID);
}
void Widget::SearchReplaceInsert()
{
STable *pNew = new STable;
QTableWidget *pCurrent = (QTableWidget *)m_ptwData->currentWidget();
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(" ");
}
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->setCurrentIndex(m_ptwData->count()-1);
/*
if (nCurrentFilterGroupID != D_NOT_SELECT)
RefreshFilter(nCurrentFilterGroupID);
*/
}
void Widget::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(),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);
}
void Widget::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 == E_ARTICLE_BODY)
strSelect += " WHERE article_form = 'body'";
if (_nSelect == E_ARTICLE_REPLY)
strSelect += " WHERE article_form = 'reply'";
QSqlQuery query(strSelect);
STable *pTable = (STable *)m_ptwData->currentWidget();
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++)
pTable->setItem(nCount,i,new QTableWidgetItem(" "+query.value(i).toString()+" "));
nCount++;
m_pProgress->setValue(nCount);
m_pProgress->repaint();
}
db.close();
}
void Widget::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 Widget::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 Widget::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 Widget::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 Widget::InsertTimeFilter(int _nCategory ,QDate _dateStart ,QDate _dateEnd ,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,timecategory,timestart,timeend,filtergroup_id) value (";
sql += "0,";
sql += QString::number(_nCategory) + ",'";
sql += _dateStart.toString("yyyy-MM-dd") + "','";
sql += _dateEnd.toString("yyyy-MM-dd") + "',";
sql += QString::number(_nGroup) + ")";
QSqlQuery query;
if (query.exec(sql.toUtf8()) == false)
{
qDebug() << sql;
qDebug() << query.lastError().text();
}
db.close();
}
void Widget::InsertSearchFilter(int _nCategory,int _nMethod,int _nKeyword, QString str,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,searchescategory,searchesmethod,searcheskeyword,searchesstring,filtergroup_id) value (";
sql += "1,";
sql += QString::number(_nCategory) + ",";
sql += QString::number(_nMethod) + ",";
sql += QString::number(_nKeyword) + ",";
sql += "'" + str + "',";
sql += QString::number(_nGroup) + ")";
QSqlQuery query;
if (query.exec(sql.toUtf8()) == false)
{
qDebug() << query.lastError().text();
}
db.close();
}
void Widget::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,timecategory,timestart,timeend,searchescategory,searchesmethod,searcheskeyword,searchesstring from filter where filtergroup_id = " + QString::number(_nGroup));
m_plwFilter->clear();
while (query.next())
{
QString str;
switch(query.value(1).toInt())
{
case 0:
str = "Type : Date ";
str += ", Start : ";
str += query.value(3).toString();
str += ", End : ";
str += query.value(4).toString();
break;
case 1:
str = "Type : Seracher ";
str += ", Catalog : ";
str += m_pcbCatalog->itemText(query.value(5).toInt());
str += ", Method : ";
str += m_pcbMethod->itemText(query.value(6).toInt());
str += ", Keyword : ";
str += m_pcbKeyword->itemText(query.value(7).toInt());
str += ", Search : ";
str += query.value(8).toString();
break;
}
QListWidgetItem *pItem = new QListWidgetItem(str,m_plwFilter);
pItem->setData(Qt::UserRole, QVariant(query.value(0)));
//m_plwFilter->insertItem(m_plwFilter->size().height()-1,pItem);
}
db.close();
}
void Widget::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 Widget::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 Widget::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,timecategory,timestart,timeend,searchescategory,searchesmethod,searcheskeyword,searchesstring from filter where id = " + _pCurrent->data(Qt::UserRole).toString());
if (!query.next()) return;
switch(query.value(1).toInt())
{
case 0:
m_pdeStart->setDate(query.value(3).toDate());
m_pdeEnd->setDate(query.value(4).toDate());
m_pleString->setText("");
break;
case 1:
m_pcbCatalog->setCurrentIndex(query.value(5).toInt());
m_pcbMethod->setCurrentIndex(query.value(6).toInt());
m_pcbKeyword->setCurrentIndex(query.value(7).toInt());
m_pleString->setText(query.value(8).toString());
break;
}
}
bool Widget::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 Widget::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;
STable *pNew = new STable;
QTextCodec *codec = QTextCodec::codecForName("eucKR");
m_pProgress->setRange(0,file.size());
int ncRow=0;
int nCount=0;
bool bQuit = true;
int nRead = 0;
while(bQuit)
{
QString strLine;
{
QByteArray byte = file.readLine(196608);
if (byte.isEmpty()) { bQuit = false; continue; }
strLine = codec->toUnicode(byte);
nRead += byte.size();
}
if (nCount == 0)
{
QStringList strings = strLine.split(",");
if (strings.at(0) == QString("#Head#"))
{
pNew->setColumnCount(strings.size()-1);
for (int i = 1; i < strings.size();i++)
pNew->setHorizontalHeaderItem(i-1,new QTableWidgetItem(strings.at(i)));
nCount++;
continue;
}
else
pNew->setColumnCount(strings.size());
}
strLine = strLine.replace("\"","");
QStringList strings = strLine.split(",");
int ncCol=0;
pNew->setRowCount(strings.size());
foreach(QString str,strings)
{
pNew->setItem(ncRow,ncCol,new QTableWidgetItem(QString(" " + str + " ")));
ncCol++;
}
ncRow++;
m_pProgress->setValue(nRead);
m_pProgress->repaint();
}
pNew->setRowCount(pNew->rowCount()-1);
file.close();
m_ptwData->addTab(pNew," i");
m_ptwData->setCurrentIndex(m_ptwData->count()-1);
}
void Widget::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);
QTableWidget *pCurrent = (QTableWidget *)m_ptwData->currentWidget();
out << "#Head#,";
for (int nCount = 0;nCount < pCurrent->columnCount() ;nCount++ )
out << pCurrent->horizontalHeaderItem(nCount)->text() << ",";
m_pProgress->setRange(0,pCurrent->rowCount()-1);
for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ )
{
for (int nColumnCount = 0;nColumnCount < pCurrent->columnCount() ;nColumnCount++ )
{
QString str = pCurrent->item(nCount,nColumnCount)->text();
str = str.replace(",",".");
str = str.replace("\n","");
out << "\"" << str << "\"" << ",";
}
out << "\"\"" << endl;
m_pProgress->setValue(nCount);
m_pProgress->repaint();
}
file.close();
}
void Widget::FileExit()
{
exit(1);
}