GUI: threaded calls to DbgIsValidExpression in Calculator/Goto/WordEdit dialog (provides a more comfortable interface)
This commit is contained in:
parent
0d3a2f192d
commit
3e391bd86b
|
@ -7,13 +7,13 @@ CalculatorDialog::CalculatorDialog(QWidget* parent) : QDialog(parent), ui(new Ui
|
|||
ui->setupUi(this);
|
||||
setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
|
||||
setFixedSize(this->size()); //fixed size
|
||||
connect(ui->txtExpression, SIGNAL(textChanged(QString)), this, SLOT(answerExpression(QString)));
|
||||
connect(this, SIGNAL(validAddress(bool)), ui->btnGoto, SLOT(setEnabled(bool)));
|
||||
emit validAddress(false);
|
||||
ui->txtBin->setInputMask(QString("bbbb ").repeated(sizeof(uint_t) * 2));
|
||||
ui->txtExpression->setText("0");
|
||||
ui->txtExpression->selectAll();
|
||||
ui->txtExpression->setFocus();
|
||||
mValidateThread = new CalculatorDialogValidateThread(this);
|
||||
}
|
||||
|
||||
CalculatorDialog::~CalculatorDialog()
|
||||
|
@ -21,21 +21,30 @@ CalculatorDialog::~CalculatorDialog()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void CalculatorDialog::showEvent(QShowEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
mValidateThread->start();
|
||||
}
|
||||
|
||||
void CalculatorDialog::hideEvent(QHideEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
mValidateThread->terminate();
|
||||
}
|
||||
|
||||
void CalculatorDialog::setExpressionFocus()
|
||||
{
|
||||
ui->txtExpression->selectAll();
|
||||
ui->txtExpression->setFocus();
|
||||
}
|
||||
|
||||
void CalculatorDialog::answerExpression(QString expression)
|
||||
void CalculatorDialog::validateExpression()
|
||||
{
|
||||
ui->txtHex->setStyleSheet("");
|
||||
ui->txtSignedDec->setStyleSheet("");
|
||||
ui->txtUnsignedDec->setStyleSheet("");
|
||||
ui->txtOct->setStyleSheet("");
|
||||
ui->txtBin->setStyleSheet("");
|
||||
ui->txtAscii->setStyleSheet("");
|
||||
ui->txtUnicode->setStyleSheet("");
|
||||
QString expression = ui->txtExpression->text();
|
||||
if(expressionText == expression)
|
||||
return;
|
||||
expressionText = expression;
|
||||
if(!DbgIsValidExpression(expression.toUtf8().constData()))
|
||||
{
|
||||
ui->txtBin->setText("");
|
||||
|
@ -46,6 +55,7 @@ void CalculatorDialog::answerExpression(QString expression)
|
|||
ui->txtAscii->setText("");
|
||||
ui->txtUnicode->setText("");
|
||||
ui->txtExpression->setStyleSheet("border: 2px solid red");
|
||||
emit validAddress(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -86,6 +96,18 @@ void CalculatorDialog::answerExpression(QString expression)
|
|||
}
|
||||
}
|
||||
|
||||
void CalculatorDialog::on_txtExpression_textChanged(const QString & arg1)
|
||||
{
|
||||
ui->txtHex->setStyleSheet("");
|
||||
ui->txtSignedDec->setStyleSheet("");
|
||||
ui->txtUnsignedDec->setStyleSheet("");
|
||||
ui->txtOct->setStyleSheet("");
|
||||
ui->txtBin->setStyleSheet("");
|
||||
ui->txtAscii->setStyleSheet("");
|
||||
ui->txtUnicode->setStyleSheet("");
|
||||
emit validAddress(false);
|
||||
}
|
||||
|
||||
QString CalculatorDialog::inFormat(const uint_t val, CalculatorDialog::NUMBERFORMAT NF) const
|
||||
{
|
||||
switch(NF)
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
#define CALCULATORDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QThread>
|
||||
#include "Bridge.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class CalculatorDialog;
|
||||
|
@ -27,14 +29,14 @@ public:
|
|||
explicit CalculatorDialog(QWidget* parent = 0);
|
||||
~CalculatorDialog();
|
||||
void setExpressionFocus();
|
||||
void validateExpression();
|
||||
void showEvent(QShowEvent* event);
|
||||
void hideEvent(QHideEvent* event);
|
||||
|
||||
signals:
|
||||
bool validAddress(bool valid);
|
||||
void showCpu();
|
||||
|
||||
public slots:
|
||||
void answerExpression(QString expression);
|
||||
|
||||
private slots:
|
||||
void on_btnGoto_clicked();
|
||||
void on_txtHex_textEdited(const QString & arg1);
|
||||
|
@ -44,10 +46,35 @@ private slots:
|
|||
void on_txtBin_textEdited(const QString & arg1);
|
||||
void on_txtAscii_textEdited(const QString & arg1);
|
||||
void on_txtUnicode_textEdited(const QString & arg1);
|
||||
void on_txtExpression_textChanged(const QString & arg1);
|
||||
|
||||
private:
|
||||
QString expressionText;
|
||||
QThread* mValidateThread;
|
||||
Ui::CalculatorDialog* ui;
|
||||
QString inFormat(const uint_t val, CalculatorDialog::NUMBERFORMAT NF) const;
|
||||
};
|
||||
|
||||
class CalculatorDialogValidateThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CalculatorDialogValidateThread(CalculatorDialog* calculatorDialog)
|
||||
{
|
||||
mCalculatorDialog = calculatorDialog;
|
||||
}
|
||||
|
||||
private:
|
||||
CalculatorDialog* mCalculatorDialog;
|
||||
|
||||
void run()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
mCalculatorDialog->validateExpression();
|
||||
Sleep(50);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CALCULATORDIALOG_H
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
#include "GotoDialog.h"
|
||||
#include "ui_GotoDialog.h"
|
||||
|
||||
GotoDialog::GotoDialog(QWidget* parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::GotoDialog)
|
||||
GotoDialog::GotoDialog(QWidget* parent) : QDialog(parent), ui(new Ui::GotoDialog)
|
||||
{
|
||||
//setup UI first
|
||||
ui->setupUi(this);
|
||||
|
@ -19,6 +17,7 @@ GotoDialog::GotoDialog(QWidget* parent) :
|
|||
ui->editExpression->setFocus();
|
||||
validRangeStart = 0;
|
||||
validRangeEnd = 0;
|
||||
mValidateThread = new GotoDialogValidateThread(this);
|
||||
connect(this, SIGNAL(finished(int)), this, SLOT(finishedSlot(int)));
|
||||
}
|
||||
|
||||
|
@ -27,15 +26,30 @@ GotoDialog::~GotoDialog()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void GotoDialog::on_editExpression_textChanged(const QString & arg1)
|
||||
void GotoDialog::showEvent(QShowEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
mValidateThread->start();
|
||||
}
|
||||
|
||||
void GotoDialog::hideEvent(QHideEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
mValidateThread->terminate();
|
||||
}
|
||||
|
||||
void GotoDialog::validateExpression()
|
||||
{
|
||||
QString expression = ui->editExpression->text();
|
||||
if(expressionText == expression)
|
||||
return;
|
||||
if(!DbgIsDebugging()) //not debugging
|
||||
{
|
||||
ui->labelError->setText("<font color='red'><b>Not debugging...</b></font>");
|
||||
ui->buttonOk->setEnabled(false);
|
||||
expressionText.clear();
|
||||
}
|
||||
else if(!DbgIsValidExpression(arg1.toUtf8().constData())) //invalid expression
|
||||
else if(!DbgIsValidExpression(expression.toUtf8().constData())) //invalid expression
|
||||
{
|
||||
ui->labelError->setText("<font color='red'><b>Invalid expression...</b></font>");
|
||||
ui->buttonOk->setEnabled(false);
|
||||
|
@ -43,7 +57,7 @@ void GotoDialog::on_editExpression_textChanged(const QString & arg1)
|
|||
}
|
||||
else
|
||||
{
|
||||
uint_t addr = DbgValFromString(arg1.toUtf8().constData());
|
||||
uint_t addr = DbgValFromString(expression.toUtf8().constData());
|
||||
if(!DbgMemIsValidReadPtr(addr))
|
||||
{
|
||||
ui->labelError->setText("<font color='red'><b>Invalid memory address...</b></font>");
|
||||
|
@ -74,11 +88,16 @@ void GotoDialog::on_editExpression_textChanged(const QString & arg1)
|
|||
addrText = QString("%1").arg(addr, sizeof(int_t) * 2, 16, QChar('0')).toUpper();
|
||||
ui->labelError->setText(QString("<font color='#00DD00'><b>Correct expression! -> </b></font>" + addrText));
|
||||
ui->buttonOk->setEnabled(true);
|
||||
expressionText = arg1;
|
||||
expressionText = expression;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GotoDialog::on_editExpression_textChanged(const QString & arg1)
|
||||
{
|
||||
ui->buttonOk->setEnabled(false);
|
||||
}
|
||||
|
||||
bool GotoDialog::IsValidMemoryRange(uint_t addr)
|
||||
{
|
||||
return ((!validRangeStart && !validRangeEnd) || (addr >= validRangeStart && addr < validRangeEnd));
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QDialog>
|
||||
#include <QPalette>
|
||||
#include <QThread>
|
||||
#include "Bridge.h"
|
||||
|
||||
namespace Ui
|
||||
|
@ -20,6 +21,9 @@ public:
|
|||
QString expressionText;
|
||||
uint_t validRangeStart;
|
||||
uint_t validRangeEnd;
|
||||
void showEvent(QShowEvent* event);
|
||||
void hideEvent(QHideEvent* event);
|
||||
void validateExpression();
|
||||
|
||||
private slots:
|
||||
void on_editExpression_textChanged(const QString & arg1);
|
||||
|
@ -28,7 +32,30 @@ private slots:
|
|||
|
||||
private:
|
||||
Ui::GotoDialog* ui;
|
||||
QThread* mValidateThread;
|
||||
bool IsValidMemoryRange(uint_t addr);
|
||||
};
|
||||
|
||||
class GotoDialogValidateThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GotoDialogValidateThread(GotoDialog* gotoDialog)
|
||||
{
|
||||
mGotoDialog = gotoDialog;
|
||||
}
|
||||
|
||||
private:
|
||||
GotoDialog* mGotoDialog;
|
||||
|
||||
void run()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
mGotoDialog->validateExpression();
|
||||
Sleep(50);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // GOTODIALOG_H
|
||||
|
|
|
@ -8,6 +8,8 @@ WordEditDialog::WordEditDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Wo
|
|||
setModal(true);
|
||||
setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
|
||||
|
||||
mValidateThread = new WordEditDialogValidateThread(this);
|
||||
|
||||
mWord = 0;
|
||||
}
|
||||
|
||||
|
@ -16,6 +18,18 @@ WordEditDialog::~WordEditDialog()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void WordEditDialog::showEvent(QShowEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
mValidateThread->start();
|
||||
}
|
||||
|
||||
void WordEditDialog::hideEvent(QHideEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
mValidateThread->terminate();
|
||||
}
|
||||
|
||||
void WordEditDialog::setup(QString title, uint_t defVal, int byteCount)
|
||||
{
|
||||
this->setWindowTitle(title);
|
||||
|
@ -31,9 +45,13 @@ uint_t WordEditDialog::getVal()
|
|||
return mWord;
|
||||
}
|
||||
|
||||
void WordEditDialog::on_expressionLineEdit_textChanged(const QString & arg1)
|
||||
void WordEditDialog::validateExpression()
|
||||
{
|
||||
if(DbgIsValidExpression(arg1.toUtf8().constData()))
|
||||
QString expression = ui->expressionLineEdit->text();
|
||||
if(expressionText == expression)
|
||||
return;
|
||||
expressionText = expression;
|
||||
if(DbgIsValidExpression(expression.toUtf8().constData()))
|
||||
{
|
||||
ui->expressionLineEdit->setStyleSheet("");
|
||||
ui->unsignedLineEdit->setStyleSheet("");
|
||||
|
@ -41,7 +59,7 @@ void WordEditDialog::on_expressionLineEdit_textChanged(const QString & arg1)
|
|||
ui->buttons->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
|
||||
//hex
|
||||
mWord = DbgValFromString(arg1.toUtf8().constData());
|
||||
mWord = DbgValFromString(expression.toUtf8().constData());
|
||||
uint_t hexWord = 0;
|
||||
unsigned char* hex = (unsigned char*)&hexWord;
|
||||
unsigned char* word = (unsigned char*)&mWord;
|
||||
|
@ -73,6 +91,11 @@ void WordEditDialog::on_expressionLineEdit_textChanged(const QString & arg1)
|
|||
}
|
||||
}
|
||||
|
||||
void WordEditDialog::on_expressionLineEdit_textChanged(const QString & arg1)
|
||||
{
|
||||
ui->buttons->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
}
|
||||
|
||||
void WordEditDialog::on_signedLineEdit_textEdited(const QString & arg1)
|
||||
{
|
||||
LONGLONG value;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QtGui>
|
||||
#include <QDialog>
|
||||
#include <QThread>
|
||||
#include <QPushButton>
|
||||
#include "Bridge.h"
|
||||
|
||||
|
@ -20,6 +21,9 @@ public:
|
|||
~WordEditDialog();
|
||||
void setup(QString title, uint_t defVal, int byteCount);
|
||||
uint_t getVal();
|
||||
void showEvent(QShowEvent* event);
|
||||
void hideEvent(QHideEvent* event);
|
||||
void validateExpression();
|
||||
|
||||
private slots:
|
||||
void on_expressionLineEdit_textChanged(const QString & arg1);
|
||||
|
@ -29,6 +33,30 @@ private slots:
|
|||
private:
|
||||
Ui::WordEditDialog* ui;
|
||||
uint_t mWord;
|
||||
QString expressionText;
|
||||
QThread* mValidateThread;
|
||||
};
|
||||
|
||||
class WordEditDialogValidateThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
WordEditDialogValidateThread(WordEditDialog* wordEditDialog)
|
||||
{
|
||||
mWordEditDialog = wordEditDialog;
|
||||
}
|
||||
|
||||
private:
|
||||
WordEditDialog* mWordEditDialog;
|
||||
|
||||
void run()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
mWordEditDialog->validateExpression();
|
||||
Sleep(50);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // WORDEDITDIALOG_H
|
||||
|
|
Loading…
Reference in New Issue