Skip to content

Commit f82021d

Browse files
committed
GUI: Improving application handling code.
Only allow access to Application's attributes through accessor methods.
1 parent 3cb3992 commit f82021d

4 files changed

Lines changed: 116 additions & 17 deletions

File tree

gui/application.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "application.h"
20+
21+
Application::Application(const QString &name, const QString &path,
22+
const QString &params)
23+
: mName(name)
24+
, mPath(path)
25+
, mParameters(params)
26+
{
27+
}

gui/application.h

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,105 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
119
#ifndef APPLICATION_H
220
#define APPLICATION_H
321

22+
#include <QString>
23+
424
/**
525
* @brief A class containing information of the application to execute.
626
*
727
*/
828
class Application
929
{
1030
public:
31+
Application(const QString &name, const QString &path, const QString &params);
32+
33+
/**
34+
* @brief Get application name.
35+
* @return Application name.
36+
*/
37+
QString getName() const
38+
{
39+
return mName;
40+
}
41+
42+
/**
43+
* @brief Get application path.
44+
* @return Application path.
45+
*/
46+
QString getPath() const
47+
{
48+
return mPath;
49+
}
50+
51+
/**
52+
* @brief Get application command line parameters.
53+
* @return Application command line parameters.
54+
*/
55+
QString getParameters() const
56+
{
57+
return mParameters;
58+
}
59+
60+
/**
61+
* @brief Set application name.
62+
* @param name Application name.
63+
*/
64+
void setName(const QString &name)
65+
{
66+
mName = name;
67+
}
68+
69+
/**
70+
* @brief Set application path.
71+
* @param path Application path.
72+
*/
73+
void setPath(const QString &path)
74+
{
75+
mPath = path;
76+
}
77+
78+
/**
79+
* @brief Set application command line parameters.
80+
* @param parameters Application command line parameters.
81+
*/
82+
void setParameters(const QString &parameters)
83+
{
84+
mParameters = parameters;
85+
}
86+
87+
private:
88+
1189
/**
1290
* @brief Application's name
13-
*
1491
*/
15-
QString Name;
92+
QString mName;
1693

1794
/**
1895
* @brief Application's path
19-
*
2096
*/
21-
QString Path;
97+
QString mPath;
2298

2399
/**
24100
* @brief Application's parameters
25-
*
26101
*/
27-
QString Parameters;
102+
QString mParameters;
28103
};
29104

30105
#endif // APPLICATION_H

gui/applicationlist.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ QString ApplicationList::GetApplicationName(const int index) const
127127
{
128128
if (index >= 0 && index < mApplications.size())
129129
{
130-
return mApplications[index].Name;
130+
return mApplications[index].getName();
131131
}
132132

133133
return QString();
@@ -137,7 +137,7 @@ QString ApplicationList::GetApplicationPath(const int index) const
137137
{
138138
if (index >= 0 && index < mApplications.size())
139139
{
140-
return mApplications[index].Path;
140+
return mApplications[index].getPath();
141141
}
142142

143143
return QString();
@@ -147,7 +147,7 @@ QString ApplicationList::GetApplicationParameters(const int index) const
147147
{
148148
if (index >= 0 && index < mApplications.size())
149149
{
150-
return mApplications[index].Parameters;
150+
return mApplications[index].getParameters();
151151
}
152152

153153
return QString();
@@ -160,9 +160,8 @@ void ApplicationList::SetApplication(const int index,
160160
{
161161
if (index >= 0 && index < mApplications.size())
162162
{
163-
mApplications[index].Name = name;
164-
mApplications[index].Path = path;
165-
mApplications[index].Parameters = parameters;
163+
Application app(name, path, parameters);
164+
mApplications.replace(index, app);
166165
}
167166
}
168167

@@ -175,10 +174,7 @@ void ApplicationList::AddApplication(const QString &name,
175174
return;
176175
}
177176

178-
Application app;
179-
app.Name = name;
180-
app.Path = path;
181-
app.Parameters = parameters;
177+
Application app(name, path, parameters);
182178
mApplications << app;
183179
}
184180

gui/gui.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ SOURCES += main.cpp \
105105
logview.cpp \
106106
filelist.cpp \
107107
statsdialog.cpp \
108-
checkstatistics.cpp
108+
checkstatistics.cpp \
109+
application.cpp
109110

110111
win32 {
111112
DEFINES += _CRT_SECURE_NO_WARNINGS

0 commit comments

Comments
 (0)