From 65faabeed48584c461ca21d784c3f1d46f67f832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 18 Mar 2013 23:00:46 +0100 Subject: Connect instance list to model. --- libmultimc/src/instancelist.cpp | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'libmultimc/src/instancelist.cpp') diff --git a/libmultimc/src/instancelist.cpp b/libmultimc/src/instancelist.cpp index 78650634..83a72afb 100644 --- a/libmultimc/src/instancelist.cpp +++ b/libmultimc/src/instancelist.cpp @@ -15,11 +15,10 @@ #include "include/instancelist.h" -#include "siglist_impl.h" - #include #include #include +#include #include "include/instance.h" #include "include/instanceloader.h" @@ -37,7 +36,7 @@ InstanceList::InstListError InstanceList::loadList() { QDir dir(m_instDir); QDirIterator iter(dir); - + m_instances.clear(); while (iter.hasNext()) { QString subDir = iter.next(); @@ -78,10 +77,41 @@ InstanceList::InstListError InstanceList::loadList() qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8()); inst->setParent(this); - append(QSharedPointer(inst)); + m_instances.append(inst); } } } - + emit invalidated(); return NoError; } + +/// Clear all instances. Triggers notifications. +void InstanceList::clear() +{ + m_instances.clear(); + emit invalidated(); +}; + +/// Add an instance. Triggers notifications, returns the new index +int InstanceList::add(InstancePtr t) +{ + m_instances.append(t); + emit instanceAdded(count() - 1); + return count() - 1; +} + +InstancePtr InstanceList::getInstanceById(QString instId) +{ + QListIterator iter(m_instances); + InstancePtr inst; + while(iter.hasNext()) + { + inst = iter.next(); + if (inst->id() == instId) + break; + } + if (inst->id() != instId) + return InstancePtr(); + else + return iter.peekPrevious(); +} \ No newline at end of file -- cgit v1.2.3