Skip to content

Commit

Permalink
Followup bad94e0
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 23, 2014
1 parent 34f00d1 commit 0f8fef1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
17 changes: 17 additions & 0 deletions python/gui/qgscodeeditor.sip
Expand Up @@ -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
*/
Expand All @@ -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();
};
20 changes: 14 additions & 6 deletions src/gui/qgscodeeditor.cpp
Expand Up @@ -67,7 +67,7 @@ void QgsCodeEditor::setSciWidget()
setAutoCompletionSource( QsciScintilla::AcsAPIs );
}

void QgsCodeEditor::setTitle( QString title )
void QgsCodeEditor::setTitle( const QString title )
{
setWindowTitle( title );
}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/gui/qgscodeeditor.h
Expand Up @@ -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
Expand All @@ -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:

Expand Down
7 changes: 5 additions & 2 deletions src/gui/qgsexpressionbuilderwidget.cpp
Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -392,13 +392,16 @@ 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();
}

void QgsExpressionBuilderWidget::operatorButtonClicked()
{
QPushButton* button = dynamic_cast<QPushButton*>( sender() );

// Insert the button text or replace selected text
txtExpressionString->insertText( " " + button->text() + " " );
txtExpressionString->setFocus();
}
Expand Down

1 comment on commit 0f8fef1

@slarosa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh I couldn't remember when I had inserted the python bindings and the replace text feature :) thanks for the followup!

Please sign in to comment.