Mantid
Loading...
Searching...
No Matches
CatalogSelector.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 +
9
10#include <QDesktopWidget>
11
12namespace MantidQt {
13namespace MantidWidgets {
17CatalogSelector::CatalogSelector(QWidget *parent) : QWidget(parent), m_uiForm() { initLayout(); }
18
25 std::vector<std::string> selectedSessions;
26 for (int row = 0; row < m_uiForm.selectedCatalogs->count(); ++row) {
27 if (m_uiForm.selectedCatalogs->item(row)->isSelected()) {
28 selectedSessions.emplace_back(m_uiForm.selectedCatalogs->item(row)->data(Qt::UserRole).toString().toStdString());
29 }
30 }
31 return selectedSessions;
32}
33
39 auto session = Mantid::API::CatalogManager::Instance().getActiveSessions();
40
41 for (unsigned row = 0; row < session.size(); ++row) {
42 // This prevents the same items being appended (again) to the list widget.
43 if (!m_uiForm.selectedCatalogs->item(row)) {
44 QListWidgetItem *item = new QListWidgetItem(QString::fromStdString(session.at(row)->getFacility()));
45 // Set sessionID to user specific meta-data to easily obtain it later.
46 item->setData(Qt::UserRole, QVariant(QString::fromStdString(session.at(row)->getSessionId())));
47 // Add tooltip to see the difference if logged into two facilities with
48 // different end-points.
49 item->setData(Qt::ToolTipRole, QVariant(QString::fromStdString("The soap-endpoint for this catalog is: " +
50 session.at(row)->getSoapEndpoint())));
51 // When a new item is added, we want to select & check it by default.
52 item->setCheckState(Qt::Checked);
53 m_uiForm.selectedCatalogs->insertItem(row, item);
54 m_uiForm.selectedCatalogs->item(row)->setSelected(true);
55 }
56 }
57 // Set the list widget as focus to better show the selected facilities.
58 m_uiForm.selectedCatalogs->setFocus();
59}
60
65 m_uiForm.setupUi(this);
66
68
69 connect(m_uiForm.updateBtn, SIGNAL(clicked()), this, SLOT(close()));
70 connect(m_uiForm.cancelBtn, SIGNAL(clicked()), this, SLOT(close()));
71
72 // Check/un-check the checkbox when an item is clicked or selected.
73 connect(m_uiForm.selectedCatalogs, SIGNAL(itemClicked(QListWidgetItem *)), this,
74 SLOT(checkSelectedFacility(QListWidgetItem *)));
75
76 // Centre the GUI on screen.
77 this->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, this->window()->size(),
78 QDesktopWidget().availableGeometry()));
79}
80
84void CatalogSelector::checkSelectedFacility(QListWidgetItem *item) {
85 if (item->isSelected())
86 item->setCheckState(Qt::Checked);
87 if (!item->isSelected())
88 item->setCheckState(Qt::Unchecked);
89}
90
91} // namespace MantidWidgets
92} // namespace MantidQt
void populateFacilitySelection()
Populate the ListWidget with the facilities of the catalogs the user is logged in to.
std::vector< std::string > getSelectedCatalogSessions()
Obtain the session information for the facilities selected.
Ui::CatalogSelector m_uiForm
The form generated by QT Designer.
CatalogSelector(QWidget *parent=nullptr)
Default constructor.
virtual void initLayout()
Initialise the layout.
void checkSelectedFacility(QListWidgetItem *item)
Checks the checkbox of the list item selected.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...