GUI: Added a dedicated 'Add function' dialog to the LibraryDialog
This commit is contained in:
parent
f9415fc904
commit
ab4adf2836
|
@ -51,7 +51,8 @@ FORMS = about.ui \
|
|||
scratchpad.ui \
|
||||
settings.ui \
|
||||
stats.ui \
|
||||
librarydialog.ui
|
||||
librarydialog.ui \
|
||||
libraryaddfunctiondialog.ui
|
||||
|
||||
TRANSLATIONS = cppcheck_de.ts \
|
||||
cppcheck_es.ts \
|
||||
|
@ -108,7 +109,8 @@ HEADERS += aboutdialog.h \
|
|||
xmlreportv1.h \
|
||||
xmlreportv2.h \
|
||||
librarydialog.h \
|
||||
librarydata.h
|
||||
librarydata.h \
|
||||
libraryaddfunctiondialog.h
|
||||
|
||||
SOURCES += aboutdialog.cpp \
|
||||
application.cpp \
|
||||
|
@ -144,7 +146,8 @@ SOURCES += aboutdialog.cpp \
|
|||
xmlreportv1.cpp \
|
||||
xmlreportv2.cpp \
|
||||
librarydialog.cpp \
|
||||
librarydata.cpp
|
||||
librarydata.cpp \
|
||||
libraryaddfunctiondialog.cpp
|
||||
|
||||
win32 {
|
||||
DEFINES += _CRT_SECURE_NO_WARNINGS
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#include "libraryaddfunctiondialog.h"
|
||||
#include "ui_libraryaddfunctiondialog.h"
|
||||
|
||||
#include <QRegExp>
|
||||
#include <QValidator>
|
||||
|
||||
#define SIMPLENAME "[_a-zA-Z][_a-zA-Z0-9]*" // just a name
|
||||
#define SCOPENAME SIMPLENAME "(::" SIMPLENAME ")*" // names with optional scope
|
||||
#define NAMES SCOPENAME "(," SCOPENAME ")*" // names can be separated by comma
|
||||
|
||||
LibraryAddFunctionDialog::LibraryAddFunctionDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::LibraryAddFunctionDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
QRegExp rx(NAMES);
|
||||
QValidator *validator = new QRegExpValidator(rx, this);
|
||||
ui->functionName->setValidator(validator);
|
||||
}
|
||||
|
||||
LibraryAddFunctionDialog::~LibraryAddFunctionDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString LibraryAddFunctionDialog::functionName() const
|
||||
{
|
||||
return ui->functionName->text();
|
||||
}
|
||||
|
||||
int LibraryAddFunctionDialog::numberOfArguments() const
|
||||
{
|
||||
return ui->numberOfArguments->value();
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef LIBRARYADDFUNCTIONDIALOG_H
|
||||
#define LIBRARYADDFUNCTIONDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class LibraryAddFunctionDialog;
|
||||
}
|
||||
|
||||
class LibraryAddFunctionDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LibraryAddFunctionDialog(QWidget *parent = 0);
|
||||
~LibraryAddFunctionDialog();
|
||||
|
||||
QString functionName() const;
|
||||
int numberOfArguments() const;
|
||||
|
||||
private:
|
||||
Ui::LibraryAddFunctionDialog *ui;
|
||||
};
|
||||
|
||||
#endif // LIBRARYADDFUNCTIONDIALOG_H
|
|
@ -0,0 +1,141 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LibraryAddFunctionDialog</class>
|
||||
<widget class="QDialog" name="LibraryAddFunctionDialog">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::WindowModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>386</width>
|
||||
<height>89</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Add function</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Function name(s)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="functionName"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Number of arguments</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QSpinBox" name="numberOfArguments"/>
|
||||
</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>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<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>
|
||||
<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>
|
||||
</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>
|
||||
<receiver>LibraryAddFunctionDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>330</x>
|
||||
<y>77</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>342</x>
|
||||
<y>87</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>validateName(QString)</slot>
|
||||
</slots>
|
||||
</ui>
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "librarydialog.h"
|
||||
#include "ui_librarydialog.h"
|
||||
#include "libraryaddfunctiondialog.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QSettings>
|
||||
|
@ -85,14 +86,16 @@ void LibraryDialog::saveCfg()
|
|||
|
||||
void LibraryDialog::addFunction()
|
||||
{
|
||||
LibraryAddFunctionDialog *d = new LibraryAddFunctionDialog;
|
||||
if (d->exec() != QDialog::Accepted) {
|
||||
delete d;
|
||||
return;
|
||||
}
|
||||
|
||||
LibraryData::Function f;
|
||||
bool ok;
|
||||
f.name = QInputDialog::getText(this, tr("Add function"), tr("Function name"), QLineEdit::Normal, "doStuff", &ok);
|
||||
if (!ok)
|
||||
return;
|
||||
int args = QInputDialog::getInt(this, tr("Add function"), tr("Number of arguments"), 0, 0, 20, 1, &ok);
|
||||
if (!ok)
|
||||
return;
|
||||
f.name = d->functionName();
|
||||
int args = d->numberOfArguments();
|
||||
|
||||
for (int i = 1; i <= args; i++) {
|
||||
LibraryData::Function::Arg arg;
|
||||
arg.nr = i;
|
||||
|
|
Loading…
Reference in New Issue