Skip to content

Commit 8e52635

Browse files
committedMar 20, 2023
Move toggle comment handling to base QgsCodeEditor class
1 parent e04aa7b commit 8e52635

File tree

9 files changed

+40
-4
lines changed

9 files changed

+40
-4
lines changed
 

‎python/core/auto_additions/qgis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,8 @@
25912591
# monkey patching scoped based enum
25922592
Qgis.ScriptLanguageCapability.Reformat.__doc__ = "Language supports automatic code reformatting"
25932593
Qgis.ScriptLanguageCapability.CheckSyntax.__doc__ = "Language supports syntax checking"
2594-
Qgis.ScriptLanguageCapability.__doc__ = 'Script language capabilities.\n\nThe flags reflect the support capabilities of a scripting language.\n\n.. versionadded:: 3.32\n\n' + '* ``Reformat``: ' + Qgis.ScriptLanguageCapability.Reformat.__doc__ + '\n' + '* ``CheckSyntax``: ' + Qgis.ScriptLanguageCapability.CheckSyntax.__doc__
2594+
Qgis.ScriptLanguageCapability.ToggleComment.__doc__ = "Language supports comment toggling"
2595+
Qgis.ScriptLanguageCapability.__doc__ = 'Script language capabilities.\n\nThe flags reflect the support capabilities of a scripting language.\n\n.. versionadded:: 3.32\n\n' + '* ``Reformat``: ' + Qgis.ScriptLanguageCapability.Reformat.__doc__ + '\n' + '* ``CheckSyntax``: ' + Qgis.ScriptLanguageCapability.CheckSyntax.__doc__ + '\n' + '* ``ToggleComment``: ' + Qgis.ScriptLanguageCapability.ToggleComment.__doc__
25952596
# --
25962597
Qgis.ScriptLanguageCapability.baseClass = Qgis
25972598
Qgis.ScriptLanguageCapabilities.baseClass = Qgis

‎python/core/auto_generated/qgis.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,7 @@ The development version
15931593
{
15941594
Reformat,
15951595
CheckSyntax,
1596+
ToggleComment,
15961597
};
15971598

15981599
typedef QFlags<Qgis::ScriptLanguageCapability> ScriptLanguageCapabilities;

‎python/gui/auto_generated/codeeditors/qgscodeeditor.sip.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,15 @@ Applies syntax checking to the editor.
436436

437437
This is only supported for editors which return the Qgis.ScriptLanguageCapability.CheckSyntax capability from :py:func:`~QgsCodeEditor.languageCapabilities`.
438438

439+
.. versionadded:: 3.32
440+
%End
441+
442+
virtual void toggleComment();
443+
%Docstring
444+
Toggle comment for the selected text.
445+
446+
This is only supported for editors which return the Qgis.ScriptLanguageCapability.ToggleComment capability from :py:func:`~QgsCodeEditor.languageCapabilities`.
447+
439448
.. versionadded:: 3.32
440449
%End
441450

‎python/gui/auto_generated/codeeditors/qgscodeeditorpython.sip.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ Searches the selected text in the official PyQGIS online documentation.
9797
.. versionadded:: 3.16
9898
%End
9999

100-
void toggleComment();
100+
virtual void toggleComment();
101+
101102
%Docstring
102103
Toggle comment for the selected text.
103104

‎src/core/qgis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,6 +2736,7 @@ class CORE_EXPORT Qgis
27362736
{
27372737
Reformat = 1 << 0, //!< Language supports automatic code reformatting
27382738
CheckSyntax = 1 << 1, //!< Language supports syntax checking
2739+
ToggleComment = 1 << 2, //!< Language supports comment toggling
27392740
};
27402741
Q_ENUM( ScriptLanguageCapability )
27412742

‎src/gui/codeeditors/qgscodeeditor.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ void QgsCodeEditor::contextMenuEvent( QContextMenuEvent *event )
247247
menu->addAction( syntaxCheckAction );
248248
}
249249

250+
if ( languageCapabilities() & Qgis::ScriptLanguageCapability::ToggleComment )
251+
{
252+
QAction *toggleCommentAction = new QAction( tr( "Toggle Comment" ), menu );
253+
toggleCommentAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "console/iconCommentEditorConsole.svg" ) ) );
254+
toggleCommentAction->setEnabled( !isReadOnly() );
255+
connect( toggleCommentAction, &QAction::triggered, this, &QgsCodeEditor::toggleComment );
256+
menu->addAction( toggleCommentAction );
257+
}
258+
250259
populateContextMenu( menu );
251260

252261
menu->exec( mapToGlobal( event->pos() ) );
@@ -727,6 +736,11 @@ bool QgsCodeEditor::checkSyntax()
727736
return true;
728737
}
729738

739+
void QgsCodeEditor::toggleComment()
740+
{
741+
742+
}
743+
730744
QStringList QgsCodeEditor::history() const
731745
{
732746
return mHistory;

‎src/gui/codeeditors/qgscodeeditor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,15 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
455455
*/
456456
virtual bool checkSyntax();
457457

458+
/**
459+
* Toggle comment for the selected text.
460+
*
461+
* This is only supported for editors which return the Qgis::ScriptLanguageCapability::ToggleComment capability from languageCapabilities().
462+
*
463+
* \since QGIS 3.32
464+
*/
465+
virtual void toggleComment();
466+
458467
signals:
459468

460469
/**

‎src/gui/codeeditors/qgscodeeditorpython.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ QString QgsCodeEditorPython::characterAfterCursor() const
622622

623623
void QgsCodeEditorPython::updateCapabilities()
624624
{
625-
mCapabilities = Qgis::ScriptLanguageCapabilities();
625+
mCapabilities = Qgis::ScriptLanguageCapability::ToggleComment;
626626

627627
if ( !QgsPythonRunner::isValid() )
628628
return;

‎src/gui/codeeditors/qgscodeeditorpython.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
120120
*
121121
* \since QGIS 3.30
122122
*/
123-
void toggleComment();
123+
void toggleComment() override;
124124

125125
protected:
126126

0 commit comments

Comments
 (0)