Exemple #1
0
void Clean_tree_view::keyPressEvent(QKeyEvent* ev)
{
	if (ev->key() == Qt::Key_Delete)
	{
		QModelIndexList indexes = selectedIndexes();
		int row = -1;
		int first_row = -1;
		for (QModelIndexList::iterator i = indexes.begin(); i != indexes.end(); ++i)
		{
			if (row != i->row())
			{
				row = i->row();

				if (first_row == -1)
					first_row = i->row();

				model()->removeRow(i->row(), i->parent());
			}
		}
		// All rows removed

		// Now select the new one selected row for fast massive deleting
		if (first_row != -1)
		{
			selectionModel()->select(model()->index(first_row, 0, QModelIndex()), 
				QItemSelectionModel::Select);
		}

		emit clean_updated();
	}
}
QModelIndexList SearchWidget::removeHiddenItems(QModelIndexList& items){
	QModelIndexList toReturn;
	for(QModelIndexList::iterator it = items.begin(); it != items.end(); ++it){
		if(!treeView->isRowHidden(it->row(), it->parent())){
			toReturn.append(*it);
		}
	}
	return toReturn;
}