Commit 367934f2 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Pass shared pointers around rather than raw pointers

parent 7576ea7a
......@@ -132,14 +132,18 @@ QStringList printAll(const QVector<T*> & p)
const int defsize = /*500*/0;
Analyzer::Analyzer()
: m_vars(new Variables), m_runStackTop(-1), m_varsOwned(true), m_hasdeps(true)
: m_vars(new Variables), m_runStackTop(-1), m_hasdeps(true)
{
m_runStack.reserve(defsize);
registerBuiltinMethods();
}
Analyzer::Analyzer(Variables* v)
: m_vars(v), m_runStackTop(-1), m_varsOwned(false), m_hasdeps(true)
: Analyzer(QSharedPointer<Variables>(new Variables(*v)))
{}
Analyzer::Analyzer(const QSharedPointer<Variables> & v)
: m_vars(v), m_runStackTop(-1), m_hasdeps(true)
{
m_runStack.reserve(defsize);
Q_ASSERT(v);
......@@ -147,17 +151,14 @@ Analyzer::Analyzer(Variables* v)
}
Analyzer::Analyzer(const Analyzer& a)
: m_exp(a.m_exp), m_err(a.m_err), m_runStackTop(-1), m_varsOwned(true), m_hasdeps(a.m_hasdeps)
: m_exp(a.m_exp), m_vars(new Variables(*a.m_vars)), m_err(a.m_err), m_runStackTop(-1), m_hasdeps(a.m_hasdeps)
{
m_vars = new Variables(*a.m_vars);
m_runStack.reserve(defsize);
registerBuiltinMethods();
}
Analyzer::~Analyzer()
{
if(m_varsOwned)
delete m_vars;
}
void Analyzer::registerBuiltinMethods()
......@@ -186,7 +187,7 @@ void Analyzer::setExpression(const Expression & e)
if(!e.tree()) {
m_err << QCoreApplication::tr("Cannot calculate an empty expression");
} else if(m_exp.isCorrect()) {
ExpressionTypeChecker check(m_vars);
ExpressionTypeChecker check(m_vars.data());
check.initializeVars(m_builtin.varTypes());
m_currentType=check.check(m_exp);
......
......@@ -21,12 +21,13 @@
#define ANALYZER_H
#include <QStringList>
#include <QSharedPointer>
#include <QStack>
#include "expression.h"
#include "analitzaexport.h"
#include "expressiontype.h"
#include "builtinmethods.h"
#include <QStack>
#include <analitza/analitzautils.h>
namespace Analitza
......@@ -65,7 +66,8 @@ class ANALITZA_EXPORT Analyzer
/** Constructor. Creates an empty Analyzer module.
@param v: Sets a custom variables module. This module will _not_ be deleted along with Analyzer
*/
Analyzer(Variables* v);
explicit Analyzer(Variables* v);
explicit Analyzer(const QSharedPointer<Variables> &v);
/** Copy constructor. Creates a copy of the @p a Analyzer instance. Inherits its Variable structure. */
Analyzer(const Analyzer& a);
......@@ -110,7 +112,7 @@ class ANALITZA_EXPORT Analyzer
QStringList errors() const { return m_exp.error() + m_err; }
/** @returns Returns a way to query variables. */
Variables *variables() const { return m_vars; }
QSharedPointer<Variables> variables() const { return m_vars; }
/**
Adds a variable entry. It is the proper way to do it because tracks some possible errors.
......@@ -163,13 +165,12 @@ class ANALITZA_EXPORT Analyzer
static funcContainer operateContainer[];
Expression m_exp;
Variables *m_vars;
QSharedPointer<Variables> m_vars;
QStringList m_err;
QVector<Object*> m_runStack;
int m_runStackTop;
BuiltinMethods m_builtin;
const bool m_varsOwned;
bool m_hasdeps;
ExpressionType m_currentType;
QMap<QString, ExpressionType> m_variablesTypes;
......
......@@ -44,6 +44,7 @@ class Cn;
class ANALITZA_EXPORT Expression
{
Q_GADGET
public:
typedef void (*CustomObjectDestructor)(const QVariant&);
/**
......
......@@ -20,6 +20,7 @@
#define OPERATORSMODEL_H
#include <QAbstractTableModel>
#include <QSharedPointer>
#include "analitzaguiexport.h"
namespace Analitza
......@@ -56,14 +57,14 @@ class ANALITZAGUI_EXPORT OperatorsModel : public QAbstractTableModel
int rowCount(const QModelIndex &parent=QModelIndex()) const override;
int columnCount(const QModelIndex &parent=QModelIndex()) const override;
void setVariables(const Analitza::Variables* v) { m_vars=v; }
void setVariables(const QSharedPointer<Analitza::Variables> &v) { m_vars=v; }
QModelIndex indexForOperatorName(const QString& id) const;
QString parameterHelp(const QModelIndex& idx, int param, bool inbounds) const;
static QString standardFunctionCallHelp(const QString& funcname, int param, int paramcount, bool inbounds, bool isbounded);
private:
const Analitza::Variables *m_vars;
QSharedPointer<Analitza::Variables> m_vars;
};
......
......@@ -26,7 +26,7 @@
using namespace Analitza;
VariablesModel::VariablesModel(Variables* v, QObject *parent)
VariablesModel::VariablesModel(const QSharedPointer<Variables>& v, QObject *parent)
: QAbstractTableModel(parent), m_vars(v), m_editable(true)
{}
......@@ -34,9 +34,9 @@ VariablesModel::VariablesModel(QObject* parent)
: QAbstractTableModel(parent), m_vars(0), m_editable(true)
{}
void VariablesModel::setVariables(Variables* v)
void VariablesModel::setVariables(const QSharedPointer<Variables> &v)
{
m_vars=v;
m_vars = v;
}
QVariant VariablesModel::data(const QModelIndex & index, int role) const
......
......@@ -20,6 +20,7 @@
#define VARIABLESMODEL_H
#include <QAbstractTableModel>
#include <QSharedPointer>
#include "analitzaguiexport.h"
namespace Analitza
......@@ -38,12 +39,12 @@ class Expression;
class ANALITZAGUI_EXPORT VariablesModel : public QAbstractTableModel
{
Q_OBJECT
Q_PROPERTY(Analitza::Variables* variables READ variables WRITE setVariables)
Q_PROPERTY(QSharedPointer<Analitza::Variables> variables READ variables WRITE setVariables)
public:
/** Constructor. Creates a new Variable Model. */
explicit VariablesModel(QObject *parent=0);
VariablesModel(Analitza::Variables* v, QObject *parent=0);
void setVariables(Analitza::Variables* v);
VariablesModel(const QSharedPointer<Analitza::Variables> &v, QObject *parent = nullptr);
void setVariables(const QSharedPointer<Analitza::Variables> &v);
virtual QFlags< Qt::ItemFlag > flags(const QModelIndex& index) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role=Qt::EditRole) override;
......@@ -55,13 +56,13 @@ class ANALITZAGUI_EXPORT VariablesModel : public QAbstractTableModel
void insertVariable(const QString& name, const Analitza::Expression& value);
void setEditable(bool ed) { m_editable=ed; }
Analitza::Variables* variables() const { return m_vars; }
QSharedPointer<Analitza::Variables> variables() const { return m_vars; }
public Q_SLOTS:
/** Updates the variables information */
void updateInformation();
private:
Analitza::Variables *m_vars;
QSharedPointer<Analitza::Variables> m_vars;
bool m_editable;
};
......
......@@ -34,7 +34,6 @@ PlotsFactory::PlotsFactory()
PlotsFactory::~PlotsFactory()
{
delete m_vars;
}
PlotsFactory* PlotsFactory::self()
......@@ -42,7 +41,7 @@ PlotsFactory* PlotsFactory::self()
return factoryInstance;
}
PlotBuilder PlotsFactory::requestPlot(const Analitza::Expression& testexp, Dimension dim, Variables* vars) const
PlotBuilder PlotsFactory::requestPlot(const Analitza::Expression& testexp, Dimension dim, const QSharedPointer<Variables> &vars) const
{
QStringList errs;
......
......@@ -40,7 +40,7 @@ class ANALITZAPLOT_EXPORT PlotBuilder
FunctionGraph* create(const QColor& color, const QString& name) const;
Analitza::Expression expression() const;
QString display() const;
Variables* m_vars;
QSharedPointer<Variables> m_vars;
protected:
PlotBuilder();
......@@ -58,11 +58,11 @@ class ANALITZAPLOT_EXPORT PlotsFactory
virtual ~PlotsFactory();
static PlotsFactory* self();
PlotBuilder requestPlot(const Analitza::Expression& expresssion, Dimension dim, Variables* vars = 0) const;
PlotBuilder requestPlot(const Analitza::Expression& expresssion, Dimension dim, const QSharedPointer<Variables> &vars = {}) const;
QStringList examples(Dimensions s) const;
private:
Variables* m_vars;
QSharedPointer<Variables> m_vars;
};
}
......
......@@ -267,7 +267,7 @@ void PlotsModel::setResolution(int res)
static QColor randomFunctionColor() { return QColor::fromHsv(qrand()%255, 255, 225); }
QStringList PlotsModel::addFunction(const QString& expression, Dimension dim, Analitza::Variables* vars)
QStringList PlotsModel::addFunction(const QString& expression, Dimension dim, const QSharedPointer<Analitza::Variables>& vars)
{
Analitza::Expression e(expression, Analitza::Expression::isMathML(expression));
......
......@@ -78,7 +78,7 @@ public:
/**
* Helper method to help easily add elements to the model
*/
Q_SCRIPTABLE QStringList addFunction(const QString& expression, Analitza::Dimension dim, Analitza::Variables* vars);
Q_SCRIPTABLE QStringList addFunction(const QString& expression, Analitza::Dimension dim, const QSharedPointer<Analitza::Variables>& vars);
protected:
void emitChanged(PlotItem* it);
......
......@@ -33,7 +33,7 @@ using namespace Analitza;
// Make the list control large enough that it can show at least four items at a time without scrolling.
// For lists of ten or more items, increase this minimum size as appropriate.
AbstractFunctionGraph::AbstractFunctionGraph(const Analitza::Expression& e, Analitza::Variables* v)
AbstractFunctionGraph::AbstractFunctionGraph(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v)
: AbstractMappingGraph()
, m_resolution(200)
, m_e(e)
......
......@@ -60,8 +60,8 @@ class AbstractFunctionGraph : public AbstractMappingGraph
{
friend class FunctionGraphFactory;
public:
AbstractFunctionGraph(const Analitza::Expression& e, Analitza::Variables* v = 0);
virtual ~AbstractFunctionGraph();
explicit AbstractFunctionGraph(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v = {});
~AbstractFunctionGraph() override;
Dimension spaceDimension() const override;
......
......@@ -29,7 +29,7 @@
using namespace Analitza;
AbstractPlaneCurve::AbstractPlaneCurve(const Analitza::Expression& e, Analitza::Variables* v)
AbstractPlaneCurve::AbstractPlaneCurve(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v)
: AbstractFunctionGraph(e, v)
{}
......
......@@ -24,7 +24,7 @@
#include <QLineF>
#define CONSTRUCTORS(name) \
name (const Analitza::Expression &functionExpression, Analitza::Variables *variables) :AbstractPlaneCurve(functionExpression, variables) { }
name (const Analitza::Expression &functionExpression, const QSharedPointer<Analitza::Variables>& variables) :AbstractPlaneCurve(functionExpression, variables) { }
namespace Analitza {
class Variables;
......@@ -32,8 +32,8 @@ class Variables;
class AbstractPlaneCurve : public AbstractFunctionGraph
{
public:
AbstractPlaneCurve(const Analitza::Expression& e, Analitza::Variables* v = 0);
virtual ~AbstractPlaneCurve();
explicit AbstractPlaneCurve(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v = {});
~AbstractPlaneCurve() override;
QVector<QPointF> points;
QVector<int> jumps;
......
......@@ -33,7 +33,7 @@ using namespace Analitza;
using std::atan2;
AbstractSpaceCurve::AbstractSpaceCurve(const Analitza::Expression& e, Analitza::Variables* v)
AbstractSpaceCurve::AbstractSpaceCurve(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v)
: AbstractFunctionGraph(e, v)
{}
......
......@@ -22,7 +22,7 @@
#include "abstractfunctiongraph.h"
#define CONSTRUCTORS(name) \
name (const Analitza::Expression &functionExpression, Analitza::Variables *variables) :AbstractSpaceCurve(functionExpression, variables) { }
name (const Analitza::Expression &functionExpression, const QSharedPointer<Analitza::Variables>& variables) :AbstractSpaceCurve(functionExpression, variables) { }
namespace Analitza {
class Variables;
......@@ -30,7 +30,7 @@ class Variables;
class AbstractSpaceCurve : public AbstractFunctionGraph
{
public:
AbstractSpaceCurve(const Analitza::Expression& e, Analitza::Variables* v = 0);
AbstractSpaceCurve(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v = {});
virtual ~AbstractSpaceCurve();
//Curve ... los expongo como publicos tanto para planecurve como para los backend (
......
......@@ -27,7 +27,7 @@ static const int MAXALONG = 32;
using namespace Analitza;
AbstractSurface::AbstractSurface(const Analitza::Expression& e, Analitza::Variables* v)
AbstractSurface::AbstractSurface(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v)
: AbstractFunctionGraph(e, v)
{}
......
......@@ -23,14 +23,14 @@
#include "abstractfunctiongraph.h"
#define CONSTRUCTORS(name) \
name (const Analitza::Expression &functionExpression, Analitza::Variables *variables) : AbstractSurface(functionExpression, variables) { }
name (const Analitza::Expression &functionExpression, const QSharedPointer<Analitza::Variables>& variables) : AbstractSurface(functionExpression, variables) { }
namespace Analitza {
class AbstractSurface : public AbstractFunctionGraph //strategy pattern for curves
{
public:
explicit AbstractSurface(const Analitza::Expression& e, Analitza::Variables* v = 0);
explicit AbstractSurface(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v = {});
virtual ~AbstractSurface();
//Own
......
......@@ -31,7 +31,7 @@ using namespace Analitza;
class FunctionCartesian : public AbstractPlaneCurve
{
public:
FunctionCartesian(const Analitza::Expression &functionExpression, Analitza::Variables *variables)
FunctionCartesian(const Analitza::Expression &functionExpression, const QSharedPointer<Analitza::Variables>& variables)
: AbstractPlaneCurve(functionExpression, variables) { }
void update(const QRectF& viewport) override;
......@@ -59,7 +59,7 @@ class FunctionCartesian : public AbstractPlaneCurve
class FunctionY : public FunctionCartesian
{
public:
FunctionY(const Analitza::Expression &functionExpression, Analitza::Variables *variables)
FunctionY(const Analitza::Expression &functionExpression, const QSharedPointer<Analitza::Variables>& variables)
: FunctionCartesian(functionExpression, variables) { initDerivative(); }
TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Plane Curve F(y)"))
EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter(
......@@ -75,7 +75,7 @@ public:
class FunctionX : public FunctionCartesian
{
public:
FunctionX(const Analitza::Expression &functionExpression, Analitza::Variables *variables)
FunctionX(const Analitza::Expression &functionExpression, const QSharedPointer<Analitza::Variables>& variables)
: FunctionCartesian(functionExpression, variables) { initDerivative(); }
TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Plane Curve F(x)"))
EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter(
......
......@@ -32,7 +32,7 @@ class Frp : public AbstractSurface/*, static class? better macros FooClass*/
{
public:
explicit Frp(const Analitza::Expression& e);
Frp(const Analitza::Expression& e, Analitza::Variables* v);
Frp(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v);
TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Cylindrical Surface z=F(r: Radial, p: Polar)"))
EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter(
......@@ -93,7 +93,7 @@ Frp::Frp(const Analitza::Expression& e): AbstractSurface(e)
setInterval(QStringLiteral("p"), 0, M_PI);
}
Frp::Frp(const Analitza::Expression& e, Analitza::Variables*): AbstractSurface(e)
Frp::Frp(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& /*v*/): AbstractSurface(e)
{}
QVector3D Frp::fromParametricArgs(double r, double p)
......
......@@ -33,7 +33,7 @@ using namespace Analitza;
class ImplicitPolar : public AbstractPlaneCurve, MarchingSquares
{
public:
ImplicitPolar(const Analitza::Expression& e, Analitza::Variables* v = 0);
ImplicitPolar(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v = {});
TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Polar implicit Curve 0=F(r: Radial, p: Polar)"))
EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda)
.addParameter(Analitza::ExpressionType(Analitza::ExpressionType::Value))
......@@ -55,7 +55,7 @@ public:
Analitza::Cn *p;
};
ImplicitPolar::ImplicitPolar(const Analitza::Expression& e, Analitza::Variables* v)
ImplicitPolar::ImplicitPolar(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v)
: AbstractPlaneCurve(e, v)
{
r = arg(QStringLiteral("r"));
......
......@@ -30,7 +30,7 @@ using namespace Analitza;
class ImplicitSurf : public AbstractSurface , public MarchingCubes/*, static class? better macros FooClass*/
{
public:
ImplicitSurf(const Analitza::Expression& e, Analitza::Variables* v);
ImplicitSurf(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v);
TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Implicit Surface"))
EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda)
......@@ -60,7 +60,7 @@ double ImplicitSurf::evalScalarField(double x, double y, double z)
}
ImplicitSurf::ImplicitSurf(const Analitza::Expression& e, Analitza::Variables* v): AbstractSurface(e, v)
ImplicitSurf::ImplicitSurf(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v): AbstractSurface(e, v)
{
}
......
......@@ -33,7 +33,7 @@ using namespace Analitza;
class FunctionParametric : public AbstractPlaneCurve
{
public:
FunctionParametric(const Expression& e, Variables* v = 0);
FunctionParametric(const Expression& e, const QSharedPointer<Analitza::Variables>& v);
TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Parametric Curve 2D"))
EXPRESSION_TYPE(
Analitza::ExpressionType(Analitza::ExpressionType::Lambda)
......@@ -56,7 +56,7 @@ private:
int resolution() { return 5000; }
};
FunctionParametric::FunctionParametric(const Expression& e, Variables* v): AbstractPlaneCurve(e, v)
FunctionParametric::FunctionParametric(const Expression& e, const QSharedPointer<Analitza::Variables>& v): AbstractPlaneCurve(e, v)
{
t = arg(QStringLiteral("t"));
}
......
......@@ -33,7 +33,7 @@ using namespace Analitza;
class FunctionPolar : public AbstractPlaneCurve
{
public:
FunctionPolar(const Analitza::Expression& e, Analitza::Variables* v = 0);
FunctionPolar(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v = 0);
TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Polar Curve r=F(p: Polar)"))
EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter(
Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter(
......@@ -51,7 +51,7 @@ public:
Analitza::Cn *p;
};
FunctionPolar::FunctionPolar(const Analitza::Expression& e, Analitza::Variables* v): AbstractPlaneCurve(e, v)
FunctionPolar::FunctionPolar(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v): AbstractPlaneCurve(e, v)
{
p = arg(QStringLiteral("q"));
}
......
......@@ -30,7 +30,7 @@ class SphericalSurface : public AbstractSurface/*, static class? better macros F
{
public:
explicit SphericalSurface(const Analitza::Expression& e);
SphericalSurface(const Analitza::Expression& e, Analitza::Variables* v);
SphericalSurface(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v);
TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Spherical Surface Radial=F(t:Azimuth, p: Polar)"))
EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter(
......@@ -97,7 +97,7 @@ SphericalSurface::SphericalSurface(const Analitza::Expression& e): AbstractSurfa
setInterval(QStringLiteral("p"), 0, M_PI);
}
SphericalSurface::SphericalSurface(const Analitza::Expression& e, Analitza::Variables* v)
SphericalSurface::SphericalSurface(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v)
: AbstractSurface(e, v)
{}
......
......@@ -129,7 +129,7 @@ bool FunctionGraphFactory::contains(const QString& id) const
return builderFunctionsWithVars.contains(id);
}
AbstractFunctionGraph* FunctionGraphFactory::build(const QString& id, const Analitza::Expression& exp, Analitza::Variables* v) const
AbstractFunctionGraph* FunctionGraphFactory::build(const QString& id, const Analitza::Expression& exp, const QSharedPointer<Analitza::Variables>& v) const
{
Q_ASSERT(builderFunctionsWithVars.contains(id));
AbstractFunctionGraph* ret = builderFunctionsWithVars.value(id)(exp, v);
......@@ -138,7 +138,7 @@ AbstractFunctionGraph* FunctionGraphFactory::build(const QString& id, const Anal
return ret;
}
FunctionGraph* FunctionGraphFactory::buildItem(const QString& id, const Analitza::Expression& exp, Analitza::Variables* v) const
FunctionGraph* FunctionGraphFactory::buildItem(const QString& id, const Analitza::Expression& exp, const QSharedPointer<Analitza::Variables>& v) const
{
return plotConstructor[id](build(id, exp, v));
}
......
......@@ -27,13 +27,14 @@
#include <QPair>
#include <QMap>
#include <QSharedPointer>
#include "planecurve.h"
#include "spacecurve.h"
#include "surface.h"
#define REGISTER_FUNCTIONGRAPH_DIM(dim, constructor, name) \
static AbstractFunctionGraph * vcreate##name(const Analitza::Expression &exp, Analitza::Variables* v) { return new name (exp, v); } \
static AbstractFunctionGraph * vcreate##name(const Analitza::Expression &exp, const QSharedPointer<Analitza::Variables>& v) { return new name (exp, v); } \
namespace { bool _##name=FunctionGraphFactory::self()->registerFunctionGraph(dim, constructor, vcreate##name, \
name ::TypeName(), name ::ExpressionType, name ::CoordSystem(), name ::Parameters(), \
name ::IconName(), name ::Examples); }
......@@ -52,7 +53,7 @@ class PlotItem;
class FunctionGraphFactory
{
public:
typedef AbstractFunctionGraph* (*BuilderFunctionWithVars)(const Analitza::Expression&, Analitza::Variables* );
typedef AbstractFunctionGraph* (*BuilderFunctionWithVars)(const Analitza::Expression&, const QSharedPointer<Analitza::Variables>& );
typedef FunctionGraph* (*PlotItemConstuctor)(AbstractFunctionGraph*);
typedef Analitza::ExpressionType (*ExpressionTypeFunction)();
typedef QStringList (*ExamplesFunction)();
......@@ -81,8 +82,8 @@ public:
QString trait(const Analitza::Expression& expr, const Analitza::ExpressionType& t, Dimension dim) const;
bool contains(const QString &id) const;
AbstractFunctionGraph * build(const QString& id, const Analitza::Expression& exp, Analitza::Variables* v) const;
FunctionGraph* buildItem(const QString& id, const Analitza::Expression& exp, Analitza::Variables* v) const;
AbstractFunctionGraph * build(const QString& id, const Analitza::Expression& exp, const QSharedPointer<Analitza::Variables>& v) const;
FunctionGraph* buildItem(const QString& id, const Analitza::Expression& exp, const QSharedPointer<Analitza::Variables>& v) const;
QMap< QString, QPair< QStringList, Analitza::ExpressionType > > registeredFunctionGraphs() const;
......
......@@ -32,13 +32,12 @@ QTEST_MAIN( PlaneCurveTest )
PlaneCurveTest::PlaneCurveTest(QObject *parent)
: QObject(parent)
, m_vars(new Analitza::Variables)
{
m_vars=new Analitza::Variables;
}
PlaneCurveTest::~PlaneCurveTest()
{
delete m_vars;
}
void PlaneCurveTest::initTestCase()
......
......@@ -21,6 +21,7 @@
#define ANALITZATEST_H
#include <QObject>
#include <QSharedPointer>
/**
@author Aleix Pol
......@@ -51,7 +52,7 @@ Q_OBJECT
void cleanupTestCase();
private:
Analitza::Variables* m_vars;
QSharedPointer<Analitza::Variables> m_vars;
};
#endif
......@@ -288,7 +288,7 @@ void ExpressionEdit::cursorMov()
QString help = helpShow(m_highlight->editingName(),
m_highlight->editingParameter(),
m_highlight->editingBounds(),
a ? a->variables() : 0);
a ? a->variables().data() : nullptr);
if(help.isEmpty()) {
if(isCorrect()) {
......
......@@ -61,7 +61,7 @@ void AnalitzaWrapper::initWrapped()
m_wrapped.reset(new Analitza::Analyzer(m_vars));
else {
m_wrapped.reset(new Analitza::Analyzer);
m_vars = m_wrapped->variables();
m_vars = m_wrapped->variables().data();
}
}
}
......@@ -167,3 +167,11 @@ void AnalitzaWrapper::removeVariable(const QString& name)
bool AnalitzaWrapper::isCorrect() const { return m_wrapped->isCorrect(); }
QStringList AnalitzaWrapper::errors() const { return m_wrapped->errors(); }
void AnalitzaWrapper::setCalculate(bool calc)
{
if (m_calc != calc) {
m_calc = calc;