Skip to content

Commit

Permalink
Qt/CodeViewWidget: Make columns resizable by the user and set sensibl…
Browse files Browse the repository at this point in the history
…e defaults.
  • Loading branch information
AdmiralCurtiss committed Mar 15, 2020
1 parent 24a0164 commit 00587e7
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QTableWidgetItem>
#include <QWheelEvent>

#include "Common/GekkoDisassembler.h"
#include "Common/StringUtil.h"
#include "Core/Core.h"
#include "Core/Debugger/PPCDebugInterface.h"
Expand Down Expand Up @@ -140,7 +141,14 @@ CodeViewWidget::CodeViewWidget()
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);

verticalHeader()->hide();
horizontalHeader()->hide();
horizontalHeader()->setSectionResizeMode(CODE_VIEW_COLUMN_BREAKPOINT, QHeaderView::Fixed);
horizontalHeader()->setStretchLastSection(true);
setHorizontalHeaderItem(CODE_VIEW_COLUMN_BREAKPOINT, new QTableWidgetItem());
setHorizontalHeaderItem(CODE_VIEW_COLUMN_ADDRESS, new QTableWidgetItem(tr("Address")));
setHorizontalHeaderItem(CODE_VIEW_COLUMN_INSTRUCTION, new QTableWidgetItem(tr("Instr.")));
setHorizontalHeaderItem(CODE_VIEW_COLUMN_PARAMETERS, new QTableWidgetItem(tr("Parameters")));
setHorizontalHeaderItem(CODE_VIEW_COLUMN_DESCRIPTION, new QTableWidgetItem(tr("Symbols")));
setHorizontalHeaderItem(CODE_VIEW_COLUMN_BRANCH_ARROWS, new QTableWidgetItem(tr("Branches")));

setFont(Settings::Instance().GetDebugFont());
setItemDelegateForColumn(CODE_VIEW_COLUMN_BRANCH_ARROWS, new BranchDisplayDelegate(this));
Expand Down Expand Up @@ -182,6 +190,18 @@ void CodeViewWidget::FontBasedSizing()
verticalHeader()->setMaximumSectionSize(rowh);
horizontalHeader()->setMinimumSectionSize(rowh + 5);
setColumnWidth(CODE_VIEW_COLUMN_BREAKPOINT, rowh + 5);
setColumnWidth(CODE_VIEW_COLUMN_ADDRESS, fm.width(QStringLiteral("80000000")));

// this is the longest diassembled instruction i could find, so use it as a reference for how long
// to make the columns by default
const std::string disas = Common::GekkoDisassembler::Disassemble(0x57ff843fu, 0);
const auto split = disas.find('\t');
const std::string ins = (split == std::string::npos ? disas : disas.substr(0, split));
const std::string param = (split == std::string::npos ? "" : disas.substr(split + 1));
setColumnWidth(CODE_VIEW_COLUMN_INSTRUCTION, fm.width(QString::fromStdString(ins)));
setColumnWidth(CODE_VIEW_COLUMN_PARAMETERS, fm.width(QString::fromStdString(param)));
setColumnWidth(CODE_VIEW_COLUMN_DESCRIPTION, fm.width(QStringLiteral("0")) * 25);

Update();
}

Expand Down Expand Up @@ -322,13 +342,6 @@ void CodeViewWidget::Update()

CalculateBranchIndentation();

u32 max_indent = 0;
for (const CodeViewBranch& branch : m_branches)
max_indent = std::max(max_indent, branch.indentation);

resizeColumnsToContents();
setColumnWidth(CODE_VIEW_COLUMN_BRANCH_ARROWS,
static_cast<int>(WIDTH_PER_BRANCH_ARROW * (max_indent + 1)));
g_symbolDB.FillInCallers();

repaint();
Expand Down

0 comments on commit 00587e7

Please sign in to comment.