patch_for_1716.txt

patch for zoomlast/zoomnext tools - Steven Mizuno, 2009-05-26 06:24 PM

Download (5.36 KB)

 
1
Index: python/gui/qgsmapcanvas.sip
2
===================================================================
3
--- python/gui/qgsmapcanvas.sip	(revision 10775)
4
+++ python/gui/qgsmapcanvas.sip	(working copy)
5
@@ -93,6 +93,9 @@
6
     //! Zoom to the next extent (view)
7
     void zoomToNextExtent();
8
 
9
+    // ! Clears the list of extents and sets current extent as first item
10
+    void clearExtentHistory();
11
+
12
     /**Zooms to the extend of the selected features*/
13
     void zoomToSelected();
14
 
15
@@ -254,6 +257,12 @@
16
     //! Emit map tool changed event
17
     void mapToolSet(QgsMapTool *tool);
18
 
19
+    //! Emitted when zoom last status changed
20
+    void zoomLastStatusChanged( bool );
21
+
22
+    //! Emitted when zoom next status changed
23
+    void zoomNextStatusChanged( bool );
24
+
25
   protected:
26
 
27
     //! Overridden key press event
28
Index: src/app/legend/qgslegend.cpp
29
===================================================================
30
--- src/app/legend/qgslegend.cpp	(revision 10775)
31
+++ src/app/legend/qgslegend.cpp	(working copy)
32
@@ -543,7 +543,10 @@
33
 
34
   // first layer?
35
   if ( mMapCanvas->layerCount() == 1 )
36
+  {
37
     mMapCanvas->zoomToFullExtent();
38
+    mMapCanvas->clearExtentHistory(); 
39
+  }
40
   setCurrentItem( llayer );
41
   //make the QTreeWidget item up-to-date
42
   doItemsLayout();
43
Index: src/app/qgisapp.cpp
44
===================================================================
45
--- src/app/qgisapp.cpp	(revision 10775)
46
+++ src/app/qgisapp.cpp	(working copy)
47
@@ -445,6 +445,7 @@
48
   //finally show all the application settings as initialised above
49
   QgsApplication::showSettings();
50
   mMapCanvas->freeze( false );
51
+  mMapCanvas->clearExtentHistory();	// reset zoomnext/zoomlast
52
 } // QgisApp ctor
53
 
54
 
55
@@ -1642,6 +1643,10 @@
56
 
57
   connect( QgsProject::instance(), SIGNAL( layerLoaded( int, int ) ), this, SLOT( showProgress( int, int ) ) );
58
 
59
+  // Connect status from ZoomLast/ZoomNext to corresponding action
60
+  connect( mMapCanvas, SIGNAL( zoomLastStatusChanged( bool ) ), mActionZoomLast, SLOT( setEnabled( bool ) ) );
61
+  connect( mMapCanvas, SIGNAL( zoomNextStatusChanged( bool ) ), mActionZoomNext, SLOT( setEnabled( bool ) ) );
62
+
63
 }
64
 void QgisApp::createCanvas()
65
 {
66
@@ -3049,6 +3054,7 @@
67
 
68
   mMapCanvas->freeze( false );
69
   mMapCanvas->refresh();
70
+  mMapCanvas->clearExtentHistory();
71
 
72
   mMapCanvas->mapRenderer()->setProjectionsEnabled( FALSE );
73
 
74
Index: src/gui/qgsmapcanvas.cpp
75
===================================================================
76
--- src/gui/qgsmapcanvas.cpp	(revision 10775)
77
+++ src/gui/qgsmapcanvas.cpp	(working copy)
78
@@ -506,6 +506,9 @@
79
 
80
   mLastExtent.append( extent() ) ;
81
   mLastExtentIndex = mLastExtent.size() - 1;
82
+  // update controls' enabled state
83
+  emit zoomLastStatusChanged( mLastExtentIndex > 0 );
84
+  emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
85
   // notify canvas items of change
86
   updateCanvasItemPositions();
87
 
88
@@ -557,7 +560,7 @@
89
     return;
90
   }
91
 
92
-  if ( mLastExtentIndex > 1 )
93
+  if ( mLastExtentIndex > 0 )
94
   {
95
     mLastExtentIndex--;
96
     mMapRenderer->setExtent( mLastExtent[mLastExtentIndex] );
97
@@ -565,9 +568,12 @@
98
     updateScale();
99
     if ( mMapOverview )
100
       mMapOverview->drawExtentRect();
101
+    refresh();
102
+    // update controls' enabled state
103
+    emit zoomLastStatusChanged( mLastExtentIndex > 0 );
104
+    emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
105
   }
106
 
107
-  refresh();
108
 } // zoomToPreviousExtent
109
 
110
 void QgsMapCanvas::zoomToNextExtent()
111
@@ -584,10 +590,22 @@
112
     updateScale();
113
     if ( mMapOverview )
114
       mMapOverview->drawExtentRect();
115
+    refresh();
116
+    // update controls' enabled state
117
+    emit zoomLastStatusChanged( mLastExtentIndex > 0 );
118
+    emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
119
   }
120
-  refresh();
121
 }// zoomToNextExtent
122
 
123
+void QgsMapCanvas::clearExtentHistory()
124
+{
125
+  mLastExtent.clear();	// clear the zoom history list
126
+  mLastExtent.append( extent() ) ;	// set the current extent in the list
127
+  mLastExtentIndex = mLastExtent.size() - 1;
128
+  // update controls' enabled state
129
+  emit zoomLastStatusChanged( mLastExtentIndex > 0 );
130
+  emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
131
+}// clearExtentHistory
132
 
133
 
134
 bool QgsMapCanvas::hasCrsTransformEnabled()
135
@@ -1334,6 +1352,7 @@
136
   {
137
     QDomNode node = nodes.item( 0 );
138
     mMapRenderer->readXML( node );
139
+    clearExtentHistory();	// clear the extent history on project load
140
   }
141
   else
142
   {
143
Index: src/gui/qgsmapcanvas.h
144
===================================================================
145
--- src/gui/qgsmapcanvas.h	(revision 10775)
146
+++ src/gui/qgsmapcanvas.h	(working copy)
147
@@ -146,6 +146,9 @@
148
     //! Zoom to the Next extent (view)
149
     void zoomToNextExtent();
150
 
151
+    // ! Clears the list of extents and sets current extent as first item
152
+    void clearExtentHistory();
153
+
154
     /**Zooms to the extend of the selected features*/
155
     void zoomToSelected();
156
 
157
@@ -317,6 +320,12 @@
158
     //! Emitted when selection in any layer gets changed
159
     void selectionChanged( QgsMapLayer * layer );
160
 
161
+    //! Emitted when zoom last status changed
162
+    void zoomLastStatusChanged( bool );
163
+
164
+    //! Emitted when zoom next status changed
165
+    void zoomNextStatusChanged( bool );
166
+
167
   protected:
168
     //! Overridden key press event
169
     void keyPressEvent( QKeyEvent * e );