QModelIndex CObjectModel::parent(const QModelIndex &child) const
{
	if ( !child.isValid() ) { return QModelIndex() ; }
	ObjectItem *c = static_cast<ObjectItem *>(child.internalPointer()) ;
	ObjectItem *p = c->parent() ;
	if ( p == m_pRoot || c == m_pRoot ) { return QModelIndex() ; }
	return createIndex(p->row(), 0, p) ;
}
Example #2
0
bool ObjectContainer::remove(int id)
{
	ObjectItem* item = getItem(id);
	if (!item)
	{
		StaticLogger::logit("WARNING: Object not removed! The object with id '" + QString::number(id) + "' does not exist.");
		return false;
	}

	QJsonObject json = item->data().toJsonObject();
	m_model.removeRow(item->row());
	m_ids.erase(json["id"].toInt());

	return true;
}