Files
clients/DataAnalyzer/stable.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

92 lines
2.4 KiB
C++

#include "stable.h"
#include <QKeyEvent>
#include <QApplication>
#include <qclipboard>
#include <QMenu>
#include <QDebug>
#include <QHeaderView>
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);
}
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::keyPressEvent(QKeyEvent* event)
{
// If Ctrl-C typed
if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier))
{
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);
}
if (event->key() == Qt::Key_V && (event->modifiers() & Qt::ControlModifier))
{
}
}
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();
}