Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit 6cae591

Browse files
authored
Code improvements (#85)
* Code analysis improvements: - Add cppcheck wrapper script: `./scripts/cppcheck` - Address cppcheck errors - Fix warnings in project * Fix more cppcheck warnings. Add unit test for SER color conversion * More cppcheck issues addressed #skip_ci
1 parent 8554a02 commit 6cae591

33 files changed

Lines changed: 86 additions & 88 deletions

scripts/cppcheck

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
PROJECT_DIR="$( cd "$( dirname "$0" )/.."; pwd )"
3+
BUILD_DIR="${BUILD_DIR:-$PROJECT_DIR/build}"
4+
mkdir -p "$BUILD_DIR"
5+
6+
cppcheck \
7+
--cppcheck-build-dir="${BUILD_DIR}" \
8+
--enable=all \
9+
-i src/drivers/zwo_asi/ASI_Linux_Mac_v1.14.0425 \
10+
-i src/drivers/zwo_asi/ASI_Windows_v1.14.0425 \
11+
-i src/drivers/qhy/QHY_Linux_armv7_v5.0.7 \
12+
-i src/drivers/qhy/QHY_Linux_x86_64_v5.0.7 \
13+
-i src/drivers/qhy/QHY_Mac_x86_64_v5.0.7 \
14+
-i src/drivers/qhy/QHY_Windows_v5.0.7 \
15+
-DQ_IMPORT_PLUGIN \
16+
-DQ_DECLARE_METATYPE \
17+
--xml \
18+
-I "${BUILD_DIR}/GuLinux-Commons" \
19+
-I "${BUILD_DIR}/GuLinux-Commons/c++" \
20+
-I "${BUILD_DIR}/GuLinux-Commons/Qt" \
21+
"$@" \
22+
src 2> "$BUILD_DIR/cppcheck.xml"
23+
if [ -r "$BUILD_DIR/cppcheck.xml" ]; then
24+
cppcheck-htmlreport \
25+
--title="PlanetaryImager cppcheck report" \
26+
--file="$BUILD_DIR/cppcheck.xml" \
27+
--report-dir="$BUILD_DIR/cppcheck" \
28+
--source-dir="$PROJECT_DIR"
29+
fi

src/commons/commandline.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ using namespace std::placeholders;
3131

3232
DPTR_IMPL(CommandLine) {
3333
QCoreApplication &app;
34-
CommandLine *q;
3534
QCommandLineParser parser;
3635
void loggingOptions();
3736
};
@@ -46,7 +45,7 @@ void CommandLine::Private::loggingOptions()
4645
}
4746

4847

49-
CommandLine::CommandLine(QCoreApplication& app) : dptr(app, this)
48+
CommandLine::CommandLine(QCoreApplication& app) : dptr(app)
5049
{
5150
d->parser.addHelpOption();
5251
d->parser.addVersionOption();

src/commons/commandline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class QCoreApplication;
2626
class CommandLine
2727
{
2828
public:
29-
CommandLine(QCoreApplication &app);
29+
explicit CommandLine(QCoreApplication &app);
3030
~CommandLine();
3131
CommandLine &backend();
3232
CommandLine &daemon(const QString &listenAddress = "0.0.0.0");

src/commons/configuration.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ template<typename T> void Configuration::Private::set(const QString& key, const
7676
{
7777
settings->setValue(key, value);
7878
values_cache[key] = value;
79-
emit q->settings_changed();
79+
emit this->q->settings_changed();
8080
}
8181

8282

@@ -295,8 +295,3 @@ void Configuration::Preset::save(const QVariantMap& presets)
295295
}
296296
file.write(QJsonDocument::fromVariant(presets).toJson());
297297
}
298-
299-
300-
301-
302-
#include "configuration.moc"

src/commons/crashhandler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
class CrashHandler {
2525
public:
26-
CrashHandler(const std::list<int> &install_signals);
27-
CrashHandler(const std::initializer_list<int> &install_signals);
26+
explicit CrashHandler(const std::list<int> &install_signals);
27+
explicit CrashHandler(const std::initializer_list<int> &install_signals);
2828
~CrashHandler();
2929
};
3030

src/commons/exposuretimer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,3 @@ void ExposureTimer::Private::finished()
7676
timer->stop();
7777
emit q->finished();
7878
}
79-
80-
#include "exposuretimer.moc"

src/commons/filesystembrowser.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,4 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*
1717
*/
18-
1918
#include "filesystembrowser.h"
20-
#include "filesystembrowser.moc"
21-

src/commons/fps_counter.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,3 @@ fps_counter& fps_counter::operator++()
7979
d->timeout();
8080
return *this;
8181
}
82-
83-
84-
85-
#include "fps_counter.moc"

src/commons/messageslogger.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,3 @@ MessagesLogger * MessagesLogger::instance()
4545
static MessagesLogger *instance = new MessagesLogger;
4646
return instance;
4747
}
48-
49-
50-
#include "messageslogger.moc"

src/commons/ser_header.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ int SER_Header::bytesPerPixel() const
5858

5959
Frame::ColorFormat SER_Header::frame_color_format() const
6060
{
61-
for(auto format: color_format_conversion()) {
62-
if(format.second == static_cast<ColorId>(colorId))
63-
return format.first;
64-
}
61+
auto formats = color_format_conversion();
62+
auto format_it = find_if(begin(formats), end(formats), [this](auto format) {
63+
return format.second == static_cast<ColorId>(this->colorId);
64+
});
65+
return format_it == end(formats) ? Frame::Mono : format_it->first;
6566
}
6667

6768
void SER_Header::set_color_format(const Frame::ColorFormat& format)

0 commit comments

Comments
 (0)