From fe4721d4b3e1b3cfa845bd52788f790038d34578 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Fri, 15 Feb 2019 23:08:00 +0100 Subject: Enable copy from memory and program views. Signed-off-by: Pavel Pisa --- qtmips_gui/memorytableview.cpp | 20 ++++++++++++++++++++ qtmips_gui/memorytableview.h | 2 ++ qtmips_gui/programtableview.cpp | 21 ++++++++++++++++++++- qtmips_gui/programtableview.h | 2 ++ 4 files changed, 44 insertions(+), 1 deletion(-) (limited to 'qtmips_gui') diff --git a/qtmips_gui/memorytableview.cpp b/qtmips_gui/memorytableview.cpp index e2386fa..aeec25e 100644 --- a/qtmips_gui/memorytableview.cpp +++ b/qtmips_gui/memorytableview.cpp @@ -36,6 +36,9 @@ #include #include #include +#include +#include +#include #include "memorytableview.h" #include "memorymodel.h" @@ -191,3 +194,20 @@ void MemoryTableView::focus_address(std::uint32_t address) { return; setCurrentIndex(m->index(row, 1)); } + +void MemoryTableView::keyPressEvent(QKeyEvent *event) { + if(event->matches(QKeySequence::Copy)) { + QString text; + QItemSelectionRange range = selectionModel()->selection().first(); + for (auto i = range.top(); i <= range.bottom(); ++i) + { + QStringList rowContents; + for (auto j = range.left(); j <= range.right(); ++j) + rowContents << model()->index(i,j).data().toString(); + text += rowContents.join("\t"); + text += "\n"; + } + QApplication::clipboard()->setText(text); + } else + Super::keyPressEvent(event); +} diff --git a/qtmips_gui/memorytableview.h b/qtmips_gui/memorytableview.h index a0f2617..f2ed9cb 100644 --- a/qtmips_gui/memorytableview.h +++ b/qtmips_gui/memorytableview.h @@ -57,6 +57,8 @@ public slots: void set_cell_size(int index); void go_to_address(std::uint32_t address); void focus_address(std::uint32_t address); +protected: + void keyPressEvent(QKeyEvent *event); private slots: void adjust_scroll_pos(); private: diff --git a/qtmips_gui/programtableview.cpp b/qtmips_gui/programtableview.cpp index 005b518..e3114a6 100644 --- a/qtmips_gui/programtableview.cpp +++ b/qtmips_gui/programtableview.cpp @@ -36,6 +36,9 @@ #include #include #include +#include +#include +#include #include "programtableview.h" #include "programmodel.h" @@ -82,7 +85,6 @@ void ProgramTableView::adjustColumnCount() { } } - void ProgramTableView:: adjust_scroll_pos() { std::uint32_t address; ProgramModel *m = dynamic_cast(model()); @@ -165,3 +167,20 @@ void ProgramTableView::focus_address(std::uint32_t address) { return; setCurrentIndex(m->index(row, 3)); } + +void ProgramTableView::keyPressEvent(QKeyEvent *event) { + if(event->matches(QKeySequence::Copy)) { + QString text; + QItemSelectionRange range = selectionModel()->selection().first(); + for (auto i = range.top(); i <= range.bottom(); ++i) + { + QStringList rowContents; + for (auto j = range.left(); j <= range.right(); ++j) + rowContents << model()->index(i,j).data().toString(); + text += rowContents.join("\t"); + text += "\n"; + } + QApplication::clipboard()->setText(text); + } else + Super::keyPressEvent(event); +} diff --git a/qtmips_gui/programtableview.h b/qtmips_gui/programtableview.h index 30fc5f6..5a67f51 100644 --- a/qtmips_gui/programtableview.h +++ b/qtmips_gui/programtableview.h @@ -56,6 +56,8 @@ signals: public slots: void go_to_address(std::uint32_t address); void focus_address(std::uint32_t address); +protected: + void keyPressEvent(QKeyEvent *event); private slots: void adjust_scroll_pos(); private: -- cgit v1.2.3