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>
|
#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)
|
const char * const *extensions)
|
||||||
: mBaseDirectory (baseDirectory)
|
: mBaseDirectory (baseDirectory), mType (type)
|
||||||
{
|
{
|
||||||
int baseSize = mBaseDirectory.size();
|
int baseSize = mBaseDirectory.size();
|
||||||
|
|
||||||
|
@ -95,4 +95,9 @@ int CSMWorld::Resources::searchId (const std::string& id) const
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return iter->second;
|
return iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMWorld::UniversalId::Type CSMWorld::Resources::getType() const
|
||||||
|
{
|
||||||
|
return mType;
|
||||||
}
|
}
|
|
@ -5,6 +5,8 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "universalid.hpp"
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class Resources
|
class Resources
|
||||||
|
@ -12,10 +14,13 @@ namespace CSMWorld
|
||||||
std::map<std::string, int> mIndex;
|
std::map<std::string, int> mIndex;
|
||||||
std::vector<std::string> mFiles;
|
std::vector<std::string> mFiles;
|
||||||
std::string mBaseDirectory;
|
std::string mBaseDirectory;
|
||||||
|
UniversalId::Type mType;
|
||||||
|
|
||||||
public:
|
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;
|
int getSize() const;
|
||||||
|
|
||||||
|
@ -24,6 +29,8 @@ namespace CSMWorld
|
||||||
int getIndex (const std::string& id) const;
|
int getIndex (const std::string& id) const;
|
||||||
|
|
||||||
int searchId (const std::string& id) const;
|
int searchId (const std::string& id) const;
|
||||||
|
|
||||||
|
UniversalId::Type getType() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,21 @@
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
void CSMWorld::ResourcesManager::addResources (const Resources& resources)
|
||||||
|
{
|
||||||
|
mResources.insert (std::make_pair (resources.getType(), resources));
|
||||||
|
}
|
||||||
|
|
||||||
void CSMWorld::ResourcesManager::listResources()
|
void CSMWorld::ResourcesManager::listResources()
|
||||||
{
|
{
|
||||||
static const char * const sMeshTypes[] = { "nif", 0 };
|
static const char * const sMeshTypes[] = { "nif", 0 };
|
||||||
|
|
||||||
mResources.insert (
|
addResources (Resources ("meshes", UniversalId::Type_Mesh, sMeshTypes));
|
||||||
std::make_pair (UniversalId::Type_Mesh, Resources ("meshes", sMeshTypes)));
|
addResources (Resources ("icons", UniversalId::Type_Icon));
|
||||||
mResources.insert (std::make_pair (UniversalId::Type_Icon, "icons"));
|
addResources (Resources ("music", UniversalId::Type_Music));
|
||||||
mResources.insert (std::make_pair (UniversalId::Type_Music, "music"));
|
addResources (Resources ("sound", UniversalId::Type_SoundRes));
|
||||||
mResources.insert (std::make_pair (UniversalId::Type_SoundRes, "sound"));
|
addResources (Resources ("textures", UniversalId::Type_Texture));
|
||||||
mResources.insert (std::make_pair (UniversalId::Type_Texture, "textures"));
|
addResources (Resources ("videos", UniversalId::Type_Video));
|
||||||
mResources.insert (std::make_pair (UniversalId::Type_Video, "videos"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const CSMWorld::Resources& CSMWorld::ResourcesManager::get (UniversalId::Type type) const
|
const CSMWorld::Resources& CSMWorld::ResourcesManager::get (UniversalId::Type type) const
|
||||||
|
|
|
@ -12,6 +12,10 @@ namespace CSMWorld
|
||||||
{
|
{
|
||||||
std::map<UniversalId::Type, Resources> mResources;
|
std::map<UniversalId::Type, Resources> mResources;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void addResources (const Resources& resources);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Ask OGRE for a list of available resources.
|
/// Ask OGRE for a list of available resources.
|
||||||
|
|
|
@ -26,7 +26,7 @@ int CSMWorld::ResourceTable::columnCount (const QModelIndex & parent) const
|
||||||
if (parent.isValid())
|
if (parent.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 2; // ID, type
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CSMWorld::ResourceTable::data (const QModelIndex & index, int role) const
|
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)
|
if (role!=Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (index.column()!=0)
|
if (index.column()==0)
|
||||||
throw std::logic_error ("Invalid column in resource table");
|
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,
|
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)
|
if (orientation==Qt::Vertical)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (role==Qt::DisplayRole)
|
|
||||||
return "ID";
|
|
||||||
|
|
||||||
if (role==ColumnBase::Role_Flags)
|
if (role==ColumnBase::Role_Flags)
|
||||||
return ColumnBase::Flag_Table;
|
return ColumnBase::Flag_Table;
|
||||||
|
|
||||||
if (role==ColumnBase::Role_Display)
|
switch (section)
|
||||||
return ColumnBase::Display_String;
|
{
|
||||||
|
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();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -78,7 +100,7 @@ QModelIndex CSMWorld::ResourceTable::index (int row, int column, const QModelInd
|
||||||
if (row<0 || row>=mResources->getSize())
|
if (row<0 || row>=mResources->getSize())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
if (column!=0)
|
if (column<0 || column>1)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
return createIndex (row, column);
|
return createIndex (row, column);
|
||||||
|
@ -99,6 +121,9 @@ int CSMWorld::ResourceTable::searchColumnIndex (Columns::ColumnId id) const
|
||||||
if (id==Columns::ColumnId_Id)
|
if (id==Columns::ColumnId_Id)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (id==Columns::ColumnId_RecordType)
|
||||||
|
return 1;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue