Пример #1
0
    /**
     * @brief Database::load
     * @param errorList
     */
    void Database::load(ErrorList &errorList)
    {
        QFile f(makeFullPath());
        if (f.open(QIODevice::ReadOnly)) {
            QJsonParseError errorMessage;
            QJsonDocument jdoc(QJsonDocument::fromJson(f.readAll(), &errorMessage));

            if (errorMessage.error == QJsonParseError::NoError) {
                fromJson(jdoc.object(), errorList);
            } else {
                errorList << errorMessage.errorString();
            }
        } else {
            errorList << QObject::tr("Can't load database: %1.").arg(f.fileName());
        }

        m_Valid = errorList.isEmpty();
    }
Пример #2
0
    /**
     * @brief RelationFactory::make
     * @param src
     * @param addToScene
     * @return
     */
    SharedRelation RelationFactory::make(const QJsonObject &src, ErrorList &errors,
                                         CreationOptions options) const
    {
        if (src.contains(relationship::Relation::typeMarker())) {
            auto relType = RelationType(src[relationship::Relation::typeMarker()].toInt());
            if (auto maker = G_ASSERT(relationMaker[relType])) {
                db::WeakTypeSearchers ts {G_ASSERT(project())->database(), G_ASSERT(project())->globalDatabase()};
                if (auto relation = maker(common::ID::nullID(), common::ID::nullID(), ts)) {
                    relation->fromJson(src, errors);

                    if (errors.isEmpty()) {
                        addRelation(relation, G_ASSERT(project())->database(), scene(), options);
                        return relation;
                    } else {
                        qWarning() << "Relation was loaded with errors.";
                    }
                }
            }
        }

        return nullptr;
    }