aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/memorytableview.cpp
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-03-15 00:56:41 +0100
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-03-15 00:56:41 +0100
commit227683b0116dce54502b081b8932781a20fe437a (patch)
tree5d57bca95867f822af675d9557675e0abcc3145c /qtmips_gui/memorytableview.cpp
parent36747de2c73d3c11e30abd7b371cc5a5cf91a331 (diff)
downloadqtmips-227683b0116dce54502b081b8932781a20fe437a.tar.gz
qtmips-227683b0116dce54502b081b8932781a20fe437a.tar.bz2
qtmips-227683b0116dce54502b081b8932781a20fe437a.zip
More precise program and memory tableviews column width calculation.
This should resolve text elide problem experienced on some combination of desktop/fonts setting. Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_gui/memorytableview.cpp')
-rw-r--r--qtmips_gui/memorytableview.cpp40
1 files changed, 28 insertions, 12 deletions
diff --git a/qtmips_gui/memorytableview.cpp b/qtmips_gui/memorytableview.cpp
index 74729c5..0ff6bfb 100644
--- a/qtmips_gui/memorytableview.cpp
+++ b/qtmips_gui/memorytableview.cpp
@@ -41,8 +41,10 @@
#include <QApplication>
#include "memorytableview.h"
#include "memorymodel.h"
+#include "hinttabledelegate.h"
MemoryTableView::MemoryTableView(QWidget *parent, QSettings *settings) : Super(parent) {
+ setItemDelegate(new HintTableDelegate);
connect(verticalScrollBar() , SIGNAL(valueChanged(int)),
this, SLOT(adjust_scroll_pos_check()));
connect(this , SIGNAL(adjust_scroll_pos_queue()),
@@ -58,31 +60,41 @@ void MemoryTableView::addr0_save_change(std::uint32_t val) {
void MemoryTableView::adjustColumnCount() {
MemoryModel *m = dynamic_cast<MemoryModel*>(model());
+ if (m == nullptr)
+ return;
+
+ HintTableDelegate *delegate = dynamic_cast<HintTableDelegate*>(itemDelegate());
+ if (delegate == nullptr)
+ return;
- if (horizontalHeader()->count() >= 2 && m != nullptr) {
+ if (horizontalHeader()->count() >= 2) {
+ QModelIndex idx;
QFontMetrics fm(*m->getFont());
- int width0 = fm.width("0x00000000");
+ idx = m->index(0, 0);
+ // int width0_dh = itemDelegate(idx)->sizeHint(viewOptions(), idx).width() + 2;
+ int width0_dh = delegate->sizeHintForText(viewOptions(), idx,
+ "0x00000000").width() + 2;
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
- horizontalHeader()->resizeSection(0, width0);
+ horizontalHeader()->resizeSection(0, width0_dh);
+ idx = m->index(0, 1);
QString t = "";
t.fill(QChar('0'), m->cellSizeBytes() * 2);
- /* t + = " C"; */
- int width1 = fm.width(t);
- if (width1 < fm.width("+99"))
- width1 = fm.width("+99");
+ int width1_dh = delegate->sizeHintForText(viewOptions(), idx, t).width() + 2;
+ if (width1_dh < fm.width("+99"))
+ width1_dh = fm.width("+99");
horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
- horizontalHeader()->resizeSection(1, width1);
+ horizontalHeader()->resizeSection(1, width1_dh);
int w = verticalHeader()->width() + 4;
unsigned int cells;
- width0 = columnWidth(0);
- width1 = columnWidth(1);
+ int width0 = columnWidth(0);
+ int width1 = columnWidth(1);
w = width() - w - width0;
- if (w < width1 + 2) {
+ if (w < width1 + 4) {
cells = 1;
} else {
- cells = w / (width1 + 2);
+ cells = w / (width1 + 4);
}
if (cells != m->cellsPerRow()) {
m->setCellsPerRow(cells);
@@ -98,6 +110,10 @@ void MemoryTableView::adjustColumnCount() {
}
}
+void MemoryTableView::recompute_columns() {
+ adjustColumnCount();
+}
+
void MemoryTableView::set_cell_size(int index) {
std::uint32_t address;
int row;