fix: editing non-string values causes crash
This commit is contained in:
parent
49066db8fb
commit
4ed32e44f0
|
@ -1,4 +1,5 @@
|
||||||
#include "propertiesmodel.h"
|
#include "propertiesmodel.h"
|
||||||
|
#include "datatypes/base.h"
|
||||||
#include "qnamespace.h"
|
#include "qnamespace.h"
|
||||||
|
|
||||||
PropertiesModel::PropertiesModel(InstanceRef selectedItem, QWidget *parent)
|
PropertiesModel::PropertiesModel(InstanceRef selectedItem, QWidget *parent)
|
||||||
|
@ -21,8 +22,9 @@ QVariant PropertiesModel::data(const QModelIndex &index, int role) const {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
if (index.column() == 0)
|
if (index.column() == 0)
|
||||||
return QString::fromStdString(propertyName);
|
return QString::fromStdString(propertyName);
|
||||||
else if (index.column() == 1)
|
else if (index.column() == 1) {
|
||||||
return QString::fromStdString(selectedItem->GetPropertyValue(propertyName).value().ToString());
|
return QString::fromStdString(selectedItem->GetPropertyValue(propertyName).value().ToString());
|
||||||
|
}
|
||||||
// case Qt::DecorationRole:
|
// case Qt::DecorationRole:
|
||||||
// return iconOf(item->GetClass());
|
// return iconOf(item->GetClass());
|
||||||
}
|
}
|
||||||
|
@ -33,8 +35,12 @@ QVariant PropertiesModel::data(const QModelIndex &index, int role) const {
|
||||||
bool PropertiesModel::setData(const QModelIndex &index, const QVariant &value, int role) {
|
bool PropertiesModel::setData(const QModelIndex &index, const QVariant &value, int role) {
|
||||||
if (index.column() != 1 && role != Qt::EditRole) return false;
|
if (index.column() != 1 && role != Qt::EditRole) return false;
|
||||||
|
|
||||||
selectedItem->SetPropertyValue(propertiesList[index.row()], value.toString().toStdString());
|
if (selectedItem->GetPropertyMeta(propertiesList[index.row()])->type == &Data::String::TYPE) {
|
||||||
return true;
|
selectedItem->SetPropertyValue(propertiesList[index.row()], value.toString().toStdString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags PropertiesModel::flags(const QModelIndex &index) const {
|
Qt::ItemFlags PropertiesModel::flags(const QModelIndex &index) const {
|
||||||
|
|
|
@ -18,6 +18,7 @@ public: \
|
||||||
namespace Data {
|
namespace Data {
|
||||||
struct TypeInfo {
|
struct TypeInfo {
|
||||||
std::string name;
|
std::string name;
|
||||||
|
TypeInfo(const TypeInfo&) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
class String;
|
class String;
|
||||||
|
|
|
@ -30,7 +30,7 @@ Instance::Instance(InstanceType* type) {
|
||||||
this->memberMap = std::make_unique<MemberMap>( MemberMap {
|
this->memberMap = std::make_unique<MemberMap>( MemberMap {
|
||||||
.super = std::nullopt,
|
.super = std::nullopt,
|
||||||
.members = {
|
.members = {
|
||||||
{ "Name", { .backingField = &name, .codec = fieldCodecOf<Data::String, std::string>() } }
|
{ "Name", { .backingField = &name, .type = &Data::String::TYPE, .codec = fieldCodecOf<Data::String, std::string>() } }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ constexpr FieldCodec fieldCodecOf() {
|
||||||
|
|
||||||
struct PropertyMeta {
|
struct PropertyMeta {
|
||||||
void* backingField;
|
void* backingField;
|
||||||
Data::TypeInfo type;
|
const Data::TypeInfo* type;
|
||||||
FieldCodec codec;
|
FieldCodec codec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,11 @@ Part::Part(): Part(PartConstructParams {}) {
|
||||||
|
|
||||||
Part::Part(PartConstructParams params): Instance(&TYPE_), position(params.position), rotation(params.rotation),
|
Part::Part(PartConstructParams params): Instance(&TYPE_), position(params.position), rotation(params.rotation),
|
||||||
scale(params.scale), material(params.material), anchored(params.anchored) {
|
scale(params.scale), material(params.material), anchored(params.anchored) {
|
||||||
|
|
||||||
this->memberMap = std::make_unique<MemberMap>(MemberMap {
|
this->memberMap = std::make_unique<MemberMap>(MemberMap {
|
||||||
.super = std::move(this->memberMap),
|
.super = std::move(this->memberMap),
|
||||||
.members = {
|
.members = {
|
||||||
{ "Anchored", { .backingField = &anchored, .codec = fieldCodecOf<Data::Bool, bool>() } }
|
{ "Anchored", { .backingField = &anchored, .type = &Data::Bool::TYPE, .codec = fieldCodecOf<Data::Bool, bool>() } }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue