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_error(), m_isOutputWsProp(false), m_previousValue(),
183 m_enteredValue(), m_icons(), m_useHistory(true) {
185 throw std::runtime_error(
"NULL Property passed to the PropertyWidget constructor.");
186 setObjectName(QString::fromStdString(prop->
name()));
208 auto *infoWidget =
new QWidget();
209 infoWidget->setLayout(
new QHBoxLayout(
this));
210 infoWidget->layout()->setSpacing(1);
211 infoWidget->layout()->setContentsMargins(0, 0, 0, 0);
214 QMap<Info, QPair<QString, QString>> pathsAndToolTips;
216 QPair<QString, QString>(
":/history.png",
"This property had a previously-entered value. Click "
217 "to toggle it off and on.");
219 QPair<QString, QString>(
":/replace.png",
"A workspace with this name already exists and so will be overwritten.");
220 pathsAndToolTips[
INVALID] = QPair<QString, QString>(
":/invalid.png",
"");
224 for (
const Info &info : labelOrder) {
225 const QString iconPath = pathsAndToolTips[info].first;
226 const QString toolTip = pathsAndToolTips[info].second;
229 icon->setPixmap(QPixmap(iconPath).scaledToHeight(15));
230 icon->setVisible(
false);
231 icon->setToolTip(toolTip);
233 infoWidget->layout()->addWidget(icon);
242 if (!isOptionalProperty(prop)) {
243 if (!
m_doc.isEmpty())
245 m_doc +=
"This property is required.";
296 QString userError(
error);
297 if (userError.isEmpty()) {
306 }
catch (std::exception &err_details) {
307 userError = QString::fromLatin1(err_details.what());
310 this->
setError(userError.trimmed());
364 const QString iconPath = useHistory ?
":/history.png" :
":/history_off.png";
365 m_icons[
RESTORE]->setPixmap(QPixmap(iconPath).scaledToHeight(15));
407 widget->setEnabled(val);
408 QWidget::setEnabled(val);
415 widget->setVisible(val);
416 QWidget::setVisible(val);
428 if (!isOptionalProperty(prop)) {
429 auto font = label->font();
431 label->setFont(font);
444 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.
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.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
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.