Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[more convenient] On 'Main memory' window, provides the input completion. #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mb3h
Copy link

@mb3h mb3h commented Feb 3, 2025

[How to patch]
(1) Appending the signal flow.
   DebuggerForm::systemSymbolManager(),
   | symbolsChanged
+ MainMemoryViewer::updateCompleter(),
   DisasmViewer::refresh()
(2) In the following, appending a bit of codes.
   MainMemoryViewer::updateCompleter()

--- old/DebuggerForm.cpp	2023-06-06 20:37:52.000000000 -0300
+++ src/DebuggerForm.cpp	2025-01-16 00:00:00.000000000 +0000
@@ -687,6 +687,7 @@
 	// Main memory viewer
 	connect(this, &DebuggerForm::connected, mainMemoryView, &MainMemoryViewer::refresh);
 	connect(this, &DebuggerForm::breakStateEntered, mainMemoryView, &MainMemoryViewer::refresh);
+	connect(this, &DebuggerForm::symbolsChanged, mainMemoryView, &MainMemoryViewer::updateCompleter);
 
 	// Slot viewer
 	connect(this, &DebuggerForm::connected, slotView, &SlotViewer::refresh);
@@ -718,6 +719,7 @@
 	disasmView->setMemoryLayout(&memLayout);
 	disasmView->setSymbolTable(&session.symbolTable());
 	mainMemoryView->setRegsView(regsView);
+	mainMemoryView->setMemoryLayout(&memLayout);
 	mainMemoryView->setSymbolTable(&session.symbolTable());
 	mainMemoryView->setDebuggable("memory", 0x10000);
 	stackView->setData(mainMemory, 0x10000);
--- old/MainMemoryViewer.cpp	2022-05-14 20:53:15.000000000 +0200
+++ src/MainMemoryViewer.cpp	2025-01-16 00:00:00.000000000 +0000
@@ -9,6 +9,8 @@
 #include <QHBoxLayout>
 #include <QLineEdit>
 #include <iostream>
+#include <cassert>
+#include <QCompleter>
 
 static const int linkRegisters[] = {
 	CpuRegs::REG_BC, CpuRegs::REG_DE, CpuRegs::REG_HL,
@@ -54,11 +56,15 @@
 	linkedId = 0;
 	regsViewer = nullptr;
 	symTable = nullptr;
+	memLayout = nullptr;
+	completer = nullptr;
 
 	connect(hexView, &HexViewer::locationChanged,
 	        this, &MainMemoryViewer::hexViewChanged);
 	connect(addressValue, &QLineEdit::returnPressed,
 	        this, &MainMemoryViewer::addressValueChanged);
+	connect(addressValue, &QLineEdit::textEdited,
+	        this, &MainMemoryViewer::addressValueChanging);
 	connect(addressSourceList, qOverload<int>(&QComboBox::currentIndexChanged),
 	        this, &MainMemoryViewer::addressSourceListChanged);
 }
@@ -99,6 +105,32 @@
 	addressValue->setText(hexValue(addr, 4));
 }
 
+void MainMemoryViewer::setMemoryLayout(MemoryLayout* ml)
+{
+	memLayout = ml;
+}
+
+void MainMemoryViewer::updateCompleter()
+{
+	assert(symTable);
+	assert(memLayout);
+	// release the previous
+	if (completer) {
+		addressValue->setCompleter(nullptr);
+		//delete completer; // PENDING: done in setCompleter() above? (not obvious in document)
+		completer = nullptr; // safety
+	}
+	// create address completer
+	completer = new QCompleter(symTable->labelList(true, memLayout), this);
+	completer->setCaseSensitivity(Qt::CaseInsensitive);
+	addressValue->setCompleter(completer);
+}
+
+void MainMemoryViewer::addressValueChanging()
+{
+	// PENDING: Needing the color, someone will implement.
+}
+
 void MainMemoryViewer::addressValueChanged()
 {
 	auto addr = stringToValue<uint16_t>(addressValue->text());
--- old/MainMemoryViewer.h	2022-05-14 22:43:40.000000000 +0200
+++ src/MainMemoryViewer.h	2025-01-16 00:00:00.000000000 +0000
@@ -8,6 +8,8 @@
 class SymbolTable;
 class QComboBox;
 class QLineEdit;
+class QCompleter;
+struct MemoryLayout;
 
 class MainMemoryViewer : public QWidget
 {
@@ -18,6 +20,7 @@
 	void setDebuggable(const QString& name, int size);
 	void setRegsView(CPURegsViewer* viewer);
 	void setSymbolTable(SymbolTable* symtable);
+	void setMemoryLayout(MemoryLayout* ml);
 
 	void setLocation(int addr);
 	void settingsChanged();
@@ -25,6 +28,8 @@
 	void registerChanged(int id, int value);
 
 	void hexViewChanged(int addr);
+	void updateCompleter();
+	void addressValueChanging();
 	void addressValueChanged();
 	void addressSourceListChanged(int index);
 
@@ -32,9 +37,11 @@
 	HexViewer* hexView;
 	QComboBox* addressSourceList;
 	QLineEdit* addressValue;
+	QCompleter* completer;
 
 	CPURegsViewer* regsViewer;
 	SymbolTable* symTable;
+	MemoryLayout* memLayout;
 	int linkedId;
 	bool isLinked;
 };

[Related flow]

- DebuggerForm::createForm()
  | .session
  - DebugSession::symbolTable()
    | (SymbolTable)
  - MainMemoryViewer::setSymbolTable()
  | .memLayout (MemoryLayout)
  - SlotViewer::setMemoryLayout()

- DebuggerForm::searchGoto()
  | .memLayout, .session
  - GotoDialog::ctor()
    | session
    - DebugSession::symbolTable()
    | (SymbolTable), ml
    - SymbolTable::labelList()
      | (QStringList)
    - QCompleter()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant