2022-01-28 15:56:11 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2022-02-05 11:45:17 +01:00
|
|
|
* Copyright (C) 2007-2022 Cppcheck team.
|
2022-01-28 15:56:11 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-08-30 13:35:02 +02:00
|
|
|
#include "libraryeditargdialog.h"
|
2022-02-02 16:17:28 +01:00
|
|
|
|
2015-08-30 13:35:02 +02:00
|
|
|
#include "ui_libraryeditargdialog.h"
|
|
|
|
|
2022-04-13 12:24:00 +02:00
|
|
|
class QWidget;
|
|
|
|
|
2015-08-31 09:04:35 +02:00
|
|
|
LibraryEditArgDialog::LibraryEditArgDialog(QWidget *parent, const CppcheckLibraryData::Function::Arg &arg) :
|
2015-08-30 13:35:02 +02:00
|
|
|
QDialog(parent),
|
2018-06-18 10:13:33 +02:00
|
|
|
mUi(new Ui::LibraryEditArgDialog),
|
2018-06-18 14:15:13 +02:00
|
|
|
mMinSizes(arg.minsizes)
|
2015-08-30 13:35:02 +02:00
|
|
|
{
|
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);
|
2015-09-01 18:13:27 +02:00
|
|
|
|
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");
|
2015-09-01 18:13:27 +02:00
|
|
|
|
|
|
|
QStringList items;
|
2018-01-05 11:10:21 +01:00
|
|
|
items << "None" << "argvalue" << "mul" << "sizeof" << "strlen";
|
2015-09-01 18:13:27 +02:00
|
|
|
|
2018-06-18 10:13:33 +02:00
|
|
|
mUi->minsize1type->clear();
|
|
|
|
mUi->minsize1type->addItems(items);
|
2015-09-01 18:13:27 +02:00
|
|
|
if (arg.minsizes.count() >= 1) {
|
2018-06-18 14:15:13 +02:00
|
|
|
mUi->minsize1type->setCurrentIndex(items.indexOf(mMinSizes[0].type));
|
|
|
|
mUi->minsize1arg->setValue(mMinSizes[0].arg.toInt());
|
2015-09-01 18:13:27 +02:00
|
|
|
if (arg.minsizes[0].type == "mul")
|
2018-06-18 14:15:13 +02:00
|
|
|
mUi->minsize1arg2->setValue(mMinSizes[0].arg2.toInt());
|
2015-09-01 18:13:27 +02:00
|
|
|
else
|
2018-06-18 10:13:33 +02:00
|
|
|
mUi->minsize1arg2->setValue(0);
|
2015-09-01 18:13:27 +02:00
|
|
|
} else {
|
2018-06-18 10:13:33 +02:00
|
|
|
mUi->minsize1type->setCurrentIndex(0);
|
|
|
|
mUi->minsize1arg->setValue(0);
|
|
|
|
mUi->minsize1arg2->setValue(0);
|
2015-09-01 18:13:27 +02:00
|
|
|
}
|
|
|
|
|
2018-06-18 10:13:33 +02:00
|
|
|
mUi->minsize2type->clear();
|
|
|
|
mUi->minsize2type->addItems(items);
|
2015-09-01 18:13:27 +02:00
|
|
|
if (arg.minsizes.count() >= 2) {
|
2018-06-18 14:15:13 +02:00
|
|
|
mUi->minsize2type->setCurrentIndex(items.indexOf(mMinSizes[1].type));
|
|
|
|
mUi->minsize2arg->setValue(mMinSizes[1].arg.toInt());
|
2015-09-01 18:13:27 +02:00
|
|
|
if (arg.minsizes[1].type == "mul")
|
2018-06-18 14:15:13 +02:00
|
|
|
mUi->minsize2arg2->setValue(mMinSizes[1].arg2.toInt());
|
2015-08-31 09:04:35 +02:00
|
|
|
else
|
2018-06-18 10:13:33 +02:00
|
|
|
mUi->minsize2arg2->setValue(0);
|
2015-09-01 18:13:27 +02:00
|
|
|
} else {
|
2018-06-18 10:13:33 +02:00
|
|
|
mUi->minsize2type->setCurrentIndex(0);
|
|
|
|
mUi->minsize2arg->setValue(0);
|
|
|
|
mUi->minsize2arg2->setValue(0);
|
2015-08-31 09:04:35 +02:00
|
|
|
}
|
2015-08-30 13:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LibraryEditArgDialog::~LibraryEditArgDialog()
|
|
|
|
{
|
2018-06-18 10:13:33 +02:00
|
|
|
delete mUi;
|
2015-08-30 13:35:02 +02:00
|
|
|
}
|
|
|
|
|
2015-08-30 13:41:57 +02:00
|
|
|
CppcheckLibraryData::Function::Arg LibraryEditArgDialog::getArg() const
|
2015-08-30 13:35:02 +02:00
|
|
|
{
|
2015-08-30 13:41:57 +02:00
|
|
|
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) {
|
2015-09-01 18:13:27 +02:00
|
|
|
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());
|
2015-09-01 18:13:27 +02:00
|
|
|
if (minsize1.type == "mul")
|
2018-06-18 10:13:33 +02:00
|
|
|
minsize1.arg2 = QString::number(mUi->minsize1arg2->value());
|
2015-09-01 18:13:27 +02:00
|
|
|
ret.minsizes.append(minsize1);
|
|
|
|
|
2018-06-18 10:13:33 +02:00
|
|
|
if (mUi->minsize2type->currentIndex() != 0) {
|
2015-09-01 18:13:27 +02:00
|
|
|
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());
|
2015-09-01 18:13:27 +02:00
|
|
|
if (minsize2.type == "mul")
|
2018-06-18 10:13:33 +02:00
|
|
|
minsize2.arg2 = QString::number(mUi->minsize2arg2->value());
|
2015-09-01 18:13:27 +02:00
|
|
|
ret.minsizes.append(minsize2);
|
|
|
|
}
|
|
|
|
}
|
2018-06-18 10:13:33 +02:00
|
|
|
ret.valid = mUi->valid->text();
|
2015-08-30 13:35:02 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2015-09-01 18:13:27 +02:00
|
|
|
|
2022-09-27 20:03:25 +02:00
|
|
|
void LibraryEditArgDialog::minsizeChanged()
|
2015-09-01 18:13:27 +02:00
|
|
|
{
|
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");
|
2015-09-01 18:13:27 +02:00
|
|
|
}
|