improved layer order manipulation - closes bug #820684

git-svn-id: http://svn.osgeo.org/qgis/trunk@301 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
stevehalasz 2003-11-13 01:40:58 +00:00
parent 22312b7c1a
commit 62d6209cd2
3 changed files with 52 additions and 53 deletions

View File

@ -27,10 +27,10 @@
# the same distribution terms that you use for the rest of that program.
# A sed that does not truncate output.
SED="/usr/bin/sed"
SED="/bin/sed"
# Sed that helps us avoid accidentally triggering echo(1) options like -n.
Xsed="/usr/bin/sed -e s/^X//"
Xsed="/bin/sed -e s/^X//"
# The HP-UX ksh and POSIX shell print the target directory to stdout
# if CDPATH is set.
@ -38,7 +38,7 @@ if test "X${CDPATH+set}" = Xset; then CDPATH=:; export CDPATH; fi
# ### BEGIN LIBTOOL CONFIG
# Libtool was configured on host linux:
# Libtool was configured on host marcy:
# Shell to use when invoking shell scripts.
SHELL="/bin/sh"
@ -73,7 +73,7 @@ CC="gcc"
with_gcc=yes
# The linker used to build libraries.
LD="/usr/i486-suse-linux/bin/ld"
LD="/usr/bin/ld"
# Whether we need hard or soft links.
LN_S="ln -s"

View File

@ -11,76 +11,77 @@
//
//
#include <qapplication.h>
#include <qdragobject.h>
#include <qcursor.h>
#include <qlistview.h>
#include <qpoint.h>
#include <qrect.h>
#include "qgslegendview.h"
QgsLegendView::QgsLegendView( QWidget *parent, const char *name ):QListView( parent, name ), mousePressed( FALSE )
{
setAcceptDrops( TRUE );
viewport()->setAcceptDrops( TRUE );
}
void QgsLegendView::contentsDragEnterEvent( QDragEnterEvent* e )
{
QString text;
if ( QTextDrag::decode(e, text) ) {
// verify text is 'legend-drag' to avoid
// handling regular text drops
if ( text.compare("legend-drag") == 0 ) {
e->accept( TRUE );
}
}
}
void QgsLegendView::contentsDropEvent(QDropEvent* e)
{
QString text;
if ( QTextDrag::decode(e, text) ) {
// verify text is 'legend-drag' to avoid
// handling regular text drops
if ( text.compare("legend-drag") == 0 ) {
QListViewItem *item = itemAt( contentsToViewport(e->pos()) );
// insert item in motion after one it was dropped on
movingItem->moveItem( item );
// avoid having more than one layer appear selected after drop
setCurrentItem(movingItem);
emit zOrderChanged(this);
}
} else {
e->ignore();
return;
}
}
void QgsLegendView::contentsMousePressEvent( QMouseEvent* e )
{
QListView::contentsMousePressEvent( e );
QPoint p( contentsToViewport( e->pos() ) );
QListViewItem *i = itemAt( p );
if ( i ) {
presspos = e->pos();
mousePressed = TRUE;
if (e->button() == LeftButton) {
QPoint p( contentsToViewport( e->pos() ) );
QListViewItem *i = itemAt( p );
if ( i ) {
presspos = e->pos();
mousePressed = TRUE;
}
}
}
void QgsLegendView::contentsMouseMoveEvent( QMouseEvent* e )
{
if ( mousePressed && ( presspos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
if ( mousePressed ) {
mousePressed = FALSE;
// remember item we've pressed as the one being moved
QListViewItem *item = itemAt( contentsToViewport(presspos) );
if ( item ) {
movingItem = item;
// create drag object with some useless text
QDragObject *d = new QTextDrag( "legend-drag", this );
d->drag();
setCursor( SizeVerCursor );
}
} else if ( movingItem ) {
// move item in list if we're dragging over another item
QListViewItem *item = itemAt( e->pos() );
if ( item && ( item != movingItem ) ) {
// find if we're over the top or bottom half of the item
QRect rect = itemRect( item );
int height = rect.height();
int top = rect.top();
int mid = top + ( height / 2 );
if ( e->y() < mid) {
// move item we're over now to after one in motion
// unless it's already there
if ( movingItem->nextSibling() != item ) {
item->moveItem( movingItem );
}
} else {
// move item in motion to after one we're over now
// unless it's already there
if ( movingItem != item->nextSibling() ) {
movingItem->moveItem( item );
}
}
}
}
}
void QgsLegendView::contentsMouseReleaseEvent( QMouseEvent * )
void QgsLegendView::contentsMouseReleaseEvent( QMouseEvent* e)
{
mousePressed = FALSE;
QListView::contentsMouseReleaseEvent( e );
if (e->button() == LeftButton) {
mousePressed = FALSE;
unsetCursor();
if ( movingItem ) {
// tell qgsmapcanvas to reset layer order using the legend order
emit zOrderChanged(this);
}
movingItem = NULL;
}
}

View File

@ -20,9 +20,7 @@ public:
QgsLegendView( QWidget *parent=0, const char *name=0 );
protected:
// override these to provide drag-n-drop
void contentsDragEnterEvent( QDragEnterEvent *e );
void contentsDropEvent( QDropEvent *e );
// override these to handle layer order manipulation
void contentsMouseMoveEvent( QMouseEvent *e );
void contentsMousePressEvent( QMouseEvent *e );
void contentsMouseReleaseEvent( QMouseEvent *e );