Files
clients/MorphereAnalyzer/stable.cpp
admin 631710f631 1.형태소분석 centerkeyword 방식 추가
2.일괄처리방식 search 마지막에 스페이스 있을 경우 분석결과가 나오지 않는 오류
3.형태소분석 위젯 순서 변경
4.anlayzer new column 할 경우 QTableWidgetItem(QString(" ")) 수행되도록 수정
5.엑셀에서 붙혀 넣기할 때 row 가 추가될 경우 빈 cell에 공백 추가하기(4번과 유사함)


git-svn-id: svn://192.168.0.12/source@255 8346c931-da38-4b9b-9d4c-e48b93cbd075
2016-02-23 10:17:09 +00:00

196 lines
5.2 KiB
C++

#include "stable.h"
#include <QKeyEvent>
#include <QApplication>
#include <QClipboard>
#include <QMenu>
#include <QHeaderView>
#include <QMessageBox>
STable::STable(QWidget *parent):
QTableWidget(parent)
{
setSortingEnabled(true);
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);
m_nArticle = E_ARTICLE_NONE;
}
void STable::SetHeaderList(QVector <QStringList>* _pvecHead,int _nColumn)
{
setColumnCount(_pvecHead->size());
int i = 0;
foreach(QStringList strList, *_pvecHead )
setHorizontalHeaderItem(i++,new QTableWidgetItem(strList.at(_nColumn)));
}
void STable::SetHeaderList(QStringList _Head)
{
setColumnCount(_Head.size());
int i = 0;
foreach(QString str,_Head )
setHorizontalHeaderItem(i++,new QTableWidgetItem(str));
}
void STable::keyPressEvent(QKeyEvent* event)
{
// If Ctrl-C typed
if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier))
Copy();
if (event->key() == Qt::Key_V && (event->modifiers() & Qt::ControlModifier))
Paste();
if (event->key() == Qt::Key_Delete)
Delete();
}
void STable::menuInsert()
{
int nRow = currentRow();
insertRow(nRow);
for (int i = 0; i < columnCount() ; i++)
setItem(nRow,i,new QTableWidgetItem(" "));
}
void STable::menuDelete()
{
int nCount = 0;
foreach(QModelIndex current,verticalHeader()->selectionModel()->selectedRows())
{
removeRow(current.row()-nCount);
nCount++;
}
}
void STable::HeaderContextMenuShow(const QPoint& pos) // this is a slot
{
QMenu myMenu;
myMenu.addAction("Insert", this, SLOT(menuInsert()));
myMenu.addAction("Delete", this, SLOT(menuDelete()));
myMenu.exec(mapToGlobal(pos));
}
void STable::CellClick(int nRow,int nPrev)
{
Q_UNUSED(nPrev);
if (rowHeight(nRow) == 30)
resizeRowToContents(nRow);
else
setRowHeight(nRow,30);
repaint();
}
void STable::Copy()
{
QModelIndexList cells = selectedIndexes();
//qSort(cells);
QString text;
int currentRow = 0;
foreach (const QModelIndex& cell, cells)
{
if (text.length() == 0)
{
}
else if (cell.row() != currentRow)
text += '\n';
else
text += '\t';
currentRow = cell.row();
text += cell.data().toString();
}
QApplication::clipboard()->setText(text);
}
void STable::Paste()
{
//if(qApp->clipboard()->mimeData()->hasHtml())
{
// TODO, parse the html data
}
//else
{
QModelIndexList cells = selectedIndexes();
qSort(cells);
if (cells.size() == 0) return;
QString str = QApplication::clipboard()->text();
QStringList strRows = str.split("\n");
if (strRows.size() == 0) return;
int nStartRow = cells.at(0).row();
int nStartCol = cells.at(0).column();
int nRows = strRows.size();
{
int nPlusRow = nStartRow + nRows - rowCount();
if (nPlusRow > 0)
{
int rowcnt = rowCount();
setRowCount(rowCount()+nPlusRow);
for(int i = rowcnt; i < rowcnt + nPlusRow; i++)
{
for(int j = 0; j < columnCount(); j++)
{
setItem(i, j, new QTableWidgetItem(QString(" ")));
}
}
}
}
int nRow = nStartRow;
foreach(QString strRow,strRows)
{
QStringList strCols = strRow.split("\t");
int nCol = nStartCol;
foreach(QString strCol,strCols)
{
if (nCol >= columnCount()) continue;
QTableWidgetItem *pItem;
if (nRows >= nRows)
pItem = new QTableWidgetItem;
else
pItem = item(nRow,nCol);
pItem->setText(" "+strCol.trimmed()+" ");
setItem(nRow,nCol,pItem);
nCol++;
}
nRow++;
}
}
}
void STable::Delete()
{
QModelIndexList cells = selectedIndexes();
foreach (const QModelIndex& cell, cells)
{
QTableWidgetItem *pItem = item(cell.row(),cell.column());
if (pItem != NULL)
{
pItem->setText("");
setItem(cell.row(),cell.column(),pItem);
}
}
}
void STable::setArticleSelect(int _nArticle)
{
m_nArticle = _nArticle;
}
QString STable::GetArticleType(int _nSelect)
{
switch(_nSelect)
{
case E_ARTICLE_NONE:
return QString("{None} ");
case E_ARTICLE_BODY:
return QString("{Body} ");
case E_ARTICLE_REPLY:
return QString("{Relpy} ");
case E_ARTICLE_ALL:
return QString("{All} ");
}
return QString("{Other} ");
}