From 8411d71741d596cb07b07ec7fe0c977726fc94e6 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Thu, 5 Jan 2017 16:53:13 +0100 Subject: [PATCH] Store the QStrings by value instead of by pointer --- word.cpp | 14 +++++--------- word.h | 12 ++++++------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/word.cpp b/word.cpp index b6905aad..ec581e87 100644 --- a/word.cpp +++ b/word.cpp @@ -3,26 +3,22 @@ Word::Word(LazyLoadedImage* image, Type type, const QString& copytext, const QString& tooltip) { this->image = image; - this->text = NULL; m_isImage = true; m_type = type; - m_copyText = new QString(copytext); - m_tooltip = new QString(tooltip); + m_copyText = copytext; + m_tooltip = tooltip; } Word::Word(const QString& text, Type type, const QString& copytext, const QString& tooltip) { this->image = NULL; - this->text = new QString(text); + this->text = text; m_isImage = false; m_type = type; - m_copyText = new QString(copytext); - m_tooltip = new QString(tooltip); + m_copyText = copytext; + m_tooltip = tooltip; } Word::~Word() { - delete text; - delete m_copyText; - delete m_tooltip; } diff --git a/word.h b/word.h index 7bcd1bb8..b0d0840c 100644 --- a/word.h +++ b/word.h @@ -50,7 +50,7 @@ public: } QString& getText() { - return *text; + return text; } int width() { @@ -78,7 +78,7 @@ public: } QString& copyText() { - return *m_copyText; + return m_copyText; } bool hasTrailingSpace() { @@ -94,17 +94,17 @@ public: } QString& tooltip() { - return *m_tooltip; + return m_tooltip; } private: LazyLoadedImage* image; - QString* text; + QString text; bool m_isImage; Type m_type; - QString* m_copyText; - QString* m_tooltip; + QString m_copyText; + QString m_tooltip; int m_x; int m_y; int m_width;