git-svn-id: svn://192.168.0.12/source@1 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
94
DataAnalyzer/stable.cpp
Normal file
94
DataAnalyzer/stable.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#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);
|
||||
SetHeaderList();
|
||||
}
|
||||
|
||||
void STable::SetHeaderList()
|
||||
{
|
||||
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());
|
||||
int i = 0;
|
||||
foreach(QString str, m_strListHeader )
|
||||
setHorizontalHeaderItem(i++,new QTableWidgetItem(str));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (rowHeight(nRow) == 30)
|
||||
resizeRowToContents(nRow);
|
||||
else
|
||||
setRowHeight(nRow,30);
|
||||
repaint();
|
||||
}
|
||||
Reference in New Issue
Block a user