Show the reservation’s holder name in timelineview
TimelineView is not a general control that can be used with any model, thus i do not need the complexity of Qt’s QQmlDelegateModel incubation task to initialize required properties. I _would_ have used it if it were available in C++, but since it is not, what i mean is that i do not need to _reimplement_ all of it for my case: i already know what required properties there are.
This commit is contained in:
parent
66e12d5019
commit
e404727c45
|
@ -80,9 +80,19 @@ Page {
|
|||
viewportX: ListView.view.contentX
|
||||
|
||||
delegate: Rectangle {
|
||||
id: booking
|
||||
|
||||
required property string holder
|
||||
|
||||
border.color: "black"
|
||||
border.width: 1
|
||||
color: "blue"
|
||||
color: "lightblue"
|
||||
|
||||
Label {
|
||||
anchors.fill: parent
|
||||
elide: Text.ElideRight
|
||||
text: booking.holder
|
||||
}
|
||||
}
|
||||
}
|
||||
header: Pane {
|
||||
|
|
|
@ -167,16 +167,26 @@ void TimelineView::componentComplete()
|
|||
populate();
|
||||
}
|
||||
|
||||
TimelineView::Item *TimelineView::createItem(qint64 day, qint64 len)
|
||||
TimelineView::Item *TimelineView::createItem(qint64 day, const TimelineModel::Item &modelItem)
|
||||
{
|
||||
QQuickItem *item = m_reusableItems.isEmpty() ? qobject_cast<QQuickItem *>(m_delegate->create(
|
||||
m_delegate->creationContext()))
|
||||
: m_reusableItems.takeLast();
|
||||
if (!item) {
|
||||
qmlWarning(m_delegate) << TimelineView::tr("Delegate must be of Item type");
|
||||
return nullptr;
|
||||
QQuickItem *item;
|
||||
|
||||
if (m_reusableItems.isEmpty()) {
|
||||
QVariantMap initialProperties{
|
||||
{"holder", modelItem.holder},
|
||||
};
|
||||
item = qobject_cast<QQuickItem *>(
|
||||
m_delegate->createWithInitialProperties(initialProperties,
|
||||
m_delegate->creationContext()));
|
||||
if (!item) {
|
||||
qmlWarning(m_delegate) << TimelineView::tr("Delegate must be of Item type");
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
item = m_reusableItems.takeLast();
|
||||
item->setProperty("holder", modelItem.holder);
|
||||
}
|
||||
auto *viewItem = new TimelineView::Item(day, len, *item, *this);
|
||||
auto *viewItem = new TimelineView::Item(day, modelItem.nights, *item, *this);
|
||||
return viewItem;
|
||||
}
|
||||
|
||||
|
@ -235,7 +245,7 @@ void TimelineView::populate()
|
|||
if (!m_items.isEmpty() && m_items.first()->day <= day) {
|
||||
continue;
|
||||
}
|
||||
TimelineView::Item *viewItem = createItem(day, item->nights);
|
||||
TimelineView::Item *viewItem = createItem(day, *item);
|
||||
if (!viewItem) {
|
||||
break;
|
||||
}
|
||||
|
@ -263,7 +273,7 @@ void TimelineView::populate()
|
|||
if (!m_items.isEmpty() && m_items.last()->day >= day) {
|
||||
continue;
|
||||
}
|
||||
TimelineView::Item *viewItem = createItem(day, item->nights);
|
||||
TimelineView::Item *viewItem = createItem(day, *item);
|
||||
if (!viewItem) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ private:
|
|||
|
||||
struct Item;
|
||||
|
||||
Item *createItem(qint64 day, qint64 len);
|
||||
Item *createItem(qint64 day, const TimelineModel::Item &modelItem);
|
||||
void releaseItem(Item *item);
|
||||
void drainItems();
|
||||
|
||||
|
|
Loading…
Reference in New Issue