当前位置: 首页>>代码示例>>C++>>正文


C++ SolarSystem::addHeavenlyBody方法代码示例

本文整理汇总了C++中SolarSystem::addHeavenlyBody方法的典型用法代码示例。如果您正苦于以下问题:C++ SolarSystem::addHeavenlyBody方法的具体用法?C++ SolarSystem::addHeavenlyBody怎么用?C++ SolarSystem::addHeavenlyBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SolarSystem的用法示例。


在下文中一共展示了SolarSystem::addHeavenlyBody方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SqlQueryException

/*!
 \brief Create a list of all solar systems stored in the database.

 \return QList<HeavenlyBody *> List of all stored solar systems including all data.
*/
QList<SolarSystem *> SolarSystemRepository::fetchAllSolarSystemEntities()
{
    QSqlQuery solarSystemQuery;
    solarSystemQuery.prepare("SELECT"
                             "     solarsystemid, "
                             "     solarsystem.name, "
                             "     heavenlybodyid, "
                             "     heavenlybody.name, "
                             "     diameter, "
                             "     color, "
                             "     type "
                             "FROM "
                             "     solarsystem "
                             "INNER JOIN "
                             "     heavenlybody "
                             "ON "
                             "     centralstarid = heavenlybodyid "
                             "ORDER BY "
                             "     solarsystem.name, "
                             "     solarsystemid");

    if (!solarSystemQuery.exec())
    {
        throw SqlQueryException("The solar system entities could not be retrieved!",
                                solarSystemQuery.lastError().text());
    }

    QList<SolarSystem *> entities;

    QSqlQuery innerQuery;
    innerQuery.prepare("SELECT"
                  "     excentricity, "
                  "     semimajoraxis, "
                  "     angle, "
                  "     orbitalplaneangle, "
                  "     heavenlybody.heavenlybodyid, "
                  "     heavenlybody.name, "
                  "     diameter, "
                  "     color, "
                  "     type "
                  "FROM "
                  "     solarsystemtoheavenlybody "
                  "INNER JOIN "
                  "     heavenlybody "
                  "ON "
                  "     solarsystemtoheavenlybody.heavenlybodyid = heavenlybody.heavenlybodyid "
                  "WHERE "
                  "     solarsystemid = :solarsystemid "
                  "ORDER BY "
                  "     semimajoraxis");

    while (solarSystemQuery.next())
    {
        // The solar system data.
        qint64 solarSystemId = solarSystemQuery.value(0).toLongLong();
        QString solarSystemName = solarSystemQuery.value(1).toString();

        // The central star data.
        qint64 id = solarSystemQuery.value(2).toLongLong();
        QString name = solarSystemQuery.value(3).toString();
        int diameter = solarSystemQuery.value(4).toInt();
        QString color = solarSystemQuery.value(5).toString();
        QString type = solarSystemQuery.value(6).toString();

        SolarSystem *solarSystem = new SolarSystem(solarSystemId,
                                                   solarSystemName,
                                                   new HeavenlyBody(id, name, diameter, color, type));

        innerQuery.bindValue(":solarsystemid", solarSystemId);

        // If there was an error in the inner query the _complete_ execution is canceled here!
        if (!innerQuery.exec())
        {
            throw SqlQueryException("The solar system heavenly bodies could not be retrieved!",
                                    innerQuery.lastError().text());
        }

        while (innerQuery.next())
        {
            // The planet within the solar system.
            SolarSystemHeavenlyBody *solarSystemHeavenlyBody = new SolarSystemHeavenlyBody(
                        new HeavenlyBody(innerQuery.value(4).toLongLong(),
                                         innerQuery.value(5).toString(),
                                         innerQuery.value(6).toInt(),
                                         innerQuery.value(7).toString(),
                                         innerQuery.value(8).toString()),
                        innerQuery.value(0).toDouble(),
                        innerQuery.value(1).toDouble(),
                        innerQuery.value(2).toDouble(),
                        innerQuery.value(3).toDouble());

            solarSystem->addHeavenlyBody(solarSystemHeavenlyBody);
        }

        entities.append(solarSystem);
//.........这里部分代码省略.........
开发者ID:fdeitelhoff,项目名称:SolarSystemSimulation,代码行数:101,代码来源:solarsystemrepository.cpp


注:本文中的SolarSystem::addHeavenlyBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。