From e272db6dece00cb0b64da07d2f926ba85bcb9488 Mon Sep 17 00:00:00 2001 From: rabla Date: Wed, 30 Mar 2005 08:55:11 +0000 Subject: [PATCH] +invalidate() - bugfix for crash on delete git-svn-id: http://svn.osgeo.org/qgis/trunk@3043 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/qgscomposerscalebar.cpp | 13 +++++++++---- src/qgscomposerscalebar.h | 2 +- src/qgscomposition.cpp | 17 ++--------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/qgscomposerscalebar.cpp b/src/qgscomposerscalebar.cpp index 193f70c419f..99c1471620c 100644 --- a/src/qgscomposerscalebar.cpp +++ b/src/qgscomposerscalebar.cpp @@ -394,13 +394,13 @@ void QgsComposerScalebar::sizeChanged ( ) writeSettings(); } -void QgsComposerScalebar::move(int x, int y ) +void QgsComposerScalebar::moveBy(double x, double y ) { std::cout << "QgsComposerScalebar::move" << std::endl; - setX( (double)x ); - setY( (double)y ); + QCanvasItem::moveBy ( x, y ); + recalculate(); - writeSettings(); + //writeSettings(); // not necessary called by composition } void QgsComposerScalebar::recalculate ( void ) @@ -410,7 +410,12 @@ void QgsComposerScalebar::recalculate ( void ) mHeight = (int) ( 25.4 * mComposition->scale() * mFont.pointSize() / 72); mMargin = (int) (3.*mHeight/2); + // !!! invalidate() MUST BE called before the value returned by areaPoints() changes + QCanvasPolygonalItem::invalidate(); + mBoundingRect = render(0); + + QCanvasItem::update(); } QRect QgsComposerScalebar::boundingRect ( void ) const diff --git a/src/qgscomposerscalebar.h b/src/qgscomposerscalebar.h index 96914eb923a..5a61368003b 100644 --- a/src/qgscomposerscalebar.h +++ b/src/qgscomposerscalebar.h @@ -125,7 +125,7 @@ public slots: void mapChanged ( int id ); // Move to position - void move ( int x, int y ); + void moveBy ( double x, double y ); private: // Pointer to composition diff --git a/src/qgscomposition.cpp b/src/qgscomposition.cpp index 9f59451829b..63f3742fe0d 100644 --- a/src/qgscomposition.cpp +++ b/src/qgscomposition.cpp @@ -346,14 +346,7 @@ void QgsComposition::contentsMouseMoveEvent(QMouseEvent* e) double x,y; mView->inverseWorldMatrix().map( e->pos().x(), e->pos().y(), &x, &y ); - // TODO better move - if ( typeid (*mSelectedItem) == typeid(QgsComposerScalebar) ) { - QgsComposerScalebar *sb = dynamic_cast (mSelectedItem); - sb->move ( (int)(mSelectedItem->x() + x - mLastX), (int)(mSelectedItem->y() + y - mLastY) ); - } else { - mSelectedItem->setX( mSelectedItem->x() + x - mLastX ); - mSelectedItem->setY( mSelectedItem->y() + y - mLastY ); - } + mSelectedItem->moveBy ( x - mLastX, y - mLastY ); QgsComposerItem *ci = dynamic_cast (mSelectedItem); ci->writeSettings(); @@ -388,14 +381,8 @@ void QgsComposition::contentsMouseMoveEvent(QMouseEvent* e) case AddVectorLegend: case AddLabel: - mNewCanvasItem->setX( p.x() ); - mNewCanvasItem->setY( p.y() ); - mCanvas->update(); - break; - case AddScalebar: - QgsComposerScalebar *sb = dynamic_cast (mNewCanvasItem); - sb->move ( p.x(), p.y() ); + mNewCanvasItem->move ( p.x(), p.y() ); mCanvas->update(); break; }