Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit 15f67ef

Browse files
committed
add ios qml bindings
1 parent 8a2f382 commit 15f67ef

File tree

6 files changed

+62
-4
lines changed

6 files changed

+62
-4
lines changed

examples/datasync/AndroidSync/main.qml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Window {
1414
id: syncControl
1515
}
1616

17-
1817
ColumnLayout {
1918
anchors.centerIn: parent
2019

examples/datasync/IosSync/main.qml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@ import QtQuick 2.10
22
import QtQuick.Controls 2.4
33
import QtQuick.Layouts 1.3
44
import QtQuick.Window 2.10
5+
import de.skycoder42.QtDataSync 4.2
56

67
Window {
78
visible: true
89
width: 640
910
height: 480
1011
title: qsTr("Hello World")
1112

13+
property IosSyncDelegate syncDelegate: IosSyncSingleton.delegate
14+
1215
ColumnLayout {
1316
anchors.centerIn: parent
1417

1518
CheckBox {
1619
id: cBox
17-
text: qsTr("Background fetch enabled")
20+
checked: syncDelegate.enabled
21+
onCheckedChanged: syncDelegate.enabled = cBox.checked
22+
23+
text: qsTr("Background sync active")
1824
}
1925
}
2026
}

src/imports/datasync/datasync.pro

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
QT = core datasync qml
22
android: QT += datasyncandroid
3+
ios: QT += datasyncios
34

45
CXX_MODULE = datasync
56
TARGETPATH = de/skycoder42/QtDataSync
@@ -15,7 +16,7 @@ HEADERS += \
1516
qqmldatastoremodel.h \
1617
qqmluserexchangemanager.h \
1718
qtdatasync_plugin.h \
18-
qqmleventcursor.h
19+
qqmleventcursor.h
1920

2021
SOURCES += \
2122
qqmldatastore.cpp \
@@ -24,7 +25,12 @@ SOURCES += \
2425
qqmldatastoremodel.cpp \
2526
qqmluserexchangemanager.cpp \
2627
qtdatasync_plugin.cpp \
27-
qqmleventcursor.cpp
28+
qqmleventcursor.cpp
29+
30+
ios {
31+
HEADERS += qqmliossyncsingleton.h
32+
SOURCES += qqmliossyncsingleton.cpp
33+
}
2834

2935
OTHER_FILES += qmldir
3036

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "qqmliossyncsingleton.h"
2+
using namespace QtDataSync;
3+
4+
QQmlIosSyncSingleton::QQmlIosSyncSingleton(QObject *parent) :
5+
QObject{parent}
6+
{}
7+
8+
IosSyncDelegate *QQmlIosSyncSingleton::delegate() const
9+
{
10+
return IosSyncDelegate::currentDelegate();
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef QQMLIOSSYNCSINGLETON_H
2+
#define QQMLIOSSYNCSINGLETON_H
3+
4+
#include <QtCore/QObject>
5+
6+
#include <QtDataSyncIos/IosSyncDelegate>
7+
8+
namespace QtDataSync {
9+
10+
class QQmlIosSyncSingleton : public QObject
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
explicit QQmlIosSyncSingleton(QObject *parent = nullptr);
16+
17+
Q_INVOKABLE QtDataSync::IosSyncDelegate *delegate() const;
18+
};
19+
20+
}
21+
22+
#endif // QQMLIOSSYNCSINGLETON_H

src/imports/datasync/qtdatasync_plugin.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#ifdef Q_OS_ANDROID
66
#include <QtDataSyncAndroid/AndroidSyncControl>
77
#endif
8+
#ifdef Q_OS_IOS
9+
#include <QtDataSyncIos/IosSyncDelegate>
10+
#endif
811

912
#include "qqmldatastore.h"
1013
#include "qqmldatastoremodel.h"
@@ -20,6 +23,13 @@ QObject *createEventLogInstance(QQmlEngine *qmlEngine, QJSEngine *)
2023
return new QtDataSync::QQmlEventCursor{qmlEngine};
2124
}
2225

26+
#ifdef Q_OS_IOS
27+
QObject *createIosSyncSingletonInstance(QQmlEngine *qmlEngine, QJSEngine *)
28+
{
29+
return new QtDataSync::QQmlIosSyncSingleton{qmlEngine};
30+
}
31+
#endif
32+
2333
}
2434

2535
QtDataSyncDeclarativeModule::QtDataSyncDeclarativeModule(QObject *parent) :
@@ -50,6 +60,10 @@ void QtDataSyncDeclarativeModule::registerTypes(const char *uri)
5060
#ifdef Q_OS_ANDROID
5161
qmlRegisterType<QtDataSync::AndroidSyncControl>(uri, 4, 2, "AndroidSyncControl");
5262
#endif
63+
#ifdef Q_OS_IOS
64+
qmlRegisterUncreatableType<QtDataSync::IosSyncDelegate>(uri, 4, 2, "IosSyncDelegate", QStringLiteral("Use the IosSyncSingleton singleton to obtain the current IosSyncDelegate"));
65+
qmlRegisterSingletonType<QtDataSync::QQmlIosSyncSingleton>(uri, 4, 2, "IosSyncSingleton", createIosSyncSingletonInstance);
66+
#endif
5367

5468
// Check to make shure no module update is forgotten
5569
static_assert(VERSION_MAJOR == 4 && VERSION_MINOR == 2, "QML module version needs to be updated");

0 commit comments

Comments
 (0)