Connect instance list to model.
This commit is contained in:
@ -17,16 +17,14 @@
|
||||
#define INSTANCELIST_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "siglist.h"
|
||||
|
||||
#include "instance.h"
|
||||
#include "libmmc_config.h"
|
||||
|
||||
class Instance;
|
||||
|
||||
class LIBMULTIMC_EXPORT InstanceList : public QObject, public SigList< QSharedPointer<Instance> >
|
||||
class LIBMULTIMC_EXPORT InstanceList : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -46,14 +44,43 @@ public:
|
||||
QString instDir() const { return m_instDir; }
|
||||
|
||||
/*!
|
||||
* \brief Loads the instance list.
|
||||
* \brief Loads the instance list. Triggers notifications.
|
||||
*/
|
||||
InstListError loadList();
|
||||
|
||||
DEFINE_SIGLIST_SIGNALS(QSharedPointer<Instance>);
|
||||
SETUP_SIGLIST_SIGNALS(QSharedPointer<Instance>);
|
||||
/*!
|
||||
* \brief Get the instance at index
|
||||
*/
|
||||
InstancePtr at(int i) const
|
||||
{
|
||||
return m_instances.at(i);
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Get the count of loaded instances
|
||||
*/
|
||||
int count() const
|
||||
{
|
||||
return m_instances.count();
|
||||
};
|
||||
|
||||
/// Clear all instances. Triggers notifications.
|
||||
void clear();
|
||||
|
||||
/// Add an instance. Triggers notifications, returns the new index
|
||||
int add(InstancePtr t);
|
||||
|
||||
/// Get an instance by ID
|
||||
InstancePtr getInstanceById (QString id);
|
||||
|
||||
signals:
|
||||
void instanceAdded(int index);
|
||||
void instanceChanged(int index);
|
||||
void invalidated();
|
||||
|
||||
protected:
|
||||
QString m_instDir;
|
||||
QList< InstancePtr > m_instances;
|
||||
};
|
||||
|
||||
#endif // INSTANCELIST_H
|
||||
|
@ -15,11 +15,10 @@
|
||||
|
||||
#include "include/instancelist.h"
|
||||
|
||||
#include "siglist_impl.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QDirIterator>
|
||||
#include <QThread>
|
||||
|
||||
#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<Instance>(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<InstancePtr> 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();
|
||||
}
|
Reference in New Issue
Block a user