aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/programtableview.cpp
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-11 15:09:10 +0100
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-11 15:09:10 +0100
commit32084b4f5dfbfa2f653f55cfa514317c4b065b1e (patch)
treea5a30b51a71aa662b5bc34e96d6f6c8b6ee90338 /qtmips_gui/programtableview.cpp
parent20a381e4ba81777b2ad2d9cc988b990ca2ed0f55 (diff)
downloadqtmips-32084b4f5dfbfa2f653f55cfa514317c4b065b1e.tar.gz
qtmips-32084b4f5dfbfa2f653f55cfa514317c4b065b1e.tar.bz2
qtmips-32084b4f5dfbfa2f653f55cfa514317c4b065b1e.zip
Converted program listing to be QTableView based.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_gui/programtableview.cpp')
-rw-r--r--qtmips_gui/programtableview.cpp155
1 files changed, 155 insertions, 0 deletions
diff --git a/qtmips_gui/programtableview.cpp b/qtmips_gui/programtableview.cpp
new file mode 100644
index 0000000..34a119a
--- /dev/null
+++ b/qtmips_gui/programtableview.cpp
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*******************************************************************************
+ * QtMips - MIPS 32-bit Architecture Subset Simulator
+ *
+ * Implemented to support following courses:
+ *
+ * B35APO - Computer Architectures
+ * https://cw.fel.cvut.cz/wiki/courses/b35apo
+ *
+ * B4M35PAP - Advanced Computer Architectures
+ * https://cw.fel.cvut.cz/wiki/courses/b4m35pap/start
+ *
+ * Copyright (c) 2017-2019 Karel Koci<cynerd@email.cz>
+ * Copyright (c) 2019 Pavel Pisa <pisa@cmp.felk.cvut.cz>
+ *
+ * Faculty of Electrical Engineering (http://www.fel.cvut.cz)
+ * Czech Technical University (http://www.cvut.cz/)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ ******************************************************************************/
+
+#include <QHeaderView>
+#include <QFontMetrics>
+#include <QScrollBar>
+#include "programtableview.h"
+#include "programmodel.h"
+
+ProgramTableView::ProgramTableView(QWidget *parent, QSettings *settings) : Super(parent) {
+ connect(verticalScrollBar() , SIGNAL(valueChanged(int)),
+ this, SLOT(adjust_scroll_pos()));
+ this->settings = settings;
+ initial_address = settings->value("ProgramViewAddr0", 0).toULongLong();
+}
+
+void ProgramTableView::addr0_save_change(std::uint32_t val) {
+ settings->setValue("ProgramViewAddr0", val);
+}
+
+void ProgramTableView::adjustColumnCount() {
+ int cwidth;
+ int totwidth;
+ ProgramModel *m = dynamic_cast<ProgramModel*>(model());
+
+ if (m == nullptr)
+ return;
+
+ QFontMetrics fm(*m->getFont());
+ cwidth = fm.width("Bp");
+ totwidth = cwidth;
+ horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
+ horizontalHeader()->resizeSection(0, cwidth);
+ cwidth = fm.width("0x00000000");
+ totwidth += cwidth;
+ horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
+ horizontalHeader()->resizeSection(1, cwidth);
+ totwidth += cwidth;
+ cwidth = fm.width("00000000");
+ horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed);
+ horizontalHeader()->resizeSection(2, cwidth);
+ horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch);
+ totwidth += fm.width("BEQ $18, $17, 0x80020058");
+ totwidth += verticalHeader()->width();
+ setColumnHidden(2, totwidth > width());
+
+ if (initial_address != 0) {
+ go_to_address(initial_address);
+ initial_address = 0;
+ }
+}
+
+
+void ProgramTableView:: adjust_scroll_pos() {
+ std::uint32_t address;
+ ProgramModel *m = dynamic_cast<ProgramModel*>(model());
+ if (m == nullptr)
+ return;
+
+ QModelIndex prev_index = currentIndex();
+ std::uint32_t row_bytes = m->cellSizeBytes();
+ std::uint32_t index0_offset = m->getIndex0Offset();
+
+ do {
+ int row = rowAt(0);
+ int prev_row = row;
+ if (row < m->rowCount() / 8) {
+ if ((row == 0) && (index0_offset < row_bytes) && (index0_offset != 0)) {
+ m->adjustRowAndOffset(row, 0, 0);
+ } else if (index0_offset > row_bytes) {
+ m->get_row_address(address, row);
+ m->adjustRowAndOffset(row, m->rowCount() / 7, address);
+ } else {
+ break;
+ }
+ } else if (row > m->rowCount() - m->rowCount() / 8) {
+ m->get_row_address(address, row);
+ m->adjustRowAndOffset(row, m->rowCount() - m->rowCount() / 7, address);
+ } else {
+ break;
+ }
+ scrollTo(m->index(row, 0), QAbstractItemView::PositionAtTop);
+ setCurrentIndex(m->index(prev_index.row() + row - prev_row,
+ prev_index.column()));
+ emit m->update_all();
+ } while(0);
+ m->get_row_address(address, rowAt(0));
+ addr0_save_change(address);
+ emit address_changed(address);
+}
+
+void ProgramTableView::resizeEvent(QResizeEvent *event) {
+ ProgramModel *m = dynamic_cast<ProgramModel*>(model());
+ std::uint32_t address;
+ bool keep_row0 = false;
+
+ if (m != nullptr) {
+ if (initial_address == 0) {
+ keep_row0 = m->get_row_address(address, rowAt(0));
+ } else {
+ address = initial_address;
+ }
+ }
+ Super::resizeEvent(event);
+ adjustColumnCount();
+ if (keep_row0) {
+ initial_address = 0;
+ go_to_address(address);
+ }
+}
+
+void ProgramTableView:: go_to_address(std::uint32_t address) {
+ ProgramModel *m = dynamic_cast<ProgramModel*>(model());
+ int row;
+ if (m == nullptr)
+ return;
+ m->adjustRowAndOffset(row, m->rowCount() / 2, address);
+ scrollTo(m->index(row, 0),
+ QAbstractItemView::PositionAtTop);
+ setCurrentIndex(m->index(row, 1));
+ addr0_save_change(address);
+ emit m->update_all();
+}