Skip to content

Commit

Permalink
improve dragging legend layers
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14704 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 17, 2010
1 parent 523b7b7 commit 337c290
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 42 deletions.
4 changes: 3 additions & 1 deletion ms-windows/osgeo4w/package.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ touch exclude

tar -C %OSGEO4W_ROOT% -cjf %PACKAGENAME%-%VERSION%-%PACKAGE%.tar.bz2 ^
--exclude-from exclude ^
--exclude "*.pyc" ^
--exclude "apps/%PACKAGENAME%/themes/classic/grass" ^
--exclude "apps/%PACKAGENAME%/themes/default/grass" ^
--exclude "apps/%PACKAGENAME%/themes/qgis/grass" ^
Expand All @@ -162,8 +163,9 @@ tar -C %OSGEO4W_ROOT% -cjf %PACKAGENAME%-%VERSION%-%PACKAGE%.tar.bz2 ^
>>%LOG% 2>&1
if errorlevel 1 goto error

tar -C %OSGEO4W_ROOT% -cjf %PACKAGENAME%-grass-%VERSION%-%PACKAGE%.tar.bz2 ^
tar -C %OSGEO4W_ROOT% -cjf %PACKAGENAME%-grass-plugin-%VERSION%-%PACKAGE%.tar.bz2 ^
--exclude-from exclude ^
--exclude "*.pyc" \
"apps/%PACKAGENAME%/themes/classic/grass" ^
"apps/%PACKAGENAME%/themes/default/grass" ^
"apps/%PACKAGENAME%/themes/gis/grass" ^
Expand Down
92 changes: 51 additions & 41 deletions src/app/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ static const char *const ident_ = "$Id$";
const int AUTOSCROLL_MARGIN = 16;

QgsLegend::QgsLegend( QgsMapCanvas *canvas, QWidget * parent, const char *name )
: QTreeWidget( parent )
, mMousePressedFlag( false )
, mMapCanvas( canvas )
, mMinimumIconSize( 20, 20 )
, mChanging( false )
: QTreeWidget( parent )
, mMousePressedFlag( false )
, mMapCanvas( canvas )
, mMinimumIconSize( 20, 20 )
, mChanging( false )
{
setObjectName( name );

Expand Down Expand Up @@ -117,7 +117,7 @@ void QgsLegend::showItem( QString msg, QTreeWidgetItem *item )
return;
}

QgsLegendItem *litem = dynamic_cast<QgsLegendGroup *>( item );
QgsLegendItem *litem = dynamic_cast<QgsLegendItem *>( item );
QgsLegendGroup *group = dynamic_cast<QgsLegendGroup *>( item );
QgsLegendLayer *layer = dynamic_cast<QgsLegendLayer *>( item );

Expand Down Expand Up @@ -327,54 +327,65 @@ void QgsLegend::mouseMoveEvent( QMouseEvent * e )
{
showItem( "moveMoveEvent" , item );

QgsLegendItem *litem = dynamic_cast<QgsLegendGroup *>( item );
QgsLegendItem *litem = dynamic_cast<QgsLegendItem *>( item );
QgsLegendGroup *group = dynamic_cast<QgsLegendGroup *>( item );
QgsLegendLayer *layer = dynamic_cast<QgsLegendLayer *>( item );

if ( group || layer )
while ( item->parent() && !group && !layer )
{
item = item->parent();
litem = dynamic_cast<QgsLegendItem *>( item );
group = dynamic_cast<QgsLegendGroup *>( item );
layer = dynamic_cast<QgsLegendLayer *>( item );
}

showItem( "layer/group" , item );

int line_x = visualItemRect( item ).left();
int line_y;
if ( layer )
{
QTreeWidgetItem *lastItem = item->childCount() > 0 ? item->child( item->childCount() - 1 ) : item;
int y0 = visualItemRect( item ).top() + 1;
int y1 = visualItemRect( lastItem ).bottom() - 2;

mDropTarget = layer;

if ( e->y() < ( y0 + y1 ) / 2 )
{
QgsDebugMsg( "insert before layer" );
mDropAction = BEFORE;
line_y = y0;
}
else
{
QgsDebugMsg( "insert after layer" );
mDropAction = AFTER;
line_y = y1;
}
}
else if ( group )
{
if ( yCoordAboveCenter( litem, e->y() ) ) //over center of item
{
int line_y = visualItemRect( item ).top() + 1;
int line_left = visualItemRect( item ).left();

QgsDebugMsg( "insert before layer/group" );
showLine( line_y, line_left );
setCursor( QCursor( Qt::SizeVerCursor ) );
QgsDebugMsg( "insert before group" );

line_y = visualItemRect( item ).top() + 1;
mDropTarget = item;
mDropAction = BEFORE;
}
else // below center of item
{
int line_y = visualItemRect( item ).bottom() - 2;
int line_left = visualItemRect( item ).left();

if ( group )
{
QgsDebugMsg( "insert into group" );
showLine( line_y, line_left );
setCursor( QCursor( Qt::SizeVerCursor ) );
QgsDebugMsg( "insert into group" );

mDropTarget = item;
mDropAction = INSERT;
}
else
{
QgsDebugMsg( "insert after layer" );
showLine( line_y, line_left );
setCursor( QCursor( Qt::SizeVerCursor ) );

mDropTarget = item;
mDropAction = AFTER;
}
line_y = visualItemRect( item ).bottom() - 2;
mDropTarget = item;
mDropAction = INSERT;
}
}
else
{
QgsDebugMsg( "no action" );
setCursor( QCursor( Qt::ForbiddenCursor ) );
}

showLine( line_y, line_x );
setCursor( QCursor( Qt::SizeVerCursor ) );
}
else if ( !item
&& e->pos().y() >= 0 && e->pos().y() < viewport()->height()
Expand All @@ -383,12 +394,11 @@ void QgsLegend::mouseMoveEvent( QMouseEvent * e )
// Outside the listed items, but check if we are in the empty area
// of the viewport, so we can drop after the last top level item.
mDropTarget = topLevelItem( topLevelItemCount() - 1 );
mDropAction = AFTER;

QgsDebugMsg( "insert after last layer/group" );
showLine( visualItemRect( lastVisibleItem() ).bottom() + 1, 0 );
setCursor( QCursor( Qt::SizeVerCursor ) );

mDropAction = AFTER;
}
else
{
Expand Down

0 comments on commit 337c290

Please sign in to comment.