aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-01-25 17:10:59 +0100
committerKarel Kočí <cynerd@email.cz>2018-01-25 17:10:59 +0100
commitc82fd7320a83daec780bb9f7c11239e269410c91 (patch)
treea5939471652ded3943606699480a6a105696807f
parentdb722b7163fffc868cdea338bd6a4c6eddffd2b1 (diff)
downloadqtmips-c82fd7320a83daec780bb9f7c11239e269410c91.tar.gz
qtmips-c82fd7320a83daec780bb9f7c11239e269410c91.tar.bz2
qtmips-c82fd7320a83daec780bb9f7c11239e269410c91.zip
Add focus function to memory view
-rw-r--r--qtmips_gui/memoryview.cpp54
-rw-r--r--qtmips_gui/memoryview.h4
-rw-r--r--qtmips_gui/programdock.cpp2
-rw-r--r--qtmips_machine/memory.cpp10
-rw-r--r--qtmips_machine/memory.h4
5 files changed, 64 insertions, 10 deletions
diff --git a/qtmips_gui/memoryview.cpp b/qtmips_gui/memoryview.cpp
index c391169..4b6fee1 100644
--- a/qtmips_gui/memoryview.cpp
+++ b/qtmips_gui/memoryview.cpp
@@ -3,6 +3,8 @@
///////////////////////////
// Minimal reserved range in pixels of scroll area (otherwise 10% of height are used)
#define MIN_OFF 10
+// Focus point (this is multiplied with height of widget to know position where we want to focus)
+#define FOCUS 0.25
///////////////////////////
#include <iostream>
@@ -29,9 +31,11 @@ MemoryView::MemoryView(QWidget *parent) : QWidget(parent) {
connect(go_edit, SIGNAL(editingFinished()), this, SLOT(go_edit_finish()));
up = new QToolButton(ctl_widg);
up->setArrowType(Qt::UpArrow);
+ connect(up, SIGNAL(clicked(bool)), this, SLOT(prev_section()));
ctl_layout->addWidget(up);
down = new QToolButton(ctl_widg);
down->setArrowType(Qt::DownArrow);
+ connect(down, SIGNAL(clicked(bool)), this, SLOT(next_section()));
ctl_layout->addWidget(down);
}
@@ -41,13 +45,21 @@ void MemoryView::setup(machine::QtMipsMachine *machine) {
}
void MemoryView::set_focus(std::uint32_t address) {
- // TODO center
- // TODO update view
+ if (address < addr_0 || (address - addr_0)/4 > (unsigned)memf->widg->count()) {
+ // This is outside of loaded area so just move it and reload everything
+ addr_0 = address - 4*memf->focussed();
+ reload_content();
+ } else {
+ memf->focus((address - addr_0) / 4);
+ }
}
std::uint32_t MemoryView::focus() {
- // TODO
- return 0;
+ return addr_0 + 4*memf->focussed();
+}
+
+void MemoryView::edit_load_focus() {
+ go_edit->setText(QString("0x%1").arg(focus(), 8, 16, QChar('0')));
}
void MemoryView::reload_content() {
@@ -90,7 +102,27 @@ void MemoryView::update_content(int count, int shift) {
}
void MemoryView::go_edit_finish() {
- // TODO
+ QString hex = go_edit->text();
+ hex.remove(0, 2);
+
+ bool ok;
+ std::uint32_t nw = hex.toUInt(&ok, 16);
+ if (ok) {
+ set_focus(nw);
+ } else
+ edit_load_focus();
+}
+
+void MemoryView::next_section() {
+ if (memory == nullptr)
+ return;
+ set_focus(memory->next_allocated(focus()));
+}
+
+void MemoryView::prev_section() {
+ if (memory == nullptr)
+ return;
+ set_focus(memory->prev_allocated(focus()));
}
MemoryView::Frame::Frame(MemoryView *parent) : QAbstractScrollArea(parent) {
@@ -107,12 +139,16 @@ MemoryView::Frame::Frame(MemoryView *parent) : QAbstractScrollArea(parent) {
}
void MemoryView::Frame::focus(unsigned i) {
- // TODO
+ content_y = (FOCUS*height()) - widg->row_size()*i - widg->row_size()/2;
+ viewport()->move(0, content_y);
+ viewport()->repaint(0, content_y, width(), height());
+ check_update();
}
+// Calculate which row is in focus at the moment
unsigned MemoryView::Frame::focussed() {
- // TODO
- return 0;
+ int h = (FOCUS*height() - content_y) / widg->row_size();
+ return qMax(h, 0);
}
// This verifies that we are not scrolled too far away down or up and that we have enought height
@@ -135,6 +171,8 @@ void MemoryView::Frame::check_update() {
content_y -= shift * row_h;
widg->setGeometry(0, content_y, width(), widg->heightForWidth(width()));
}
+
+ mv->edit_load_focus();
}
void MemoryView::Frame::resizeEvent(QResizeEvent *e) {
diff --git a/qtmips_gui/memoryview.h b/qtmips_gui/memoryview.h
index be2c8a2..ec909f0 100644
--- a/qtmips_gui/memoryview.h
+++ b/qtmips_gui/memoryview.h
@@ -24,6 +24,8 @@ public:
void set_focus(std::uint32_t address);
std::uint32_t focus();
+ void edit_load_focus(); // Set current focus to edit field
+
protected:
const machine::Memory *memory;
@@ -36,6 +38,8 @@ protected:
private slots:
void go_edit_finish();
+ void next_section();
+ void prev_section();
private:
unsigned count;
diff --git a/qtmips_gui/programdock.cpp b/qtmips_gui/programdock.cpp
index 06aa9cd..3d881df 100644
--- a/qtmips_gui/programdock.cpp
+++ b/qtmips_gui/programdock.cpp
@@ -2,8 +2,6 @@
#include "qtmipsexception.h"
ProgramView::ProgramView(QWidget *parent) : MemoryView(parent) {
- set_focus(0x80020000); // Initialize focus address to program start
-
cb_single = new QComboBox(this);
cb_single->addItems({
"Don't follow",
diff --git a/qtmips_machine/memory.cpp b/qtmips_machine/memory.cpp
index eec9f8c..07c8e3c 100644
--- a/qtmips_machine/memory.cpp
+++ b/qtmips_machine/memory.cpp
@@ -254,6 +254,16 @@ const union machine::MemoryTree *Memory::get_memorytree_root() const {
return this->mt_root;
}
+std::uint32_t Memory::next_allocated(std::uint32_t addr) const {
+ // TODO
+ return addr;
+}
+
+std::uint32_t Memory::prev_allocated(std::uint32_t addr) const {
+ // TODO
+ return addr;
+}
+
union machine::MemoryTree *Memory::allocate_section_tree() {
union MemoryTree *mt = new union MemoryTree[MEMORY_TREE_LEN];
for (size_t i = 0; i < MEMORY_TREE_LEN; i++)
diff --git a/qtmips_machine/memory.h b/qtmips_machine/memory.h
index d1fa2e7..525ca56 100644
--- a/qtmips_machine/memory.h
+++ b/qtmips_machine/memory.h
@@ -87,6 +87,10 @@ public:
const union MemoryTree *get_memorytree_root() const;
+ // These functions locate next start or end of next allocated tree leaf
+ std::uint32_t next_allocated(std::uint32_t) const;
+ std::uint32_t prev_allocated(std::uint32_t) const;
+
private:
union MemoryTree *mt_root;
static union MemoryTree *allocate_section_tree();