Improve QVariant usage

pull/3236/head
Andrei Kortunov 5 months ago
parent a9281b5246
commit 54271b872c

@ -30,7 +30,7 @@ opencs_units (model/world
)
opencs_hdrs (model/world
columnimp idcollection collection info subcellcollection
columnimp disabletag idcollection collection info subcellcollection
)

@ -13,6 +13,7 @@
#include <components/platform/platform.hpp>
#include "model/doc/messages.hpp"
#include "model/world/disabletag.hpp"
#include "model/world/universalid.hpp"
#ifdef Q_OS_MAC
@ -53,6 +54,7 @@ int runApplication(int argc, char* argv[])
qRegisterMetaType<std::string>("std::string");
qRegisterMetaType<CSMWorld::UniversalId>("CSMWorld::UniversalId");
qRegisterMetaType<CSMWorld::DisableTag>("CSMWorld::DisableTag");
qRegisterMetaType<CSMDoc::Message>("CSMDoc::Message");
setQSurfaceFormat();

@ -2,6 +2,7 @@
#include <apps/opencs/model/world/columnbase.hpp>
#include <apps/opencs/model/world/columns.hpp>
#include <apps/opencs/model/world/disabletag.hpp>
#include <apps/opencs/model/world/land.hpp>
#include <apps/opencs/model/world/record.hpp>
@ -283,7 +284,8 @@ namespace CSMWorld
{
return QString::fromUtf8(record.get().mRace.getRefIdString().c_str());
}
return QVariant(QVariant::UserType);
return DisableTag::getVariant();
}
void BodyPartRaceColumn::set(Record<ESM::BodyPart>& record, const QVariant& data)

@ -0,0 +1,22 @@
#ifndef CSM_WOLRD_DISABLETAG_H
#define CSM_WOLRD_DISABLETAG_H
#include <QVariant>
namespace CSMWorld
{
class DisableTag
{
public:
static QVariant getVariant() { return QVariant::fromValue(CSMWorld::DisableTag()); }
static bool isDisableTag(const QVariant& variant)
{
return strcmp(variant.typeName(), "CSMWorld::DisableTag") == 0;
}
};
}
Q_DECLARE_METATYPE(CSMWorld::DisableTag)
#endif

@ -7,6 +7,7 @@
#include <variant>
#include <apps/opencs/model/world/cell.hpp>
#include <apps/opencs/model/world/disabletag.hpp>
#include <apps/opencs/model/world/nestedtablewrapper.hpp>
#include <apps/opencs/model/world/record.hpp>
@ -892,24 +893,24 @@ namespace CSMWorld
// While the ambient information is not necessarily valid if the subrecord wasn't loaded,
// the user should still be allowed to edit it
case 1:
return (isInterior && !behaveLikeExterior) ? cell.mAmbi.mAmbient : QVariant(QVariant::UserType);
return (isInterior && !behaveLikeExterior) ? cell.mAmbi.mAmbient : DisableTag::getVariant();
case 2:
return (isInterior && !behaveLikeExterior) ? cell.mAmbi.mSunlight : QVariant(QVariant::UserType);
return (isInterior && !behaveLikeExterior) ? cell.mAmbi.mSunlight : DisableTag::getVariant();
case 3:
return (isInterior && !behaveLikeExterior) ? cell.mAmbi.mFog : QVariant(QVariant::UserType);
return (isInterior && !behaveLikeExterior) ? cell.mAmbi.mFog : DisableTag::getVariant();
case 4:
return (isInterior && !behaveLikeExterior) ? cell.mAmbi.mFogDensity : QVariant(QVariant::UserType);
return (isInterior && !behaveLikeExterior) ? cell.mAmbi.mFogDensity : DisableTag::getVariant();
case 5:
{
if (isInterior && interiorWater)
return cell.mWater;
else
return QVariant(QVariant::UserType);
return DisableTag::getVariant();
}
case 6:
return isInterior ? QVariant(QVariant::UserType) : cell.mMapColor; // TODO: how to select?
return isInterior ? DisableTag::getVariant() : cell.mMapColor; // TODO: how to select?
// case 7: return isInterior ?
// behaveLikeExterior : QVariant(QVariant::UserType);
// behaveLikeExterior : DisableTag::getVariant();
default:
throw std::runtime_error("Cell subcolumn index out of range");
}

@ -3,6 +3,7 @@
#include <stdexcept>
#include <apps/opencs/model/world/columnbase.hpp>
#include <apps/opencs/model/world/disabletag.hpp>
#include <apps/opencs/model/world/record.hpp>
#include <apps/opencs/model/world/refiddata.hpp>
#include <apps/opencs/model/world/universalid.hpp>
@ -1117,11 +1118,11 @@ QVariant CSMWorld::NpcMiscRefIdAdapter::getNestedData(
case 0:
return static_cast<int>(record.get().mNpdt.mLevel);
case 1:
return QVariant(QVariant::UserType);
return CSMWorld::DisableTag::getVariant();
case 2:
return QVariant(QVariant::UserType);
return CSMWorld::DisableTag::getVariant();
case 3:
return QVariant(QVariant::UserType);
return CSMWorld::DisableTag::getVariant();
case 4:
return static_cast<int>(record.get().mNpdt.mDisposition);
case 5:

@ -30,6 +30,7 @@
#include <apps/opencs/model/prefs/setting.hpp>
#include <apps/opencs/model/world/commanddispatcher.hpp>
#include <apps/opencs/model/world/data.hpp>
#include <apps/opencs/model/world/disabletag.hpp>
#include <apps/opencs/model/world/idtablebase.hpp>
#include <apps/opencs/model/world/universalid.hpp>
#include <apps/opencs/view/doc/subview.hpp>
@ -655,7 +656,7 @@ void CSVWorld::EditWidget::remake(int row)
++unlocked;
}
if (mTable->index(row, i).data().type() == QVariant::UserType)
if (CSMWorld::DisableTag::isDisableTag(mTable->index(row, i).data()))
{
editor->setEnabled(false);
label->setEnabled(false);
@ -705,7 +706,7 @@ void CSVWorld::EditWidget::remake(int row)
unlockedLayout->addWidget(editor, unlocked, 1);
++unlocked;
if (tree->index(0, col, tree->index(row, i)).data().type() == QVariant::UserType)
if (CSMWorld::DisableTag::isDisableTag(tree->index(0, col, tree->index(row, i)).data()))
{
editor->setEnabled(false);
label->setEnabled(false);

Loading…
Cancel
Save