Mantid
Loading...
Searching...
No Matches
CatalogPublishDialog.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 +
8
11#include "MantidAPI/ICatalog.h"
19
21DECLARE_DIALOG(CatalogPublishDialog)
22
23
27CatalogPublishDialog::CatalogPublishDialog(QWidget *parent) : API::AlgorithmDialog(parent), m_uiForm() {}
28
31 m_uiForm.setupUi(this);
32 this->setWindowTitle(m_algName);
33
34 tie(m_uiForm.nameInCatalogTxt, "NameInCatalog");
35 tie(m_uiForm.investigationNumberCb, "InvestigationNumber");
36 tie(m_uiForm.descriptionInput, "DataFileDescription");
37
38 // Assign the buttons with the inherited methods.
39 connect(m_uiForm.runBtn, SIGNAL(clicked()), this, SLOT(accept()));
40 connect(m_uiForm.cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
41 connect(m_uiForm.helpBtn, SIGNAL(clicked()), this, SLOT(helpClicked()));
42 connect(m_uiForm.investigationNumberCb, SIGNAL(currentIndexChanged(int)), this, SLOT(setSessionProperty(int)));
43 connect(m_uiForm.dataSelector, SIGNAL(dataReady(const QString &)), this, SLOT(workspaceSelected(const QString &)));
44 // When a file is chosen to be published, set the related "FileName" property
45 // of the algorithm.
46 connect(m_uiForm.dataSelector, SIGNAL(filesFound()), this, SLOT(fileSelected()));
47
48 // Populate "investigationNumberCb" with the investigation IDs that the user
49 // can publish to.
51
52 // Get optional message here as we may set it if user has no investigations to
53 // publish to.
54 m_uiForm.instructions->setText(getOptionalMessage());
55 // This is required as we use the currentIndexChanged SLOT.
56 storePropertyValue("Session", m_uiForm.investigationNumberCb->itemData(0, Qt::UserRole).toString());
57}
58
65 auto session = Mantid::API::CatalogManager::Instance().getActiveSessions();
66
67 // We need to catch the exception to prevent a fatal error.
68 try {
69 if (!session.empty()) {
70 // Cast a catalog to a catalogInfoService to access downloading
71 // functionality.
72 auto catalogInfoService = std::dynamic_pointer_cast<Mantid::API::ICatalogInfoService>(
73 Mantid::API::CatalogManager::Instance().getCatalog(session.front()->getSessionId()));
74 // Check if the catalog created supports publishing functionality.
75 if (!catalogInfoService)
76 throw std::runtime_error("The catalog that you are using does not support publishing.");
77 // Populate the workspace with investigations that the user has CREATE
78 // access to.
79 workspace = catalogInfoService->getPublishInvestigations();
80 }
81 } catch (std::runtime_error &e) {
82 setOptionalMessage(e.what());
83 }
84
85 if (workspace->rowCount() > 0) {
86 // Populate the form with investigations that the user can publish to.
87 for (size_t row = 0; row < workspace->rowCount(); row++) {
88 m_uiForm.investigationNumberCb->addItem(
89 QString::fromStdString(workspace->getRef<std::string>("InvestigationID", row)));
90 // Added tooltips to improve usability.
91 m_uiForm.investigationNumberCb->setItemData(
92 static_cast<int>(row),
93 QString::fromStdString(
94 "The title of the investigation is: \"" + workspace->getRef<std::string>("Title", row) +
95 "\".\nThe instrument of the investigation is: \"" + workspace->getRef<std::string>("Instrument", row)) +
96 "\".",
97 Qt::ToolTipRole);
98 // Set the user role to the sessionID.
99 m_uiForm.investigationNumberCb->setItemData(
100 static_cast<int>(row), QString::fromStdString(workspace->getRef<std::string>("SessionID", row)),
101 Qt::UserRole);
102 }
103 } else {
105 }
106}
107
113void CatalogPublishDialog::workspaceSelected(const QString &wsName) {
114 // Prevents both a file and workspace being published at same time.
115 storePropertyValue("FileName", "");
116 setPropertyValue("FileName", true);
117 // Set the workspace property to the one the user has selected to publish.
118 storePropertyValue("InputWorkspace", wsName);
119 setPropertyValue("InputWorkspace", true);
120}
121
126 // Reset workspace property as the input is a file. This prevents both being
127 // selected.
128 storePropertyValue("InputWorkspace", "");
129 setPropertyValue("InputWorkspace", true);
130 // Set the FileName property to the path that appears in the input field on
131 // the dialog.
132 storePropertyValue("FileName", m_uiForm.dataSelector->getFullFilePath());
133 setPropertyValue("FileName", true);
134}
135
140 m_uiForm.scrollArea->setDisabled(true);
141 m_uiForm.runBtn->setDisabled(true);
142}
143
149 storePropertyValue("Session", m_uiForm.investigationNumberCb->itemData(index, Qt::UserRole).toString());
150}
151
156 if (!m_uiForm.dataSelector->isValid()) {
157 if (m_uiForm.dataSelector->getFullFilePath().isEmpty()) {
158 QMessageBox::critical(this, "Error in catalog publishing.", "No file specified.");
159 } else {
160 QMessageBox::critical(this, "Error in catalog publishing.", m_uiForm.dataSelector->getProblem());
161 }
162 } else {
163 AlgorithmDialog::accept();
164 }
165}
166} // namespace MantidQt::CustomDialogs
#define DECLARE_DIALOG(classname)
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
void setOptionalMessage(const QString &message)
Set an optional message to be displayed at the top of the dialog.
bool setPropertyValue(const QString &pName, bool validateOthers)
Sets the value of a single property, using the value previously stored using storePropertyValue()
void reject() override
A default slot that can be used for a rejected button.
QString m_algName
The name of the algorithm.
virtual void helpClicked()
Help button clicked;.
void storePropertyValue(const QString &name, const QString &value)
Adds a property (name,value) pair to the stored map.
QWidget * tie(QWidget *widget, const QString &property, QLayout *parent_layout=nullptr, bool readHistory=true)
Tie a widget to a property.
const QString & getOptionalMessage() const
Get the message string.
This class gives specialised dialog for the CatalogPublish algorithm.
void workspaceSelected(const QString &wsName)
When the "browse" button is clicked open a file browser.
void initLayout() override
Create the inital layout.
void disableDialog()
Diables fields on dialog to improve usability.
void populateUserInvestigations()
Populate the investigation number combo-box with investigations that the user can publish to.
void accept() override
Overridden to enable dataselector validators.
Ui::CatalogPublishDialog m_uiForm
The form generated by QT Designer.
void setSessionProperty(int index)
Set session property when user selects an investigation to publish to.
void fileSelected()
Set the "FileName" property when a file is selected from the file browser.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...