Browse Source

Code improvements

- Cleanup deprecated using from AbstractCredentials
- Make generated list properties writable
Alexey Edelev 5 years ago
parent
commit
f537945f20

BIN
examples/addressbook/images/arrow.png


+ 5 - 0
examples/addressbook/qml/CountryCodesModel.qml

@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Item {
+
+}

+ 5 - 0
examples/addressbook/qml/DropDownColumn.qml

@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Item {
+
+}

+ 5 - 0
examples/addressbook/qml/InputRow.qml

@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Item {
+
+}

+ 5 - 0
examples/addressbook/qml/PhoneInput.qml

@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Item {
+
+}

+ 0 - 1
src/grpc/abstractcredentials.h

@@ -67,7 +67,6 @@ protected:
     void setChannelCredentials(const CredentialMap& credentialMap) { mChannelCredentials = credentialMap; }
 
 private:
-    using CredentialsFunction = std::function<CredentialMap(void)>;
     CredentialMap mCallCredentials;
     CredentialMap mChannelCredentials;
 };

+ 11 - 5
src/protobuf/qprotobufobject_p.h

@@ -28,7 +28,8 @@
 #include <QObject>
 #include <QSharedPointer>
 #include <QMetaProperty>
-#include <QtQml/QQmlListProperty>
+#include <QQmlListProperty>
+#include <QQmlEngine>
 
 #include <unordered_map>
 #include <memory>
@@ -288,6 +289,10 @@ public:
 
         QByteArray serializedList;
         for (auto &value : listValue) {
+            if (!value) {
+                qProtoWarning() << "Null pointer in list";
+                continue;
+            }
             QByteArray serializedValue = serializeLengthDelimited(value->serialize());
             serializedValue.prepend(encodeHeaderByte(outFieldIndex, LengthDelimited));
             serializedList.append(serializedValue);
@@ -669,8 +674,9 @@ public:
     //###########################################################################
 
     template<typename T>
-    static void qmllistpropertyAppend(QQmlListProperty<T> *, T *) {
-        Q_ASSERT_X(false, "", "Access to append functionality of protobuf lists is restricted");
+    static void qmllistpropertyAppend(QQmlListProperty<T> *p, T *v) {
+        QQmlEngine::setObjectOwnership(v, QQmlEngine::CppOwnership);
+        reinterpret_cast<QList<QSharedPointer<T>> *>(p->data)->append(QSharedPointer<T>(v));
     }
 
     template<typename T>
@@ -684,8 +690,8 @@ public:
     }
 
     template<typename T>
-    static void qmllistpropertyReset(QQmlListProperty<T> *){
-        Q_ASSERT_X(false, "", "Access to reset functionality of protobuf lists is restricted");
+    static void qmllistpropertyReset(QQmlListProperty<T> *p){
+        reinterpret_cast<QList<QSharedPointer<T>> *>(p->data)->clear();
     }
 
     template<typename T>