Skip to content
Permalink
Browse files

Followup bad94e0

  • Loading branch information
nyalldawson committed Sep 23, 2014
1 parent 34f00d1 commit 0f8fef12037e7859f661fd3255b8cf66e80f1049
Showing with 43 additions and 12 deletions.
  1. +17 −0 python/gui/qgscodeeditor.sip
  2. +14 −6 src/gui/qgscodeeditor.cpp
  3. +7 −4 src/gui/qgscodeeditor.h
  4. +5 −2 src/gui/qgsexpressionbuilderwidget.cpp
@@ -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();
};
@@ -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
@@ -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:

@@ -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,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();
}

1 comment on commit 0f8fef1

@slarosa

This comment has been minimized.

Copy link
Member

@slarosa slarosa commented on 0f8fef1 Sep 25, 2014

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.
You can’t perform that action at this time.