Exemplo n.º 1
0
void ItemDocument::slotUpdateZOrdering() {

	{ //begin WORKAROUND
 // remove zeros, Where are these zeros coming from??? they shouldn't be here!!!
		ItemMap::iterator end = m_itemList.end();
		ItemMap::iterator it = m_itemList.begin();

		while(it != end) {
			if(!(it->second)) {
				ItemMap::iterator toRemove = it; 
				it++;
				m_itemList.erase(toRemove);
			} else it++;
		}
	} //END WORKAROUND

	ItemMap toAdd = m_itemList;

	IntItemMap newZOrder;
	int atLevel = 0;

	IntItemMap::iterator zEnd = m_zOrder.end();
	for (IntItemMap::iterator it = m_zOrder.begin(); it != zEnd; ++it) {
		Item *item = it->second;

assert(item->itemDocument() == this); 

		toAdd.erase(item->id());

		if (!item->parentItem() && item->isMovable())
			newZOrder[atLevel++] = item;
	}

	{
		ItemMap::iterator addEnd = toAdd.end();
		for (ItemMap::iterator it = toAdd.begin(); it != addEnd; ++it) {
			Item *item = it->second;
assert(item && item->itemDocument() == this);
			if (item->parentItem() || !item->isMovable())
				continue;

			newZOrder[atLevel++] = item;
		}
	}

	m_zOrder = newZOrder;

	for (IntItemMap::iterator it = m_zOrder.begin(); it != zEnd; ++it)
		it->second->updateZ(it->first); // valgrind says there's a FIXME here. =\ "invalid read of size 4"
}
Exemplo n.º 2
0
void WAbstractProxyModel::shiftModelIndexes(const WModelIndex& sourceParent,
					    int start, int count,
					    ItemMap& items)
{
  /*
   * We must shift all indexes within sourceParent >= start with count
   * and delete items when count < 0.
   */
  std::vector<BaseItem *> shifted;
  std::vector<BaseItem *> erased;

  for (ItemMap::iterator it
	 = items.lower_bound(sourceModel()->index(start, 0, sourceParent));
       it != items.end();) {
#ifndef WT_TARGET_JAVA
    ItemMap::iterator n = it;
    ++n;
#endif
    WModelIndex i = it->first;

    if (i.isValid()) {
      WModelIndex p = i.parent();
      if (p != sourceParent && !WModelIndex::isAncestor(p, sourceParent))
	break;

      if (p == sourceParent) {
	shifted.push_back(it->second);
      } else if (count < 0) {
	// delete indexes that are about to be deleted, if they are within
	// the range of deleted indexes
	do {
	  if (p.parent() == sourceParent
	      && p.row() >= start
	      && p.row() < start - count) {
	    erased.push_back(it->second);
	    break;
	  } else
	    p = p.parent();
	} while (p != sourceParent);
      }
    }

#ifndef WT_TARGET_JAVA
    it = n;
#endif
  }

  for (unsigned i = 0; i < erased.size(); ++i) {
    items.erase(erased[i]->sourceIndex_);
    delete erased[i];
  }

  for (unsigned i = 0; i < shifted.size(); ++i) {
    BaseItem *item = shifted[i];
    items.erase(item->sourceIndex_);
    if (item->sourceIndex_.row() + count >= start) {
      item->sourceIndex_ = sourceModel()->index
	(item->sourceIndex_.row() + count,
	 item->sourceIndex_.column(),
	 sourceParent);
    } else {
      delete item;
      shifted[i] = 0;
    }
  }

  for (unsigned i = 0; i < shifted.size(); ++i) {
    if (shifted[i])
      items[shifted[i]->sourceIndex_] = shifted[i];
  }
}