Instance model (or at least something like it)

This commit is contained in:
Petr Mrázek 2013-01-22 05:56:12 +01:00
parent f33ab9beb1
commit 00893b3cfc
12 changed files with 1002 additions and 107 deletions

View file

@ -16,6 +16,7 @@
#include "instancebase.h"
#include <QFileInfo>
#include <QDir>
#include "../util/pathutils.h"
@ -23,10 +24,27 @@ InstanceBase::InstanceBase(QString dir, QObject *parent) :
QObject(parent),
rootDir(dir)
{
QFileInfo cfgFile;
QFileInfo cfgFile(PathCombine(rootDir, "instance.cfg"));
if (cfgFile.exists())
config.loadFile(PathCombine(rootDir, "instance.cfg"));
{
if(!config.loadFile(cfgFile.absoluteFilePath()))
{
QString debugmsg("Can't load instance config file for instance ");
debugmsg+= getInstID();
qDebug(debugmsg.toLocal8Bit());
}
}
else
{
QString debugmsg("Can't find instance config file for instance ");
debugmsg+= getInstID();
debugmsg += " : ";
debugmsg +=
debugmsg+=" ... is this an instance even?";
qDebug(debugmsg.toLocal8Bit());
}
currentGroup = nullptr;
}
QString InstanceBase::getRootDir() const
@ -47,3 +65,45 @@ void InstanceBase::setInstName(QString name)
{
config.set("name", name);
}
QString InstanceBase::getInstID() const
{
return QDir(rootDir).dirName();
}
InstanceModelItem* InstanceBase::getParent() const
{
return currentGroup;
}
QVariant InstanceBase::data ( int role ) const
{
switch(role)
{
case Qt::DisplayRole:
return getInstName();
default:
return QVariant();
}
}
int InstanceBase::getRow() const
{
return currentGroup->getIndexOf((InstanceBase*)this);
}
InstanceModelItem* InstanceBase::getChild ( int index ) const
{
return nullptr;
}
InstanceModel* InstanceBase::getModel() const
{
return currentGroup->getModel();
}
IMI_type InstanceBase::getModelItemType() const
{
return IMI_Instance;
}
int InstanceBase::numChildren() const
{
return 0;
}