1199 lines
41 KiB
C++
1199 lines
41 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>
|
|
#include <QInputDialog>
|
|
#include "../Json/sjson.h"
|
|
#include "../common.h"
|
|
|
|
/*
|
|
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)));
|
|
connect(m_ptwData,SIGNAL(tabBarDoubleClicked(int)),this,SLOT(DoubleClickTab(int)));
|
|
m_pProgress = new QProgressBar;
|
|
vMainLayout->addWidget(m_pProgress,1);
|
|
}
|
|
setLayout(vMainLayout);
|
|
DataGroupRefresh();
|
|
FilterGroupRefresh();
|
|
AddTable("Start");
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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();
|
|
connect(pFile->addAction("Exit"), SIGNAL(triggered()), this, SLOT(FileExit()));
|
|
}
|
|
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;
|
|
|
|
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);
|
|
|
|
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 *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(CountSave()));
|
|
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_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 *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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
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 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;
|
|
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 Widget::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 Widget::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 Widget::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 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(),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)
|
|
{
|
|
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 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::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 Widget::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 Widget::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 Widget::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 Widget::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 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,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 += "<Date> Start : ";
|
|
str += json.Get(strJson,"Start");
|
|
str += " End : ";
|
|
str += json.Get(strJson,"End");
|
|
break;
|
|
case E_FILTER_TYPE_SEARCH:
|
|
str += "<Search> ";
|
|
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 += "<Length> ";
|
|
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 += "<Replace> ";
|
|
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 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,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 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,"import");
|
|
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);
|
|
}
|
|
|
|
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 <SCount> 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();
|
|
}
|