Skip to content

Commit ab4adf2

Browse files
committed
GUI: Added a dedicated 'Add function' dialog to the LibraryDialog
1 parent f9415fc commit ab4adf2

5 files changed

Lines changed: 217 additions & 10 deletions

File tree

gui/gui.pro

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ FORMS = about.ui \
5151
scratchpad.ui \
5252
settings.ui \
5353
stats.ui \
54-
librarydialog.ui
54+
librarydialog.ui \
55+
libraryaddfunctiondialog.ui
5556

5657
TRANSLATIONS = cppcheck_de.ts \
5758
cppcheck_es.ts \
@@ -108,7 +109,8 @@ HEADERS += aboutdialog.h \
108109
xmlreportv1.h \
109110
xmlreportv2.h \
110111
librarydialog.h \
111-
librarydata.h
112+
librarydata.h \
113+
libraryaddfunctiondialog.h
112114

113115
SOURCES += aboutdialog.cpp \
114116
application.cpp \
@@ -144,7 +146,8 @@ SOURCES += aboutdialog.cpp \
144146
xmlreportv1.cpp \
145147
xmlreportv2.cpp \
146148
librarydialog.cpp \
147-
librarydata.cpp
149+
librarydata.cpp \
150+
libraryaddfunctiondialog.cpp
148151

149152
win32 {
150153
DEFINES += _CRT_SECURE_NO_WARNINGS

gui/libraryaddfunctiondialog.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "libraryaddfunctiondialog.h"
2+
#include "ui_libraryaddfunctiondialog.h"
3+
4+
#include <QRegExp>
5+
#include <QValidator>
6+
7+
#define SIMPLENAME "[_a-zA-Z][_a-zA-Z0-9]*" // just a name
8+
#define SCOPENAME SIMPLENAME "(::" SIMPLENAME ")*" // names with optional scope
9+
#define NAMES SCOPENAME "(," SCOPENAME ")*" // names can be separated by comma
10+
11+
LibraryAddFunctionDialog::LibraryAddFunctionDialog(QWidget *parent) :
12+
QDialog(parent),
13+
ui(new Ui::LibraryAddFunctionDialog)
14+
{
15+
ui->setupUi(this);
16+
QRegExp rx(NAMES);
17+
QValidator *validator = new QRegExpValidator(rx, this);
18+
ui->functionName->setValidator(validator);
19+
}
20+
21+
LibraryAddFunctionDialog::~LibraryAddFunctionDialog()
22+
{
23+
delete ui;
24+
}
25+
26+
QString LibraryAddFunctionDialog::functionName() const
27+
{
28+
return ui->functionName->text();
29+
}
30+
31+
int LibraryAddFunctionDialog::numberOfArguments() const
32+
{
33+
return ui->numberOfArguments->value();
34+
}
35+

gui/libraryaddfunctiondialog.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef LIBRARYADDFUNCTIONDIALOG_H
2+
#define LIBRARYADDFUNCTIONDIALOG_H
3+
4+
#include <QDialog>
5+
6+
namespace Ui {
7+
class LibraryAddFunctionDialog;
8+
}
9+
10+
class LibraryAddFunctionDialog : public QDialog
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
explicit LibraryAddFunctionDialog(QWidget *parent = 0);
16+
~LibraryAddFunctionDialog();
17+
18+
QString functionName() const;
19+
int numberOfArguments() const;
20+
21+
private:
22+
Ui::LibraryAddFunctionDialog *ui;
23+
};
24+
25+
#endif // LIBRARYADDFUNCTIONDIALOG_H

gui/libraryaddfunctiondialog.ui

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>LibraryAddFunctionDialog</class>
4+
<widget class="QDialog" name="LibraryAddFunctionDialog">
5+
<property name="windowModality">
6+
<enum>Qt::WindowModal</enum>
7+
</property>
8+
<property name="geometry">
9+
<rect>
10+
<x>0</x>
11+
<y>0</y>
12+
<width>386</width>
13+
<height>89</height>
14+
</rect>
15+
</property>
16+
<property name="sizePolicy">
17+
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
18+
<horstretch>0</horstretch>
19+
<verstretch>0</verstretch>
20+
</sizepolicy>
21+
</property>
22+
<property name="windowTitle">
23+
<string>Add function</string>
24+
</property>
25+
<property name="modal">
26+
<bool>true</bool>
27+
</property>
28+
<layout class="QVBoxLayout" name="verticalLayout">
29+
<item>
30+
<layout class="QGridLayout" name="gridLayout">
31+
<item row="0" column="0">
32+
<widget class="QLabel" name="label">
33+
<property name="text">
34+
<string>Function name(s)</string>
35+
</property>
36+
</widget>
37+
</item>
38+
<item row="0" column="1">
39+
<widget class="QLineEdit" name="functionName"/>
40+
</item>
41+
<item row="1" column="0">
42+
<widget class="QLabel" name="label_2">
43+
<property name="text">
44+
<string>Number of arguments</string>
45+
</property>
46+
</widget>
47+
</item>
48+
<item row="1" column="1">
49+
<layout class="QHBoxLayout" name="horizontalLayout">
50+
<item>
51+
<widget class="QSpinBox" name="numberOfArguments"/>
52+
</item>
53+
<item>
54+
<spacer name="horizontalSpacer">
55+
<property name="orientation">
56+
<enum>Qt::Horizontal</enum>
57+
</property>
58+
<property name="sizeHint" stdset="0">
59+
<size>
60+
<width>40</width>
61+
<height>20</height>
62+
</size>
63+
</property>
64+
</spacer>
65+
</item>
66+
</layout>
67+
</item>
68+
</layout>
69+
</item>
70+
<item>
71+
<layout class="QHBoxLayout" name="horizontalLayout_2">
72+
<item>
73+
<spacer name="horizontalSpacer_2">
74+
<property name="orientation">
75+
<enum>Qt::Horizontal</enum>
76+
</property>
77+
<property name="sizeHint" stdset="0">
78+
<size>
79+
<width>40</width>
80+
<height>20</height>
81+
</size>
82+
</property>
83+
</spacer>
84+
</item>
85+
<item>
86+
<widget class="QPushButton" name="cancelButton">
87+
<property name="text">
88+
<string>Cancel</string>
89+
</property>
90+
</widget>
91+
</item>
92+
<item>
93+
<widget class="QPushButton" name="addFunctionButton">
94+
<property name="text">
95+
<string>Add function</string>
96+
</property>
97+
</widget>
98+
</item>
99+
</layout>
100+
</item>
101+
</layout>
102+
</widget>
103+
<resources/>
104+
<connections>
105+
<connection>
106+
<sender>cancelButton</sender>
107+
<signal>clicked()</signal>
108+
<receiver>LibraryAddFunctionDialog</receiver>
109+
<slot>reject()</slot>
110+
<hints>
111+
<hint type="sourcelabel">
112+
<x>210</x>
113+
<y>72</y>
114+
</hint>
115+
<hint type="destinationlabel">
116+
<x>201</x>
117+
<y>85</y>
118+
</hint>
119+
</hints>
120+
</connection>
121+
<connection>
122+
<sender>addFunctionButton</sender>
123+
<signal>clicked()</signal>
124+
<receiver>LibraryAddFunctionDialog</receiver>
125+
<slot>accept()</slot>
126+
<hints>
127+
<hint type="sourcelabel">
128+
<x>330</x>
129+
<y>77</y>
130+
</hint>
131+
<hint type="destinationlabel">
132+
<x>342</x>
133+
<y>87</y>
134+
</hint>
135+
</hints>
136+
</connection>
137+
</connections>
138+
<slots>
139+
<slot>validateName(QString)</slot>
140+
</slots>
141+
</ui>

gui/librarydialog.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "librarydialog.h"
2020
#include "ui_librarydialog.h"
21+
#include "libraryaddfunctiondialog.h"
2122

2223
#include <QFile>
2324
#include <QSettings>
@@ -85,14 +86,16 @@ void LibraryDialog::saveCfg()
8586

8687
void LibraryDialog::addFunction()
8788
{
88-
LibraryData::Function f;
89-
bool ok;
90-
f.name = QInputDialog::getText(this, tr("Add function"), tr("Function name"), QLineEdit::Normal, "doStuff", &ok);
91-
if (!ok)
92-
return;
93-
int args = QInputDialog::getInt(this, tr("Add function"), tr("Number of arguments"), 0, 0, 20, 1, &ok);
94-
if (!ok)
89+
LibraryAddFunctionDialog *d = new LibraryAddFunctionDialog;
90+
if (d->exec() != QDialog::Accepted) {
91+
delete d;
9592
return;
93+
}
94+
95+
LibraryData::Function f;
96+
f.name = d->functionName();
97+
int args = d->numberOfArguments();
98+
9699
for (int i = 1; i <= args; i++) {
97100
LibraryData::Function::Arg arg;
98101
arg.nr = i;

0 commit comments

Comments
 (0)