#include "stdafx.h"
#include "Location.h"

LocationWrapper* LocationWrapper::createWrapper(const AutoPopulatedLocation* location)
{
  const Map* map = dynamic_cast<const Map*>(location);
  if (map != NULL)
  {
    return new LocationDecompositionWrapper(map);
  }
  else
  {
    return new LocationDisplayUnitsWrapper(location);
  }
}

void LocationWrapper::displayIn(QTreeWidgetItemKey* item) const
{
  item->setText(0, m_name);
  item->setExpanded(true);
}

void LocationDisplayUnitsWrapper::displayIn(QTreeWidgetItemKey* item) const
{
  LocationWrapper::displayIn(item);
  for (std::list<UnitRecordWrapper>::const_iterator it = m_units.begin(); it != m_units.end(); ++it)
  {
    const UnitRecordWrapper& unit = *it;
    unit.display(item);
  }    
}

void LocationDecompositionWrapper::displayIn(QTreeWidgetItemKey* item) const
{
  LocationWrapper::displayIn(item);
  for (std::vector<LocationWrapper*>::const_iterator itLocation = m_childLocations.begin(); itLocation != m_childLocations.end(); ++itLocation)
  {
    const LocationWrapper* childLocation = *itLocation;
    childLocation->display(item);
  }
}