CWorldTreeModel: Tidy up warnings
This commit is contained in:
parent
32041a843d
commit
9c8749d5b0
|
@ -6,6 +6,8 @@
|
|||
#include <Core/GameProject/CResourceIterator.h>
|
||||
#include <QIcon>
|
||||
|
||||
#include <memory>
|
||||
|
||||
CWorldTreeModel::CWorldTreeModel(CWorldEditor *pEditor)
|
||||
{
|
||||
connect(gpEdApp, &CEditorApplication::ActiveProjectChanged, this, &CWorldTreeModel::OnProjectChanged);
|
||||
|
@ -14,9 +16,13 @@ CWorldTreeModel::CWorldTreeModel(CWorldEditor *pEditor)
|
|||
|
||||
int CWorldTreeModel::rowCount(const QModelIndex& rkParent) const
|
||||
{
|
||||
if (!rkParent.isValid()) return mWorldList.size();
|
||||
else if (IndexIsWorld(rkParent)) return mWorldList[rkParent.row()].Areas.size();
|
||||
else return 0;
|
||||
if (!rkParent.isValid())
|
||||
return mWorldList.size();
|
||||
|
||||
if (IndexIsWorld(rkParent))
|
||||
return mWorldList[rkParent.row()].Areas.size();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CWorldTreeModel::columnCount(const QModelIndex&) const
|
||||
|
@ -34,16 +40,15 @@ QModelIndex CWorldTreeModel::index(int Row, int Column, const QModelIndex& rkPar
|
|||
return createIndex(Row, Column, quint64((Row << 16) | 0xFFFF));
|
||||
|
||||
// Area
|
||||
else
|
||||
return createIndex(Row, Column, quint64((rkParent.row() << 16) | (Row & 0xFFFF)) );
|
||||
return createIndex(Row, Column, quint64((rkParent.row() << 16) | (Row & 0xFFFF)) );
|
||||
}
|
||||
|
||||
QModelIndex CWorldTreeModel::parent(const QModelIndex& rkChild) const
|
||||
{
|
||||
if (IndexIsWorld(rkChild))
|
||||
return QModelIndex();
|
||||
else
|
||||
return createIndex((rkChild.internalId() >> 16) & 0xFFFF, 0, rkChild.internalId() | 0xFFFF);
|
||||
|
||||
return createIndex((rkChild.internalId() >> 16) & 0xFFFF, 0, rkChild.internalId() | 0xFFFF);
|
||||
}
|
||||
|
||||
QVariant CWorldTreeModel::data(const QModelIndex& rkIndex, int Role) const
|
||||
|
@ -59,31 +64,26 @@ QVariant CWorldTreeModel::data(const QModelIndex& rkIndex, int Role) const
|
|||
// are often missing, confusing, or just straight-up inaccurate, which makes the internal name a better
|
||||
// means of telling worlds apart.
|
||||
// For DKCR worlds, we only display the world name in the first column.
|
||||
uint32 InternalNameCol = (gpEdApp->ActiveProject()->Game() >= EGame::Corruption ? 0 : 1);
|
||||
const int InternalNameCol = (gpEdApp->ActiveProject()->Game() >= EGame::Corruption ? 0 : 1);
|
||||
|
||||
// Internal name
|
||||
if (rkIndex.column() == InternalNameCol)
|
||||
return rkInfo.WorldName;
|
||||
|
||||
// In-Game name
|
||||
else
|
||||
{
|
||||
if (rkInfo.pWorld)
|
||||
return TO_QSTRING( rkInfo.pWorld->InGameName() );
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
if (rkInfo.pWorld != nullptr)
|
||||
return TO_QSTRING(rkInfo.pWorld->InGameName());
|
||||
|
||||
// Area
|
||||
else
|
||||
return QString{};
|
||||
}
|
||||
else // Area
|
||||
{
|
||||
CWorld *pWorld = WorldForIndex(rkIndex);
|
||||
int AreaIndex = AreaIndexForIndex(rkIndex);
|
||||
const CWorld *pWorld = WorldForIndex(rkIndex);
|
||||
const int AreaIndex = AreaIndexForIndex(rkIndex);
|
||||
ASSERT(pWorld);
|
||||
|
||||
TString AreaInternalName = pWorld->AreaInternalName(AreaIndex);
|
||||
TString AreaInGameName = (gpEdApp->ActiveProject()->Game() == EGame::DKCReturns ? pWorld->InGameName() : pWorld->AreaInGameName( AreaIndexForIndex(rkIndex) ));
|
||||
const TString AreaInternalName = pWorld->AreaInternalName(AreaIndex);
|
||||
const TString AreaInGameName = (gpEdApp->ActiveProject()->Game() == EGame::DKCReturns ? pWorld->InGameName() : pWorld->AreaInGameName(AreaIndexForIndex(rkIndex)));
|
||||
|
||||
// Return name
|
||||
if (rkIndex.column() == 1)
|
||||
|
@ -93,7 +93,7 @@ QVariant CWorldTreeModel::data(const QModelIndex& rkIndex, int Role) const
|
|||
}
|
||||
}
|
||||
|
||||
else if (Role == Qt::DecorationRole)
|
||||
if (Role == Qt::DecorationRole)
|
||||
{
|
||||
static const QIcon sWorldIcon = QIcon(QStringLiteral(":/icons/World_16px.svg"));
|
||||
static const QIcon sAreaIcon = QIcon(QStringLiteral(":/icons/New_16px.svg"));
|
||||
|
@ -106,7 +106,7 @@ QVariant CWorldTreeModel::data(const QModelIndex& rkIndex, int Role) const
|
|||
return sAreaIcon;
|
||||
}
|
||||
|
||||
else if (Role == Qt::FontRole)
|
||||
if (Role == Qt::FontRole)
|
||||
{
|
||||
QFont Font;
|
||||
int PointSize = Font.pointSize() + 2;
|
||||
|
@ -116,14 +116,12 @@ QVariant CWorldTreeModel::data(const QModelIndex& rkIndex, int Role) const
|
|||
PointSize += 1;
|
||||
|
||||
const SWorldInfo& rkInfo = WorldInfoForIndex(rkIndex);
|
||||
CWorld *pActiveWorld = gpEdApp->WorldEditor()->ActiveWorld();
|
||||
|
||||
if (pActiveWorld)
|
||||
if (CWorld* pActiveWorld = gpEdApp->WorldEditor()->ActiveWorld())
|
||||
{
|
||||
EGame Game = gpEdApp->ActiveProject()->Game();
|
||||
|
||||
bool IsActiveWorld = (Game <= EGame::Corruption && rkInfo.pWorld == pActiveWorld) ||
|
||||
(Game == EGame::DKCReturns && rkInfo.Areas.contains(pActiveWorld->Entry()));
|
||||
const EGame Game = gpEdApp->ActiveProject()->Game();
|
||||
const bool IsActiveWorld = (Game <= EGame::Corruption && rkInfo.pWorld == pActiveWorld) ||
|
||||
(Game == EGame::DKCReturns && rkInfo.Areas.contains(pActiveWorld->Entry()));
|
||||
|
||||
if (IsActiveWorld)
|
||||
Font.setBold(true);
|
||||
|
@ -131,9 +129,9 @@ QVariant CWorldTreeModel::data(const QModelIndex& rkIndex, int Role) const
|
|||
}
|
||||
else
|
||||
{
|
||||
CResourceEntry *pEntry = AreaEntryForIndex(rkIndex);
|
||||
const CResourceEntry *pEntry = AreaEntryForIndex(rkIndex);
|
||||
|
||||
if (pEntry && pEntry->IsLoaded())
|
||||
if (pEntry != nullptr && pEntry->IsLoaded())
|
||||
{
|
||||
if (gpEdApp->WorldEditor()->ActiveArea() == pEntry->Resource())
|
||||
Font.setBold(true);
|
||||
|
@ -163,8 +161,8 @@ QVariant CWorldTreeModel::headerData(int Section, Qt::Orientation Orientation, i
|
|||
|
||||
bool CWorldTreeModel::IndexIsWorld(const QModelIndex& rkIndex) const
|
||||
{
|
||||
int AreaIndex = (int) rkIndex.internalId() & 0xFFFF;
|
||||
return (AreaIndex == 0xFFFF);
|
||||
const auto AreaIndex = static_cast<int>(rkIndex.internalId()) & 0xFFFF;
|
||||
return AreaIndex == 0xFFFF;
|
||||
}
|
||||
|
||||
int CWorldTreeModel::AreaIndexForIndex(const QModelIndex& rkIndex) const
|
||||
|
@ -172,11 +170,8 @@ int CWorldTreeModel::AreaIndexForIndex(const QModelIndex& rkIndex) const
|
|||
if (gpEdApp->ActiveProject()->Game() == EGame::DKCReturns)
|
||||
return 0;
|
||||
|
||||
else
|
||||
{
|
||||
int InternalID = (int) rkIndex.internalId();
|
||||
return (InternalID & 0xFFFF);
|
||||
}
|
||||
const auto InternalID = static_cast<int>(rkIndex.internalId());
|
||||
return InternalID & 0xFFFF;
|
||||
}
|
||||
|
||||
CWorld* CWorldTreeModel::WorldForIndex(const QModelIndex& rkIndex) const
|
||||
|
@ -186,28 +181,31 @@ CWorld* CWorldTreeModel::WorldForIndex(const QModelIndex& rkIndex) const
|
|||
|
||||
if (gpEdApp->ActiveProject()->Game() == EGame::DKCReturns && !IndexIsWorld(rkIndex))
|
||||
{
|
||||
int AreaIndex = (int) rkIndex.internalId() & 0xFFFF;
|
||||
const auto AreaIndex = static_cast<int>(rkIndex.internalId() & 0xFFFF);
|
||||
CResourceEntry *pEntry = rkInfo.Areas[AreaIndex];
|
||||
return pEntry ? (CWorld*) pEntry->Load() : nullptr;
|
||||
return pEntry != nullptr ? static_cast<CWorld*>(pEntry->Load()) : nullptr;
|
||||
}
|
||||
else
|
||||
return rkInfo.pWorld;
|
||||
|
||||
return rkInfo.pWorld;
|
||||
}
|
||||
|
||||
CResourceEntry* CWorldTreeModel::AreaEntryForIndex(const QModelIndex& rkIndex) const
|
||||
{
|
||||
ASSERT(rkIndex.isValid() && !IndexIsWorld(rkIndex));
|
||||
CWorld *pWorld = WorldForIndex(rkIndex);
|
||||
int AreaIndex = AreaIndexForIndex(rkIndex);
|
||||
|
||||
CAssetID AreaID;
|
||||
if (pWorld) AreaID = pWorld->AreaResourceID(AreaIndex);
|
||||
if (const CWorld* pWorld = WorldForIndex(rkIndex))
|
||||
{
|
||||
const int AreaIndex = AreaIndexForIndex(rkIndex);
|
||||
AreaID = pWorld->AreaResourceID(AreaIndex);
|
||||
}
|
||||
|
||||
return gpResourceStore->FindEntry(AreaID);
|
||||
}
|
||||
|
||||
const CWorldTreeModel::SWorldInfo& CWorldTreeModel::WorldInfoForIndex(const QModelIndex& rkIndex) const
|
||||
{
|
||||
int WorldIndex = ((int) rkIndex.internalId() >> 16) & 0xFFFF;
|
||||
const int WorldIndex = (static_cast<int>(rkIndex.internalId()) >> 16) & 0xFFFF;
|
||||
return mWorldList[WorldIndex];
|
||||
}
|
||||
|
||||
|
@ -217,7 +215,7 @@ void CWorldTreeModel::OnProjectChanged(CGameProject *pProj)
|
|||
beginResetModel();
|
||||
mWorldList.clear();
|
||||
|
||||
if (pProj)
|
||||
if (pProj != nullptr)
|
||||
{
|
||||
if (pProj->Game() != EGame::DKCReturns)
|
||||
{
|
||||
|
@ -228,13 +226,11 @@ void CWorldTreeModel::OnProjectChanged(CGameProject *pProj)
|
|||
|
||||
for (const CAssetID& rkID : QWorldIDs)
|
||||
{
|
||||
CResourceEntry *pEntry = pProj->ResourceStore()->FindEntry(rkID);
|
||||
|
||||
if (pEntry)
|
||||
if (CResourceEntry* pEntry = pProj->ResourceStore()->FindEntry(rkID))
|
||||
{
|
||||
TResPtr<CWorld> pWorld = pEntry->Load();
|
||||
|
||||
if (pWorld)
|
||||
if (pWorld != nullptr)
|
||||
{
|
||||
SWorldInfo Info;
|
||||
Info.WorldName = TO_QSTRING( pWorld->Name() );
|
||||
|
@ -262,23 +258,21 @@ void CWorldTreeModel::OnProjectChanged(CGameProject *pProj)
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
// DKCR - Get worlds from areas.lst
|
||||
else
|
||||
else // DKCR - Get worlds from areas.lst
|
||||
{
|
||||
TString AreaListPath = pProj->DiscFilesystemRoot(false) + "areas.lst";
|
||||
|
||||
// I really need a good text stream class at some point
|
||||
FILE* pAreaList = fopen(*AreaListPath, "r");
|
||||
using FILEPtr = std::unique_ptr<FILE, decltype(&std::fclose)>;
|
||||
FILEPtr pAreaList{std::fopen(*AreaListPath, "r"), std::fclose};
|
||||
SWorldInfo *pInfo = nullptr;
|
||||
std::set<CAssetID> UsedWorlds;
|
||||
|
||||
while (!feof(pAreaList))
|
||||
while (!std::feof(pAreaList.get()))
|
||||
{
|
||||
char LineBuffer[256];
|
||||
memset(LineBuffer, 0, 256);
|
||||
fgets(LineBuffer, 256, pAreaList);
|
||||
TString Line(LineBuffer);
|
||||
char LineBuffer[256] = {};
|
||||
std::fgets(LineBuffer, sizeof(LineBuffer), pAreaList.get());
|
||||
const TString Line(LineBuffer);
|
||||
|
||||
CAssetID WorldID;
|
||||
TString WorldName;
|
||||
|
@ -287,13 +281,13 @@ void CWorldTreeModel::OnProjectChanged(CGameProject *pProj)
|
|||
if (IDSplit != -1)
|
||||
{
|
||||
// Get world ID
|
||||
TString IDString = (IDSplit == -1 ? "" : Line.SubString(2, IDSplit - 2));
|
||||
const TString IDString = (IDSplit == -1 ? "" : Line.SubString(2, IDSplit - 2));
|
||||
WorldID = CAssetID::FromString(IDString);
|
||||
|
||||
// Get world name
|
||||
TString WorldPath = (IDSplit == -1 ? "" : Line.SubString(IDSplit + 1, Line.Size() - IDSplit - 1));
|
||||
uint32 UnderscoreIdx = WorldPath.IndexOf('_');
|
||||
uint32 WorldDirEnd = WorldPath.IndexOf("\\/", UnderscoreIdx);
|
||||
const TString WorldPath = (IDSplit == -1 ? "" : Line.SubString(IDSplit + 1, Line.Size() - IDSplit - 1));
|
||||
const uint32 UnderscoreIdx = WorldPath.IndexOf('_');
|
||||
const uint32 WorldDirEnd = WorldPath.IndexOf("\\/", UnderscoreIdx);
|
||||
|
||||
if (UnderscoreIdx != -1 && WorldDirEnd != -1)
|
||||
WorldName = WorldPath.SubString(UnderscoreIdx + 1, WorldDirEnd - UnderscoreIdx - 1);
|
||||
|
@ -301,9 +295,7 @@ void CWorldTreeModel::OnProjectChanged(CGameProject *pProj)
|
|||
|
||||
if (WorldID.IsValid() && !WorldName.IsEmpty())
|
||||
{
|
||||
CResourceEntry *pEntry = gpResourceStore->FindEntry(WorldID);
|
||||
|
||||
if (pEntry)
|
||||
if (CResourceEntry* pEntry = gpResourceStore->FindEntry(WorldID))
|
||||
{
|
||||
QString WorldNameQ = TO_QSTRING(WorldName);
|
||||
|
||||
|
@ -319,10 +311,10 @@ void CWorldTreeModel::OnProjectChanged(CGameProject *pProj)
|
|||
}
|
||||
}
|
||||
}
|
||||
fclose(pAreaList);
|
||||
pAreaList.reset();
|
||||
|
||||
// Add remaining worlds to FrontEnd world
|
||||
mWorldList.prepend( SWorldInfo() );
|
||||
mWorldList.prepend(SWorldInfo());
|
||||
pInfo = &mWorldList.front();
|
||||
pInfo->WorldName = "FrontEnd";
|
||||
|
||||
|
@ -333,11 +325,10 @@ void CWorldTreeModel::OnProjectChanged(CGameProject *pProj)
|
|||
}
|
||||
|
||||
// Sort FrontEnd world
|
||||
std::sort( pInfo->Areas.begin(), pInfo->Areas.end(), [](CResourceEntry *pA, CResourceEntry *pB) -> bool {
|
||||
std::sort( pInfo->Areas.begin(), pInfo->Areas.end(), [](const CResourceEntry *pA, const CResourceEntry *pB) {
|
||||
return pA->UppercaseName() < pB->UppercaseName();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
|
@ -347,25 +338,25 @@ void CWorldTreeModel::OnMapChanged()
|
|||
{
|
||||
// Flag all data as changed to ensure the font updates correctly based on which areas are loaded
|
||||
// note we don't know which areas used to be loaded, so flagging those specific indices isn't an option
|
||||
int MaxRow = rowCount(QModelIndex()) - 1;
|
||||
int MaxCol = columnCount(QModelIndex()) - 1;
|
||||
const int MaxRow = rowCount(QModelIndex()) - 1;
|
||||
const int MaxCol = columnCount(QModelIndex()) - 1;
|
||||
emit dataChanged(index(0, 0, QModelIndex()), index(MaxRow, MaxCol, QModelIndex()));
|
||||
}
|
||||
|
||||
// ************ PROXY MODEL ************
|
||||
bool CWorldTreeProxyModel::lessThan(const QModelIndex& rkSourceLeft, const QModelIndex& rkSourceRight) const
|
||||
{
|
||||
CWorldTreeModel *pModel = qobject_cast<CWorldTreeModel*>(sourceModel());
|
||||
const CWorldTreeModel *pModel = qobject_cast<CWorldTreeModel*>(sourceModel());
|
||||
ASSERT(pModel != nullptr);
|
||||
|
||||
if (pModel->IndexIsWorld(rkSourceLeft))
|
||||
{
|
||||
ASSERT(pModel->IndexIsWorld(rkSourceRight));
|
||||
bool IsLessThan = (rkSourceLeft.row() < rkSourceRight.row());
|
||||
const bool IsLessThan = (rkSourceLeft.row() < rkSourceRight.row());
|
||||
return (sortOrder() == Qt::AscendingOrder ? IsLessThan : !IsLessThan);
|
||||
}
|
||||
else
|
||||
return pModel->data(rkSourceLeft, Qt::DisplayRole).toString().toUpper() < pModel->data(rkSourceRight, Qt::DisplayRole).toString().toUpper();
|
||||
|
||||
return pModel->data(rkSourceLeft, Qt::DisplayRole).toString().toUpper() < pModel->data(rkSourceRight, Qt::DisplayRole).toString().toUpper();
|
||||
}
|
||||
|
||||
bool CWorldTreeProxyModel::filterAcceptsRow(int SourceRow, const QModelIndex& rkSourceParent) const
|
||||
|
@ -374,12 +365,12 @@ bool CWorldTreeProxyModel::filterAcceptsRow(int SourceRow, const QModelIndex& rk
|
|||
if (!rkSourceParent.isValid() || mFilterString.isEmpty())
|
||||
return true;
|
||||
|
||||
CWorldTreeModel *pModel = qobject_cast<CWorldTreeModel*>(sourceModel());
|
||||
const CWorldTreeModel *pModel = qobject_cast<CWorldTreeModel*>(sourceModel());
|
||||
ASSERT(pModel != nullptr);
|
||||
|
||||
for (int iCol = 0; iCol < pModel->columnCount(rkSourceParent); iCol++)
|
||||
{
|
||||
QModelIndex Index = pModel->index(SourceRow, iCol, rkSourceParent);
|
||||
const QModelIndex Index = pModel->index(SourceRow, iCol, rkSourceParent);
|
||||
if (pModel->data(Index, Qt::DisplayRole).toString().contains(mFilterString, Qt::CaseInsensitive))
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue