Newer
Older
#include "QtReflSaveTabView.h"
#include "ReflSaveTabPresenter.h"
#include <QFileDialog>
#include <QMessageBox>
#include <boost/algorithm/string.hpp>
namespace MantidQt {
namespace CustomInterfaces {
/** Constructor
* @param parent :: The parent of this view
*/
QtReflSaveTabView::QtReflSaveTabView(QWidget *parent) : m_presenter(nullptr) {
UNUSED_ARG(parent);
initLayout();
}
void QtReflSaveTabView::subscribe(IReflSaveTabPresenter *presenter) {
m_presenter = presenter;
populateListOfWorkspaces();
suggestSaveDir();
}
QtReflSaveTabView::~QtReflSaveTabView() {}
/**
Initialize the Interface
*/
void QtReflSaveTabView::initLayout() {
m_ui.setupUi(this);
connect(m_ui.refreshButton, SIGNAL(clicked()), this,
SLOT(populateListOfWorkspaces()));
connect(m_ui.saveButton, SIGNAL(clicked()), this, SLOT(saveWorkspaces()));
connect(m_ui.filterEdit, SIGNAL(textEdited(const QString &)), this,
SLOT(filterWorkspaceList()));
connect(m_ui.listOfWorkspaces, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
this, SLOT(requestWorkspaceParams()));
connect(m_ui.saveReductionResultsCheckBox, SIGNAL(stateChanged(int)), this,
SLOT(onAutosaveChanged(int)));
connect(m_ui.savePathEdit, SIGNAL(editingFinished()), this,
SLOT(onSavePathChanged()));
connect(m_ui.savePathBrowseButton, SIGNAL(clicked()), this,
SLOT(browseToSaveDirectory()));
}
void QtReflSaveTabView::browseToSaveDirectory() {
auto savePath = QFileDialog::getExistingDirectory(
this, "Select the directory to save to.");
if (!savePath.isEmpty()) {
m_ui.savePathEdit->setText(savePath);
onSavePathChanged();
}
void QtReflSaveTabView::onSavePathChanged() {
m_presenter->notify(IReflSaveTabPresenter::Flag::savePathChanged);
void QtReflSaveTabView::onAutosaveChanged(int state) {
if (state == Qt::CheckState::Checked)
m_presenter->notify(IReflSaveTabPresenter::Flag::autosaveEnabled);
else
m_presenter->notify(IReflSaveTabPresenter::Flag::autosaveDisabled);
}
void QtReflSaveTabView::disableAutosaveControls() {
m_ui.autosaveGroup->setEnabled(false);
}
void QtReflSaveTabView::enableAutosaveControls() {
m_ui.autosaveGroup->setEnabled(true);
}
void QtReflSaveTabView::enableFileFormatAndLocationControls() {
m_ui.fileFormatGroup->setEnabled(true);
m_ui.fileLocationGroup->setEnabled(true);
}
void QtReflSaveTabView::disableFileFormatAndLocationControls() {
m_ui.fileFormatGroup->setEnabled(false);
m_ui.fileLocationGroup->setEnabled(false);
}
std::string QtReflSaveTabView::getSavePath() const {
return m_ui.savePathEdit->text().toStdString();
/** Sets the save path
void QtReflSaveTabView::setSavePath(const std::string &path) const {
m_ui.savePathEdit->setText(QString::fromStdString(path));
}
/** Returns the file name prefix
std::string QtReflSaveTabView::getPrefix() const {
return m_ui.prefixEdit->text().toStdString();
}
/** Returns the workspace list filter
std::string QtReflSaveTabView::getFilter() const {
return m_ui.filterEdit->text().toStdString();
}
/** Returns the regular expression check value
bool QtReflSaveTabView::getRegexCheck() const {
return m_ui.regexCheckBox->isChecked();
/** Returns the name of the currently selected workspace from the 'List of
* workspaces' widget
* @return :: item name
*/
std::string QtReflSaveTabView::getCurrentWorkspaceName() const {
return m_ui.listOfWorkspaces->currentItem()->text().toStdString();
/** Returns a list of names of currently selected workspaces
std::vector<std::string> QtReflSaveTabView::getSelectedWorkspaces() const {
std::vector<std::string> itemNames;
auto items = m_ui.listOfWorkspaces->selectedItems();
for (auto it = items.begin(); it != items.end(); it++) {
itemNames.push_back((*it)->text().toStdString());
}
return itemNames;
}
/** Returns a list of names of currently selected parameters
std::vector<std::string> QtReflSaveTabView::getSelectedParameters() const {
std::vector<std::string> paramNames;
auto items = m_ui.listOfLoggedParameters->selectedItems();
for (auto it = items.begin(); it != items.end(); it++) {
paramNames.push_back((*it)->text().toStdString());
}
return paramNames;
}
/** Returns the index of the selected file format
int QtReflSaveTabView::getFileFormatIndex() const {
return m_ui.fileFormatComboBox->currentIndex();
/** Returns the title check value
bool QtReflSaveTabView::getTitleCheck() const {
return m_ui.titleCheckBox->isChecked();
}
/** Returns the Q resolution check value
bool QtReflSaveTabView::getQResolutionCheck() const {
return m_ui.qResolutionCheckBox->isChecked();
}
void QtReflSaveTabView::disallowAutosave() {
m_ui.saveReductionResultsCheckBox->setCheckState(Qt::CheckState::Unchecked);
/** Returns the separator type
std::string QtReflSaveTabView::getSeparator() const {
auto sep = m_ui.separatorButtonGroup->checkedButton()->text().toStdString();
boost::to_lower(sep); // lowercase
/** Clear the 'List of workspaces' widget
void QtReflSaveTabView::clearWorkspaceList() const {
m_ui.listOfWorkspaces->clear();
}
/** Clear the 'List of Logged Parameters' widget
void QtReflSaveTabView::clearParametersList() const {
m_ui.listOfLoggedParameters->clear();
}
/** Set the 'List of workspaces' widget with workspace names
* @param names :: The list of workspace names
*/
void QtReflSaveTabView::setWorkspaceList(
const std::vector<std::string> &names) const {
for (auto it = names.begin(); it != names.end(); it++) {
m_ui.listOfWorkspaces->addItem(QString::fromStdString(*it));
}
}
/** Set the 'List of logged parameters' widget with workspace run logs
* @param logs :: The list of workspace run logs
*/
void QtReflSaveTabView::setParametersList(
const std::vector<std::string> &logs) const {
for (auto it = logs.begin(); it != logs.end(); it++) {
m_ui.listOfLoggedParameters->addItem(QString::fromStdString(*it));
}
}
/** Populate the 'List of workspaces' widget
void QtReflSaveTabView::populateListOfWorkspaces() const {
m_presenter->notify(IReflSaveTabPresenter::populateWorkspaceListFlag);
}
/** Filter the 'List of workspaces' widget
void QtReflSaveTabView::filterWorkspaceList() const {
m_presenter->notify(IReflSaveTabPresenter::filterWorkspaceListFlag);
}
/** Request for the parameters of a workspace
void QtReflSaveTabView::requestWorkspaceParams() const {
m_presenter->notify(IReflSaveTabPresenter::workspaceParamsFlag);
}
/** Save selected workspaces
void QtReflSaveTabView::saveWorkspaces() const {
m_presenter->notify(IReflSaveTabPresenter::saveWorkspacesFlag);
}
/** Suggest a save directory
void QtReflSaveTabView::suggestSaveDir() const {
m_presenter->notify(IReflSaveTabPresenter::suggestSaveDirFlag);
}
void QtReflSaveTabView::error(const std::string &title,
const std::string &prompt) {
QMessageBox::critical(this, QString::fromStdString(title),
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
void QtReflSaveTabView::warning(const std::string &title,
const std::string &prompt) {
QMessageBox::critical(this, QString::fromStdString(title),
QString::fromStdString(prompt));
}
void QtReflSaveTabView::invalidRegex() {
error("Invalid Regex", "Error, invalid regular expression.");
}
void QtReflSaveTabView::errorInvalidSaveDirectory() {
error("Invalid directory", "The save path specified doesn't exist or is "
"not writable.");
}
void QtReflSaveTabView::warnInvalidSaveDirectory() {
warning("Invalid directory",
"You just changed the save path to a directory which "
"doesn't exist or is not writable.");
}
void QtReflSaveTabView::noWorkspacesSelected() {
error("No workspaces selected.",
"You must select the workspaces in order to save.");
}
void QtReflSaveTabView::cannotSaveWorkspaces() {
error("Error", "Unknown error while saving workspaces");
}
void QtReflSaveTabView::cannotSaveWorkspaces(std::string const &fullError) {
error("Error", fullError);
} // namespace CustomInterfaces