Skip to content
Snippets Groups Projects
Commit c6c557f3 authored by Hahn, Steven's avatar Hahn, Steven Committed by GitHub
Browse files

Merge pull request #17392 from mantidproject/17329_DataSelector_multipleFiles

DataSelector to support all properties of it's two child widgets
parents a5ec6193 96efc37d
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
namespace MantidQt { namespace MantidQt {
namespace MantidWidgets { namespace MantidWidgets {
using ButtonOpts = MWRunFiles::ButtonOpts;
using LiveButtonOpts = MWRunFiles::LiveButtonOpts;
/** /**
This class defines a widget for selecting a workspace of file path by using a This class defines a widget for selecting a workspace of file path by using a
combination combination
...@@ -48,15 +52,42 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS DataSelector ...@@ -48,15 +52,42 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS DataSelector
: public API::MantidWidget { : public API::MantidWidget {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool autoLoad READ willAutoLoad WRITE setAutoLoad) // These are properties of the file browser sub-widget
Q_PROPERTY(QString loadLabelText READ getLoadBtnText WRITE setLoadBtnText)
Q_PROPERTY(QStringList workspaceSuffixes READ getWSSuffixes WRITE
setWSSuffixes)
Q_PROPERTY(QStringList fileBrowserSuffixes READ getFBSuffixes WRITE Q_PROPERTY(QStringList fileBrowserSuffixes READ getFBSuffixes WRITE
setFBSuffixes) setFBSuffixes)
Q_PROPERTY(bool showLoad READ willShowLoad WRITE setShowLoad) Q_PROPERTY(bool showLoad READ willShowLoad WRITE setShowLoad)
Q_PROPERTY(QString instrumentOverride READ getInstrumentOverride WRITE Q_PROPERTY(QString instrumentOverride READ getInstrumentOverride WRITE
setInstrumentOverride) setInstrumentOverride)
Q_PROPERTY(bool multipleFiles READ allowMultipleFiles WRITE
allowMultipleFiles)
Q_PROPERTY(bool findRunFiles READ isForRunFiles WRITE isForRunFiles)
Q_PROPERTY(bool findDirectory READ isForDirectory WRITE isForDirectory)
Q_PROPERTY(QString label READ getLabelText WRITE setLabelText)
Q_PROPERTY(bool multiEntry READ doMultiEntry WRITE doMultiEntry)
Q_PROPERTY(QString algorithmAndProperty READ getAlgorithmProperty WRITE
setAlgorithmProperty)
Q_PROPERTY(bool extsAsSingleOption READ extsAsSingleOption WRITE
extsAsSingleOption)
Q_PROPERTY(ButtonOpts buttonOpts READ doButtonOpt WRITE doButtonOpt)
Q_PROPERTY(LiveButtonOpts liveButton READ liveButtonState WRITE
liveButtonState)
Q_ENUMS(ButtonOpts)
Q_ENUMS(LiveButtonOpts)
// These are properties of the workspace selector sub-widget
Q_PROPERTY(QStringList workspaceSuffixes READ getWSSuffixes WRITE
setWSSuffixes)
Q_PROPERTY(QStringList WorkspaceTypes READ getWorkspaceTypes WRITE
setWorkspaceTypes)
Q_PROPERTY(bool ShowHidden READ showHiddenWorkspaces WRITE
showHiddenWorkspaces)
Q_PROPERTY(QString Algorithm READ getValidatingAlgorithm WRITE
setValidatingAlgorithm)
// These are global properties of data selector
Q_PROPERTY(bool optional READ isOptional WRITE isOptional)
Q_PROPERTY(bool autoLoad READ willAutoLoad WRITE setAutoLoad)
Q_PROPERTY(QString loadLabelText READ getLoadBtnText WRITE setLoadBtnText)
public: public:
DataSelector(QWidget *parent = 0); DataSelector(QWidget *parent = 0);
...@@ -74,34 +105,282 @@ public: ...@@ -74,34 +105,282 @@ public:
bool isValid(); bool isValid();
/// Get file problem, empty string means no error. /// Get file problem, empty string means no error.
QString getProblem() const; QString getProblem() const;
/// Check if the widget is set to automatically attempt to load files
bool willAutoLoad();
/// Set the widget to automatically attempt to load files
void setAutoLoad(bool load);
/// Get the text of the load files button
QString getLoadBtnText();
/// Set the text of the load files button
void setLoadBtnText(const QString &text);
/// Get file suffixes to filter for in the workspace selector
QStringList getWSSuffixes();
/// Set file suffixes to filter for in the workspace selector
void setWSSuffixes(const QStringList &suffixes);
/// Get file suffixes to filter for in the file browser
QStringList getFBSuffixes();
/// Set file suffixes to filter for in the file browser
void setFBSuffixes(const QStringList &suffixes);
/// Read settings from the given group /// Read settings from the given group
void readSettings(const QString &group); void readSettings(const QString &);
/// Save settings in the given group /// Save settings in the given group
void saveSettings(const QString &group); void saveSettings(const QString &);
/// Gets if optional
bool isOptional() const;
/// Sets if optional
void isOptional(bool);
/// Gets will auto load
bool willAutoLoad() const;
/// Sets will auto load
void setAutoLoad(bool);
/// Check if the widget will show the load button /// Check if the widget will show the load button
bool willShowLoad(); bool willShowLoad();
/// Set if the load button should be shown /// Set if the load button should be shown
void setShowLoad(bool load); void setShowLoad(bool load);
/// Gets the instrument currently fixed to /// Gets the load button text
QString getInstrumentOverride(); QString getLoadBtnText() const;
/// Overrides the value of default instrument /// Sets the load button text
void setInstrumentOverride(const QString &instName); void setLoadBtnText(const QString &);
// These are accessors/modifiers of the child MWRunFiles
/**
* Return whether this widget allows multiple files to be specified within the
* edit box
* @returns True if multiple files can be specified, false otherwise
*/
bool allowMultipleFiles() const {
return m_uiForm.rfFileInput->allowMultipleFiles();
}
/**
* Set whether this widget allows multiple files to be specifed or not
* @param allow :: If true then the widget will accept multiple files else only
* a
* single file may be specified
*/
void allowMultipleFiles(const bool allow) {
m_uiForm.rfFileInput->allowMultipleFiles(allow);
}
/**
* Returns if this widget is for run file searching or not
* @returns True if this widget searches for run files, false otherwise
*/
bool isForRunFiles() const { return m_uiForm.rfFileInput->isForRunFiles(); }
/**
* Sets whether this widget is for run file searching or not
* @param mode :: True if this widget searches for run files, false otherwise
*/
void isForRunFiles(const bool mode) {
m_uiForm.rfFileInput->isForRunFiles(mode);
}
/**
* Returns if this widget is for selecting a directory or not.
* @return True if selecting a directory
*/
bool isForDirectory() const { return m_uiForm.rfFileInput->isForDirectory(); }
/**
* Sets directory searching mode.
* @param mode True to search for directories only
*/
void isForDirectory(const bool mode) {
m_uiForm.rfFileInput->isForDirectory(mode);
}
/**
* Return the label text on the widget
* @returns The current value of the text on the label
*/
QString getLabelText() const { return m_uiForm.rfFileInput->getLabelText(); }
/**
* Set the text on the label
* @param text :: A string giving the label to use for the text
*/
void setLabelText(const QString &text) {
m_uiForm.rfFileInput->setLabelText(text);
}
/**
* Whether to find the number of entries in the file or assume (the
* normal situation) of one entry
* @return true if the widget is to look for multiple entries
*/
bool doMultiEntry() const { return m_uiForm.rfFileInput->doMultiEntry(); }
/**
* Set to true to enable the period number box
* @param multiEntry whether to show the multiperiod box
*/
void doMultiEntry(const bool multiEntry) {
m_uiForm.rfFileInput->doMultiEntry(multiEntry);
}
/**
* Returns the algorithm name
* @returns The algorithm name
*/
QString getAlgorithmProperty() const {
return m_uiForm.rfFileInput->getAlgorithmProperty();
}
/**
* Sets an algorithm name that can be tied to this widget
* @param text :: The name of the algorithm and property in the form
* [AlgorithmName|PropertyName]
*/
void setAlgorithmProperty(const QString &text) {
m_uiForm.rfFileInput->setAlgorithmProperty(text);
}
/**
* Returns whether the file dialog should display the exts as a single list or
* as multiple items
* @return boolean
*/
bool extsAsSingleOption() const {
return m_uiForm.rfFileInput->extsAsSingleOption();
}
/**
* Sets whether the file dialog should display the exts as a single list or as
* multiple items
* @param value :: If true the file dialog wil contain a single entry will all
* filters
*/
void extsAsSingleOption(const bool value) {
m_uiForm.rfFileInput->extsAsSingleOption(value);
}
/**
* Gets the suffixes allowed by the file browser
*
* @return List of suffixes allowed by the file browser
*/
QStringList getFBSuffixes() {
return m_uiForm.rfFileInput->getFileExtensions();
}
/**
* Sets the suffixes allowed by the file browser
*
* @param suffixes :: List of suffixes allowed by the file browser
*/
void setFBSuffixes(const QStringList &suffixes) {
m_uiForm.rfFileInput->setFileExtensions(suffixes);
}
/**
* Gets the instrument override
*
* @return List of instrument override
*/
QString getInstrumentOverride() {
return m_uiForm.rfFileInput->getInstrumentOverride();
}
/**
* Sets the instrument override
*
* @param instName :: name of instrument override
*/
void setInstrumentOverride(const QString &instName) {
m_uiForm.rfFileInput->setInstrumentOverride(instName);
}
/**
* Returns the preference for how the dialog control should be
* @return the setting
*/
ButtonOpts doButtonOpt() const { return m_uiForm.rfFileInput->doButtonOpt(); }
/**
* Set how the browse should appear
* @param buttonOpt :: the preference for the control, if there will be one, to
* activate the dialog box
*/
void doButtonOpt(const ButtonOpts buttonOpt) {
m_uiForm.rfFileInput->doButtonOpt(buttonOpt);
}
/**
* Gets the live button state
*
* @return live button option
*/
LiveButtonOpts liveButtonState() const {
return m_uiForm.rfFileInput->liveButtonState();
}
/**
* Sets the live button state
*
* @param option :: livebutton option
*/
void liveButtonState(const LiveButtonOpts option) {
m_uiForm.rfFileInput->liveButtonState(option);
}
// These are accessors/modifiers of the child WorkspaceSelector
/**
* Gets the suffixes allowed by the workspace selector
*
* @return List of suffixes allowed by the workspace selector
*/
QStringList getWSSuffixes() {
return m_uiForm.wsWorkspaceInput->getSuffixes();
}
/**
* Sets the suffixes allowed by the workspace selector
*
* @param suffixes :: List of suffixes allowed by the workspace selector
*/
void setWSSuffixes(const QStringList &suffixes) {
m_uiForm.wsWorkspaceInput->setSuffixes(suffixes);
}
/**
* Gets the workspace types allowed by the workspace selector
*
* @return List of workspace types allowed by the workspace selector
*/
QStringList getWorkspaceTypes() const {
return m_uiForm.wsWorkspaceInput->getWorkspaceTypes();
}
/**
* Sets the workspace types allowed by the workspace selector
*
* @param types :: List of workspace types allowed by the workspace selector
*/
void setWorkspaceTypes(const QStringList &types) {
m_uiForm.wsWorkspaceInput->setWorkspaceTypes(types);
}
/**
* Gets if the workspace selector shows hidden workspaces
*
* @return Boolean flag if hidden workspaces are shown
*/
bool showHiddenWorkspaces() const {
return m_uiForm.wsWorkspaceInput->showHiddenWorkspaces();
}
/**
* Sets if the workspace selector shows hidden workspaces
*
* @param show :: Boolean flag if hidden workspaces are shown
*/
void showHiddenWorkspaces(bool show) {
m_uiForm.wsWorkspaceInput->showHiddenWorkspaces(show);
}
/**
* Gets if the validating algorithm of workspace selector
*
* @return validating algorithm
*/
QString getValidatingAlgorithm() const {
return m_uiForm.wsWorkspaceInput->getValidatingAlgorithm();
}
/**
* Sets the validating algorithm of workspace selector
*
* @param algName :: validating algorithm
*/
void setValidatingAlgorithm(const QString &algName) {
m_uiForm.wsWorkspaceInput->setValidatingAlgorithm(algName);
}
signals: signals:
/// Signal emitted when files were found but widget isn't autoloading /// Signal emitted when files were found but widget isn't autoloading
...@@ -143,6 +422,8 @@ private: ...@@ -143,6 +422,8 @@ private:
bool m_autoLoad; bool m_autoLoad;
/// Flag to show or hide the load button. By default this is set to true. /// Flag to show or hide the load button. By default this is set to true.
bool m_showLoad; bool m_showLoad;
/// Flag if optional
bool m_isOptional;
}; };
} /* namespace MantidWidgets */ } /* namespace MantidWidgets */
......
...@@ -38,12 +38,28 @@ DataSelector::DataSelector(QWidget *parent) ...@@ -38,12 +38,28 @@ DataSelector::DataSelector(QWidget *parent)
DataSelector::~DataSelector() {} DataSelector::~DataSelector() {}
/**
* Return whether empty input is allowed
* @return :: Flag if is optional
*/
bool DataSelector::isOptional() const { return m_isOptional; }
/**
* Sets if the text field is optional
* @param optional :: Set the optional status of the text field
*/
void DataSelector::isOptional(bool optional) {
m_isOptional = optional;
m_uiForm.rfFileInput->isOptional(optional);
m_uiForm.wsWorkspaceInput->setOptional(optional);
}
/** /**
* Handle signals when files are found or the user manually clicks load. * Handle signals when files are found or the user manually clicks load.
*/ */
void DataSelector::handleFileInput() { void DataSelector::handleFileInput() {
// Get filename and check it's not empty // Get filename and check it's not empty
QString filename = m_uiForm.rfFileInput->getFirstFilename(); QString filename = m_uiForm.rfFileInput->getUserInput().toString();
if (filename.isEmpty()) { if (filename.isEmpty()) {
return; return;
...@@ -101,7 +117,8 @@ bool DataSelector::isValid() { ...@@ -101,7 +117,8 @@ bool DataSelector::isValid() {
if (!AnalysisDataService::Instance().doesExist(wsName.toStdString())) { if (!AnalysisDataService::Instance().doesExist(wsName.toStdString())) {
// attempt to reload if we can // attempt to reload if we can
// don't use algorithm runner because we need to know instantly. // don't use algorithm runner because we need to know instantly.
const QString filepath = m_uiForm.rfFileInput->getFirstFilename(); const QString filepath =
m_uiForm.rfFileInput->getUserInput().toString();
const Algorithm_sptr loadAlg = const Algorithm_sptr loadAlg =
AlgorithmManager::Instance().createUnmanaged("Load"); AlgorithmManager::Instance().createUnmanaged("Load");
loadAlg->initialize(); loadAlg->initialize();
...@@ -231,7 +248,7 @@ void DataSelector::handleViewChanged(int index) { ...@@ -231,7 +248,7 @@ void DataSelector::handleViewChanged(int index) {
* @return The full file path * @return The full file path
*/ */
QString DataSelector::getFullFilePath() const { QString DataSelector::getFullFilePath() const {
return m_uiForm.rfFileInput->getFirstFilename(); return m_uiForm.rfFileInput->getUserInput().toString();
} }
/** /**
...@@ -253,8 +270,7 @@ QString DataSelector::getCurrentDataName() const { ...@@ -253,8 +270,7 @@ QString DataSelector::getCurrentDataName() const {
case 0: case 0:
// the file selector is visible // the file selector is visible
if (m_uiForm.rfFileInput->isValid()) { if (m_uiForm.rfFileInput->isValid()) {
QFileInfo qfio(m_uiForm.rfFileInput->getFirstFilename()); filename = m_uiForm.rfFileInput->getUserInput().toString();
filename = qfio.completeBaseName();
} }
break; break;
case 1: case 1:
...@@ -271,7 +287,7 @@ QString DataSelector::getCurrentDataName() const { ...@@ -271,7 +287,7 @@ QString DataSelector::getCurrentDataName() const {
* *
* @return Whether the widget will auto load * @return Whether the widget will auto load
*/ */
bool DataSelector::willAutoLoad() { return m_autoLoad; } bool DataSelector::willAutoLoad() const { return m_autoLoad; }
/** /**
* Sets whether the widget will attempt to auto load files. * Sets whether the widget will attempt to auto load files.
...@@ -285,7 +301,9 @@ void DataSelector::setAutoLoad(bool load) { m_autoLoad = load; } ...@@ -285,7 +301,9 @@ void DataSelector::setAutoLoad(bool load) { m_autoLoad = load; }
* *
* @return The text on the load button * @return The text on the load button
*/ */
QString DataSelector::getLoadBtnText() { return m_uiForm.pbLoadFile->text(); } QString DataSelector::getLoadBtnText() const {
return m_uiForm.pbLoadFile->text();
}
/** /**
* Sets the text shown on the load button. * Sets the text shown on the load button.
...@@ -296,42 +314,6 @@ void DataSelector::setLoadBtnText(const QString &text) { ...@@ -296,42 +314,6 @@ void DataSelector::setLoadBtnText(const QString &text) {
m_uiForm.pbLoadFile->setText(text); m_uiForm.pbLoadFile->setText(text);
} }
/**
* Gets the suffixes allowed by the workspace selector
*
* @return List of suffixes allowed by the workspace selector
*/
QStringList DataSelector::getWSSuffixes() {
return m_uiForm.wsWorkspaceInput->getSuffixes();
}
/**
* Sets the suffixes allowed by the workspace selector
*
* @param suffixes :: List of suffixes allowed by the workspace selector
*/
void DataSelector::setWSSuffixes(const QStringList &suffixes) {
m_uiForm.wsWorkspaceInput->setSuffixes(suffixes);
}
/**
* Gets the suffixes allowed by the file browser
*
* @return List of suffixes allowed by the file browser
*/
QStringList DataSelector::getFBSuffixes() {
return m_uiForm.rfFileInput->getFileExtensions();
}
/**
* Sets the suffixes allowed by the file browser
*
* @param suffixes :: List of suffixes allowed by the file browser
*/
void DataSelector::setFBSuffixes(const QStringList &suffixes) {
m_uiForm.rfFileInput->setFileExtensions(suffixes);
}
/** /**
* Read settings from the given group * Read settings from the given group
* @param group :: The name of the group key to retrieve data from * @param group :: The name of the group key to retrieve data from
...@@ -367,34 +349,6 @@ void DataSelector::setShowLoad(bool load) { ...@@ -367,34 +349,6 @@ void DataSelector::setShowLoad(bool load) {
m_showLoad = load; m_showLoad = load;
} }
/**
* Gets the instrument currently set by the override property.
*
* If no override is set then the instrument set by default instrument
* configurtion
* option will be used and this function returns an empty string.
*
* @return Name of instrument, empty if not set
*/
QString DataSelector::getInstrumentOverride() {
return m_uiForm.rfFileInput->getInstrumentOverride();
}
/**
* Sets an instrument to fix the widget to.
*
* If an instrument name is geven then the widget will only look for files for
* that
* instrument, providing na empty string will remove this restriction and will
* search
* using the default instrument.
*
* @param instName Name of instrument, empty to disable override
*/
void DataSelector::setInstrumentOverride(const QString &instName) {
m_uiForm.rfFileInput->setInstrumentOverride(instName);
}
/** /**
* Called when an item is dropped * Called when an item is dropped
* @param de :: the drop event data package * @param de :: the drop event data package
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment