Files
PrimeWorldEditor/src/Editor/WorldEditor/CLayerModel.cpp
Lioncache b2bd0cd326 General: Update to Qt6
Migrate over to Qt 6 so that we can keep the UI toolkit pegged at the
current major version.

Unfortunately this also means we have to gut a small feature in the
progress dialogs, since the extras module doesn't exist in Qt6 anymore.

Few things of note:

QVector<> is internally an alias of QList now, so any changeover is due
to that to make the semantics a little clearer.

QtConcurrent requires arguments to be swapped on some invocations, and
discarding instances need to use the global thread pool instead.

fromStdList(), etc can be replaced with range constructors.

--no-angle and other commands are removed from newer versions of
windeployqt

QVariant::Invalid (and other type IDs) are deprecated and also break
existing functionality. Instead we can return default constructed
QVariants where applicable, which restores functionality that would be
broken if left as is (e.g. many list would straight up not populate or
have wonky size hinting).

The reason for this is that the QVariant(QVariant::Type) constructor
models a unique kind of internal QVariant state where it's considered
to be in an invalid state, but accessing the (supposedly) invalid state
will instead return a default constructed value of the internal type.

This kinda sucks because this means genuinely invalid states that would
warrant an assertion or other type of error would be silently ignored
and execution would continue on as normal, so this also enforces
correctness a little bit (on top of, well, fixing all the broken UI
controls).
2025-11-29 19:54:35 -05:00

43 lines
1001 B
C++

#include "CLayerModel.h"
#include "Editor/UICommon.h"
#include <Core/Resource/Script/CScriptLayer.h>
CLayerModel::CLayerModel(QObject *pParent)
: QAbstractListModel(pParent)
{
}
CLayerModel::~CLayerModel() = default;
int CLayerModel::rowCount(const QModelIndex& /*parent*/) const
{
return mpArea ? static_cast<int>(mpArea->NumScriptLayers()) : 0;
}
QVariant CLayerModel::data(const QModelIndex &index, int role) const
{
if (mpArea && (role == Qt::DisplayRole) && (index.row() < rowCount(QModelIndex())))
return TO_QSTRING(Layer(index)->Name());
return QVariant();
}
void CLayerModel::SetArea(CGameArea *pArea)
{
mpArea = pArea;
emit layoutChanged();
}
CScriptLayer* CLayerModel::Layer(const QModelIndex& index) const
{
if (!mpArea)
return nullptr;
const size_t NumLayers = mpArea->NumScriptLayers();
if (index.row() < static_cast<int>(NumLayers))
return mpArea->ScriptLayer(static_cast<size_t>(index.row()));
return nullptr;
}