Commit 6bdc9149 authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Fix memory leaks in class Tracer

The global variable states is now a static member of class Tracer.

CCBUG:301932
parent 028532ac
...@@ -31,7 +31,7 @@ Q_LOGGING_CATEGORY(UMBRELLO, "umbrello") ...@@ -31,7 +31,7 @@ Q_LOGGING_CATEGORY(UMBRELLO, "umbrello")
Tracer* Tracer::m_instance = 0; Tracer* Tracer::m_instance = 0;
Tracer::MapType *Tracer::m_classes = 0; Tracer::MapType *Tracer::m_classes = 0;
Tracer::StateMap *Tracer::m_states = 0;
Tracer* Tracer::instance() Tracer* Tracer::instance()
{ {
...@@ -51,6 +51,8 @@ Tracer::Tracer(QWidget *parent) ...@@ -51,6 +51,8 @@ Tracer::Tracer(QWidget *parent)
// in case no one called registerClass() before // in case no one called registerClass() before
if (!m_classes) if (!m_classes)
m_classes = new Tracer::MapType; m_classes = new Tracer::MapType;
if (!m_states)
m_states = new Tracer::StateMap;
setRootIsDecorated(true); setRootIsDecorated(true);
setAlternatingRowColors(true); setAlternatingRowColors(true);
setHeaderLabel(i18n("Class Name")); setHeaderLabel(i18n("Class Name"));
...@@ -65,6 +67,9 @@ Tracer::~Tracer() ...@@ -65,6 +67,9 @@ Tracer::~Tracer()
{ {
clear(); clear();
delete m_classes; delete m_classes;
m_classes = nullptr;
delete m_states;
m_states = nullptr;
} }
/** /**
...@@ -136,8 +141,6 @@ void Tracer::update(const QString &name) ...@@ -136,8 +141,6 @@ void Tracer::update(const QString &name)
} }
} }
QMap<QString,Qt::CheckState> states;
/** /**
* Update check box of parent items. * Update check box of parent items.
* *
...@@ -157,7 +160,7 @@ void Tracer::updateParentItemCheckBox(QTreeWidgetItem* parent) ...@@ -157,7 +160,7 @@ void Tracer::updateParentItemCheckBox(QTreeWidgetItem* parent)
else else
parent->setCheckState(0, Qt::PartiallyChecked); parent->setCheckState(0, Qt::PartiallyChecked);
states[parent->text(0)] = parent->checkState(0); (*m_states)[parent->text(0)] = parent->checkState(0);
} }
/** /**
...@@ -196,7 +199,7 @@ void Tracer::slotParentItemClicked(QTreeWidgetItem* parent) ...@@ -196,7 +199,7 @@ void Tracer::slotParentItemClicked(QTreeWidgetItem* parent)
{ {
// @TODO parent->checkState(0) do not return the correct state // @TODO parent->checkState(0) do not return the correct state
// Qt::CheckState state = parent->checkState(0); // Qt::CheckState state = parent->checkState(0);
Qt::CheckState state = states[parent->text(0)]; Qt::CheckState state = (*m_states)[parent->text(0)];
if (state == Qt::PartiallyChecked || state == Qt::Unchecked) { if (state == Qt::PartiallyChecked || state == Qt::Unchecked) {
for(int i = 0; i < parent->childCount(); i++) { for(int i = 0; i < parent->childCount(); i++) {
QString text = parent->child(i)->text(0); QString text = parent->child(i)->text(0);
......
...@@ -104,9 +104,11 @@ private: ...@@ -104,9 +104,11 @@ private:
}; };
typedef QMap<QString, MapEntry> MapType; typedef QMap<QString, MapEntry> MapType;
typedef QMap<QString,Qt::CheckState> StateMap;
static Tracer* m_instance; static Tracer* m_instance;
static MapType *m_classes; static MapType *m_classes;
static StateMap *m_states;
explicit Tracer(QWidget *parent = 0); explicit Tracer(QWidget *parent = 0);
}; };
......
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