Rename struct TimelineViewItem to TimelineView::Item
This commit is contained in:
parent
00255f67a0
commit
accc627ebd
|
@ -2,9 +2,9 @@
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QQmlInfo>
|
#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)
|
: item(&qitem)
|
||||||
, day(day)
|
, day(day)
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ struct TimelineViewItem
|
||||||
item->setVisible(true);
|
item->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
~TimelineViewItem()
|
~Item()
|
||||||
{
|
{
|
||||||
item->setVisible(false);
|
item->setVisible(false);
|
||||||
item->setParent(nullptr);
|
item->setParent(nullptr);
|
||||||
|
@ -150,7 +150,7 @@ void TimelineView::componentComplete()
|
||||||
populate();
|
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(
|
QQuickItem *item = m_reusableItems.isEmpty() ? qobject_cast<QQuickItem *>(m_delegate->create(
|
||||||
m_delegate->creationContext()))
|
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");
|
qmlWarning(m_delegate) << TimelineView::tr("Delegate must be of Item type");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto *viewItem = new TimelineViewItem(day, len, *item, *this);
|
auto *viewItem = new TimelineView::Item(day, len, *item, *this);
|
||||||
return viewItem;
|
return viewItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineView::releaseItem(TimelineViewItem *item)
|
void TimelineView::releaseItem(TimelineView::Item *item)
|
||||||
{
|
{
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return;
|
return;
|
||||||
|
@ -201,7 +201,7 @@ void TimelineView::populate()
|
||||||
if (m_viewportX > m_prevViewportX) {
|
if (m_viewportX > m_prevViewportX) {
|
||||||
// Delete from the left
|
// Delete from the left
|
||||||
while (!m_items.isEmpty()) {
|
while (!m_items.isEmpty()) {
|
||||||
TimelineViewItem *item = m_items.first();
|
TimelineView::Item *item = m_items.first();
|
||||||
if (item->right() >= m_viewportX) {
|
if (item->right() >= m_viewportX) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ void TimelineView::populate()
|
||||||
lastDay = qMax(-1, qFloor((m_viewportX - (len * m_dayWidth)) / m_dayWidth));
|
lastDay = qMax(-1, qFloor((m_viewportX - (len * m_dayWidth)) / m_dayWidth));
|
||||||
day > lastDay;
|
day > lastDay;
|
||||||
day -= len) {
|
day -= len) {
|
||||||
TimelineViewItem *viewItem = createItem(day, len);
|
TimelineView::Item *viewItem = createItem(day, len);
|
||||||
if (!viewItem) {
|
if (!viewItem) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ void TimelineView::populate()
|
||||||
if (currentRight < prevRight) {
|
if (currentRight < prevRight) {
|
||||||
// Delete from the right
|
// Delete from the right
|
||||||
while (!m_items.isEmpty()) {
|
while (!m_items.isEmpty()) {
|
||||||
TimelineViewItem *item = m_items.last();
|
TimelineView::Item *item = m_items.last();
|
||||||
if (item->left() < currentRight) {
|
if (item->left() < currentRight) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ void TimelineView::populate()
|
||||||
lastDay = qFloor((currentRight + (len * m_dayWidth)) / m_dayWidth);
|
lastDay = qFloor((currentRight + (len * m_dayWidth)) / m_dayWidth);
|
||||||
day < lastDay;
|
day < lastDay;
|
||||||
day += len) {
|
day += len) {
|
||||||
TimelineViewItem *viewItem = createItem(day, len);
|
TimelineView::Item *viewItem = createItem(day, len);
|
||||||
if (!viewItem) {
|
if (!viewItem) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include <QQmlComponent>
|
#include <QQmlComponent>
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
|
|
||||||
struct TimelineViewItem;
|
|
||||||
class TimelineView : public QQuickItem
|
class TimelineView : public QQuickItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -54,8 +53,10 @@ protected:
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY_MOVE(TimelineView)
|
Q_DISABLE_COPY_MOVE(TimelineView)
|
||||||
|
|
||||||
TimelineViewItem *createItem(qint64 day, qint64 len);
|
struct Item;
|
||||||
void releaseItem(TimelineViewItem *item);
|
|
||||||
|
Item *createItem(qint64 day, qint64 len);
|
||||||
|
void releaseItem(Item *item);
|
||||||
void drainItems();
|
void drainItems();
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
@ -65,7 +66,7 @@ private:
|
||||||
qreal m_dayWidth;
|
qreal m_dayWidth;
|
||||||
QQmlComponent *m_delegate;
|
QQmlComponent *m_delegate;
|
||||||
QDate m_fromDate;
|
QDate m_fromDate;
|
||||||
QList<TimelineViewItem *> m_items;
|
QList<Item *> m_items;
|
||||||
QList<QQuickItem *> m_reusableItems;
|
QList<QQuickItem *> m_reusableItems;
|
||||||
QDate m_toDate;
|
QDate m_toDate;
|
||||||
qreal m_viewportX;
|
qreal m_viewportX;
|
||||||
|
|
Loading…
Reference in New Issue