GUI: Try to reuse Qt Assistant to show help
This commit is contained in:
parent
69893fa9bc
commit
14dfa035c1
|
@ -0,0 +1,62 @@
|
|||
#include "assistant.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QDir>
|
||||
#include <QLibraryInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
|
||||
Assistant::Assistant()
|
||||
: mProc(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
Assistant::~Assistant()
|
||||
{
|
||||
if (mProc && mProc->state() == QProcess::Running) {
|
||||
mProc->terminate();
|
||||
mProc->waitForFinished(3000);
|
||||
}
|
||||
delete mProc;
|
||||
}
|
||||
|
||||
void Assistant::showDocumentation(const QString &page)
|
||||
{
|
||||
if (!startAssistant())
|
||||
return;
|
||||
|
||||
QByteArray ba("SetSource ");
|
||||
ba.append("qthelp://cppcheck.sourceforge.net/doc/");
|
||||
|
||||
mProc->write(ba + page.toLocal8Bit() + '\n');
|
||||
}
|
||||
|
||||
bool Assistant::startAssistant()
|
||||
{
|
||||
if (!mProc)
|
||||
mProc = new QProcess();
|
||||
|
||||
if (mProc->state() != QProcess::Running) {
|
||||
QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator();
|
||||
#if !defined(Q_OS_MAC)
|
||||
app += QLatin1String("assistant");
|
||||
#else
|
||||
app += QLatin1String("Assistant.app/Contents/MacOS/Assistant");
|
||||
#endif
|
||||
|
||||
QStringList args;
|
||||
args << QLatin1String("-collectionFile")
|
||||
<< QLatin1String("online-help.qhc")
|
||||
<< QLatin1String("-enableRemoteControl");
|
||||
|
||||
mProc->start(app, args);
|
||||
|
||||
if (!mProc->waitForStarted()) {
|
||||
QMessageBox::critical(nullptr,
|
||||
tr("Cppcheck"),
|
||||
tr("Unable to launch Qt Assistant (%1)").arg(app));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef ASSISTANT_H
|
||||
#define ASSISTANT_H
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
class QProcess;
|
||||
|
||||
class Assistant
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Assistant)
|
||||
|
||||
public:
|
||||
Assistant();
|
||||
~Assistant();
|
||||
void showDocumentation(const QString &file);
|
||||
|
||||
private:
|
||||
bool startAssistant();
|
||||
QProcess *mProc;
|
||||
};
|
||||
|
||||
#endif // ASSISTANT_H
|
|
@ -68,7 +68,6 @@ FORMS = about.ui \
|
|||
application.ui \
|
||||
file.ui \
|
||||
functioncontractdialog.ui \
|
||||
helpdialog.ui \
|
||||
mainwindow.ui \
|
||||
projectfiledialog.ui \
|
||||
resultsview.ui \
|
||||
|
@ -106,6 +105,7 @@ HEADERS += aboutdialog.h \
|
|||
application.h \
|
||||
applicationdialog.h \
|
||||
applicationlist.h \
|
||||
assistant.h \
|
||||
checkstatistics.h \
|
||||
checkthread.h \
|
||||
codeeditstylecontrols.h \
|
||||
|
@ -118,7 +118,6 @@ HEADERS += aboutdialog.h \
|
|||
filelist.h \
|
||||
fileviewdialog.h \
|
||||
functioncontractdialog.h \
|
||||
helpdialog.h \
|
||||
mainwindow.h \
|
||||
platforms.h \
|
||||
printablereport.h \
|
||||
|
@ -147,6 +146,7 @@ SOURCES += aboutdialog.cpp \
|
|||
application.cpp \
|
||||
applicationdialog.cpp \
|
||||
applicationlist.cpp \
|
||||
assistant.cpp \
|
||||
checkstatistics.cpp \
|
||||
checkthread.cpp \
|
||||
codeeditorstyle.cpp \
|
||||
|
@ -159,7 +159,6 @@ SOURCES += aboutdialog.cpp \
|
|||
filelist.cpp \
|
||||
fileviewdialog.cpp \
|
||||
functioncontractdialog.cpp \
|
||||
helpdialog.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp\
|
||||
platforms.cpp \
|
||||
|
|
|
@ -1,5 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<QHelpCollectionProject version="1.0">
|
||||
<assistant>
|
||||
<title>Cppcheck GUI</title>
|
||||
<applicationIcon>../cppcheck.ico</applicationIcon>
|
||||
<cacheDirectory>QtProject/Cppcheck</cacheDirectory>
|
||||
<startPage>qthelp://cppcheck.sourceforge.net/doc/index.html</startPage>
|
||||
<aboutMenuText>
|
||||
<text>About Cppcheck</text>
|
||||
</aboutMenuText>
|
||||
<aboutDialog>
|
||||
<file>about.txt</file>
|
||||
<icon>images/icon.png</icon>
|
||||
</aboutDialog>
|
||||
<enableDocumentationManager>false</enableDocumentationManager>
|
||||
<enableAddressBar>false</enableAddressBar>
|
||||
<enableFilterFunctionality>false</enableFilterFunctionality>
|
||||
</assistant>
|
||||
<docFiles>
|
||||
<generate>
|
||||
<file>
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
#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;
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
#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
|
|
@ -1,67 +0,0 @@
|
|||
<?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>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>HelpBrowser</class>
|
||||
<extends>QTextBrowser</extends>
|
||||
<header>helpdialog.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -33,11 +33,11 @@
|
|||
|
||||
#include "applicationlist.h"
|
||||
#include "aboutdialog.h"
|
||||
#include "assistant.h"
|
||||
#include "common.h"
|
||||
#include "filelist.h"
|
||||
#include "fileviewdialog.h"
|
||||
#include "functioncontractdialog.h"
|
||||
#include "helpdialog.h"
|
||||
#include "librarydialog.h"
|
||||
#include "projectfile.h"
|
||||
#include "projectfiledialog.h"
|
||||
|
@ -219,6 +219,8 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
|
|||
mUI.mActionEnforceCpp->setActionGroup(mSelectLanguageActions);
|
||||
mUI.mActionAutoDetectLanguage->setActionGroup(mSelectLanguageActions);
|
||||
|
||||
mAssistant = new Assistant;
|
||||
|
||||
// For Windows platforms default to Win32 checked platform.
|
||||
// For other platforms default to unspecified/default which means the
|
||||
// platform Cppcheck GUI was compiled on.
|
||||
|
@ -235,6 +237,7 @@ MainWindow::~MainWindow()
|
|||
{
|
||||
delete mProjectFile;
|
||||
delete mScratchPad;
|
||||
delete mAssistant;
|
||||
}
|
||||
|
||||
void MainWindow::handleCLIParams(const QStringList ¶ms)
|
||||
|
@ -1466,8 +1469,7 @@ void MainWindow::openHelpContents()
|
|||
|
||||
void MainWindow::openOnlineHelp()
|
||||
{
|
||||
HelpDialog *helpDialog = new HelpDialog;
|
||||
helpDialog->showMaximized();
|
||||
mAssistant->showDocumentation("index.html");
|
||||
}
|
||||
|
||||
void MainWindow::openProjectFile()
|
||||
|
|
|
@ -35,6 +35,7 @@ class TranslationHandler;
|
|||
class ScratchPad;
|
||||
class ProjectFile;
|
||||
class QAction;
|
||||
class Assistant;
|
||||
|
||||
/// @addtogroup GUI
|
||||
/// @{
|
||||
|
@ -458,6 +459,8 @@ private:
|
|||
* List of MRU menu actions. Needs also to store the separator.
|
||||
*/
|
||||
QAction *mRecentProjectActs[MaxRecentProjects + 1];
|
||||
|
||||
Assistant *mAssistant;
|
||||
};
|
||||
/// @}
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -39,10 +39,12 @@
|
|||
</File>
|
||||
<File Id='onlinehelpqhc' Name='online-help.qhc' Source='$(var.GuiHelpDir)\online-help.qhc' />
|
||||
<File Id='onlinehelpqch' Name='online-help.qch' Source='$(var.GuiHelpDir)\online-help.qch' />
|
||||
<File Id='assistantexe' Name='assistant.exe' Source='$(var.QtDllDir)\assistant.exe' />
|
||||
<File Id='Qt5Coredll' Name='Qt5Core.dll' Source='$(var.QtDllDir)\Qt5Core.dll' />
|
||||
<File Id='Qt5Guidll' Name='Qt5Gui.dll' Source='$(var.QtDllDir)\Qt5Gui.dll' />
|
||||
<File Id='Qt5Helpdll' Name='Qt5Help.dll' Source='$(var.QtDllDir)\Qt5Help.dll' />
|
||||
<File Id='Qt5Sqldll' Name='Qt5Sql.dll' Source='$(var.QtDllDir)\Qt5Sql.dll' />
|
||||
<File Id='qsqlitedll' Name='qsqlite.dll' Source='$(var.QtDllDir)\..\plugins\sqldrivers\qsqlite.dll' />
|
||||
<File Id='Qt5Widgetsdll' Name='Qt5Widgets.dll' Source='$(var.QtDllDir)\Qt5Widgets.dll' />
|
||||
<File Id='Qt5PrintSupportdll' Name='Qt5PrintSupport.dll' Source='$(var.QtDllDir)\Qt5PrintSupport.dll' />
|
||||
<?if $(var.Platform) = x64 ?>
|
||||
|
|
Loading…
Reference in New Issue