本文整理汇总了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);
//.........这里部分代码省略.........