Skip to content

Commit

Permalink
Refs #4494. SentTo option to populate with compatible save algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-Whitley committed Feb 10, 2012
1 parent c482fbb commit 9f55606
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 38 deletions.
62 changes: 33 additions & 29 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,52 +1231,56 @@ void MantidDockWidget::popupMenu(const QPoint & pos)
{
addTableWorkspaceMenuItems(menu);
}
else {}

//Get the names of the programs for the send to option
std::vector<std::string> programNames = (Mantid::Kernel::ConfigService::Instance().getKeys("workspace.sendto.name"));

bool firstPass(true);
//Check to see if any options aren't visible
std::map<std::string,std::string> programVisible;
bool allVisible(false);
for (size_t i = 0; i<programNames.size(); i++)
{
programVisible[programNames[i]] = Mantid::Kernel::ConfigService::Instance().getString("workspace.sendto." + programNames[i] + ".visible");
std::string visible = Mantid::Kernel::ConfigService::Instance().getString("workspace.sendto." + programNames[i] + ".visible");
std::string target = Mantid::Kernel::ConfigService::Instance().getString("workspace.sendto." + programNames[i] + ".target");
if (Mantid::Kernel::ConfigService::Instance().isExecutable(target) && programVisible.find(programNames[i])->second == "Yes")
allVisible = true;
}

if(allVisible == true)
{
m_saveToProgram = new QMenu(tr("Send to"),this);
menu->addMenu(m_saveToProgram);

//Sub-menu for program list
m_programMapper = new QSignalMapper(this);



for (size_t i = 0; i<programNames.size(); i++)
if (Mantid::Kernel::ConfigService::Instance().isExecutable(target) && visible == "Yes")
{
//Find out if visible is selected for any of the programs
std::string visible = Mantid::Kernel::ConfigService::Instance().getString("workspace.sendto." + programNames[i] + ".visible");

if(visible == "Yes")
bool compatible(true);
std::string saveUsing(Mantid::Kernel::ConfigService::Instance().getString("workspace.sendto." + programNames[i] + ".saveusing") );
try
{
Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create(saveUsing);
alg->setPropertyValue("InputWorkspace", selectedWsName.toStdString() );
}
catch(std::exception& ex)
{
//Convert name from std string to QString for use with QAction menu entry
compatible = false;
}
if (compatible != false)
{
if (firstPass == true)
{
m_saveToProgram = new QMenu(tr("Send to"),this);
menu->addMenu(m_saveToProgram);

//Sub-menu for program list
m_programMapper = new QSignalMapper(this);
}
QString name = QString::fromStdString(programNames[i]);
//Setup new menu option for the program
m_program = new QAction(tr(name),this);
connect(m_program,SIGNAL(activated()),m_programMapper,SLOT(map()));
//Send name of program when clicked
m_programMapper->setMapping(m_program, name);
m_saveToProgram->addAction(m_program);
}
}
//Tell the button what to listen for and what to do once clicked
connect(m_programMapper, SIGNAL(mapped(const QString &)), this, SLOT(saveToProgram(const QString &)));

// Set first pass to false so that it doesn't set up another menu entry for all programs.
firstPass = false;
}
}
}

//Tell the button what to listen for and what to do once clicked (if there is anything to connect it will be set to false)
if (firstPass == false)
connect(m_programMapper, SIGNAL(mapped(const QString &)), this, SLOT(saveToProgram(const QString &)));

//Rename is valid for all workspace types
menu->addAction(m_rename);
//separate delete
Expand Down
40 changes: 32 additions & 8 deletions Code/Mantid/MantidPlot/src/SendToProgramDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <map>


//Constructor when adding a new program to the send to list
/**
* Constructor when adding a new program to the send to list
*/
SendToProgramDialog::SendToProgramDialog(QWidget* parent, Qt::WFlags fl)
: QDialog( parent, fl ), validName(false), validTarget(false), validSaveUsing(false)
{
Expand All @@ -44,7 +46,9 @@ SendToProgramDialog::SendToProgramDialog(QWidget* parent, Qt::WFlags fl)
}


//Constructor when editing a program settings
/**
* Constructor when editing a program settings
*/
SendToProgramDialog::SendToProgramDialog(QWidget* parent, QString& programName, std::map<std::string, std::string> programKeysAndDetails, Qt::WFlags fl)
: QDialog(parent, fl), validName(true), validTarget(true), validSaveUsing(true)
{
Expand Down Expand Up @@ -93,7 +97,9 @@ SendToProgramDialog::SendToProgramDialog(QWidget* parent, QString& programName,
connect(m_uiform.saveUsingText, SIGNAL(textChanged(const QString&)), this, SLOT(validateSaveUsing()));
}

//Open up a new file browsing window
/**
* Open up a new file browsing window
*/
void SendToProgramDialog::browse()
{
// (*) Will let all files be selected
Expand All @@ -105,6 +111,9 @@ void SendToProgramDialog::browse()
}


/**
* See whether anything has been entered as a program name.
*/
void SendToProgramDialog::validateName()
{
if (m_uiform.nameText->text() == "")
Expand All @@ -121,6 +130,9 @@ void SendToProgramDialog::validateName()
}


/**
* Make sure the user specified target program is executable.
*/
void SendToProgramDialog::validateTarget()
{
QString filePath = m_uiform.targetText->text();
Expand Down Expand Up @@ -148,14 +160,17 @@ void SendToProgramDialog::validateTarget()
}


/**
* Make sure the user specified save algorithm exists.
*/
void SendToProgramDialog::validateSaveUsing()
{
validSaveUsing = true;
try
{
Mantid::API::AlgorithmManager::Instance().createUnmanaged(m_uiform.saveUsingText->text().toStdString(),-1);
Mantid::API::AlgorithmManager::Instance().create(m_uiform.saveUsingText->text().toStdString() );
}
catch(std::runtime_error&)
catch(std::exception& ex)
{
m_uiform.validateSaveUsing->setVisible(true);
validSaveUsing = false;
Expand All @@ -169,7 +184,10 @@ void SendToProgramDialog::validateSaveUsing()
}


//If a validation passes or fails then a validation of the entire dialog needs to be done to enable or disable the save button.
/**
* If a validation passes or fails then a validation of the entire
* dialog needs to be done to enable or disable the save button.
*/
void SendToProgramDialog::validateAll()
{
//If validation passes on name, target and the save algorithm the save button becomes available for the user to press.
Expand All @@ -180,7 +198,9 @@ void SendToProgramDialog::validateAll()
}


//Save the new program or changes to a program
/**
* Save the new program or changes to a program
*/
void SendToProgramDialog::save()
{
//Collect mandatory information and then check to see if it has been collected (visible will always be true or false and is therefore not collected yet)
Expand Down Expand Up @@ -212,7 +232,11 @@ void SendToProgramDialog::save()
}


//Get the settings (key and detail of what is to go in the config service)
/**
* Get the settings
*
* @return m_settings :: Key and detail of what is to go in the config service
*/
std::pair<std::string, std::map<std::string, std::string> > SendToProgramDialog::getSettings() const
{
return m_settings;
Expand Down
12 changes: 11 additions & 1 deletion Code/Mantid/MantidPlot/src/SendToProgramDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,27 @@ class SendToProgramDialog : public QDialog
std::pair<std::string,std::map<std::string,std::string> > getSettings() const;

private slots:
/// Open up a new file browsing window.
void browse();

/// Validate all user entered fields to enable/disable the save button.
void validateAll();

/// See if user has entered a name for the program.
void validateName();

/// Validate user specified target.
void validateTarget();

/// Validate user specified save algorithm.
void validateSaveUsing();

/// Save the new/edited program.
void save();

private:
bool validName, validTarget, validSaveUsing;
Ui::SendToProgramDialog m_uiform;
//MantidUI * const m_mantidUI;
std::pair<std::string,std::map<std::string,std::string> > m_settings;
};

Expand Down

0 comments on commit 9f55606

Please sign in to comment.