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