2012-11-26 11:29:22 +00:00
|
|
|
|
|
|
|
#include "data.hpp"
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2013-03-21 09:07:25 +00:00
|
|
|
#include <QAbstractItemModel>
|
2012-11-26 11:29:22 +00:00
|
|
|
|
2013-02-07 11:52:01 +00:00
|
|
|
#include <components/esm/esmreader.hpp>
|
2013-03-05 07:02:27 +00:00
|
|
|
#include <components/esm/defs.hpp>
|
2012-11-26 11:29:22 +00:00
|
|
|
#include <components/esm/loadglob.hpp>
|
|
|
|
|
|
|
|
#include "idtable.hpp"
|
|
|
|
#include "columns.hpp"
|
|
|
|
|
2013-03-21 09:07:25 +00:00
|
|
|
void CSMWorld::Data::addModel (QAbstractItemModel *model, UniversalId::Type type1,
|
2012-12-30 13:01:52 +00:00
|
|
|
UniversalId::Type type2)
|
|
|
|
{
|
|
|
|
mModels.push_back (model);
|
|
|
|
mModelIndex.insert (std::make_pair (type1, model));
|
|
|
|
|
|
|
|
if (type2!=UniversalId::Type_None)
|
|
|
|
mModelIndex.insert (std::make_pair (type2, model));
|
|
|
|
}
|
|
|
|
|
2012-11-26 11:29:22 +00:00
|
|
|
CSMWorld::Data::Data()
|
|
|
|
{
|
2012-11-29 17:56:28 +00:00
|
|
|
mGlobals.addColumn (new StringIdColumn<ESM::Global>);
|
2012-12-01 12:42:12 +00:00
|
|
|
mGlobals.addColumn (new RecordStateColumn<ESM::Global>);
|
2012-12-13 12:35:08 +00:00
|
|
|
mGlobals.addColumn (new FixedRecordTypeColumn<ESM::Global> (UniversalId::Type_Global));
|
2013-03-05 10:37:13 +00:00
|
|
|
mGlobals.addColumn (new VarTypeColumn<ESM::Global> (ColumnBase::Display_GlobalVarType));
|
|
|
|
mGlobals.addColumn (new VarValueColumn<ESM::Global>);
|
2012-11-26 11:29:22 +00:00
|
|
|
|
2013-02-08 08:58:19 +00:00
|
|
|
mGmsts.addColumn (new StringIdColumn<ESM::GameSetting>);
|
|
|
|
mGmsts.addColumn (new RecordStateColumn<ESM::GameSetting>);
|
|
|
|
mGmsts.addColumn (new FixedRecordTypeColumn<ESM::GameSetting> (UniversalId::Type_Gmst));
|
2013-03-05 10:37:13 +00:00
|
|
|
mGmsts.addColumn (new VarTypeColumn<ESM::GameSetting> (ColumnBase::Display_GmstVarType));
|
2013-02-08 13:48:38 +00:00
|
|
|
mGmsts.addColumn (new VarValueColumn<ESM::GameSetting>);
|
2013-02-08 08:58:19 +00:00
|
|
|
|
2013-03-21 13:31:32 +00:00
|
|
|
mSkills.addColumn (new StringIdColumn<ESM::Skill>);
|
|
|
|
mSkills.addColumn (new RecordStateColumn<ESM::Skill>);
|
|
|
|
|
2012-12-30 13:01:52 +00:00
|
|
|
addModel (new IdTable (&mGlobals), UniversalId::Type_Globals, UniversalId::Type_Global);
|
2013-02-08 08:58:19 +00:00
|
|
|
addModel (new IdTable (&mGmsts), UniversalId::Type_Gmsts, UniversalId::Type_Gmst);
|
2013-03-21 13:31:32 +00:00
|
|
|
addModel (new IdTable (&mSkills), UniversalId::Type_Skills, UniversalId::Type_Skill);
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSMWorld::Data::~Data()
|
|
|
|
{
|
2013-03-21 09:07:25 +00:00
|
|
|
for (std::vector<QAbstractItemModel *>::iterator iter (mModels.begin()); iter!=mModels.end(); ++iter)
|
2012-12-30 13:01:52 +00:00
|
|
|
delete *iter;
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const CSMWorld::IdCollection<ESM::Global>& CSMWorld::Data::getGlobals() const
|
|
|
|
{
|
|
|
|
return mGlobals;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSMWorld::IdCollection<ESM::Global>& CSMWorld::Data::getGlobals()
|
|
|
|
{
|
|
|
|
return mGlobals;
|
|
|
|
}
|
|
|
|
|
2013-02-17 19:03:39 +00:00
|
|
|
const CSMWorld::IdCollection<ESM::GameSetting>& CSMWorld::Data::getGmsts() const
|
|
|
|
{
|
|
|
|
return mGmsts;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSMWorld::IdCollection<ESM::GameSetting>& CSMWorld::Data::getGmsts()
|
|
|
|
{
|
|
|
|
return mGmsts;
|
|
|
|
}
|
|
|
|
|
2013-03-21 09:07:25 +00:00
|
|
|
QAbstractItemModel *CSMWorld::Data::getTableModel (const UniversalId& id)
|
2012-11-26 11:29:22 +00:00
|
|
|
{
|
2013-03-21 09:07:25 +00:00
|
|
|
std::map<UniversalId::Type, QAbstractItemModel *>::iterator iter = mModelIndex.find (id.getType());
|
2012-11-26 11:29:22 +00:00
|
|
|
|
2012-12-30 13:01:52 +00:00
|
|
|
if (iter==mModelIndex.end())
|
2012-11-26 11:29:22 +00:00
|
|
|
throw std::logic_error ("No table model available for " + id.toString());
|
|
|
|
|
|
|
|
return iter->second;
|
2012-12-03 12:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMWorld::Data::merge()
|
|
|
|
{
|
|
|
|
mGlobals.merge();
|
2013-02-07 10:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMWorld::Data::loadFile (const boost::filesystem::path& path, bool base)
|
|
|
|
{
|
2013-02-07 11:52:01 +00:00
|
|
|
ESM::ESMReader reader;
|
2013-02-17 18:26:01 +00:00
|
|
|
|
|
|
|
/// \todo set encoding properly, once config implementation has been fixed.
|
|
|
|
ToUTF8::Utf8Encoder encoder (ToUTF8::calculateEncoding ("win1252"));
|
|
|
|
reader.setEncoder (&encoder);
|
|
|
|
|
2013-02-07 11:52:01 +00:00
|
|
|
reader.open (path.string());
|
|
|
|
|
|
|
|
// Note: We do not need to send update signals here, because at this point the model is not connected
|
|
|
|
// to any view.
|
|
|
|
while (reader.hasMoreRecs())
|
|
|
|
{
|
|
|
|
ESM::NAME n = reader.getRecName();
|
|
|
|
reader.getRecHeader();
|
|
|
|
|
|
|
|
switch (n.val)
|
|
|
|
{
|
|
|
|
case ESM::REC_GLOB: mGlobals.load (reader, base); break;
|
2013-02-08 08:58:19 +00:00
|
|
|
case ESM::REC_GMST: mGmsts.load (reader, base); break;
|
2013-03-21 13:31:32 +00:00
|
|
|
case ESM::REC_SKIL: mSkills.load (reader, base); break;
|
2013-02-07 11:52:01 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
/// \todo throw an exception instead, once all records are implemented
|
|
|
|
reader.skipRecord();
|
|
|
|
}
|
|
|
|
}
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|