Exemple #1
0
static void setupCompilerPathByLanguage(Profile &profile, const QStringList &toolchainTypes,
        const QString &toolchainInstallPath, const QString &toolchainPrefix)
{
    QVariantMap m;
    if (toolchainTypes.contains(QLatin1String("clang"))) {
        m[QLatin1String("c")] = m[QLatin1String("objc")] = QLatin1String("clang");
        m[QLatin1String("cpp")] = m[QLatin1String("objcpp")] = QLatin1String("clang++");
    } else if (toolchainTypes.contains(QLatin1String("gcc"))) {
        m[QLatin1String("c")] = m[QLatin1String("objc")] = QLatin1String("gcc");
        m[QLatin1String("cpp")] = m[QLatin1String("objcpp")] = QLatin1String("g++");
    } else {
        qDebug("WARNING: unexpected toolchain %s", qPrintable(toJSLiteral(toolchainTypes)));
        return;
    }

    const QString toolchainPathPrefix = toolchainInstallPath + QLatin1Char('/') + toolchainPrefix;
    for (QVariantMap::iterator it = m.begin(); it != m.end();) {
        const QString filePath = HostOsInfo::appendExecutableSuffix(toolchainPathPrefix
                                                                    + it.value().toString());
        if (QFile::exists(filePath)) {
            it.value() = filePath;
            ++it;
            continue;
        }
        qDebug("WARNING: Compiler %s for file tag %s not found.",
               qPrintable(QDir::toNativeSeparators(filePath)), qPrintable(it.key()));
        it = m.erase(it);
    }
    if (!m.isEmpty())
        profile.setValue(QLatin1String("cpp.compilerPathByLanguage"), m);
}
QVariantMap Decision::canonicalizeOpinions(QVariantMap opinions)
{
    auto itr = opinions.begin();
    while (itr != opinions.end())
        if (itr.value().toInt() == 0)
            itr = opinions.erase(itr);
        else
            ++itr;
    return opinions;
}
    void PrefabSystem::updatePrefab(const QString& path, const QVariantMap& newcomponents, bool updateInstances)
    {
        // fetch prefab by path
        Prefab* prefab;
        {
            auto i = _prefabs.find(path);
            if(i == _prefabs.end())
            {
                return;
            }
            prefab = i.value().data();
        }

        for(auto k: newcomponents.keys())
        {
            qDebug() << "Receeived: " << k;
        }

        if(updateInstances)
        {

            // update existing components in prefab and delete components no longer in prefab
            for(auto j = prefab->components().begin(); j != prefab->components().end(); ++j)
            {
                EntitySystem* es = entityManager()->system(j.key());
                Q_ASSERT(es);
                if(!es) continue;

                // component is in prefab but not in components map. Delete it from prefab instances.
                if(newcomponents.find(j.key()) == newcomponents.end())
                {
                    qDebug() << "Removing from prefab instances:" << j.key();
                    // find all prefab instances and destroy the component
                    for(auto k = this->begin(); k != this->end(); ++k)
                    {
                        PrefabInstance* pi = static_cast<PrefabInstance*>(k->second);
                        if(pi->prefab() == prefab)
                        {
                            es->destroyComponent(k->first);
                        }
                    }
                }
                else
                {
                    // component exists in component map and in prefab. Update prefab.
                    QVariantMap newvals = newcomponents[j.key()].toMap();
                    
                    // find all prefab instances and update the components
                    for(auto k = this->begin(); k != this->end(); ++k)
                    {
                        PrefabInstance* pi = static_cast<PrefabInstance*>(k->second);
                        if(pi->prefab() == prefab)
                        {
                            QVariantMap data = es->toVariantMap(k->first);
                            for(auto i = newvals.begin(); i != newvals.end(); ++i)
                            {
                                data[i.key()] = i.value();
                            }

                            auto i = data.begin();
                            while(i != data.end())
                            {
                                if(prefab->parameters().contains(i.key()) || i.key() == "objectName")
                                {
                                    i = data.erase(i);
                                }
                                else
                                {
                                    ++i;
                                }
                            }
                            es->fromVariantMap(k->first, data);
                        }
                    }
                }
            }

            // now handle the components that did not exist in prefab yet

            for(auto i = newcomponents.begin(); i != newcomponents.end(); ++i)
            {
                QString key = i.key();
                if(prefab->components().find(key) == prefab->components().end())
                {
                    EntitySystem* es = entityManager()->system(key);
                    Q_ASSERT(es);
                    if(!es) continue;
                    for(auto k = this->begin(); k != this->end(); ++k)
                    {
                        PrefabInstance* pi = static_cast<PrefabInstance*>(k->second);
                        if(pi->prefab() == prefab)
                        {
                            es->createComponent(k->first, i.value().toMap());
                        }
                    }
                }
            }
        }

        // finally update prefab in prefab store
        prefab->setComponents(newcomponents);
        emit prefabUpdated(path);
    }