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 \
|
||||
stats.ui \
|
||||
librarydialog.ui \
|
||||
libraryaddfunctiondialog.ui
|
||||
libraryaddfunctiondialog.ui \
|
||||
libraryeditargdialog.ui
|
||||
|
||||
TRANSLATIONS = cppcheck_de.ts \
|
||||
cppcheck_es.ts \
|
||||
|
@ -110,7 +111,8 @@ HEADERS += aboutdialog.h \
|
|||
xmlreportv2.h \
|
||||
librarydialog.h \
|
||||
librarydata.h \
|
||||
libraryaddfunctiondialog.h
|
||||
libraryaddfunctiondialog.h \
|
||||
libraryeditargdialog.h
|
||||
|
||||
SOURCES += aboutdialog.cpp \
|
||||
application.cpp \
|
||||
|
@ -147,7 +149,8 @@ SOURCES += aboutdialog.cpp \
|
|||
xmlreportv2.cpp \
|
||||
librarydialog.cpp \
|
||||
librarydata.cpp \
|
||||
libraryaddfunctiondialog.cpp
|
||||
libraryaddfunctiondialog.cpp \
|
||||
libraryeditargdialog.cpp
|
||||
|
||||
win32 {
|
||||
DEFINES += _CRT_SECURE_NO_WARNINGS
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>386</width>
|
||||
<width>353</width>
|
||||
<height>89</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -68,68 +68,47 @@
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancelButton">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="addFunctionButton">
|
||||
<property name="text">
|
||||
<string>Add function</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>cancelButton</sender>
|
||||
<signal>clicked()</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>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>LibraryAddFunctionDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>330</x>
|
||||
<y>77</y>
|
||||
<x>57</x>
|
||||
<y>71</y>
|
||||
</hint>
|
||||
<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>
|
||||
</hint>
|
||||
</hints>
|
||||
|
|
|
@ -58,9 +58,11 @@ static LibraryData::Function::Arg loadFunctionArg(const QDomElement &functionArg
|
|||
else if (childElement.tagName() == "valid")
|
||||
arg.valid = childElement.text();
|
||||
else if (childElement.tagName() == "minsize") {
|
||||
arg.minsize.type = childElement.attribute("type");
|
||||
arg.minsize.arg = childElement.attribute("arg");
|
||||
arg.minsize.arg2 = childElement.attribute("arg2");
|
||||
LibraryData::Function::Arg::MinSize minsize;
|
||||
minsize.type = childElement.attribute("type");
|
||||
minsize.arg = childElement.attribute("arg");
|
||||
minsize.arg2 = childElement.attribute("arg2");
|
||||
arg.minsizes.append(minsize);
|
||||
}
|
||||
}
|
||||
return arg;
|
||||
|
@ -210,15 +212,17 @@ static QDomElement FunctionElement(QDomDocument &doc, const LibraryData::Functio
|
|||
argElement.appendChild(e);
|
||||
}
|
||||
|
||||
if (!arg.minsize.type.isEmpty()) {
|
||||
if (!arg.minsizes.isEmpty()) {
|
||||
foreach(const LibraryData::Function::Arg::MinSize &minsize, arg.minsizes) {
|
||||
QDomElement e = doc.createElement("minsize");
|
||||
e.setAttribute("type", arg.minsize.type);
|
||||
e.setAttribute("arg", arg.minsize.arg);
|
||||
if (!arg.minsize.arg2.isEmpty())
|
||||
e.setAttribute("arg2", arg.minsize.arg2);
|
||||
e.setAttribute("type", minsize.type);
|
||||
e.setAttribute("arg", minsize.arg);
|
||||
if (!minsize.arg2.isEmpty())
|
||||
e.setAttribute("arg2", minsize.arg2);
|
||||
argElement.appendChild(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return functionElement;
|
||||
}
|
||||
|
|
|
@ -63,11 +63,12 @@ public:
|
|||
bool formatstr;
|
||||
bool strz;
|
||||
QString valid;
|
||||
struct {
|
||||
struct MinSize {
|
||||
QString type;
|
||||
QString arg;
|
||||
QString arg2;
|
||||
} minsize;
|
||||
};
|
||||
QList<struct MinSize> minsizes;
|
||||
};
|
||||
QList<struct Arg> args;
|
||||
};
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "librarydialog.h"
|
||||
#include "ui_librarydialog.h"
|
||||
#include "libraryaddfunctiondialog.h"
|
||||
#include "libraryeditargdialog.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QSettings>
|
||||
|
@ -87,10 +88,7 @@ void LibraryDialog::saveCfg()
|
|||
void LibraryDialog::addFunction()
|
||||
{
|
||||
LibraryAddFunctionDialog *d = new LibraryAddFunctionDialog;
|
||||
if (d->exec() != QDialog::Accepted) {
|
||||
delete d;
|
||||
return;
|
||||
}
|
||||
if (d->exec() == QDialog::Accepted && !d->functionName().isEmpty()) {
|
||||
|
||||
LibraryData::Function f;
|
||||
f.name = d->functionName();
|
||||
|
@ -103,6 +101,9 @@ void LibraryDialog::addFunction()
|
|||
}
|
||||
data.functions.append(f);
|
||||
ui->functions->addItem(f.name);
|
||||
ui->buttonSave->setEnabled(true);
|
||||
}
|
||||
delete d;
|
||||
}
|
||||
|
||||
void LibraryDialog::selectFunction(int row)
|
||||
|
@ -120,40 +121,7 @@ void LibraryDialog::selectFunction(int row)
|
|||
ui->functionreturn->setChecked(!function.noreturn);
|
||||
ui->useretval->setChecked(function.useretval);
|
||||
ui->leakignore->setChecked(function.leakignore);
|
||||
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);
|
||||
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 : "*"));
|
||||
}
|
||||
updateArguments(function);
|
||||
ignoreChanges = false;
|
||||
}
|
||||
|
||||
|
@ -170,44 +138,44 @@ void LibraryDialog::changeFunction()
|
|||
ui->buttonSave->setEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
void LibraryDialog::argumentChanged(QListWidgetItem *changedItem)
|
||||
void LibraryDialog::editArg()
|
||||
{
|
||||
if (ignoreChanges)
|
||||
if (ui->functions->selectedItems().count() != 1)
|
||||
return;
|
||||
unsigned argnr = 0;
|
||||
for (int row = 0; row < ui->arguments->count(); row++) {
|
||||
const QListWidgetItem *argItem = ui->arguments->item(row);
|
||||
if (argItem == changedItem)
|
||||
break;
|
||||
if (argItem->text() == "arg")
|
||||
argnr = LibraryData::Function::Arg::ANY;
|
||||
else if (argItem->text().startsWith("arg"))
|
||||
argnr = argItem->text().mid(3).toInt();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (ui->arguments->selectedItems().count() != 1)
|
||||
return;
|
||||
|
||||
LibraryData::Function &function = data.functions[ui->functions->row(ui->functions->selectedItems().first())];
|
||||
LibraryData::Function::Arg &arg = function.args[ui->arguments->row(ui->arguments->selectedItems().first())];
|
||||
|
||||
LibraryEditArgDialog *d = new LibraryEditArgDialog(0, arg);
|
||||
if (d->exec() == QDialog::Accepted) {
|
||||
arg = d->getArg();
|
||||
updateArguments(function);
|
||||
}
|
||||
|
||||
delete d;
|
||||
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 selectFunction(int row);
|
||||
void changeFunction();
|
||||
void argumentChanged(QListWidgetItem *);
|
||||
void editArg();
|
||||
|
||||
private:
|
||||
Ui::LibraryDialog *ui;
|
||||
LibraryData data;
|
||||
QString mFileName;
|
||||
bool ignoreChanges;
|
||||
|
||||
void updateArguments(const LibraryData::Function &function);
|
||||
};
|
||||
|
||||
#endif // LIBRARYDIALOG_H
|
||||
|
|
|
@ -126,14 +126,23 @@
|
|||
<widget class="QListWidget" name="arguments"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="editArgButton">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
|
@ -143,6 +152,8 @@
|
|||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
@ -242,22 +253,6 @@
|
|||
</hint>
|
||||
</hints>
|
||||
</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>
|
||||
<sender>addFunction</sender>
|
||||
<signal>clicked()</signal>
|
||||
|
@ -274,6 +269,22 @@
|
|||
</hint>
|
||||
</hints>
|
||||
</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>
|
||||
<slots>
|
||||
<slot>selectFunction(int)</slot>
|
||||
|
@ -282,5 +293,6 @@
|
|||
<slot>saveCfg()</slot>
|
||||
<slot>argumentChanged(QListWidgetItem*)</slot>
|
||||
<slot>addFunction()</slot>
|
||||
<slot>editArg()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
|
Loading…
Reference in New Issue