<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<font face="Ubuntu">Hi Luke,<br>
<br>
My guess is that when more than one feature is selected, and the
rotation is ended, geometryChanged signal is emitted for each
rotated feature.<br>
<br>
element_layer_rotated() is run when the first geometryChanged
signal is emitted, and is disconnected, and the layer is saved,
and the other geometryChanged signals don't trigger anything.<br>
<br>
NB:
self.vector_layer.editBuffer().geometryChanged.disconnect()
is risky, if other slots are connected, prefer </font><font
face="Ubuntu">self.vector_layer.editBuffer().geometryChanged.disconnect(self.element_layer_rotated)</font><br>
<font face="Ubuntu"><br>
Regards,<br>
</font>
<pre class="moz-signature" cols="72">--
Jacky Volpes
Ingénieur développeur SIG - Oslandia</pre>
<div class="moz-cite-prefix">Le 01/08/2024 à 20:29, Catania, Luke A
ERDC-RDE-GRL-VA CIV a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:03b73cd41cdd4ea39f6a4eddca16689a@erdc.dren.mil">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator"
content="Microsoft Word 15 (filtered medium)">
<style>@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}@font-face
{font-family:Ubuntu;
panose-1:0 0 0 0 0 0 0 0 0 0;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ligatures:standardcontextual;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;}span.EmailStyle21
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}div.WordSection1
{page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal">def rotateFeature(self):<o:p></o:p></p>
<p class="MsoNormal"> """Find the rotate feature action
in QGIS toolbar and trigger it so the user can rotate the
element.<o:p></o:p></p>
<p class="MsoNormal"> """<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> # We want to detect when the
rotation is complete with a geometryChanged signal so we can
commit the changes and<o:p></o:p></p>
<p class="MsoNormal"> # end the edit session.<o:p></o:p></p>
<p class="MsoNormal">
self.vector_layer.editBuffer().geometryChanged.connect(self.element_layer_rotated)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> # Get all actions so we can search
for the mActionRotateFeature action.<o:p></o:p></p>
<p class="MsoNormal"> actions =
iface.mainWindow().findChildren(QAction)<o:p></o:p></p>
<p class="MsoNormal"> action = [x for x in actions if
x.objectName()=='mActionRotateFeature'][0]<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> expression = '"Element_Nb" = '<o:p></o:p></p>
<p class="MsoNormal"> expression = expression + "\'" +
f'{self.element_number}' + "\'"<o:p></o:p></p>
<p class="MsoNormal">
QgsMessageLog.logMessage(f"expression: {expression}",
"StandoffLayers", Qgis.Info)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">
processing.run("qgis:selectbyexpression", <o:p></o:p></p>
<p class="MsoNormal"> {'INPUT':self.vector_layer,<o:p></o:p></p>
<p class="MsoNormal"> 'EXPRESSION':
expression,<o:p></o:p></p>
<p class="MsoNormal"> 'METHOD':0<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"> )<o:p></o:p></p>
<p class="MsoNormal"> # Inititates rotate feature action
allowing to select a snap to value.<o:p></o:p></p>
<p class="MsoNormal"> action.trigger()<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> QgsMessageLog.logMessage(f"Rotate
Feature Action Triggered", "ElementPlacementTool", Qgis.Info)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">def element_layer_rotated(self):<o:p></o:p></p>
<p class="MsoNormal"> """When the rotate action is
triggered it seems to ignore the ElementPlacementTool events,
so in order to end the edit session<o:p></o:p></p>
<p class="MsoNormal"> we need to detect a geometryChanged
event after the rotation is complete.<o:p></o:p></p>
<p class="MsoNormal"> """<o:p></o:p></p>
<p class="MsoNormal"> QgsMessageLog.logMessage(f"Element
Layer Rotated: {self.vector_layer.name()}",
"ElementPlacementTool", Qgis.Info)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> # Disconnect from the signal so we
can just commit the changes.<o:p></o:p></p>
<p class="MsoNormal">
self.vector_layer.editBuffer().geometryChanged.disconnect()<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> # Save changes and end edit mode<o:p></o:p></p>
<p class="MsoNormal"> self.vector_layer.commitChanges()<o:p></o:p></p>
<p class="MsoNormal"> self.vector_layer.endEditCommand()<o:p></o:p></p>
<p class="MsoNormal"> self.deactivate()<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div
style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="mso-ligatures:none">From:</span></b><span
style="mso-ligatures:none"> Jacky Volpes
<a class="moz-txt-link-rfc2396E" href="mailto:jacky.volpes@oslandia.com"><jacky.volpes@oslandia.com></a>
<br>
<b>Sent:</b> Thursday, August 1, 2024 8:26 AM<br>
<b>To:</b> Catania, Luke A ERDC-RDE-GRL-VA CIV
<a class="moz-txt-link-rfc2396E" href="mailto:Luke.A.Catania@erdc.dren.mil"><Luke.A.Catania@erdc.dren.mil></a>; 'qgis-developer'
<a class="moz-txt-link-rfc2396E" href="mailto:qgis-developer@lists.osgeo.org"><qgis-developer@lists.osgeo.org></a><br>
<b>Subject:</b> Re: [QGIS-Developer] Rotating selected
features programmatically<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span
style="font-family:"Ubuntu",serif">Hi Luke,<br>
<br>
Please provide a PyQGIS code snippet to reproduce. It will
be more convenient to comment and suggest modifications.<br>
Thanks,<br>
<br>
</span><span style="mso-ligatures:none"><o:p></o:p></span></p>
<pre>--<o:p></o:p></pre>
<pre>Jacky Volpes<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Ingénieur développeur SIG - Oslandia<o:p></o:p></pre>
<div>
<p class="MsoNormal"><br>
Le 26/07/2024 à 22:06, Catania, Luke A ERDC-RDE-GRL-VA CIV
via QGIS-Developer a écrit :<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">I am using the select by expression tool
through python to select my features and then I trigger
rotation through python I see both selected features
rotating, but when I click to end the rotation, it only
rotated one of the features and left the other one as is.
If I do this through the QGIS using the selection by
expression in the selection toolbar and the rotate in the
advanced digitizing tool bar rotating both features works
fine.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Any Ideas?<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Luke<o:p></o:p></p>
<p class="MsoNormal"><span style="mso-ligatures:none"><br>
<br>
<o:p></o:p></span></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>QGIS-Developer mailing list<o:p></o:p></pre>
<pre><a href="mailto:QGIS-Developer@lists.osgeo.org"
moz-do-not-send="true" class="moz-txt-link-freetext">QGIS-Developer@lists.osgeo.org</a><o:p></o:p></pre>
<pre>List info: <a
href="Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked"
moz-do-not-send="true">Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked</a><o:p></o:p></pre>
<pre>Unsubscribe: <a
href="Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked"
moz-do-not-send="true">Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked</a><o:p></o:p></pre>
</blockquote>
<p class="MsoNormal"><span style="mso-ligatures:none"><o:p> </o:p></span></p>
</div>
</blockquote>
<br>
</body>
</html>