Ejemplo n.º 1
0
bool SignalTransition::eventTest(QEvent *event)
{
    Q_ASSERT(event);
    if (!QSignalTransition::eventTest(event))
        return false;

    if (m_guard.isEmpty())
        return true;

    QQmlContext *outerContext = QQmlEngine::contextForObject(this);
    QQmlContext context(outerContext);
    QQmlContextData::get(outerContext)->imports->addref();
    QQmlContextData::get(&context)->imports = QQmlContextData::get(outerContext)->imports;

    QStateMachine::SignalEvent *e = static_cast<QStateMachine::SignalEvent*>(event);

    // Set arguments as context properties
    int count = e->arguments().count();
    QMetaMethod metaMethod = e->sender()->metaObject()->method(e->signalIndex());
    for (int i = 0; i < count; i++)
        context.setContextProperty(metaMethod.parameterNames()[i], QVariant::fromValue(e->arguments().at(i)));

    QQmlExpression expr(m_guard, &context, this);
    QVariant result = expr.evaluate();

    return result.toBool();
}
Ejemplo n.º 2
0
/*!
  \reimp

  The default implementation returns true if the \a event is a
  QStateMachine::SignalEvent object and the event's sender and signal index
  match this transition, and returns false otherwise.
*/
bool QSignalTransition::eventTest(QEvent *event)
{
    Q_D(const QSignalTransition);
    if (event->type() == QEvent::StateMachineSignal) {
        if (d->signalIndex == -1)
            return false;
        QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(event);
        return (se->sender() == d->sender)
            && (se->signalIndex() == d->signalIndex);
    }
    return false;
}