@@ -44,6 +44,9 @@ class TestQgsMapToolRotateFeature: public QObject
44
44
void cleanupTestCase ();// will be called after the last testfunction was executed.
45
45
46
46
void testRotateFeature ();
47
+ void testRotateFeatureManualAnchor ();
48
+ void testCancelManualAnchor ();
49
+ void testRotateFeatureManualAnchorAfterStartRotate ();
47
50
48
51
private:
49
52
QgisApp *mQgisApp = nullptr ;
@@ -140,6 +143,68 @@ void TestQgsMapToolRotateFeature::testRotateFeature()
140
143
mLayerBase ->undoStack ()->undo ();
141
144
}
142
145
146
+ void TestQgsMapToolRotateFeature::testRotateFeatureManualAnchor ()
147
+ {
148
+ // test rotating around a fixed anchor point
149
+ TestQgsMapToolUtils utils ( mRotateTool );
150
+
151
+ // set anchor point
152
+ utils.mouseClick ( 0 , 5 , Qt::LeftButton, Qt::ControlModifier, true );
153
+
154
+ utils.mouseClick ( 1 , 1 , Qt::LeftButton, Qt::KeyboardModifiers (), true );
155
+ utils.mouseMove ( 2 , 1 );
156
+ utils.mouseClick ( 2 , 1 , Qt::LeftButton, Qt::KeyboardModifiers (), true );
157
+
158
+ QCOMPARE ( mLayerBase ->getFeature ( 1 ).geometry ().asWkt ( 2 ), QStringLiteral ( " Polygon ((2.06 0.34, 0.87 1.1, 1.84 1.31, 2.06 0.34))" ) );
159
+ QCOMPARE ( mLayerBase ->getFeature ( 2 ).geometry ().asWkt ( 2 ), QStringLiteral ( " Polygon ((1.1 0, 1.1 5, 2.1 5, 2.1 0))" ) );
160
+
161
+ mLayerBase ->undoStack ()->undo ();
162
+ }
163
+
164
+ void TestQgsMapToolRotateFeature::testCancelManualAnchor ()
165
+ {
166
+ // test canceling rotation around a fixed anchor point
167
+ TestQgsMapToolUtils utils ( mRotateTool );
168
+
169
+ // set anchor point
170
+ utils.mouseClick ( 0 , 5 , Qt::LeftButton, Qt::ControlModifier, true );
171
+
172
+ // right click = remove anchor point
173
+ utils.mouseClick ( 10 , 15 , Qt::RightButton, Qt::KeyboardModifiers (), true );
174
+
175
+ // now rotate -- should be around feature center, not anchor point
176
+ utils.mouseClick ( 1 , 1 , Qt::LeftButton, Qt::KeyboardModifiers (), true );
177
+ utils.mouseMove ( 2 , 1 );
178
+ utils.mouseClick ( 2 , 1 , Qt::LeftButton, Qt::KeyboardModifiers (), true );
179
+
180
+ QCOMPARE ( mLayerBase ->getFeature ( 1 ).geometry ().asWkt ( 2 ), QStringLiteral ( " Polygon ((0.72 -0.17, 0.28 1.17, 1.17 0.72, 0.72 -0.17))" ) );
181
+ QCOMPARE ( mLayerBase ->getFeature ( 2 ).geometry ().asWkt ( 2 ), QStringLiteral ( " Polygon ((1.1 0, 1.1 5, 2.1 5, 2.1 0))" ) );
182
+
183
+ mLayerBase ->undoStack ()->undo ();
184
+ }
185
+
186
+ void TestQgsMapToolRotateFeature::testRotateFeatureManualAnchorAfterStartRotate ()
187
+ {
188
+ // test rotating around a fixed anchor point, where the fixed anchor point is placed after rotation begins
189
+ TestQgsMapToolUtils utils ( mRotateTool );
190
+
191
+ // start rotation
192
+ utils.mouseClick ( 1 , 1 , Qt::LeftButton, Qt::KeyboardModifiers (), true );
193
+
194
+ // set anchor point
195
+ utils.mouseMove ( 0 , 5 );
196
+ utils.mouseClick ( 0 , 5 , Qt::LeftButton, Qt::ControlModifier, true );
197
+
198
+ // complete rotation
199
+ utils.mouseMove ( 2 , 1 );
200
+ utils.mouseClick ( 2 , 1 , Qt::LeftButton, Qt::KeyboardModifiers (), true );
201
+
202
+ QCOMPARE ( mLayerBase ->getFeature ( 1 ).geometry ().asWkt ( 2 ), QStringLiteral ( " Polygon ((-5.06 5.63, -3.79 6.26, -4.11 5.32, -5.06 5.63))" ) );
203
+ QCOMPARE ( mLayerBase ->getFeature ( 2 ).geometry ().asWkt ( 2 ), QStringLiteral ( " Polygon ((1.1 0, 1.1 5, 2.1 5, 2.1 0))" ) );
204
+
205
+ mLayerBase ->undoStack ()->undo ();
206
+ }
207
+
143
208
144
209
QGSTEST_MAIN ( TestQgsMapToolRotateFeature )
145
210
#include " testqgsmaptoolrotatefeature.moc"
0 commit comments