mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-15 14:15:54 -06:00
Support for wrapping read only lists.
This commit is contained in:
parent
45f4196da0
commit
7837ab167e
4 changed files with 57 additions and 14 deletions
|
|
@ -31,6 +31,11 @@ bool NetTypeArrayFacade::isFixed()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool NetTypeArrayFacade::isReadOnly()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
uint NetTypeArrayFacade::getLength(const QSharedPointer<NetReference>&)
|
||||
{
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public:
|
|||
virtual ~NetTypeArrayFacade() {}
|
||||
static QSharedPointer<NetTypeArrayFacade> fromType(const QSharedPointer<NetTypeInfo>& type);
|
||||
virtual bool isFixed();
|
||||
virtual bool isReadOnly();
|
||||
virtual uint getLength(const QSharedPointer<NetReference>& reference);
|
||||
virtual QSharedPointer<NetVariant> getIndexed(const QSharedPointer<NetReference>& reference, uint index);
|
||||
virtual void setIndexed(const QSharedPointer<NetReference>& reference, uint index, const QSharedPointer<NetVariant>& value);
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@
|
|||
#include <QmlNet/qml/NetVariant.h>
|
||||
#include <QmlNet/qml/NetVariantList.h>
|
||||
#include <QmlNet/types/Callbacks.h>
|
||||
#include <QDebug>
|
||||
|
||||
NetTypeArrayFacade_List::NetTypeArrayFacade_List(const QSharedPointer<NetTypeInfo>& type) :
|
||||
_isIncomplete(false)
|
||||
_isIncomplete(false),
|
||||
_isReadOnly(false)
|
||||
{
|
||||
for(int x = 0; x < type->getPropertyCount(); x++) {
|
||||
QSharedPointer<NetPropertyInfo> property = type->getProperty(x);
|
||||
|
|
@ -18,22 +20,30 @@ NetTypeArrayFacade_List::NetTypeArrayFacade_List(const QSharedPointer<NetTypeInf
|
|||
}
|
||||
}
|
||||
|
||||
for(int x = 0; x < type->getLocalMethodCount(); x++) {
|
||||
QSharedPointer<NetMethodInfo> 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<NetMethodInfo> 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<NetReference>& reference)
|
||||
|
|
@ -64,6 +79,11 @@ QSharedPointer<NetVariant> NetTypeArrayFacade_List::getIndexed(const QSharedPoin
|
|||
|
||||
void NetTypeArrayFacade_List::setIndexed(const QSharedPointer<NetReference>& reference, uint index, const QSharedPointer<NetVariant>& value)
|
||||
{
|
||||
if(_isReadOnly) {
|
||||
qWarning() << "Can't modify a readonly .NET list.";
|
||||
return;
|
||||
}
|
||||
|
||||
QSharedPointer<NetVariant> indexParameter = QSharedPointer<NetVariant>(new NetVariant());
|
||||
indexParameter->setInt(qint32(index));
|
||||
QmlNet::writeProperty(_itemProperty, reference, indexParameter, value);
|
||||
|
|
@ -71,6 +91,11 @@ void NetTypeArrayFacade_List::setIndexed(const QSharedPointer<NetReference>& ref
|
|||
|
||||
void NetTypeArrayFacade_List::push(const QSharedPointer<NetReference>& reference, const QSharedPointer<NetVariant>& value)
|
||||
{
|
||||
if(_isReadOnly) {
|
||||
qWarning() << "Can't modify a readonly .NET list.";
|
||||
return;
|
||||
}
|
||||
|
||||
QSharedPointer<NetVariantList> parameters = QSharedPointer<NetVariantList>(new NetVariantList());
|
||||
parameters->add(value);
|
||||
QmlNet::invokeNetMethod(_addMethod, reference, parameters, nullptr);
|
||||
|
|
@ -78,6 +103,11 @@ void NetTypeArrayFacade_List::push(const QSharedPointer<NetReference>& reference
|
|||
|
||||
QSharedPointer<NetVariant> NetTypeArrayFacade_List::pop(const QSharedPointer<NetReference>& reference)
|
||||
{
|
||||
if(_isReadOnly) {
|
||||
qWarning() << "Can't modify a readonly .NET list.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint length = getLength(reference);
|
||||
QSharedPointer<NetVariant> item = getIndexed(reference, length - 1);
|
||||
deleteAt(reference, length - 1);
|
||||
|
|
@ -86,6 +116,11 @@ QSharedPointer<NetVariant> NetTypeArrayFacade_List::pop(const QSharedPointer<Net
|
|||
|
||||
void NetTypeArrayFacade_List::deleteAt(const QSharedPointer<NetReference>& reference, uint index)
|
||||
{
|
||||
if(_isReadOnly) {
|
||||
qWarning() << "Can't modify a readonly .NET list.";
|
||||
return;
|
||||
}
|
||||
|
||||
QSharedPointer<NetVariantList> parameters = QSharedPointer<NetVariantList>(new NetVariantList());
|
||||
QSharedPointer<NetVariant> parameter = QSharedPointer<NetVariant>(new NetVariant());
|
||||
parameter->setInt(static_cast<int>(index));
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public:
|
|||
NetTypeArrayFacade_List(const QSharedPointer<NetTypeInfo>& type);
|
||||
bool isIncomplete();
|
||||
bool isFixed() override;
|
||||
bool isReadOnly() override;
|
||||
uint getLength(const QSharedPointer<NetReference>& reference) override;
|
||||
QSharedPointer<NetVariant> getIndexed(const QSharedPointer<NetReference>& reference, uint index) override;
|
||||
void setIndexed(const QSharedPointer<NetReference>& reference, uint index, const QSharedPointer<NetVariant>& value) override;
|
||||
|
|
@ -20,6 +21,7 @@ public:
|
|||
void deleteAt(const QSharedPointer<NetReference>& reference, uint index) override;
|
||||
private:
|
||||
bool _isIncomplete;
|
||||
bool _isReadOnly;
|
||||
QSharedPointer<NetPropertyInfo> _lengthProperty;
|
||||
QSharedPointer<NetPropertyInfo> _itemProperty;
|
||||
QSharedPointer<NetMethodInfo> _removeAtMethod;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue