Beispiel #1
0
/**
 * Appends the given list to the one held by the model.
 * @param  locList  Result information
 * @param  parent   Index under which to add the results (ignored)
 */
void LocationListModel::add(const LocationList& locList,
                            const QModelIndex& parent)
{
	(void)parent;

	locationsAdded_ = true;

	// Determine the first and last rows for the new items.
	int firstRow = locList_.size();
	int lastRow = firstRow + locList.size() - 1;
	if (lastRow < firstRow)
		return;

	// Begin row insertion.
	// This is required by QAbstractItemModel.
	beginInsertRows(QModelIndex(), firstRow, lastRow);

	// Add the entries.
	// The condition optimises for the case where the list can be internally
	// copied from one object to another.
	// Not sure whether the condition is also checked by the += operator itself
	// (probably it is, but let's be on the safe side).
	if (locList_.isEmpty())
		locList_ = locList;
	else
		locList_ += locList;

	// End row insertion.
	// This is required by QAbstractItemModel.
	endInsertRows();
}
        PeerToFinderPeerLocationFindResultPtr PeerToFinderPeerLocationFindResult::create(ElementPtr root)
        {
          PeerToFinderPeerLocationFindResultPtr ret(new message::PeerToFinderPeerLocationFindResult);

          ret->mID = IMessageHelper::getAttributeID(root);
          ret->mTime = IMessageHelper::getAttributeEpoch(root);

          ElementPtr locs = root->findFirstChildElement("locations");
          if (locs)
          {
            LocationList ll;
            ElementPtr loc = locs->findFirstChildElement("location");
            while (loc)
            {
              Location l = MessageHelper::createLocation(loc->findFirstChildElement("details"));
              l.mID = IMessageHelper::getAttributeID(loc);
              ll.push_back(l);

              loc = loc->getNextSiblingElement();
            }

            if (ll.size() > 0)
              ret->mLocations = ll;
          }

          return ret;
        }