8#include <private/qqmlbinding_p.h>
9#include <private/qqmlglobal_p.h>
11#include <QtCore/qstringlist.h>
12#include <QtCore/qdebug.h>
13#include <QtCore/qvector.h>
15#include <private/qobject_p.h>
29 : nullState(
nullptr), componentComplete(true),
30 ignoreTrans(
false), applyingState(
false), unnamedCount(0) {}
36 static qsizetype count_state(QQmlListProperty<QQuickState> *
list);
38 static void clear_states(QQmlListProperty<QQuickState> *
list);
40 static void removeLast_states(QQmlListProperty<QQuickState> *
list);
43 static qsizetype count_transitions(QQmlListProperty<QQuickTransition> *
list);
45 static void clear_transitions(QQmlListProperty<QQuickTransition> *
list);
56 void setCurrentStateInternal(
const QString &
state,
bool =
false);
57 bool updateAutoState();
101 state->setStateGroup(
nullptr);
104 d->nullState->setStateGroup(
nullptr);
136 return QQmlListProperty<QQuickState>(
this, &
d->states,
150 state->setStateGroup(_this);
156 return _this->d_func()->
states.size();
168 d->setCurrentStateInternal(
QString(),
true);
171 state->setStateGroup(
nullptr);
179 auto *
d = self->d_func();
180 auto *oldState =
d->states.
at(
index);
181 if (oldState !=
state) {
183 oldState->setStateGroup(
nullptr);
186 state->setStateGroup(self);
188 if (!oldState ||
d->currentState == oldState->name())
197 if (
d->currentState == last->name()) {
203 d->states.removeLast();
286 return d->currentState;
292 if (
d->currentState ==
state)
295 d->setCurrentStateInternal(
state);
301 d->componentComplete =
false;
307 d->componentComplete =
true;
309 QVarLengthArray<QString, 4>
names;
310 names.reserve(
d->states.size());
315 if (!
state->isNamed())
319 if (
names.contains(stateName))
320 qmlWarning(
state->parent()) <<
"Found duplicate state name: " << stateName;
325 if (
d->updateAutoState()) {
327 }
else if (!
d->currentState.isEmpty()) {
329 d->currentState.clear();
330 d->setCurrentStateInternal(cs,
true);
337bool QQuickStateGroup::updateAutoState()
340 return d->updateAutoState();
354 bool whenValue =
state->when();
357 Q_ASSERT(!potentialWhenBinding.isUntypedPropertyBinding());
365 const auto boolType = QMetaType::fromType<bool>();
366 const bool isUndefined = !binding->
evaluate(&whenValue, boolType);
373 qCDebug(lcStates) <<
"Setting auto state due to expression";
375 q->setState(
state->name());
397 bool reversed =
false;
404 for (
int ii = 0; ii < 2; ++ii)
406 if (ii && (!
t->reversible() ||
410 const QString fromStateStr =
t->fromState();
411 const QString toStateStr =
t->toState();
414 for (
int jj = 0; jj < fromState.size(); ++jj)
415 fromState[jj] = fromState.at(jj).trimmed();
417 for (
int jj = 0; jj < toState.size(); ++jj)
418 toState[jj] = toState.at(jj).trimmed();
420 qSwap(fromState, toState);
425 else if (fromState.contains(
QStringView(asterisk)))
446 }
else if (tScore > score) {
454 highest->setReversed(reversed);
469 qmlWarning(
q) <<
"Can't apply a state change as part of a state definition.";
476 if (lcStates().isDebugEnabled()) {
504 if (oldState ==
nullptr ||
newState ==
nullptr) {
532 d->states.removeOne(
state);
535void QQuickStateGroup::stateAboutToComplete()
538 d->applyingState =
false;
544#include "moc_qquickstategroup_p.cpp"
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
static QQmlAnyBinding ofProperty(const QQmlProperty &prop)
bool hasValidContext() const
static qsizetype count_transitions(QQmlListProperty< QQuickTransition > *list)
QList< QQuickTransition * > transitions
static void clear_states(QQmlListProperty< QQuickState > *list)
static void replace_states(QQmlListProperty< QQuickState > *list, qsizetype index, QQuickState *state)
static void removeLast_states(QQmlListProperty< QQuickState > *list)
void setCurrentStateInternal(const QString &state, bool=false)
QQuickStateGroupPrivate()
static QQuickTransition * at_transition(QQmlListProperty< QQuickTransition > *list, qsizetype index)
static QQuickState * at_state(QQmlListProperty< QQuickState > *list, qsizetype index)
static void clear_transitions(QQmlListProperty< QQuickTransition > *list)
static void append_transition(QQmlListProperty< QQuickTransition > *list, QQuickTransition *state)
QQuickTransition * findTransition(const QString &from, const QString &to)
static qsizetype count_state(QQmlListProperty< QQuickState > *list)
static void append_state(QQmlListProperty< QQuickState > *list, QQuickState *state)
QList< QQuickState * > states
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void removeState(QQuickState *state)
QQmlListProperty< QQuickTransition > transitionsProperty()
\qmlproperty list<Transition> QtQuick::StateGroup::transitions This property holds a list of transiti...
QQuickStateGroup(QObject *=nullptr)
\qmltype StateGroup \instantiates QQuickStateGroup \inqmlmodule QtQuick
QQuickState * findState(const QString &name) const
QQmlListProperty< QQuickState > states
void setState(const QString &)
QQmlListProperty< QQuickState > statesProperty()
\qmlproperty list<State> QtQuick::StateGroup::states This property holds a list of states defined by ...
virtual ~QQuickStateGroup()
void classBegin() override
Invoked after class creation, but before any properties have been set.
QQmlListProperty< QQuickTransition > transitions
void apply(QQuickTransition *, QQuickState *revert)
void setStateGroup(QQuickStateGroup *)
QString fromState() const
\qmlproperty string QtQuick::Transition::from \qmlproperty string QtQuick::Transition::to
Q_CORE_EXPORT QList< QStringView > split(QStringView sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the view into substring views wherever sep occurs, and returns the list of those string views.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString & append(QChar c)
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLdouble GLdouble GLdouble GLdouble q
void QQml_setParent_noEvent(QObject *object, QObject *parent)
Makes the object a child of parent.
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define QStringLiteral(str)
QT_BEGIN_NAMESPACE constexpr void qSwap(T &value1, T &value2) noexcept(std::is_nothrow_swappable_v< T >)
\inmodule QtCore \reentrant