Skip to content

Commit 233cf5a

Browse files
author
timlinux
committed
Removed the need for updatePositionManual - when you want to implement custom position
logic simply override updatePosition... git-svn-id: http://svn.osgeo.org/qgis/trunk@5128 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 26a96f8 commit 233cf5a

File tree

4 files changed

+18
-51
lines changed

4 files changed

+18
-51
lines changed

src/gui/qgsmapcanvasitem.cpp

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

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

6666
void QgsMapCanvasItem::updatePosition()
6767
{
68-
if (mResizeType == ResizeAuto)
68+
QRect r; // empty rect by default
69+
if (!mRect.isEmpty())
6970
{
70-
QRect r; // empty rect by default
71-
if (!mRect.isEmpty())
72-
{
73-
r = QRect(toCanvasCoords(QgsPoint(mRect.xMin(), mRect.yMin())),
74-
toCanvasCoords(QgsPoint(mRect.xMax(), mRect.yMax())));
75-
r = r.normalized();
76-
}
77-
move(r.left(), r.top());
78-
setSize(r.width(), r.height());
79-
}
80-
else
81-
{
82-
updatePositionManual();
71+
r = QRect(toCanvasCoords(QgsPoint(mRect.xMin(), mRect.yMin())),
72+
toCanvasCoords(QgsPoint(mRect.xMax(), mRect.yMax())));
73+
r = r.normalized();
8374
}
75+
move(r.left(), r.top());
76+
setSize(r.width(), r.height());
8477

8578
#ifdef QGISDEBUG
86-
std::cout << "QgsMapCanvasItem::updatePosition: " << (mResizeType == ResizeAuto ? "<AUTO>" : "<MANUAL>")
87-
<< " [" << (int) x() << "," << (int) y() << "]-[" << width() << "x" << height() << "]" << std::endl;
79+
std::cout << "QgsMapCanvasItem::updatePosition: " << " [" << (int) x()
80+
<< "," << (int) y() << "]-[" << width() << "x" << height() << "]" << std::endl;
8881
#endif
8982
}
9083

9184

92-
void QgsMapCanvasItem::drawShape(QPainter & p)
93-
{
94-
#ifdef QGISDEBUG
95-
std::cout << "drawShape: WARNING: this function should be reimplemented in child class!" << std::endl;
96-
#endif
97-
}
98-
99-
void QgsMapCanvasItem::updatePositionManual()
100-
{
101-
#ifdef QGISDEBUG
102-
std::cout << "updatePositionManual: WARNING: this function should be reimplemented in child class!" << std::endl;
103-
#endif
104-
}
10585

10686
void QgsMapCanvasItem::updateCanvas()
10787
{
10888
update();
10989
mMapCanvas->canvas()->update(); //Contents();
11090
}
11191

112-
void QgsMapCanvasItem::setResizeType(ResizeType type)
113-
{
114-
mResizeType = type;
115-
}
11692

11793
void QgsMapCanvasItem::setPanningOffset(const QPoint& point)
11894
{

src/gui/qgsmapcanvasitem.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class QPainter;
2525

2626
class QgsMapCanvasItem : public QObject, public Q3CanvasRectangle
2727
{
28-
Q_OBJECT
28+
Q_OBJECT;
2929

3030
protected:
3131

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

3737
//! function to be implemented by derived classes
38-
virtual void drawShape(QPainter & p);
39-
40-
//! handler for manual updating of position and size
41-
virtual void updatePositionManual();
38+
virtual void drawShape(QPainter & p)=0;
4239

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

46-
enum ResizeType { ResizeAuto, ResizeManual };
4743

4844
public:
4945

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

65-
//! changes position updating policy
66-
void setResizeType(ResizeType type);
6761

6862

6963
public slots:
7064

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

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

7975
//! canvas item rectangle (in map coordinates)
8076
QgsRect mRect;
81-
82-
//! determines which position updating policy will be used
83-
ResizeType mResizeType;
8477

8578
//! offset from normal position due current panning operation,
8679
//! used when converting map coordinates to move map canvas items

src/gui/qgsvertexmarker.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ QgsVertexMarker::QgsVertexMarker(QgsMapCanvas* mapCanvas)
2424
{
2525
mIconSize = 10;
2626
mIconType = ICON_X;
27-
mResizeType = ResizeManual;
2827
}
2928

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

8180

82-
void QgsVertexMarker::updatePositionManual()
81+
void QgsVertexMarker::updatePosition()
8382
{
8483
QPoint pt = toCanvasCoords(mCenter);
8584
int s = (mIconSize - 1) / 2;

src/gui/qgsvertexmarker.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ class QgsVertexMarker : public QgsMapCanvasItem
4444
void setIconSize(int iconSize);
4545

4646
void drawShape(QPainter & p);
47-
48-
//! handler for manual updating of position and size
49-
void updatePositionManual();
47+
48+
void updatePosition();
5049

5150
protected:
5251

0 commit comments

Comments
 (0)