diff --git a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.cpp b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.cpp index a2a21625..7da4cd3b 100644 --- a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.cpp +++ b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.cpp @@ -31,6 +31,11 @@ bool NetTypeArrayFacade::isFixed() return false; } +bool NetTypeArrayFacade::isReadOnly() +{ + return false; +} + uint NetTypeArrayFacade::getLength(const QSharedPointer&) { return 0; diff --git a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.h b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.h index f4aba7f7..c193344f 100644 --- a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.h +++ b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacade.h @@ -15,6 +15,7 @@ public: virtual ~NetTypeArrayFacade() {} static QSharedPointer fromType(const QSharedPointer& type); virtual bool isFixed(); + virtual bool isReadOnly(); virtual uint getLength(const QSharedPointer& reference); virtual QSharedPointer getIndexed(const QSharedPointer& reference, uint index); virtual void setIndexed(const QSharedPointer& reference, uint index, const QSharedPointer& value); diff --git a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeList.cpp b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeList.cpp index c64daa18..93c1162f 100644 --- a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeList.cpp +++ b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeList.cpp @@ -5,9 +5,11 @@ #include #include #include +#include NetTypeArrayFacade_List::NetTypeArrayFacade_List(const QSharedPointer& type) : - _isIncomplete(false) + _isIncomplete(false), + _isReadOnly(false) { for(int x = 0; x < type->getPropertyCount(); x++) { QSharedPointer property = type->getProperty(x); @@ -18,22 +20,30 @@ NetTypeArrayFacade_List::NetTypeArrayFacade_List(const QSharedPointergetLocalMethodCount(); x++) { - QSharedPointer method = type->getLocalMethodInfo(x); - if(method->getMethodName().compare("RemoveAt") == 0) { - _removeAtMethod = method; - } else if(method->getMethodName().compare("Add") == 0) { - _addMethod = method; - } - } - if(_lengthProperty == nullptr || - _itemProperty == nullptr || - _removeAtMethod == nullptr || - _addMethod == nullptr) { + _itemProperty == nullptr) { _isIncomplete = true; return; } + + if(!_itemProperty->canWrite()) { + _isReadOnly = true; + } else { + for(int x = 0; x < type->getLocalMethodCount(); x++) { + QSharedPointer method = type->getLocalMethodInfo(x); + if(method->getMethodName().compare("RemoveAt") == 0) { + _removeAtMethod = method; + } else if(method->getMethodName().compare("Add") == 0) { + _addMethod = method; + } + } + + if(_removeAtMethod == nullptr || + _addMethod == nullptr) { + _isIncomplete = true; + return; + } + } } bool NetTypeArrayFacade_List::isIncomplete() @@ -43,7 +53,12 @@ bool NetTypeArrayFacade_List::isIncomplete() bool NetTypeArrayFacade_List::isFixed() { - return false; + return _isReadOnly; +} + +bool NetTypeArrayFacade_List::isReadOnly() +{ + return _isReadOnly; } uint NetTypeArrayFacade_List::getLength(const QSharedPointer& reference) @@ -64,6 +79,11 @@ QSharedPointer NetTypeArrayFacade_List::getIndexed(const QSharedPoin void NetTypeArrayFacade_List::setIndexed(const QSharedPointer& reference, uint index, const QSharedPointer& value) { + if(_isReadOnly) { + qWarning() << "Can't modify a readonly .NET list."; + return; + } + QSharedPointer indexParameter = QSharedPointer(new NetVariant()); indexParameter->setInt(qint32(index)); QmlNet::writeProperty(_itemProperty, reference, indexParameter, value); @@ -71,6 +91,11 @@ void NetTypeArrayFacade_List::setIndexed(const QSharedPointer& ref void NetTypeArrayFacade_List::push(const QSharedPointer& reference, const QSharedPointer& value) { + if(_isReadOnly) { + qWarning() << "Can't modify a readonly .NET list."; + return; + } + QSharedPointer parameters = QSharedPointer(new NetVariantList()); parameters->add(value); QmlNet::invokeNetMethod(_addMethod, reference, parameters, nullptr); @@ -78,6 +103,11 @@ void NetTypeArrayFacade_List::push(const QSharedPointer& reference QSharedPointer NetTypeArrayFacade_List::pop(const QSharedPointer& reference) { + if(_isReadOnly) { + qWarning() << "Can't modify a readonly .NET list."; + return nullptr; + } + uint length = getLength(reference); QSharedPointer item = getIndexed(reference, length - 1); deleteAt(reference, length - 1); @@ -86,6 +116,11 @@ QSharedPointer NetTypeArrayFacade_List::pop(const QSharedPointer& reference, uint index) { + if(_isReadOnly) { + qWarning() << "Can't modify a readonly .NET list."; + return; + } + QSharedPointer parameters = QSharedPointer(new NetVariantList()); QSharedPointer parameter = QSharedPointer(new NetVariant()); parameter->setInt(static_cast(index)); diff --git a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeList.h b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeList.h index d8e7ef27..406bce99 100644 --- a/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeList.h +++ b/src/native/QmlNet/QmlNet/types/NetTypeArrayFacadeList.h @@ -12,6 +12,7 @@ public: NetTypeArrayFacade_List(const QSharedPointer& type); bool isIncomplete(); bool isFixed() override; + bool isReadOnly() override; uint getLength(const QSharedPointer& reference) override; QSharedPointer getIndexed(const QSharedPointer& reference, uint index) override; void setIndexed(const QSharedPointer& reference, uint index, const QSharedPointer& value) override; @@ -20,6 +21,7 @@ public: void deleteAt(const QSharedPointer& reference, uint index) override; private: bool _isIncomplete; + bool _isReadOnly; QSharedPointer _lengthProperty; QSharedPointer _itemProperty; QSharedPointer _removeAtMethod;