Exemple #1
0
    /**
     * @brief SignatureMaker::makeType
     * @param type
     * @return
     */
    QString SignatureMaker::makeType(const Entity::SharedType &type) const
    {
        if (!type)
            return "";

        QString result;

        QStringList scopes;
        auto scopeId = type->scopeId();
        QSet<Common::ID> forbidden = {Common::ID::projectScopeID(),
                                            Common::ID::globalScopeID(),
                                            Common::ID::localTemplateScopeID()};
        while (!globalIds.contains(scopeId)) {
            if (auto scope = findScope(scopeId)) {
                if (!scope->name().isEmpty() && !forbidden.contains(scopeId))
                    scopes.prepend(scope->name());
                scopeId = scope->scopeId();
            } else {
                return "";
            }
        }

        scopes.removeAll("");
        if (!scopes.isEmpty())
            result.prepend(scopes.join("::").append("::"));

        result.append(type->name());

        return result;
    }
Exemple #2
0
    /**
     * @brief SignatureMaker::makeTypeOrExt
     * @param type
     * @return
     */
    QString SignatureMaker::makeTypeOrExtType(const Entity::SharedType &type) const
    {
        if (!type)
            return "";

        if (type->hashType() == Entity::ExtendedType::staticHashType())
            // Return extended type which may be alias (with optioanl *, &, const)
            return makeExtType(std::static_pointer_cast<Entity::ExtendedType>(type));
        else
            // Or return name (with namespaces) of type, class, enum or union
            return makeType(type);
    }
 /**
  * @brief MoveTypeToOtherScope::MoveTypeToOtherScope
  * @param type
  * @param appModel
  * @param srcScope
  * @param dstScope
  * @param parent
  */
 MoveTypeToOtherScope::MoveTypeToOtherScope(const entity::SharedType &type,
                                            const models::SharedApplicationModel &appModel,
                                            const entity::SharedScope &srcScope,
                                            const entity::SharedScope &dstScope,
                                            QUndoCommand *parent)
     : BaseCommand(tr("Move \"%1\" from \"%2\" to \"%3\".").arg(type->name(), srcScope->name(), dstScope->name()),
                   parent)
     , m_Type(type)
     , m_SrcScope(srcScope)
     , m_DstScope(dstScope)
     , m_Model(appModel)
 {
 }
Exemple #4
0
    /**
     * @brief scopesNamesList
     * @param type
     * @param db
     * @return
     */
    QStringList scopesNamesList(const entity::SharedType &type, const db::SharedDatabase &db)
    {
        QStringList result;
        entity::SharedScope scope(db->depthScopeSearch(type->scopeId()));
        QString id(scope ? scope->id() : GLOBAL_SCOPE_ID);

        while (scope && id != GLOBAL_SCOPE_ID) {
            result << scope->name();
            id = scope->parentScopeId();
            scope = db->depthScopeSearch(id);
        }

        return result;
    }
/**
 * @brief EditEntityDialog::setData
 * @param model
 * @param id
 */
void EditEntityDialog::setData(const models::SharedApplicationModel &model, const entity::SharedType &type)
{
    Q_ASSERT(model);
    Q_ASSERT(type);

    m_ApplicationModel = model;
    m_Project = m_ApplicationModel->currentProject();
    m_Scope = m_Project->database()->getScope(type->scopeId());
    m_Type = type;

    components::ComponentsMaker &maker = m_SignatureEditDelegate->maker();
    maker.setModel(m_ApplicationModel);
    maker.setScope(m_Scope);
    maker.setEntity(m_Type);

    // Temporary {
    if (m_Type->hashType() == entity::Class::staticHashType()) {
        auto cl = std::static_pointer_cast<entity::Class>(m_Type);

        if (cl->methods().isEmpty()) {
            auto intType = m_Scope->addType("int");
            auto doubleType = m_Scope->addType("double");

            cl->makeMethod("foo")->setReturnTypeId(intType->id());
            cl->makeMethod("bar")->setReturnTypeId(doubleType->id());
            cl->makeMethod("baz");
        }

        if (cl->fields().isEmpty()) {
            cl->addField("f1", "stub");
            cl->addField("f2", "stub");
        }
    }
    // }

    auto signatureMaker = std::make_unique<translation::SignatureMaker>(
                              m_ApplicationModel->globalDatabase(), m_Project->database(),
                              m_Scope, m_Type
                          );
    m_ComponentsModel->setSignatureMaker(std::move(signatureMaker));
    m_ComponentsModel->setComponents(m_Type);

    fillMaps();
}
Exemple #6
0
    /**
     * @brief ProjectTreeModel::addType
     * @param type
     * @param scopeId
     * @param projectId
     */
    void ProjectTreeModel::addType(const entity::SharedType &type, const common::ID &scopeID,
                                   const QString &projectName)
    {
        if (auto &&pr = find(projectName)) {
            auto &&projectIndex = index(indexOf(pr), 0);
            Q_ASSERT(projectIndex.isValid());

            if (auto &&scope = pr->itemById(QVariant::fromValue(scopeID))) {
                auto &&scopeIndex = projectIndex.child(pr->rowForItem(scope), 0);
                Q_ASSERT(scopeIndex.isValid());

                auto pos = scopeIndex.row() + 1;
                beginInsertRows(scopeIndex, pos, pos);
                auto &&newItem = scope->makeChild(QVariant::fromValue(type), TreeItemType::TypeItem);
                endInsertRows();

                observeItemChanging(m_CurrentProject, type.get(), newItem);
            }
        }
    }