Rename struct TimelineViewItem to TimelineView::Item

This commit is contained in:
jordi fita mas 2025-01-07 17:46:50 +01:00
parent 00255f67a0
commit accc627ebd
2 changed files with 15 additions and 14 deletions

View File

@ -2,9 +2,9 @@
#include <QQmlContext>
#include <QQmlInfo>
struct TimelineViewItem
struct TimelineView::Item
{
TimelineViewItem(qint64 day, qint64 len, QQuickItem &qitem, TimelineView &view)
Item(qint64 day, qint64 len, QQuickItem &qitem, TimelineView &view)
: item(&qitem)
, day(day)
{
@ -14,7 +14,7 @@ struct TimelineViewItem
item->setVisible(true);
}
~TimelineViewItem()
~Item()
{
item->setVisible(false);
item->setParent(nullptr);
@ -150,7 +150,7 @@ void TimelineView::componentComplete()
populate();
}
TimelineViewItem *TimelineView::createItem(qint64 day, qint64 len)
TimelineView::Item *TimelineView::createItem(qint64 day, qint64 len)
{
QQuickItem *item = m_reusableItems.isEmpty() ? qobject_cast<QQuickItem *>(m_delegate->create(
m_delegate->creationContext()))
@ -159,11 +159,11 @@ TimelineViewItem *TimelineView::createItem(qint64 day, qint64 len)
qmlWarning(m_delegate) << TimelineView::tr("Delegate must be of Item type");
return nullptr;
}
auto *viewItem = new TimelineViewItem(day, len, *item, *this);
auto *viewItem = new TimelineView::Item(day, len, *item, *this);
return viewItem;
}
void TimelineView::releaseItem(TimelineViewItem *item)
void TimelineView::releaseItem(TimelineView::Item *item)
{
if (!item) {
return;
@ -201,7 +201,7 @@ void TimelineView::populate()
if (m_viewportX > m_prevViewportX) {
// Delete from the left
while (!m_items.isEmpty()) {
TimelineViewItem *item = m_items.first();
TimelineView::Item *item = m_items.first();
if (item->right() >= m_viewportX) {
break;
}
@ -215,7 +215,7 @@ void TimelineView::populate()
lastDay = qMax(-1, qFloor((m_viewportX - (len * m_dayWidth)) / m_dayWidth));
day > lastDay;
day -= len) {
TimelineViewItem *viewItem = createItem(day, len);
TimelineView::Item *viewItem = createItem(day, len);
if (!viewItem) {
break;
}
@ -227,7 +227,7 @@ void TimelineView::populate()
if (currentRight < prevRight) {
// Delete from the right
while (!m_items.isEmpty()) {
TimelineViewItem *item = m_items.last();
TimelineView::Item *item = m_items.last();
if (item->left() < currentRight) {
break;
}
@ -241,7 +241,7 @@ void TimelineView::populate()
lastDay = qFloor((currentRight + (len * m_dayWidth)) / m_dayWidth);
day < lastDay;
day += len) {
TimelineViewItem *viewItem = createItem(day, len);
TimelineView::Item *viewItem = createItem(day, len);
if (!viewItem) {
break;
}

View File

@ -5,7 +5,6 @@
#include <QQmlComponent>
#include <QQuickItem>
struct TimelineViewItem;
class TimelineView : public QQuickItem
{
Q_OBJECT
@ -54,8 +53,10 @@ protected:
private:
Q_DISABLE_COPY_MOVE(TimelineView)
TimelineViewItem *createItem(qint64 day, qint64 len);
void releaseItem(TimelineViewItem *item);
struct Item;
Item *createItem(qint64 day, qint64 len);
void releaseItem(Item *item);
void drainItems();
void clear();
@ -65,7 +66,7 @@ private:
qreal m_dayWidth;
QQmlComponent *m_delegate;
QDate m_fromDate;
QList<TimelineViewItem *> m_items;
QList<Item *> m_items;
QList<QQuickItem *> m_reusableItems;
QDate m_toDate;
qreal m_viewportX;