Skip to content
Permalink
Browse files

Removed the need for updatePositionManual - when you want to implemen…

…t custom position

logic simply override updatePosition...


git-svn-id: http://svn.osgeo.org/qgis/trunk@5128 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux
timlinux committed Apr 1, 2006
1 parent 26a96f8 commit 233cf5a14fe44f167ee0e4f794435655b56b76f6
Showing with 18 additions and 51 deletions.
  1. +10 −34 src/gui/qgsmapcanvasitem.cpp
  2. +5 −12 src/gui/qgsmapcanvasitem.h
  3. +1 −2 src/gui/qgsvertexmarker.cpp
  4. +2 −3 src/gui/qgsvertexmarker.h
@@ -25,7 +25,7 @@

QgsMapCanvasItem::QgsMapCanvasItem(QgsMapCanvas* mapCanvas)
: Q3CanvasRectangle(mapCanvas->canvas()), mMapCanvas(mapCanvas),
mResizeType(ResizeAuto), mPanningOffset(0,0)
mPanningOffset(0,0)
{
//setCanvas(mapCanvas->canvas());
}
@@ -65,54 +65,30 @@ void QgsMapCanvasItem::setRect(const QgsRect& r)

void QgsMapCanvasItem::updatePosition()
{
if (mResizeType == ResizeAuto)
QRect r; // empty rect by default
if (!mRect.isEmpty())
{
QRect r; // empty rect by default
if (!mRect.isEmpty())
{
r = QRect(toCanvasCoords(QgsPoint(mRect.xMin(), mRect.yMin())),
toCanvasCoords(QgsPoint(mRect.xMax(), mRect.yMax())));
r = r.normalized();
}
move(r.left(), r.top());
setSize(r.width(), r.height());
}
else
{
updatePositionManual();
r = QRect(toCanvasCoords(QgsPoint(mRect.xMin(), mRect.yMin())),
toCanvasCoords(QgsPoint(mRect.xMax(), mRect.yMax())));
r = r.normalized();
}
move(r.left(), r.top());
setSize(r.width(), r.height());

#ifdef QGISDEBUG
std::cout << "QgsMapCanvasItem::updatePosition: " << (mResizeType == ResizeAuto ? "<AUTO>" : "<MANUAL>")
<< " [" << (int) x() << "," << (int) y() << "]-[" << width() << "x" << height() << "]" << std::endl;
std::cout << "QgsMapCanvasItem::updatePosition: " << " [" << (int) x()
<< "," << (int) y() << "]-[" << width() << "x" << height() << "]" << std::endl;
#endif
}


void QgsMapCanvasItem::drawShape(QPainter & p)
{
#ifdef QGISDEBUG
std::cout << "drawShape: WARNING: this function should be reimplemented in child class!" << std::endl;
#endif
}

void QgsMapCanvasItem::updatePositionManual()
{
#ifdef QGISDEBUG
std::cout << "updatePositionManual: WARNING: this function should be reimplemented in child class!" << std::endl;
#endif
}

void QgsMapCanvasItem::updateCanvas()
{
update();
mMapCanvas->canvas()->update(); //Contents();
}

void QgsMapCanvasItem::setResizeType(ResizeType type)
{
mResizeType = type;
}

void QgsMapCanvasItem::setPanningOffset(const QPoint& point)
{
@@ -25,7 +25,7 @@ class QPainter;

class QgsMapCanvasItem : public QObject, public Q3CanvasRectangle
{
Q_OBJECT
Q_OBJECT;

protected:

@@ -35,15 +35,11 @@ class QgsMapCanvasItem : public QObject, public Q3CanvasRectangle
virtual ~QgsMapCanvasItem();

//! function to be implemented by derived classes
virtual void drawShape(QPainter & p);

//! handler for manual updating of position and size
virtual void updatePositionManual();
virtual void drawShape(QPainter & p)=0;

//! schedules map canvas for repaint
void updateCanvas();

enum ResizeType { ResizeAuto, ResizeManual };

public:

@@ -62,13 +58,13 @@ class QgsMapCanvasItem : public QObject, public Q3CanvasRectangle
//! transformation from map coordinates to screen coordinates
QPoint toCanvasCoords(const QgsPoint& point);

//! changes position updating policy
void setResizeType(ResizeType type);


public slots:

//! called on changed extents or changed item rectangle
/** called on changed extents or changed item rectangle
* Override this in your subclass if you wish to have custom
* behaviour for when the canvas area of interest is changed */
void updatePosition();

protected:
@@ -78,9 +74,6 @@ class QgsMapCanvasItem : public QObject, public Q3CanvasRectangle

//! canvas item rectangle (in map coordinates)
QgsRect mRect;

//! determines which position updating policy will be used
ResizeType mResizeType;

//! offset from normal position due current panning operation,
//! used when converting map coordinates to move map canvas items
@@ -24,7 +24,6 @@ QgsVertexMarker::QgsVertexMarker(QgsMapCanvas* mapCanvas)
{
mIconSize = 10;
mIconType = ICON_X;
mResizeType = ResizeManual;
}

void QgsVertexMarker::setIconType(int type)
@@ -79,7 +78,7 @@ void QgsVertexMarker::drawShape(QPainter & p)
}


void QgsVertexMarker::updatePositionManual()
void QgsVertexMarker::updatePosition()
{
QPoint pt = toCanvasCoords(mCenter);
int s = (mIconSize - 1) / 2;
@@ -44,9 +44,8 @@ class QgsVertexMarker : public QgsMapCanvasItem
void setIconSize(int iconSize);

void drawShape(QPainter & p);

//! handler for manual updating of position and size
void updatePositionManual();

void updatePosition();

protected:

0 comments on commit 233cf5a

Please sign in to comment.
You can’t perform that action at this time.