GUI: Added a dedicated dialog for LibraryDialog for configuration of function arguments
This commit is contained in:
parent
5e9325b4f4
commit
dd7c0b353d
|
@ -52,7 +52,8 @@ FORMS = about.ui \
|
||||||
settings.ui \
|
settings.ui \
|
||||||
stats.ui \
|
stats.ui \
|
||||||
librarydialog.ui \
|
librarydialog.ui \
|
||||||
libraryaddfunctiondialog.ui
|
libraryaddfunctiondialog.ui \
|
||||||
|
libraryeditargdialog.ui
|
||||||
|
|
||||||
TRANSLATIONS = cppcheck_de.ts \
|
TRANSLATIONS = cppcheck_de.ts \
|
||||||
cppcheck_es.ts \
|
cppcheck_es.ts \
|
||||||
|
@ -110,7 +111,8 @@ HEADERS += aboutdialog.h \
|
||||||
xmlreportv2.h \
|
xmlreportv2.h \
|
||||||
librarydialog.h \
|
librarydialog.h \
|
||||||
librarydata.h \
|
librarydata.h \
|
||||||
libraryaddfunctiondialog.h
|
libraryaddfunctiondialog.h \
|
||||||
|
libraryeditargdialog.h
|
||||||
|
|
||||||
SOURCES += aboutdialog.cpp \
|
SOURCES += aboutdialog.cpp \
|
||||||
application.cpp \
|
application.cpp \
|
||||||
|
@ -147,7 +149,8 @@ SOURCES += aboutdialog.cpp \
|
||||||
xmlreportv2.cpp \
|
xmlreportv2.cpp \
|
||||||
librarydialog.cpp \
|
librarydialog.cpp \
|
||||||
librarydata.cpp \
|
librarydata.cpp \
|
||||||
libraryaddfunctiondialog.cpp
|
libraryaddfunctiondialog.cpp \
|
||||||
|
libraryeditargdialog.cpp
|
||||||
|
|
||||||
win32 {
|
win32 {
|
||||||
DEFINES += _CRT_SECURE_NO_WARNINGS
|
DEFINES += _CRT_SECURE_NO_WARNINGS
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>386</width>
|
<width>353</width>
|
||||||
<height>89</height>
|
<height>89</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -68,68 +68,47 @@
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<item>
|
<property name="orientation">
|
||||||
<spacer name="horizontalSpacer_2">
|
<enum>Qt::Horizontal</enum>
|
||||||
<property name="orientation">
|
</property>
|
||||||
<enum>Qt::Horizontal</enum>
|
<property name="standardButtons">
|
||||||
</property>
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
<property name="sizeHint" stdset="0">
|
</property>
|
||||||
<size>
|
</widget>
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="cancelButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Cancel</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="addFunctionButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Add function</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>cancelButton</sender>
|
<sender>buttonBox</sender>
|
||||||
<signal>clicked()</signal>
|
<signal>accepted()</signal>
|
||||||
<receiver>LibraryAddFunctionDialog</receiver>
|
|
||||||
<slot>reject()</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>210</x>
|
|
||||||
<y>72</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>201</x>
|
|
||||||
<y>85</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
|
||||||
<sender>addFunctionButton</sender>
|
|
||||||
<signal>clicked()</signal>
|
|
||||||
<receiver>LibraryAddFunctionDialog</receiver>
|
<receiver>LibraryAddFunctionDialog</receiver>
|
||||||
<slot>accept()</slot>
|
<slot>accept()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>330</x>
|
<x>57</x>
|
||||||
<y>77</y>
|
<y>71</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>342</x>
|
<x>71</x>
|
||||||
|
<y>87</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>LibraryAddFunctionDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>132</x>
|
||||||
|
<y>69</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>156</x>
|
||||||
<y>87</y>
|
<y>87</y>
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
|
|
|
@ -58,9 +58,11 @@ static LibraryData::Function::Arg loadFunctionArg(const QDomElement &functionArg
|
||||||
else if (childElement.tagName() == "valid")
|
else if (childElement.tagName() == "valid")
|
||||||
arg.valid = childElement.text();
|
arg.valid = childElement.text();
|
||||||
else if (childElement.tagName() == "minsize") {
|
else if (childElement.tagName() == "minsize") {
|
||||||
arg.minsize.type = childElement.attribute("type");
|
LibraryData::Function::Arg::MinSize minsize;
|
||||||
arg.minsize.arg = childElement.attribute("arg");
|
minsize.type = childElement.attribute("type");
|
||||||
arg.minsize.arg2 = childElement.attribute("arg2");
|
minsize.arg = childElement.attribute("arg");
|
||||||
|
minsize.arg2 = childElement.attribute("arg2");
|
||||||
|
arg.minsizes.append(minsize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return arg;
|
return arg;
|
||||||
|
@ -210,13 +212,15 @@ static QDomElement FunctionElement(QDomDocument &doc, const LibraryData::Functio
|
||||||
argElement.appendChild(e);
|
argElement.appendChild(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!arg.minsize.type.isEmpty()) {
|
if (!arg.minsizes.isEmpty()) {
|
||||||
QDomElement e = doc.createElement("minsize");
|
foreach(const LibraryData::Function::Arg::MinSize &minsize, arg.minsizes) {
|
||||||
e.setAttribute("type", arg.minsize.type);
|
QDomElement e = doc.createElement("minsize");
|
||||||
e.setAttribute("arg", arg.minsize.arg);
|
e.setAttribute("type", minsize.type);
|
||||||
if (!arg.minsize.arg2.isEmpty())
|
e.setAttribute("arg", minsize.arg);
|
||||||
e.setAttribute("arg2", arg.minsize.arg2);
|
if (!minsize.arg2.isEmpty())
|
||||||
argElement.appendChild(e);
|
e.setAttribute("arg2", minsize.arg2);
|
||||||
|
argElement.appendChild(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,11 +63,12 @@ public:
|
||||||
bool formatstr;
|
bool formatstr;
|
||||||
bool strz;
|
bool strz;
|
||||||
QString valid;
|
QString valid;
|
||||||
struct {
|
struct MinSize {
|
||||||
QString type;
|
QString type;
|
||||||
QString arg;
|
QString arg;
|
||||||
QString arg2;
|
QString arg2;
|
||||||
} minsize;
|
};
|
||||||
|
QList<struct MinSize> minsizes;
|
||||||
};
|
};
|
||||||
QList<struct Arg> args;
|
QList<struct Arg> args;
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "librarydialog.h"
|
#include "librarydialog.h"
|
||||||
#include "ui_librarydialog.h"
|
#include "ui_librarydialog.h"
|
||||||
#include "libraryaddfunctiondialog.h"
|
#include "libraryaddfunctiondialog.h"
|
||||||
|
#include "libraryeditargdialog.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
@ -87,22 +88,22 @@ void LibraryDialog::saveCfg()
|
||||||
void LibraryDialog::addFunction()
|
void LibraryDialog::addFunction()
|
||||||
{
|
{
|
||||||
LibraryAddFunctionDialog *d = new LibraryAddFunctionDialog;
|
LibraryAddFunctionDialog *d = new LibraryAddFunctionDialog;
|
||||||
if (d->exec() != QDialog::Accepted) {
|
if (d->exec() == QDialog::Accepted && !d->functionName().isEmpty()) {
|
||||||
delete d;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LibraryData::Function f;
|
LibraryData::Function f;
|
||||||
f.name = d->functionName();
|
f.name = d->functionName();
|
||||||
int args = d->numberOfArguments();
|
int args = d->numberOfArguments();
|
||||||
|
|
||||||
for (int i = 1; i <= args; i++) {
|
for (int i = 1; i <= args; i++) {
|
||||||
LibraryData::Function::Arg arg;
|
LibraryData::Function::Arg arg;
|
||||||
arg.nr = i;
|
arg.nr = i;
|
||||||
f.args.append(arg);
|
f.args.append(arg);
|
||||||
|
}
|
||||||
|
data.functions.append(f);
|
||||||
|
ui->functions->addItem(f.name);
|
||||||
|
ui->buttonSave->setEnabled(true);
|
||||||
}
|
}
|
||||||
data.functions.append(f);
|
delete d;
|
||||||
ui->functions->addItem(f.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryDialog::selectFunction(int row)
|
void LibraryDialog::selectFunction(int row)
|
||||||
|
@ -120,40 +121,7 @@ void LibraryDialog::selectFunction(int row)
|
||||||
ui->functionreturn->setChecked(!function.noreturn);
|
ui->functionreturn->setChecked(!function.noreturn);
|
||||||
ui->useretval->setChecked(function.useretval);
|
ui->useretval->setChecked(function.useretval);
|
||||||
ui->leakignore->setChecked(function.leakignore);
|
ui->leakignore->setChecked(function.leakignore);
|
||||||
ui->arguments->clear();
|
updateArguments(function);
|
||||||
foreach(const LibraryData::Function::Arg &arg, function.args) {
|
|
||||||
QString s("arg");
|
|
||||||
if (arg.nr != LibraryData::Function::Arg::ANY)
|
|
||||||
s += QString::number(arg.nr);
|
|
||||||
ui->arguments->addItem(s);
|
|
||||||
|
|
||||||
QListWidgetItem *item = new QListWidgetItem(tr("Not bool"), ui->arguments);
|
|
||||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
||||||
item->setCheckState(arg.notbool ? Qt::Checked : Qt::Unchecked);
|
|
||||||
ui->arguments->addItem(item);
|
|
||||||
|
|
||||||
item = new QListWidgetItem(tr("Not null"), ui->arguments);
|
|
||||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
||||||
item->setCheckState(arg.notnull ? Qt::Checked : Qt::Unchecked);
|
|
||||||
ui->arguments->addItem(item);
|
|
||||||
|
|
||||||
item = new QListWidgetItem(tr("Not uninit"), ui->arguments);
|
|
||||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
||||||
item->setCheckState(arg.notuninit ? Qt::Checked : Qt::Unchecked);
|
|
||||||
ui->arguments->addItem(item);
|
|
||||||
|
|
||||||
item = new QListWidgetItem(tr("Format string"), ui->arguments);
|
|
||||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
||||||
item->setCheckState(arg.formatstr ? Qt::Checked : Qt::Unchecked);
|
|
||||||
ui->arguments->addItem(item);
|
|
||||||
|
|
||||||
item = new QListWidgetItem(tr("Zero-terminated string"), ui->arguments);
|
|
||||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
||||||
item->setCheckState(arg.strz ? Qt::Checked : Qt::Unchecked);
|
|
||||||
ui->arguments->addItem(item);
|
|
||||||
|
|
||||||
ui->arguments->addItem("valid: " + ((!arg.valid.isNull()) ? arg.valid : "*"));
|
|
||||||
}
|
|
||||||
ignoreChanges = false;
|
ignoreChanges = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,44 +138,44 @@ void LibraryDialog::changeFunction()
|
||||||
ui->buttonSave->setEnabled(true);
|
ui->buttonSave->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LibraryDialog::editArg()
|
||||||
void LibraryDialog::argumentChanged(QListWidgetItem *changedItem)
|
|
||||||
{
|
{
|
||||||
if (ignoreChanges)
|
if (ui->functions->selectedItems().count() != 1)
|
||||||
return;
|
return;
|
||||||
unsigned argnr = 0;
|
if (ui->arguments->selectedItems().count() != 1)
|
||||||
for (int row = 0; row < ui->arguments->count(); row++) {
|
return;
|
||||||
const QListWidgetItem *argItem = ui->arguments->item(row);
|
|
||||||
if (argItem == changedItem)
|
LibraryData::Function &function = data.functions[ui->functions->row(ui->functions->selectedItems().first())];
|
||||||
break;
|
LibraryData::Function::Arg &arg = function.args[ui->arguments->row(ui->arguments->selectedItems().first())];
|
||||||
if (argItem->text() == "arg")
|
|
||||||
argnr = LibraryData::Function::Arg::ANY;
|
LibraryEditArgDialog *d = new LibraryEditArgDialog(0, arg);
|
||||||
else if (argItem->text().startsWith("arg"))
|
if (d->exec() == QDialog::Accepted) {
|
||||||
argnr = argItem->text().mid(3).toInt();
|
arg = d->getArg();
|
||||||
}
|
updateArguments(function);
|
||||||
|
|
||||||
foreach(const QListWidgetItem *functionItem, ui->functions->selectedItems()) {
|
|
||||||
LibraryData::Function &function = data.functions[ui->functions->row(functionItem)];
|
|
||||||
|
|
||||||
for (LibraryData::Function::Arg &arg : function.args) {
|
|
||||||
if (arg.nr == argnr) {
|
|
||||||
// TODO: Don't use a stringbased lookup
|
|
||||||
if (changedItem->text() == "Not bool")
|
|
||||||
arg.notbool = (changedItem->checkState() != Qt::Unchecked);
|
|
||||||
else if (changedItem->text() == "Not null")
|
|
||||||
arg.notnull = (changedItem->checkState() != Qt::Unchecked);
|
|
||||||
else if (changedItem->text() == "Not uninit")
|
|
||||||
arg.notuninit = (changedItem->checkState() != Qt::Unchecked);
|
|
||||||
else if (changedItem->text() == "Format string")
|
|
||||||
arg.formatstr = (changedItem->checkState() != Qt::Unchecked);
|
|
||||||
else if (changedItem->text() == "Zero-terminated string")
|
|
||||||
arg.strz = (changedItem->checkState() != Qt::Unchecked);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete d;
|
||||||
ui->buttonSave->setEnabled(true);
|
ui->buttonSave->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LibraryDialog::updateArguments(const LibraryData::Function &function)
|
||||||
|
{
|
||||||
|
ui->arguments->clear();
|
||||||
|
foreach(const LibraryData::Function::Arg &arg, function.args) {
|
||||||
|
QString s("arg");
|
||||||
|
if (arg.nr != LibraryData::Function::Arg::ANY)
|
||||||
|
s += QString::number(arg.nr);
|
||||||
|
|
||||||
|
s += "\n not bool: " + QString(arg.notbool ? "true" : "false");
|
||||||
|
s += "\n not null: " + QString(arg.notnull ? "true" : "false");
|
||||||
|
s += "\n not uninit: " + QString(arg.notuninit ? "true" : "false");
|
||||||
|
s += "\n format string: " + QString(arg.formatstr ? "true" : "false");
|
||||||
|
s += "\n strz: " + QString(arg.strz ? "true" : "false");
|
||||||
|
s += "\n valid: " + QString(arg.valid.isEmpty() ? "any" : arg.valid);
|
||||||
|
foreach(const LibraryData::Function::Arg::MinSize &minsize, arg.minsizes) {
|
||||||
|
s += "\n minsize: " + minsize.type + " " + minsize.arg + " " + minsize.arg2;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->arguments->addItem(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -43,13 +43,15 @@ private slots:
|
||||||
void addFunction();
|
void addFunction();
|
||||||
void selectFunction(int row);
|
void selectFunction(int row);
|
||||||
void changeFunction();
|
void changeFunction();
|
||||||
void argumentChanged(QListWidgetItem *);
|
void editArg();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::LibraryDialog *ui;
|
Ui::LibraryDialog *ui;
|
||||||
LibraryData data;
|
LibraryData data;
|
||||||
QString mFileName;
|
QString mFileName;
|
||||||
bool ignoreChanges;
|
bool ignoreChanges;
|
||||||
|
|
||||||
|
void updateArguments(const LibraryData::Function &function);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LIBRARYDIALOG_H
|
#endif // LIBRARYDIALOG_H
|
||||||
|
|
|
@ -126,17 +126,28 @@
|
||||||
<widget class="QListWidget" name="arguments"/>
|
<widget class="QListWidget" name="arguments"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<property name="orientation">
|
<item>
|
||||||
<enum>Qt::Vertical</enum>
|
<widget class="QPushButton" name="editArgButton">
|
||||||
</property>
|
<property name="text">
|
||||||
<property name="sizeHint" stdset="0">
|
<string>Edit</string>
|
||||||
<size>
|
</property>
|
||||||
<width>20</width>
|
</widget>
|
||||||
<height>40</height>
|
</item>
|
||||||
</size>
|
<item>
|
||||||
</property>
|
<spacer name="horizontalSpacer_3">
|
||||||
</spacer>
|
<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>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
@ -242,22 +253,6 @@
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
<connection>
|
|
||||||
<sender>arguments</sender>
|
|
||||||
<signal>itemChanged(QListWidgetItem*)</signal>
|
|
||||||
<receiver>LibraryDialog</receiver>
|
|
||||||
<slot>argumentChanged(QListWidgetItem*)</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>517</x>
|
|
||||||
<y>140</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>542</x>
|
|
||||||
<y>117</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
<connection>
|
||||||
<sender>addFunction</sender>
|
<sender>addFunction</sender>
|
||||||
<signal>clicked()</signal>
|
<signal>clicked()</signal>
|
||||||
|
@ -274,6 +269,22 @@
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>editArgButton</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>LibraryDialog</receiver>
|
||||||
|
<slot>editArg()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>317</x>
|
||||||
|
<y>278</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>349</x>
|
||||||
|
<y>281</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
</connections>
|
</connections>
|
||||||
<slots>
|
<slots>
|
||||||
<slot>selectFunction(int)</slot>
|
<slot>selectFunction(int)</slot>
|
||||||
|
@ -282,5 +293,6 @@
|
||||||
<slot>saveCfg()</slot>
|
<slot>saveCfg()</slot>
|
||||||
<slot>argumentChanged(QListWidgetItem*)</slot>
|
<slot>argumentChanged(QListWidgetItem*)</slot>
|
||||||
<slot>addFunction()</slot>
|
<slot>addFunction()</slot>
|
||||||
|
<slot>editArg()</slot>
|
||||||
</slots>
|
</slots>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
Loading…
Reference in New Issue