Skip to content

Commit 0924103

Browse files
committed
GUI: Add online help
1 parent b812d48 commit 0924103

7 files changed

Lines changed: 279 additions & 9 deletions

File tree

gui/gui.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ INCLUDEPATH += . \
1010
../externals/z3/include
1111
QT += widgets
1212
QT += printsupport
13+
QT += help
1314

1415
contains(LINKCORE, [yY][eE][sS]) {
1516
LIBS += -l../bin/cppcheck-core
@@ -61,6 +62,7 @@ FORMS = about.ui \
6162
application.ui \
6263
file.ui \
6364
functioncontractdialog.ui \
65+
helpdialog.ui \
6466
mainwindow.ui \
6567
projectfiledialog.ui \
6668
resultsview.ui \
@@ -110,6 +112,7 @@ HEADERS += aboutdialog.h \
110112
filelist.h \
111113
fileviewdialog.h \
112114
functioncontractdialog.h \
115+
helpdialog.h \
113116
mainwindow.h \
114117
platforms.h \
115118
printablereport.h \
@@ -150,6 +153,7 @@ SOURCES += aboutdialog.cpp \
150153
filelist.cpp \
151154
fileviewdialog.cpp \
152155
functioncontractdialog.cpp \
156+
helpdialog.cpp \
153157
main.cpp \
154158
mainwindow.cpp\
155159
platforms.cpp \

gui/help/index.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<html>
2+
<head>
3+
<title>Cppcheck GUI</title>
4+
</head>
5+
<body>
6+
7+
<h1>Cppcheck GUI</h1>
8+
9+
<p>With the Cppcheck GUI you can analyze your code.</p>
10+
11+
<h2>Quick walk through</h2>
12+
13+
<h3>Step 1: Create a project.</h3>
14+
15+
<p>Create a new project.</p>
16+
17+
<p>In the <i>Paths and Defines</i> tab, it is recommended that you import your project file at the top.</p>
18+
19+
<p>In the <i>Types and Functions</i> tab, try to activate all 3rd party libraries you use (windows, posix, ...).</p>
20+
21+
<p>In the <i>Analysis</i> tab, leave the default settings to start with.</p>
22+
23+
<p>In the <i>Warnings options</i> tab, leave the default settings to start with.</p>
24+
25+
<p>In the <i>Addons</i> tab, leave the default settings to start with.</p>
26+
27+
28+
<h3>Step 2: Analyze code.</h3>
29+
30+
<p>When the project file has been created, the analysis will start automatically.</p>
31+
32+
<p>While analysis is performed in the background, you can investigate the warnings.</p>
33+
34+
35+
<h3>Step 3: Investigate warnings.</h3>
36+
37+
<p>In the toolbar you choose what types of warnings you want to see (error/warning/style/performance/portability/information).</p>
38+
39+
<p>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.</p>
40+
41+
<p>If you right click on warning(s) then you get a context menu.</p>
42+
43+
44+
<h3>Step 4: Configuration.</h3>
45+
46+
<p>It is possible to improve configuration to get better analysis. The automatic assumptions are conservative and through configuration those automatic assumptions can be avoided.</p>
47+
48+
<p>TODO: library, contracts</p>
49+
50+
</body>
51+
</html>
52+

gui/help/online-help.qhp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@
44
<virtualFolder>doc</virtualFolder>
55
<filterSection>
66
<toc>
7-
<section title="Manual" ref="manual.html"/>
7+
<section title="Cppcheck GUI help" ref="index.html">
8+
<section title="Investigating warnings" ref="./investigating-warnings.html"/>
9+
<section title="Preferences" ref="./preferences.html"/>
10+
<section title="Project file dialog" ref="./projectfiledialog.html"/>
11+
<section title="Standalone analysis" ref="./standalone-analysis.html"/>
12+
<section title="Tagging" ref="./tagging.html"/>
13+
</section>
814
</toc>
9-
<keywords/>
15+
<keywords>
16+
<keyword name="Project" ref="./projectfiledialog.html"/>
17+
<keyword name="Tag" ref="./tagging.html"/>
18+
</keywords>
1019
<files>
11-
<file>manual.html</file>
20+
<file>index.html</file>
21+
<file>investigating-warnings.html</file>
22+
<file>preferences.html</file>
23+
<file>projectfiledialog.html</file>
24+
<file>standalone-analysis.html</file>
25+
<file>tagging.html</file>
1226
</files>
1327
</filterSection>
14-
</QtHelpProject>
28+
</QtHelpProject>

gui/helpdialog.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "helpdialog.h"
2+
#include "ui_helpdialog.h"
3+
4+
#include <QHelpEngine>
5+
#include <QHelpContentWidget>
6+
#include <QHelpIndexWidget>
7+
8+
void HelpBrowser::setHelpEngine(QHelpEngine *helpEngine)
9+
{
10+
mHelpEngine = helpEngine;
11+
}
12+
13+
QVariant HelpBrowser::loadResource(int type, const QUrl &name){
14+
if (name.scheme() == "qthelp") {
15+
QString url(name.toString());
16+
while (url.indexOf("/./") > 0)
17+
url.remove(url.indexOf("/./"), 2);
18+
return QVariant(mHelpEngine->fileData(QUrl(url)));
19+
}
20+
return QTextBrowser::loadResource(type, name);
21+
}
22+
23+
HelpDialog::HelpDialog(QWidget *parent) :
24+
QDialog(parent),
25+
mUi(new Ui::HelpDialog)
26+
{
27+
mUi->setupUi(this);
28+
29+
mHelpEngine = new QHelpEngine(QApplication::applicationDirPath() + "/online-help.qhc");
30+
mHelpEngine->setupData();
31+
32+
mUi->contents->addWidget(mHelpEngine->contentWidget());
33+
mUi->index->addWidget(mHelpEngine->indexWidget());
34+
35+
mUi->textBrowser->setHelpEngine(mHelpEngine);
36+
37+
mUi->textBrowser->setSource(QUrl("qthelp://cppcheck.sourceforge.net/doc/index.html"));
38+
connect(mHelpEngine->contentWidget(),
39+
SIGNAL(linkActivated(QUrl)),
40+
mUi->textBrowser,
41+
SLOT(setSource(QUrl)));
42+
43+
connect(mHelpEngine->indexWidget(),
44+
SIGNAL(linkActivated(QUrl, QString)),
45+
mUi->textBrowser,
46+
SLOT(setSource(QUrl)));
47+
}
48+
49+
HelpDialog::~HelpDialog()
50+
{
51+
delete mUi;
52+
}

gui/helpdialog.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef HELPDIALOG_H
2+
#define HELPDIALOG_H
3+
4+
#include <QDialog>
5+
#include <QTextBrowser>
6+
7+
namespace Ui {
8+
class HelpDialog;
9+
}
10+
11+
class QHelpEngine;
12+
13+
class HelpBrowser : public QTextBrowser
14+
{
15+
public:
16+
HelpBrowser(QWidget* parent = 0) : QTextBrowser(parent), mHelpEngine(nullptr) {}
17+
void setHelpEngine(QHelpEngine *helpEngine);
18+
QVariant loadResource (int type, const QUrl& name);
19+
private:
20+
QHelpEngine* mHelpEngine;
21+
};
22+
23+
class HelpDialog : public QDialog
24+
{
25+
Q_OBJECT
26+
27+
public:
28+
explicit HelpDialog(QWidget *parent = nullptr);
29+
~HelpDialog();
30+
31+
private:
32+
Ui::HelpDialog *mUi;
33+
QHelpEngine* mHelpEngine;
34+
};
35+
36+
#endif // HELPDIALOG_H

gui/helpdialog.ui

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>HelpDialog</class>
4+
<widget class="QDialog" name="HelpDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>635</width>
10+
<height>446</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Cppcheck GUI help</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<item>
18+
<widget class="QSplitter" name="splitter">
19+
<property name="orientation">
20+
<enum>Qt::Horizontal</enum>
21+
</property>
22+
<widget class="QTabWidget" name="tabs">
23+
<property name="maximumSize">
24+
<size>
25+
<width>200</width>
26+
<height>16777215</height>
27+
</size>
28+
</property>
29+
<property name="currentIndex">
30+
<number>0</number>
31+
</property>
32+
<widget class="QWidget" name="tabContents">
33+
<attribute name="title">
34+
<string>Contents</string>
35+
</attribute>
36+
<layout class="QVBoxLayout" name="verticalLayout_5">
37+
<item>
38+
<layout class="QVBoxLayout" name="contents"/>
39+
</item>
40+
</layout>
41+
</widget>
42+
<widget class="QWidget" name="tabIndex">
43+
<attribute name="title">
44+
<string>Index</string>
45+
</attribute>
46+
<layout class="QVBoxLayout" name="verticalLayout_3">
47+
<item>
48+
<layout class="QVBoxLayout" name="index"/>
49+
</item>
50+
</layout>
51+
</widget>
52+
</widget>
53+
<widget class="HelpBrowser" name="textBrowser"/>
54+
</widget>
55+
</item>
56+
<item>
57+
<widget class="QDialogButtonBox" name="buttonBox">
58+
<property name="orientation">
59+
<enum>Qt::Horizontal</enum>
60+
</property>
61+
<property name="standardButtons">
62+
<set>QDialogButtonBox::Close</set>
63+
</property>
64+
</widget>
65+
</item>
66+
</layout>
67+
</widget>
68+
<customwidgets>
69+
<customwidget>
70+
<class>HelpBrowser</class>
71+
<extends>QTextBrowser</extends>
72+
<header>helpdialog.h</header>
73+
</customwidget>
74+
</customwidgets>
75+
<resources/>
76+
<connections>
77+
<connection>
78+
<sender>buttonBox</sender>
79+
<signal>accepted()</signal>
80+
<receiver>HelpDialog</receiver>
81+
<slot>accept()</slot>
82+
<hints>
83+
<hint type="sourcelabel">
84+
<x>248</x>
85+
<y>254</y>
86+
</hint>
87+
<hint type="destinationlabel">
88+
<x>157</x>
89+
<y>274</y>
90+
</hint>
91+
</hints>
92+
</connection>
93+
<connection>
94+
<sender>buttonBox</sender>
95+
<signal>rejected()</signal>
96+
<receiver>HelpDialog</receiver>
97+
<slot>reject()</slot>
98+
<hints>
99+
<hint type="sourcelabel">
100+
<x>316</x>
101+
<y>260</y>
102+
</hint>
103+
<hint type="destinationlabel">
104+
<x>286</x>
105+
<y>274</y>
106+
</hint>
107+
</hints>
108+
</connection>
109+
</connections>
110+
</ui>

gui/mainwindow.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,21 @@
3434
#include "applicationlist.h"
3535
#include "aboutdialog.h"
3636
#include "common.h"
37-
#include "threadhandler.h"
37+
#include "filelist.h"
3838
#include "fileviewdialog.h"
3939
#include "functioncontractdialog.h"
40+
#include "helpdialog.h"
41+
#include "librarydialog.h"
4042
#include "projectfile.h"
4143
#include "projectfiledialog.h"
4244
#include "report.h"
4345
#include "scratchpad.h"
46+
#include "showtypes.h"
4447
#include "statsdialog.h"
4548
#include "settingsdialog.h"
49+
#include "threadhandler.h"
4650
#include "threadresult.h"
4751
#include "translationhandler.h"
48-
#include "filelist.h"
49-
#include "showtypes.h"
50-
#include "librarydialog.h"
5152

5253
static const QString OnlineHelpURL("http://cppcheck.net/manual.html");
5354
static const QString compile_commands_json("compile_commands.json");
@@ -1465,7 +1466,8 @@ void MainWindow::openHelpContents()
14651466

14661467
void MainWindow::openOnlineHelp()
14671468
{
1468-
QDesktopServices::openUrl(QUrl(OnlineHelpURL));
1469+
HelpDialog *helpDialog = new HelpDialog;
1470+
helpDialog->showMaximized();
14691471
}
14701472

14711473
void MainWindow::openProjectFile()

0 commit comments

Comments
 (0)