Skip to content

Commit

Permalink
Refs #11040 Additional check for drag and drop for VSI
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonPiccardoSelg committed Feb 10, 2015
1 parent 9a42252 commit bb31f01
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
Expand Up @@ -180,8 +180,8 @@ protected slots:
bool checkIfTechniqueContainsKeyword(const std::set<std::string>& techniques, const std::string& keyword) const;
/// Reset the current view to the appropriate initial view.
void resetCurrentView(int workspaceType, const std::string& instrumentName);
/// Drag and drop PeaksWorkspace
void createPeakWorkspaceViaDragAndDrop(QStringList workspaces);
/// Handle drag and drop of peaks workspcaes
void handleDragAndDropPeaksWorkspaces(QEvent* e, QString text, QStringList& wsNames);
};

} // SimpleGui
Expand Down
67 changes: 31 additions & 36 deletions Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp
Expand Up @@ -1108,19 +1108,8 @@ void MdViewerWidget::dragEnterEvent(QDragEnterEvent *e) {
QString name = e->mimeData()->objectName();
if (name == "MantidWorkspace") {
QString text = e->mimeData()->text();
int endIndex = 0;
QStringList wsNames;
while (text.indexOf("[\"", endIndex) > -1) {
int startIndex = text.indexOf("[\"", endIndex) + 2;
endIndex = text.indexOf("\"]", startIndex);
QString candidate = text.mid(startIndex, endIndex - startIndex);
if(boost::dynamic_pointer_cast<IPeaksWorkspace>(AnalysisDataService::Instance().retrieve(candidate.toStdString()))){
e->accept();
}
else{
e->ignore();
}
}
handleDragAndDropPeaksWorkspaces(e,text, wsNames);
}
else {
e->ignore();
Expand All @@ -1135,38 +1124,44 @@ void MdViewerWidget::dropEvent(QDropEvent *e) {
QString name = e->mimeData()->objectName();
if (name == "MantidWorkspace") {
QString text = e->mimeData()->text();
int endIndex = 0;
QStringList wsNames;
while (text.indexOf("[\"", endIndex) > -1) {
int startIndex = text.indexOf("[\"", endIndex) + 2;
endIndex = text.indexOf("\"]", startIndex);
QString candidate = text.mid(startIndex, endIndex - startIndex);
handleDragAndDropPeaksWorkspaces(e,text, wsNames);
if(!wsNames.empty()){
// We render the first workspace name, it is a peak workspace and the instrument is not relevant
renderWorkspace(wsNames[0], 1, "");
}
}
}

/**
* Handle the drag and drop events of peaks workspaces.
* @param e The event.
* @param text String containing information regarding the workspace name.
* @param wsNames A reference to a list of workspaces names, which are being extracted.
*/
void MdViewerWidget::handleDragAndDropPeaksWorkspaces(QEvent* e, QString text, QStringList& wsNames)
{
int endIndex = 0;
while (text.indexOf("[\"", endIndex) > -1) {
int startIndex = text.indexOf("[\"", endIndex) + 2;
endIndex = text.indexOf("\"]", startIndex);
QString candidate = text.mid(startIndex, endIndex - startIndex);
if(dynamic_cast<SplatterPlotView *>(this->currentView))
{
if(boost::dynamic_pointer_cast<IPeaksWorkspace>(AnalysisDataService::Instance().retrieve(candidate.toStdString())))
{
wsNames.append(candidate);
e->accept();
wsNames.append(candidate);
e->accept();
}
else
else
{
e->ignore();
e->ignore();
}
}
if(!wsNames.empty()){
// Show these peaks workspaces
this->createPeakWorkspaceViaDragAndDrop(wsNames);
else
{
e->ignore();
}
}
}

/**
* Load the peaks workspace into the VSI if the current view is a SplatterplotView.
* @param workspaces A list with the workspace names.
*/
void MdViewerWidget::createPeakWorkspaceViaDragAndDrop(QStringList workspaces){
if (dynamic_cast<SplatterPlotView *>(this->currentView))
{
// We render the first workspace name, it is a peak workspace and the instrument is not relevant
renderWorkspace(workspaces[0], 1, "");
}
}

Expand Down

0 comments on commit bb31f01

Please sign in to comment.