GUI: Make it possible to configure minsizes through the LibraryDialog

This commit is contained in:
Daniel Marjamäki 2015-09-01 18:13:27 +02:00
parent d87d2ff779
commit 6b49a39282
3 changed files with 343 additions and 23 deletions

View File

@ -13,19 +13,45 @@ LibraryEditArgDialog::LibraryEditArgDialog(QWidget *parent, const CppcheckLibrar
ui->strz->setChecked(arg.strz); ui->strz->setChecked(arg.strz);
ui->formatstr->setChecked(arg.formatstr); ui->formatstr->setChecked(arg.formatstr);
ui->valid->setText(arg.valid); ui->valid->setText(arg.valid);
foreach(const CppcheckLibraryData::Function::Arg::MinSize &minsize, arg.minsizes) {
if (ui->minsizes->count() > 0) ui->minsize1type->setEnabled(true);
ui->minsizes->addItem("and"); ui->minsize1arg->setEnabled(arg.minsizes.count() >= 1);
if (minsize.type == "argvalue") ui->minsize1arg2->setEnabled(arg.minsizes.count() >= 1 && arg.minsizes[0].type == "mul");
ui->minsizes->addItem("Buffer size must be at least as many bytes as given by argument " + minsize.arg); ui->minsize2type->setEnabled(arg.minsizes.count() >= 1);
else if (minsize.type == "constant") ui->minsize2arg->setEnabled(arg.minsizes.count() >= 2);
ui->minsizes->addItem("Buffer size must be at least " + minsize.arg + " bytes"); ui->minsize2arg2->setEnabled(arg.minsizes.count() >= 2 && arg.minsizes[1].type == "mul");
else if (minsize.type == "mul")
ui->minsizes->addItem("Buffer size must be at least as many bytes as multiplication result of argument " + minsize.arg + " and " + minsize.arg2); QStringList items;
else if (minsize.type == "strlen") items << "None" << "argvalue" << "constant" << "mul" << "strlen";
ui->minsizes->addItem("Buffer size must be at least as big as the string in argument " + minsize.arg + "");
ui->minsize1type->clear();
ui->minsize1type->addItems(items);
if (arg.minsizes.count() >= 1) {
ui->minsize1type->setCurrentIndex(items.indexOf(minsizes[0].type));
ui->minsize1arg->setValue(minsizes[0].arg.toInt());
if (arg.minsizes[0].type == "mul")
ui->minsize1arg2->setValue(minsizes[0].arg2.toInt());
else else
ui->minsizes->addItem("unhandled type: " + minsize.type); ui->minsize1arg2->setValue(0);
} else {
ui->minsize1type->setCurrentIndex(0);
ui->minsize1arg->setValue(0);
ui->minsize1arg2->setValue(0);
}
ui->minsize2type->clear();
ui->minsize2type->addItems(items);
if (arg.minsizes.count() >= 2) {
ui->minsize2type->setCurrentIndex(items.indexOf(minsizes[1].type));
ui->minsize2arg->setValue(minsizes[1].arg.toInt());
if (arg.minsizes[1].type == "mul")
ui->minsize2arg2->setValue(minsizes[1].arg2.toInt());
else
ui->minsize2arg2->setValue(0);
} else {
ui->minsize2type->setCurrentIndex(0);
ui->minsize2arg->setValue(0);
ui->minsize2arg2->setValue(0);
} }
} }
@ -42,7 +68,32 @@ CppcheckLibraryData::Function::Arg LibraryEditArgDialog::getArg() const
ret.notuninit = ui->notuninit->isChecked(); ret.notuninit = ui->notuninit->isChecked();
ret.strz = ui->strz->isChecked(); ret.strz = ui->strz->isChecked();
ret.formatstr = ui->formatstr->isChecked(); ret.formatstr = ui->formatstr->isChecked();
ret.minsizes = minsizes; if (ui->minsize1type->currentIndex() != 0) {
CppcheckLibraryData::Function::Arg::MinSize minsize1;
minsize1.type = ui->minsize1type->currentText();
minsize1.arg = QString::number(ui->minsize1arg->value());
if (minsize1.type == "mul")
minsize1.arg2 = QString::number(ui->minsize1arg2->value());
ret.minsizes.append(minsize1);
if (ui->minsize2type->currentIndex() != 0) {
CppcheckLibraryData::Function::Arg::MinSize minsize2;
minsize2.type = ui->minsize2type->currentText();
minsize2.arg = QString::number(ui->minsize2arg->value());
if (minsize2.type == "mul")
minsize2.arg2 = QString::number(ui->minsize2arg2->value());
ret.minsizes.append(minsize2);
}
}
ret.valid = ui->valid->text(); ret.valid = ui->valid->text();
return ret; return ret;
} }
void LibraryEditArgDialog::minsizeChanged(int)
{
ui->minsize1arg->setEnabled(ui->minsize1type->currentIndex() != 0);
ui->minsize1arg2->setEnabled(ui->minsize1type->currentText() == "mul");
ui->minsize2type->setEnabled(ui->minsize1type->currentIndex() != 0);
ui->minsize2arg->setEnabled(ui->minsize2type->currentIndex() != 0);
ui->minsize2arg2->setEnabled(ui->minsize2type->currentText() == "mul");
}

View File

@ -17,6 +17,9 @@ public:
CppcheckLibraryData::Function::Arg getArg() const; CppcheckLibraryData::Function::Arg getArg() const;
private slots:
void minsizeChanged(int);
private: private:
Ui::LibraryEditArgDialog *ui; Ui::LibraryEditArgDialog *ui;

View File

@ -6,14 +6,14 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>448</width>
<height>448</height> <height>465</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Edit argument</string> <string>Edit argument</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QCheckBox" name="notbool"> <widget class="QCheckBox" name="notbool">
<property name="toolTip"> <property name="toolTip">
@ -72,14 +72,245 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label"> <spacer name="verticalSpacer_3">
<property name="text"> <property name="orientation">
<string>Min size of buffer</string> <enum>Qt::Vertical</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item> </item>
<item> <item>
<widget class="QListWidget" name="minsizes"/> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Min size of buffer</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="minsize1type">
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>argvalue</string>
</property>
</item>
<item>
<property name="text">
<string>constant</string>
</property>
</item>
<item>
<property name="text">
<string>mul</string>
</property>
</item>
<item>
<property name="text">
<string>strlen</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Arg</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QSpinBox" name="minsize1arg"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Arg2</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSpinBox" name="minsize1arg2"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="andlabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>and</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="minsize2label1">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="minsize2type">
<property name="enabled">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>argvalue</string>
</property>
</item>
<item>
<property name="text">
<string>constant</string>
</property>
</item>
<item>
<property name="text">
<string>mul</string>
</property>
</item>
<item>
<property name="text">
<string>strlen</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="minsize2label2">
<property name="text">
<string>Arg</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QSpinBox" name="minsize2arg"/>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="minsize2label3">
<property name="text">
<string>Arg2</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QSpinBox" name="minsize2arg2"/>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
@ -116,8 +347,8 @@
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>222</x> <x>226</x>
<y>433</y> <y>460</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>157</x> <x>157</x>
@ -141,5 +372,40 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>minsize1type</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>LibraryEditArgDialog</receiver>
<slot>minsizeChanged(int)</slot>
<hints>
<hint type="sourcelabel">
<x>413</x>
<y>194</y>
</hint>
<hint type="destinationlabel">
<x>446</x>
<y>175</y>
</hint>
</hints>
</connection>
<connection>
<sender>minsize2type</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>LibraryEditArgDialog</receiver>
<slot>minsizeChanged(int)</slot>
<hints>
<hint type="sourcelabel">
<x>436</x>
<y>299</y>
</hint>
<hint type="destinationlabel">
<x>447</x>
<y>297</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots>
<slot>minsizeChanged(int)</slot>
</slots>
</ui> </ui>