fix: use bound component context

This commit is contained in:
2 * r + 2 * t 2026-04-03 22:28:10 +11:00
parent 009c5519fd
commit a40b1c2c77
5 changed files with 17 additions and 5 deletions

View file

@ -88,7 +88,7 @@ StyledRect {
anchors.leftMargin: Appearance.spacing.small
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
elide: Text.ElideRight
}
@ -138,7 +138,7 @@ StyledRect {
Layout.fillWidth: true
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
wrapMode: Text.WordWrap

View file

@ -1,3 +1,5 @@
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Layouts
import Quickshell.Widgets

View file

@ -1,3 +1,5 @@
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Caelestia.Components

View file

@ -1,3 +1,5 @@
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Layouts
import Quickshell

View file

@ -637,8 +637,9 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
const auto roleNames = m_model->roleNames();
const auto role = roleNames.isEmpty() ? Qt::DisplayRole : roleNames.constBegin().key();
// Use the delegate component's creation context so the delegate
// can access ids and properties from the scope where it was defined.
// Use the delegate component's creation context directly for beginCreate
// so bound components (pragma ComponentBehavior: Bound) are accepted.
// A per-delegate child context is kept for data updates.
auto* compContext = m_delegate->creationContext();
auto* parentContext = compContext ? compContext : qmlContext(this);
if (!parentContext)
@ -669,10 +670,15 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) {
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);
if (!entry.item) {
if (obj)
m_delegate->completeCreate();
delete obj;
delete entry.context;
entry.context = nullptr;