8#include <private/qqmlobjectmodel_p.h>
9#include <private/qquicksmoothedanimation_p_p.h>
11#include <QtGui/qevent.h>
12#include <QtCore/qmath.h>
13#include <QtCore/qcoreapplication.h>
14#include "qplatformdefs.h"
20#ifndef QML_FLICK_SNAPONETHRESHOLD
21#define QML_FLICK_SNAPONETHRESHOLD 30
61 return colSize * (columns-1) -
itemX();
87 moveTo(pointForPosition(col,
row), immediate);
165#if QT_CONFIG(quick_viewtransitions)
166 void translateAndTransitionItemsAfter(
int afterModelIndex,
const ChangeResult &insertionResult,
const ChangeResult &removalResult)
override;
281 return firstItem->
colPos();
305 return firstItem->
rowPos();
348 pos += highlightStart;
352 snapPos -= highlightStart;
373 if (
item->index == -1)
386 if (
item->index == -1)
390 if (itemTop >= hItem->rowPos()-
rowSize()/2 && itemTop < hItem->rowPos()+
rowSize()/2) {
393 if (gridItem->colPos() >= hItem->colPos()-
colSize()/2 && gridItem->colPos() < hItem->colPos()+
colSize()/2)
394 return gridItem->index;
406 return -
q->leftMargin();
417 return -
pos -
q->width();
429 return -
pos -
q->height();
433 return -
q->topMargin();
435 return -
q->height() +
q->bottomMargin();
443 ?
q->width() -
q->leftMargin() -
q->rightMargin()
444 :
q->height() -
q->topMargin() -
q->bottomMargin();
460 item->trackGeometry(
true);
469 rowPos = lastItem->
rowPos();
479 modelIndex = modelIndex < 0 ?
visibleIndex : modelIndex + 1;
490 else if (modelIndex < 0)
500 bool changed =
false;
505 qCDebug(lcItemViewDelegateLifecycle) <<
"refill: append item" << modelIndex << colPos << rowPos;
508#if QT_CONFIG(quick_viewtransitions)
510 item->setPosition(colPos, rowPos,
true);
529 rowPos = firstItem->
rowPos();
530 colPos = firstItem->
colPos();
541 qCDebug(lcItemViewDelegateLifecycle) <<
"refill: prepend item" <<
visibleIndex-1 <<
"top pos" << rowPos << colPos;
545#if QT_CONFIG(quick_viewtransitions)
547 item->setPosition(colPos, rowPos,
true);
564#if QT_CONFIG(quick_viewtransitions)
565 if (
item->transitionScheduledOrRunning()) {
566 qCDebug(lcItemViewDelegateLifecycle) <<
"\tnot releasing animating item:" <<
item->index <<
item->item->objectName();
567 item->releaseAfterTransition =
true;
568 releasePendingTransition.append(
item);
579 bool changed =
false;
584 if (
item->attached->delayRemove())
586 qCDebug(lcItemViewDelegateLifecycle) <<
"refill: remove first" <<
visibleIndex <<
"top end pos" <<
item->endRowPos();
587 if (
item->index != -1)
596 if (
item->attached->delayRemove())
623 if (colPos != col *
colSize()) {
635 if (
item->index >= fromModelIndex) {
636 item->setPosition(colPos, rowPos);
684 int moveCount = (forwards - backwards) /
rowSize();
685 if (moveCount == 0 && changeBeforeVisible != 0)
694 bool changed =
false;
715 std::unique_ptr<FxGridItemSG> newHighlight
716 = std::make_unique<FxGridItemSG>(
item,
q,
true);
717 newHighlight->trackGeometry(
true);
732 emit q->highlightItemChanged();
789 bool created =
false;
806 colOffset += gridItem->item->width() -
cellWidth;
810 colOffset += gridItem->item->height() -
cellHeight;
812 rowOffset += gridItem->item->height() -
cellHeight;
817 gridItem->setPosition(colOffset, endPos + rowOffset);
820 if (endPos <= visiblePos || gridItem->
endPosition() <= endPos + rowOffset)
821 gridItem->setPosition(colOffset, endPos + rowOffset);
824 gridItem->setPosition(colOffset, rowOffset);
828 emit q->footerItemChanged();
834 qmlAttachedPropertiesObject<QQuickGridView>(
item));
842 bool created =
false;
857 rowOffset += gridItem->item->width() -
cellWidth;
859 colOffset += gridItem->item->width() -
cellWidth;
863 colOffset += gridItem->item->height() -
cellHeight;
865 rowOffset += gridItem->item->height() -
cellHeight;
870 gridItem->setPosition(colOffset, startPos + rowOffset);
874 if (tempPos <= startPos || headerPos > startPos + rowOffset)
875 gridItem->setPosition(colOffset, startPos + rowOffset);
879 gridItem->setPosition(colOffset, rowOffset);
881 gridItem->setPosition(colOffset, -
headerSize());
885 emit q->headerItemChanged();
897 || !actualItem->transitionScheduledOrRunning()
931 else if (
data.velocity < 0 && dist < -QML_FLICK_SNAPONETHRESHOLD && dist > -
rowSize()/2)
935 tempPosition -=
bias;
951 if (topItem && (isInBounds || strictHighlightRange)) {
961 }
else if (bottomItem && isInBounds) {
976 data.fixingUp =
true;
991 viewPos = -viewPos-
size();
996 data.fixingUp =
true;
1006 data.inOvershoot =
false;
1013 data.fixingUp =
false;
1019 qreal maxDistance = 0;
1031 maxDistance =
qAbs(
data.flickTarget -
data.move.value());
1048 maxDistance =
qAbs(
data.flickTarget -
data.move.value());
1058 if (maxDistance > 0 || overShoot) {
1069 qreal overshootDist = 0.0;
1084 data.flickTarget += overshootDist;
1087 data.flickTarget -= overshootDist;
1093 qreal adjv2 = accel * 2.0f *
qAbs(adjDist);
1258 if (
d->autoHighlight != autoHighlight) {
1259 if (!autoHighlight &&
d->highlightXAnimator) {
1260 d->highlightXAnimator->stop();
1261 d->highlightYAnimator->stop();
1632 if (
d->highlightMoveDuration != duration) {
1633 if (
d->highlightYAnimator) {
1634 d->highlightXAnimator->userDuration = duration;
1635 d->highlightYAnimator->userDuration = duration;
1659 if (
d->flow !=
flow) {
1670 d->regenerate(
true);
1687 return d->cellWidth;
1695 d->updateViewport();
1697 d->forceLayoutPolish();
1705 return d->cellHeight;
1713 d->updateViewport();
1715 d->forceLayoutPolish();
1741 if (
d->snapMode !=
mode) {
2099 if (
d->inViewportMoved)
2101 d->inViewportMoved =
true;
2104 if (
d->isContentFlowReversed())
2109 if (
d->isContentFlowReversed())
2115 d->refillOrLayout();
2118 qreal from =
d->isContentFlowReversed() ? -
d->position()-
d->displayMarginBeginning-
d->size() :
d->position()-
d->displayMarginBeginning;
2119 qreal to =
d->isContentFlowReversed() ? -
d->position()+
d->displayMarginEnd :
d->position()+
d->size()+
d->displayMarginEnd;
2122 QQuickItemPrivate::get(gridItem->item)->setCulled(gridItem->rowPos() +
d->rowSize() < from || gridItem->rowPos() > to);
2124 if (
d->currentItem) {
2129 if (
d->hData.flicking ||
d->vData.flicking ||
d->hData.moving ||
d->vData.moving)
2135 qreal viewPos =
d->isContentFlowReversed() ? -
d->position()-
d->size() :
d->position();
2136 if (
pos > viewPos +
d->highlightRangeEnd -
d->highlight->size())
2137 pos = viewPos +
d->highlightRangeEnd -
d->highlight->size();
2138 if (pos < viewPos + d->highlightRangeStart)
2139 pos = viewPos +
d->highlightRangeStart;
2141 if (
pos !=
d->highlight->position()) {
2142 d->highlightXAnimator->stop();
2143 d->highlightYAnimator->stop();
2147 d->updateHighlight();
2151 int idx =
d->snapIndex();
2152 if (idx >= 0 && idx !=
d->currentIndex) {
2153 d->updateCurrent(idx);
2157 &&
d->autoHighlight) {
2159 d->highlightXAnimator->to =
d->currentItem->itemX();
2161 d->highlightYAnimator->to =
d->currentItem->itemY();
2167 d->inViewportMoved =
false;
2173 if (
d->model &&
d->model->count() && ((
d->interactive && !
d->explicitKeyNavigationEnabled)
2174 || (
d->explicitKeyNavigationEnabled &&
d->keyNavigationEnabled))) {
2177 switch (
event->key()) {
2207 if (newGeometry.
width() != oldGeometry.
width()
2209 d->setPosition(
d->position());
2210 }
else if (newGeometry.
width() != oldGeometry.
width()) {
2212 }
else if (newGeometry.
height() != oldGeometry.
height()) {
2228 qmlAttachedPropertiesObject<QQuickGridView>(
item));
2248 const int count =
d->model ?
d->model->count() : 0;
2290 const int count =
d->model ?
d->model->count() : 0;
2333 const int count =
d->model ?
d->model->count() : 0;
2376 const int count =
d->model ?
d->model->count() : 0;
2410 if (
q->size().isEmpty())
2413 int modelIndex = change.
index;
2430 if (
item->index != -1 &&
item->index >= modelIndex)
2445 colPos = gridItem->
colPos();
2446 rowPos = gridItem->rowPos();
2451 rowPos = gridItem->
rowPos();
2461#if QT_CONFIG(quick_viewtransitions)
2464 if (
item->index != -1 &&
item->index >= modelIndex) {
2475 if (insertResult->visiblePos.isValid() && rowPos < insertResult->visiblePos) {
2477 int insertionIdx =
index;
2483 insertResult->countChangeBeforeVisible +=
count;
2490 item->index = modelIndex +
i;
2498 if (insertionIdx == 0)
2499 insertResult->changedFirstItem =
true;
2501 addedItems->append(
item);
2502#if QT_CONFIG(quick_viewtransitions)
2509 insertResult->sizeChangesBeforeVisiblePos +=
rowSize();
2511 if (--colNum < 0 ) {
2524 int firstOkIdx = -1;
2532 for (
int i = 0;
i < firstOkIdx;
i++) {
2534 addedItems->removeOne(nvItem);
2544 item->index = modelIndex +
i;
2545 bool newItem = !
item;
2554 insertResult->changedFirstItem =
true;
2565 addedItems->append(
item);
2566#if QT_CONFIG(quick_viewtransitions)
2573 insertResult->sizeChangesAfterVisiblePos +=
rowSize();
2590#if QT_CONFIG(quick_viewtransitions)
2591void QQuickGridViewPrivate::translateAndTransitionItemsAfter(
int afterModelIndex,
const ChangeResult &insertionResult,
const ChangeResult &removalResult)
2596 int markerItemIndex = -1;
2599 markerItemIndex =
i;
2603 if (markerItemIndex < 0)
2607 int countItemsRemoved = -(removalResult.sizeChangesAfterVisiblePos /
rowSize());
2610 int changeBeforeVisible = insertionResult.countChangeBeforeVisible - removalResult.countChangeBeforeVisible;
2611 if (changeBeforeVisible != 0)
2612 countItemsRemoved += (changeBeforeVisible %
columns) - (
columns - 1);
2614 countItemsRemoved -= removalResult.countChangeAfterVisibleItems;
2618 if (gridItem->position() >= viewEndPos)
2620 if (!gridItem->transitionScheduledOrRunning()) {
2622 qreal origColPos = gridItem->rowPos();
2623 int indexDiff = gridItem->index - countItemsRemoved;
2626 gridItem->setPosition(origRowPos, origColPos);
2777#include "moc_qquickgridview_p.cpp"
bool contains(qreal x, qreal y) const override
qreal position() const override
void setPosition(qreal col, qreal row, bool immediate=false)
qreal size() const override
qreal sectionSize() const override
qreal endPosition() const override
FxGridItemSG(QQuickItem *i, QQuickGridView *v, bool own)
Type
This enum type defines the valid event types in Qt.
qreal y() const
This convenience function is equivalent to calling pos().y().
qreal x() const
This convenience function is equivalent to calling pos().x().
void setVisible(bool visible)
If visible is true, the item is made visible.
The QKeyEvent class describes a key event.
qsizetype size() const noexcept
void removeFirst() noexcept
bool isEmpty() const noexcept
const T & constLast() const noexcept
iterator insert(qsizetype i, parameter_type t)
const_reference at(qsizetype i) const noexcept
void prepend(rvalue_ref t)
const T & constFirst() const noexcept
void removeLast() noexcept
void append(parameter_type t)
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it.
\inmodule QtCore\reentrant
IncubationMode
Specifies the mode the incubator operates in.
The QQmlProperty class abstracts accessing properties on objects created from QML.
virtual bool flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, QQuickTimeLineCallback::Callback fixupCallback, QEvent::Type eventType, qreal velocity)
MovementReason moveReason
qreal overShootDistance(qreal velocity) const
virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent)
QQuickFlickable::BoundsBehavior boundsBehavior
void setContentWidth(qreal)
virtual void setContentX(qreal pos)
virtual void viewportMoved(Qt::Orientations orient)
virtual void setContentY(qreal pos)
void setFlickableDirection(FlickableDirection)
void setContentHeight(qreal)
qreal footerSize() const override
bool addVisibleItems(qreal fillFrom, qreal fillTo, qreal bufferFrom, qreal bufferTo, bool doBuffer) override
qreal snapPosAt(qreal pos) const
void fixupPosition() override
void updateViewport() override
void updateHighlight() override
bool showFooterForIndex(int index) const override
bool isContentFlowReversed() const override
bool flick(QQuickItemViewPrivate::AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, QQuickTimeLineCallback::Callback fixupCallback, QEvent::Type eventType, qreal velocity) override
void repositionPackageItemAt(QQuickItem *item, int index) override
bool showHeaderForIndex(int index) const override
bool needsRefillForAddedOrRemovedIndex(int index) const override
QQuickGridView::Flow flow
void createHighlight(bool onDestruction=false) override
QQuickGridView::SnapMode snapMode
void initializeViewItem(FxViewItem *item) override
void removeItem(FxViewItem *item)
qreal positionAt(int index) const override
void updateFooter() override
Qt::Orientation layoutOrientation() const override
qreal endPositionAt(int index) const override
void setPosition(qreal pos) override
void resetFirstItemPosition(qreal pos=0.0) override
bool applyInsertionChange(const QQmlChangeSet::Change &insert, ChangeResult *changeResult, QList< FxViewItem * > *addedItems, QList< MovedItem > *movingIntoView) override
void initializeComponentItem(QQuickItem *item) const override
void adjustFirstItem(qreal forwards, qreal backwards, int changeBeforeVisible) override
QSmoothedAnimation * highlightYAnimator
qreal rowPosAt(int modelIndex) const
void repositionItemAt(FxViewItem *item, int index, qreal sizeBuffer) override
FxViewItem * snapItemAt(qreal pos) const
void fixup(AxisData &data, qreal minExtent, qreal maxExtent) override
void resetHighlightPosition() override
void changedVisibleIndex(int newIndex) override
void layoutVisibleItems(int fromModelIndex=0) override
qreal contentYForPosition(qreal pos) const
qreal lastPosition() const override
FxViewItem * newViewItem(int index, QQuickItem *item) override
QSmoothedAnimation * highlightXAnimator
qreal contentXForPosition(qreal pos) const
qreal headerSize() const override
qreal originPosition() const override
void updateHeader() override
bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) override
qreal colPosAt(int modelIndex) const
void initializeCurrentItem() override
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void setHighlightFollowsCurrentItem(bool) override
void moveCurrentIndexRight()
\qmlmethod QtQuick::GridView::moveCurrentIndexRight()
static QQuickGridViewAttached * qmlAttachedProperties(QObject *)
\qmlmethod QtQuick::GridView::positionViewAtIndex(int index, PositionMode mode)
void moveCurrentIndexDown()
\qmlmethod QtQuick::GridView::moveCurrentIndexDown()
void moveCurrentIndexUp()
\qmlmethod QtQuick::GridView::moveCurrentIndexUp()
QQuickGridView(QQuickItem *parent=nullptr)
\qmltype GridView \instantiates QQuickGridView \inqmlmodule QtQuick
void moveCurrentIndexLeft()
\qmlmethod QtQuick::GridView::moveCurrentIndexLeft()
void initItem(int index, QObject *item) override
void setCellHeight(qreal)
void setHighlightMoveDuration(int) override
\qmlattachedproperty bool QtQuick::GridView::isCurrentItem \readonly
void setSnapMode(SnapMode mode)
void viewportMoved(Qt::Orientations) override
\qmlproperty Component QtQuick::GridView::footer This property holds the component to use as the foot...
void keyPressEvent(QKeyEvent *) override
This event handler can be reimplemented in a subclass to receive key press events for an item.
static QQuickItemPrivate * get(QQuickItem *item)
void setView(QQuickItemView *view)
QMultiHash< QQmlChangeSet::MoveKey, FxViewItem * > removedItems
QPointer< QQuickItem > item
void setVisible(bool visible)
void moveTo(const QPointF &pos, bool immediate)
void trackGeometry(bool track)
int findLastVisibleIndex(int defaultValue=-1) const
qreal highlightRangeStart
virtual void updateViewport()
FxViewItem * visibleItem(int modelIndex) const
int highlightMoveDuration
QQuickItem * createHighlightItem() const
QPointer< QQmlInstanceModel > model
QList< FxViewItem * > visibleItems
int displayMarginBeginning
virtual void initializeViewItem(FxViewItem *)
qreal endPosition() const
QQmlComponent * footerComponent
QQuickItemViewChangeSet currentChanges
void applyPendingChanges()
QQuickItemView::VerticalLayoutDirection verticalLayoutDirection
int mapFromModel(int modelIndex) const
void updateVisibleIndex()
QQuickItem * createComponentItem(QQmlComponent *component, qreal zValue, bool createDefault=false) const
void releaseVisibleItems(QQmlInstanceModel::ReusableFlag reusableFlag)
FxViewItem * createItem(int modelIndex, QQmlIncubator::IncubationMode incubationMode=QQmlIncubator::AsynchronousIfNested)
QQmlComponent * headerComponent
virtual bool releaseItem(FxViewItem *item, QQmlInstanceModel::ReusableFlag reusableFlag)
QQmlInstanceModel::ReusableFlag reusableFlag
std::unique_ptr< FxViewItem > highlight
virtual void setHighlightFollowsCurrentItem(bool)
void setContentX(qreal pos) override
Qt::LayoutDirection effectiveLayoutDirection
void setContentY(qreal pos) override
virtual void initItem(int index, QObject *item)
virtual void setHighlightMoveDuration(int)
void setCurrentIndex(int idx)
VerticalLayoutDirection verticalLayoutDirection
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
virtual void keyPressEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key press events for an item.
qreal width
This property holds the width of this item.
qreal height
This property holds the height of this item.
void reset(QQuickTimeLineValue &)
Cancel (but don't complete) all scheduled actions for timeLineValue.
int accel(QQuickTimeLineValue &, qreal velocity, qreal accel)
Decelerate timeLineValue from the starting velocity to zero at the given acceleration rate.
void callback(const QQuickTimeLineCallback &)
Execute the event.
void set(QQuickTimeLineValue &, qreal)
Set the value of timeLineValue.
void move(QQuickTimeLineValue &, qreal destination, int time=500)
Linearly change the timeLineValue from its current value to the given destination value over time mil...
\inmodule QtCore\reentrant
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
cache insert(employee->id(), employee)
Combined button and popup list for selecting options.
qfloat16 qSqrt(qfloat16 f)
#define qCDebug(category,...)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
constexpr T qAbs(const T &t)
n void setPosition(void) \n\
GLint GLfloat GLfloat GLfloat v2
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
QObject * qmlAttachedPropertiesObject(QObject *object, QQmlAttachedPropertiesFunc func, bool create)
QQuickItem * qmlobject_cast< QQuickItem * >(QObject *object)
#define QML_FLICK_SNAPONETHRESHOLD
QLatin1StringView QLatin1String
#define QT_CONFIG(feature)
std::uniform_real_distribution dist(1, 2.5)
[2]
MoveKey moveKey(int index) const