mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-10 09:02:26 +02:00
Added null pointer check for asQuickItem()
This commit is contained in:
parent
72137f52f7
commit
1e8d032ea3
1 changed files with 47 additions and 13 deletions
|
@ -167,11 +167,19 @@ void QmlWindowClass::qmlToScript(const QVariant& message) {
|
|||
|
||||
void QmlWindowClass::sendToQml(const QVariant& message) {
|
||||
// Forward messages received from the script on to QML
|
||||
QMetaObject::invokeMethod(asQuickItem(), "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||
if (asQuickItem()) {
|
||||
QMetaObject::invokeMethod(asQuickItem(), "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||
} else {
|
||||
qDebug() << "QmlWindowClass::sendToQml: asQuickItem() returned NULL";
|
||||
}
|
||||
}
|
||||
|
||||
void QmlWindowClass::clearDebugWindow() {
|
||||
QMetaObject::invokeMethod(asQuickItem(), "clearDebugWindow", Qt::QueuedConnection);
|
||||
if (asQuickItem()) {
|
||||
QMetaObject::invokeMethod(asQuickItem(), "clearDebugWindow", Qt::QueuedConnection);
|
||||
} else {
|
||||
qDebug() << "QmlWindowClass::clearDebugWindow: asQuickItem() returned NULL";
|
||||
}
|
||||
}
|
||||
|
||||
void QmlWindowClass::emitScriptEvent(const QVariant& scriptMessage) {
|
||||
|
@ -192,9 +200,17 @@ void QmlWindowClass::emitWebEvent(const QVariant& webMessage) {
|
|||
const QString LOWER_KEYBOARD = "_LOWER_KEYBOARD";
|
||||
QString messageString = webMessage.type() == QVariant::String ? webMessage.toString() : "";
|
||||
if (messageString.left(RAISE_KEYBOARD.length()) == RAISE_KEYBOARD) {
|
||||
setKeyboardRaised(asQuickItem(), true, messageString == RAISE_KEYBOARD_NUMERIC);
|
||||
if (asQuickItem()) {
|
||||
setKeyboardRaised(asQuickItem(), true, messageString == RAISE_KEYBOARD_NUMERIC);
|
||||
} else {
|
||||
qDebug() << "QmlWindowClass::emitWebEvent: asQuickItem() returned NULL";
|
||||
}
|
||||
} else if (messageString == LOWER_KEYBOARD) {
|
||||
setKeyboardRaised(asQuickItem(), false);
|
||||
if (asQuickItem()) {
|
||||
setKeyboardRaised(asQuickItem(), false);
|
||||
} else {
|
||||
qDebug() << "QmlWindowClass::emitWebEvent: asQuickItem() returned NULL";
|
||||
}
|
||||
} else {
|
||||
emit webEventReceived(webMessage);
|
||||
}
|
||||
|
@ -234,7 +250,12 @@ void QmlWindowClass::setVisible(bool visible) {
|
|||
}
|
||||
|
||||
QQuickItem* targetWindow = asQuickItem();
|
||||
targetWindow->setProperty(OFFSCREEN_VISIBILITY_PROPERTY, visible);
|
||||
//TODO: all asQuickItem() need to be guarded like this
|
||||
if (targetWindow) {
|
||||
targetWindow->setProperty(OFFSCREEN_VISIBILITY_PROPERTY, visible);
|
||||
} else {
|
||||
qDebug() << "QmlWindowClass::setVisible: asQuickItem() returned NULL";
|
||||
}
|
||||
}
|
||||
|
||||
bool QmlWindowClass::isVisible() {
|
||||
|
@ -249,7 +270,11 @@ bool QmlWindowClass::isVisible() {
|
|||
return false;
|
||||
}
|
||||
|
||||
return asQuickItem()->isVisible();
|
||||
if (asQuickItem()) {
|
||||
return asQuickItem()->isVisible();
|
||||
} else {
|
||||
qDebug() << "QmlWindowClass::isVisible: asQuickItem() returned NULL";
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec2 QmlWindowClass::getPosition() {
|
||||
|
@ -263,17 +288,21 @@ glm::vec2 QmlWindowClass::getPosition() {
|
|||
return {};
|
||||
}
|
||||
|
||||
return toGlm(asQuickItem()->position());
|
||||
if (asQuickItem()) {
|
||||
return toGlm(asQuickItem()->position());
|
||||
} else {
|
||||
qDebug() << "QmlWindowClass::getPosition: asQuickItem() returned NULL";
|
||||
return glm::vec2(0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QmlWindowClass::setPosition(const glm::vec2& position) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "setPosition", Q_ARG(const glm::vec2&, position));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_qmlWindow.isNull()) {
|
||||
if (asQuickItem()) {
|
||||
asQuickItem()->setPosition(QPointF(position.x, position.y));
|
||||
}
|
||||
}
|
||||
|
@ -298,7 +327,12 @@ glm::vec2 QmlWindowClass::getSize() {
|
|||
return {};
|
||||
}
|
||||
QQuickItem* targetWindow = asQuickItem();
|
||||
return vec2(targetWindow->width(), targetWindow->height());
|
||||
if (targetWindow) {
|
||||
return vec2(targetWindow->width(), targetWindow->height());
|
||||
} else {
|
||||
qDebug() << "QmlWindowClass::getSize: asQuickItem() returned NULL";
|
||||
return vec2(0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void QmlWindowClass::setSize(const glm::vec2& size) {
|
||||
|
@ -307,7 +341,7 @@ void QmlWindowClass::setSize(const glm::vec2& size) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!_qmlWindow.isNull()) {
|
||||
if (asQuickItem()) {
|
||||
asQuickItem()->setSize(QSizeF(size.x, size.y));
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +356,7 @@ void QmlWindowClass::setTitle(const QString& title) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!_qmlWindow.isNull()) {
|
||||
if (asQuickItem()) {
|
||||
asQuickItem()->setProperty(TITLE_PROPERTY, title);
|
||||
}
|
||||
}
|
||||
|
@ -353,7 +387,7 @@ void QmlWindowClass::raise() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (_qmlWindow) {
|
||||
if (asQuickItem()) {
|
||||
QMetaObject::invokeMethod(asQuickItem(), "raise", Qt::DirectConnection);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue