Finish EditMethodDialog

This commit is contained in:
Florian Märkl 2019-02-02 11:59:58 +01:00
parent 7bdc28d07d
commit 1864e7b95d
4 changed files with 42 additions and 23 deletions

View File

@ -1,16 +1,22 @@
#include "EditMethodDialog.h" #include "EditMethodDialog.h"
#include "ui_EditMethodDialog.h" #include "ui_EditMethodDialog.h"
EditMethodDialog::EditMethodDialog(QWidget *parent) : EditMethodDialog::EditMethodDialog(bool classFixed, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::EditMethodDialog) ui(new Ui::EditMethodDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
ui->classComboBox->clear(); if (classFixed) {
classLabel = new QLabel(this);
ui->formLayout->setItem(0, QFormLayout::FieldRole, new QWidgetItem(classLabel));
} else {
classComboBox = new QComboBox(this);
ui->formLayout->setItem(0, QFormLayout::FieldRole, new QWidgetItem(classComboBox));
for (auto &cls : Core()->getAllAnalClasses()) { for (auto &cls : Core()->getAllAnalClasses()) {
ui->classComboBox->addItem(cls, cls); classComboBox->addItem(cls, cls);
}
} }
updateVirtualUI(); updateVirtualUI();
@ -58,18 +64,23 @@ bool EditMethodDialog::inputValid()
void EditMethodDialog::setClass(const QString &className) void EditMethodDialog::setClass(const QString &className)
{ {
if (classComboBox) {
if (className.isEmpty()) { if (className.isEmpty()) {
ui->classComboBox->setCurrentIndex(0); classComboBox->setCurrentIndex(0);
return; return;
} }
for (int i=0; i<ui->classComboBox->count(); i++) { for (int i=0; i<classComboBox->count(); i++) {
QString cls = ui->classComboBox->itemData(i).toString(); QString cls = classComboBox->itemData(i).toString();
if (cls == className) { if (cls == className) {
ui->classComboBox->setCurrentIndex(i); classComboBox->setCurrentIndex(i);
break; break;
} }
} }
} else {
classLabel->setText(className);
fixedClass = className;
}
validateInput(); validateInput();
} }
@ -93,11 +104,15 @@ void EditMethodDialog::setMethod(const AnalMethodDescription &desc)
QString EditMethodDialog::getClass() QString EditMethodDialog::getClass()
{ {
int index = ui->classComboBox->currentIndex(); if (classComboBox) {
int index = classComboBox->currentIndex();
if (index < 0) { if (index < 0) {
return nullptr; return nullptr;
} }
return ui->classComboBox->itemData(index).value<BinClassDescription>().name; return classComboBox->itemData(index).toString();
} else {
return fixedClass;
}
} }
AnalMethodDescription EditMethodDialog::getMethod() AnalMethodDescription EditMethodDialog::getMethod()
@ -105,7 +120,7 @@ AnalMethodDescription EditMethodDialog::getMethod()
AnalMethodDescription ret; AnalMethodDescription ret;
ret.name = ui->nameEdit->text(); ret.name = ui->nameEdit->text();
ret.addr = Core()->num(ui->addressEdit->text()); ret.addr = Core()->num(ui->addressEdit->text());
if (ui->virtualCheckBox->isChecked()) { if (!ui->virtualCheckBox->isChecked()) {
ret.vtableOffset = -1; ret.vtableOffset = -1;
} else { } else {
ret.vtableOffset = Core()->num(ui->vtableOffsetEdit->text()); ret.vtableOffset = Core()->num(ui->vtableOffsetEdit->text());

View File

@ -2,6 +2,8 @@
#define EDITMETHODDIALOG_H #define EDITMETHODDIALOG_H
#include <QDialog> #include <QDialog>
#include <QComboBox>
#include <memory> #include <memory>
#include "Cutter.h" #include "Cutter.h"
@ -15,7 +17,7 @@ class EditMethodDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit EditMethodDialog(QWidget *parent = nullptr); explicit EditMethodDialog(bool classFixed, QWidget *parent = nullptr);
~EditMethodDialog(); ~EditMethodDialog();
void setClass(const QString &className); void setClass(const QString &className);
@ -38,6 +40,10 @@ private slots:
private: private:
std::unique_ptr<Ui::EditMethodDialog> ui; std::unique_ptr<Ui::EditMethodDialog> ui;
QComboBox *classComboBox = nullptr;
QLabel *classLabel = nullptr;
QString fixedClass;
bool inputValid(); bool inputValid();
}; };

View File

@ -26,9 +26,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QComboBox" name="classComboBox"/>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="nameLabel"> <widget class="QLabel" name="nameLabel">
<property name="text"> <property name="text">

View File

@ -224,6 +224,7 @@ AnalClassesModel::AnalClassesModel(QObject *parent)
void AnalClassesModel::refreshClasses() void AnalClassesModel::refreshClasses()
{ {
beginResetModel(); beginResetModel();
attrs->clear();
classes = Core()->getAllAnalClasses(); classes = Core()->getAllAnalClasses();
endResetModel(); endResetModel();
} }