Ejemplo n.º 1
0
void ItemsListModel::ItemDataUpdated (Item_ptr item)
{
    ItemShort is = item->ToShort ();

    items_shorts_t::iterator pos = CurrentItems_.end ();

    for (items_shorts_t::iterator i = CurrentItems_.begin (),
            end = CurrentItems_.end (); i != end; ++i)
        if (is.Title_ == i->Title_ &&
                is.URL_ == i->URL_)
        {
            pos = i;
            break;
        }

    // Item is new
    if (pos == CurrentItems_.end ())
    {
        items_shorts_t::iterator insertPos =
            std::find_if (CurrentItems_.begin (), CurrentItems_.end (),
                          FindEarlierDate (item->PubDate_));

        int shift = std::distance (CurrentItems_.begin (), insertPos);

        beginInsertRows (QModelIndex (), shift, shift);
        CurrentItems_.insert (insertPos, is);
        endInsertRows ();
    }
    // Item exists already
    else
    {
        *pos = is;

        int distance = std::distance (CurrentItems_.begin (), pos);
        emit dataChanged (index (distance, 0), index (distance, 1));
    }
}
Ejemplo n.º 2
0
	void ItemsListModel::ItemDataUpdated (Item_ptr item)
	{
		ItemShort is = item->ToShort ();

		auto pos = CurrentItems_.end ();

		for (auto i = CurrentItems_.begin (),
				end = CurrentItems_.end (); i != end; ++i)
			if (is.Title_ == i->Title_ &&
					is.URL_ == i->URL_)
			{
				pos = i;
				break;
			}

		// Item is new
		if (pos == CurrentItems_.end ())
		{
			auto insertPos = std::find_if (CurrentItems_.begin (), CurrentItems_.end (),
						[item] (const ItemShort& is) { return item->PubDate_ > is.PubDate_; });

			int shift = std::distance (CurrentItems_.begin (), insertPos);

			beginInsertRows (QModelIndex (), shift, shift);
			CurrentItems_.insert (insertPos, is);
			endInsertRows ();
		}
		// Item exists already
		else
		{
			*pos = is;

			int distance = std::distance (CurrentItems_.begin (), pos);
			emit dataChanged (index (distance, 0), index (distance, 1));
		}
	}