[FEATURE][processing][needs-docs] add find and replace functionality to

Processing script editor (forward-port from 2.18 branch)
This commit is contained in:
Alexander Bruy 2017-12-15 11:07:15 +02:00
parent 5c28ecab8f
commit 5016c21ed3
5 changed files with 217 additions and 11 deletions

View File

@ -599,6 +599,7 @@
<file>themes/default/mActionRegularPolygon2Points.svg</file>
<file>themes/default/mActionCircle3Tangents.svg</file>
<file>themes/default/mActionAddGeoPackageLayer.svg</file>
<file>themes/default/mActionFindReplace.svg</file>
<file>icons/qgis_icon.svg</file>
<file>themes/default/mActionCircle2TangentsPoint.svg</file>
<file>themes/default/mActionRegularPolygonCenterPoint.svg</file>

View File

@ -1,12 +1,54 @@
<svg height="32" width="32" xmlns="http://www.w3.org/2000/svg">
<path d="m421.00204 163.64888c-29.25997.19554-57.45718 9.34167-86.17703 12.99876-11.98703 1.5264-24.34118 1.90088-36.34832.48145-15.96387-1.88721-31.42011-6.90053-47.37334-9.14729-14.25702-2.00788-28.69336-4.10405-43.04038-4.1885-25.07177-.14756-49.32119 7.70223-73.9004 11.93962 0 7.19027-1.46022 16.4188 2.2146 21.47205 3.79039 5.21214 10.18464 9.97919 11.84335 17.0428 3.93346 16.75125 9.51772 33.17206 16.65765 48.91394 3.46979 7.64996 10.01899 12.98367 17.33165 16.65766 17.60972 8.84726 38.45266 10.14822 57.7724 7.36593 27.51204-3.96207 42.43718-24.60507 53.82454-48.19171 4.26242-9.58801 4.73783-20.65335 10.35089-29.41576 3.33396-5.20466 11.07615-3.01394 16.60941-3.03303 5.53326-.0191 10.2226 9.18396 11.93967 15.30966 6.07724 21.67923 16.21023 44.67981 36.34851 56.03916 30.07287 16.96316 77.44971 13.79007 96.96118-16.8021 7.63599-11.97262 9.74533-26.49991 13.57645-40.05545 2.33236-8.25235 4.41555-18.09056 12.70996-22.62753 3.34741-1.831.99835-9.1373 1.49243-13.3839.53833-4.62758 1.57629-8.71977-5.00696-9.62872-11.48321-1.58556-22.62198-6.4079-34.37451-8.03998-11.1373-1.54666-22.04919-3.78299-33.41174-3.70706zm-193.44088 7.70297c8.30565-.0529 16.57643.5551 24.64953 2.26274 48.1005 10.17424 49.07312 29.99182 29.27131 70.96369-16.13553 33.38583-49.56026 41.75103-83.2403 33.74859-15.52551-3.68875-26.14195-14.52633-31.14894-29.36755-5.28445-15.66373-9.28183-32.30637-8.37697-48.76946 1.21181-22.04638 26.14827-25.14477 44.00325-27.15298 8.19316-.92154 16.53638-1.63223 24.84212-1.68503zm175.62784 0c8.30572.0528 16.64895.76349 24.8421 1.68503 17.85498 2.00821 42.7915 5.1066 44.00317 27.15298.90494 16.46309-3.09244 33.10573-8.37689 48.76946-5.00699 14.84122-15.62354 25.6788-31.14902 29.36755-33.67996 8.00244-67.10476-.36276-83.2402-33.74859-19.80182-40.97187-18.82919-60.78939 29.2713-70.96369 8.07318-1.70764 16.34378-2.31553 24.64954-2.26274z" stroke="#000" stroke-width="13.18221569" transform="matrix(.08569061 0 0 .08479374 -10.91010672 -10.50676947)"/>
<rect fill="#5a8c5a" height="13" rx="2.6149368" width="25" x="7" y="19"/>
<path d="m21.6 25.499999l7.8 0" style="fill:#fff;fill-rule:evenodd;stroke:#fff;stroke-width:2.5999999;stroke-linecap:round;stroke-linejoin:round;overflow:visible"/>
<path d="m25.5 29.399999l0-7.799999" style="fill:#fff;fill-rule:evenodd;stroke:#fff;stroke-width:2.5999999;stroke-linecap:round;stroke-linejoin:round;overflow:visible"/>
<path d="m20.3 25.499999h10.4c0 0 0 0 0-2.6 0-2.599999-.65-2.599999-5.2-2.599999-4.55 0-5.2 0-5.2 2.599999 0 2.6 0 2.6 0 2.6z" fill="#fcffff" fill-rule="evenodd" opacity=".3"/>
<g fill-rule="evenodd" transform="translate(-12 .00000105)">
<path d="m21.6 25.499999l7.8 0" style="fill:#fff;stroke:#fff;stroke-width:2.5999999;stroke-linecap:round;stroke-linejoin:round;overflow:visible"/>
<path d="m25.5 29.399999l0-7.799999" style="fill:#fff;stroke:#fff;stroke-width:2.5999999;stroke-linecap:round;stroke-linejoin:round;overflow:visible"/>
<path d="m20.3 25.499999h10.4c0 0 0 0 0-2.6 0-2.599999-.65-2.599999-5.2-2.599999-4.55 0-5.2 0-5.2 2.599999 0 2.6 0 2.6 0 2.6z" fill="#fcffff" opacity=".3"/>
</g>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
height="32"
width="32"
id="svg19181"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="mActionAddAllToOverview.svg">
<metadata
id="metadata19205">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs19203" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1366"
inkscape:window-height="746"
id="namedview19201"
showgrid="false"
inkscape:zoom="17.53125"
inkscape:cx="16"
inkscape:cy="12.669433"
inkscape:window-x="0"
inkscape:window-y="22"
inkscape:window-maximized="1"
inkscape:current-layer="svg19181" />
<path
d="m 25.165815,10.85116 c -2.507305,0.01658 -4.923541,0.792115 -7.384562,1.102213 -1.027176,0.12943 -2.085811,0.161183 -3.11471,0.04082 -1.367954,-0.160023 -2.692408,-0.585121 -4.05945,-0.775632 -1.2216932,-0.170256 -2.458752,-0.347998 -3.6881569,-0.355159 -2.1484153,-0.01251 -4.2263629,0.653101 -6.33257036,1.012405 0,0.60969 -0.12512714,1.392211 0.18977043,1.820695 0.32480083,0.441957 0.87272803,0.846173 1.01486393,1.445123 0.3370605,1.420401 0.8155792,2.812783 1.4274041,4.147596 0.2973285,0.648669 0.8585334,1.100934 1.4851597,1.412465 1.5089877,0.750192 3.2950319,0.860506 4.9505522,0.624585 2.3575239,-0.335959 3.6364679,-2.086356 4.6122579,-4.086355 0.365249,-0.813004 0.405987,-1.751275 0.886974,-2.494273 0.285689,-0.441322 0.949122,-0.255563 1.42327,-0.257182 0.474149,-0.0016 0.875981,0.778743 1.023118,1.298164 0.520762,1.838263 1.389064,3.788568 3.114726,4.75177 2.576962,1.438369 6.636713,1.169311 8.308663,-1.424713 0.654332,-1.015203 0.835083,-2.247027 1.163374,-3.396452 0.199861,-0.699747 0.378371,-1.533966 1.089124,-1.918673 0.286842,-0.155257 0.08555,-0.774785 0.127887,-1.13487 0.04613,-0.39239 0.135074,-0.739382 -0.429049,-0.816456 C 29.990458,11.71279 29.03597,11.303886 28.028888,11.165495 27.074526,11.034348 26.13948,10.844722 25.165816,10.85116 Z M 8.5897479,11.504324 c 0.7117162,-0.0045 1.4204441,0.04707 2.1122331,0.191866 4.121761,0.862712 4.205106,2.543118 2.508277,6.017276 -1.382664,2.83091 -4.2468493,3.540226 -7.1329125,2.86167 C 4.7469551,20.262353 3.8372258,19.343394 3.4081738,18.084951 2.9553461,16.756765 2.6128081,15.345573 2.6903461,13.949606 2.7941869,12.080211 4.9310073,11.817487 6.4610115,11.647204 7.1630884,11.569063 7.878024,11.508801 8.5897479,11.504324 Z m 15.0496571,0 c 0.711722,0.0045 1.426658,0.06474 2.128734,0.14288 1.530004,0.170283 3.66683,0.433007 3.770659,2.302402 0.07755,1.395967 -0.264993,2.807159 -0.717821,4.135345 -0.429052,1.258443 -1.338791,2.177402 -2.669179,2.490185 -2.886056,0.678556 -5.750247,-0.03076 -7.132903,-2.86167 -1.69683,-3.474158 -1.613485,-5.154559 2.508276,-6.017276 0.691795,-0.144797 1.400508,-0.196343 2.112234,-0.191866 z"
id="path19183"
inkscape:connector-curvature="0"
style="stroke:#000000;stroke-width:1.12366521" />
</svg>

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
height="32"
width="32"
id="svg19181"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="mActionFindReplace.svg">
<metadata
id="metadata19205">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs19203" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1366"
inkscape:window-height="746"
id="namedview19201"
showgrid="false"
inkscape:zoom="17.53125"
inkscape:cx="16"
inkscape:cy="12.669433"
inkscape:window-x="0"
inkscape:window-y="22"
inkscape:window-maximized="1"
inkscape:current-layer="svg19181" />
<path
d="m 25.165815,10.85116 c -2.507305,0.01658 -4.923541,0.792115 -7.384562,1.102213 -1.027176,0.12943 -2.085811,0.161183 -3.11471,0.04082 -1.367954,-0.160023 -2.692408,-0.585121 -4.05945,-0.775632 -1.2216932,-0.170256 -2.458752,-0.347998 -3.6881569,-0.355159 -2.1484153,-0.01251 -4.2263629,0.653101 -6.33257036,1.012405 0,0.60969 -0.12512714,1.392211 0.18977043,1.820695 0.32480083,0.441957 0.87272803,0.846173 1.01486393,1.445123 0.3370605,1.420401 0.8155792,2.812783 1.4274041,4.147596 0.2973285,0.648669 0.8585334,1.100934 1.4851597,1.412465 1.5089877,0.750192 3.2950319,0.860506 4.9505522,0.624585 2.3575239,-0.335959 3.6364679,-2.086356 4.6122579,-4.086355 0.365249,-0.813004 0.405987,-1.751275 0.886974,-2.494273 0.285689,-0.441322 0.949122,-0.255563 1.42327,-0.257182 0.474149,-0.0016 0.875981,0.778743 1.023118,1.298164 0.520762,1.838263 1.389064,3.788568 3.114726,4.75177 2.576962,1.438369 6.636713,1.169311 8.308663,-1.424713 0.654332,-1.015203 0.835083,-2.247027 1.163374,-3.396452 0.199861,-0.699747 0.378371,-1.533966 1.089124,-1.918673 0.286842,-0.155257 0.08555,-0.774785 0.127887,-1.13487 0.04613,-0.39239 0.135074,-0.739382 -0.429049,-0.816456 C 29.990458,11.71279 29.03597,11.303886 28.028888,11.165495 27.074526,11.034348 26.13948,10.844722 25.165816,10.85116 Z M 8.5897479,11.504324 c 0.7117162,-0.0045 1.4204441,0.04707 2.1122331,0.191866 4.121761,0.862712 4.205106,2.543118 2.508277,6.017276 -1.382664,2.83091 -4.2468493,3.540226 -7.1329125,2.86167 C 4.7469551,20.262353 3.8372258,19.343394 3.4081738,18.084951 2.9553461,16.756765 2.6128081,15.345573 2.6903461,13.949606 2.7941869,12.080211 4.9310073,11.817487 6.4610115,11.647204 7.1630884,11.569063 7.878024,11.508801 8.5897479,11.504324 Z m 15.0496571,0 c 0.711722,0.0045 1.426658,0.06474 2.128734,0.14288 1.530004,0.170283 3.66683,0.433007 3.770659,2.302402 0.07755,1.395967 -0.264993,2.807159 -0.717821,4.135345 -0.429052,1.258443 -1.338791,2.177402 -2.669179,2.490185 -2.886056,0.678556 -5.750247,-0.03076 -7.132903,-2.86167 -1.69683,-3.474158 -1.613485,-5.154559 2.508276,-6.017276 0.691795,-0.144797 1.400508,-0.196343 2.112234,-0.191866 z"
id="path19183"
inkscape:connector-curvature="0"
style="stroke:#000000;stroke-width:1.12366521" />
</svg>

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -64,6 +64,8 @@ class ScriptEditorDialog(BASE, WIDGET):
Qt.WindowMaximizeButtonHint |
Qt.WindowCloseButtonHint)
self.searchWidget.setVisible(False)
settings = QgsSettings()
self.restoreState(settings.value("/Processing/stateScriptEditor", QByteArray()))
self.restoreGeometry(settings.value("/Processing/geometryScriptEditor", QByteArray()))
@ -90,6 +92,8 @@ class ScriptEditorDialog(BASE, WIDGET):
QgsApplication.getThemeIcon('/mActionUndo.svg'))
self.actionRedo.setIcon(
QgsApplication.getThemeIcon('/mActionRedo.svg'))
self.actionFindReplace.setIcon(
QgsApplication.getThemeIcon('/mActionFindReplace.svg'))
self.actionIncreaseFontSize.setIcon(
QgsApplication.getThemeIcon('/mActionIncreaseFont.svg'))
self.actionDecreaseFontSize.setIcon(
@ -106,10 +110,15 @@ class ScriptEditorDialog(BASE, WIDGET):
self.actionPaste.triggered.connect(self.editor.paste)
self.actionUndo.triggered.connect(self.editor.undo)
self.actionRedo.triggered.connect(self.editor.redo)
self.actionFindReplace.toggled.connect(self.toggleSearchBox)
self.actionIncreaseFontSize.triggered.connect(self.editor.zoomIn)
self.actionDecreaseFontSize.triggered.connect(self.editor.zoomOut)
self.editor.textChanged.connect(lambda: self.setHasChanged(True))
self.btnFind.clicked.connect(self.find)
self.btnReplace.clicked.connect(self.replace)
self.lastSearch = None
self.alg = alg
self.algType = algType
@ -287,3 +296,19 @@ class ScriptEditorDialog(BASE, WIDGET):
except:
pass
canvas.setMapTool(prevMapTool)
def find(self):
textToFind = self.leFindText.text()
caseSensitive = self.chkCaseSensitive.isChecked()
wholeWord = self.chkWholeWord.isChecked()
if self.lastSearch is None or textToFind != self.lastSearch:
self.editor.findFirst(textToFind, False, caseSensitive, wholeWord, True)
else:
self.editor.findNext()
def replace(self):
textToReplace = self.leReplaceText.text()
self.editor.replaceSelectedText(textToReplace)
def toggleSearchBox(self, checked):
self.searchWidget.setVisible(checked)

View File

@ -18,6 +18,79 @@
<item row="0" column="0">
<widget class="ScriptEdit" name="editor"/>
</item>
<item row="1" column="0">
<widget class="QWidget" name="searchWidget" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item row="0" column="0">
<widget class="QCheckBox" name="chkCaseSensitive">
<property name="text">
<string>Case sensitive</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="chkWholeWord">
<property name="text">
<string>Whole word</string>
</property>
</widget>
</item>
<item row="1" column="4" colspan="2">
<widget class="QPushButton" name="btnReplace">
<property name="text">
<string>Replace</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Find what:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Replace with:</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="leReplaceText"/>
</item>
<item row="0" column="4" colspan="2">
<widget class="QPushButton" name="btnFind">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="leFindText"/>
</item>
<item row="0" column="1" rowspan="2">
<widget class="Line" name="line_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="toolBar">
@ -45,6 +118,8 @@
<addaction name="actionUndo"/>
<addaction name="actionRedo"/>
<addaction name="separator"/>
<addaction name="actionFindReplace"/>
<addaction name="separator"/>
<addaction name="actionIncreaseFontSize"/>
<addaction name="actionDecreaseFontSize"/>
</widget>
@ -171,6 +246,14 @@
<string>Decrease font size</string>
</property>
</action>
<action name="actionFindReplace">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>FindReplace</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>