Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 094aca5a authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Expose further PlotsModel and Expression API to use from QML

parent f2093d85
......@@ -169,7 +169,7 @@ class ANALITZA_EXPORT Expression
/**
* Converts the expression to a string expression.
*/
QString toString() const;
Q_SCRIPTABLE QString toString() const;
/**
* Converts the expression to MathML.
......@@ -279,4 +279,6 @@ class ANALITZA_EXPORT Expression
}
Q_DECLARE_METATYPE(Analitza::Expression)
#endif
......@@ -62,14 +62,16 @@ PlotBuilder PlotsFactory::requestPlot(const Analitza::Expression& testexp, Dimen
Analitza::Analyzer a(vars ? vars : m_vars);
a.setExpression(exp);
a.setExpression(a.dependenciesToLambda());
QString id;
if(a.isCorrect()) {
QString expectedid = FunctionGraphFactory::self()->trait(a.expression(), a.type(), dim);
if(FunctionGraphFactory::self()->contains(expectedid)) {
id = expectedid;
} else
} else if (!expectedid.isEmpty())
errs << QCoreApplication::tr("Function type '%1' not recognized").arg(expectedid);
else
errs << QCoreApplication::tr("Function '%1' not recognized").arg(a.expression().toString());
} else {
errs << a.errors();
}
......
......@@ -292,3 +292,11 @@ QStringList PlotsModel::addFunction(const QString& expression, Dimension dim, co
return err;
}
bool Analitza::PlotsModel::canAddFunction(const QString& expression, int _dim, const QSharedPointer<Analitza::Variables>& vars)
{
const Analitza::Dimension dim = static_cast<Analitza::Dimension>(_dim);
Analitza::Expression e(expression, Analitza::Expression::isMathML(expression));
PlotBuilder req = PlotsFactory::self()->requestPlot(e, dim, vars);
return req.canDraw();
}
......@@ -78,7 +78,15 @@ public:
/**
* Helper method to help easily add elements to the model
*/
Q_SCRIPTABLE QStringList addFunction(const QString& expression, Analitza::Dimension dim, const QSharedPointer<Analitza::Variables>& vars);
QStringList addFunction(const QString& expression, Analitza::Dimension dim, const QSharedPointer<Analitza::Variables>& vars);
///convenience function for QML
Q_SCRIPTABLE QStringList addFunction(const QString& expression, int dim, const QSharedPointer<Analitza::Variables>& vars) { return addFunction(expression, Analitza::Dimension(dim), vars); }
/**
* Helper method to help easily add elements to the model
*/
Q_SCRIPTABLE bool canAddFunction(const QString& expression, int dim, const QSharedPointer<Analitza::Variables>& vars);
protected:
void emitChanged(PlotItem* it);
......
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