summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2017-06-14 15:46:14 +0200
committerAleix Pol <[email protected]>2017-06-14 15:46:14 +0200
commit367934f253de23c7186907750becaeaa101ad097 (patch)
tree15b48ac2542879e3e2c1bf235e31b5067090a389
parent7576ea7a76c9201fd9a6950cccf586c44f086611 (diff)
Pass shared pointers around rather than raw pointers
-rw-r--r--analitza/analyzer.cpp15
-rw-r--r--analitza/analyzer.h11
-rw-r--r--analitza/expression.h1
-rw-r--r--analitzagui/operatorsmodel.h5
-rw-r--r--analitzagui/variablesmodel.cpp6
-rw-r--r--analitzagui/variablesmodel.h11
-rw-r--r--analitzaplot/plotsfactory.cpp3
-rw-r--r--analitzaplot/plotsfactory.h6
-rw-r--r--analitzaplot/plotsmodel.cpp2
-rw-r--r--analitzaplot/plotsmodel.h2
-rw-r--r--analitzaplot/private/abstractfunctiongraph.cpp2
-rw-r--r--analitzaplot/private/abstractfunctiongraph.h4
-rw-r--r--analitzaplot/private/abstractplanecurve.cpp2
-rw-r--r--analitzaplot/private/abstractplanecurve.h6
-rw-r--r--analitzaplot/private/abstractspacecurve.cpp2
-rw-r--r--analitzaplot/private/abstractspacecurve.h4
-rw-r--r--analitzaplot/private/abstractsurface.cpp2
-rw-r--r--analitzaplot/private/abstractsurface.h4
-rw-r--r--analitzaplot/private/backends/cartesiancurve.cpp6
-rw-r--r--analitzaplot/private/backends/cylindricalsurface.cpp4
-rw-r--r--analitzaplot/private/backends/implicitpolarcurve.cpp4
-rw-r--r--analitzaplot/private/backends/implicitsurface.cpp4
-rw-r--r--analitzaplot/private/backends/parametriccurve2d.cpp4
-rw-r--r--analitzaplot/private/backends/polarcurve.cpp4
-rw-r--r--analitzaplot/private/backends/sphericalsurface.cpp4
-rw-r--r--analitzaplot/private/functiongraphfactory.cpp4
-rw-r--r--analitzaplot/private/functiongraphfactory.h9
-rw-r--r--analitzaplot/tests/planecurvetest.cpp3
-rw-r--r--analitzaplot/tests/planecurvetest.h3
-rw-r--r--analitzawidgets/expressionedit.cpp2
-rw-r--r--declarative/analitzawrapper.cpp10
-rw-r--r--declarative/analitzawrapper.h7
-rw-r--r--declarative/graph2dmobile.cpp2
-rw-r--r--declarative/graph2dmobile.h2
-rw-r--r--declarative/graph3ditem.cpp2
-rw-r--r--declarative/graph3ditem.h2
36 files changed, 90 insertions, 74 deletions
diff --git a/analitza/analyzer.cpp b/analitza/analyzer.cpp
index 9d1b58b..0161860 100644
--- a/analitza/analyzer.cpp
+++ b/analitza/analyzer.cpp
@@ -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);
diff --git a/analitza/analyzer.h b/analitza/analyzer.h
index 31e8228..0372611 100644
--- a/analitza/analyzer.h
+++ b/analitza/analyzer.h
@@ -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;
diff --git a/analitza/expression.h b/analitza/expression.h
index cd5b2c5..fe3403b 100644
--- a/analitza/expression.h
+++ b/analitza/expression.h
@@ -44,6 +44,7 @@ class Cn;
class ANALITZA_EXPORT Expression
{
+ Q_GADGET
public:
typedef void (*CustomObjectDestructor)(const QVariant&);
/**
diff --git a/analitzagui/operatorsmodel.h b/analitzagui/operatorsmodel.h
index 942a035..5ac0a19 100644
--- a/analitzagui/operatorsmodel.h
+++ b/analitzagui/operatorsmodel.h
@@ -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;
};
diff --git a/analitzagui/variablesmodel.cpp b/analitzagui/variablesmodel.cpp
index 927a47d..ebbbd7c 100644
--- a/analitzagui/variablesmodel.cpp
+++ b/analitzagui/variablesmodel.cpp
@@ -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
diff --git a/analitzagui/variablesmodel.h b/analitzagui/variablesmodel.h
index 65c4496..1130682 100644
--- a/analitzagui/variablesmodel.h
+++ b/analitzagui/variablesmodel.h
@@ -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;
};
diff --git a/analitzaplot/plotsfactory.cpp b/analitzaplot/plotsfactory.cpp
index 2346b43..b62fd24 100644
--- a/analitzaplot/plotsfactory.cpp
+++ b/analitzaplot/plotsfactory.cpp
@@ -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;
diff --git a/analitzaplot/plotsfactory.h b/analitzaplot/plotsfactory.h
index fc6ecbd..1244eae 100644
--- a/analitzaplot/plotsfactory.h
+++ b/analitzaplot/plotsfactory.h
@@ -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;
};
}
diff --git a/analitzaplot/plotsmodel.cpp b/analitzaplot/plotsmodel.cpp
index ecb9896..2cf7604 100644
--- a/analitzaplot/plotsmodel.cpp
+++ b/analitzaplot/plotsmodel.cpp
@@ -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));
diff --git a/analitzaplot/plotsmodel.h b/analitzaplot/plotsmodel.h
index d19e360..9a3a763 100644
--- a/analitzaplot/plotsmodel.h
+++ b/analitzaplot/plotsmodel.h
@@ -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);
diff --git a/analitzaplot/private/abstractfunctiongraph.cpp b/analitzaplot/private/abstractfunctiongraph.cpp
index 89e9ccc..39f43b9 100644
--- a/analitzaplot/private/abstractfunctiongraph.cpp
+++ b/analitzaplot/private/abstractfunctiongraph.cpp
@@ -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)
diff --git a/analitzaplot/private/abstractfunctiongraph.h b/analitzaplot/private/abstractfunctiongraph.h
index d3fafe6..7789eb6 100644
--- a/analitzaplot/private/abstractfunctiongraph.h
+++ b/analitzaplot/private/abstractfunctiongraph.h
@@ -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;
diff --git a/analitzaplot/private/abstractplanecurve.cpp b/analitzaplot/private/abstractplanecurve.cpp
index 10190bc..4573db6 100644
--- a/analitzaplot/private/abstractplanecurve.cpp
+++ b/analitzaplot/private/abstractplanecurve.cpp
@@ -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)
{}
diff --git a/analitzaplot/private/abstractplanecurve.h b/analitzaplot/private/abstractplanecurve.h
index 59aa10d..65278f2 100644
--- a/analitzaplot/private/abstractplanecurve.h
+++ b/analitzaplot/private/abstractplanecurve.h
@@ -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;
diff --git a/analitzaplot/private/abstractspacecurve.cpp b/analitzaplot/private/abstractspacecurve.cpp
index 671939d..bf06204 100644
--- a/analitzaplot/private/abstractspacecurve.cpp
+++ b/analitzaplot/private/abstractspacecurve.cpp
@@ -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)
{}
diff --git a/analitzaplot/private/abstractspacecurve.h b/analitzaplot/private/abstractspacecurve.h
index 9a4d0dc..b778c31 100644
--- a/analitzaplot/private/abstractspacecurve.h
+++ b/analitzaplot/private/abstractspacecurve.h
@@ -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 (
diff --git a/analitzaplot/private/abstractsurface.cpp b/analitzaplot/private/abstractsurface.cpp
index a429213..376bb03 100644
--- a/analitzaplot/private/abstractsurface.cpp
+++ b/analitzaplot/private/abstractsurface.cpp
@@ -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)
{}
diff --git a/analitzaplot/private/abstractsurface.h b/analitzaplot/private/abstractsurface.h
index ce84fe5..1b69ecb 100644
--- a/analitzaplot/private/abstractsurface.h
+++ b/analitzaplot/private/abstractsurface.h
@@ -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
diff --git a/analitzaplot/private/backends/cartesiancurve.cpp b/analitzaplot/private/backends/cartesiancurve.cpp
index 442fb6e..4b5cd1b 100644
--- a/analitzaplot/private/backends/cartesiancurve.cpp
+++ b/analitzaplot/private/backends/cartesiancurve.cpp
@@ -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(
diff --git a/analitzaplot/private/backends/cylindricalsurface.cpp b/analitzaplot/private/backends/cylindricalsurface.cpp
index 863e63e..ba54c91 100644
--- a/analitzaplot/private/backends/cylindricalsurface.cpp
+++ b/analitzaplot/private/backends/cylindricalsurface.cpp
@@ -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)
diff --git a/analitzaplot/private/backends/implicitpolarcurve.cpp b/analitzaplot/private/backends/implicitpolarcurve.cpp
index 0107e8c..4c4cf45 100644
--- a/analitzaplot/private/backends/implicitpolarcurve.cpp
+++ b/analitzaplot/private/backends/implicitpolarcurve.cpp
@@ -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"));
diff --git a/analitzaplot/private/backends/implicitsurface.cpp b/analitzaplot/private/backends/implicitsurface.cpp
index b4fbe6a..30b8f49 100644
--- a/analitzaplot/private/backends/implicitsurface.cpp
+++ b/analitzaplot/private/backends/implicitsurface.cpp
@@ -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)
{
}
diff --git a/analitzaplot/private/backends/parametriccurve2d.cpp b/analitzaplot/private/backends/parametriccurve2d.cpp
index f7412de..509305a 100644
--- a/analitzaplot/private/backends/parametriccurve2d.cpp
+++ b/analitzaplot/private/backends/parametriccurve2d.cpp
@@ -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"));
}
diff --git a/analitzaplot/private/backends/polarcurve.cpp b/analitzaplot/private/backends/polarcurve.cpp
index 1ba8f3b..ad97477 100644
--- a/analitzaplot/private/backends/polarcurve.cpp
+++ b/analitzaplot/private/backends/polarcurve.cpp
@@ -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"));
}
diff --git a/analitzaplot/private/backends/sphericalsurface.cpp b/analitzaplot/private/backends/sphericalsurface.cpp
index d4867c3..a017cb2 100644
--- a/analitzaplot/private/backends/sphericalsurface.cpp
+++ b/analitzaplot/private/backends/sphericalsurface.cpp
@@ -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)
{}
diff --git a/analitzaplot/private/functiongraphfactory.cpp b/analitzaplot/private/functiongraphfactory.cpp
index 7d2fadb..0d01914 100644
--- a/analitzaplot/private/functiongraphfactory.cpp
+++ b/analitzaplot/private/functiongraphfactory.cpp
@@ -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));
}
diff --git a/analitzaplot/private/functiongraphfactory.h b/analitzaplot/private/functiongraphfactory.h
index 39e6208..1020510 100644
--- a/analitzaplot/private/functiongraphfactory.h
+++ b/analitzaplot/private/functiongraphfactory.h
@@ -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;
diff --git a/analitzaplot/tests/planecurvetest.cpp b/analitzaplot/tests/planecurvetest.cpp
index cace796..0f3b5ac 100644
--- a/analitzaplot/tests/planecurvetest.cpp
+++ b/analitzaplot/tests/planecurvetest.cpp
@@ -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()
diff --git a/analitzaplot/tests/planecurvetest.h b/analitzaplot/tests/planecurvetest.h
index 777fc2d..48cf6a7 100644
--- a/analitzaplot/tests/planecurvetest.h
+++ b/analitzaplot/tests/planecurvetest.h
@@ -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
diff --git a/analitzawidgets/expressionedit.cpp b/analitzawidgets/expressionedit.cpp
index a3b5c35..1366975 100644
--- a/analitzawidgets/expressionedit.cpp
+++ b/analitzawidgets/expressionedit.cpp
@@ -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()) {
diff --git a/declarative/analitzawrapper.cpp b/declarative/analitzawrapper.cpp
index 4233007..5b28be5 100644
--- a/declarative/analitzawrapper.cpp
+++ b/declarative/analitzawrapper.cpp
@@ -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;
+ Q_EMIT isCalculateChanged(calc);
+ }
+}
diff --git a/declarative/analitzawrapper.h b/declarative/analitzawrapper.h
index 1380bb0..50d115e 100644
--- a/declarative/analitzawrapper.h
+++ b/declarative/analitzawrapper.h
@@ -52,7 +52,7 @@ class ExpressionWrapper : public QObject
class AnalitzaWrapper : public QObject
{
Q_OBJECT
- Q_PROPERTY(bool calculate READ isCalculate WRITE setCalculate)
+ 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)
@@ -60,7 +60,7 @@ class AnalitzaWrapper : public QObject
explicit AnalitzaWrapper(QObject* parent = 0);
~AnalitzaWrapper();
- void setCalculate(bool calc) { m_calc = calc; }
+ void setCalculate(bool calc);
bool isCalculate() const { return m_calc; }
Analitza::Analyzer* wrapped() const { return m_wrapped.data(); }
@@ -79,6 +79,9 @@ class AnalitzaWrapper : public QObject
Analitza::Variables* variables() const { return m_vars; }
void setVariables(Analitza::Variables* v);
+
+ Q_SIGNALS:
+ void isCalculateChanged(bool isCalculate);
private:
void initWrapped();
diff --git a/declarative/graph2dmobile.cpp b/declarative/graph2dmobile.cpp
index 0534970..81c4bc3 100644
--- a/declarative/graph2dmobile.cpp
+++ b/declarative/graph2dmobile.cpp
@@ -102,7 +102,7 @@ void Graph2DMobile::translate(qreal x, qreal y)
moveViewport(QPoint(x,y));
}
-QStringList Graph2DMobile::addFunction(const QString& expression, Analitza::Variables* vars)
+QStringList Graph2DMobile::addFunction(const QString& expression, const QSharedPointer<Analitza::Variables>& vars)
{
PlotsModel* plotsmodel = qobject_cast<PlotsModel*>(model());
if(!plotsmodel)
diff --git a/declarative/graph2dmobile.h b/declarative/graph2dmobile.h
index 37d8fed..bc11b0b 100644
--- a/declarative/graph2dmobile.h
+++ b/declarative/graph2dmobile.h
@@ -58,7 +58,7 @@ class Graph2DMobile : public QQuickItem, public Analitza::Plotter2D
void translate(qreal x, qreal y);
void scale(qreal s, int x, int y);
void resetViewport();
- QStringList addFunction(const QString& expression, Analitza::Variables* vars=0);
+ QStringList addFunction(const QString& expression, const QSharedPointer<Analitza::Variables>& vars = {});
private Q_SLOTS:
void updateFuncs(const QModelIndex& start, const QModelIndex& end);
diff --git a/declarative/graph3ditem.cpp b/declarative/graph3ditem.cpp
index 01249f4..7eeb0d9 100644
--- a/declarative/graph3ditem.cpp
+++ b/declarative/graph3ditem.cpp
@@ -55,7 +55,7 @@ Graph3DItem::Graph3DItem(QQuickItem* parent)
Graph3DItem::~Graph3DItem()
{}
-QStringList Graph3DItem::addFunction(const QString& expression, Analitza::Variables* vars)
+QStringList Graph3DItem::addFunction(const QString& expression, const QSharedPointer<Analitza::Variables>& vars)
{
PlotsModel* plotsmodel = qobject_cast<PlotsModel*>(m_plotter->model());
if(!plotsmodel)
diff --git a/declarative/graph3ditem.h b/declarative/graph3ditem.h
index 62cdf18..e2dbe82 100644
--- a/declarative/graph3ditem.h
+++ b/declarative/graph3ditem.h
@@ -52,7 +52,7 @@ class Graph3DItem : public QQuickFramebufferObject
QQuickFramebufferObject::Renderer * createRenderer() const override;
- Q_SCRIPTABLE QStringList addFunction(const QString& expression, Analitza::Variables* vars=0);
+ Q_SCRIPTABLE QStringList addFunction(const QString& expression, const QSharedPointer<Analitza::Variables>& vars = {});
Q_SCRIPTABLE void rotate(qreal x, qreal y);
Q_SCRIPTABLE void scale(qreal s);
Q_SCRIPTABLE void resetView();