Commit ab87248a authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Allow to change the variables instance from an analyzer

parent 367934f2
......@@ -200,6 +200,11 @@ void Analyzer::setExpression(const Expression & e)
}
}
void Analitza::Analyzer::setVariables(const QSharedPointer<Analitza::Variables>& v)
{
m_vars = v;
}
void Analyzer::importScript(QTextStream* stream)
{
ExpressionStream s(stream);
......
......@@ -74,6 +74,9 @@ class ANALITZA_EXPORT Analyzer
/** Destructor. */
~Analyzer();
/** sets the @p v Variables tuple we are going to use */
void setVariables(const QSharedPointer<Variables> &v);
/** Sets an expression to calculate. */
void setExpression(const Expression &e);
......
......@@ -46,7 +46,7 @@ QStringList ExpressionWrapper::errors() const { return m_exp.error(); }
AnalitzaWrapper::AnalitzaWrapper(QObject* parent)
: QObject(parent)
, m_wrapped(0), m_vars(nullptr), m_calc(false)
, m_wrapped(0), m_vars(new Analitza::Variables), m_calc(false)
{
initWrapped();
}
......@@ -57,18 +57,13 @@ AnalitzaWrapper::~AnalitzaWrapper()
void AnalitzaWrapper::initWrapped()
{
if(!m_wrapped) {
if(m_vars)
m_wrapped.reset(new Analitza::Analyzer(m_vars));
else {
m_wrapped.reset(new Analitza::Analyzer);
m_vars = m_wrapped->variables().data();
}
m_wrapped.reset(new Analitza::Analyzer(m_vars));
}
}
void AnalitzaWrapper::setVariables(Analitza::Variables* v)
void AnalitzaWrapper::setVariables(const QSharedPointer<Analitza::Variables> &v)
{
m_wrapped.reset(nullptr);
m_wrapped->setVariables(v);
m_vars = v;
initWrapped();
}
......
......@@ -55,7 +55,7 @@ class AnalitzaWrapper : public QObject
Q_PROPERTY(bool calculate READ isCalculate WRITE setCalculate NOTIFY isCalculateChanged)
Q_PROPERTY(bool isCorrect READ isCorrect)
Q_PROPERTY(QStringList errors READ errors)
Q_PROPERTY(Analitza::Variables* variables READ variables WRITE setVariables)
Q_PROPERTY(QSharedPointer<Analitza::Variables> variables READ variables WRITE setVariables)
public:
explicit AnalitzaWrapper(QObject* parent = 0);
~AnalitzaWrapper();
......@@ -77,8 +77,8 @@ class AnalitzaWrapper : public QObject
QStringList errors() const;
bool isCorrect() const;
Analitza::Variables* variables() const { return m_vars; }
void setVariables(Analitza::Variables* v);
QSharedPointer<Analitza::Variables> variables() const { return m_vars; }
void setVariables(const QSharedPointer<Analitza::Variables> &v);
Q_SIGNALS:
void isCalculateChanged(bool isCalculate);
......@@ -87,7 +87,7 @@ class AnalitzaWrapper : public QObject
void initWrapped();
QScopedPointer<Analitza::Analyzer> m_wrapped;
Analitza::Variables* m_vars;
QSharedPointer<Analitza::Variables> m_vars;
bool m_calc;
};
......
Markdown is supported
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