Mantid
Loading...
Searching...
No Matches
SelectWorkspacesDialog.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//---------------------------------------
8// Includes
9//---------------------------------------
10
12
15#include <QDialogButtonBox>
16#include <QListWidget>
17#include <QPushButton>
18#include <QVBoxLayout>
19#include <set>
20
22
27private:
28 const std::string m_type;
30
31public:
32 explicit WorkspaceIsNotOfType(const std::string &type)
33 : m_type(type), m_isMatrixWorkspace(type == "MatrixWorkspace") {}
35 if (m_type.empty())
36 return false;
38 return dynamic_cast<Mantid::API::MatrixWorkspace *>(ws.get()) == nullptr;
39 }
40 return ws->id() != m_type;
41 }
42};
43
44//---------------------------------------
45// Public member functions
46//---------------------------------------
47
54SelectWorkspacesDialog::SelectWorkspacesDialog(QWidget *parent, const std::string &typeFilter,
55 const std::string &customButtonLabel)
56 : QDialog(parent), m_wsList(nullptr), m_okButton(nullptr), m_customButton(nullptr) {
57 setWindowTitle("Mantid - Select workspace");
58 m_wsList = new QListWidget(parent);
59
61 using VecWorkspaces = std::vector<Mantid::API::Workspace_sptr>;
62 VecWorkspaces workspaces = ADS.getObjects();
63 WorkspaceIsNotOfType comparitor(typeFilter);
64 workspaces.erase(std::remove_if(workspaces.begin(), workspaces.end(), comparitor), workspaces.end());
65 QStringList tmp;
66 for (VecWorkspaces::const_iterator it = workspaces.begin(); it != workspaces.end(); ++it) {
67 // if(useFilter && ADS::
68 tmp << QString::fromStdString((*it)->getName());
69 }
70
71 m_wsList->addItems(tmp);
72 m_wsList->setSelectionMode(QAbstractItemView::MultiSelection);
73
74 auto *btnBox = new QDialogButtonBox(Qt::Horizontal);
75
76 if (!customButtonLabel.empty()) {
77 m_customButton = new QPushButton(QString::fromStdString(customButtonLabel));
78 btnBox->addButton(m_customButton, QDialogButtonBox::DestructiveRole);
79 connect(m_customButton, SIGNAL(clicked()), this, SLOT(customButtonPress()));
80 }
81
82 m_okButton = new QPushButton("Select");
83 auto *cancelButton = new QPushButton("Cancel");
84 btnBox->addButton(m_okButton, QDialogButtonBox::AcceptRole);
85 btnBox->addButton(cancelButton, QDialogButtonBox::RejectRole);
86 connect(btnBox, SIGNAL(accepted()), this, SLOT(accept()));
87 connect(btnBox, SIGNAL(rejected()), this, SLOT(reject()));
88
89 auto *vLayout = new QVBoxLayout();
90 vLayout->addWidget(m_wsList);
91 vLayout->addWidget(btnBox);
92
93 setLayout(vLayout);
94
95 connect(m_wsList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
96
98}
99
101 QList<QListWidgetItem *> items = m_wsList->selectedItems();
102 QStringList res;
103 foreach (QListWidgetItem *item, items) { res << item->text(); }
104 return res;
105}
106
108void SelectWorkspacesDialog::selectionChanged() { m_okButton->setEnabled(m_wsList->selectionModel()->hasSelection()); }
109
112} // namespace MantidQt::MantidWidgets
gsl_vector * tmp
void selectionChanged()
Slot to monitor the workspace selection status.
SelectWorkspacesDialog(QWidget *parent=nullptr, const std::string &typeFilter="", const std::string &customButtonLabel="")
Constructor.
QListWidget * m_wsList
Displays available workspace names.
QStringList getSelectedNames() const
Return the selected names.
static const int CustomButton
return value of the Custom button
void customButtonPress()
slot to handle the custom button press
Helper comparitor class used to determine if a workspace is not of a given type.
bool operator()(const Mantid::API::Workspace_sptr &ws) const
The Analysis data service stores instances of the Workspace objects and anything that derives from te...
Base MatrixWorkspace Abstract Class.
virtual const std::string id() const =0
A string ID for the class.
std::vector< std::shared_ptr< T > > getObjects(DataServiceHidden includeHidden=DataServiceHidden::Auto) const
Get a vector of the pointers to the data objects stored by the service.
Definition: DataService.h:451
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20