ExpressionValidator.hpp
1 #pragma once
2 
3 #include <State/Expression.hpp>
4 
5 #include <QValidator>
6 
7 // TODO move in state plugin
8 template <typename T>
9 class ExpressionValidator final : public QValidator
10 {
11 public:
12  QValidator::State validate(QString& str, int&) const override
13  {
14  if(str.isEmpty())
15  {
16  // Remove the condition
17  m_currentExp = T{};
18  return QValidator::State::Acceptable;
19  }
20  else
21  {
22  m_currentExp = ::State::parseExpression(str);
23  return m_currentExp ? QValidator::State::Acceptable
24  : QValidator::State::Intermediate;
25  }
26  }
27 
28  std::optional<::State::Expression> get() const { return m_currentExp; }
29 
30 private:
31  mutable std::optional<::State::Expression> m_currentExp;
32 };
Definition: ExpressionValidator.hpp:10