40double stringToRoundedNumber(
const std::string &s) {
46 const bool containsComma = s.find(
",") != std::string::npos;
48 throw std::runtime_error(
"string contains a comma");
62 const auto guineaPig = std::shared_ptr<Property>(prop->
clone());
63 return guineaPig->setValue(
value).empty();
76bool isEmptyNumMacro(
const std::string &
value,
const double value_d) {
81 if (
value ==
"2.14748e+09")
84 static const std::vector<double> EMPTY_NUM_MACROS = {
EMPTY_DBL(),
89 static_cast<double>(-INT_MAX),
90 static_cast<double>(-LONG_MAX)};
92 return std::find(EMPTY_NUM_MACROS.begin(), EMPTY_NUM_MACROS.end(), value_d) != EMPTY_NUM_MACROS.end();
103 return isValidPropertyValue(prop,
"") || isValidPropertyValue(prop, prop->
getDefault());
117 const std::string defaultValue = prop->
getDefault();
118 if (defaultValue.empty())
121 if (!isValidPropertyValue(prop, defaultValue))
127 if (defaultValue ==
"-0" || defaultValue ==
"-0.0")
132 double roundedNumber;
134 roundedNumber = stringToRoundedNumber(defaultValue);
135 }
catch (std::exception &) {
139 if (isEmptyNumMacro(prop->
getDefault(), roundedNumber))
146 static const std::size_t STRING_ROUNDING_LENGTH = 15;
147 if (defaultValue.length() >= STRING_ROUNDING_LENGTH) {
148 std::stringstream roundedValue;
149 roundedValue << roundedNumber;
150 return roundedValue.str();
182 : QWidget(parent), m_prop(prop), m_gridLayout(layout), m_parent(nullptr), m_row(row),
183 m_doc(), m_replaceWSButton(nullptr), m_widgets(), m_lastValue(), m_error(), m_isOutputWsProp(false),
184 m_previousValue(), m_previous_isDynamicDefault(false), m_enteredValue(), m_entered_isDynamicDefault(false),
185 m_icons(), m_useHistory(true) {
187 throw std::runtime_error(
"NULL Property passed to the PropertyWidget constructor.");
188 setObjectName(QString::fromStdString(prop->
name()));
210 auto *infoWidget =
new QWidget();
211 infoWidget->setLayout(
new QHBoxLayout(
this));
212 infoWidget->layout()->setSpacing(1);
213 infoWidget->layout()->setContentsMargins(0, 0, 0, 0);
217 QMap<Info, std::pair<QString, QString>> pathsAndToolTips;
219 std::pair<QString, QString>(
":/history.png",
"This property had a previously-entered value. Click "
220 "to toggle it off and on.");
221 pathsAndToolTips[
REPLACE] = std::pair<QString, QString>(
222 ":/replace.png",
"A workspace with this name already exists and so will be overwritten.");
223 pathsAndToolTips[
INVALID] = std::pair<QString, QString>(
":/invalid.png",
"");
227 for (
const Info &info : labelOrder) {
228 const QString iconPath = pathsAndToolTips[info].first;
229 const QString toolTip = pathsAndToolTips[info].second;
232 icon->setPixmap(QPixmap(iconPath).scaledToHeight(15));
233 icon->setVisible(
false);
234 icon->setToolTip(toolTip);
236 infoWidget->layout()->addWidget(icon);
243 connect(
this, &QObject::destroyed,
this, [infoWidget]() {
244 infoWidget->deleteLater();
252 if (!isOptionalProperty(prop)) {
253 if (!
m_doc.isEmpty())
255 m_doc +=
"This property is required.";
366 QString userError(
error);
367 if (userError.isEmpty()) {
376 }
catch (std::exception &err_details) {
377 userError = QString::fromLatin1(err_details.what());
380 this->
setError(userError.trimmed());
386 const bool wsExists = Mantid::API::AnalysisDataService::Instance().doesExist(
getValue().toStdString());
463 const QString iconPath = useHistory ? (isDynamicDefault ?
":/history_dynamic_default.png" :
":/history.png")
464 : (isDynamicDefault ?
":/history_off_dynamic_default.png" :
":/history_off.png");
465 m_icons[
RESTORE]->setPixmap(QPixmap(iconPath).scaledToHeight(15));
512 widget->setEnabled(val);
513 QWidget::setEnabled(val);
520 widget->setVisible(val);
521 QWidget::setVisible(val);
533 if (!isOptionalProperty(prop)) {
534 auto font = label->font();
536 label->setFont(font);
549 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.