enable dragging from resources tables

This commit is contained in:
Marc Zinnschlag 2014-07-07 15:20:05 +02:00
parent df6996d4ae
commit c1bbefb840
5 changed files with 65 additions and 20 deletions

View file

@ -8,9 +8,9 @@
#include <components/misc/stringops.hpp>
CSMWorld::Resources::Resources (const std::string& baseDirectory,
CSMWorld::Resources::Resources (const std::string& baseDirectory, UniversalId::Type type,
const char * const *extensions)
: mBaseDirectory (baseDirectory)
: mBaseDirectory (baseDirectory), mType (type)
{
int baseSize = mBaseDirectory.size();
@ -96,3 +96,8 @@ int CSMWorld::Resources::searchId (const std::string& id) const
return iter->second;
}
CSMWorld::UniversalId::Type CSMWorld::Resources::getType() const
{
return mType;
}

View file

@ -5,6 +5,8 @@
#include <map>
#include <vector>
#include "universalid.hpp"
namespace CSMWorld
{
class Resources
@ -12,10 +14,13 @@ namespace CSMWorld
std::map<std::string, int> mIndex;
std::vector<std::string> mFiles;
std::string mBaseDirectory;
UniversalId::Type mType;
public:
Resources (const std::string& baseDirectory, const char * const *extensions = 0);
/// \param type Type of resources in this table.
Resources (const std::string& baseDirectory, UniversalId::Type type,
const char * const *extensions = 0);
int getSize() const;
@ -24,6 +29,8 @@ namespace CSMWorld
int getIndex (const std::string& id) const;
int searchId (const std::string& id) const;
UniversalId::Type getType() const;
};
}

View file

@ -3,17 +3,21 @@
#include <stdexcept>
void CSMWorld::ResourcesManager::addResources (const Resources& resources)
{
mResources.insert (std::make_pair (resources.getType(), resources));
}
void CSMWorld::ResourcesManager::listResources()
{
static const char * const sMeshTypes[] = { "nif", 0 };
mResources.insert (
std::make_pair (UniversalId::Type_Mesh, Resources ("meshes", sMeshTypes)));
mResources.insert (std::make_pair (UniversalId::Type_Icon, "icons"));
mResources.insert (std::make_pair (UniversalId::Type_Music, "music"));
mResources.insert (std::make_pair (UniversalId::Type_SoundRes, "sound"));
mResources.insert (std::make_pair (UniversalId::Type_Texture, "textures"));
mResources.insert (std::make_pair (UniversalId::Type_Video, "videos"));
addResources (Resources ("meshes", UniversalId::Type_Mesh, sMeshTypes));
addResources (Resources ("icons", UniversalId::Type_Icon));
addResources (Resources ("music", UniversalId::Type_Music));
addResources (Resources ("sound", UniversalId::Type_SoundRes));
addResources (Resources ("textures", UniversalId::Type_Texture));
addResources (Resources ("videos", UniversalId::Type_Video));
}
const CSMWorld::Resources& CSMWorld::ResourcesManager::get (UniversalId::Type type) const

View file

@ -12,6 +12,10 @@ namespace CSMWorld
{
std::map<UniversalId::Type, Resources> mResources;
private:
void addResources (const Resources& resources);
public:
/// Ask OGRE for a list of available resources.

View file

@ -26,7 +26,7 @@ int CSMWorld::ResourceTable::columnCount (const QModelIndex & parent) const
if (parent.isValid())
return 0;
return 1;
return 2; // ID, type
}
QVariant CSMWorld::ResourceTable::data (const QModelIndex & index, int role) const
@ -34,10 +34,13 @@ QVariant CSMWorld::ResourceTable::data (const QModelIndex & index, int role) co
if (role!=Qt::DisplayRole)
return QVariant();
if (index.column()!=0)
throw std::logic_error ("Invalid column in resource table");
if (index.column()==0)
return QString::fromUtf8 (mResources->getId (index.row()).c_str());
if (index.column()==1)
return static_cast<int> (mResources->getType());
throw std::logic_error ("Invalid column in resource table");
}
QVariant CSMWorld::ResourceTable::headerData (int section, Qt::Orientation orientation,
@ -46,15 +49,34 @@ QVariant CSMWorld::ResourceTable::headerData (int section, Qt::Orientation orien
if (orientation==Qt::Vertical)
return QVariant();
if (role==Qt::DisplayRole)
return "ID";
if (role==ColumnBase::Role_Flags)
return ColumnBase::Flag_Table;
switch (section)
{
case 0:
if (role==Qt::DisplayRole)
return Columns::getName (Columns::ColumnId_Id).c_str();
if (role==ColumnBase::Role_Display)
return ColumnBase::Display_String;
break;
case 1:
if (role==Qt::DisplayRole)
return Columns::getName (Columns::ColumnId_RecordType).c_str();
if (role==ColumnBase::Role_Display)
return ColumnBase::Display_Integer;
break;
}
// xxx
return QVariant();
}
@ -78,7 +100,7 @@ QModelIndex CSMWorld::ResourceTable::index (int row, int column, const QModelInd
if (row<0 || row>=mResources->getSize())
return QModelIndex();
if (column!=0)
if (column<0 || column>1)
return QModelIndex();
return createIndex (row, column);
@ -99,6 +121,9 @@ int CSMWorld::ResourceTable::searchColumnIndex (Columns::ColumnId id) const
if (id==Columns::ColumnId_Id)
return 0;
if (id==Columns::ColumnId_RecordType)
return 1;
return -1;
}