CVirtualDirectory: Make use of size_t where applicable

This commit is contained in:
Lioncash 2020-07-05 10:31:43 -04:00
parent a8e51f86d7
commit 05df1fcf89
5 changed files with 35 additions and 31 deletions

View File

@ -49,7 +49,7 @@ void RecursiveGetListOfEmptyDirectories(CVirtualDirectory *pDir, TStringList& rO
}
else
{
for (uint32 SubIdx = 0; SubIdx < pDir->NumSubdirectories(); SubIdx++)
for (size_t SubIdx = 0; SubIdx < pDir->NumSubdirectories(); SubIdx++)
RecursiveGetListOfEmptyDirectories(pDir->SubdirectoryByIndex(SubIdx), rOutList);
}
}

View File

@ -52,12 +52,12 @@ public:
bool IsRoot() const { return !mpParent; }
TString Name() const { return mName; }
uint32 NumSubdirectories() const { return mSubdirectories.size(); }
CVirtualDirectory* SubdirectoryByIndex(uint32 Index) { return mSubdirectories[Index]; }
const CVirtualDirectory* SubdirectoryByIndex(uint32 Index) const { return mSubdirectories[Index]; }
uint32 NumResources() const { return mResources.size(); }
CResourceEntry* ResourceByIndex(uint32 Index) { return mResources[Index]; }
const CResourceEntry* ResourceByIndex(uint32 Index) const { return mResources[Index]; }
size_t NumSubdirectories() const { return mSubdirectories.size(); }
CVirtualDirectory* SubdirectoryByIndex(size_t Index) { return mSubdirectories[Index]; }
const CVirtualDirectory* SubdirectoryByIndex(size_t Index) const { return mSubdirectories[Index]; }
size_t NumResources() const { return mResources.size(); }
CResourceEntry* ResourceByIndex(size_t Index) { return mResources[Index]; }
const CResourceEntry* ResourceByIndex(size_t Index) const { return mResources[Index]; }
};
#endif // CVIRTUALDIRECTORY

View File

@ -700,14 +700,14 @@ bool CResourceBrowser::Delete(QVector<CResourceEntry*> Resources, QVector<CVirtu
for (int DirIdx = 0; DirIdx < Directories.size(); DirIdx++)
{
CVirtualDirectory* pDir = Directories[DirIdx];
Resources.reserve( Resources.size() + pDir->NumResources() );
Directories.reserve( Directories.size() + pDir->NumSubdirectories() );
Resources.reserve(Resources.size() + static_cast<int>(pDir->NumResources()));
Directories.reserve(Directories.size() + static_cast<int>(pDir->NumSubdirectories()));
for (uint ResourceIdx = 0; ResourceIdx < pDir->NumResources(); ResourceIdx++)
Resources << pDir->ResourceByIndex(ResourceIdx);
for (size_t ResourceIdx = 0; ResourceIdx < pDir->NumResources(); ResourceIdx++)
Resources.push_back(pDir->ResourceByIndex(ResourceIdx));
for (uint SubdirIdx = 0; SubdirIdx < pDir->NumSubdirectories(); SubdirIdx++)
Directories << pDir->SubdirectoryByIndex(SubdirIdx);
for (size_t SubdirIdx = 0; SubdirIdx < pDir->NumSubdirectories(); SubdirIdx++)
Directories.push_back(pDir->SubdirectoryByIndex(SubdirIdx));
}
// Exit if we have nothing to do.

View File

@ -219,12 +219,12 @@ void CResourceTableModel::FillEntryList(CVirtualDirectory *pDir, bool AssetListM
if (!mIsAssetListMode)
{
if (!pDir->IsRoot())
mDirectories << pDir->Parent();
mDirectories.push_back(pDir->Parent());
for (uint32 iDir = 0; iDir < pDir->NumSubdirectories(); iDir++)
mDirectories << pDir->SubdirectoryByIndex(iDir);
for (size_t iDir = 0; iDir < pDir->NumSubdirectories(); iDir++)
mDirectories.push_back(pDir->SubdirectoryByIndex(iDir));
for (uint32 iRes = 0; iRes < pDir->NumResources(); iRes++)
for (size_t iRes = 0; iRes < pDir->NumResources(); iRes++)
{
CResourceEntry *pEntry = pDir->ResourceByIndex(iRes);
@ -235,10 +235,11 @@ void CResourceTableModel::FillEntryList(CVirtualDirectory *pDir, bool AssetListM
}
}
}
// In asset list mode, do not show subdirectories and show all assets in current directory + all subdirectories.
else
{
RecursiveAddDirectoryContents(pDir);
}
}
if (pDir)
@ -262,7 +263,7 @@ void CResourceTableModel::DisplayEntryList(QList<CResourceEntry*>& rkEntries, co
void CResourceTableModel::RecursiveAddDirectoryContents(CVirtualDirectory *pDir)
{
for (uint32 iRes = 0; iRes < pDir->NumResources(); iRes++)
for (size_t iRes = 0; iRes < pDir->NumResources(); iRes++)
{
CResourceEntry *pEntry = pDir->ResourceByIndex(iRes);
@ -273,7 +274,7 @@ void CResourceTableModel::RecursiveAddDirectoryContents(CVirtualDirectory *pDir)
}
}
for (uint32 iDir = 0; iDir < pDir->NumSubdirectories(); iDir++)
for (size_t iDir = 0; iDir < pDir->NumSubdirectories(); iDir++)
RecursiveAddDirectoryContents(pDir->SubdirectoryByIndex(iDir));
}

View File

@ -22,10 +22,10 @@ QModelIndex CVirtualDirectoryModel::index(int Row, int Column, const QModelIndex
CVirtualDirectory *pDir = IndexDirectory(rkParent);
if (pDir && pDir->NumSubdirectories() > (uint32) Row)
if (pDir != nullptr && pDir->NumSubdirectories() > static_cast<uint32>(Row))
return createIndex(Row, Column, pDir->SubdirectoryByIndex(Row));
else if (!pDir)
if (pDir == nullptr)
return createIndex(Row, Column, mpRoot);
return QModelIndex();
@ -42,14 +42,16 @@ QModelIndex CVirtualDirectoryModel::parent(const QModelIndex& rkChild) const
if (pGrandparent)
{
for (uint32 iSub = 0; iSub < pGrandparent->NumSubdirectories(); iSub++)
for (size_t iSub = 0; iSub < pGrandparent->NumSubdirectories(); iSub++)
{
if (pGrandparent->SubdirectoryByIndex(iSub) == pParent)
return createIndex(iSub, 0, pParent);
return createIndex(static_cast<int>(iSub), 0, pParent);
}
}
else return createIndex(0, 0, mpRoot);
else
{
return createIndex(0, 0, mpRoot);
}
}
return QModelIndex();
@ -57,9 +59,10 @@ QModelIndex CVirtualDirectoryModel::parent(const QModelIndex& rkChild) const
int CVirtualDirectoryModel::rowCount(const QModelIndex& rkParent) const
{
CVirtualDirectory *pDir = IndexDirectory(rkParent);
if (pDir) return pDir->NumSubdirectories();
else return mpRoot ? 1 : 0;
if (const CVirtualDirectory* pDir = IndexDirectory(rkParent))
return static_cast<int>(pDir->NumSubdirectories());
return mpRoot ? 1 : 0;
}
int CVirtualDirectoryModel::columnCount(const QModelIndex&) const
@ -201,11 +204,11 @@ QModelIndex CVirtualDirectoryModel::GetIndexForDirectory(CVirtualDirectory *pDir
{
bool Found = false;
for (uint32 iDir = 0; iDir < pParent->NumSubdirectories(); iDir++)
for (size_t iDir = 0; iDir < pParent->NumSubdirectories(); iDir++)
{
if (pParent->SubdirectoryByIndex(iDir) == pDir)
{
Indices.push_front(iDir);
Indices.push_front(static_cast<int>(iDir));
pDir = pParent;
pParent = pParent->Parent();
Found = true;