From 0b8af4fff797b37510e76a251ff1bed1f12630a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 13 Mar 2023 15:44:00 +0100 Subject: [PATCH] some minor `QtCharts` usage cleanups (#4890) --- .github/workflows/CI-unixish.yml | 4 ++-- .github/workflows/asan.yml | 4 ++-- .github/workflows/selfcheck.yml | 6 +++--- .github/workflows/tsan.yml | 4 ++-- .github/workflows/ubsan.yml | 4 ++-- gui/CMakeLists.txt | 1 - gui/gui.pro | 1 - gui/statsdialog.cpp | 15 +++++++++------ gui/statsdialog.h | 20 -------------------- 9 files changed, 20 insertions(+), 39 deletions(-) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index da3b62a77..18ee4f427 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -459,9 +459,9 @@ jobs: ./cppcheck $selfcheck_options --cppcheck-build-dir=b1 --addon=naming.json -DCHECK_INTERNAL cli lib || ec=1 # check gui with qt settings mkdir b2 - ./cppcheck $selfcheck_options --cppcheck-build-dir=b2 -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1 + ./cppcheck $selfcheck_options --cppcheck-build-dir=b2 -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1 # self check test and tools ./cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1 # triage - ./cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1 + ./cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1 exit $ec \ No newline at end of file diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index ff59f86b5..873c5cfca 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -75,7 +75,7 @@ jobs: selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings" ec=0 ./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json -DCHECK_INTERNAL cli lib || ec=1 - ./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1 + ./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1 ./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1 - ./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage/*.cpp || ec=1 + ./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage/*.cpp || ec=1 exit $ec diff --git a/.github/workflows/selfcheck.yml b/.github/workflows/selfcheck.yml index 1e2307f28..8cd028f9a 100644 --- a/.github/workflows/selfcheck.yml +++ b/.github/workflows/selfcheck.yml @@ -68,7 +68,7 @@ jobs: - name: Self check (unusedFunction) if: false # TODO: fails with preprocessorErrorDirective - see #10667 run: | - ./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --enable=unusedFunction --exception-handling -rp=. --project=cmake.output/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr + ./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --enable=unusedFunction --exception-handling -rp=. --project=cmake.output/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr env: DISABLE_VALUEFLOW: 1 UNUSEDFUNCTION_ONLY: 1 @@ -89,7 +89,7 @@ jobs: # TODO: find a way to report unmatched suppressions without need to add information checks - name: Self check (unusedFunction / no test) run: | - ./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.notest/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr + ./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.notest/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr env: DISABLE_VALUEFLOW: 1 UNUSEDFUNCTION_ONLY: 1 @@ -115,7 +115,7 @@ jobs: - name: Self check (unusedFunction / corpus / no test / callgrind) run: | # TODO: fix -rp so the suppressions actually work - valgrind --tool=callgrind ./cppcheck --template=selfcheck --error-exitcode=0 --library=cppcheck-lib --library=qt -D__GNUC__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.corpus/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr 2>callgrind.log || (cat callgrind.log && false) + valgrind --tool=callgrind ./cppcheck --template=selfcheck --error-exitcode=0 --library=cppcheck-lib --library=qt -D__GNUC__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.corpus/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr 2>callgrind.log || (cat callgrind.log && false) cat callgrind.log callgrind_annotate --auto=no > callgrind.annotated.log head -50 callgrind.annotated.log diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml index 3e7cf819a..d776d1556 100644 --- a/.github/workflows/tsan.yml +++ b/.github/workflows/tsan.yml @@ -61,7 +61,7 @@ jobs: selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=0 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings" ec=0 ./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json -DCHECK_INTERNAL cli lib || ec=1 - ./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1 + ./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1 ./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1 - ./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1 + ./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1 exit $ec diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml index c422c7272..0370c83e7 100644 --- a/.github/workflows/ubsan.yml +++ b/.github/workflows/ubsan.yml @@ -73,7 +73,7 @@ jobs: selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings" ec=0 ./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json -DCHECK_INTERNAL cli lib || ec=1 - ./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1 + ./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1 ./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1 - ./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage/*.cpp || ec=1 + ./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 -DQT_CHARTS_LIB --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage/*.cpp || ec=1 exit $ec diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index e319c35b0..1759ace96 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -55,7 +55,6 @@ CheckOptions: endif() target_link_libraries(cppcheck-gui ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB} ${QT_PRINTSUPPORT_LIB} ${QT_HELP_LIB} ${QT_NETWORK_LIB}) if(WITH_QCHART) - target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART) target_link_libraries(cppcheck-gui ${QT_CHARTS_LIB}) endif() if (BUILD_CORE_DLL) diff --git a/gui/gui.pro b/gui/gui.pro index 49f6e37fc..e1a3a94d5 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -214,7 +214,6 @@ contains(QMAKE_CXX, clang++) { contains(HAVE_QCHART, [yY][eE][sS]) { QT += charts - DEFINES += HAVE_QCHART } else { message("Charts disabled - to enable it pass HAVE_QCHART=yes to qmake.") } diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index 6f74dd852..b99a96c04 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -35,7 +35,7 @@ #include #include -#ifdef HAVE_QCHART +#ifdef QT_CHARTS_LIB #include #include #include @@ -44,8 +44,11 @@ #include #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) -using namespace QtCharts; +QT_CHARTS_USE_NAMESPACE #endif + +static QLineSeries *numberOfReports(const QString &fileName, const QString &severity); +static QChartView *createChart(const QString &statsFile, const QString &tool); #endif static const QString CPPCHECK("cppcheck"); @@ -76,7 +79,7 @@ void StatsDialog::setProject(const ProjectFile* projectFile) mUI->mIncludePaths->setText(projectFile->getIncludeDirs().join(";")); mUI->mDefines->setText(projectFile->getDefines().join(";")); mUI->mUndefines->setText(projectFile->getUndefines().join(";")); -#ifndef HAVE_QCHART +#ifndef QT_CHARTS_LIB mUI->mTabHistory->setVisible(false); #else QString statsFile; @@ -356,8 +359,8 @@ void StatsDialog::setStatistics(const CheckStatistics *stats) mUI->mLblInformation->setText(QString("%1").arg(stats->getCount(CPPCHECK,ShowTypes::ShowInformation))); } -#ifdef HAVE_QCHART -QChartView *StatsDialog::createChart(const QString &statsFile, const QString &tool) +#ifdef QT_CHARTS_LIB +QChartView *createChart(const QString &statsFile, const QString &tool) { QChart *chart = new QChart; chart->addSeries(numberOfReports(statsFile, tool + "-error")); @@ -399,7 +402,7 @@ QChartView *StatsDialog::createChart(const QString &statsFile, const QString &to return chartView; } -QLineSeries *StatsDialog::numberOfReports(const QString &fileName, const QString &severity) const +QLineSeries *numberOfReports(const QString &fileName, const QString &severity) { QLineSeries *series = new QLineSeries(); series->setName(severity); diff --git a/gui/statsdialog.h b/gui/statsdialog.h index b1b678252..de2f5cda8 100644 --- a/gui/statsdialog.h +++ b/gui/statsdialog.h @@ -29,17 +29,6 @@ namespace Ui { class StatsDialog; } -#ifdef HAVE_QCHART -#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) -namespace QtCharts { -#endif -class QChartView; -class QLineSeries; -#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) -} -#endif -#endif - /// @addtogroup GUI /// @{ @@ -81,15 +70,6 @@ public: private slots: void copyToClipboard(); void pdfExport(); -#ifdef HAVE_QCHART -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) - QChartView *createChart(const QString &statsFile, const QString &tool); - QLineSeries *numberOfReports(const QString &fileName, const QString &severity) const; -#else - QtCharts::QChartView *createChart(const QString &statsFile, const QString &tool); - QtCharts::QLineSeries *numberOfReports(const QString &fileName, const QString &severity) const; -#endif -#endif private: Ui::StatsDialog *mUI; const CheckStatistics *mStatistics;