Resize memory view to window size
MODIFY
src/memorymodel.h
src/memorymodel.h
@@ -17,6 +17,7 @@ class MemoryModel : public QStandardItemModel {
void offsetCentralAddress(int byteOffset);
void setAddressCount(int count);
long long getCentralAddress() const { return m_centralAddress; }
+ int getModelRows() const { return rowCount(); }
public slots:
void jumpToAddress(uint32_t address);
@@ -31,7 +32,7 @@ class MemoryModel : public QStandardItemModel {
memory* m_memoryPtr;
long long m_centralAddress = 4; // Address at the center of the model
- int m_addressRadius = 5; // amount of addresses in each direction, from
+ int m_addressRadius = 20; // amount of addresses in each direction, from
// centralAddress
};

MODIFY
src/memorytab.cpp
src/memorytab.cpp
@@ -152,6 +152,8 @@ void MemoryTab::initializeMemoryView() {
// Connect save address button
connect(m_ui->save, &QPushButton::clicked, this, &MemoryTab::saveAddress);
+
+ connect(m_model, &MemoryModel::dataChanged, m_ui->memoryView, &MemoryView::setVisibleRows);
}
MemoryTab::~MemoryTab() { delete m_ui; }

MODIFY
src/memoryview.cpp
src/memoryview.cpp
#include "memoryview.h"
+#include "memorymodel.h"
+
+#include <QHeaderView>
+
MemoryView::MemoryView(QWidget* parent) : QTableView(parent) {}
void MemoryView::wheelEvent(QWheelEvent* event) {
@@ -9,3 +13,34 @@ void MemoryView::wheelEvent(QWheelEvent* event) {
emit scrolled(false);
}
}
+
+void MemoryView::setVisibleRows() {
+ // Detect and set changes in rowheight
+ if (rowHeight(1) != 0) {
+ m_rowHeight = rowHeight(1);
+ }
+
+ // Set visible rows from model, based on tableView size and rowheights
+ int modelRows = dynamic_cast< MemoryModel* >(model())->getModelRows();
+
+ // Calculate number of visible rows
+ int visibleRows = (height() - horizontalHeader()->height() - 10) / m_rowHeight;
+ if ((visibleRows % 2) == 0) visibleRows--;
+
+ // Hide the rows above and below the requested range
+ const int removeCnt = (modelRows - visibleRows) / 2;
+ for (int i = 0; i < removeCnt; i++) {
+ setRowHidden(i, true);
+ }
+ for (int i = removeCnt; i < (visibleRows + removeCnt); i++) {
+ setRowHidden(i, false);
+ }
+ for (int i = visibleRows + removeCnt; i < (visibleRows + 2 * removeCnt); i++) {
+ setRowHidden(i, true);
+ }
+}
+
+void MemoryView::resizeEvent(QResizeEvent* event) {
+ QTableView::resizeEvent(event);
+ setVisibleRows();
+}

MODIFY
src/memoryview.h
src/memoryview.h
@@ -16,8 +16,17 @@ class MemoryView : public QTableView {
void wheelEvent(QWheelEvent* event) override;
+ protected:
+ void resizeEvent(QResizeEvent* event);
+
+ public slots:
+ void setVisibleRows();
+
signals:
void scrolled(bool dir);
+
+ private:
+ int m_rowHeight = 0;
};
#endif // MEMORYVIEW_H

Resize memory view to window size