added signals and functions to Data for handling ID list changes

actorid
Marc Zinnschlag 11 years ago
parent 78f7f80fc3
commit 3d2281fe80

@ -18,12 +18,12 @@ opencs_hdrs_noqt (model/doc
opencs_units (model/world
idtable idtableproxymodel regionmap
idtable idtableproxymodel regionmap data
)
opencs_units_noqt (model/world
universalid data record commands columnbase scriptcontext cell refidcollection
universalid record commands columnbase scriptcontext cell refidcollection
refidadapter refiddata refidadapterimp ref collectionbase refcollection columns
)

@ -107,6 +107,11 @@ namespace CSMWorld
virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const;
///< \param type Will be ignored, unless the collection supports multiple record types
virtual std::vector<std::string> getIds() const;
///< Return a sorted collection of all IDs
///
/// \note Deleted records are not listed.
void addColumn (Column<ESXRecordT> *column);
void setRecord (int index, const Record<ESXRecordT>& record);
@ -293,6 +298,21 @@ namespace CSMWorld
return static_cast<int> (mRecords.size());
}
template<typename ESXRecordT, typename IdAccessorT>
std::vector<std::string> Collection<ESXRecordT, IdAccessorT>::getIds() const
{
std::vector<std::string> ids;
for (typename std::map<std::string, int>::const_iterator iter = mIndex.begin();
iter!=mIndex.end(); ++iter)
{
if (!mRecords[iter->second].isDeleted())
ids.push_back (IdAccessorT().getId (mRecords[iter->second].get()));
}
return ids;
}
template<typename ESXRecordT, typename IdAccessorT>
const Record<ESXRecordT>& Collection<ESXRecordT, IdAccessorT>::getRecord (const std::string& id) const
{

@ -78,8 +78,12 @@ namespace CSMWorld
virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const = 0;
///< \param type Will be ignored, unless the collection supports multiple record types
};
virtual std::vector<std::string> getIds() const = 0;
///< Return a sorted collection of all IDs
///
/// \note Deleted records are not listed.
};
}
#endif

@ -2,6 +2,7 @@
#include "data.hpp"
#include <stdexcept>
#include <algorithm>
#include <QAbstractItemModel>
@ -15,13 +16,30 @@
#include "columns.hpp"
void CSMWorld::Data::addModel (QAbstractItemModel *model, UniversalId::Type type1,
UniversalId::Type type2)
UniversalId::Type type2, bool update)
{
mModels.push_back (model);
mModelIndex.insert (std::make_pair (type1, model));
if (type2!=UniversalId::Type_None)
mModelIndex.insert (std::make_pair (type2, model));
if (update)
{
connect (model, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
this, SLOT (dataChanged (const QModelIndex&, const QModelIndex&)));
connect (model, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
this, SLOT (rowsChanged (const QModelIndex&, int, int)));
connect (model, SIGNAL (rowsRemoved (const QModelIndex&, int, int)),
this, SLOT (rowsChanged (const QModelIndex&, int, int)));
}
}
void CSMWorld::Data::appendIds (std::vector<std::string>& ids, const CollectionBase& collection)
{
std::vector<std::string> ids2 = collection.getIds();
ids.insert (ids.end(), ids2.begin(), ids2.end());
}
CSMWorld::Data::Data() : mRefs (mCells)
@ -155,7 +173,7 @@ CSMWorld::Data::Data() : mRefs (mCells)
addModel (new IdTable (&mGlobals), UniversalId::Type_Globals, UniversalId::Type_Global);
addModel (new IdTable (&mGmsts), UniversalId::Type_Gmsts, UniversalId::Type_Gmst);
addModel (new IdTable (&mSkills), UniversalId::Type_Skills, UniversalId::Type_Skill);
addModel (new IdTable (&mSkills), UniversalId::Type_Skills, UniversalId::Type_Skill, false);
addModel (new IdTable (&mClasses), UniversalId::Type_Classes, UniversalId::Type_Class);
addModel (new IdTable (&mFactions), UniversalId::Type_Factions, UniversalId::Type_Faction);
addModel (new IdTable (&mRaces), UniversalId::Type_Races, UniversalId::Type_Race);
@ -167,8 +185,8 @@ CSMWorld::Data::Data() : mRefs (mCells)
addModel (new IdTable (&mCells), UniversalId::Type_Cells, UniversalId::Type_Cell);
addModel (new IdTable (&mReferenceables), UniversalId::Type_Referenceables,
UniversalId::Type_Referenceable);
addModel (new IdTable (&mRefs), UniversalId::Type_References, UniversalId::Type_Reference);
addModel (new IdTable (&mFilters), UniversalId::Type_Filters, UniversalId::Type_Filter);
addModel (new IdTable (&mRefs), UniversalId::Type_References, UniversalId::Type_Reference, false);
addModel (new IdTable (&mFilters), UniversalId::Type_Filters, UniversalId::Type_Filter, false);
}
CSMWorld::Data::~Data()
@ -341,7 +359,7 @@ QAbstractItemModel *CSMWorld::Data::getTableModel (const UniversalId& id)
{
RegionMap *table = 0;
addModel (table = new RegionMap (*this), UniversalId::Type_RegionMap,
UniversalId::Type_None);
UniversalId::Type_None, false);
return table;
}
throw std::logic_error ("No table model available for " + id.toString());
@ -440,3 +458,37 @@ bool CSMWorld::Data::hasId (const std::string& id) const
getCells().searchId (id)!=-1 ||
getReferenceables().searchId (id)!=-1;
}
std::vector<std::string> CSMWorld::Data::getIds() const
{
std::vector<std::string> ids;
appendIds (ids, mGlobals);
appendIds (ids, mGmsts);
appendIds (ids, mClasses);
appendIds (ids, mFactions);
appendIds (ids, mRaces);
appendIds (ids, mSounds);
appendIds (ids, mScripts);
appendIds (ids, mRegions);
appendIds (ids, mBirthsigns);
appendIds (ids, mSpells);
appendIds (ids, mCells);
appendIds (ids, mReferenceables);
std::sort (ids.begin(), ids.end());
return ids;
}
void CSMWorld::Data::dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
// Note: The performance of of ID list change updates could be improved only emit the signal, if
// the state of the record is changed.
emit idListChanged();
}
void CSMWorld::Data::rowsChanged (const QModelIndex& parent, int start, int end)
{
emit idListChanged();
}

@ -6,6 +6,9 @@
#include <boost/filesystem/path.hpp>
#include <QObject>
#include <QModelIndex>
#include <components/esm/loadglob.hpp>
#include <components/esm/loadgmst.hpp>
#include <components/esm/loadskil.hpp>
@ -30,8 +33,10 @@ class QAbstractItemModel;
namespace CSMWorld
{
class Data
class Data : public QObject
{
Q_OBJECT
IdCollection<ESM::Global> mGlobals;
IdCollection<ESM::GameSetting> mGmsts;
IdCollection<ESM::Skill> mSkills;
@ -55,13 +60,16 @@ namespace CSMWorld
Data& operator= (const Data&);
void addModel (QAbstractItemModel *model, UniversalId::Type type1,
UniversalId::Type type2 = UniversalId::Type_None);
UniversalId::Type type2 = UniversalId::Type_None, bool update = true);
static void appendIds (std::vector<std::string>& ids, const CollectionBase& collection);
///< Append all IDs from collection to \a ids.
public:
Data();
~Data();
virtual ~Data();
const IdCollection<ESM::Global>& getGlobals() const;
@ -136,6 +144,21 @@ namespace CSMWorld
///< Merging content of a file into base or modified.
bool hasId (const std::string& id) const;
std::vector<std::string> getIds() const;
///< Return a sorted collection of all IDs that are not internal to the editor.
///
/// \note Deleted records are not listed.
signals:
void idListChanged();
private slots:
void dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
void rowsChanged (const QModelIndex& parent, int start, int end);
};
}

@ -534,3 +534,8 @@ int CSMWorld::RefIdCollection::getAppendIndex (UniversalId::Type type) const
{
return mData.getAppendIndex (type);
}
std::vector<std::string> CSMWorld::RefIdCollection::getIds() const
{
return mData.getIds();
}

@ -89,6 +89,11 @@ namespace CSMWorld
virtual int getAppendIndex (UniversalId::Type type) const;
///< \param type Will be ignored, unless the collection supports multiple record types
virtual std::vector<std::string> getIds() const;
///< Return a sorted collection of all IDs
///
/// \note Deleted records are not listed.
};
}

@ -196,3 +196,25 @@ int CSMWorld::RefIdData::getSize() const
{
return mIndex.size();
}
std::vector<std::string> CSMWorld::RefIdData::getIds() const
{
std::vector<std::string> ids;
for (std::map<std::string, LocalIndex>::const_iterator iter (mIndex.begin()); iter!=mIndex.end();
++iter)
{
if (!getRecord (iter->second).isDeleted())
{
std::map<UniversalId::Type, RefIdDataContainerBase *>::const_iterator container =
mRecordContainers.find (iter->second.second);
if (container==mRecordContainers.end())
throw std::logic_error ("Invalid referenceable ID type");
ids.push_back (container->second->getId (iter->second.first));
}
}
return ids;
}

@ -182,6 +182,11 @@ namespace CSMWorld
void load (const LocalIndex& index, ESM::ESMReader& reader, bool base);
int getSize() const;
std::vector<std::string> getIds() const;
///< Return a sorted collection of all IDs
///
/// \note Deleted records are not listed.
};
}

Loading…
Cancel
Save