From 5fb2a587b6547f197a01a938b74cdb721f116ada Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 14 May 2017 03:07:21 +0200 Subject: [PATCH] Handle NULL / nil in toOF() / toQt() --- src/QtCore/QtChildEvent.h | 3 +++ src/QtCore/QtCoreApplication.h | 3 +++ src/QtCore/QtEvent.h | 3 +++ src/QtCore/QtObject.h | 3 +++ src/QtCore/QtThread.h | 3 +++ src/QtGui/QtGUIApplication.h | 3 +++ src/QtWidgets/QtAbstractButton.h | 3 +++ src/QtWidgets/QtAction.h | 3 +++ src/QtWidgets/QtApplication.h | 3 +++ src/QtWidgets/QtPushButton.h | 3 +++ src/QtWidgets/QtWidget.h | 3 +++ src/common/OFDataArray+QByteArray.h | 6 ++++++ src/common/OFString+QString.h | 6 ++++++ src/common/helpers.h | 6 +++--- 14 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/QtCore/QtChildEvent.h b/src/QtCore/QtChildEvent.h index 5951ad6..8ccabff 100644 --- a/src/QtCore/QtChildEvent.h +++ b/src/QtCore/QtChildEvent.h @@ -42,6 +42,9 @@ namespace ObjQt { static OF_INLINE QtChildEvent * toOF(QChildEvent *qChildEvent) { + if (qChildEvent == NULL) + return nil; + return [[[QtChildEvent alloc] initWithQChildEvent: qChildEvent] autorelease]; } diff --git a/src/QtCore/QtCoreApplication.h b/src/QtCore/QtCoreApplication.h index 250e7e0..81b6666 100644 --- a/src/QtCore/QtCoreApplication.h +++ b/src/QtCore/QtCoreApplication.h @@ -45,6 +45,9 @@ namespace ObjQt { static OF_INLINE QtCoreApplication * toOF(QCoreApplication *qCoreApplication) { + if (qCoreApplication == NULL) + return nil; + return [[[QtCoreApplication alloc] initWithQCoreApplication: qCoreApplication] autorelease]; } diff --git a/src/QtCore/QtEvent.h b/src/QtCore/QtEvent.h index 7b6c18e..165a7de 100644 --- a/src/QtCore/QtEvent.h +++ b/src/QtCore/QtEvent.h @@ -49,6 +49,9 @@ namespace ObjQt { static OF_INLINE QtEvent * toOF(QEvent *qEvent) { + if (qEvent == NULL) + return nil; + return [[[QtEvent alloc] initWithQEvent: qEvent] autorelease]; } diff --git a/src/QtCore/QtObject.h b/src/QtCore/QtObject.h index f7296f1..80800f4 100644 --- a/src/QtCore/QtObject.h +++ b/src/QtCore/QtObject.h @@ -87,6 +87,9 @@ namespace ObjQt { static OF_INLINE QtObject * toOF(QObject *qObject) { + if (qObject == NULL) + return nil; + return [[[QtObject alloc] initWithQObject: qObject] autorelease]; } diff --git a/src/QtCore/QtThread.h b/src/QtCore/QtThread.h index 5c00093..4343b12 100644 --- a/src/QtCore/QtThread.h +++ b/src/QtCore/QtThread.h @@ -50,6 +50,9 @@ namespace ObjQt { static OF_INLINE QtThread * toOF(QThread *qThread) { + if (qThread == NULL) + return nil; + return [[[QtThread alloc] initWithQThread: qThread] autorelease]; } diff --git a/src/QtGui/QtGUIApplication.h b/src/QtGui/QtGUIApplication.h index df5057e..ca60268 100644 --- a/src/QtGui/QtGUIApplication.h +++ b/src/QtGui/QtGUIApplication.h @@ -51,6 +51,9 @@ namespace ObjQt { static OF_INLINE QtGUIApplication * toOF(QGuiApplication *qGuiApplication) { + if (qGuiApplication == NULL) + return nil; + return [[[QtGUIApplication alloc] initWithQGuiApplication: qGuiApplication] autorelease]; } diff --git a/src/QtWidgets/QtAbstractButton.h b/src/QtWidgets/QtAbstractButton.h index 91f8b05..d9ed12c 100644 --- a/src/QtWidgets/QtAbstractButton.h +++ b/src/QtWidgets/QtAbstractButton.h @@ -49,6 +49,9 @@ namespace ObjQt { static OF_INLINE QtAbstractButton * toOF(QAbstractButton *qAbstractButton) { + if (qAbstractButton == NULL) + return nil; + return [[[QtAbstractButton alloc] initWithQAbstractButton: qAbstractButton] autorelease]; } diff --git a/src/QtWidgets/QtAction.h b/src/QtWidgets/QtAction.h index 36e5d25..7c54a07 100644 --- a/src/QtWidgets/QtAction.h +++ b/src/QtWidgets/QtAction.h @@ -71,6 +71,9 @@ namespace ObjQt { static OF_INLINE QtAction * toOF(QAction *qAction) { + if (qAction == NULL) + return nil; + return [[[QtAction alloc] initWithQAction: qAction] autorelease]; } diff --git a/src/QtWidgets/QtApplication.h b/src/QtWidgets/QtApplication.h index 39f571f..f4beb8a 100644 --- a/src/QtWidgets/QtApplication.h +++ b/src/QtWidgets/QtApplication.h @@ -47,6 +47,9 @@ namespace ObjQt { static OF_INLINE QtApplication * toOF(QApplication *qApplication) { + if (qApplication == NULL) + return nil; + return [[[QtApplication alloc] initWithQApplication: qApplication] autorelease]; } diff --git a/src/QtWidgets/QtPushButton.h b/src/QtWidgets/QtPushButton.h index e189dc5..1a2e29b 100644 --- a/src/QtWidgets/QtPushButton.h +++ b/src/QtWidgets/QtPushButton.h @@ -45,6 +45,9 @@ namespace ObjQt { static OF_INLINE QtPushButton * toOF(QPushButton *qPushButton) { + if (qPushButton == NULL) + return nil; + return [[[QtPushButton alloc] initWithQPushButton: qPushButton] autorelease]; } diff --git a/src/QtWidgets/QtWidget.h b/src/QtWidgets/QtWidget.h index 2375f36..14b5622 100644 --- a/src/QtWidgets/QtWidget.h +++ b/src/QtWidgets/QtWidget.h @@ -229,6 +229,9 @@ namespace ObjQt { static OF_INLINE QtWidget * toOF(QWidget *qWidget) { + if (qWidget == NULL) + return nil; + return [[[QtWidget alloc] initWithQWidget: qWidget] autorelease]; } diff --git a/src/common/OFDataArray+QByteArray.h b/src/common/OFDataArray+QByteArray.h index 0ac0815..946419b 100644 --- a/src/common/OFDataArray+QByteArray.h +++ b/src/common/OFDataArray+QByteArray.h @@ -34,12 +34,18 @@ namespace ObjQt { static OF_INLINE OFDataArray * toOF(const QByteArray &qByteArray) { + if (qByteArray.isNull()) + return nil; + return [OFDataArray dataArrayWithQByteArray: qByteArray]; } static OF_INLINE QByteArray toQt(OFDataArray *dataArray) { + if (dataArray == nil) + return QByteArray(); + return [dataArray qByteArray]; } diff --git a/src/common/OFString+QString.h b/src/common/OFString+QString.h index 147e0f5..1236d38 100644 --- a/src/common/OFString+QString.h +++ b/src/common/OFString+QString.h @@ -35,12 +35,18 @@ namespace ObjQt { static OF_INLINE OFString * toOF(const QString &qString) { + if (qString.isNull()) + return nil; + return [OFString stringWithQString: qString]; } static OF_INLINE QString toQt(OFString *string) { + if (string == nil) + return QString(); + return [string qString]; } diff --git a/src/common/helpers.h b/src/common/helpers.h index b7a2a85..aef7ee2 100644 --- a/src/common/helpers.h +++ b/src/common/helpers.h @@ -41,7 +41,7 @@ toOF(const QPoint &qPoint) } static OF_INLINE QPoint -toQt(of_point_t point) +toQt(const of_point_t &point) { return QPoint(point.x, point.y); } @@ -53,7 +53,7 @@ toOF(const QSize &qSize) } static OF_INLINE QSize -toQt(of_dimension_t dimension) +toQt(const of_dimension_t &dimension) { return QSize(dimension.width, dimension.height); } @@ -66,7 +66,7 @@ toOF(const QRect &qRect) } static OF_INLINE QRect -toQt(of_rectangle_t rectangle) +toQt(const of_rectangle_t &rectangle) { return QRect(rectangle.origin.x, rectangle.origin.y, rectangle.size.width, rectangle.size.height);