Followup bad94e0

This commit is contained in:
Nyall Dawson 2014-09-23 19:30:41 +10:00
parent 34f00d106f
commit 0f8fef1203
4 changed files with 43 additions and 12 deletions

View File

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

View File

@ -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

View File

@ -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:

View File

@ -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<QPushButton*>( sender() );
// Insert the button text or replace selected text
txtExpressionString->insertText( " " + button->text() + " " );
txtExpressionString->setFocus();
}