mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-11 03:21:29 +00:00
b22f1da59e
Subsurface creates a lot of singleton instances on demand, but nothing ever deleted them. Since they are singletons, these memory allocations are technically not leaks. However, they clutter the output in valgrind and other memory analysers, hiding the real issues. The solution is to delete these items at exit. For the models and for gettextFromC, the solution is to use a QScopedPointer, which will delete its payload when it gets destroyed. For the dialogs and other widgets, we can't do that: they need to be deleted before QApplication exits, so we just set the parent in all of them to the main window. Signed-off-by: Thiago Macieira <thiago@macieira.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#include "completionmodels.h"
|
|
#include "dive.h"
|
|
#include "mainwindow.h"
|
|
|
|
#define CREATE_SINGLETON(X) \
|
|
X* X::instance() \
|
|
{ \
|
|
static QScopedPointer<X> self(new X()); \
|
|
return self.data(); \
|
|
}
|
|
|
|
CREATE_SINGLETON(BuddyCompletionModel);
|
|
CREATE_SINGLETON(DiveMasterCompletionModel);
|
|
CREATE_SINGLETON(LocationCompletionModel);
|
|
CREATE_SINGLETON(SuitCompletionModel);
|
|
CREATE_SINGLETON(TagCompletionModel);
|
|
|
|
#undef CREATE_SINGLETON
|
|
|
|
#define CREATE_UPDATE_METHOD(Class, diveStructMember) \
|
|
void Class::updateModel() \
|
|
{ \
|
|
QStringList list; \
|
|
struct dive* dive; \
|
|
int i = 0; \
|
|
for_each_dive(i, dive){ \
|
|
QString buddy(dive->diveStructMember); \
|
|
if (!list.contains(buddy)){ \
|
|
list.append(buddy); \
|
|
} \
|
|
} \
|
|
setStringList(list); \
|
|
}
|
|
|
|
CREATE_UPDATE_METHOD(BuddyCompletionModel, buddy);
|
|
CREATE_UPDATE_METHOD(DiveMasterCompletionModel, divemaster);
|
|
CREATE_UPDATE_METHOD(LocationCompletionModel, location);
|
|
CREATE_UPDATE_METHOD(SuitCompletionModel, suit);
|
|
|
|
void TagCompletionModel::updateModel()
|
|
{
|
|
if(g_tag_list == NULL)
|
|
return;
|
|
QStringList list;
|
|
struct tag_entry *current_tag_entry = g_tag_list->next;
|
|
while (current_tag_entry != NULL) {
|
|
list.append(QString(current_tag_entry->tag->name));
|
|
current_tag_entry = current_tag_entry->next;
|
|
}
|
|
setStringList(list);
|
|
}
|