diff --git a/python/gui/qgscodeeditor.sip b/python/gui/qgscodeeditor.sip index 6fd85fb370f..7421c7ac70d 100644 --- a/python/gui/qgscodeeditor.sip +++ b/python/gui/qgscodeeditor.sip @@ -8,6 +8,11 @@ class QgsCodeEditor: QsciScintilla QgsCodeEditor( QWidget *parent /TransferThis/ = 0, QString title = "" , bool folding = false, bool margin = false ); ~QgsCodeEditor(); + /** Set the widget title + * @param title widget title + */ + void setTitle( const QString title ); + /** Set margin visible state * @param margin Set margin in the editor */ @@ -19,4 +24,16 @@ class QgsCodeEditor: QsciScintilla */ void setFoldingVisible( bool folding); bool foldingVisible(); + + /** Insert text at cursor position, or replace any selected text if user has + * made a selection. + * @param theText The text to be inserted + */ + void insertText( const QString theText ); + + protected: + + bool isFixedPitch( const QFont& font ); + + QFont getMonospaceFont(); }; diff --git a/src/gui/qgscodeeditor.cpp b/src/gui/qgscodeeditor.cpp index 14142247176..db96499f93b 100644 --- a/src/gui/qgscodeeditor.cpp +++ b/src/gui/qgscodeeditor.cpp @@ -67,7 +67,7 @@ void QgsCodeEditor::setSciWidget() setAutoCompletionSource( QsciScintilla::AcsAPIs ); } -void QgsCodeEditor::setTitle( QString title ) +void QgsCodeEditor::setTitle( const QString title ) { setWindowTitle( title ); } @@ -106,12 +106,20 @@ void QgsCodeEditor::setFoldingVisible( bool folding ) } } -void QgsCodeEditor::insertText( QString theText ) +void QgsCodeEditor::insertText( const QString theText ) { - int line, index; - getCursorPosition( &line, &index ); - insertAt( theText, line, index ); - setCursorPosition( line, index + theText.length() ); + // Insert the text or replace selected text + if ( hasSelectedText() ) + { + replaceSelectedText( theText ); + } + else + { + int line, index; + getCursorPosition( &line, &index ); + insertAt( theText, line, index ); + setCursorPosition( line, index + theText.length() ); + } } // Settings for font and fontsize diff --git a/src/gui/qgscodeeditor.h b/src/gui/qgscodeeditor.h index 525731a2073..30644cb2a65 100644 --- a/src/gui/qgscodeeditor.h +++ b/src/gui/qgscodeeditor.h @@ -45,8 +45,10 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla QgsCodeEditor( QWidget *parent = 0, QString title = "" , bool folding = false, bool margin = false ); ~QgsCodeEditor(); - /** Set the widget title */ - void setTitle( QString ); + /** Set the widget title + * @param title widget title + */ + void setTitle( const QString title ); /** Set margin visible state * @param margin Set margin in the editor @@ -60,10 +62,11 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla void setFoldingVisible( bool folding ); bool foldingVisible() { return mFolding; } - /** Isert text at cursor position + /** Insert text at cursor position, or replace any selected text if user has + * made a selection. * @param theText The text to be inserted */ - void insertText( QString theText ); + void insertText( const QString theText ); protected: diff --git a/src/gui/qgsexpressionbuilderwidget.cpp b/src/gui/qgsexpressionbuilderwidget.cpp index 1231334e08b..6b27c33c1ea 100644 --- a/src/gui/qgsexpressionbuilderwidget.cpp +++ b/src/gui/qgsexpressionbuilderwidget.cpp @@ -92,7 +92,7 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent ) QString name = func->name(); if ( name.startsWith( "_" ) ) // do not display private functions continue; - if ( func->params() >= 1 ) + if ( func->params() != 0 ) name += "("; registerItem( func->group(), func->name(), " " + name + " ", func->helptext() ); } @@ -157,7 +157,7 @@ void QgsExpressionBuilderWidget::on_expressionTree_doubleClicked( const QModelIn if ( item->getItemType() == QgsExpressionItem::Header ) return; - // Insert the expression text. + // Insert the expression text or replace selected text txtExpressionString->insertText( item->getExpressionText() ); txtExpressionString->setFocus(); } @@ -392,6 +392,7 @@ void QgsExpressionBuilderWidget::on_lblPreview_linkActivated( QString link ) void QgsExpressionBuilderWidget::on_mValueListWidget_itemDoubleClicked( QListWidgetItem *item ) { + // Insert the item text or replace selected text txtExpressionString->insertText( " " + item->text() + " " ); txtExpressionString->setFocus(); } @@ -399,6 +400,8 @@ void QgsExpressionBuilderWidget::on_mValueListWidget_itemDoubleClicked( QListWid void QgsExpressionBuilderWidget::operatorButtonClicked() { QPushButton* button = dynamic_cast( sender() ); + + // Insert the button text or replace selected text txtExpressionString->insertText( " " + button->text() + " " ); txtExpressionString->setFocus(); }