15#include <QApplication>
17#include <QDragMoveEvent>
33 setObjectName(
"WorkspaceTree");
34 setSelectionMode(QAbstractItemView::ExtendedSelection);
47 if (de->mimeData()->hasUrls())
57 if (de->mimeData()->hasUrls())
58 de->acceptProposedAction();
67 de->acceptProposedAction();
69 for (
int i = 0; i < filenames.size(); ++i) {
71 QFileInfo fi(filenames[i]);
72 QString basename = fi.completeBaseName();
75 alg->setProperty(
"Filename", filenames[i].toStdString());
76 alg->setProperty(
"OutputWorkspace", basename.toStdString());
78 }
catch (std::runtime_error &
error) {
79 treelog.error() <<
"Failed to Load the file " << filenames[i].toStdString()
80 <<
" . The reason for failure is: " <<
error.what() <<
'\n';
81 }
catch (std::logic_error &
error) {
82 treelog.error() <<
"Failed to Load the file " << filenames[i].toStdString()
83 <<
" . The reason for failure is: " <<
error.what() <<
'\n';
84 }
catch (std::exception &
error) {
85 treelog.error() <<
"Failed to Load the file " << filenames[i].toStdString()
86 <<
" . The reason for failure is: " <<
error.what() <<
'\n';
92 if (e->button() == Qt::LeftButton) {
93 if (!itemAt(e->pos()))
94 selectionModel()->clear();
98 QTreeWidget::mousePressEvent(e);
102 if (!(e->buttons() & Qt::LeftButton))
104 if ((e->pos() -
m_dragStartPosition).manhattanLength() < QApplication::startDragDistance())
108 if (wsNames.isEmpty())
113 QDrag *drag =
new QDrag(
this);
114 auto *mimeData =
new QMimeData;
115 drag->setMimeData(mimeData);
116 mimeData->setObjectName(
"MantidWorkspace");
117 mimeData->setText(wsNames.join(
"\n"));
118 drag->exec(Qt::CopyAction | Qt::MoveAction);
124 if (wsNames.isEmpty()) {
127 auto wsName = wsNames.front();
129 grpWSPstr = std::dynamic_pointer_cast<WorkspaceGroup>(
m_ads.
retrieve(wsName.toStdString()));
131 if (!wsName.isEmpty()) {
139 QTreeWidget::mouseDoubleClickEvent(e);
150 foreach (
const auto selectedItem, this->selectedItems()) {
152 names.append(selectedItem->text(0));
169 std::set<QString> selectedWsNameSet;
170 std::vector<QString> selectedWsNameList;
172 const auto groupWs = std::dynamic_pointer_cast<const WorkspaceGroup>(
m_ads.
retrieve(wsName.toStdString()));
174 const auto childWsNames = groupWs->getNames();
175 for (
const auto &childWsName : childWsNames) {
176 if (selectedWsNameSet.find(QString::fromStdString(childWsName)) == selectedWsNameSet.end()) {
177 selectedWsNameSet.insert(QString::fromStdString(childWsName));
178 selectedWsNameList.emplace_back(QString::fromStdString(childWsName));
182 if (selectedWsNameSet.insert(wsName).second) {
183 selectedWsNameList.emplace_back(wsName);
191 foreach (
const auto selectedWsName, selectedWsNameList) {
192 const auto matrixWs =
193 std::dynamic_pointer_cast<const MatrixWorkspace>(
m_ads.
retrieve(selectedWsName.toStdString()));
195 selectedMatrixWsList.append(matrixWs);
198 return selectedMatrixWsList;
216 bool showTiledOpt,
bool isAdvanced)
const {
219 foreach (
const auto matrixWs, selectedMatrixWsList) {
220 selectedMatrixWsNameList.append(QString::fromStdString(matrixWs->getName()));
224 bool plotImmediately =
true;
226 plotImmediately = selectedMatrixWsList.size() == 1 && selectedMatrixWsList[0]->getNumberHistograms() == 1;
228 foreach (
const auto selectedMatrixWs, selectedMatrixWsList) {
229 if (selectedMatrixWs->getNumberHistograms() != 1) {
230 plotImmediately =
false;
237 if (plotImmediately) {
238 const std::set<int> SINGLE_SPECTRUM = {0};
240 foreach (
const auto selectedMatrixWs, selectedMatrixWsList) {
241 spectrumToPlot.insert(QString::fromStdString(selectedMatrixWs->getName()), SINGLE_SPECTRUM);
245 selections.
plots = spectrumToPlot;
248 selections.
tiled =
false;
256 showTiledOpt, isAdvanced);
std::shared_ptr< T > retrieve(const std::string &name) const
Get a shared pointer to a stored data object.
Exception for when an item is not found in a collection.
The Logger class is in charge of the publishing messages from the framework through various channels.
Manage the lifetime of a class intended to be a singleton.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
Helper class which provides the Collimation Length for SANS instruments.