Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Trying to fix the very erratic reordering of layer legend, by only us…
…ing INSERT in lower half of layer group, and also inserting item first in child list

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9547 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann committed Oct 25, 2008
1 parent a776092 commit c94f87b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
56 changes: 36 additions & 20 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -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() )
Expand All @@ -251,37 +251,53 @@ void QgsLegend::mouseMoveEvent( QMouseEvent * e )
moveItem( dest, origin );
}
}
setCurrentItem( origin );
}
else //over top of item
else
{
if ( mItemBeingMoved != dest->nextSibling() )
QgsDebugMsg( "mouseMoveEvent::NO_ACTION" );

if ( origin->type() == QgsLegendItem::LEGEND_LAYER_FILE && mItemBeingMovedOrigPos != getItemPos( mItemBeingMoved ) )
{
//origin->moveItem(dest);
moveItem( origin, dest );
resetToInitialPosition( mItemBeingMoved );
}
setCursor( QCursor( Qt::ForbiddenCursor ) );
}
setCurrentItem( origin );
}
else if ( action == QgsLegendItem::INSERT )
else // below center of item
{
QgsDebugMsg( "mouseMoveEvent::INSERT" );

setCursor( QCursor( Qt::PointingHandCursor ) );
if ( origin->parent() != dest )
if ( action == QgsLegendItem::REORDER )
{
insertItem( origin, dest );
QgsDebugMsg( "mouseMoveEvent::REORDER bottom half" );
if ( mItemBeingMoved != dest->nextSibling() )
{
//origin->moveItem(dest);
moveItem( origin, dest );
}
setCurrentItem( origin );
}
}
else//no action
{
QgsDebugMsg( "mouseMoveEvent::NO_ACTION" );
else if ( action == QgsLegendItem::INSERT )
{
QgsDebugMsg( "mouseMoveEvent::INSERT" );

if ( origin->type() == QgsLegendItem::LEGEND_LAYER_FILE && mItemBeingMovedOrigPos != getItemPos( mItemBeingMoved ) )
setCursor( QCursor( Qt::PointingHandCursor ) );
if ( origin->parent() != dest )
{
insertItem( origin, dest );
setCurrentItem( origin );
}
}
else//no action
{
resetToInitialPosition( mItemBeingMoved );
QgsDebugMsg( "mouseMoveEvent::NO_ACTION" );

if ( origin->type() == QgsLegendItem::LEGEND_LAYER_FILE && mItemBeingMovedOrigPos != getItemPos( mItemBeingMoved ) )
{
resetToInitialPosition( mItemBeingMoved );
}
setCursor( QCursor( Qt::ForbiddenCursor ) );
}
setCursor( QCursor( Qt::ForbiddenCursor ) );
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/legend/qgslegendgroup.cpp
Expand Up @@ -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
Expand Down

0 comments on commit c94f87b

Please sign in to comment.