fix: use bound component context
This commit is contained in:
parent
009c5519fd
commit
a40b1c2c77
5 changed files with 17 additions and 5 deletions
|
|
@ -88,7 +88,7 @@ StyledRect {
|
||||||
anchors.leftMargin: Appearance.spacing.small
|
anchors.leftMargin: Appearance.spacing.small
|
||||||
|
|
||||||
sourceComponent: StyledText {
|
sourceComponent: StyledText {
|
||||||
text: (root.modelData?.body ?? "").replace(/\n/g, " ")
|
text: String(root.modelData?.body ?? "").replace(/\n/g, " ")
|
||||||
color: root.modelData?.urgency === "critical" ? Colours.palette.m3secondary : Colours.palette.m3outline
|
color: root.modelData?.urgency === "critical" ? Colours.palette.m3secondary : Colours.palette.m3outline
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +138,7 @@ StyledRect {
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
textFormat: Text.MarkdownText
|
textFormat: Text.MarkdownText
|
||||||
text: (root.modelData?.body ?? "").replace(/(.)\n(?!\n)/g, "$1\n\n") || qsTr("No body here! :/")
|
text: String(root.modelData?.body ?? "").replace(/(.)\n(?!\n)/g, "$1\n\n") || qsTr("No body here! :/")
|
||||||
color: root.modelData?.urgency === "critical" ? Colours.palette.m3secondary : Colours.palette.m3outline
|
color: root.modelData?.urgency === "critical" ? Colours.palette.m3secondary : Colours.palette.m3outline
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
pragma ComponentBehavior: Bound
|
||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Quickshell.Widgets
|
import Quickshell.Widgets
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
pragma ComponentBehavior: Bound
|
||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Caelestia.Components
|
import Caelestia.Components
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
pragma ComponentBehavior: Bound
|
||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Quickshell
|
import Quickshell
|
||||||
|
|
|
||||||
|
|
@ -637,8 +637,9 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
|
||||||
const auto roleNames = m_model->roleNames();
|
const auto roleNames = m_model->roleNames();
|
||||||
const auto role = roleNames.isEmpty() ? Qt::DisplayRole : roleNames.constBegin().key();
|
const auto role = roleNames.isEmpty() ? Qt::DisplayRole : roleNames.constBegin().key();
|
||||||
|
|
||||||
// Use the delegate component's creation context so the delegate
|
// Use the delegate component's creation context directly for beginCreate
|
||||||
// can access ids and properties from the scope where it was defined.
|
// so bound components (pragma ComponentBehavior: Bound) are accepted.
|
||||||
|
// A per-delegate child context is kept for data updates.
|
||||||
auto* compContext = m_delegate->creationContext();
|
auto* compContext = m_delegate->creationContext();
|
||||||
auto* parentContext = compContext ? compContext : qmlContext(this);
|
auto* parentContext = compContext ? compContext : qmlContext(this);
|
||||||
if (!parentContext)
|
if (!parentContext)
|
||||||
|
|
@ -669,10 +670,15 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
|
||||||
initialProps.insert(QStringLiteral("modelData"), value);
|
initialProps.insert(QStringLiteral("modelData"), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* obj = m_delegate->beginCreate(entry.context);
|
// Use the creation context for beginCreate to satisfy bound component checks
|
||||||
|
// (pragma ComponentBehavior: Bound). Data is passed via setInitialProperties.
|
||||||
|
auto* creationCtx = compContext ? compContext : parentContext;
|
||||||
|
auto* obj = m_delegate->beginCreate(creationCtx);
|
||||||
entry.item = qobject_cast<QQuickItem*>(obj);
|
entry.item = qobject_cast<QQuickItem*>(obj);
|
||||||
|
|
||||||
if (!entry.item) {
|
if (!entry.item) {
|
||||||
|
if (obj)
|
||||||
|
m_delegate->completeCreate();
|
||||||
delete obj;
|
delete obj;
|
||||||
delete entry.context;
|
delete entry.context;
|
||||||
entry.context = nullptr;
|
entry.context = nullptr;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue