From e09317b243bceb62ed48da091d17ae839f444d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 4 Oct 2016 10:00:57 +0200 Subject: [PATCH] [apps/graph] Recompute expression and layout when a function sets a new content Change-Id: I15f39c72cfed28fe6eca5b401eb8da149d30fe12 --- apps/graph/function.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/graph/function.cpp b/apps/graph/function.cpp index 358af7d32..6970a4fe6 100644 --- a/apps/graph/function.cpp +++ b/apps/graph/function.cpp @@ -11,14 +11,20 @@ Graph::Function::Function(const char * text, KDColor color) : } void Graph::Function::setContent(const char * c) { - #if __GLIBC__ +#if __GLIBC__ // FIXME: This is ugly. strncpy(m_text, c, sizeof(m_text)); #else strlcpy(m_text, c, sizeof(m_text)); #endif - m_expression = expression(); - m_layout = layout(); + if (m_expression != nullptr) { + delete m_expression; + } + m_expression = Expression::parse(m_text); + if (m_layout != nullptr) { + delete m_layout; + } + m_layout = expression()->createLayout(); } void Graph::Function::setColor(KDColor color) { @@ -26,7 +32,6 @@ void Graph::Function::setColor(KDColor color) { } Graph::Function::~Function() { - //FIXME: Free m_text! if (m_layout != nullptr) { delete m_layout; } @@ -44,16 +49,10 @@ const char * Graph::Function::name() { } Expression * Graph::Function::expression() { - if (m_expression == nullptr) { - m_expression = Expression::parse(m_text); - } return m_expression; } ExpressionLayout * Graph::Function::layout() { - if (m_layout == nullptr) { - m_layout = expression()->createLayout(); - } return m_layout; }