QList<QGraphicsItem*> DefaultVisualization::createPrimitiveItems(const stromx::runtime::Data & data,
    const VisualizationState::Properties & properties)
{    
    using namespace stromx::runtime;
    
    if(data.isVariant(Variant::BOOL))
        return createPrimitiveItemsTemplate<Bool>(data, properties);
    else if(data.isVariant(Variant::INT_8))
        return createPrimitiveItemsTemplate<Int8>(data, properties);
    else if(data.isVariant(Variant::UINT_8))
        return createPrimitiveItemsTemplate<UInt8>(data, properties);
    else if(data.isVariant(Variant::INT_16))
        return createPrimitiveItemsTemplate<Int16>(data, properties);
    else if(data.isVariant(Variant::UINT_16))
        return createPrimitiveItemsTemplate<UInt16>(data, properties);
    else if(data.isVariant(Variant::INT_32))
        return createPrimitiveItemsTemplate<Int32>(data, properties);
    else if(data.isVariant(Variant::UINT_32))
        return createPrimitiveItemsTemplate<UInt32>(data, properties);
    else if(data.isVariant(Variant::FLOAT_32))
        return createPrimitiveItemsTemplate<Float32>(data, properties);
    else if(data.isVariant(Variant::FLOAT_64))
        return createPrimitiveItemsTemplate<Float64>(data, properties);
    else
        return QList<QGraphicsItem*>();
}
QList< QGraphicsItem* > DefaultVisualization::createItems(const stromx::runtime::Data & data,
        const VisualizationState::Properties & properties) const
{
    using namespace stromx::runtime;
    
    QList<QGraphicsItem*> items;
    
    if(data.isVariant(Variant::IMAGE))
    {
        items = createImageItems(data, properties);
    }
    else if(data.isVariant(Variant::PRIMITIVE))
    {
        items = createPrimitiveItems(data, properties);
    } 
    else if(data.isVariant(Variant::STRING))
    {
        items = createStringItems(data, properties);
    }
    
    return items;
}
Пример #3
0
QList< QGraphicsItem* > LineSegments::createItems(const stromx::runtime::Data & data,
        const VisualizationState::Properties & properties) const
{
    using namespace stromx::runtime;
    
    if(data.isVariant(Variant::INT_8_MATRIX))
        return createLineSegmentItemsTemplate<int8_t>(data, properties);
    else if(data.isVariant(Variant::UINT_8_MATRIX))
        return createLineSegmentItemsTemplate<uint8_t>(data, properties);
    else if(data.isVariant(Variant::INT_16_MATRIX))
        return createLineSegmentItemsTemplate<int16_t>(data, properties);
    else if(data.isVariant(Variant::UINT_16_MATRIX))
        return createLineSegmentItemsTemplate<uint16_t>(data, properties);
    else if(data.isVariant(Variant::INT_32_MATRIX))
        return createLineSegmentItemsTemplate<int32_t>(data, properties);
    else if(data.isVariant(Variant::UINT_32_MATRIX))
        return createLineSegmentItemsTemplate<uint32_t>(data, properties);
    else if(data.isVariant(Variant::FLOAT_32_MATRIX))
        return createLineSegmentItemsTemplate<float>(data, properties);
    else if(data.isVariant(Variant::FLOAT_64_MATRIX))
        return createLineSegmentItemsTemplate<double>(data, properties);
    else
        return QList<QGraphicsItem*>();
}
Пример #4
0
QVariant DataConverter::toQVariant(const stromx::runtime::Data& data, const stromx::runtime::Parameter& param, int role)
{
    try
    {
        QString dataString;
        
        if (data.isVariant(stromx::runtime::DataVariant::NONE))
        {
            if(role == Qt::DisplayRole)
                return QString("None");
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::TRIGGER))
        {
            if(role == Qt::DisplayRole)
                return QString("Trigger");
            
            if(role == TriggerRole)
                return QString("Trigger");
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::BOOL))
        {
            const stromx::runtime::Bool & boolData = stromx::runtime::data_cast<stromx::runtime::Bool>(data);
                
            if(role == Qt::DisplayRole)
            {
                return bool(boolData) ? QApplication::tr("True") : QApplication::tr("False");
            }
            else if(role == Qt::EditRole)
            {
                return boolData ? 1 : 0;
            } 
            else if(role == ChoicesRole)
            {
                QStringList choices;
                
                choices.append(QApplication::tr("False"));
                choices.append(QApplication::tr("True"));
                
                return choices;
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::ENUM))
        {
            const stromx::runtime::Enum& value = stromx::runtime::data_cast<stromx::runtime::Enum>(data);
            unsigned int intValue = (unsigned int)(value);
            const std::vector<stromx::runtime::EnumDescription> & vectorEnumDesc = param.descriptions();
            
            if(role == Qt::DisplayRole)
            {
                for(std::vector<stromx::runtime::EnumDescription>::const_iterator iter_enumDesc = vectorEnumDesc.begin();
                    iter_enumDesc != vectorEnumDesc.end();
                    ++iter_enumDesc)
                {
                    if (intValue == iter_enumDesc->value())
                        return QString::fromStdString(iter_enumDesc->title());
                }
                return QString(QObject::tr("<Unknown ENUM>"));
            }
            else if(role == Qt::EditRole)
            {
                int choice = 0;
                for(std::vector<stromx::runtime::EnumDescription>::const_iterator iter_enumDesc = vectorEnumDesc.begin();
                    iter_enumDesc != vectorEnumDesc.end();
                    ++iter_enumDesc)
                {
                    if (intValue == iter_enumDesc->value())
                        return choice;
                    ++choice;
                }
                return -1;
            } 
            else if(role == ChoicesRole)
            {
                QStringList choices;
                for(std::vector<stromx::runtime::EnumDescription>::const_iterator iter_enumDesc = vectorEnumDesc.begin();
                    iter_enumDesc != vectorEnumDesc.end();
                    ++iter_enumDesc)
                {
                    choices.append(QString::fromStdString(iter_enumDesc->title()));
                }
                return choices;
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::INT_8))
        {
            if(role == Qt::DisplayRole || role == Qt::EditRole)
            {
                const stromx::runtime::Int8 & int8Data = stromx::runtime::data_cast<stromx::runtime::Int8>(data);
                return int(int8Data);
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::UINT_8))
        {
            if(role == Qt::DisplayRole || role == Qt::EditRole)
            {
                const stromx::runtime::UInt8 & uint8Data = stromx::runtime::data_cast<stromx::runtime::UInt8>(data);
                return uint(uint8Data);
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::INT_16))
        {
            if(role == Qt::DisplayRole || role == Qt::EditRole)
            {
                const stromx::runtime::Int16 & int16Data = stromx::runtime::data_cast<stromx::runtime::Int16>(data);
                return int(int16Data);
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::UINT_16))
        {
            if(role == Qt::DisplayRole || role == Qt::EditRole)
            {
                const stromx::runtime::UInt16 & uint16Data = stromx::runtime::data_cast<stromx::runtime::UInt16>(data);
                return uint(uint16Data);
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::INT_32))
        {
            if(role == Qt::DisplayRole || role == Qt::EditRole)
            {
                const stromx::runtime::Int32 & int32Data = stromx::runtime::data_cast<stromx::runtime::Int32>(data);
                return int(int32Data);
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::UINT_32))
        {
            if(role == Qt::DisplayRole || role == Qt::EditRole)
            {
                const stromx::runtime::UInt32 & uint32Data = stromx::runtime::data_cast<stromx::runtime::UInt32>(data);
                return uint(uint32Data);
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::FLOAT_32))
        {
            if(role == Qt::DisplayRole || role == Qt::EditRole)
            {
                const stromx::runtime::Float32 & floatData = stromx::runtime::data_cast<stromx::runtime::Float32>(data);
                return double(floatData);
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::FLOAT_64))
        {
            if(role == Qt::DisplayRole || role == Qt::EditRole)
            {
                const stromx::runtime::Float64 & doubleData = stromx::runtime::data_cast<stromx::runtime::Float64>(data);
                return double(doubleData);
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::STRING))
        {
            if(role == Qt::DisplayRole || role == Qt::EditRole)
            {
                const stromx::runtime::String & stringData = stromx::runtime::data_cast<stromx::runtime::String>(data);
                return QString::fromStdString(std::string(stringData));
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::IMAGE))
        {
            if(role == Qt::DisplayRole || role == ImageRole)
            {
                const stromx::runtime::Image & imageData = stromx::runtime::data_cast<stromx::runtime::Image>(data);
                return QString(QObject::tr("Width: %1 | Height: %2"))
                    .arg(imageData.width()).arg(imageData.height());
            }
        }
        
        if (data.isVariant(stromx::runtime::DataVariant::MATRIX))
        {
            if(role == Qt::DisplayRole)
            {
                const stromx::runtime::Matrix & matrixData = stromx::runtime::data_cast<stromx::runtime::Matrix>(data);
                return QString(QObject::tr("Rows: %1 | Columns: %2"))
                    .arg(matrixData.rows()).arg(matrixData.cols());
            }
            
            if(role == MatrixRole)
            {
                const stromx::runtime::Matrix & matrixData = stromx::runtime::data_cast<stromx::runtime::Matrix>(data);
                const Matrix matrix(matrixData);
                QVariant variantData;
                variantData.setValue<Matrix>(matrix);
                return variantData;
            }
        }
        
        return QVariant();
    }
    catch(stromx::runtime::BadCast&)
    {
        return QVariant();
    }  
}
Пример #5
0
bool DataConverter::stromxDataEqualsTarget(const stromx::runtime::Data& newValue, const stromx::runtime::Data& targetValue)
{
    if(! newValue.isVariant(targetValue.variant()))
        return false;
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::BOOL))
    {
        return isEqual<stromx::runtime::Bool>(newValue, targetValue);
    }
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::INT_8))
    {
        return isEqual<stromx::runtime::Int8>(newValue, targetValue);
    }
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::UINT_8))
    {
        return isEqual<stromx::runtime::UInt8>(newValue, targetValue);
    }
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::INT_16))
    {
        return isEqual<stromx::runtime::Int16>(newValue, targetValue);
    }
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::UINT_16))
    {
        return isEqual<stromx::runtime::UInt16>(newValue, targetValue);
    }
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::INT_32))
    {
        return isEqual<stromx::runtime::Int32>(newValue, targetValue);
    }
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::UINT_32))
    {
        return isEqual<stromx::runtime::UInt32>(newValue, targetValue);
    }
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::ENUM))
    {
        return isEqual<stromx::runtime::Enum>(newValue, targetValue);
    }
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::FLOAT_32))
    {
        return isEqual<stromx::runtime::Float32>(newValue, targetValue);
    }
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::FLOAT_64))
    {
        return isEqual<stromx::runtime::Float64>(newValue, targetValue);
    }
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::STRING))
    {
        return isEqual<stromx::runtime::String>(newValue, targetValue);
    }
    
    if(targetValue.isVariant(stromx::runtime::DataVariant::MATRIX))
    {
        return isEqual<stromx::runtime::Matrix>(newValue, targetValue);
    }
    
    return false;
}