Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QSyncable::assign(QVariantMap&, QObject*) - Assign properties fro…
…m source object to the dest object
- Loading branch information
Showing
9 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
#include "qspatch.h" | ||
#include "qspatchable.h" | ||
#include "qsyncablefunctions.h" | ||
|
||
class QSDiffRunner | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <QMetaProperty> | ||
#include <QtQml> | ||
#include "qsyncablefunctions.h" | ||
|
||
void QSyncable::assign(QVariantMap &dest, const QObject *source) | ||
{ | ||
|
||
const QMetaObject* meta = source->metaObject(); | ||
|
||
for (int i = 0 ; i < meta->propertyCount(); i++) { | ||
const QMetaProperty property = meta->property(i); | ||
QVariant value = source->property(property.name()); | ||
|
||
if (value.canConvert<QObject*>()) { | ||
QVariantMap map; | ||
assign(map, value.value<QObject*>()); | ||
value = map; | ||
} | ||
|
||
dest[property.name()] = value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef QSYNCABLEFUNCTIONS_H | ||
#define QSYNCABLEFUNCTIONS_H | ||
|
||
#include <QObject> | ||
|
||
namespace QSyncable { | ||
|
||
/// Assign properties from source object to the destination objec | ||
void assign(QVariantMap& dest, | ||
const QObject* source); | ||
|
||
} | ||
|
||
#endif // QSYNCABLEFUNCTIONS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import QtQuick 2.0 | ||
|
||
QtObject { | ||
id: root | ||
objectName: "Root" | ||
|
||
property int value1 : 1 | ||
|
||
property string value2: "2" | ||
|
||
property bool value3 : true | ||
|
||
// Nested object | ||
property var value4: QtObject { | ||
property var value1 : 4 + 1 | ||
} | ||
|
||
} |