added resources tables

This commit is contained in:
Marc Zinnschlag 2014-07-05 15:50:47 +02:00
parent 42db9a5091
commit b2c957a56f
4 changed files with 194 additions and 1 deletions

View file

@ -18,7 +18,7 @@ opencs_hdrs_noqt (model/doc
opencs_units (model/world
idtable idtableproxymodel regionmap data commanddispatcher idtablebase
idtable idtableproxymodel regionmap data commanddispatcher idtablebase resourcetable
)

View file

@ -16,6 +16,7 @@
#include "regionmap.hpp"
#include "columns.hpp"
#include "resourcesmanager.hpp"
#include "resourcetable.hpp"
void CSMWorld::Data::addModel (QAbstractItemModel *model, UniversalId::Type type, bool update)
{
@ -279,6 +280,18 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
UniversalId::Type_Referenceable);
addModel (new IdTable (&mRefs, IdTable::Feature_ViewCell | IdTable::Feature_Preview), UniversalId::Type_Reference);
addModel (new IdTable (&mFilters), UniversalId::Type_Filter);
addModel (new ResourceTable (&mResourcesManager.get (UniversalId::Type_Mesh)),
UniversalId::Type_Mesh);
addModel (new ResourceTable (&mResourcesManager.get (UniversalId::Type_Icon)),
UniversalId::Type_Icon);
addModel (new ResourceTable (&mResourcesManager.get (UniversalId::Type_Music)),
UniversalId::Type_Music);
addModel (new ResourceTable (&mResourcesManager.get (UniversalId::Type_SoundRes)),
UniversalId::Type_SoundRes);
addModel (new ResourceTable (&mResourcesManager.get (UniversalId::Type_Texture)),
UniversalId::Type_Texture);
addModel (new ResourceTable (&mResourcesManager.get (UniversalId::Type_Video)),
UniversalId::Type_Video);
}
CSMWorld::Data::~Data()

View file

@ -0,0 +1,123 @@
#include "resourcetable.hpp"
#include <stdexcept>
#include "resources.hpp"
#include "columnbase.hpp"
#include "universalid.hpp"
CSMWorld::ResourceTable::ResourceTable (const Resources *resources, unsigned int features)
: IdTableBase (features | Feature_Constant), mResources (resources)
{}
CSMWorld::ResourceTable::~ResourceTable() {}
int CSMWorld::ResourceTable::rowCount (const QModelIndex & parent) const
{
if (parent.isValid())
return 0;
return mResources->getSize();
}
int CSMWorld::ResourceTable::columnCount (const QModelIndex & parent) const
{
if (parent.isValid())
return 0;
return 1;
}
QVariant CSMWorld::ResourceTable::data (const QModelIndex & index, int role) const
{
if (role!=Qt::DisplayRole)
return QVariant();
if (index.column()!=0)
throw std::logic_error ("Invalid column in resource table");
return QString::fromUtf8 (mResources->getId (index.row()).c_str());
}
QVariant CSMWorld::ResourceTable::headerData (int section, Qt::Orientation orientation,
int role ) const
{
if (orientation==Qt::Vertical)
return QVariant();
if (role==Qt::DisplayRole)
return "ID";
if (role==ColumnBase::Role_Flags)
return ColumnBase::Flag_Table;
if (role==ColumnBase::Role_Display)
return ColumnBase::Display_String;
return QVariant();
}
bool CSMWorld::ResourceTable::setData ( const QModelIndex &index, const QVariant &value,
int role)
{
return false;
}
Qt::ItemFlags CSMWorld::ResourceTable::flags (const QModelIndex & index) const
{
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;;
}
QModelIndex CSMWorld::ResourceTable::index (int row, int column, const QModelIndex& parent)
const
{
if (parent.isValid())
return QModelIndex();
if (row<0 || row>=mResources->getSize())
return QModelIndex();
if (column!=0)
return QModelIndex();
return createIndex (row, column);
}
QModelIndex CSMWorld::ResourceTable::parent (const QModelIndex& index) const
{
return QModelIndex();
}
QModelIndex CSMWorld::ResourceTable::getModelIndex (const std::string& id, int column) const
{
return index (mResources->getIndex (id), column);
}
int CSMWorld::ResourceTable::searchColumnIndex (Columns::ColumnId id) const
{
if (id==Columns::ColumnId_Id)
return 0;
return -1;
}
int CSMWorld::ResourceTable::findColumnIndex (Columns::ColumnId id) const
{
int index = searchColumnIndex (id);
if (index==-1)
throw std::logic_error ("invalid column index");
return index;
}
std::pair<CSMWorld::UniversalId, std::string> CSMWorld::ResourceTable::view (int row) const
{
return std::make_pair (UniversalId::Type_None, "");
}
bool CSMWorld::ResourceTable::isDeleted (const std::string& id) const
{
return false;
}

View file

@ -0,0 +1,57 @@
#ifndef CSM_WOLRD_RESOURCETABLE_H
#define CSM_WOLRD_RESOURCETABLE_H
#include "idtablebase.hpp"
namespace CSMWorld
{
class Resources;
class ResourceTable : public IdTableBase
{
const Resources *mResources;
public:
/// \note The feature Feature_Constant will be added implicitly.
ResourceTable (const Resources *resources, unsigned int features = 0);
virtual ~ResourceTable();
virtual int rowCount (const QModelIndex & parent = QModelIndex()) const;
virtual int columnCount (const QModelIndex & parent = QModelIndex()) const;
virtual QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const;
virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual bool setData ( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
virtual Qt::ItemFlags flags (const QModelIndex & index) const;
virtual QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex())
const;
virtual QModelIndex parent (const QModelIndex& index) const;
virtual QModelIndex getModelIndex (const std::string& id, int column) const;
/// Return index of column with the given \a id. If no such column exists, -1 is
/// returned.
virtual int searchColumnIndex (Columns::ColumnId id) const;
/// Return index of column with the given \a id. If no such column exists, an
/// exception is thrown.
virtual int findColumnIndex (Columns::ColumnId id) const;
/// Return the UniversalId and the hint for viewing \a row. If viewing is not
/// supported by this table, return (UniversalId::Type_None, "").
virtual std::pair<UniversalId, std::string> view (int row) const;
/// Is \a id flagged as deleted?
virtual bool isDeleted (const std::string& id) const;
};
}
#endif