Skip to content
Snippets Groups Projects
InterfaceManager.h 5.77 KiB
Newer Older
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2009 ISIS Rutherford Appleton Laboratory UKRI,
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +

//----------------------------------
// Includes
//----------------------------------
#include "DllOption.h"
//#include "MantidKernel/SingletonHolder.h"
#include <QHash>

//----------------------------------
// Qt Forward declarations
//----------------------------------
class QWidget;

//----------------------------------
// Mantid forward declarations
//----------------------------------
namespace Mantid {
namespace API {
class IAlgorithm;
} // namespace Mantid
namespace MantidQt {

//----------------------------------
// Forward declarations
//----------------------------------
class AlgorithmDialog;
class MantidHelpInterface;
/**
    This class is responsible for creating the correct dialog for an algorithm.
   If
    no specialized version is registered for that algorithm then the default is
   created

    @author Martyn Gigg, Tessella Support Services plc
    @date 24/02/2009
*/
class EXPORT_OPT_MANTIDQT_COMMON InterfaceManager {
  /// Create a new instance of the correct type of AlgorithmDialog
  AlgorithmDialog *createDialog(
      const boost::shared_ptr<Mantid::API::IAlgorithm> &alg,
      QWidget *parent = nullptr, bool forScript = false,
      const QHash<QString, QString> &presetValues = (QHash<QString, QString>()),
      const QString &optional_msg = QString(),
      const QStringList &enabled = QStringList(),
      const QStringList &disabled = QStringList());

  /// Create an algorithm dialog for a given name and version
  AlgorithmDialog *createDialogFromName(
Peterson, Peter's avatar
Peterson, Peter committed
      const QString &algorithmName, const int version = -1,
      QWidget *parent = nullptr, bool forScript = false,
      const QHash<QString, QString> &presetValues = (QHash<QString, QString>()),
      const QString &optionalMsg = QString(),
      const QStringList &enabled = QStringList(),
      const QStringList &disabled = QStringList());
  /// Create a new instance of the correct type of UserSubWindow
  UserSubWindow *createSubWindow(const QString &interface_name,
                                 QWidget *parent = nullptr,
                                 bool isWindow = true);
  /**
   * Function that instantiates the Vates simple user interface.
   * @return the Vates simple user interface
   */
  VatesViewerInterface *createVatesSimpleGui() const;
  /**
   * Registration function for the Vates simple interface factory.
   * @param factory the factory instance
   */
  static void registerVatesGuiFactory(
      Mantid::Kernel::AbstractInstantiator<VatesViewerInterface> *factory);
  /**
   * Function that instantiates the help window.
   * @return the help window
   */
  MantidHelpInterface *createHelpWindow() const;

  /// @param url Relative URL of help page to show.
  void showHelpPage(const QString &url = QString());

  /// @param page Wiki page to show help for
  void showWikiPage(const QString &page = QString());

  /// @param name of algorithm to show help for
  /// @param version of algorithm
  void showAlgorithmHelp(const QString &name, const int version = -1);

  /// @param name of concept to show help for
  void showConceptHelp(const QString &name);

  /// @param name of fit function to show help for
  void showFitFunctionHelp(const QString &name = QString());

  /// @param name of interface to show help for
  void showCustomInterfaceHelp(const QString &name);

  /// @param url of web page to open in browser
  void showWebPage(const QString &url);

  void closeHelpWindow();

  /**
   * Registration function for the help window factory.
   * @param factory the factory instance
   */
  static void registerHelpWindowFactory(
      Mantid::Kernel::AbstractInstantiator<MantidHelpInterface> *factory);
  /// The keys associated with UserSubWindow classes
  QStringList getUserSubWindowKeys() const;

  /// Getter for vates libraries availablity
  static bool hasVatesLibraries();

  InterfaceManager();
  virtual ~InterfaceManager();
  void notifyExistingInterfaces(UserSubWindow *newWindow);

  /// Handle to the Vates simple user interface factory
  static Mantid::Kernel::AbstractInstantiator<VatesViewerInterface>
      *m_vatesGuiFactory;
  /// Handle to the help window factory
  static Mantid::Kernel::AbstractInstantiator<MantidHelpInterface>
      *m_helpViewer;
} // namespace API
} // namespace MantidQt
#define REGISTER_VATESGUI(TYPE)                                                \
  namespace {                                                                  \
  Mantid::Kernel::RegistrationHelper register_vatesgui(                        \
      ((MantidQt::API::InterfaceManager::registerVatesGuiFactory(              \
           new Mantid::Kernel::Instantiator<TYPE, VatesViewerInterface>())),   \
       0));                                                                    \
  }

/// Used to register help window
#define REGISTER_HELPWINDOW(TYPE)                                              \
  namespace {                                                                  \
  Mantid::Kernel::RegistrationHelper register_helpviewer(                      \
      ((MantidQt::API::InterfaceManager::registerHelpWindowFactory(            \
           new Mantid::Kernel::Instantiator<TYPE, MantidHelpInterface>())),    \
       0));                                                                    \
  }