Skip to content

Commit

Permalink
Refs #11040 Added drag and drop feature for peaks workspace in vsi
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonPiccardoSelg committed Mar 3, 2015
1 parent 8b7efb3 commit d3e4208
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
Expand Up @@ -15,6 +15,8 @@ class pqPipelineSource;
class pqViewSettingsReaction;
class vtkSMDoubleVectorProperty;

class QDragEnterEvent;
class QDropEvent;
class QAction;
class QEvent;
class QHBoxLayout;
Expand Down Expand Up @@ -109,7 +111,10 @@ protected slots:
/// Handle workspace replacement tasks.
void afterReplaceHandle(const std::string &wsName,
const boost::shared_ptr<Mantid::API::Workspace> ws);

/// Detects if something is dragged onto the VSI
void dragEnterEvent(QDragEnterEvent *e);
/// Reacts to something being dropped onto the VSI
void dropEvent(QDropEvent *e);
private:
Q_DISABLE_COPY(MdViewerWidget)

Expand Down Expand Up @@ -177,6 +182,8 @@ protected slots:
void resetCurrentView(int workspaceType, const std::string& instrumentName);
/// Set visibility listener
void setVisibilityListener();
/// Handle drag and drop of peaks workspcaes
void handleDragAndDropPeaksWorkspaces(QEvent* e, QString text, QStringList& wsNames);
};

} // SimpleGui
Expand Down
Expand Up @@ -11,6 +11,7 @@
#include "MantidVatesSimpleGuiViewWidgets/TimeControlWidget.h"

#include "MantidQtAPI/InterfaceManager.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidKernel/DynamicFactory.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/ConfigService.h"
Expand Down Expand Up @@ -84,6 +85,8 @@

#include <QAction>
#include <QDesktopServices>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QHBoxLayout>
#include <QMainWindow>
#include <QMenuBar>
Expand All @@ -96,6 +99,7 @@
#include <set>
#include <string>
#include <boost/regex.hpp>
#include <boost/shared_ptr.hpp>

namespace Mantid
{
Expand Down Expand Up @@ -127,8 +131,7 @@ MdViewerWidget::MdViewerWidget() : VatesViewerInterface(), currentView(NULL),

this->internalSetup(true);

// Create the mapping from the measurement technique to the view

setAcceptDrops(true);
}

/**
Expand Down Expand Up @@ -1144,6 +1147,71 @@ void MdViewerWidget::setVisibilityListener()
}
}

/**
* Dectect when a PeaksWorkspace is dragged into the VSI.
* @param A drag event.
*/
void MdViewerWidget::dragEnterEvent(QDragEnterEvent *e) {
QString name = e->mimeData()->objectName();
if (name == "MantidWorkspace") {
QString text = e->mimeData()->text();
QStringList wsNames;
handleDragAndDropPeaksWorkspaces(e,text, wsNames);
}
else {
e->ignore();
}
}

/**
* React to dropping a PeaksWorkspace ontot the VSI.
* @param e A drop event.
*/
void MdViewerWidget::dropEvent(QDropEvent *e) {
QString name = e->mimeData()->objectName();
if (name == "MantidWorkspace") {
QString text = e->mimeData()->text();
QStringList wsNames;
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();
}
else
{
e->ignore();
}
}
else
{
e->ignore();
}
}
}


} // namespace SimpleGui
} // namespace Vates
Expand Down

0 comments on commit d3e4208

Please sign in to comment.