aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_gui')
-rw-r--r--qtmips_gui/memorymodel.cpp6
-rw-r--r--qtmips_gui/memorymodel.h2
-rw-r--r--qtmips_gui/memorytableview.cpp25
-rw-r--r--qtmips_gui/memorytableview.h7
-rw-r--r--qtmips_gui/programmodel.cpp6
-rw-r--r--qtmips_gui/programmodel.h2
-rw-r--r--qtmips_gui/programtableview.cpp25
-rw-r--r--qtmips_gui/programtableview.h7
8 files changed, 50 insertions, 30 deletions
diff --git a/qtmips_gui/memorymodel.cpp b/qtmips_gui/memorymodel.cpp
index 597b88f..b88c5b7 100644
--- a/qtmips_gui/memorymodel.cpp
+++ b/qtmips_gui/memorymodel.cpp
@@ -199,11 +199,7 @@ void MemoryModel::check_for_updates() {
update_all();
}
-bool MemoryModel::adjustRowAndOffset(int &row, int optimal_row, std::uint32_t address) {
- if (optimal_row < rowCount() / 8)
- optimal_row = rowCount() / 8;
- if (optimal_row >= rowCount() - rowCount() / 8)
- optimal_row = rowCount() - rowCount() / 8;
+bool MemoryModel::adjustRowAndOffset(int &row, std::uint32_t address) {
row = rowCount() / 2;
address -= address % cellSizeBytes();
std::uint32_t row_bytes = cells_per_row * cellSizeBytes();
diff --git a/qtmips_gui/memorymodel.h b/qtmips_gui/memorymodel.h
index 7d12f91..01b5310 100644
--- a/qtmips_gui/memorymodel.h
+++ b/qtmips_gui/memorymodel.h
@@ -59,7 +59,7 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex & index, const QVariant & value, int role);
- bool adjustRowAndOffset(int &row, int optimal_row, std::uint32_t address);
+ bool adjustRowAndOffset(int &row, std::uint32_t address);
void update_all();
void setCellsPerRow(unsigned int cells);
diff --git a/qtmips_gui/memorytableview.cpp b/qtmips_gui/memorytableview.cpp
index aeec25e..74729c5 100644
--- a/qtmips_gui/memorytableview.cpp
+++ b/qtmips_gui/memorytableview.cpp
@@ -44,9 +44,12 @@
MemoryTableView::MemoryTableView(QWidget *parent, QSettings *settings) : Super(parent) {
connect(verticalScrollBar() , SIGNAL(valueChanged(int)),
- this, SLOT(adjust_scroll_pos()));
+ this, SLOT(adjust_scroll_pos_check()));
+ connect(this , SIGNAL(adjust_scroll_pos_queue()),
+ this, SLOT(adjust_scroll_pos_process()), Qt::QueuedConnection);
this->settings = settings;
initial_address = settings->value("DataViewAddr0", 0).toULongLong();
+ adjust_scroll_pos_in_progress = false;
}
void MemoryTableView::addr0_save_change(std::uint32_t val) {
@@ -106,13 +109,21 @@ void MemoryTableView::set_cell_size(int index) {
}
adjustColumnCount();
if (keep_row0) {
- m->adjustRowAndOffset(row, m->rowCount() / 2, address);
+ m->adjustRowAndOffset(row, address);
scrollTo(m->index(row, 0),
QAbstractItemView::PositionAtTop);
}
}
-void MemoryTableView:: adjust_scroll_pos() {
+void MemoryTableView::adjust_scroll_pos_check() {
+ if (!adjust_scroll_pos_in_progress) {
+ adjust_scroll_pos_in_progress = true;
+ emit adjust_scroll_pos_queue();
+ }
+}
+
+void MemoryTableView::adjust_scroll_pos_process() {
+ adjust_scroll_pos_in_progress = false;
std::uint32_t address;
MemoryModel *m = dynamic_cast<MemoryModel*>(model());
if (m == nullptr)
@@ -127,16 +138,16 @@ void MemoryTableView:: adjust_scroll_pos() {
int prev_row = row;
if (row < m->rowCount() / 8) {
if ((row == 0) && (index0_offset < row_bytes) && (index0_offset != 0)) {
- m->adjustRowAndOffset(row, 0, 0);
+ m->adjustRowAndOffset(row, 0);
} else if (index0_offset > row_bytes) {
m->get_row_address(address, row);
- m->adjustRowAndOffset(row, m->rowCount() / 7, address);
+ m->adjustRowAndOffset(row, 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);
+ m->adjustRowAndOffset(row, address);
} else {
break;
}
@@ -175,7 +186,7 @@ void MemoryTableView::go_to_address(std::uint32_t address) {
int row;
if (m == nullptr)
return;
- m->adjustRowAndOffset(row, m->rowCount() / 2, address);
+ m->adjustRowAndOffset(row, address);
scrollTo(m->index(row, 0),
QAbstractItemView::PositionAtTop);
setCurrentIndex(m->index(row, 1));
diff --git a/qtmips_gui/memorytableview.h b/qtmips_gui/memorytableview.h
index f2ed9cb..a84b80e 100644
--- a/qtmips_gui/memorytableview.h
+++ b/qtmips_gui/memorytableview.h
@@ -53,20 +53,23 @@ public:
void resizeEvent(QResizeEvent *event) override;
signals:
void address_changed(std::uint32_t address);
+ void adjust_scroll_pos_queue();
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);
+ void keyPressEvent(QKeyEvent *event);
private slots:
- void adjust_scroll_pos();
+ void adjust_scroll_pos_check();
+ void adjust_scroll_pos_process();
private:
void addr0_save_change(std::uint32_t val);
void adjustColumnCount();
QSettings *settings;
std::uint32_t initial_address;
+ bool adjust_scroll_pos_in_progress;
};
#endif // MEMORYTABLEVIEW_H
diff --git a/qtmips_gui/programmodel.cpp b/qtmips_gui/programmodel.cpp
index 76473a8..838c058 100644
--- a/qtmips_gui/programmodel.cpp
+++ b/qtmips_gui/programmodel.cpp
@@ -167,11 +167,7 @@ void ProgramModel::check_for_updates() {
update_all();
}
-bool ProgramModel::adjustRowAndOffset(int &row, int optimal_row, std::uint32_t address) {
- if (optimal_row < rowCount() / 8)
- optimal_row = rowCount() / 8;
- if (optimal_row >= rowCount() - rowCount() / 8)
- optimal_row = rowCount() - rowCount() / 8;
+bool ProgramModel::adjustRowAndOffset(int &row, std::uint32_t address) {
row = rowCount() / 2;
address -= address % cellSizeBytes();
std::uint32_t row_bytes = cellSizeBytes();
diff --git a/qtmips_gui/programmodel.h b/qtmips_gui/programmodel.h
index 9beecef..f5159af 100644
--- a/qtmips_gui/programmodel.h
+++ b/qtmips_gui/programmodel.h
@@ -53,7 +53,7 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex & index, const QVariant & value, int role);
- bool adjustRowAndOffset(int &row, int optimal_row, std::uint32_t address);
+ bool adjustRowAndOffset(int &row, std::uint32_t address);
void update_all();
inline const QFont *getFont() const {
diff --git a/qtmips_gui/programtableview.cpp b/qtmips_gui/programtableview.cpp
index e3114a6..a684692 100644
--- a/qtmips_gui/programtableview.cpp
+++ b/qtmips_gui/programtableview.cpp
@@ -44,9 +44,12 @@
ProgramTableView::ProgramTableView(QWidget *parent, QSettings *settings) : Super(parent) {
connect(verticalScrollBar() , SIGNAL(valueChanged(int)),
- this, SLOT(adjust_scroll_pos()));
+ this, SLOT(adjust_scroll_pos_check()));
+ connect(this , SIGNAL(adjust_scroll_pos_queue()),
+ this, SLOT(adjust_scroll_pos_process()), Qt::QueuedConnection);
this->settings = settings;
initial_address = settings->value("ProgramViewAddr0", 0).toULongLong();
+ adjust_scroll_pos_in_progress = false;
}
void ProgramTableView::addr0_save_change(std::uint32_t val) {
@@ -85,7 +88,15 @@ void ProgramTableView::adjustColumnCount() {
}
}
-void ProgramTableView:: adjust_scroll_pos() {
+void ProgramTableView::adjust_scroll_pos_check() {
+ if (!adjust_scroll_pos_in_progress) {
+ adjust_scroll_pos_in_progress = true;
+ emit adjust_scroll_pos_queue();
+ }
+}
+
+void ProgramTableView::adjust_scroll_pos_process() {
+ adjust_scroll_pos_in_progress = false;
std::uint32_t address;
ProgramModel *m = dynamic_cast<ProgramModel*>(model());
if (m == nullptr)
@@ -100,16 +111,16 @@ void ProgramTableView:: adjust_scroll_pos() {
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->adjustRowAndOffset(row, 0);
+ } else if (index0_offset >= row_bytes) {
m->get_row_address(address, row);
- m->adjustRowAndOffset(row, m->rowCount() / 7, address);
+ m->adjustRowAndOffset(row, 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);
+ m->adjustRowAndOffset(row, address);
} else {
break;
}
@@ -148,7 +159,7 @@ void ProgramTableView:: go_to_address(std::uint32_t address) {
int row;
if (m == nullptr)
return;
- m->adjustRowAndOffset(row, m->rowCount() / 2, address);
+ m->adjustRowAndOffset(row, address);
scrollTo(m->index(row, 0),
QAbstractItemView::PositionAtTop);
setCurrentIndex(m->index(row, 1));
diff --git a/qtmips_gui/programtableview.h b/qtmips_gui/programtableview.h
index 5a67f51..6298d89 100644
--- a/qtmips_gui/programtableview.h
+++ b/qtmips_gui/programtableview.h
@@ -53,19 +53,22 @@ public:
void resizeEvent(QResizeEvent *event) override;
signals:
void address_changed(std::uint32_t address);
+ void adjust_scroll_pos_queue();
public slots:
void go_to_address(std::uint32_t address);
void focus_address(std::uint32_t address);
protected:
- void keyPressEvent(QKeyEvent *event);
+ void keyPressEvent(QKeyEvent *event);
private slots:
- void adjust_scroll_pos();
+ void adjust_scroll_pos_check();
+ void adjust_scroll_pos_process();
private:
void addr0_save_change(std::uint32_t val);
void adjustColumnCount();
QSettings *settings;
std::uint32_t initial_address;
+ bool adjust_scroll_pos_in_progress;
};
#endif // PROGRAMTABLEVIEW_H