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

View File

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

View File

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

View File

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