Skip to content

Commit 23f9055

Browse files
author
jef
committed
improve dragging legend layers
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14704 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c2a400a commit 23f9055

File tree

2 files changed

+54
-42
lines changed

2 files changed

+54
-42
lines changed

ms-windows/osgeo4w/package.cmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ touch exclude
147147

148148
tar -C %OSGEO4W_ROOT% -cjf %PACKAGENAME%-%VERSION%-%PACKAGE%.tar.bz2 ^
149149
--exclude-from exclude ^
150+
--exclude "*.pyc" ^
150151
--exclude "apps/%PACKAGENAME%/themes/classic/grass" ^
151152
--exclude "apps/%PACKAGENAME%/themes/default/grass" ^
152153
--exclude "apps/%PACKAGENAME%/themes/qgis/grass" ^
@@ -162,8 +163,9 @@ tar -C %OSGEO4W_ROOT% -cjf %PACKAGENAME%-%VERSION%-%PACKAGE%.tar.bz2 ^
162163
>>%LOG% 2>&1
163164
if errorlevel 1 goto error
164165

165-
tar -C %OSGEO4W_ROOT% -cjf %PACKAGENAME%-grass-%VERSION%-%PACKAGE%.tar.bz2 ^
166+
tar -C %OSGEO4W_ROOT% -cjf %PACKAGENAME%-grass-plugin-%VERSION%-%PACKAGE%.tar.bz2 ^
166167
--exclude-from exclude ^
168+
--exclude "*.pyc" \
167169
"apps/%PACKAGENAME%/themes/classic/grass" ^
168170
"apps/%PACKAGENAME%/themes/default/grass" ^
169171
"apps/%PACKAGENAME%/themes/gis/grass" ^

src/app/legend/qgslegend.cpp

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ static const char *const ident_ = "$Id$";
4848
const int AUTOSCROLL_MARGIN = 16;
4949

5050
QgsLegend::QgsLegend( QgsMapCanvas *canvas, QWidget * parent, const char *name )
51-
: QTreeWidget( parent )
52-
, mMousePressedFlag( false )
53-
, mMapCanvas( canvas )
54-
, mMinimumIconSize( 20, 20 )
55-
, mChanging( false )
51+
: QTreeWidget( parent )
52+
, mMousePressedFlag( false )
53+
, mMapCanvas( canvas )
54+
, mMinimumIconSize( 20, 20 )
55+
, mChanging( false )
5656
{
5757
setObjectName( name );
5858

@@ -117,7 +117,7 @@ void QgsLegend::showItem( QString msg, QTreeWidgetItem *item )
117117
return;
118118
}
119119

120-
QgsLegendItem *litem = dynamic_cast<QgsLegendGroup *>( item );
120+
QgsLegendItem *litem = dynamic_cast<QgsLegendItem *>( item );
121121
QgsLegendGroup *group = dynamic_cast<QgsLegendGroup *>( item );
122122
QgsLegendLayer *layer = dynamic_cast<QgsLegendLayer *>( item );
123123

@@ -327,54 +327,65 @@ void QgsLegend::mouseMoveEvent( QMouseEvent * e )
327327
{
328328
showItem( "moveMoveEvent" , item );
329329

330-
QgsLegendItem *litem = dynamic_cast<QgsLegendGroup *>( item );
330+
QgsLegendItem *litem = dynamic_cast<QgsLegendItem *>( item );
331331
QgsLegendGroup *group = dynamic_cast<QgsLegendGroup *>( item );
332332
QgsLegendLayer *layer = dynamic_cast<QgsLegendLayer *>( item );
333333

334-
if ( group || layer )
334+
while ( item->parent() && !group && !layer )
335+
{
336+
item = item->parent();
337+
litem = dynamic_cast<QgsLegendItem *>( item );
338+
group = dynamic_cast<QgsLegendGroup *>( item );
339+
layer = dynamic_cast<QgsLegendLayer *>( item );
340+
}
341+
342+
showItem( "layer/group" , item );
343+
344+
int line_x = visualItemRect( item ).left();
345+
int line_y;
346+
if ( layer )
347+
{
348+
QTreeWidgetItem *lastItem = item->childCount() > 0 ? item->child( item->childCount() - 1 ) : item;
349+
int y0 = visualItemRect( item ).top() + 1;
350+
int y1 = visualItemRect( lastItem ).bottom() - 2;
351+
352+
mDropTarget = layer;
353+
354+
if ( e->y() < ( y0 + y1 ) / 2 )
355+
{
356+
QgsDebugMsg( "insert before layer" );
357+
mDropAction = BEFORE;
358+
line_y = y0;
359+
}
360+
else
361+
{
362+
QgsDebugMsg( "insert after layer" );
363+
mDropAction = AFTER;
364+
line_y = y1;
365+
}
366+
}
367+
else if ( group )
335368
{
336369
if ( yCoordAboveCenter( litem, e->y() ) ) //over center of item
337370
{
338-
int line_y = visualItemRect( item ).top() + 1;
339-
int line_left = visualItemRect( item ).left();
340-
341-
QgsDebugMsg( "insert before layer/group" );
342-
showLine( line_y, line_left );
343-
setCursor( QCursor( Qt::SizeVerCursor ) );
371+
QgsDebugMsg( "insert before group" );
344372

373+
line_y = visualItemRect( item ).top() + 1;
345374
mDropTarget = item;
346375
mDropAction = BEFORE;
347376
}
348377
else // below center of item
349378
{
350-
int line_y = visualItemRect( item ).bottom() - 2;
351-
int line_left = visualItemRect( item ).left();
352-
353-
if ( group )
354-
{
355-
QgsDebugMsg( "insert into group" );
356-
showLine( line_y, line_left );
357-
setCursor( QCursor( Qt::SizeVerCursor ) );
379+
QgsDebugMsg( "insert into group" );
358380

359-
mDropTarget = item;
360-
mDropAction = INSERT;
361-
}
362-
else
363-
{
364-
QgsDebugMsg( "insert after layer" );
365-
showLine( line_y, line_left );
366-
setCursor( QCursor( Qt::SizeVerCursor ) );
367-
368-
mDropTarget = item;
369-
mDropAction = AFTER;
370-
}
381+
line_y = visualItemRect( item ).bottom() - 2;
382+
mDropTarget = item;
383+
mDropAction = INSERT;
371384
}
372385
}
373-
else
374-
{
375-
QgsDebugMsg( "no action" );
376-
setCursor( QCursor( Qt::ForbiddenCursor ) );
377-
}
386+
387+
showLine( line_y, line_x );
388+
setCursor( QCursor( Qt::SizeVerCursor ) );
378389
}
379390
else if ( !item
380391
&& e->pos().y() >= 0 && e->pos().y() < viewport()->height()
@@ -383,12 +394,11 @@ void QgsLegend::mouseMoveEvent( QMouseEvent * e )
383394
// Outside the listed items, but check if we are in the empty area
384395
// of the viewport, so we can drop after the last top level item.
385396
mDropTarget = topLevelItem( topLevelItemCount() - 1 );
397+
mDropAction = AFTER;
386398

387399
QgsDebugMsg( "insert after last layer/group" );
388400
showLine( visualItemRect( lastVisibleItem() ).bottom() + 1, 0 );
389401
setCursor( QCursor( Qt::SizeVerCursor ) );
390-
391-
mDropAction = AFTER;
392402
}
393403
else
394404
{

0 commit comments

Comments
 (0)