From 00893b3cfc68f12c09e84643d255044a488b0eb6 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Tue, 22 Jan 2013 05:56:12 +0100 Subject: Instance model (or at least something like it) --- data/instancebase.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'data/instancebase.cpp') diff --git a/data/instancebase.cpp b/data/instancebase.cpp index 15dc54f4..a5ef35a2 100644 --- a/data/instancebase.cpp +++ b/data/instancebase.cpp @@ -16,6 +16,7 @@ #include "instancebase.h" #include +#include #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; +} -- cgit