GUI: Add online help

This commit is contained in:
Daniel Marjamäki 2020-07-20 11:59:28 +02:00
parent b812d48397
commit 09241030c3
7 changed files with 279 additions and 9 deletions

View File

@ -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 \

52
gui/help/index.html Normal file
View File

@ -0,0 +1,52 @@
<html>
<head>
<title>Cppcheck GUI</title>
</head>
<body>
<h1>Cppcheck GUI</h1>
<p>With the Cppcheck GUI you can analyze your code.</p>
<h2>Quick walk through</h2>
<h3>Step 1: Create a project.</h3>
<p>Create a new project.</p>
<p>In the <i>Paths and Defines</i> tab, it is recommended that you import your project file at the top.</p>
<p>In the <i>Types and Functions</i> tab, try to activate all 3rd party libraries you use (windows, posix, ...).</p>
<p>In the <i>Analysis</i> tab, leave the default settings to start with.</p>
<p>In the <i>Warnings options</i> tab, leave the default settings to start with.</p>
<p>In the <i>Addons</i> tab, leave the default settings to start with.</p>
<h3>Step 2: Analyze code.</h3>
<p>When the project file has been created, the analysis will start automatically.</p>
<p>While analysis is performed in the background, you can investigate the warnings.</p>
<h3>Step 3: Investigate warnings.</h3>
<p>In the toolbar you choose what types of warnings you want to see (error/warning/style/performance/portability/information).</p>
<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>
<p>If you right click on warning(s) then you get a context menu.</p>
<h3>Step 4: Configuration.</h3>
<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>
<p>TODO: library, contracts</p>
</body>
</html>

View File

@ -4,11 +4,25 @@
<virtualFolder>doc</virtualFolder>
<filterSection>
<toc>
<section title="Manual" ref="manual.html"/>
<section title="Cppcheck GUI help" ref="index.html">
<section title="Investigating warnings" ref="./investigating-warnings.html"/>
<section title="Preferences" ref="./preferences.html"/>
<section title="Project file dialog" ref="./projectfiledialog.html"/>
<section title="Standalone analysis" ref="./standalone-analysis.html"/>
<section title="Tagging" ref="./tagging.html"/>
</section>
</toc>
<keywords/>
<keywords>
<keyword name="Project" ref="./projectfiledialog.html"/>
<keyword name="Tag" ref="./tagging.html"/>
</keywords>
<files>
<file>manual.html</file>
<file>index.html</file>
<file>investigating-warnings.html</file>
<file>preferences.html</file>
<file>projectfiledialog.html</file>
<file>standalone-analysis.html</file>
<file>tagging.html</file>
</files>
</filterSection>
</QtHelpProject>
</QtHelpProject>

52
gui/helpdialog.cpp Normal file
View File

@ -0,0 +1,52 @@
#include "helpdialog.h"
#include "ui_helpdialog.h"
#include <QHelpEngine>
#include <QHelpContentWidget>
#include <QHelpIndexWidget>
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;
}

36
gui/helpdialog.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef HELPDIALOG_H
#define HELPDIALOG_H
#include <QDialog>
#include <QTextBrowser>
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

110
gui/helpdialog.ui Normal file
View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HelpDialog</class>
<widget class="QDialog" name="HelpDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>635</width>
<height>446</height>
</rect>
</property>
<property name="windowTitle">
<string>Cppcheck GUI help</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QTabWidget" name="tabs">
<property name="maximumSize">
<size>
<width>200</width>
<height>16777215</height>
</size>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabContents">
<attribute name="title">
<string>Contents</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QVBoxLayout" name="contents"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabIndex">
<attribute name="title">
<string>Index</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QVBoxLayout" name="index"/>
</item>
</layout>
</widget>
</widget>
<widget class="HelpBrowser" name="textBrowser"/>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>HelpBrowser</class>
<extends>QTextBrowser</extends>
<header>helpdialog.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>HelpDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>HelpDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -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()