count 통한 분석 추가

csv import export
replace 기능 추가

git-svn-id: svn://192.168.0.12/source@20 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
admin
2015-02-11 02:02:48 +00:00
parent 53dd9275da
commit c6db89c4e4
4 changed files with 448 additions and 109 deletions

View File

@@ -13,19 +13,15 @@ STable::STable(QWidget *parent):
verticalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(verticalHeader(),SIGNAL(customContextMenuRequested(QPoint)),SLOT(HeaderContextMenuShow(QPoint)));
connect(this,SIGNAL(cellClicked(int,int)),SLOT(CellClick(int,int)));
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
SetHeaderList();
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
}
void STable::SetHeaderList()
void STable::SetHeaderList(QVector <QStringList>* _pvecHead,int _nColumn)
{
m_strListHeader << "id " << "nickname" << "date" << "title" << "data" << "platform id" << "platform title" << "url"
<< "reply nickname" << "reply parent" << "reply date" << "reply data" << "reply urlreply"
<< "keyword id " << " platfor mname " << " platform form " << " article form " << " reply rownum ";
setColumnCount(m_strListHeader.size());
setColumnCount(_pvecHead->size());
int i = 0;
foreach(QString str, m_strListHeader )
setHorizontalHeaderItem(i++,new QTableWidgetItem(str));
foreach(QStringList strList, *_pvecHead )
setHorizontalHeaderItem(i++,new QTableWidgetItem(strList.at(_nColumn)));
}
void STable::keyPressEvent(QKeyEvent* event)
@@ -86,6 +82,7 @@ void STable::HeaderContextMenuShow(const QPoint& pos) // this is a slot
void STable::CellClick(int nRow,int nPrev)
{
Q_UNUSED(nPrev);
if (rowHeight(nRow) == 30)
resizeRowToContents(nRow);
else

View File

@@ -10,7 +10,7 @@ class STable : public QTableWidget
public:
explicit STable(QWidget *parent = 0);
void keyPressEvent(QKeyEvent* event);
void SetHeaderList();
void SetHeaderList(QVector <QStringList> *_vecColumn,int _nColumn);
public:
QStringList m_strListHeader;
signals:

View File

@@ -9,6 +9,7 @@
#include <QTextCodec>
#include <QMessageBox>
#include <QSqlError>
#include <QMenuBar>
/*
QSqlDatabase dbWeb = QSqlDatabase::addDatabase("QMYSQL");
@@ -26,21 +27,36 @@ dbWeb.setDatabaseName("dbconcepters");
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *vMainLayout = new QVBoxLayout;
{
if (ReloadColumn() == false)
return;
QVBoxLayout *vMainLayout = new QVBoxLayout;
vMainLayout->setAlignment(Qt::AlignVCenter);
vMainLayout->addWidget(setMenuWidget());
{
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->addWidget(setDateWidgets());
{
QHBoxLayout *hlayout = new QHBoxLayout;
if (m_nColumn != -1)
hlayout->addWidget(setDateWidgets());
hlayout->addWidget(setCountWidgets());
vlayout->addLayout(hlayout);
}
vlayout->addWidget(setSearchWidgets());
vlayout->addWidget(setDelLengWidgets());
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);
{
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);
@@ -63,7 +79,7 @@ Widget::~Widget()
QTableWidget *Widget::AddTable(QString _str)
{
STable *pTable = new STable;
m_ptwData->addTab(pTable,_str);
m_ptwData->addTab(pTable,_str);
return (QTableWidget *)pTable;
}
@@ -72,6 +88,19 @@ 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;
@@ -90,7 +119,7 @@ QGroupBox *Widget::setDataWidgets()
QGroupBox *Widget::setDateWidgets()
{
m_pcbDateCatalog = new QComboBox;
//m_pcbDateCatalog = new QComboBox;
m_pdeStart = new QDateEdit(QDate::currentDate());
m_pdeEnd = new QDateEdit(QDate::currentDate());
@@ -106,8 +135,8 @@ QGroupBox *Widget::setDateWidgets()
m_ppbInsertCalc = new QPushButton("Insert");
QHBoxLayout *hlayout = new QHBoxLayout();
hlayout->addWidget(new QLabel("Catalog:"));
hlayout->addWidget(m_pcbDateCatalog);
//hlayout->addWidget(new QLabel("Catalog:"));
//hlayout->addWidget(m_pcbDateCatalog);
hlayout->addWidget(new QLabel("Start:"));
hlayout->addWidget(m_pdeStart);
hlayout->addWidget(new QLabel("End:"));
@@ -117,11 +146,31 @@ QGroupBox *Widget::setDateWidgets()
QGroupBox *groupBox = new QGroupBox(tr("Term"));
groupBox->setAlignment(Qt::AlignLeft|Qt::AlignTop);
groupBox->setLayout(hlayout);
m_pcbDateCatalog->addItems(QStringList() << "body date" << "reply date");
//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;
@@ -135,9 +184,9 @@ QGroupBox *Widget::setSearchWidgets()
m_pcbMethod->addItem(QString("Space"));
m_pleString = new QLineEdit;
m_ppbInsertSearch = new QPushButton("Insert");
m_pcbCatalog->addItems(QStringList() << "id " << "nickname" << "date" << "title" << "data" << "platform id" << "platform title" << "url"
<< "reply nickname" << "reply parent" << "reply date" << "reply data" << "reply urlreply"
<< "keyword id " << " platfor mname " << " platform form " << " article form " << " reply rownum ");
foreach(QStringList strList,m_vecColumn)
m_pcbCatalog->addItem(strList.at(E_COLUMN_NAME));
QVBoxLayout *vlayout = new QVBoxLayout();
{
@@ -168,26 +217,6 @@ QGroupBox *Widget::setSearchWidgets()
return groupBox;
}
QGroupBox *Widget::setDelLengWidgets()
{
QHBoxLayout *hlayout = new QHBoxLayout();
m_pcbDelLeng = new QComboBox;
m_pleDelLeng = new QLineEdit;
m_pcbDelLeng->addItems(QStringList() << "id " << "nickname" << "date" << "title" << "data" << "platform id" << "platform title" << "url"
<< "reply nickname" << "reply parent" << "reply date" << "reply data" << "reply urlreply"
<< "keyword id " << " platfor mname " << " platform form " << " article form " << " reply rownum ");
hlayout->addWidget(new QLabel("Item:"));
hlayout->addWidget(m_pcbDelLeng);
hlayout->addWidget(new QLabel("Length:"));
hlayout->addWidget(m_pleDelLeng);
QPushButton *pbDelete = new QPushButton("insert");
connect(pbDelete , SIGNAL(released()),this, SLOT(SearchLength()));
hlayout->addWidget(pbDelete);
QGroupBox *groupBox = new QGroupBox(tr("Delete Length"));
groupBox->setLayout(hlayout);
return groupBox;
}
QGroupBox *Widget::setFilterWidgets()
{
QHBoxLayout *hMainlayout = new QHBoxLayout();
@@ -232,6 +261,70 @@ QGroupBox *Widget::setFilterWidgets()
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");
@@ -267,28 +360,19 @@ void Widget::SearchDate()
{
STable *pNew = new STable;
QTableWidget *pCurrent = (QTableWidget *)m_ptwData->currentWidget();
pNew->setColumnCount(pCurrent->columnCount());
//SetColumHeader(pNew);
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_pcbDateCatalog->currentIndex(),m_pdeStart->date(),m_pdeEnd->date(),nCurrentFilterGroupID);
InsertTimeFilter(m_nColumn,m_pdeStart->date(),m_pdeEnd->date(),nCurrentFilterGroupID);
}
int nColumn;
switch(m_pcbDateCatalog->currentIndex())
{
case 0:nColumn = 2;break; // main
case 1:nColumn = 10;break; // comment
default : return;
}
for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ )
{
bool bFlag = false;
QString strTime = pCurrent->item(nCount,nColumn)->text().trimmed();
QString strTime = pCurrent->item(nCount,m_nColumn)->text().trimmed();
if (strTime.size() >= 10)
{
QChar ch = strTime.at(4);
@@ -311,9 +395,8 @@ void Widget::SearchDate()
void Widget::SearchKeyword()
{
STable *pNew = new STable;
QTableWidget *pCurrent = (QTableWidget *)m_ptwData->currentWidget();
pNew->setColumnCount(pCurrent->columnCount());
//SetColumHeader(pNew);
QTableWidget *pCurrent = (QTableWidget *)m_ptwData->currentWidget();
pNew->SetHeaderList(&m_vecColumn,E_COLUMN_NAME);
int nCurrentFilterGroupID = D_NOT_SELECT;
foreach (QListWidgetItem *item,m_plwFilterGroup->selectedItems())
{
@@ -329,8 +412,7 @@ void Widget::SearchKeyword()
strListKeyword[i] = " " + strListKeyword[i] + " ";
}
}
m_pProgress->setRange(0,pCurrent->rowCount()-1);
qDebug() << QString::number(pCurrent->rowCount());
m_pProgress->setRange(0,pCurrent->rowCount()-1);
for (int nCount = 0 ; nCount < pCurrent->rowCount(); nCount++ )
{
bool bFlag = false;
@@ -380,17 +462,119 @@ void Widget::SearchKeyword()
RefreshFilter(nCurrentFilterGroupID);
}
void Widget::SearchLength()
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)
{
DataReload("data_" + item->data(Qt::UserRole).toString());
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)
{
void Widget::DataReload(QString _strTableName,int _nSelect)
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("bigbird.iptime.org");
db.setUserName("admin");
@@ -403,36 +587,24 @@ void Widget::DataReload(QString _strTableName)
}
QString strSelect;
strSelect = "select ";
strSelect += "CONVERT(body_articleid USING utf8),";
strSelect += "CONVERT(body_nickname USING utf8),";
strSelect += "CONVERT(body_date USING utf8),";
strSelect += "CONVERT(body_articletitle USING utf8),";
strSelect += "CONVERT(body_data USING utf8),";
strSelect += "CONVERT(body_platformid USING utf8),";
strSelect += "CONVERT(body_platformtitle USING utf8),";
strSelect += "CONVERT(url USING utf8),";
strSelect += "CONVERT(reply_nickname USING utf8),";
strSelect += "CONVERT(reply_parent USING utf8),";
strSelect += "CONVERT(reply_date USING utf8),";
strSelect += "CONVERT(reply_data USING utf8),";
strSelect += "CONVERT(reply_urlreply USING utf8),";
strSelect += "CONVERT(keyword_id USING utf8),";
strSelect += "CONVERT(platformname USING utf8),";
strSelect += "CONVERT(platformform USING utf8),";
strSelect += "CONVERT(articleform USING utf8),";
strSelect += "CONVERT(reply_rownum USING utf8)";
foreach(QStringList strlist,m_vecColumn)
strSelect += "CONVERT(" + strlist.at(E_COLUMN_DATABASE) + " USING utf8),";
strSelect = strSelect.left(strSelect.size()-1);
strSelect += " from ";
strSelect += _strTableName;
strSelect += " Order by body_date";
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();
int nCount = 0;
pTable->setColumnCount(18);
pTable->SetHeaderList(&m_vecColumn,E_COLUMN_NAME);
pTable->setRowCount(query.size());
m_pProgress->setRange(0,query.size()-1);
m_pProgress->setRange(0,query.size());
int nCount = 0;
while (query.next())
{
for (int i = 0; i < pTable->columnCount() ; i++)
@@ -440,7 +612,7 @@ void Widget::DataReload(QString _strTableName)
nCount++;
m_pProgress->setValue(nCount);
m_pProgress->repaint();
}
}
db.close();
}
@@ -524,6 +696,7 @@ void Widget::FilterGroupRefresh()
}
db.close();
}
void Widget::InsertTimeFilter(int _nCategory ,QDate _dateStart ,QDate _dateEnd ,int _nGroup)
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
@@ -602,8 +775,6 @@ void Widget::RefreshFilter(int _nGroup)
{
case 0:
str = "Type : Date ";
str += ", Catalog : ";
str += m_pcbDateCatalog->itemText(query.value(2).toInt());
str += ", Start : ";
str += query.value(3).toString();
str += ", End : ";
@@ -630,6 +801,7 @@ void Widget::RefreshFilter(int _nGroup)
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());
@@ -660,6 +832,7 @@ void Widget::FilterDelete()
void Widget::currentFilterItemChanged(QListWidgetItem *_pCurrent, QListWidgetItem *_pPrev)
{
Q_UNUSED(_pPrev);
if (_pCurrent == 0) return;
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("bigbird.iptime.org");
@@ -676,7 +849,6 @@ void Widget::currentFilterItemChanged(QListWidgetItem *_pCurrent, QListWidgetIte
switch(query.value(1).toInt())
{
case 0:
m_pcbDateCatalog->setCurrentIndex(query.value(2).toInt());
m_pdeStart->setDate(query.value(3).toDate());
m_pdeEnd->setDate(query.value(4).toDate());
m_pleString->setText("");
@@ -689,3 +861,125 @@ void Widget::currentFilterItemChanged(QListWidgetItem *_pCurrent, QListWidgetIte
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);
}

View File

@@ -15,11 +15,40 @@
#include <QButtonGroup>
#include <QTableWidget>
#include <QProgressBar>
#include <QMenuBar>
#include "stable.h"
class Widget : public QWidget
{
enum E_COLUMN
{
E_COLUMN_DATABASE=0,
E_COLUMN_NAME,
E_COLUMN_DATE,
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,
E_LENGTH_COMP_LESS,
E_LENGTH_COMP_EQUAL,
};
enum E_REPLACE
{
E_REPLACE_SENTENCE=0,
E_REPLACE_SPACE,
};
Q_OBJECT
public:
Widget(QWidget *parent = 0);
@@ -32,42 +61,57 @@ private:
QDateEdit *m_pdeStart;
QDateEdit *m_pdeEnd;
QPushButton *m_ppbInsertCalc;
QComboBox *m_pcbDateCatalog;
//QComboBox *m_pcbDateCatalog;
int m_nColumn;
// Keyword
QComboBox *m_pcbCatalog;
QComboBox *m_pcbKeyword;
QComboBox *m_pcbMethod;
QLineEdit *m_pleString;
QPushButton *m_ppbInsertSearch;
// Delete Length
QComboBox *m_pcbDelLeng;
QLineEdit *m_pleDelLeng;
// Length
QComboBox *m_pcbLengthCatalog;
QComboBox *m_pcbLengthComp;
QComboBox *m_pcbLengthInsDel;
QLineEdit *m_pleLength;
// Filter
QListWidget *m_plwFilterGroup;
QListWidget *m_plwFilter;
QLineEdit *m_pleFilterGroup;
// Replace
QComboBox *m_pcbReplaceCatalog;
QComboBox *m_pcbReplaceFind;
QLineEdit *m_pleReplaceFind;
QLineEdit *m_pleReplace;
// Count
QComboBox *m_pcbCountCatalog;
//
QTabWidget *m_ptwData;
//
QProgressBar *m_pProgress;
//void keyPressEvent(QKeyEvent* event);
// Column
QVector <QStringList> m_vecColumn;
private:
QMenuBar *setMenuWidget();
QGroupBox *setDataWidgets();
QGroupBox *setDateWidgets();
QGroupBox *setSearchWidgets();
QGroupBox *setDelLengWidgets();
QGroupBox *setCountWidgets();
QGroupBox *setSearchWidgets();
QGroupBox *setLengthWidgets();
QGroupBox *setFilterWidgets();
QGroupBox *setReplaceWidgets();
QTableWidget *AddTable(QString _str);
void SetTableHead();
void SetColumHeader(QTableWidget *_pNew);
void InsertCopyRow(int _nRow,QTableWidget *_pCurrent,QTableWidget *_pNew);
void DataReload(QString _strTableName);
void DataReload(QString _strTableName,int _nSelect);
void InsertTimeFilter(int _nTimeCategory ,QDate _dateStart ,QDate _dateEnd ,int _nGroup);
void InsertSearchFilter(int _nCategory,int _nMethod,int _nKeyword, QString str,int _nGroup);
void RefreshFilter(int _nGroup);
bool ReloadColumn();
public slots:
void SearchDate();
void CloseTab(int index);
@@ -79,9 +123,13 @@ public slots:
void FilterGroupModify();
void FilterGroupRefresh();
void currentGroupItemChanged(QListWidgetItem *_pCurrent, QListWidgetItem *_pPrev=0);
void FilterDelete();
void SearchLength();
void currentFilterItemChanged(QListWidgetItem *_pCurrent, QListWidgetItem *_pPrev=0);
void FilterDelete();
void currentFilterItemChanged(QListWidgetItem *_pCurrent, QListWidgetItem *_pPrev=0);
void SearchLengthInsert();
void SearchReplaceInsert();
void FileImport();
void FileExport();
void FileExit();
};
#endif // WIDGET_H