From 2167659e7c2a31d299135ae35510ea3e290f28bf Mon Sep 17 00:00:00 2001 From: Carlos Barajas Date: Thu, 23 Nov 2017 07:09:14 -0500 Subject: [PATCH] Added ctrl+c functionality by subclassing QTableView --- cpp/rsearch.cpp | 1 - cpp/widgets/reader.cpp | 52 ++++++++++++++++++++++++++++++++++++++-- headers/widgets/reader.h | 15 +++++++++++- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/cpp/rsearch.cpp b/cpp/rsearch.cpp index e6f9743..1800afd 100644 --- a/cpp/rsearch.cpp +++ b/cpp/rsearch.cpp @@ -47,7 +47,6 @@ void rSearch::run() { // Thread Saftey at its finest complete[i] = true; } - // #pragma omp barrier if (*stopped) { qDebug() << "=rSearch (Old): Successfully killed!"; } diff --git a/cpp/widgets/reader.cpp b/cpp/widgets/reader.cpp index 7b9ab52..9cb1cc3 100644 --- a/cpp/widgets/reader.cpp +++ b/cpp/widgets/reader.cpp @@ -17,6 +17,9 @@ #include #include #include +#include +#include +#include #include "search.h" #include "rsearch.h" @@ -80,7 +83,8 @@ void Reader::initGui() { setWindowTitle("PSO2 Chat Reader"); resize(900, 500); // Build Table - table = new QTableView(this); + // table = new QTableView(this); + table = new SimpleTableView(this); table->setSortingEnabled(false); // (table->verticalHeader)()->setVisible(false); QHeaderView *vv = table->verticalHeader(); @@ -298,7 +302,7 @@ QList Reader::digestFile(QString filename) { if (len == 6) { QStringList usable; // Time - usable << line.at(0).split("T").at(0); + usable << line.at(0).split("T").at(1); // IDs usable << line.at(4) + QString("\n") + line.at(3); // Message @@ -379,3 +383,47 @@ QVariant ChatTable::headerData(int section, Qt::Orientation orientation, int rol } return QVariant(); } + +SimpleTableView::SimpleTableView(QWidget *parent) : QTableView(parent) { + setSelectionBehavior(QAbstractItemView::SelectRows); +} + +void SimpleTableView::keyPressEvent(QKeyEvent *event) { + // If Ctrl-C typed + // Or use event->matches(QKeySequence::Copy) + if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier)) + { + QModelIndexList cells = this->selectionModel()->selectedIndexes(); + qDebug() << "+Reader: Copy count" << cells.count(); + qSort(cells); // Necessary, otherwise they are in column order + QString toClip; + // QModelIndex cell; + for (int i = 0; i < cells.count() / 3; i++) { + // qDebug() << cells.at(i).row() << cells.at(i).column(); + // First column + toClip += "[" + cells.at(3*i + 0).data().toString() + "] "; + // Second column + toClip += cells.at(3*i + 1).data().toString().split(QRegExp("\\s+")).at(0) + ": "; + // Third column + toClip += cells.at(3*i+2).data().toString() + "\n"; + } + // QString text; + // int currentRow = 0; // To determine when to insert newlines + // foreach (const QModelIndex& cell, cells) { + // if (text.length() == 0) { + // // First item + // } else if (cell.row() != currentRow) { + // // New row + // text += '\n'; + // } else { + // // Next cell + // text += '\t'; + // } + // currentRow = cell.row(); + // text += cell.data().toString(); + // } +// + qDebug() << toClip; + QApplication::clipboard()->setText(toClip); + } +} diff --git a/headers/widgets/reader.h b/headers/widgets/reader.h index 7e91662..a1d9704 100644 --- a/headers/widgets/reader.h +++ b/headers/widgets/reader.h @@ -2,6 +2,7 @@ // Includes #include #include +#include #include #include #include @@ -33,6 +34,17 @@ class ChatTable : public QAbstractTableModel { QStringList chatTypes; }; +class SimpleTableView : public QTableView { + Q_OBJECT + public: + SimpleTableView(QWidget *parent = Q_NULLPTR); + protected: + void keyPressEvent(QKeyEvent *event); + + +}; + + class Reader : public QWidget { @@ -61,7 +73,8 @@ class Reader : public QWidget { // Variables QString base; QStringList headers; - QTableView *table; + // QTableView *table; + SimpleTableView *table; QTreeView *tree; QLabel *logTitle; QStandardItemModel *treeModel;