Skip to content

Commit

Permalink
fixed ticket 437, crash when the first item is deleted and recreated
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6250 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Dec 13, 2006
1 parent 8d0e068 commit 701011c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/plugins/grass/qgsgrassmodel.cpp
Expand Up @@ -456,6 +456,7 @@ QString QgsGrassModelItem::uri ()

QgsGrassModelItem *QgsGrassModelItem::child ( int i )
{
Q_ASSERT(i >= 0 );
Q_ASSERT(i < mChildren.size());
//return &(mChildren[i]);
return mChildren[i];
Expand Down Expand Up @@ -592,7 +593,7 @@ void QgsGrassModel::addItems(QgsGrassModelItem *item, QStringList list, int type

if ( insertAt >= 0 )
{
std::cerr << "-> add " << name.ascii() << std::endl;
std::cerr << "insert " << name.ascii() << " at " << insertAt << std::endl;
beginInsertRows( index, insertAt, insertAt );
QgsGrassModelItem *newItem = new QgsGrassModelItem();
item->mChildren.insert( insertAt, newItem );
Expand Down Expand Up @@ -739,6 +740,12 @@ QModelIndex QgsGrassModel::index( int row, int column,
{
//std::cerr << "QgsGrassModel::index row = " << row
// << " column = " << column << std::endl;

// It is strange(?) but Qt can call this method with row < 0
// for example if beginInsertRows(,0,0) is called and the first
// item was previously deleted => check if row < 0
// and return empty QModelIndex, but is it correct?
if ( row < 0 ) return QModelIndex ();

QgsGrassModelItem *item;
if (!parent.isValid()) {
Expand Down

0 comments on commit 701011c

Please sign in to comment.