WSL/SLF GitLab Repository

Commit 7bdd8554 authored by Michael Reisecker's avatar Michael Reisecker
Browse files

Check for coordinates only if no custom regex is given

This way, if a "validate=..." property is set in the XML, this has
priority and the warning triangle is shown if coordinates are entered
(which do not fit the user specified regex).
parent 56a81534
......@@ -118,19 +118,38 @@ void Textfield::onPropertySet()
*/
void Textfield::checkValue(const QString &text)
{
/* 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));
static const int idx_full = 0;
setDefaultPanelStyles(text);
if (coord_match.captured(idx_full) == text && !text.isEmpty()) {
nav_button_->setText(Cst::u_globe);
nav_button_->setCursor(Qt::PointingHandCursor);
nav_button_->setToolTip(tr("Show online map"));
} else {
if (!validation_regex_.isNull()) { //check against regex specified in XML
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()) {
nav_button_->setText(Cst::u_globe);
nav_button_->setCursor(Qt::PointingHandCursor);
nav_button_->setToolTip(tr("Show online map"));
return;
}
bool evaluation_success;
const bool is_expression = expr::checkExpression(text, evaluation_success,
substitutions_, needs_prefix_for_evaluation_);
const bool is_invalid = is_expression && !evaluation_success;
setInvalidStyle(is_invalid);
nav_button_->setText(is_invalid? Cst::u_warning : (is_expression? Cst::u_valid : ""));
nav_button_->setCursor(is_expression? Qt::PointingHandCursor : Qt::ArrowCursor);
nav_button_->setToolTip(is_expression?
(is_invalid? tr("Entered expression has wrong format") : tr("Valid expression")) : "");
nav_button_->setProperty("invalid", is_invalid? "true" : "false");
nav_button_->style()->unpolish(nav_button_);
nav_button_->style()->polish(nav_button_);
} else { //check against regex specified in XML
const QRegularExpression rex_xml(validation_regex_);
const QRegularExpressionMatch xml_match(rex_xml.match(text));
const bool is_invalid = xml_match.captured(idx_full) != text && !text.isEmpty();
......@@ -143,20 +162,7 @@ void Textfield::checkValue(const QString &text)
nav_button_->setProperty("invalid", is_invalid? "true" : "false");
nav_button_->style()->unpolish(nav_button_);
nav_button_->style()->polish(nav_button_);
} else { //check for (arithmetic) expressions
bool evaluation_success;
const bool is_expression = expr::checkExpression(text, evaluation_success,
substitutions_, needs_prefix_for_evaluation_);
const bool is_invalid = is_expression && !evaluation_success;
setInvalidStyle(is_invalid);
nav_button_->setText(is_invalid? Cst::u_warning : (is_expression? Cst::u_valid : ""));
nav_button_->setCursor(is_expression? Qt::PointingHandCursor : Qt::ArrowCursor);
nav_button_->setToolTip(is_expression?
(is_invalid? tr("Entered expression has wrong format") : tr("Valid expression")) : "");
nav_button_->setProperty("invalid", is_invalid? "true" : "false");
nav_button_->style()->unpolish(nav_button_);
nav_button_->style()->polish(nav_button_);
}
}
setIniValue(text); //checks are just a hint - set anyway
}
......
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