Skip to content

Commit acdbf8a

Browse files
author
homann
committed
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
1 parent 2435898 commit acdbf8a

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

src/app/legend/qgslegend.cpp

+36-20
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ void QgsLegend::mouseMoveEvent( QMouseEvent * e )
233233
if ( item && ( item != mItemBeingMoved ) )
234234
{
235235
QgsLegendItem::DRAG_ACTION action = dest->accept( origin );
236-
if ( action == QgsLegendItem::REORDER )
236+
if ( yCoordAboveCenter( dest, e->y() ) ) //over center of item
237237
{
238-
QgsDebugMsg( "mouseMoveEvent::REORDER" );
239238

240-
if ( !yCoordAboveCenter( dest, e->y() ) ) //over bottom of item
239+
if ( action == QgsLegendItem::REORDER || action == QgsLegendItem::INSERT )
241240
{
241+
QgsDebugMsg( "mouseMoveEvent::REORDER/INSERT top half" );
242242
if ( origin->nextSibling() != dest )
243243
{
244244
if ( origin->parent() != dest->parent() )
@@ -251,37 +251,53 @@ void QgsLegend::mouseMoveEvent( QMouseEvent * e )
251251
moveItem( dest, origin );
252252
}
253253
}
254+
setCurrentItem( origin );
254255
}
255-
else //over top of item
256+
else
256257
{
257-
if ( mItemBeingMoved != dest->nextSibling() )
258+
QgsDebugMsg( "mouseMoveEvent::NO_ACTION" );
259+
260+
if ( origin->type() == QgsLegendItem::LEGEND_LAYER_FILE && mItemBeingMovedOrigPos != getItemPos( mItemBeingMoved ) )
258261
{
259-
//origin->moveItem(dest);
260-
moveItem( origin, dest );
262+
resetToInitialPosition( mItemBeingMoved );
261263
}
264+
setCursor( QCursor( Qt::ForbiddenCursor ) );
262265
}
263-
setCurrentItem( origin );
264266
}
265-
else if ( action == QgsLegendItem::INSERT )
267+
else // below center of item
266268
{
267-
QgsDebugMsg( "mouseMoveEvent::INSERT" );
268269

269-
setCursor( QCursor( Qt::PointingHandCursor ) );
270-
if ( origin->parent() != dest )
270+
if ( action == QgsLegendItem::REORDER )
271271
{
272-
insertItem( origin, dest );
272+
QgsDebugMsg( "mouseMoveEvent::REORDER bottom half" );
273+
if ( mItemBeingMoved != dest->nextSibling() )
274+
{
275+
//origin->moveItem(dest);
276+
moveItem( origin, dest );
277+
}
273278
setCurrentItem( origin );
274279
}
275-
}
276-
else//no action
277-
{
278-
QgsDebugMsg( "mouseMoveEvent::NO_ACTION" );
280+
else if ( action == QgsLegendItem::INSERT )
281+
{
282+
QgsDebugMsg( "mouseMoveEvent::INSERT" );
279283

280-
if ( origin->type() == QgsLegendItem::LEGEND_LAYER_FILE && mItemBeingMovedOrigPos != getItemPos( mItemBeingMoved ) )
284+
setCursor( QCursor( Qt::PointingHandCursor ) );
285+
if ( origin->parent() != dest )
286+
{
287+
insertItem( origin, dest );
288+
setCurrentItem( origin );
289+
}
290+
}
291+
else//no action
281292
{
282-
resetToInitialPosition( mItemBeingMoved );
293+
QgsDebugMsg( "mouseMoveEvent::NO_ACTION" );
294+
295+
if ( origin->type() == QgsLegendItem::LEGEND_LAYER_FILE && mItemBeingMovedOrigPos != getItemPos( mItemBeingMoved ) )
296+
{
297+
resetToInitialPosition( mItemBeingMoved );
298+
}
299+
setCursor( QCursor( Qt::ForbiddenCursor ) );
283300
}
284-
setCursor( QCursor( Qt::ForbiddenCursor ) );
285301
}
286302
}
287303
}

src/app/legend/qgslegendgroup.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ bool QgsLegendGroup::insert( QgsLegendItem* theItem )
100100
{
101101
if ( theItem->type() == LEGEND_LAYER )
102102
{
103-
addChild( theItem );
103+
// Always insert at top of list
104+
insertChild( 0, theItem );
104105
}
105106
// XXX - mloskot - I don't know what to return
106107
// but this function must return a value

0 commit comments

Comments
 (0)