Files
pilotclient/src/blackmisc/avaircraftlist.cpp
Klaus Basan ce86c902b5 Upfront of refs #369
* consolidated ICoordinateGeodetic (e.g. fixed nested properties)
* shifted common functionality for objects/containers with callsign into interface
* shifted common functionality for objects/containers with geo position into interface
* shifted common functionality for objects/containers with timestamp into interface
* updated corresponding value objects / specialized lists
* adjusted all places where renamed functions are used
2015-03-20 16:30:18 +01:00

83 lines
3.2 KiB
C++

/* Copyright (C) 2013
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "avaircraftlist.h"
#include "nwuser.h"
#include "predicates.h"
#include "propertyindexallclasses.h"
using namespace BlackMisc;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Network;
namespace BlackMisc
{
namespace Aviation
{
/*
* Default constructor
*/
CAircraftList::CAircraftList() { }
/*
* Construct from base class object
*/
CAircraftList::CAircraftList(const CSequence<CAircraft> &other) :
CSequence<CAircraft>(other)
{ }
/*
* Register metadata
*/
void CAircraftList::registerMetadata()
{
qRegisterMetaType<BlackMisc::CSequence<CAircraft>>();
qDBusRegisterMetaType<BlackMisc::CSequence<CAircraft>>();
qRegisterMetaType<BlackMisc::CCollection<CAircraft>>();
qDBusRegisterMetaType<BlackMisc::CCollection<CAircraft>>();
qRegisterMetaType<CAircraftList>();
qDBusRegisterMetaType<CAircraftList>();
registerMetaValueType<CAircraftList>();
}
/*
* All pilots
*/
CUserList CAircraftList::getPilots() const
{
return this->findBy(Predicates::MemberValid(&CAircraft::getPilot)).transform(Predicates::MemberTransform(&CAircraft::getPilot));
}
/*
* Merge with aircraft
*/
bool CAircraftList::updateWithVatsimDataFileData(CAircraft &aircraftToBeUpdated) const
{
if (this->isEmpty()) return false;
if (aircraftToBeUpdated.hasValidRealName() && aircraftToBeUpdated.hasValidId() && aircraftToBeUpdated.hasValidAircraftAndAirlineDesignator()) return false;
CAircraft currentDataFileAircraft = this->findFirstByCallsign(aircraftToBeUpdated.getCallsign());
if (currentDataFileAircraft.getCallsign().isEmpty()) return false;
CUser user = aircraftToBeUpdated.getPilot();
if (!aircraftToBeUpdated.hasValidRealName()) user.setRealName(currentDataFileAircraft.getPilotRealname());
if (!aircraftToBeUpdated.hasValidId()) user.setId(currentDataFileAircraft.getPilotId());
aircraftToBeUpdated.setPilot(user);
CAircraftIcao icao = aircraftToBeUpdated.getIcaoInfo();
CAircraftIcao dataFileIcao = currentDataFileAircraft.getIcaoInfo();
if (!icao.hasAircraftDesignator()) icao.setAircraftDesignator(dataFileIcao.getAircraftDesignator());
if (!icao.hasAirlineDesignator()) icao.setAirlineDesignator(dataFileIcao.getAirlineDesignator());
if (!icao.hasAircraftCombinedType()) icao.setAircraftCombinedType(dataFileIcao.getAircraftCombinedType());
aircraftToBeUpdated.setIcaoInfo(icao);
return true;
}
} // namespace
} // namespace