forked from teamnwah/openmw-tes3coop
enable dragging from resources tables
This commit is contained in:
parent
df6996d4ae
commit
c1bbefb840
5 changed files with 65 additions and 20 deletions
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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());
|
||||
|
||||
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,14 +49,33 @@ 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;
|
||||
|
||||
if (role==ColumnBase::Role_Display)
|
||||
return ColumnBase::Display_String;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue