-
-
Notifications
You must be signed in to change notification settings - Fork 342
Expand file tree
/
Copy pathExpressionDialog.cpp
More file actions
87 lines (66 loc) · 2.38 KB
/
Copy pathExpressionDialog.cpp
File metadata and controls
87 lines (66 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (C) 2006 - 2025 Evan Teran <evan.teran@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "ExpressionDialog.h"
#include "Expression.h"
#include "ISymbolManager.h"
#include "Symbol.h"
#include "edb.h"
#include <QCompleter>
#include <QPushButton>
ExpressionDialog::ExpressionDialog(const QString &title, const QString &prompt, QWidget *parent, Qt::WindowFlags f)
: QDialog(parent, f) {
setWindowTitle(title);
layout_ = new QVBoxLayout(this);
labelText_ = new QLabel(prompt, this);
labelError_ = new QLabel(this);
expression_ = new QLineEdit(this);
buttonBox_ = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
connect(buttonBox_, &QDialogButtonBox::accepted, this, &ExpressionDialog::accept);
connect(buttonBox_, &QDialogButtonBox::rejected, this, &ExpressionDialog::reject);
layout_->addWidget(labelText_);
layout_->addWidget(expression_);
layout_->addWidget(labelError_);
layout_->addWidget(buttonBox_);
paletteError_.setColor(QPalette::WindowText, Qt::red);
labelError_->setPalette(paletteError_);
buttonBox_->button(QDialogButtonBox::Ok)->setEnabled(false);
setLayout(layout_);
connect(expression_, &QLineEdit::textChanged, this, &ExpressionDialog::on_text_changed);
expression_->selectAll();
std::vector<Symbol> symbols = edb::v1::symbol_manager().symbols();
QStringList allLabels;
for (const Symbol &sym : symbols) {
allLabels.append(sym.name_no_prefix);
}
allLabels.append(edb::v1::symbol_manager().labels().values());
auto completer = new QCompleter(allLabels, this);
expression_->setCompleter(completer);
allLabels.clear();
}
void ExpressionDialog::on_text_changed(const QString &text) {
QHash<edb::address_t, QString> labels = edb::v1::symbol_manager().labels();
edb::address_t resAddr = labels.key(text);
bool retval = false;
if (resAddr) {
lastAddress_ = resAddr;
retval = true;
} else {
Expression<edb::address_t> expr(text, edb::v1::get_variable, edb::v1::get_value);
Result<edb::address_t, ExpressionError> address = expr.evaluate();
if (address) {
labelError_->clear();
retval = true;
lastAddress_ = *address;
} else {
labelError_->setText(address.error().what());
retval = false;
}
}
buttonBox_->button(QDialogButtonBox::Ok)->setEnabled(retval);
}
edb::address_t ExpressionDialog::getAddress() {
return lastAddress_;
}