Use the extended QQmlListProperty interface in a few places
Task-number: QTBUG-79263 Change-Id: If518f644b5b9eddbacfb1cb16fbb557127ffcfb2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
053547fba7
commit
6d0a453f41
|
@ -81,7 +81,7 @@ void BirthdayParty::setHost(Person *c)
|
|||
|
||||
QQmlListProperty<Person> BirthdayParty::guests()
|
||||
{
|
||||
return {this, m_guests};
|
||||
return {this, &m_guests};
|
||||
}
|
||||
|
||||
int BirthdayParty::guestCount() const
|
||||
|
|
|
@ -87,7 +87,7 @@ void BirthdayParty::setHost(Person *c)
|
|||
|
||||
QQmlListProperty<Person> BirthdayParty::guests()
|
||||
{
|
||||
return QQmlListProperty<Person>(this, m_guests);
|
||||
return QQmlListProperty<Person>(this, &m_guests);
|
||||
}
|
||||
|
||||
int BirthdayParty::guestCount() const
|
||||
|
|
|
@ -66,7 +66,7 @@ void BirthdayParty::setHost(Person *c)
|
|||
|
||||
QQmlListProperty<Person> BirthdayParty::guests()
|
||||
{
|
||||
return {this, m_guests};
|
||||
return {this, &m_guests};
|
||||
}
|
||||
|
||||
int BirthdayParty::guestCount() const
|
||||
|
|
|
@ -66,7 +66,7 @@ void BirthdayParty::setHost(Person *c)
|
|||
|
||||
QQmlListProperty<Person> BirthdayParty::guests()
|
||||
{
|
||||
return {this, m_guests};
|
||||
return {this, &m_guests};
|
||||
}
|
||||
|
||||
int BirthdayParty::guestCount() const
|
||||
|
|
|
@ -66,7 +66,7 @@ void BirthdayParty::setHost(Person *c)
|
|||
|
||||
QQmlListProperty<Person> BirthdayParty::guests()
|
||||
{
|
||||
return {this, m_guests};
|
||||
return {this, &m_guests};
|
||||
}
|
||||
|
||||
int BirthdayParty::guestCount() const
|
||||
|
|
|
@ -67,7 +67,7 @@ void BirthdayParty::setHost(Person *c)
|
|||
|
||||
QQmlListProperty<Person> BirthdayParty::guests()
|
||||
{
|
||||
return {this, m_guests};
|
||||
return {this, &m_guests};
|
||||
}
|
||||
|
||||
int BirthdayParty::guestCount() const
|
||||
|
|
|
@ -71,7 +71,9 @@ QQmlListProperty<Person> BirthdayParty::guests()
|
|||
&BirthdayParty::appendGuest,
|
||||
&BirthdayParty::guestCount,
|
||||
&BirthdayParty::guest,
|
||||
&BirthdayParty::clearGuests};
|
||||
&BirthdayParty::clearGuests,
|
||||
&BirthdayParty::replaceGuest,
|
||||
&BirthdayParty::removeLastGuest};
|
||||
}
|
||||
|
||||
void BirthdayParty::appendGuest(Person* p) {
|
||||
|
@ -93,6 +95,16 @@ void BirthdayParty::clearGuests() {
|
|||
m_guests.clear();
|
||||
}
|
||||
|
||||
void BirthdayParty::replaceGuest(int index, Person *p)
|
||||
{
|
||||
m_guests[index] = p;
|
||||
}
|
||||
|
||||
void BirthdayParty::removeLastGuest()
|
||||
{
|
||||
m_guests.removeLast();
|
||||
}
|
||||
|
||||
// ![0]
|
||||
|
||||
void BirthdayParty::appendGuest(QQmlListProperty<Person>* list, Person* p) {
|
||||
|
@ -103,6 +115,16 @@ void BirthdayParty::clearGuests(QQmlListProperty<Person>* list) {
|
|||
reinterpret_cast< BirthdayParty* >(list->data)->clearGuests();
|
||||
}
|
||||
|
||||
void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, int i, Person *p)
|
||||
{
|
||||
reinterpret_cast< BirthdayParty* >(list->data)->replaceGuest(i, p);
|
||||
}
|
||||
|
||||
void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list)
|
||||
{
|
||||
reinterpret_cast< BirthdayParty* >(list->data)->removeLastGuest();
|
||||
}
|
||||
|
||||
Person* BirthdayParty::guest(QQmlListProperty<Person>* list, int i) {
|
||||
return reinterpret_cast< BirthdayParty* >(list->data)->guest(i);
|
||||
}
|
||||
|
|
|
@ -79,12 +79,16 @@ public:
|
|||
int guestCount() const;
|
||||
Person *guest(int) const;
|
||||
void clearGuests();
|
||||
void replaceGuest(int, Person*);
|
||||
void removeLastGuest();
|
||||
|
||||
private:
|
||||
static void appendGuest(QQmlListProperty<Person>*, Person*);
|
||||
static int guestCount(QQmlListProperty<Person>*);
|
||||
static Person* guest(QQmlListProperty<Person>*, int);
|
||||
static void clearGuests(QQmlListProperty<Person>*);
|
||||
static void replaceGuest(QQmlListProperty<Person>*, int, Person*);
|
||||
static void removeLastGuest(QQmlListProperty<Person>*);
|
||||
|
||||
Person *m_host;
|
||||
QVector<Person *> m_guests;
|
||||
|
|
|
@ -82,7 +82,7 @@ void BirthdayParty::setHost(Person *c)
|
|||
|
||||
QQmlListProperty<Person> BirthdayParty::guests()
|
||||
{
|
||||
return {this, m_guests};
|
||||
return {this, &m_guests};
|
||||
}
|
||||
|
||||
int BirthdayParty::guestCount() const
|
||||
|
|
|
@ -82,7 +82,7 @@ void BirthdayParty::setHost(Person *c)
|
|||
|
||||
QQmlListProperty<Person> BirthdayParty::guests()
|
||||
{
|
||||
return {this, m_guests};
|
||||
return {this, &m_guests};
|
||||
}
|
||||
|
||||
int BirthdayParty::guestCount() const
|
||||
|
|
|
@ -68,7 +68,8 @@ void PieChart::setName(const QString &name)
|
|||
//![0]
|
||||
QQmlListProperty<PieSlice> PieChart::slices()
|
||||
{
|
||||
return QQmlListProperty<PieSlice>(this, nullptr, &PieChart::append_slice, nullptr, nullptr, nullptr);
|
||||
return QQmlListProperty<PieSlice>(this, nullptr, &PieChart::append_slice, nullptr,
|
||||
nullptr, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void PieChart::append_slice(QQmlListProperty<PieSlice> *list, PieSlice *slice)
|
||||
|
|
|
@ -67,7 +67,8 @@ void PieChart::setName(const QString &name)
|
|||
|
||||
QQmlListProperty<PieSlice> PieChart::slices()
|
||||
{
|
||||
return QQmlListProperty<PieSlice>(this, nullptr, &PieChart::append_slice, nullptr, nullptr, nullptr);
|
||||
return QQmlListProperty<PieSlice>(this, nullptr, &PieChart::append_slice, nullptr,
|
||||
nullptr, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void PieChart::append_slice(QQmlListProperty<PieSlice> *list, PieSlice *slice)
|
||||
|
|
|
@ -250,7 +250,9 @@ QQmlListProperty<QQmlDelegateChoice> QQmlDelegateChooser::choices()
|
|||
QQmlDelegateChooser::choices_append,
|
||||
QQmlDelegateChooser::choices_count,
|
||||
QQmlDelegateChooser::choices_at,
|
||||
QQmlDelegateChooser::choices_clear);
|
||||
QQmlDelegateChooser::choices_clear,
|
||||
QQmlDelegateChooser::choices_replace,
|
||||
QQmlDelegateChooser::choices_removeLast);
|
||||
}
|
||||
|
||||
void QQmlDelegateChooser::choices_append(QQmlListProperty<QQmlDelegateChoice> *prop, QQmlDelegateChoice *choice)
|
||||
|
@ -282,6 +284,26 @@ void QQmlDelegateChooser::choices_clear(QQmlListProperty<QQmlDelegateChoice> *pr
|
|||
q->delegateChanged();
|
||||
}
|
||||
|
||||
void QQmlDelegateChooser::choices_replace(QQmlListProperty<QQmlDelegateChoice> *prop, int index,
|
||||
QQmlDelegateChoice *choice)
|
||||
{
|
||||
QQmlDelegateChooser *q = static_cast<QQmlDelegateChooser *>(prop->object);
|
||||
disconnect(q->m_choices[index], &QQmlDelegateChoice::changed,
|
||||
q, &QQmlAbstractDelegateComponent::delegateChanged);
|
||||
q->m_choices[index] = choice;
|
||||
connect(choice, &QQmlDelegateChoice::changed, q,
|
||||
&QQmlAbstractDelegateComponent::delegateChanged);
|
||||
q->delegateChanged();
|
||||
}
|
||||
|
||||
void QQmlDelegateChooser::choices_removeLast(QQmlListProperty<QQmlDelegateChoice> *prop)
|
||||
{
|
||||
QQmlDelegateChooser *q = static_cast<QQmlDelegateChooser *>(prop->object);
|
||||
disconnect(q->m_choices.takeLast(), &QQmlDelegateChoice::changed,
|
||||
q, &QQmlAbstractDelegateComponent::delegateChanged);
|
||||
q->delegateChanged();
|
||||
}
|
||||
|
||||
QQmlComponent *QQmlDelegateChooser::delegate(QQmlAdaptorModel *adaptorModel, int row, int column) const
|
||||
{
|
||||
QVariant v;
|
||||
|
|
|
@ -116,6 +116,8 @@ public:
|
|||
static int choices_count(QQmlListProperty<QQmlDelegateChoice> *);
|
||||
static QQmlDelegateChoice *choices_at(QQmlListProperty<QQmlDelegateChoice> *, int);
|
||||
static void choices_clear(QQmlListProperty<QQmlDelegateChoice> *);
|
||||
static void choices_replace(QQmlListProperty<QQmlDelegateChoice> *, int, QQmlDelegateChoice *);
|
||||
static void choices_removeLast(QQmlListProperty<QQmlDelegateChoice> *);
|
||||
|
||||
QQmlComponent *delegate(QQmlAdaptorModel *adaptorModel, int row, int column = -1) const override;
|
||||
|
||||
|
|
|
@ -644,7 +644,9 @@ QQmlListProperty<QQmlTableModelColumn> QQmlTableModel::columns()
|
|||
&QQmlTableModel::columns_append,
|
||||
&QQmlTableModel::columns_count,
|
||||
&QQmlTableModel::columns_at,
|
||||
&QQmlTableModel::columns_clear);
|
||||
&QQmlTableModel::columns_clear,
|
||||
&QQmlTableModel::columns_replace,
|
||||
&QQmlTableModel::columns_removeLast);
|
||||
}
|
||||
|
||||
void QQmlTableModel::columns_append(QQmlListProperty<QQmlTableModelColumn> *property,
|
||||
|
@ -674,6 +676,19 @@ void QQmlTableModel::columns_clear(QQmlListProperty<QQmlTableModelColumn> *prope
|
|||
return model->mColumns.clear();
|
||||
}
|
||||
|
||||
void QQmlTableModel::columns_replace(QQmlListProperty<QQmlTableModelColumn> *property, int index, QQmlTableModelColumn *value)
|
||||
{
|
||||
QQmlTableModel *model = static_cast<QQmlTableModel*>(property->object);
|
||||
if (QQmlTableModelColumn *column = qobject_cast<QQmlTableModelColumn*>(value))
|
||||
return model->mColumns.replace(index, column);
|
||||
}
|
||||
|
||||
void QQmlTableModel::columns_removeLast(QQmlListProperty<QQmlTableModelColumn> *property)
|
||||
{
|
||||
QQmlTableModel *model = static_cast<QQmlTableModel*>(property->object);
|
||||
model->mColumns.removeLast();
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod QModelIndex TableModel::index(int row, int column)
|
||||
|
||||
|
|
|
@ -96,6 +96,8 @@ public:
|
|||
static int columns_count(QQmlListProperty<QQmlTableModelColumn> *property);
|
||||
static QQmlTableModelColumn *columns_at(QQmlListProperty<QQmlTableModelColumn> *property, int index);
|
||||
static void columns_clear(QQmlListProperty<QQmlTableModelColumn> *property);
|
||||
static void columns_replace(QQmlListProperty<QQmlTableModelColumn> *property, int index, QQmlTableModelColumn *value);
|
||||
static void columns_removeLast(QQmlListProperty<QQmlTableModelColumn> *property);
|
||||
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
|
|
@ -1143,7 +1143,9 @@ QQuickImageParticle::~QQuickImageParticle()
|
|||
|
||||
QQmlListProperty<QQuickSprite> QQuickImageParticle::sprites()
|
||||
{
|
||||
return QQmlListProperty<QQuickSprite>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
|
||||
return QQmlListProperty<QQuickSprite>(this, &m_sprites,
|
||||
spriteAppend, spriteCount, spriteAt,
|
||||
spriteClear, spriteReplace, spriteRemoveLast);
|
||||
}
|
||||
|
||||
void QQuickImageParticle::sceneGraphInvalidated()
|
||||
|
|
|
@ -106,10 +106,15 @@ void delayedRedirect(QQmlListProperty<QObject> *prop, QObject *value)
|
|||
QQmlListProperty<QObject> QQuickParticleGroup::particleChildren()
|
||||
{
|
||||
QQuickParticleSystem* system = qobject_cast<QQuickParticleSystem*>(parent());
|
||||
if (system)
|
||||
return QQmlListProperty<QObject>(this, nullptr, &QQuickParticleSystem::statePropertyRedirect, nullptr, nullptr, nullptr);
|
||||
else
|
||||
return QQmlListProperty<QObject>(this, nullptr, &delayedRedirect, nullptr, nullptr, nullptr);
|
||||
if (system) {
|
||||
return QQmlListProperty<QObject>(this, nullptr,
|
||||
&QQuickParticleSystem::statePropertyRedirect, nullptr,
|
||||
nullptr, nullptr, nullptr, nullptr);
|
||||
} else {
|
||||
return QQmlListProperty<QObject>(this, nullptr,
|
||||
&delayedRedirect, nullptr, nullptr,
|
||||
nullptr, nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void QQuickParticleGroup::setSystem(QQuickParticleSystem* arg)
|
||||
|
|
|
@ -136,6 +136,20 @@ static void list_clear(QQmlListProperty<QObject> *prop)
|
|||
resolved.activateSignal();
|
||||
}
|
||||
|
||||
static void list_replace(QQmlListProperty<QObject> *prop, int index, QObject *o)
|
||||
{
|
||||
const ResolvedList resolved(prop);
|
||||
resolved.list()->replace(index, o);
|
||||
resolved.activateSignal();
|
||||
}
|
||||
|
||||
static void list_removeLast(QQmlListProperty<QObject> *prop)
|
||||
{
|
||||
const ResolvedList resolved(prop);
|
||||
resolved.list()->removeLast();
|
||||
resolved.activateSignal();
|
||||
}
|
||||
|
||||
QQmlVMEVariantQObjectPtr::QQmlVMEVariantQObjectPtr()
|
||||
: QQmlGuard<QObject>(nullptr), m_target(nullptr), m_index(-1)
|
||||
{
|
||||
|
@ -737,7 +751,8 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void *
|
|||
*static_cast<QQmlListProperty<QObject> *>(a[0])
|
||||
= QQmlListProperty<QObject>(
|
||||
object, reinterpret_cast<void *>(quintptr(id)),
|
||||
list_append, list_count, list_at, list_clear);
|
||||
list_append, list_count, list_at,
|
||||
list_clear, list_replace, list_removeLast);
|
||||
} else {
|
||||
*reinterpret_cast<QObject **>(a[0]) = readPropertyAsQObject(id);
|
||||
}
|
||||
|
|
|
@ -731,7 +731,7 @@ QQmlListProperty<QQmlDelegateModelGroup> QQmlDelegateModel::groups()
|
|||
QQmlDelegateModelPrivate::group_append,
|
||||
QQmlDelegateModelPrivate::group_count,
|
||||
QQmlDelegateModelPrivate::group_at,
|
||||
nullptr);
|
||||
nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -91,6 +91,15 @@ public:
|
|||
static_cast<QQmlObjectModelPrivate *>(prop->data)->clear();
|
||||
}
|
||||
|
||||
static void children_replace(QQmlListProperty<QObject> *prop, int index, QObject *item) {
|
||||
static_cast<QQmlObjectModelPrivate *>(prop->data)->replace(index, item);
|
||||
}
|
||||
|
||||
static void children_removeLast(QQmlListProperty<QObject> *prop) {
|
||||
auto data = static_cast<QQmlObjectModelPrivate *>(prop->data);
|
||||
data->remove(data->children.count() - 1, 1);
|
||||
}
|
||||
|
||||
void insert(int index, QObject *item) {
|
||||
Q_Q(QQmlObjectModel);
|
||||
children.insert(index, Item(item));
|
||||
|
@ -105,6 +114,19 @@ public:
|
|||
emit q->childrenChanged();
|
||||
}
|
||||
|
||||
void replace(int index, QObject *item) {
|
||||
Q_Q(QQmlObjectModel);
|
||||
auto *attached = QQmlObjectModelAttached::properties(children.at(index).item);
|
||||
emit q->destroyingItem(attached);
|
||||
attached->setIndex(-1);
|
||||
children.replace(index, Item(item));
|
||||
QQmlObjectModelAttached::properties(children.at(index).item)->setIndex(index);
|
||||
QQmlChangeSet changeSet;
|
||||
changeSet.change(index, 1);
|
||||
emit q->modelUpdated(changeSet, false);
|
||||
emit q->childrenChanged();
|
||||
}
|
||||
|
||||
void move(int from, int to, int n) {
|
||||
Q_Q(QQmlObjectModel);
|
||||
if (from > to) {
|
||||
|
@ -138,6 +160,7 @@ public:
|
|||
Q_Q(QQmlObjectModel);
|
||||
for (int i = index; i < index + n; ++i) {
|
||||
QQmlObjectModelAttached *attached = QQmlObjectModelAttached::properties(children.at(i).item);
|
||||
emit q->destroyingItem(attached);
|
||||
attached->setIndex(-1);
|
||||
}
|
||||
children.erase(children.begin() + index, children.begin() + index + n);
|
||||
|
@ -153,9 +176,6 @@ public:
|
|||
}
|
||||
|
||||
void clear() {
|
||||
Q_Q(QQmlObjectModel);
|
||||
for (const Item &child : qAsConst(children))
|
||||
emit q->destroyingItem(child.item);
|
||||
remove(0, children.count());
|
||||
}
|
||||
|
||||
|
@ -226,12 +246,13 @@ QQmlObjectModel::QQmlObjectModel(QObject *parent)
|
|||
QQmlListProperty<QObject> QQmlObjectModel::children()
|
||||
{
|
||||
Q_D(QQmlObjectModel);
|
||||
return QQmlListProperty<QObject>(this,
|
||||
d,
|
||||
d->children_append,
|
||||
d->children_count,
|
||||
d->children_at,
|
||||
d->children_clear);
|
||||
return QQmlListProperty<QObject>(this, d,
|
||||
QQmlObjectModelPrivate::children_append,
|
||||
QQmlObjectModelPrivate::children_count,
|
||||
QQmlObjectModelPrivate::children_at,
|
||||
QQmlObjectModelPrivate::children_clear,
|
||||
QQmlObjectModelPrivate::children_replace,
|
||||
QQmlObjectModelPrivate::children_removeLast);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -115,6 +115,14 @@ public:
|
|||
QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
|
||||
return list->count();
|
||||
}
|
||||
static void data_replace(QQmlListProperty<QObject> *prop, int index, QObject *o) {
|
||||
QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
|
||||
list->replace(index, DataGuard(o, list));
|
||||
}
|
||||
static void data_removeLast(QQmlListProperty<QObject> *prop) {
|
||||
QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
|
||||
list->removeLast();
|
||||
}
|
||||
};
|
||||
|
||||
QHash<QObject *, QQuickPackageAttached *> QQuickPackageAttached::attached;
|
||||
|
@ -152,10 +160,13 @@ QQuickPackage::~QQuickPackage()
|
|||
QQmlListProperty<QObject> QQuickPackage::data()
|
||||
{
|
||||
Q_D(QQuickPackage);
|
||||
return QQmlListProperty<QObject>(this, &d->dataList, QQuickPackagePrivate::data_append,
|
||||
QQuickPackagePrivate::data_count,
|
||||
QQuickPackagePrivate::data_at,
|
||||
QQuickPackagePrivate::data_clear);
|
||||
return QQmlListProperty<QObject>(this, &d->dataList,
|
||||
QQuickPackagePrivate::data_append,
|
||||
QQuickPackagePrivate::data_count,
|
||||
QQuickPackagePrivate::data_at,
|
||||
QQuickPackagePrivate::data_clear,
|
||||
QQuickPackagePrivate::data_replace,
|
||||
QQuickPackagePrivate::data_removeLast);
|
||||
}
|
||||
|
||||
bool QQuickPackage::hasPart(const QString &name)
|
||||
|
|
|
@ -330,6 +330,18 @@ inline int spriteCount(QQmlListProperty<QQuickSprite> *p)
|
|||
return reinterpret_cast<QList<QQuickSprite *> *>(p->data)->count();
|
||||
}
|
||||
|
||||
inline void spriteReplace(QQmlListProperty<QQuickSprite> *p, int idx, QQuickSprite *s)
|
||||
{
|
||||
reinterpret_cast<QList<QQuickSprite *> *>(p->data)->replace(idx, s);
|
||||
p->object->metaObject()->invokeMethod(p->object, "createEngine");
|
||||
}
|
||||
|
||||
inline void spriteRemoveLast(QQmlListProperty<QQuickSprite> *p)
|
||||
{
|
||||
reinterpret_cast<QList<QQuickSprite *> *>(p->data)->removeLast();
|
||||
p->object->metaObject()->invokeMethod(p->object, "createEngine");
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QQUICKSPRITEENGINE_P_H
|
||||
|
|
|
@ -162,7 +162,9 @@ void QQuickSpriteSequence::setInterpolate(bool arg)
|
|||
QQmlListProperty<QQuickSprite> QQuickSpriteSequence::sprites()
|
||||
{
|
||||
Q_D(QQuickSpriteSequence);
|
||||
return QQmlListProperty<QQuickSprite>(this, &d->m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
|
||||
return QQmlListProperty<QQuickSprite>(this, &d->m_sprites,
|
||||
spriteAppend, spriteCount, spriteAt,
|
||||
spriteClear, spriteReplace, spriteRemoveLast);
|
||||
}
|
||||
|
||||
bool QQuickSpriteSequence::running() const
|
||||
|
|
|
@ -682,10 +682,13 @@ void QQuickWindow::handleApplicationStateChanged(Qt::ApplicationState state)
|
|||
|
||||
QQmlListProperty<QObject> QQuickWindowPrivate::data()
|
||||
{
|
||||
return QQmlListProperty<QObject>(q_func(), nullptr, QQuickWindowPrivate::data_append,
|
||||
QQuickWindowPrivate::data_count,
|
||||
QQuickWindowPrivate::data_at,
|
||||
QQuickWindowPrivate::data_clear);
|
||||
return QQmlListProperty<QObject>(q_func(), nullptr,
|
||||
QQuickWindowPrivate::data_append,
|
||||
QQuickWindowPrivate::data_count,
|
||||
QQuickWindowPrivate::data_at,
|
||||
QQuickWindowPrivate::data_clear,
|
||||
QQuickWindowPrivate::data_replace,
|
||||
QQuickWindowPrivate::data_removeLast);
|
||||
}
|
||||
|
||||
static QMouseEvent *touchToMouseEvent(QEvent::Type type, const QTouchEvent::TouchPoint &p, QTouchEvent *event, QQuickItem *item, bool transformNeeded = true)
|
||||
|
@ -3257,6 +3260,20 @@ void QQuickWindowPrivate::data_clear(QQmlListProperty<QObject> *property)
|
|||
itemProperty.clear(&itemProperty);
|
||||
}
|
||||
|
||||
void QQuickWindowPrivate::data_replace(QQmlListProperty<QObject> *property, int i, QObject *o)
|
||||
{
|
||||
QQuickWindow *win = static_cast<QQuickWindow*>(property->object);
|
||||
QQmlListProperty<QObject> itemProperty = QQuickItemPrivate::get(win->contentItem())->data();
|
||||
itemProperty.replace(&itemProperty, i, o);
|
||||
}
|
||||
|
||||
void QQuickWindowPrivate::data_removeLast(QQmlListProperty<QObject> *property)
|
||||
{
|
||||
QQuickWindow *win = static_cast<QQuickWindow*>(property->object);
|
||||
QQmlListProperty<QObject> itemProperty = QQuickItemPrivate::get(win->contentItem())->data();
|
||||
itemProperty.removeLast(&itemProperty);
|
||||
}
|
||||
|
||||
bool QQuickWindowPrivate::isRenderable() const
|
||||
{
|
||||
Q_Q(const QQuickWindow);
|
||||
|
|
|
@ -299,6 +299,8 @@ public:
|
|||
static int data_count(QQmlListProperty<QObject> *);
|
||||
static QObject *data_at(QQmlListProperty<QObject> *, int);
|
||||
static void data_clear(QQmlListProperty<QObject> *);
|
||||
static void data_replace(QQmlListProperty<QObject> *, int, QObject *);
|
||||
static void data_removeLast(QQmlListProperty<QObject> *);
|
||||
|
||||
static void contextCreationFailureMessage(const QSurfaceFormat &format,
|
||||
QString *translatedMessage,
|
||||
|
|
|
@ -267,9 +267,13 @@ void QQuickState::setExtends(const QString &extends)
|
|||
QQmlListProperty<QQuickStateOperation> QQuickState::changes()
|
||||
{
|
||||
Q_D(QQuickState);
|
||||
return QQmlListProperty<QQuickStateOperation>(this, &d->operations, QQuickStatePrivate::operations_append,
|
||||
QQuickStatePrivate::operations_count, QQuickStatePrivate::operations_at,
|
||||
QQuickStatePrivate::operations_clear);
|
||||
return QQmlListProperty<QQuickStateOperation>(this, &d->operations,
|
||||
QQuickStatePrivate::operations_append,
|
||||
QQuickStatePrivate::operations_count,
|
||||
QQuickStatePrivate::operations_at,
|
||||
QQuickStatePrivate::operations_clear,
|
||||
QQuickStatePrivate::operations_replace,
|
||||
QQuickStatePrivate::operations_removeLast);
|
||||
}
|
||||
|
||||
int QQuickState::operationCount() const
|
||||
|
|
|
@ -244,6 +244,23 @@ public:
|
|||
QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
|
||||
return list->at(index);
|
||||
}
|
||||
static void operations_replace(QQmlListProperty<QQuickStateOperation> *prop, int index,
|
||||
QQuickStateOperation *op) {
|
||||
QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
|
||||
auto &guard = list->at(index);
|
||||
if (guard.object() == op) {
|
||||
op->setState(qobject_cast<QQuickState*>(prop->object));
|
||||
} else {
|
||||
list->at(index)->setState(nullptr);
|
||||
op->setState(qobject_cast<QQuickState*>(prop->object));
|
||||
list->replace(index, OperationGuard(op, list));
|
||||
}
|
||||
}
|
||||
static void operations_removeLast(QQmlListProperty<QQuickStateOperation> *prop) {
|
||||
QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
|
||||
list->last()->setState(nullptr);
|
||||
list->removeLast();
|
||||
}
|
||||
|
||||
QQuickTransitionManager transitionManager;
|
||||
|
||||
|
|
|
@ -70,6 +70,8 @@ public:
|
|||
static int count_state(QQmlListProperty<QQuickState> *list);
|
||||
static QQuickState *at_state(QQmlListProperty<QQuickState> *list, int index);
|
||||
static void clear_states(QQmlListProperty<QQuickState> *list);
|
||||
static void replace_states(QQmlListProperty<QQuickState> *list, int index, QQuickState *state);
|
||||
static void removeLast_states(QQmlListProperty<QQuickState> *list);
|
||||
|
||||
static void append_transition(QQmlListProperty<QQuickTransition> *list, QQuickTransition *state);
|
||||
static int count_transitions(QQmlListProperty<QQuickTransition> *list);
|
||||
|
@ -163,10 +165,13 @@ QList<QQuickState *> QQuickStateGroup::states() const
|
|||
QQmlListProperty<QQuickState> QQuickStateGroup::statesProperty()
|
||||
{
|
||||
Q_D(QQuickStateGroup);
|
||||
return QQmlListProperty<QQuickState>(this, &d->states, &QQuickStateGroupPrivate::append_state,
|
||||
&QQuickStateGroupPrivate::count_state,
|
||||
&QQuickStateGroupPrivate::at_state,
|
||||
&QQuickStateGroupPrivate::clear_states);
|
||||
return QQmlListProperty<QQuickState>(this, &d->states,
|
||||
&QQuickStateGroupPrivate::append_state,
|
||||
&QQuickStateGroupPrivate::count_state,
|
||||
&QQuickStateGroupPrivate::at_state,
|
||||
&QQuickStateGroupPrivate::clear_states,
|
||||
&QQuickStateGroupPrivate::replace_states,
|
||||
&QQuickStateGroupPrivate::removeLast_states);
|
||||
}
|
||||
|
||||
void QQuickStateGroupPrivate::append_state(QQmlListProperty<QQuickState> *list, QQuickState *state)
|
||||
|
@ -201,6 +206,29 @@ void QQuickStateGroupPrivate::clear_states(QQmlListProperty<QQuickState> *list)
|
|||
_this->d_func()->states.clear();
|
||||
}
|
||||
|
||||
void QQuickStateGroupPrivate::replace_states(QQmlListProperty<QQuickState> *list, int index, QQuickState *state)
|
||||
{
|
||||
auto *self = qobject_cast<QQuickStateGroup *>(list->object);
|
||||
auto *d = self->d_func();
|
||||
auto *oldState = d->states.at(index);
|
||||
if (oldState != state) {
|
||||
oldState->setStateGroup(nullptr);
|
||||
state->setStateGroup(self);
|
||||
d->states.replace(index, state);
|
||||
if (d->currentState == oldState->name())
|
||||
d->setCurrentStateInternal(state->name(), true);
|
||||
}
|
||||
}
|
||||
|
||||
void QQuickStateGroupPrivate::removeLast_states(QQmlListProperty<QQuickState> *list)
|
||||
{
|
||||
auto *d = qobject_cast<QQuickStateGroup *>(list->object)->d_func();
|
||||
if (d->currentState == d->states.last()->name())
|
||||
d->setCurrentStateInternal(d->states.length() > 1 ? d->states.first()->name() : QString(), true);
|
||||
d->states.last()->setStateGroup(nullptr);
|
||||
d->states.removeLast();
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlproperty list<Transition> QtQuick::StateGroup::transitions
|
||||
This property holds a list of transitions defined by the state group.
|
||||
|
|
Loading…
Reference in New Issue