Example #1
0
void HSSRequest::setDTarget(HSSParserNode::p value)
{
    switch (value->getType())
    {
    case HSSParserNodeTypeKeywordConstant:
    case HSSParserNodeTypeFunctionCall:
    {
        this->dTarget = value;
        if (this->observedTarget)
        {
            this->observedTarget->removeObserver(this->observedTargetProperty, HSSObservablePropertyTarget, this);
        }

        switch (value->getType())
        {
        case HSSParserNodeTypeKeywordConstant:
            /**
             *  @todo what here?
             */
            break;

        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p fnct = qSharedPointerCast<HSSFunction > (value)->clone();
            if (fnct)
            {
                fnct->setScope(this->scope);
                fnct->setThisObj(this->getThisObj());
                QVariant remoteValue = fnct->evaluate();
                if (remoteValue.canConvert< HSSSelection::p >())
                {
                    HSSSimpleSelection::p selection = remoteValue.value< HSSSelection::p >()->joinAll();
                    this->target->clear();
                    this->target->insert(this->target->end(), selection->begin(), selection->end());
                }

                /**
                 *  @todo potentially leaking
                 */
                fnct->observe(HSSObservablePropertyValue, HSSObservablePropertyTarget, this, new HSSValueChangedCallback<HSSRequest > (this, &HSSRequest::targetChanged));
                this->observedTarget = fnct.data();
                this->observedTargetProperty = HSSObservablePropertyValue;
            }

            break;
        }

        default:
            break;
        }

        this->notifyObservers(HSSObservablePropertySrc, &this->src);

        break;
    }

    default:
        throw AXRWarning("HSSRequest", "Invalid value for src of " + this->name);
    }
}
Example #2
0
HSSUnit HSSExpression::evaluate()
{
    if (this->isDirty())
    {
        this->setDirty(false);

        //left
        switch (this->getLeft()->getType())
        {
        case HSSParserNodeTypeExpression:
        {
            HSSExpression::p leftExpression = qSharedPointerCast<HSSExpression > (this->getLeft());
            this->leftval = leftExpression->evaluate();
            if (this->leftObserved)
            {
                this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this);
            }
            leftExpression->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged));
            this->leftObserved = leftExpression.data();
            this->leftObservedProperty = HSSObservablePropertyValue;
            break;
        }

        case HSSParserNodeTypeNumberConstant:
        {
            HSSNumberConstant::p leftNumber = qSharedPointerCast<HSSNumberConstant > (this->getLeft());
            this->leftval = leftNumber->getValue();
            break;
        }

        case HSSParserNodeTypePercentageConstant:
        {
            HSSPercentageConstant::p leftPercentage = qSharedPointerCast<HSSPercentageConstant > (this->getLeft());
            this->leftval = leftPercentage->getValue(this->percentageBase);
            if (this->leftObserved)
            {
                this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this);
            }
            this->percentageObserved->observe(this->percentageObservedProperty, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged));
            this->leftObserved = this->percentageObserved;
            this->leftObservedProperty = this->percentageObservedProperty;
            break;
        }

        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p leftFunction = qSharedPointerCast<HSSFunction > (this->getLeft());
            QVariant remoteValue = leftFunction->evaluate();
            if (remoteValue.canConvert<HSSUnit*>())
            {
                this->leftval = *remoteValue.value<HSSUnit*>();
                if (this->leftObserved)
                {
                    this->leftObserved->removeObserver(this->leftObservedProperty, HSSObservablePropertyValue, this);
                }
                leftFunction->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::leftChanged));
                this->leftObserved = leftFunction.data();
                this->leftObservedProperty = HSSObservablePropertyValue;

            }
            else
            {
                this->rightval = 0.;
            }

            break;
        }

        default:
            std_log1("############ HSSExpression::evaluate() unknwown node type in left member");
            break;
        }


        //right
        switch (this->getRight()->getType())
        {
        case HSSParserNodeTypeExpression:
        {
            HSSExpression::p rightExpression = qSharedPointerCast<HSSExpression > (this->getRight());
            this->rightval = rightExpression->evaluate();
            if (this->rightObserved)
            {
                this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this);
            }
            rightExpression->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged));
            this->rightObserved = rightExpression.data();
            this->rightObservedProperty = HSSObservablePropertyValue;
            break;
        }

        case HSSParserNodeTypeNumberConstant:
        {
            HSSNumberConstant::p rightNumber = qSharedPointerCast<HSSNumberConstant > (this->getRight());
            this->rightval = rightNumber->getValue();
            break;
        }

        case HSSParserNodeTypePercentageConstant:
        {
            HSSPercentageConstant::p rightPercentage = qSharedPointerCast<HSSPercentageConstant > (this->getRight());
            this->rightval = rightPercentage->getValue(this->percentageBase);
            if (this->rightObserved)
            {
                this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this);
            }
            this->percentageObserved->observe(this->percentageObservedProperty, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged));
            this->rightObserved = this->percentageObserved;
            this->rightObservedProperty = this->percentageObservedProperty;
            break;
        }

        case HSSParserNodeTypeFunctionCall:
        {
            HSSFunction::p rightFunction = qSharedPointerCast<HSSFunction > (this->getRight());
            QVariant remoteValue = rightFunction->evaluate();
            if (remoteValue.canConvert<HSSUnit*>())
            {
                this->rightval = *remoteValue.value<HSSUnit*>();
                if (this->rightObserved)
                {
                    this->rightObserved->removeObserver(this->rightObservedProperty, HSSObservablePropertyValue, this);
                }
                rightFunction->observe(HSSObservablePropertyValue, HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSExpression > (this, &HSSExpression::rightChanged));
                this->rightObserved = rightFunction.data();
                this->rightObservedProperty = HSSObservablePropertyValue;
            }
            else
            {
                this->rightval = 0.;
            }

            break;
        }

        default:
            std_log1("############ HSSExpression::evaluate() unknwown node type in right member");
            break;
        }

        this->setValue(this->calculate(this->leftval, this->rightval));
    }

    return this->getValue();
}