WSL/SLF GitLab Repository

Commit 8a4ca6ed authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Implemented issue 874

Now specifying validation="coordinates" validates the string against a
fixed coordinates regex and either prints the warning sign or a globe.
parent 2a75b577
......@@ -146,7 +146,7 @@ INIshell include file for common neccessities
</parameter>
</parametergroup>
<parametergroup name="STATIONGROUP_POSITION_SPECS">
<parameter key="VSTATION#" type="text" replicate="true" optional="false" validate="(latlon|xy)\s*\([-\d\s\.,]+\)">
<parameter key="VSTATION#" type="text" replicate="true" optional="false" validate="coordinates">
<help>Coordinates are given as lat/lon/alt or easting/northing/alt such as &lt;code&gt;"latlon (46.75, 9.80, 2200)"&lt;/code&gt; or &lt;code&gt;"xy (198754, 723458, 2200)"&lt;/code&gt;</help>
</parameter>
<parameter key="VID#" type="text" replicate="true" optional="false">
......
......@@ -332,7 +332,7 @@ Please include meteoio_parametergroups before use!
<parameter key="CSV_AZIMUTH" type="number" format="integer+" min="0" max="360">
<help>The slope azimuth at the station, in degrees from North </help>
</parameter>
<parameter key="POSITION" type="text" validate="(latlon|xy)\s*\([-\d\s\.,]+\)">
<parameter key="POSITION" type="text" validate="coordinates">
<help>Coordinates are given as lat/lon/alt or easting/northing/alt such as &lt;code&gt;latlon (46.75, 9.80, 2200)&lt;/code&gt; or &lt;code&gt;xy (198754, 723458, 2200)&lt;/code&gt;</help>
</parameter>
<parameter key="CSV_SPECIAL_HEADERS" type="text">
......@@ -350,7 +350,7 @@ Please include meteoio_parametergroups before use!
</parameter>
</option>
<option>
<parameter key="POSITION#" type="text" validate="(latlon|xy)\s*\([-\d\s\.,]+\)">
<parameter key="POSITION#" type="text" validate="coordinates">
<help>Coordinates are given as lat/lon/alt or easting/northing/alt such as &lt;code&gt;latlon (46.75, 9.80, 2200)&lt;/code&gt; or &lt;code&gt;xy (198754, 723458, 2200)&lt;/code&gt;</help>
</parameter>
</option>
......
......@@ -351,7 +351,7 @@ their own simulation software. It showcases all panels and lists their options.
&lt;li&gt;&lt;code&gt;size=&quot;small/medium/large&quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;It will automatically scan for arithmetic expressions, environment variables, and INI keys in the shown form.&lt;/li&gt;
&lt;li&gt;Or, setting &lt;code&gt;lenient="true"&lt;/code&gt; will make it parse for arithmetic expressions without pre- and postfix&lt;/li&gt;
&lt;li&gt;&lt;code&gt;validate=&quot;your_regex&quot;&lt;/code&gt; Regular expression to check text against&lt;/li&gt;
&lt;li&gt;&lt;code&gt;validate=&quot;your_regex&quot;&lt;/code&gt; Regular expression to check text against or &lt;i&gt;"coordinates"&lt;/i&gt; to validate against a format suitable for geographic coordinates &lt;/li&gt;
&lt;li&gt;&lt;code&gt;placeholder=&quot;placeholder text&quot;&lt;/code&gt; Set a placeholder text for empty text field&lt;/li&gt;
&lt;/ul&gt;&lt;br&gt;</help>
</parameter>
......@@ -362,7 +362,7 @@ their own simulation software. It showcases all panels and lists their options.
</parameter>
<parameter key="FORMULA" label="Enter arithmetic expression:" type="text" size="large" default="${{pi+sin(10)}}"/>
<parameter key="INVALID_FORMULA" label="An invalid formula:" type="text" size="large" default="${{20+x-}}"/>
<parameter key="COORDINATES" type="text" default="latlon(46.81206, 9.84721)"/>
<parameter key="COORDINATES" type="text" default="latlon(46.81206, 9.84721)" validate="coordinates"/>
<parameter key="FREE_FORMULA" label="Formula without pre/postfix:" type="text" size="large" lenient="true" default="60*60*24"/>
<parameter key="REGEX_VALIDATION" label="Check against regular expression:" type="text" validate="^(\w+)(\d+)$" default="STATION1">
<help>validate=&quot;^(\w+)(\d+)$&quot; (word plus number)</help>
......
......@@ -118,23 +118,11 @@ void Textfield::onPropertySet()
*/
void Textfield::checkValue(const QString &text)
{
setDefaultPanelStyles(text);
static const int idx_full = 0; //regex index
if (validation_regex_.isNull()) { //check for (arithmetic) expressions
/* first, check for coordinates */
static const QString regex_coord(R"(\Alatlon\s*\(([-\d\.]+)(?:,)\s*([-\d\.]+)((?:,)\s*([-\d\.]+))?\))");
static const QRegularExpression rex_coord(regex_coord);
const QRegularExpressionMatch coord_match(rex_coord.match(text));
if (coord_match.captured(idx_full) == text && !text.isEmpty()) {
validity_button_->setText(Cst::u_globe);
validity_button_->setCursor(Qt::PointingHandCursor);
validity_button_->setToolTip(tr("Show online map"));
return;
}
bool evaluation_success;
const bool is_expression = expr::checkExpression(text, evaluation_success,
substitutions_, needs_prefix_for_evaluation_);
......@@ -143,21 +131,28 @@ void Textfield::checkValue(const QString &text)
validity_button_->setText(is_invalid? Cst::u_warning : (is_expression? Cst::u_valid : ""));
validity_button_->setCursor(is_expression? Qt::PointingHandCursor : Qt::ArrowCursor);
validity_button_->setToolTip(is_expression?
(is_invalid? tr("Entered expression has wrong format") : tr("Valid expression")) : "");
(is_invalid? tr("Wrong format for the expression") : tr("Valid expression")) : "");
validity_button_->setProperty("invalid", is_invalid? "true" : "false");
validity_button_->style()->unpolish(validity_button_);
validity_button_->style()->polish(validity_button_);
} else { //check against regex specified in XML
const QRegularExpression rex_xml(validation_regex_);
const bool isCoords = (validation_regex_.compare("coordinates", Qt::CaseInsensitive)==0);
const QString regex = isCoords? R"(\Alatlon\s*\(([-\d\.]+)(?:,)\s*([-\d\.]+)((?:,)\s*([-\d\.]+))?\))" : validation_regex_;
const QString u_valid = isCoords? Cst::u_globe : Cst::u_valid;
const QString toolTipValid = isCoords? tr("Show online map") : tr("Valid expression");
const QString toolTipInvalid = isCoords? tr("Wrong format for the provided coordinates") : tr("Wrong format for the provided value");
const QRegularExpression rex_xml(regex);
const QRegularExpressionMatch xml_match(rex_xml.match(text));
const bool is_invalid = xml_match.captured(idx_full) != text && !text.isEmpty();
setInvalidStyle(is_invalid);
validity_button_->setText(is_invalid? Cst::u_warning : (text.isEmpty()? "" : Cst::u_valid));
validity_button_->setText(is_invalid? Cst::u_warning : (text.isEmpty()? "" : u_valid));
validity_button_->setCursor(text.isEmpty()? Qt::ArrowCursor : Qt::PointingHandCursor); //mark as link
validity_button_->setToolTip(text.isEmpty()? "" :
(is_invalid? tr("Entered expression has wrong format") : tr("Valid expression")));
validity_button_->setToolTip(text.isEmpty()? "" : (is_invalid? toolTipInvalid : toolTipValid));
//set "invalid" style on navigation button also:
validity_button_->setProperty("invalid", is_invalid? "true" : "false");
validity_button_->style()->unpolish(validity_button_);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment