Skip to content

Commit

Permalink
Re #6972. First pass at using the internal help widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Jun 19, 2014
1 parent 2dcef45 commit a751ba8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Expand Up @@ -8,6 +8,8 @@
#include <string>

// forward declaration
class QHelpEngine;
class QString;
class QWidget;

namespace MantidQt
Expand All @@ -33,6 +35,7 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS MantidHelpWindow : public API::MantidHel
virtual void shutdown();

private:
void showHelp(const QString &url);
void openWebpage(const std::string &url);

/// Shared pointer to the process running qt assistant.
Expand All @@ -44,6 +47,8 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS MantidHelpWindow : public API::MantidHel
std::string m_cacheFile;
/// QT assistant executable.
std::string m_assistantExe;
/// The actual help engine
boost::shared_ptr<QHelpEngine> m_helpEngine;
/// Whether this is the very first startup of the helpwindow.
bool m_firstRun;

Expand Down
46 changes: 44 additions & 2 deletions Code/Mantid/MantidQt/MantidWidgets/src/MantidHelpWindow.cpp
@@ -1,4 +1,5 @@
#include "MantidQtMantidWidgets/MantidHelpWindow.h"
#include "MantidQtMantidWidgets/pqHelpWindow.h"
#include "MantidQtAPI/InterfaceManager.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/Logger.h"
Expand All @@ -11,6 +12,7 @@
#include <Poco/Thread.h>
#include <QByteArray>
#include <QDesktopServices>
#include <QHelpEngine>
#include <QProcess>
#include <QString>
#include <QUrl>
Expand Down Expand Up @@ -54,6 +56,9 @@ MantidHelpWindow::MantidHelpWindow(QWidget* parent, Qt::WindowFlags flags) :
m_firstRun(true)
{
this->determineFileLocs();
// TODO confirm that the collection file is available
m_helpEngine = boost::make_shared<QHelpEngine>(QString(m_collectionFile.c_str()));
m_helpEngine->setupData();
}

/// Destructor does nothing.
Expand All @@ -76,6 +81,43 @@ const string stateToStr(const int code)
}
} // ANONYMOUS NAMESPACE

void MantidHelpWindow::showHelp(const QString &url)
{
// help window is a static variable
static boost::shared_ptr<pqHelpWindow> helpWindow;

// bring up the help window if it is showing
if (bool(helpWindow))
{
helpWindow->show();
helpWindow->raise();
if (!url.isEmpty())
{
helpWindow->showPage(url);
}
return;
}

// create a new help window
// TODO set the parent widget
helpWindow = boost::make_shared<pqHelpWindow>(m_helpEngine.get());
// TODO set window title

// show the home page on startup
auto registeredDocs = m_helpEngine->registeredDocumentations();
if (registeredDocs.size() > 0)
{
helpWindow->showHomePage(registeredDocs[0]);
}
helpWindow->show();
helpWindow->raise();
if (!url.isEmpty())
{
helpWindow->showPage(url);
}
}


void MantidHelpWindow::openWebpage(const string &url)
{
g_log.debug() << "open url \"" << url << "\"\n";
Expand Down Expand Up @@ -162,7 +204,7 @@ void MantidHelpWindow::showAlgorithm(const string &name, const int version)
string url(BASE_URL + "algorithms/" + name + versionStr + ".html");
if (name.empty())
url = BASE_URL + "algorithms/index.html";
this->showPage(url);
this->showHelp(QString(url.c_str()));
}
}

Expand Down Expand Up @@ -202,7 +244,7 @@ void MantidHelpWindow::showFitFunction(const std::string &name)
{
url = BASE_URL + "functions/index.html";
}
this->showPage(url);
this->showHelp(QString(url.c_str()));
}
}

Expand Down

0 comments on commit a751ba8

Please sign in to comment.