Newer
Older
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/IWorkspaceProperty.h"
#include "MantidKernel/DateAndTimeHelpers.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"
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
#include <QIcon>
#include <QLabel>
Gigg, Martyn Anthony
committed
#include <QLineEdit>
Gigg, Martyn Anthony
committed
#include <QPushButton>
#include <Poco/ActiveResult.h>
Gigg, Martyn Anthony
committed
using namespace MantidQt::API;
using namespace Mantid::Kernel::DateAndTimeHelpers;
using Mantid::Types::Core::DateAndTime;
Gigg, Martyn Anthony
committed
namespace {
Mantid::Kernel::Logger g_log("AlgorithmDialog");
Gigg, Martyn Anthony
committed
//------------------------------------------------------
// 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) {
Gigg, Martyn Anthony
committed
}
/**
* Destructor
*/
AlgorithmDialog::~AlgorithmDialog() {
if (m_statusTracked) {
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 {
if (m_keepOpenCheckBox) {
retval = m_keepOpenCheckBox->isVisible();
}
return retval;
Gigg, Martyn Anthony
committed
}
/**
* Create the layout for this dialog.
*
* 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.
Gigg, Martyn Anthony
committed
*/
void AlgorithmDialog::initializeLayout() {
if (isInitialized())
return;
Gigg, Martyn Anthony
committed
// Set a common title
setWindowTitle(QString::fromStdString(getAlgorithm()->name()) +
" input dialog");
// Set the icon
Gigg, Martyn Anthony
committed
setWindowIcon(QIcon(":/MantidPlot_Icon_32offset.png"));
// These containers are for ensuring the 'replace input workspace; button
// works correctly
Gigg, Martyn Anthony
committed
// Store all combo boxes that relate to an input workspace
Gigg, Martyn Anthony
committed
m_inputws_opts.clear();
Gigg, Martyn Anthony
committed
// Store all line edit fields that relate to an output workspace name
Gigg, Martyn Anthony
committed
m_outputws_fields.clear();
// Keep track of the input workspace that has been used to fill the output
// workspace. Each button click
Gigg, Martyn Anthony
committed
// cycles through all of the input workspaces
Gigg, Martyn Anthony
committed
m_wsbtn_tracker.clear();
Gigg, Martyn Anthony
committed
// This derived class function creates the layout of the widget. It can also
// add default input if the
Gigg, Martyn Anthony
committed
// dialog has been written this way
Gigg, Martyn Anthony
committed
this->initLayout();
Gigg, Martyn Anthony
committed
if (m_autoParseOnInit) {
// Check if there is any default input
this->parse();
// Unless told not to, try to set these values. This will validate the
// defaults and mark those that are invalid, if any.
this->setPropertyValues();
}
Gigg, Martyn Anthony
committed
executeOnAccept(true);
connect(this, SIGNAL(algCompletedSignal()), this, SLOT(algorithmCompleted()));
Gigg, Martyn Anthony
committed
m_isInitialized = true;
Gigg, Martyn Anthony
committed
}
/**
* Has this dialog been initialized yet
* @returns Whether initialzedLayout has been called yet
*/
bool AlgorithmDialog::isInitialized() const { return m_isInitialized; }
Gigg, Martyn Anthony
committed
//------------------------------------------------------
// Protected member functions
//------------------------------------------------------
Gigg, Martyn Anthony
committed
/**
* Parse input from widgets on the dialog. This function does nothing in the
Gigg, Martyn Anthony
committed
* base class
*/
void AlgorithmDialog::parseInput() {}
Janik Zikovsky
committed
//-------------------------------------------------------------------------------------------------
Gigg, Martyn Anthony
committed
/**
* Save the property values to the input history
*/
void AlgorithmDialog::saveInput() {
Gigg, Martyn Anthony
committed
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()) {
Gigg, Martyn Anthony
committed
QString pName = *pitr;
QString value = m_propertyValueMap.value(pName);
AlgorithmInputHistory::Instance().storeNewValue(
m_algName, QPair<QString, QString>(pName, value));
Gigg, Martyn Anthony
committed
}
}
}
Janik Zikovsky
committed
//-------------------------------------------------------------------------------------------------
Gigg, Martyn Anthony
committed
/**
* Set the algorithm pointer
* @param alg :: A pointer to the algorithm
*/
void AlgorithmDialog::setAlgorithm(Mantid::API::IAlgorithm_sptr alg) {
Gigg, Martyn Anthony
committed
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) {
Gigg, Martyn Anthony
committed
Mantid::Kernel::Property *p = *itr;
if (dynamic_cast<Mantid::API::IWorkspaceProperty *>(p) ||
p->direction() != Mantid::Kernel::Direction::Output) {
m_algProperties.append(QString::fromStdString(p->name()));
Gigg, Martyn Anthony
committed
}
}
Gigg, Martyn Anthony
committed
m_validators.clear();
m_noValidation.clear();
}
Gigg, Martyn Anthony
committed
/**
* Get the algorithm pointer
* @returns A pointer to the algorithm that is associated with the dialog
*/
Loading
Loading full blame...