qml: Fix warnings about dereferencing null types
This commit is contained in:
@@ -53,6 +53,7 @@ DockWidgetModel *FrameQuick::dockWidgetModel() const
|
||||
void FrameQuick::removeWidget_impl(DockWidgetBase *dw)
|
||||
{
|
||||
m_dockWidgetModel->remove(dw);
|
||||
disconnect(m_connections.take(dw));
|
||||
}
|
||||
|
||||
void FrameQuick::detachTab_impl(DockWidgetBase *)
|
||||
@@ -93,6 +94,13 @@ void FrameQuick::insertDockWidget_impl(DockWidgetBase *dw, int index)
|
||||
if (m_dockWidgetModel->insert(dw, index)) {
|
||||
dw->setParent(m_stackLayout);
|
||||
|
||||
QMetaObject::Connection conn = connect(dw, &DockWidgetBase::parentChanged, this, [dw, this] {
|
||||
if (dw->parent() != m_stackLayout)
|
||||
removeWidget_impl(dw);
|
||||
});
|
||||
|
||||
m_connections[dw] = conn;
|
||||
|
||||
if (!m_currentDockWidget)
|
||||
m_currentDockWidget = dw;
|
||||
}
|
||||
@@ -191,8 +199,9 @@ void DockWidgetModel::remove(DockWidgetBase *dw)
|
||||
if (row == -1) {
|
||||
qWarning() << Q_FUNC_INFO << "Nothing to remove" << dw;
|
||||
} else {
|
||||
disconnect(m_connections.value(dw));
|
||||
m_connections.remove(dw);
|
||||
const auto connections = m_connections.take(dw);
|
||||
for (QMetaObject::Connection conn : connections)
|
||||
disconnect(conn);
|
||||
|
||||
beginRemoveRows(QModelIndex(), row, row);
|
||||
m_dockWidgets.removeOne(dw);
|
||||
@@ -214,11 +223,11 @@ bool DockWidgetModel::insert(DockWidgetBase *dw, int index)
|
||||
return false;
|
||||
}
|
||||
|
||||
QMetaObject::Connection c = connect(dw, &DockWidgetBase::titleChanged, this, [dw, this] {
|
||||
QMetaObject::Connection conn = connect(dw, &DockWidgetBase::titleChanged, this, [dw, this] {
|
||||
emitDataChangedFor(dw);
|
||||
});
|
||||
|
||||
m_connections.insert(dw, c);
|
||||
m_connections[dw] = { conn };
|
||||
|
||||
beginInsertRows(QModelIndex(), index, index);
|
||||
m_dockWidgets.insert(index, dw);
|
||||
|
||||
@@ -53,6 +53,7 @@ private:
|
||||
QQuickItem *m_stackLayout = nullptr;
|
||||
DockWidgetBase *m_currentDockWidget = nullptr;
|
||||
DockWidgetModel *const m_dockWidgetModel;
|
||||
QHash<DockWidgetBase *, QMetaObject::Connection> m_connections; // To make it easy to disconnect from lambdas
|
||||
};
|
||||
|
||||
class DockWidgetModel : public QAbstractListModel
|
||||
@@ -79,7 +80,7 @@ Q_SIGNALS:
|
||||
private:
|
||||
void emitDataChangedFor(DockWidgetBase *);
|
||||
DockWidgetBase::List m_dockWidgets;
|
||||
QHash<DockWidgetBase *, QMetaObject::Connection> m_connections; // To make it easy to disconnect from lambda
|
||||
QHash<DockWidgetBase *, QVector<QMetaObject::Connection> > m_connections; // To make it easy to disconnect from lambdas
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ void QWidgetAdapter::itemChange(QQuickItem::ItemChange change, const QQuickItem:
|
||||
case QQuickItem::ItemVisibleHasChanged: {
|
||||
QEvent ev(QEvent::ParentChange);
|
||||
event(&ev);
|
||||
Q_EMIT parentChanged();
|
||||
break;
|
||||
}
|
||||
case QQuickItem::ItemParentHasChanged: {
|
||||
|
||||
@@ -106,6 +106,8 @@ public:
|
||||
Qt::WindowFlags windowFlags() const;
|
||||
|
||||
QQuickItem *createItem(QQmlEngine *, const QString &filename) const;
|
||||
Q_SIGNALS:
|
||||
void parentChanged();
|
||||
protected:
|
||||
void raiseAndActivate();
|
||||
virtual bool onResize(QSize newSize);
|
||||
|
||||
@@ -47,7 +47,9 @@ Rectangle {
|
||||
|
||||
onDropAreaCppChanged: {
|
||||
// Parent the cpp obj to the visual obj. So the user can style it
|
||||
dropAreaCpp.parent = dropArea;
|
||||
dropAreaCpp.anchors.fill = dropArea;
|
||||
if (dropAreaCpp) {
|
||||
dropAreaCpp.parent = dropArea;
|
||||
dropAreaCpp.anchors.fill = dropArea;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ Rectangle {
|
||||
anchors.fill: parent
|
||||
|
||||
onFrameCppChanged: {
|
||||
frameCpp.setStackLayout(stackLayout);
|
||||
if (frameCpp)
|
||||
frameCpp.setStackLayout(stackLayout);
|
||||
}
|
||||
|
||||
TitleBar {
|
||||
|
||||
@@ -26,6 +26,7 @@ Rectangle {
|
||||
}
|
||||
|
||||
onTitleBarCppChanged: {
|
||||
titleBarCpp.filterEvents(dragMouseArea)
|
||||
if (titleBarCpp)
|
||||
titleBarCpp.filterEvents(dragMouseArea)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user