Skip to content

Commit

Permalink
refs #7664. Implement new menu and options.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Aug 21, 2013
1 parent 3629a31 commit be43df0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
32 changes: 32 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ void MantidDockWidget::createWorkspaceMenuActions()
m_convertMDHistoToMatrixWorkspace = new QAction(tr("Convert to MatrixWorkpace"),this);
m_convertMDHistoToMatrixWorkspace->setIcon(QIcon(getQPixmap("mantid_matrix_xpm")));
connect(m_convertMDHistoToMatrixWorkspace,SIGNAL(triggered()),this,SLOT(convertMDHistoToMatrixWorkspace()));

m_clearUB = new QAction(tr("Clear UB Matrix"), this);
connect(m_clearUB, SIGNAL(activated()), this, SLOT(clearUB()));
}

/**
Expand Down Expand Up @@ -540,6 +543,17 @@ void MantidDockWidget::addTableWorkspaceMenuItems(QMenu * menu) const
menu->addAction(m_convertToMatrixWorkspace);
}

/**
* Add menu for clearing workspace items.
* @param menu : Parent menu.
*/
void MantidDockWidget::addClearMenuItems(QMenu* menu)
{
QMenu* clearMenu = new QMenu(tr("Clear Options"), this);
clearMenu->addAction(m_clearUB);
menu->addMenu(clearMenu);
}

void MantidDockWidget::clickedWorkspace(QTreeWidgetItem* item, int)
{
Q_UNUSED(item);
Expand Down Expand Up @@ -828,6 +842,7 @@ void MantidDockWidget::popupMenu(const QPoint & pos)
{
addTableWorkspaceMenuItems(menu);
}
addClearMenuItems(menu);

//Get the names of the programs for the send to option
std::vector<std::string> programNames = (Mantid::Kernel::ConfigService::Instance().getKeys("workspace.sendto.name"));
Expand Down Expand Up @@ -1016,6 +1031,23 @@ void MantidDockWidget::convertMDHistoToMatrixWorkspace()
m_mantidUI->executeAlgorithm("ConvertMDHistoToMatrixWorkspace",-1);
}

/**
* Handler for the clear the UB matrix event.
*/
void MantidDockWidget::clearUB()
{
QList<QTreeWidgetItem*> selectedItems = m_tree->selectedItems();
QStringList selctedWSNames;
if (!selectedItems.empty())
{
for (int i = 0; i < selectedItems.size(); ++i)
{
selctedWSNames.append(selectedItems[i]->text(0));
}
}
m_mantidUI->clearUB(selctedWSNames);
}

//------------ MantidTreeWidget -----------------------//

MantidTreeWidget::MantidTreeWidget(MantidDockWidget *w, MantidUI *mui)
Expand Down
5 changes: 4 additions & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private slots:
void convertMDHistoToMatrixWorkspace();
void updateTree();
void incrementUpdateCount();
void clearUB();

private:
void setTreeUpdating(const bool state);
Expand All @@ -96,6 +97,7 @@ private slots:
void addPeaksWorkspaceMenuItems(QMenu *menu, const Mantid::API::IPeaksWorkspace_const_sptr & WS) const;
void addWorkspaceGroupMenuItems(QMenu *menu) const;
void addTableWorkspaceMenuItems(QMenu * menu) const;
void addClearMenuItems(QMenu* menu);

void excludeItemFromSort(MantidTreeWidgetItem *item);

Expand Down Expand Up @@ -126,7 +128,8 @@ private slots:
*m_program, * m_ascendingSortAction,
*m_descendingSortAction, *m_byNameChoice, *m_byLastModifiedChoice, *m_showTransposed,
*m_convertToMatrixWorkspace,
*m_convertMDHistoToMatrixWorkspace;
*m_convertMDHistoToMatrixWorkspace,
*m_clearUB;

QAtomicInt m_updateCount;
bool m_treeUpdating;
Expand Down
26 changes: 26 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,32 @@ void MantidUI::copyWorkspacestoVector(const QList<QTreeWidgetItem*> &selectedIt
}//end of for loop for input workspaces
}

/**
* Clears the UB from the selected workspace
* @param wsName :: selected workspace name
*/
void MantidUI::clearUB(const QStringList& wsName)
{
const std::string algName("ClearUB");
const int version = -1;
for(int i = 0; i < wsName.size(); ++i)
{
Mantid::API::IAlgorithm_sptr alg;
try
{
alg = Mantid::API::AlgorithmManager::Instance().create(algName, version);
}
catch(...)
{
QMessageBox::critical(appWindow(),"MantidPlot - Algorithm error","Cannot create algorithm "+QString::fromStdString(algName)+" version "+QString::number(version));
return;
}
alg->initialize();
alg->setPropertyValue("Workspace", wsName[i].toStdString());
alg->execute();
}
}

/**
* Renames selected workspace
* @param wsName :: selected workspace name
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public slots:
Table* createDetectorTable(const QString & wsName, const Mantid::API::IPeaksWorkspace_sptr & ws);


// Clear the UB via the ClearUB algorithm
void clearUB(const QStringList& workspaces);
// ***** ***** //
void renameWorkspace(QStringList = QStringList());

Expand Down

0 comments on commit be43df0

Please sign in to comment.