[apps/graph] Recompute expression and layout when a function sets a new content

Change-Id: I15f39c72cfed28fe6eca5b401eb8da149d30fe12
This commit is contained in:
Émilie Feral
2016-10-04 10:00:57 +02:00
parent 54f3614e51
commit e09317b243

View File

@@ -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;
}