cppcheck/gui/libraryeditargdialog.cpp

100 lines
3.8 KiB
C++
Raw Normal View History

#include "libraryeditargdialog.h"
#include "ui_libraryeditargdialog.h"
LibraryEditArgDialog::LibraryEditArgDialog(QWidget *parent, const CppcheckLibraryData::Function::Arg &arg) :
QDialog(parent),
2018-06-18 10:13:33 +02:00
mUi(new Ui::LibraryEditArgDialog),
minsizes(arg.minsizes)
{
2018-06-18 10:13:33 +02:00
mUi->setupUi(this);
mUi->notbool->setChecked(arg.notbool);
mUi->notnull->setChecked(arg.notnull);
mUi->notuninit->setChecked(arg.notuninit);
mUi->strz->setChecked(arg.strz);
mUi->formatstr->setChecked(arg.formatstr);
mUi->valid->setText(arg.valid);
2018-06-18 10:13:33 +02:00
mUi->minsize1type->setEnabled(true);
mUi->minsize1arg->setEnabled(arg.minsizes.count() >= 1);
mUi->minsize1arg2->setEnabled(arg.minsizes.count() >= 1 && arg.minsizes[0].type == "mul");
mUi->minsize2type->setEnabled(arg.minsizes.count() >= 1);
mUi->minsize2arg->setEnabled(arg.minsizes.count() >= 2);
mUi->minsize2arg2->setEnabled(arg.minsizes.count() >= 2 && arg.minsizes[1].type == "mul");
QStringList items;
items << "None" << "argvalue" << "mul" << "sizeof" << "strlen";
2018-06-18 10:13:33 +02:00
mUi->minsize1type->clear();
mUi->minsize1type->addItems(items);
if (arg.minsizes.count() >= 1) {
2018-06-18 10:13:33 +02:00
mUi->minsize1type->setCurrentIndex(items.indexOf(minsizes[0].type));
mUi->minsize1arg->setValue(minsizes[0].arg.toInt());
if (arg.minsizes[0].type == "mul")
2018-06-18 10:13:33 +02:00
mUi->minsize1arg2->setValue(minsizes[0].arg2.toInt());
else
2018-06-18 10:13:33 +02:00
mUi->minsize1arg2->setValue(0);
} else {
2018-06-18 10:13:33 +02:00
mUi->minsize1type->setCurrentIndex(0);
mUi->minsize1arg->setValue(0);
mUi->minsize1arg2->setValue(0);
}
2018-06-18 10:13:33 +02:00
mUi->minsize2type->clear();
mUi->minsize2type->addItems(items);
if (arg.minsizes.count() >= 2) {
2018-06-18 10:13:33 +02:00
mUi->minsize2type->setCurrentIndex(items.indexOf(minsizes[1].type));
mUi->minsize2arg->setValue(minsizes[1].arg.toInt());
if (arg.minsizes[1].type == "mul")
2018-06-18 10:13:33 +02:00
mUi->minsize2arg2->setValue(minsizes[1].arg2.toInt());
else
2018-06-18 10:13:33 +02:00
mUi->minsize2arg2->setValue(0);
} else {
2018-06-18 10:13:33 +02:00
mUi->minsize2type->setCurrentIndex(0);
mUi->minsize2arg->setValue(0);
mUi->minsize2arg2->setValue(0);
}
}
LibraryEditArgDialog::~LibraryEditArgDialog()
{
2018-06-18 10:13:33 +02:00
delete mUi;
}
CppcheckLibraryData::Function::Arg LibraryEditArgDialog::getArg() const
{
CppcheckLibraryData::Function::Arg ret;
2018-06-18 10:13:33 +02:00
ret.notbool = mUi->notbool->isChecked();
ret.notnull = mUi->notnull->isChecked();
ret.notuninit = mUi->notuninit->isChecked();
ret.strz = mUi->strz->isChecked();
ret.formatstr = mUi->formatstr->isChecked();
if (mUi->minsize1type->currentIndex() != 0) {
CppcheckLibraryData::Function::Arg::MinSize minsize1;
2018-06-18 10:13:33 +02:00
minsize1.type = mUi->minsize1type->currentText();
minsize1.arg = QString::number(mUi->minsize1arg->value());
if (minsize1.type == "mul")
2018-06-18 10:13:33 +02:00
minsize1.arg2 = QString::number(mUi->minsize1arg2->value());
ret.minsizes.append(minsize1);
2018-06-18 10:13:33 +02:00
if (mUi->minsize2type->currentIndex() != 0) {
CppcheckLibraryData::Function::Arg::MinSize minsize2;
2018-06-18 10:13:33 +02:00
minsize2.type = mUi->minsize2type->currentText();
minsize2.arg = QString::number(mUi->minsize2arg->value());
if (minsize2.type == "mul")
2018-06-18 10:13:33 +02:00
minsize2.arg2 = QString::number(mUi->minsize2arg2->value());
ret.minsizes.append(minsize2);
}
}
2018-06-18 10:13:33 +02:00
ret.valid = mUi->valid->text();
return ret;
}
void LibraryEditArgDialog::minsizeChanged(int)
{
2018-06-18 10:13:33 +02:00
mUi->minsize1arg->setEnabled(mUi->minsize1type->currentIndex() != 0);
mUi->minsize1arg2->setEnabled(mUi->minsize1type->currentText() == "mul");
mUi->minsize2type->setEnabled(mUi->minsize1type->currentIndex() != 0);
mUi->minsize2arg->setEnabled(mUi->minsize2type->currentIndex() != 0);
mUi->minsize2arg2->setEnabled(mUi->minsize2type->currentText() == "mul");
}