Skip to content
Snippets Groups Projects
AlgorithmDialog.cpp 36.4 KiB
Newer Older
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/IWorkspaceProperty.h"
#include "MantidKernel/DateAndTimeHelpers.h"
#include "MantidKernel/IPropertySettings.h"
#include "MantidKernel/Logger.h"

#include "MantidQtWidgets/Common/AlgorithmDialog.h"
#include "MantidQtWidgets/Common/AlgorithmInputHistory.h"
#include "MantidQtWidgets/Common/FilePropertyWidget.h"
#include "MantidQtWidgets/Common/HelpWindow.h"
#include "MantidQtWidgets/Common/MantidWidget.h"
#include <QCheckBox>
#include <QCloseEvent>
#include <QComboBox>
#include <QDateTimeEdit>
#include <QHBoxLayout>
#include <QMessageBox>

#include <Poco/ActiveResult.h>
using namespace Mantid::Kernel::DateAndTimeHelpers;
using Mantid::API::IAlgorithm;
using Mantid::Types::Core::DateAndTime;
namespace {
Mantid::Kernel::Logger g_log("AlgorithmDialog");
//------------------------------------------------------
// Public member functions
//------------------------------------------------------
/**
 * Default Constructor
 */
AlgorithmDialog::AlgorithmDialog(QWidget *parent)
    : QDialog(parent), m_algorithm(), m_algName(""), m_algProperties(),
      m_propertyValueMap(), m_tied_properties(), m_forScript(false),
      m_python_arguments(), m_enabled(), m_disabled(), m_strMessage(""),
      m_keepOpen(false), m_msgAvailable(false), m_isInitialized(false),
      m_autoParseOnInit(true), m_validators(), m_noValidation(),
      m_inputws_opts(), m_outputws_fields(), m_wsbtn_tracker(),
      m_keepOpenCheckBox(nullptr), m_okButton(nullptr), m_exitButton(nullptr),
      m_observers(), m_btnTimer(), m_statusTracked(false) {
  m_btnTimer.setSingleShot(true);
AlgorithmDialog::~AlgorithmDialog() {
  m_observers.clear();
    this->stopObserving(m_algorithm);
}

/**
 * Set if the keep open option is shown.
 * This must be set after calling initializeLayout.
 * @param showOption false to hide the control, otherwise true
 */
void AlgorithmDialog::setShowKeepOpen(const bool showOption) {
  if (m_keepOpenCheckBox) {
    // if hidden then turn it off
    if (!showOption) {
      m_keepOpenCheckBox->setCheckState(Qt::CheckState::Unchecked);
    }
    m_keepOpenCheckBox->setVisible(showOption);
  }
}
/**
 * Is the keep open option going to be shown?
 * @returns true if it will be shown
 */
bool AlgorithmDialog::isShowKeepOpen() const {
  bool retval = true;
  if (m_keepOpenCheckBox) {
    retval = m_keepOpenCheckBox->isVisible();
  }
  return retval;
 *
 * The default is to execute the algorithm when accept() is called. This
 * assumes that the AlgorithmManager owns the
 * algorithm pointer as it must survive after the dialog is destroyed.
void AlgorithmDialog::initializeLayout() {
  if (isInitialized())
    return;
  // Set a common title
  setWindowTitle(QString::fromStdString(getAlgorithm()->name()) +
                 " input dialog");
  // Set the icon
  setWindowIcon(QIcon(":/MantidPlot_Icon_32offset.png"));
  // These containers are for ensuring the 'replace input workspace; button
  // works correctly
  // Store all combo boxes that relate to an input workspace
  // Store all line edit fields that relate to an output workspace name
  // Keep track of the input workspace that has been used to fill the output
  // workspace. Each button click
  // cycles through all of the input workspaces
  // This derived class function creates the layout of the widget. It can also
  // add default input if the
    // Check if there is any default input
    // Unless told not to, try to set these values. This will validate the
    // defaults and mark those that are invalid, if any.
  connect(this, SIGNAL(algCompletedSignal()), this, SLOT(algorithmCompleted()));
}

/**
 * Has this dialog been initialized yet
 *  @returns Whether initialzedLayout has been called yet
 */
bool AlgorithmDialog::isInitialized() const { return m_isInitialized; }

//------------------------------------------------------
// Protected member functions
//------------------------------------------------------
 * Parse input from widgets on the dialog. This function does nothing in the
void AlgorithmDialog::parseInput() {}

//-------------------------------------------------------------------------------------------------
/**
 * Save the property values to the input history
 */
void AlgorithmDialog::saveInput() {
  AlgorithmInputHistory::Instance().clearAlgorithmInput(m_algName);
  QStringList::const_iterator pend = m_algProperties.end();
  for (QStringList::const_iterator pitr = m_algProperties.begin(); pitr != pend;
       ++pitr) {
    Mantid::Kernel::Property *p = getAlgorithmProperty(*pitr);
    if (p->remember()) {
      QString pName = *pitr;
      QString value = m_propertyValueMap.value(pName);
      AlgorithmInputHistory::Instance().storeNewValue(
          m_algName, QPair<QString, QString>(pName, value));
//-------------------------------------------------------------------------------------------------
/**
 * Set the algorithm pointer
 * @param alg :: A pointer to the algorithm
 */
void AlgorithmDialog::setAlgorithm(Mantid::API::IAlgorithm_sptr alg) {
  m_algorithm = alg;
  m_algName = QString::fromStdString(alg->name());
  m_algProperties.clear();
  m_tied_properties.clear();
  std::vector<Mantid::Kernel::Property *>::const_iterator iend =
      alg->getProperties().end();
  for (std::vector<Mantid::Kernel::Property *>::const_iterator itr =
           alg->getProperties().begin();
       itr != iend; ++itr) {
    if (dynamic_cast<Mantid::API::IWorkspaceProperty *>(p) ||
        p->direction() != Mantid::Kernel::Direction::Output) {
      m_algProperties.append(QString::fromStdString(p->name()));
/**
 * Get the algorithm pointer
 * @returns A pointer to the algorithm that is associated with the dialog
 */
Loading
Loading full blame...