39double stringToRoundedNumber(
const std::string &s) {
45 const bool containsComma = s.find(
",") != std::string::npos;
47 throw std::runtime_error(
"string contains a comma");
61 const auto guineaPig = std::shared_ptr<Property>(prop->
clone());
62 return guineaPig->setValue(
value).empty();
75bool isEmptyNumMacro(
const std::string &
value,
const double value_d) {
80 if (
value ==
"2.14748e+09")
83 static const std::vector<double> EMPTY_NUM_MACROS = {
EMPTY_DBL(),
88 static_cast<double>(-INT_MAX),
89 static_cast<double>(-LONG_MAX)};
91 return std::find(EMPTY_NUM_MACROS.begin(), EMPTY_NUM_MACROS.end(), value_d) != EMPTY_NUM_MACROS.end();
102 return isValidPropertyValue(prop,
"") || isValidPropertyValue(prop, prop->
getDefault());
116 const std::string defaultValue = prop->
getDefault();
117 if (defaultValue.empty())
120 if (!isValidPropertyValue(prop, defaultValue))
126 if (defaultValue ==
"-0" || defaultValue ==
"-0.0")
131 double roundedNumber;
133 roundedNumber = stringToRoundedNumber(defaultValue);
134 }
catch (std::exception &) {
138 if (isEmptyNumMacro(prop->
getDefault(), roundedNumber))
145 static const std::size_t STRING_ROUNDING_LENGTH = 15;
146 if (defaultValue.length() >= STRING_ROUNDING_LENGTH) {
147 std::stringstream roundedValue;
148 roundedValue << roundedNumber;
149 return roundedValue.str();
181 : QWidget(parent), m_prop(prop), m_gridLayout(layout), m_parent(nullptr), m_row(row),
182 m_doc(), m_replaceWSButton(nullptr), m_widgets(), m_lastValue(), m_error(), m_isOutputWsProp(false),
183 m_previousValue(), m_previous_isDynamicDefault(false), m_enteredValue(), m_entered_isDynamicDefault(false),
184 m_icons(), m_useHistory(true) {
186 throw std::runtime_error(
"NULL Property passed to the PropertyWidget constructor.");
187 setObjectName(QString::fromStdString(prop->
name()));
209 auto *infoWidget =
new QWidget();
210 infoWidget->setLayout(
new QHBoxLayout(
this));
211 infoWidget->layout()->setSpacing(1);
212 infoWidget->layout()->setContentsMargins(0, 0, 0, 0);
216 QMap<Info, QPair<QString, QString>> pathsAndToolTips;
218 QPair<QString, QString>(
":/history.png",
"This property had a previously-entered value. Click "
219 "to toggle it off and on.");
221 QPair<QString, QString>(
":/replace.png",
"A workspace with this name already exists and so will be overwritten.");
222 pathsAndToolTips[
INVALID] = QPair<QString, QString>(
":/invalid.png",
"");
226 for (
const Info &info : labelOrder) {
227 const QString iconPath = pathsAndToolTips[info].first;
228 const QString toolTip = pathsAndToolTips[info].second;
231 icon->setPixmap(QPixmap(iconPath).scaledToHeight(15));
232 icon->setVisible(
false);
233 icon->setToolTip(toolTip);
235 infoWidget->layout()->addWidget(icon);
242 connect(
this, &QObject::destroyed,
this, [infoWidget]() {
243 infoWidget->deleteLater();
251 if (!isOptionalProperty(prop)) {
252 if (!
m_doc.isEmpty())
254 m_doc +=
"This property is required.";
365 QString userError(
error);
366 if (userError.isEmpty()) {
375 }
catch (std::exception &err_details) {
376 userError = QString::fromLatin1(err_details.what());
379 this->
setError(userError.trimmed());
385 const bool wsExists = Mantid::API::AnalysisDataService::Instance().doesExist(
getValue().toStdString());
462 const QString iconPath = useHistory ? (isDynamicDefault ?
":/history_dynamic_default.png" :
":/history.png")
463 : (isDynamicDefault ?
":/history_off_dynamic_default.png" :
":/history_off.png");
464 m_icons[
RESTORE]->setPixmap(QPixmap(iconPath).scaledToHeight(15));
511 widget->setEnabled(val);
512 QWidget::setEnabled(val);
519 widget->setVisible(val);
520 QWidget::setVisible(val);
532 if (!isOptionalProperty(prop)) {
533 auto font = label->font();
535 label->setFont(font);
548 field->setPlaceholderText(QString::fromStdString(createFieldPlaceholderText(prop)));
double value
The value of the point.
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
double lower
lower and upper bounds on the multiplier, if known
A small extension to QLabel, so that it emits a signal when clicked.
~ClickableLabel() override
Destructor.
void mousePressEvent(QMouseEvent *event) override
Catches the mouse press event and emits the signal.
ClickableLabel(QWidget *parent)
Constructor.
void clicked()
Signal emitted when a user clicks the label.
An interface that is implemented by WorkspaceProperty.
Base class for properties.
bool isDynamicDefault() const
Returns a flag indicating that the property's value has been set programmatically,...
void setIsDynamicDefault(const bool &flag)
Set or clear the flag indicating whether or not the property's value has been set programmatically.
unsigned int direction() const
returns the direction of the property
const std::string & documentation() const
Get the property's documentation string.
virtual std::string setValue(const std::string &)=0
Set the value of the property via a string.
virtual Property * clone() const =0
'Virtual copy constructor'
const std::string & name() const
Get the property's name.
virtual std::string getDefault() const =0
Get the default value for the property which is the value the property was initialised with.
virtual std::string value() const =0
Returns the value of the property as a string.
Helper class which provides the Collimation Length for SANS instruments.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
constexpr long EMPTY_LONG() noexcept
Returns what we consider an "empty" long within a property.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Output
An output workspace.