Cppcheck
libraryeditargdialog.cpp
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2023 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "libraryeditargdialog.h"
20 
21 #include "ui_libraryeditargdialog.h"
22 
23 #include <QCheckBox>
24 #include <QComboBox>
25 #include <QLineEdit>
26 #include <QSpinBox>
27 #include <QStringList>
28 
29 class QWidget;
30 
32  QDialog(parent),
33  mUi(new Ui::LibraryEditArgDialog),
34  mMinSizes(arg.minsizes)
35 {
36  mUi->setupUi(this);
37  mUi->notbool->setChecked(arg.notbool);
38  mUi->notnull->setChecked(arg.notnull);
39  mUi->notuninit->setChecked(arg.notuninit);
40  mUi->strz->setChecked(arg.strz);
41  mUi->formatstr->setChecked(arg.formatstr);
42  mUi->valid->setText(arg.valid);
43 
44  mUi->minsize1type->setEnabled(true);
45  mUi->minsize1arg->setEnabled(arg.minsizes.count() >= 1);
46  mUi->minsize1arg2->setEnabled(arg.minsizes.count() >= 1 && arg.minsizes[0].type == "mul");
47  mUi->minsize2type->setEnabled(arg.minsizes.count() >= 1);
48  mUi->minsize2arg->setEnabled(arg.minsizes.count() >= 2);
49  mUi->minsize2arg2->setEnabled(arg.minsizes.count() >= 2 && arg.minsizes[1].type == "mul");
50 
51  QStringList items;
52  items << "None" << "argvalue" << "mul" << "sizeof" << "strlen";
53 
54  mUi->minsize1type->clear();
55  mUi->minsize1type->addItems(items);
56  if (arg.minsizes.count() >= 1) {
57  mUi->minsize1type->setCurrentIndex(items.indexOf(mMinSizes[0].type));
58  mUi->minsize1arg->setValue(mMinSizes[0].arg.toInt());
59  if (arg.minsizes[0].type == "mul")
60  mUi->minsize1arg2->setValue(mMinSizes[0].arg2.toInt());
61  else
62  mUi->minsize1arg2->setValue(0);
63  } else {
64  mUi->minsize1type->setCurrentIndex(0);
65  mUi->minsize1arg->setValue(0);
66  mUi->minsize1arg2->setValue(0);
67  }
68 
69  mUi->minsize2type->clear();
70  mUi->minsize2type->addItems(items);
71  if (arg.minsizes.count() >= 2) {
72  mUi->minsize2type->setCurrentIndex(items.indexOf(mMinSizes[1].type));
73  mUi->minsize2arg->setValue(mMinSizes[1].arg.toInt());
74  if (arg.minsizes[1].type == "mul")
75  mUi->minsize2arg2->setValue(mMinSizes[1].arg2.toInt());
76  else
77  mUi->minsize2arg2->setValue(0);
78  } else {
79  mUi->minsize2type->setCurrentIndex(0);
80  mUi->minsize2arg->setValue(0);
81  mUi->minsize2arg2->setValue(0);
82  }
83 }
84 
86 {
87  delete mUi;
88 }
89 
91 {
93  ret.notbool = mUi->notbool->isChecked();
94  ret.notnull = mUi->notnull->isChecked();
95  ret.notuninit = mUi->notuninit->isChecked();
96  ret.strz = mUi->strz->isChecked();
97  ret.formatstr = mUi->formatstr->isChecked();
98  if (mUi->minsize1type->currentIndex() != 0) {
100  minsize1.type = mUi->minsize1type->currentText();
101  minsize1.arg = QString::number(mUi->minsize1arg->value());
102  if (minsize1.type == "mul")
103  minsize1.arg2 = QString::number(mUi->minsize1arg2->value());
104  ret.minsizes.append(minsize1);
105 
106  if (mUi->minsize2type->currentIndex() != 0) {
108  minsize2.type = mUi->minsize2type->currentText();
109  minsize2.arg = QString::number(mUi->minsize2arg->value());
110  if (minsize2.type == "mul")
111  minsize2.arg2 = QString::number(mUi->minsize2arg2->value());
112  ret.minsizes.append(minsize2);
113  }
114  }
115  ret.valid = mUi->valid->text();
116  return ret;
117 }
118 
120 {
121  mUi->minsize1arg->setEnabled(mUi->minsize1type->currentIndex() != 0);
122  mUi->minsize1arg2->setEnabled(mUi->minsize1type->currentText() == "mul");
123  mUi->minsize2type->setEnabled(mUi->minsize1type->currentIndex() != 0);
124  mUi->minsize2arg->setEnabled(mUi->minsize2type->currentIndex() != 0);
125  mUi->minsize2arg2->setEnabled(mUi->minsize2type->currentText() == "mul");
126 }
LibraryEditArgDialog(QWidget *parent, const CppcheckLibraryData::Function::Arg &arg)
Ui::LibraryEditArgDialog * mUi
CppcheckLibraryData::Function::Arg getArg() const
QList< CppcheckLibraryData::Function::Arg::MinSize > mMinSizes
Definition: aboutdialog.h:27