Skip to content

Commit 4385879

Browse files
committed
GUI: Improved handling of noreturn in library editor
1 parent 16851f4 commit 4385879

5 files changed

Lines changed: 65 additions & 31 deletions

File tree

gui/cppchecklibrarydata.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static CppcheckLibraryData::Function loadFunction(const QDomElement &functionEle
7575
function.name = functionElement.attribute("name");
7676
for (QDomElement childElement = functionElement.firstChildElement(); !childElement.isNull(); childElement = childElement.nextSiblingElement()) {
7777
if (childElement.tagName() == "noreturn")
78-
function.noreturn = (childElement.text() == "true");
78+
function.noreturn = (childElement.text() == "true") ? CppcheckLibraryData::Function::True : CppcheckLibraryData::Function::False;
7979
else if (childElement.tagName() == "pure")
8080
function.gccPure = true;
8181
else if (childElement.tagName() == "const")
@@ -160,8 +160,6 @@ bool CppcheckLibraryData::open(QIODevice &file)
160160
return true;
161161
}
162162

163-
164-
165163
static QDomElement FunctionElement(QDomDocument &doc, const CppcheckLibraryData::Function &function)
166164
{
167165
QDomElement functionElement = doc.createElement("function");
@@ -172,9 +170,9 @@ static QDomElement FunctionElement(QDomDocument &doc, const CppcheckLibraryData:
172170
functionElement.appendChild(doc.createElement("const"));
173171
if (function.gccPure)
174172
functionElement.appendChild(doc.createElement("pure"));
175-
{
173+
if (function.noreturn != CppcheckLibraryData::Function::Unknown) {
176174
QDomElement e = doc.createElement("noreturn");
177-
e.appendChild(doc.createTextNode(function.noreturn ? "true" : "false"));
175+
e.appendChild(doc.createTextNode(function.noreturn == CppcheckLibraryData::Function::True ? "true" : "false"));
178176
functionElement.appendChild(e);
179177
}
180178
if (function.leakignore)

gui/cppchecklibrarydata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ class CppcheckLibraryData {
3434
};
3535

3636
struct Function {
37-
Function() : noreturn(true), gccPure(false), gccConst(false),
37+
Function() : noreturn(Unknown), gccPure(false), gccConst(false),
3838
leakignore(false), useretval(false) {
3939
}
4040

4141
QStringList comments;
4242
QString name;
43-
bool noreturn;
43+
enum TrueFalseUnknown { False, True, Unknown } noreturn;
4444
bool gccPure;
4545
bool gccConst;
4646
bool leakignore;

gui/librarydialog.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void LibraryDialog::addFunction()
109109
void LibraryDialog::selectFunction(int row)
110110
{
111111
if (row == -1) {
112-
ui->functionreturn->setChecked(false);
112+
ui->noreturn->setCurrentIndex(0);
113113
ui->useretval->setChecked(false);
114114
ui->leakignore->setChecked(false);
115115
ui->arguments->clear();
@@ -118,20 +118,25 @@ void LibraryDialog::selectFunction(int row)
118118

119119
ignoreChanges = true;
120120
const CppcheckLibraryData::Function &function = data.functions[row];
121-
ui->functionreturn->setChecked(!function.noreturn);
121+
ui->noreturn->setCurrentIndex(function.noreturn);
122122
ui->useretval->setChecked(function.useretval);
123123
ui->leakignore->setChecked(function.leakignore);
124124
updateArguments(function);
125125
ignoreChanges = false;
126126
}
127127

128+
void LibraryDialog::changeFunction(int)
129+
{
130+
changeFunction();
131+
}
132+
128133
void LibraryDialog::changeFunction()
129134
{
130135
if (ignoreChanges)
131136
return;
132137
foreach(const QListWidgetItem *item, ui->functions->selectedItems()) {
133138
CppcheckLibraryData::Function &function = data.functions[ui->functions->row(item)];
134-
function.noreturn = !ui->functionreturn->isChecked();
139+
function.noreturn = (CppcheckLibraryData::Function::TrueFalseUnknown)ui->noreturn->currentIndex();
135140
function.useretval = ui->useretval->isChecked();
136141
function.leakignore = ui->leakignore->isChecked();
137142
}

gui/librarydialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private slots:
4343
void addFunction();
4444
void selectFunction(int row);
4545
void changeFunction();
46+
void changeFunction(int);
4647
void editArg();
4748

4849
private:

gui/librarydialog.ui

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,40 @@
9595
<item>
9696
<layout class="QVBoxLayout" name="verticalLayout_2">
9797
<item>
98-
<widget class="QCheckBox" name="functionreturn">
99-
<property name="text">
100-
<string>function always return</string>
101-
</property>
102-
</widget>
98+
<layout class="QHBoxLayout" name="horizontalLayout_5">
99+
<item>
100+
<widget class="QLabel" name="label">
101+
<property name="sizePolicy">
102+
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
103+
<horstretch>0</horstretch>
104+
<verstretch>0</verstretch>
105+
</sizepolicy>
106+
</property>
107+
<property name="text">
108+
<string>noreturn</string>
109+
</property>
110+
</widget>
111+
</item>
112+
<item>
113+
<widget class="QComboBox" name="noreturn">
114+
<item>
115+
<property name="text">
116+
<string>False</string>
117+
</property>
118+
</item>
119+
<item>
120+
<property name="text">
121+
<string>True</string>
122+
</property>
123+
</item>
124+
<item>
125+
<property name="text">
126+
<string>Unknown</string>
127+
</property>
128+
</item>
129+
</widget>
130+
</item>
131+
</layout>
103132
</item>
104133
<item>
105134
<widget class="QCheckBox" name="useretval">
@@ -189,22 +218,6 @@
189218
</hint>
190219
</hints>
191220
</connection>
192-
<connection>
193-
<sender>functionreturn</sender>
194-
<signal>clicked()</signal>
195-
<receiver>LibraryDialog</receiver>
196-
<slot>changeFunction()</slot>
197-
<hints>
198-
<hint type="sourcelabel">
199-
<x>327</x>
200-
<y>45</y>
201-
</hint>
202-
<hint type="destinationlabel">
203-
<x>353</x>
204-
<y>2</y>
205-
</hint>
206-
</hints>
207-
</connection>
208221
<connection>
209222
<sender>useretval</sender>
210223
<signal>clicked()</signal>
@@ -285,6 +298,22 @@
285298
</hint>
286299
</hints>
287300
</connection>
301+
<connection>
302+
<sender>noreturn</sender>
303+
<signal>currentIndexChanged(int)</signal>
304+
<receiver>LibraryDialog</receiver>
305+
<slot>changeFunction(int)</slot>
306+
<hints>
307+
<hint type="sourcelabel">
308+
<x>504</x>
309+
<y>45</y>
310+
</hint>
311+
<hint type="destinationlabel">
312+
<x>543</x>
313+
<y>32</y>
314+
</hint>
315+
</hints>
316+
</connection>
288317
</connections>
289318
<slots>
290319
<slot>selectFunction(int)</slot>
@@ -294,5 +323,6 @@
294323
<slot>argumentChanged(QListWidgetItem*)</slot>
295324
<slot>addFunction()</slot>
296325
<slot>editArg()</slot>
326+
<slot>changeFunction(int)</slot>
297327
</slots>
298328
</ui>

0 commit comments

Comments
 (0)