Ticket #8978: add_drag_func.patch

File add_drag_func.patch, 6.9 KB (added by Gesner Passos, 7 years ago)

Adds the drop functionality of those classes.

  • Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataSelector.h

    diff --git a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataSelector.h b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataSelector.h
    index 1ac3e9c..39e4dd7 100644
    a b namespace MantidQt 
    122122      bool m_autoLoad; 
    123123      /// Flag to show or hide the load button. By default this is set to true. 
    124124      bool m_showLoad; 
     125 
     126    protected: 
     127      void dropEvent(QDropEvent *); 
     128      void dragEnterEvent(QDragEnterEvent *); 
    125129    }; 
    126130 
    127131  } /* namespace MantidWidgets */ 
  • Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MWRunFiles.h

    diff --git a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MWRunFiles.h b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MWRunFiles.h
    index be5e810..613ca1f 100644
    a b namespace MantidQt 
    106106      Q_PROPERTY(LiveButtonOpts liveButton READ liveButtonState WRITE liveButtonState) 
    107107      Q_ENUMS(ButtonOpts) 
    108108      Q_ENUMS(LiveButtonOpts) 
    109  
     109      friend class DataSelector; 
    110110    public: 
    111111      /// options for bringing up the load file dialog 
    112112      enum ButtonOpts 
    namespace MantidQt 
    275275      QString m_fileFilter; 
    276276      /// Thread to allow asynchronous finding of files. 
    277277      FindFilesThread * m_thread; 
     278 
     279    protected: 
     280      void dropEvent(QDropEvent *); 
     281      void dragEnterEvent(QDragEnterEvent *); 
    278282    }; 
    279283  } 
    280284} 
  • Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspaceSelector.h

    diff --git a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspaceSelector.h b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/WorkspaceSelector.h
    index 1b51904..e584339 100644
    a b namespace MantidWidgets 
    6767    Q_PROPERTY(bool Optional READ isOptional WRITE setOptional) 
    6868    Q_PROPERTY(QStringList Suffix READ getSuffixes WRITE setSuffixes) 
    6969    Q_PROPERTY(QString Algorithm READ getValidatingAlgorithm WRITE setValidatingAlgorithm) 
    70  
     70    friend class DataSelector; 
    7171  public: 
    7272    /// Default Constructor 
    7373    WorkspaceSelector(QWidget *parent = NULL, bool init = true); 
    namespace MantidWidgets 
    121121    // Algorithm to validate against 
    122122    boost::shared_ptr<Mantid::API::Algorithm> m_algorithm; 
    123123 
     124  protected: 
     125    void dragEnterEvent(QDragEnterEvent*); 
     126    void dropEvent(QDropEvent*); 
    124127  }; 
    125128 
    126129} 
  • Code/Mantid/MantidQt/MantidWidgets/src/DataSelector.cpp

    diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/DataSelector.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/DataSelector.cpp
    index c75598f..7e9a13b 100644
    a b  
    66 
    77#include <QFileInfo> 
    88 
     9#include <QDropEvent> 
     10#include <QMimeData> 
     11#include <QDebug> 
     12#include <QUrl> 
     13 
    914namespace MantidQt 
    1015{ 
    1116  namespace MantidWidgets 
    namespace MantidQt 
    2429      connect(m_uiForm.pbLoadFile, SIGNAL(clicked()), this, SLOT(handleFileInput())); 
    2530 
    2631      connect(&m_algRunner, SIGNAL(algorithmComplete(bool)), this, SLOT(handleAutoLoadComplete(bool))); 
     32      m_uiForm.rfFileInput->setAcceptDrops(false); 
    2733    } 
    2834 
    2935    DataSelector::~DataSelector() 
    namespace MantidQt 
    351357      m_showLoad = load; 
    352358    } 
    353359 
     360 
     361void DataSelector::dropEvent(QDropEvent *de) 
     362{ 
     363  const QMimeData *mimeData = de->mimeData();   
     364  auto before_action = de->dropAction(); 
     365 
     366  if (de->mimeData() && mimeData->text().contains(" = mtd[\"")){ 
     367    m_uiForm.wsWorkspaceInput->dropEvent(de); 
     368    if (de->dropAction() == before_action){     
     369      m_uiForm.cbInputType->setCurrentIndex(1); 
     370      return; 
     371    } 
     372    de->setDropAction(before_action);     
     373  } 
     374   
     375  m_uiForm.rfFileInput->dropEvent(de); 
     376  if (de->dropAction() == before_action){ 
     377    m_uiForm.cbInputType->setCurrentIndex(0); 
     378  } 
     379} 
     380 
     381  void DataSelector::dragEnterEvent(QDragEnterEvent *de) 
     382{ 
     383  const QMimeData *mimeData = de->mimeData(); 
     384  if (mimeData->hasText() || mimeData->hasUrls()) 
     385    de->acceptProposedAction(); 
     386} 
     387 
     388 
    354389  } /* namespace MantidWidgets */ 
    355390} /* namespace MantidQt */ 
  • Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp

    diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp
    index 42d0b80..95ed011 100644
    a b  
    1212#include <QFileDialog> 
    1313#include <QFileInfo> 
    1414#include <QHash> 
     15#include <QDropEvent> 
     16#include <QDragEnterEvent> 
     17#include <QMimeData> 
     18#include <QUrl> 
    1519#include <QtConcurrentRun> 
    1620#include <Poco/File.h> 
    1721 
    void MWRunFiles::checkEntry() 
    10641068 
    10651069  setEntryNumProblem(""); 
    10661070} 
     1071 
     1072 
     1073void MWRunFiles::dropEvent(QDropEvent *de) 
     1074{ 
     1075  const QMimeData *mimeData = de->mimeData();  
     1076  if (mimeData->hasUrls()){ 
     1077    auto url_list = mimeData->urls();  
     1078    m_uiForm.fileEditor->setText(url_list[0].toLocalFile()); 
     1079    de->acceptProposedAction(); 
     1080  }else if (mimeData->hasText()){ 
     1081    QString text = mimeData->text(); 
     1082    if (text.contains(" = mtd[\"")) 
     1083      return; 
     1084    m_uiForm.fileEditor->setText(text);  
     1085    de->acceptProposedAction(); 
     1086  } 
     1087   
     1088} 
     1089 
     1090  void MWRunFiles::dragEnterEvent(QDragEnterEvent *de) 
     1091{ 
     1092  const QMimeData *mimeData = de->mimeData();   
     1093  if (mimeData->hasUrls()){ 
     1094    auto listurl = mimeData->urls();  
     1095    if (listurl.empty()) 
     1096      return; 
     1097    if (!listurl[0].isLocalFile()) 
     1098      return; 
     1099    de->acceptProposedAction(); 
     1100  } 
     1101  else if(mimeData->hasText())  
     1102  { 
     1103    de->acceptProposedAction(); 
     1104  } 
     1105} 
  • Code/Mantid/MantidQt/MantidWidgets/src/WorkspaceSelector.cpp

    diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/WorkspaceSelector.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/WorkspaceSelector.cpp
    index dbdebe8..170fbd1 100644
    a b  
    1010 
    1111#include "MantidAPI/AlgorithmManager.h" 
    1212 
     13#include <QDropEvent> 
     14#include <QMimeData> 
     15#include <QUrl> 
     16#include <QDebug> 
    1317using namespace MantidQt::MantidWidgets; 
    1418 
    1519/** 
    void WorkspaceSelector::refresh() 
    313317    } 
    314318  } 
    315319} 
     320 
     321void WorkspaceSelector::dropEvent(QDropEvent *de) 
     322{ 
     323  const QMimeData *mimeData = de->mimeData();  
     324  QString text =  mimeData->text(); 
     325  int equal_pos = text.indexOf("="); 
     326  QString ws_name = text.left(equal_pos-1); 
     327  QString ws_name_test = text.mid(equal_pos + 7, equal_pos-1); 
     328   
     329  if (ws_name == ws_name_test){ 
     330    int index = findText(ws_name); 
     331    if (index >= 0){ 
     332      setCurrentIndex(index); 
     333      de->acceptProposedAction(); 
     334    } 
     335  } 
     336   
     337} 
     338 
     339void WorkspaceSelector::dragEnterEvent(QDragEnterEvent *de) 
     340{ 
     341  const QMimeData *mimeData = de->mimeData();   
     342  if(mimeData->hasText())  
     343  { 
     344    QString text = mimeData->text(); 
     345    if (text.contains(" = mtd[\"")) 
     346      de->acceptProposedAction(); 
     347  } 
     348}