|
Mantid
|
A specialized class for dealing with file properties. More...
#include <FileProperty.h>
Public Types | |
| enum | FileAction { Save = 0 , OptionalSave = 1 , Load = 2 , OptionalLoad = 3 , Directory = 4 , OptionalDirectory = 5 } |
| An enumeration for load/save types. More... | |
Public Member Functions | |
| FileProperty * | clone () const override |
| 'Virtual copy constructor | |
| FileProperty (const FileProperty &)=default | |
| FileProperty (const std::string &name, const std::string &default_value, unsigned int action, const std::string &ext, unsigned int direction=Kernel::Direction::Input) | |
| Constructor taking a single extension as a string. | |
| FileProperty (const std::string &name, const std::string &default_value, unsigned int action, std::initializer_list< std::string > exts, unsigned int direction=Kernel::Direction::Input) | |
| Constructor taking a list of extensions as an initializer_list. | |
| FileProperty (const std::string &name, const std::string &defaultValue, unsigned int action, const std::vector< std::string > &exts=std::vector< std::string >(), unsigned int direction=Kernel::Direction::Input) | |
| Constructor taking a list of extensions as a vector. | |
| const std::string & | getDefaultExt () const |
| Returns the main file extension that's used. | |
| bool | isDirectoryProperty () const |
| Check if this is a directory type property. | |
| bool | isLoadProperty () const |
| Check if this is a load type property. | |
| bool | isOptional () const |
| Check if this property is optional. | |
| bool | isSaveProperty () const |
| Check if this is a save type property. | |
| std::string | isValid () const override |
| Returns an empty string if the property is valid, otherwise contains an error message. | |
| FileProperty & | operator= (const FileProperty &)=default |
| std::string | setValue (const std::string &propValue) override |
| Overridden setValue method. | |
Public Member Functions inherited from Mantid::Kernel::PropertyWithValue< std::string > | |
| std::vector< std::string > | allowedValues () const override |
| Returns the set of valid values for this property, if such a set exists. | |
| PropertyWithValue< std::string > * | clone () const override |
| 'Virtual copy constructor' | |
| std::string | getDefault () const override |
| Get the value the property was initialised with -its default value. | |
| IValidator_sptr | getValidator () const |
| Returns the validator as a constant variable so it cannot be changed. | |
| bool | isDefault () const override |
| Indicates if the property's value is the same as it was when it was set N.B. | |
| bool | isMultipleSelectionAllowed () override |
| Returns the set of valid values for this property, if such a set exists. | |
| std::string | isValid () const override |
| Check the value chosen for the property is OK, unless overidden it just calls the validator's isValid() N.B. | |
| virtual | operator const std::string & () const |
| Allows you to get the value of the property simply by typing its name. | |
| bool | operator!= (const PropertyWithValue< std::string > &rhs) const |
| Deep comparison (not equal). | |
| virtual const std::string & | operator() () const |
| Allows you to get the value of the property via an expression like myProperty() | |
| PropertyWithValue & | operator+= (Property const *right) override |
| Add the value of another property. | |
| PropertyWithValue & | operator= (const PropertyWithValue &right) |
| Copy assignment operator assigns only the value and the validator not the name, default (initial) value, etc. | |
| virtual PropertyWithValue & | operator= (const std::string &value) |
| Assignment operator. | |
| bool | operator== (const PropertyWithValue< std::string > &rhs) const |
| Deep comparison. | |
| PropertyWithValue ()=delete | |
| PropertyWithValue (const PropertyWithValue< std::string > &right) | |
| Copy constructor Note the default value of the copied object is the initial value of original. | |
| PropertyWithValue (const std::string &name, const std::string &defaultValue, const std::string &defaultValueStr, IValidator_sptr validator, const unsigned int direction) | |
| Constructor. | |
| PropertyWithValue (std::string name, std::string defaultValue, const unsigned int direction) | |
| Constructor. | |
| PropertyWithValue (std::string name, std::string defaultValue, IValidator_sptr validator=IValidator_sptr(new NullValidator), const unsigned int direction=Direction::Input) | |
| Constructor. | |
| virtual void | replaceValidator (IValidator_sptr newValidator) |
| Replace the current validator with the given one. | |
| MANTID_KERNEL_DLL void | saveProperty (Nexus::File *file) |
| MANTID_KERNEL_DLL void | saveProperty (Nexus::File *file) |
| MANTID_KERNEL_DLL void | saveProperty (Nexus::File *file) |
| MANTID_KERNEL_DLL void | saveProperty (Nexus::File *file) |
| MANTID_KERNEL_DLL void | saveProperty (Nexus::File *file) |
| MANTID_KERNEL_DLL void | saveProperty (Nexus::File *file) |
| MANTID_KERNEL_DLL void | saveProperty (Nexus::File *file) |
| MANTID_KERNEL_DLL void | saveProperty (Nexus::File *file) |
| MANTID_KERNEL_DLL void | saveProperty (Nexus::File *file) |
| void | saveProperty (Nexus::File *file) override |
| std::string | setDataItem (const std::shared_ptr< DataItem > &data) override |
| Set a property value via a DataItem. | |
| std::string | setValue (const std::string &value) override |
| Set the value of the property from a string representation. | |
| std::string | setValueFromJson (const Json::Value &value) override |
| Set the value of the property from a Json representation. | |
| int | size () const override |
| Get the size of the property. | |
| std::string | value () const override |
| Get the value of the property as a string. | |
| Json::Value | valueAsJson () const override |
| Attempt to construct a Json::Value object from the plain value. | |
| std::string | valueAsPrettyStr (const size_t maxLength=0, const bool collapseLists=true) const override |
| Get the value of the property as a string. | |
Public Member Functions inherited from Mantid::Kernel::Property | |
| bool | autoTrim () const |
| Returns if the property is set to automatically trim string unput values of whitespace. | |
| void | clearSettings () |
| Deletes the PropertySettings object contained. | |
| virtual const PropertyHistory | createHistory () const |
| Create a PropertyHistory object representing the current state of the Property. | |
| void | createTemporaryValue () |
| Create a temporary value for this property. | |
| unsigned int | direction () const |
| returns the direction of the property | |
| bool | disableReplaceWSButton () const |
| Returns if the property is set to disable the creation of the "Replace Workspace" button. | |
| const std::string & | documentation () const |
| Get the property's documentation string. | |
| const std::string & | getGroup () |
| virtual size_t | getMemorySize () const |
| IPropertySettings * | getSettings () |
| const IPropertySettings * | getSettings () const |
| bool | hasTemporaryValue () const |
| Property is using a temporary value for this property. | |
| bool | isDynamicDefault () const |
| Returns a flag indicating that the property's value has been set programmatically, for example, if the property has a default value which depends on the value of an upstream property. | |
| virtual bool | isValueSerializable () const |
| Whether the string returned by value() can be used for serialization. | |
| virtual Property & | merge (Property *) |
| Just returns the property (*this) unless overridden. | |
| const std::string & | name () const |
| Get the property's name. | |
| bool | remember () const |
| Whether to save input values. | |
| void | setAutoTrim (const bool &setting) |
| Sets if the property is set to automatically trim string unput values of whitespace. | |
| void | setDisableReplaceWSButton (const bool &disable) |
| Sets the property to disable the creation of the "Replace Workspace" button. | |
| void | setDocumentation (const std::string &documentation) |
| Sets the user level description of the property. | |
| void | setGroup (const std::string &group) |
| Set the group this property belongs to. | |
| void | setIsDynamicDefault (const bool &flag) |
| Set or clear the flag indicating whether or not the property's value has been set programmatically. | |
| void | setName (const std::string &name) |
| Set the property's name. | |
| void | setRemember (bool) |
| Set wheter to remeber this property input. | |
| void | setSettings (std::unique_ptr< IPropertySettings > settings) |
| Set the PropertySettings object. | |
| virtual void | setUnits (const std::string &unit) |
| Sets the units of the property, as a string. | |
| const std::string | type () const |
| Returns the type of the property as a string. | |
| const std::type_info * | type_info () const |
| Get the property type_info. | |
| virtual const std::string & | units () const |
| Returns the units of the property, if any, as a string. | |
| virtual | ~Property () |
| Virtual destructor. | |
Private Member Functions | |
| bool | extsMatchRunFiles () |
| Do the allowed values match the facility preference extensions for run files. | |
| std::string | isEmptyValueValid () const |
| Returns a string depending on whether an empty value is valid. | |
| std::string | setLoadProperty (const std::string &propValue) |
| Handles the filename if this is a save property. | |
| std::string | setSaveProperty (const std::string &propValue) |
| Handles the filename if this is a save property. | |
Private Attributes | |
| unsigned int | m_action |
| The action type of this property, i.e. load/save. | |
| std::string | m_defaultExt |
| The default file extension associated with the type of file this property will handle. | |
| std::string | m_oldLoadFoundFile |
| Last value of foundFile used in FileProperty::setLoadProperty. | |
| std::string | m_oldLoadPropValue |
| Last value of propValue used in FileProperty::setLoadProperty. | |
| bool | m_runFileProp |
| Is this property for run files? | |
Additional Inherited Members | |
Protected Member Functions inherited from Mantid::Kernel::Property | |
| Property (const Property &right) | |
| Copy constructor. | |
| Property (std::string name, const std::type_info &type, const unsigned int &direction=Direction::Input) | |
| Constructor. | |
Protected Attributes inherited from Mantid::Kernel::PropertyWithValue< std::string > | |
| std::string | m_initialValue |
| the property's default value which is also its initial value | |
| std::string | m_value |
| The value of the property. | |
Protected Attributes inherited from Mantid::Kernel::Property | |
| std::string | m_name |
| The name of the property. | |
A specialized class for dealing with file properties.
Mantid allows multiple search paths to be defined so that each of these is used when attempting to load a file with a relative path.
When attempting to load a file this class handles searching the specified paths and, if found, the value() method returns the full path to the file. For saving, Mantid's default save directory is used when a relative path is encountered.
This class can also be used to browse for a Directory, by specify the appropriate FileAction type parameter in the constructor.
Definition at line 42 of file FileProperty.h.
An enumeration for load/save types.
This is passed on to the FileValidator as a constructor parameter.
Definition at line 46 of file FileProperty.h.
| Mantid::API::FileProperty::FileProperty | ( | const std::string & | name, |
| const std::string & | defaultValue, | ||
| unsigned int | action, | ||
| const std::vector< std::string > & | exts = std::vector<std::string>(), |
||
| unsigned int | direction = Kernel::Direction::Input |
||
| ) |
Constructor taking a list of extensions as a vector.
Constructor.
| name | The name of the property |
| defaultValue | A default value for the property |
| action | Inndicate whether this should be a load/save property |
| exts | The allowed extensions. The front entry in the vector will be the default extension |
| direction | An optional direction (default=Input) |
Definition at line 153 of file FileProperty.cpp.
| Mantid::API::FileProperty::FileProperty | ( | const std::string & | name, |
| const std::string & | default_value, | ||
| unsigned int | action, | ||
| const std::string & | ext, | ||
| unsigned int | direction = Kernel::Direction::Input |
||
| ) |
Constructor taking a single extension as a string.
Constructor.
| name | :: The name of the property |
| default_value | :: A default value for the property |
| ext | :: The allowed extension |
| action | :: An enum indicating whether this should be a load/save property |
| direction | :: An optional direction (default=Input) |
Definition at line 168 of file FileProperty.cpp.
| Mantid::API::FileProperty::FileProperty | ( | const std::string & | name, |
| const std::string & | default_value, | ||
| unsigned int | action, | ||
| std::initializer_list< std::string > | exts, | ||
| unsigned int | direction = Kernel::Direction::Input |
||
| ) |
Constructor taking a list of extensions as an initializer_list.
Constructor.
| name | :: The name of the property |
| default_value | :: A default value for the property |
| exts | :: The braced-list of allowed extensions |
| action | :: An enum indicating whether this should be a load/save property |
| direction | :: An optional direction (default=Input) |
Definition at line 181 of file FileProperty.cpp.
|
default |
|
inlineoverridevirtual |
'Virtual copy constructor
Implements Mantid::Kernel::Property.
Definition at line 73 of file FileProperty.h.
|
private |
Do the allowed values match the facility preference extensions for run files.
Definition at line 286 of file FileProperty.cpp.
References Mantid::Kernel::PropertyWithValue< std::string >::allowedValues(), and Mantid::Kernel::FacilityInfo::extensions().
|
inline |
Returns the main file extension that's used.
Definition at line 90 of file FileProperty.h.
Referenced by MantidQt::API::FileFinderWidget::getFileExtensionsFromAlgorithm(), MantidQt::MantidWidgets::SaveWorkspaces::getSaveAlgExt(), and MantidQt::MantidWidgets::WorkspaceTreeWidget::saveToProgram().
| bool Mantid::API::FileProperty::isDirectoryProperty | ( | ) | const |
Check if this is a directory type property.
Check if this is a directory selection property.
Definition at line 201 of file FileProperty.cpp.
References Directory, m_action, and OptionalDirectory.
|
private |
Returns a string depending on whether an empty value is valid.
Definition at line 272 of file FileProperty.cpp.
References isOptional().
Referenced by isValid(), and setValue().
| bool Mantid::API::FileProperty::isLoadProperty | ( | ) | const |
Check if this is a load type property.
Check if this is a load property.
Definition at line 189 of file FileProperty.cpp.
References m_action, and OptionalLoad.
Referenced by setValue().
| bool Mantid::API::FileProperty::isOptional | ( | ) | const |
Check if this property is optional.
Definition at line 207 of file FileProperty.cpp.
References m_action, OptionalDirectory, OptionalLoad, and OptionalSave.
Referenced by isEmptyValueValid().
| bool Mantid::API::FileProperty::isSaveProperty | ( | ) | const |
Check if this is a save type property.
Check if this is a Save property.
Definition at line 195 of file FileProperty.cpp.
References m_action, OptionalSave, and Save.
Referenced by setValue().
|
overridevirtual |
Returns an empty string if the property is valid, otherwise contains an error message.
Checks whether the current value is considered valid.
Use the validator unless the value is an empty string. In this case it is only valid if the property is not optional
Reimplemented from Mantid::Kernel::Property.
Definition at line 260 of file FileProperty.cpp.
References isEmptyValueValid(), Mantid::Kernel::PropertyWithValue< TYPE >::isValid(), and Mantid::Kernel::PropertyWithValue< std::string >::value().
|
default |
|
private |
Handles the filename if this is a save property.
Handles the filename if this is a load property.
| propValue | :: The filename to treat as a filepath to be loaded |
Definition at line 308 of file FileProperty.cpp.
References Mantid::Kernel::PropertyWithValue< std::string >::allowedValues(), lower, m_defaultExt, m_oldLoadFoundFile, m_oldLoadPropValue, m_runFileProp, Mantid::Kernel::PropertyWithValue< TYPE >::setValue(), Mantid::Kernel::Strings::toLower(), Mantid::Kernel::Strings::toUpper(), and upper.
Referenced by setValue().
|
private |
Handles the filename if this is a save property.
| propValue | :: The filename to treat as a filepath to be saved |
Definition at line 364 of file FileProperty.cpp.
References m_action, OptionalSave, and Mantid::Kernel::PropertyWithValue< TYPE >::setValue().
Referenced by setValue().
|
overridevirtual |
Overridden setValue method.
Set the value of the property.
| propValue | :: The value here is treated as relating to a filename |
Implements Mantid::Kernel::Property.
Definition at line 217 of file FileProperty.cpp.
References error, isEmptyValueValid(), isLoadProperty(), isSaveProperty(), setLoadProperty(), setSaveProperty(), Mantid::Kernel::PropertyWithValue< TYPE >::setValue(), and Mantid::Kernel::Strings::strip().
Referenced by Mantid::API::MultipleFileProperty::setValueAsMultipleFiles(), and Mantid::API::MultipleFileProperty::setValueAsSingleFile().
|
private |
The action type of this property, i.e. load/save.
Definition at line 106 of file FileProperty.h.
Referenced by isDirectoryProperty(), isLoadProperty(), isOptional(), isSaveProperty(), and setSaveProperty().
|
private |
The default file extension associated with the type of file this property will handle.
Definition at line 109 of file FileProperty.h.
Referenced by setLoadProperty().
|
private |
Last value of foundFile used in FileProperty::setLoadProperty.
Definition at line 115 of file FileProperty.h.
Referenced by setLoadProperty().
|
private |
Last value of propValue used in FileProperty::setLoadProperty.
Definition at line 113 of file FileProperty.h.
Referenced by setLoadProperty().
|
private |
Is this property for run files?
Definition at line 111 of file FileProperty.h.
Referenced by setLoadProperty().