Trying to fix the very erratic reordering of layer legend, by only using INSERT in lower half of layer group, and also inserting item first in child list

git-svn-id: http://svn.osgeo.org/qgis/trunk@9547 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
homann 2008-10-25 18:37:06 +00:00
parent 243589896e
commit acdbf8af6f
2 changed files with 41 additions and 24 deletions

View File

@ -233,12 +233,12 @@ void QgsLegend::mouseMoveEvent( QMouseEvent * e )
if ( item && ( item != mItemBeingMoved ) )
{
QgsLegendItem::DRAG_ACTION action = dest->accept( origin );
if ( action == QgsLegendItem::REORDER )
if ( yCoordAboveCenter( dest, e->y() ) ) //over center of item
{
QgsDebugMsg( "mouseMoveEvent::REORDER" );
if ( !yCoordAboveCenter( dest, e->y() ) ) //over bottom of item
if ( action == QgsLegendItem::REORDER || action == QgsLegendItem::INSERT )
{
QgsDebugMsg( "mouseMoveEvent::REORDER/INSERT top half" );
if ( origin->nextSibling() != dest )
{
if ( origin->parent() != dest->parent() )
@ -251,37 +251,53 @@ void QgsLegend::mouseMoveEvent( QMouseEvent * e )
moveItem( dest, origin );
}
}
setCurrentItem( origin );
}
else //over top of item
else
{
QgsDebugMsg( "mouseMoveEvent::NO_ACTION" );
if ( origin->type() == QgsLegendItem::LEGEND_LAYER_FILE && mItemBeingMovedOrigPos != getItemPos( mItemBeingMoved ) )
{
resetToInitialPosition( mItemBeingMoved );
}
setCursor( QCursor( Qt::ForbiddenCursor ) );
}
}
else // below center of item
{
if ( action == QgsLegendItem::REORDER )
{
QgsDebugMsg( "mouseMoveEvent::REORDER bottom half" );
if ( mItemBeingMoved != dest->nextSibling() )
{
//origin->moveItem(dest);
moveItem( origin, dest );
}
}
setCurrentItem( origin );
}
else if ( action == QgsLegendItem::INSERT )
{
QgsDebugMsg( "mouseMoveEvent::INSERT" );
setCursor( QCursor( Qt::PointingHandCursor ) );
if ( origin->parent() != dest )
{
insertItem( origin, dest );
setCurrentItem( origin );
}
}
else//no action
{
QgsDebugMsg( "mouseMoveEvent::NO_ACTION" );
if ( origin->type() == QgsLegendItem::LEGEND_LAYER_FILE && mItemBeingMovedOrigPos != getItemPos( mItemBeingMoved ) )
else if ( action == QgsLegendItem::INSERT )
{
resetToInitialPosition( mItemBeingMoved );
QgsDebugMsg( "mouseMoveEvent::INSERT" );
setCursor( QCursor( Qt::PointingHandCursor ) );
if ( origin->parent() != dest )
{
insertItem( origin, dest );
setCurrentItem( origin );
}
}
else//no action
{
QgsDebugMsg( "mouseMoveEvent::NO_ACTION" );
if ( origin->type() == QgsLegendItem::LEGEND_LAYER_FILE && mItemBeingMovedOrigPos != getItemPos( mItemBeingMoved ) )
{
resetToInitialPosition( mItemBeingMoved );
}
setCursor( QCursor( Qt::ForbiddenCursor ) );
}
setCursor( QCursor( Qt::ForbiddenCursor ) );
}
}
}

View File

@ -100,7 +100,8 @@ bool QgsLegendGroup::insert( QgsLegendItem* theItem )
{
if ( theItem->type() == LEGEND_LAYER )
{
addChild( theItem );
// Always insert at top of list
insertChild( 0, theItem );
}
// XXX - mloskot - I don't know what to return
// but this function must return a value