From 09241030c38e435d046e69e04ae0cd1878cc1db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 20 Jul 2020 11:59:28 +0200 Subject: [PATCH] GUI: Add online help --- gui/gui.pro | 4 ++ gui/help/index.html | 52 ++++++++++++++++++ gui/help/online-help.qhp | 22 ++++++-- gui/helpdialog.cpp | 52 ++++++++++++++++++ gui/helpdialog.h | 36 +++++++++++++ gui/helpdialog.ui | 110 +++++++++++++++++++++++++++++++++++++++ gui/mainwindow.cpp | 12 +++-- 7 files changed, 279 insertions(+), 9 deletions(-) create mode 100644 gui/help/index.html create mode 100644 gui/helpdialog.cpp create mode 100644 gui/helpdialog.h create mode 100644 gui/helpdialog.ui diff --git a/gui/gui.pro b/gui/gui.pro index 7052e4b90..b8d53034d 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -10,6 +10,7 @@ INCLUDEPATH += . \ ../externals/z3/include QT += widgets QT += printsupport +QT += help contains(LINKCORE, [yY][eE][sS]) { LIBS += -l../bin/cppcheck-core @@ -61,6 +62,7 @@ FORMS = about.ui \ application.ui \ file.ui \ functioncontractdialog.ui \ + helpdialog.ui \ mainwindow.ui \ projectfiledialog.ui \ resultsview.ui \ @@ -110,6 +112,7 @@ HEADERS += aboutdialog.h \ filelist.h \ fileviewdialog.h \ functioncontractdialog.h \ + helpdialog.h \ mainwindow.h \ platforms.h \ printablereport.h \ @@ -150,6 +153,7 @@ SOURCES += aboutdialog.cpp \ filelist.cpp \ fileviewdialog.cpp \ functioncontractdialog.cpp \ + helpdialog.cpp \ main.cpp \ mainwindow.cpp\ platforms.cpp \ diff --git a/gui/help/index.html b/gui/help/index.html new file mode 100644 index 000000000..b466002dc --- /dev/null +++ b/gui/help/index.html @@ -0,0 +1,52 @@ + + +Cppcheck GUI + + + +

Cppcheck GUI

+ +

With the Cppcheck GUI you can analyze your code.

+ +

Quick walk through

+ +

Step 1: Create a project.

+ +

Create a new project.

+ +

In the Paths and Defines tab, it is recommended that you import your project file at the top.

+ +

In the Types and Functions tab, try to activate all 3rd party libraries you use (windows, posix, ...).

+ +

In the Analysis tab, leave the default settings to start with.

+ +

In the Warnings options tab, leave the default settings to start with.

+ +

In the Addons tab, leave the default settings to start with.

+ + +

Step 2: Analyze code.

+ +

When the project file has been created, the analysis will start automatically.

+ +

While analysis is performed in the background, you can investigate the warnings.

+ + +

Step 3: Investigate warnings.

+ +

In the toolbar you choose what types of warnings you want to see (error/warning/style/performance/portability/information).

+ +

All warnings are shown in a list. If you select a warning in the list, then details about that warning is shown below the list.

+ +

If you right click on warning(s) then you get a context menu.

+ + +

Step 4: Configuration.

+ +

It is possible to improve configuration to get better analysis. The automatic assumptions are conservative and through configuration those automatic assumptions can be avoided.

+ +

TODO: library, contracts

+ + + + diff --git a/gui/help/online-help.qhp b/gui/help/online-help.qhp index 16ab79981..4bbe8074d 100644 --- a/gui/help/online-help.qhp +++ b/gui/help/online-help.qhp @@ -4,11 +4,25 @@ doc -
+
+
+
+
+
+
+
- + + + + - manual.html + index.html + investigating-warnings.html + preferences.html + projectfiledialog.html + standalone-analysis.html + tagging.html - + diff --git a/gui/helpdialog.cpp b/gui/helpdialog.cpp new file mode 100644 index 000000000..920671834 --- /dev/null +++ b/gui/helpdialog.cpp @@ -0,0 +1,52 @@ +#include "helpdialog.h" +#include "ui_helpdialog.h" + +#include +#include +#include + +void HelpBrowser::setHelpEngine(QHelpEngine *helpEngine) +{ + mHelpEngine = helpEngine; +} + +QVariant HelpBrowser::loadResource(int type, const QUrl &name){ + if (name.scheme() == "qthelp") { + QString url(name.toString()); + while (url.indexOf("/./") > 0) + url.remove(url.indexOf("/./"), 2); + return QVariant(mHelpEngine->fileData(QUrl(url))); + } + return QTextBrowser::loadResource(type, name); +} + +HelpDialog::HelpDialog(QWidget *parent) : + QDialog(parent), + mUi(new Ui::HelpDialog) +{ + mUi->setupUi(this); + + mHelpEngine = new QHelpEngine(QApplication::applicationDirPath() + "/online-help.qhc"); + mHelpEngine->setupData(); + + mUi->contents->addWidget(mHelpEngine->contentWidget()); + mUi->index->addWidget(mHelpEngine->indexWidget()); + + mUi->textBrowser->setHelpEngine(mHelpEngine); + + mUi->textBrowser->setSource(QUrl("qthelp://cppcheck.sourceforge.net/doc/index.html")); + connect(mHelpEngine->contentWidget(), + SIGNAL(linkActivated(QUrl)), + mUi->textBrowser, + SLOT(setSource(QUrl))); + + connect(mHelpEngine->indexWidget(), + SIGNAL(linkActivated(QUrl, QString)), + mUi->textBrowser, + SLOT(setSource(QUrl))); +} + +HelpDialog::~HelpDialog() +{ + delete mUi; +} diff --git a/gui/helpdialog.h b/gui/helpdialog.h new file mode 100644 index 000000000..36e1e7954 --- /dev/null +++ b/gui/helpdialog.h @@ -0,0 +1,36 @@ +#ifndef HELPDIALOG_H +#define HELPDIALOG_H + +#include +#include + +namespace Ui { +class HelpDialog; +} + +class QHelpEngine; + +class HelpBrowser : public QTextBrowser +{ +public: + HelpBrowser(QWidget* parent = 0) : QTextBrowser(parent), mHelpEngine(nullptr) {} + void setHelpEngine(QHelpEngine *helpEngine); + QVariant loadResource (int type, const QUrl& name); +private: + QHelpEngine* mHelpEngine; +}; + +class HelpDialog : public QDialog +{ + Q_OBJECT + +public: + explicit HelpDialog(QWidget *parent = nullptr); + ~HelpDialog(); + +private: + Ui::HelpDialog *mUi; + QHelpEngine* mHelpEngine; +}; + +#endif // HELPDIALOG_H diff --git a/gui/helpdialog.ui b/gui/helpdialog.ui new file mode 100644 index 000000000..bc5ccc706 --- /dev/null +++ b/gui/helpdialog.ui @@ -0,0 +1,110 @@ + + + HelpDialog + + + + 0 + 0 + 635 + 446 + + + + Cppcheck GUI help + + + + + + Qt::Horizontal + + + + + 200 + 16777215 + + + + 0 + + + + Contents + + + + + + + + + + Index + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + HelpBrowser + QTextBrowser +
helpdialog.h
+
+
+ + + + buttonBox + accepted() + HelpDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + HelpDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index d98ea4b6e..5a1e8189f 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -34,20 +34,21 @@ #include "applicationlist.h" #include "aboutdialog.h" #include "common.h" -#include "threadhandler.h" +#include "filelist.h" #include "fileviewdialog.h" #include "functioncontractdialog.h" +#include "helpdialog.h" +#include "librarydialog.h" #include "projectfile.h" #include "projectfiledialog.h" #include "report.h" #include "scratchpad.h" +#include "showtypes.h" #include "statsdialog.h" #include "settingsdialog.h" +#include "threadhandler.h" #include "threadresult.h" #include "translationhandler.h" -#include "filelist.h" -#include "showtypes.h" -#include "librarydialog.h" static const QString OnlineHelpURL("http://cppcheck.net/manual.html"); static const QString compile_commands_json("compile_commands.json"); @@ -1465,7 +1466,8 @@ void MainWindow::openHelpContents() void MainWindow::openOnlineHelp() { - QDesktopServices::openUrl(QUrl(OnlineHelpURL)); + HelpDialog *helpDialog = new HelpDialog; + helpDialog->showMaximized(); } void MainWindow::openProjectFile()