From 685b1f36236bbfcfdd85970ef9527203e762fbbc Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 1 Jun 2015 06:47:08 +0000 Subject: [PATCH] crawling qtableview ctrl-c ctrl-v git-svn-id: svn://192.168.0.12/source@136 8346c931-da38-4b9b-9d4c-e48b93cbd075 --- GroupManager/stable.cpp | 31 ++++++++++++++++++++++++++++++- GroupManager/stable.h | 9 ++++++++- GroupManager/widget.cpp | 4 +++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/GroupManager/stable.cpp b/GroupManager/stable.cpp index f345105..782a424 100644 --- a/GroupManager/stable.cpp +++ b/GroupManager/stable.cpp @@ -1,5 +1,5 @@ #include "stable.h" - +#include STable::STable() { @@ -10,3 +10,32 @@ STable::~STable() } +void STable::keyPressEvent(QKeyEvent* event) +{ + // If Ctrl-C typed + if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier)) + Copy(); +} + + +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); +} diff --git a/GroupManager/stable.h b/GroupManager/stable.h index 2611e95..2d4cc6a 100644 --- a/GroupManager/stable.h +++ b/GroupManager/stable.h @@ -2,13 +2,20 @@ #define STABLE_H #include - +#include +#include +#include class STable : public QTableView { + //Q_OBJECT public: STable(); ~STable(); + +public: + void keyPressEvent(QKeyEvent* event); + void Copy(); }; #endif // STABLE_H diff --git a/GroupManager/widget.cpp b/GroupManager/widget.cpp index 17a8419..a14d5f0 100644 --- a/GroupManager/widget.cpp +++ b/GroupManager/widget.cpp @@ -12,6 +12,7 @@ #include #include #include +#include "stable.h" Widget::Widget(QWidget *parent) : QWidget(parent) @@ -278,7 +279,8 @@ QGroupBox *Widget::setCrawlingWidgets() } { - m_ptableCrawling = new QTableView; + //m_ptableCrawling = new QTableView; + m_ptableCrawling = new STable; m_ptableCrawling->setModel(m_pmodelCrawling); m_ptableCrawling->setSelectionBehavior(QAbstractItemView::SelectRows); m_ptableCrawling->setSelectionMode(QAbstractItemView::ContiguousSelection);