Skip to content
Permalink
Browse files
Clean up code editor code and API. Add tr() and fix spelling.
Moved show/hide folding and margin methods to base class.
  • Loading branch information
NathanW2 committed Jul 16, 2014
1 parent 93fb9db commit b2ff71868ab7ebdfb73834a83f5de1da6cce9ff2
@@ -8,7 +8,15 @@ class QgsCodeEditor: QsciScintilla
QgsCodeEditor( QWidget *parent /TransferThis/ = 0, QString title = "" , bool folding = false, bool margin = false );
~QgsCodeEditor();

bool enableMargin( bool margin );
/** Set margin visible state
* @param margin Set margin in the editor
*/
void setMarginVisible( bool margin );
bool marginVisible();

void enableFolding( bool folding);
/** Set folding visible state
* @param folding Set folding in the editor
*/
void setFoldingVisible( bool folding);
bool foldingVisible();
};
@@ -8,10 +8,8 @@ class QgsCodeEditorPython: QgsCodeEditor
QgsCodeEditorPython( QWidget *parent /TransferThis/ = 0, const QList<QString> &filenames = QList<QString>() );
~QgsCodeEditorPython();

void setTitle( QString );

void loadAPIs(const QList<QString> &filenames );

void loadScript( const QString &script );
bool loadScript( const QString &script );

};
@@ -7,11 +7,4 @@ class QgsCodeEditorSQL: QgsCodeEditor
public:
QgsCodeEditorSQL( QWidget *parent /TransferThis/ = 0 );
~QgsCodeEditorSQL();

void setTitle( QString );

void showMargin( bool withMargin );

void showFolding( bool withFolding );

};
@@ -1,5 +1,6 @@
/***************************************************************************
qgscodeeditor.cpp - description
qgscodeeditor.cpp - A base code editor for QGIS and plugins. Provides
a base editor using QScintilla for editors
--------------------------------------
Date : 06-Oct-2013
Copyright : (C) 2013 by Salvatore Larosa
@@ -21,10 +22,10 @@
#include <QDebug>

QgsCodeEditor::QgsCodeEditor( QWidget *parent, QString title, bool folding, bool margin )
: QsciScintilla( parent ),
mWidgetTitle( title ),
mFolding( folding ),
mMargin( margin )
: QsciScintilla( parent )
, mWidgetTitle( title )
, mFolding( folding )
, mMargin( margin )
{
if ( !parent && mWidgetTitle.isEmpty() )
{
@@ -52,9 +53,9 @@ void QgsCodeEditor::setSciWidget()
setBraceMatching( QsciScintilla::SloppyBraceMatch );
setMatchedBraceBackgroundColor( QColor( "#b7f907" ) );
// whether margin will be shown
enableMargin( mMargin );
setMarginVisible( mMargin );
// whether margin will be shown
enableFolding( mFolding );
setFoldingVisible( mFolding );
// indentation
setAutoIndent( true );
setIndentationWidth( 4 );
@@ -66,8 +67,14 @@ void QgsCodeEditor::setSciWidget()
setAutoCompletionSource( QsciScintilla::AcsAPIs );
}

bool QgsCodeEditor::enableMargin( bool margin )
void QgsCodeEditor::setTitle( QString title )
{
setWindowTitle( title );
}

void QgsCodeEditor::setMarginVisible( bool margin )
{
mMargin = margin;
if ( margin )
{
QFont marginFont( "Courier", 10 );
@@ -76,19 +83,18 @@ bool QgsCodeEditor::enableMargin( bool margin )
setMarginWidth( 1, "00000" );
setMarginsForegroundColor( QColor( "#3E3EE3" ) );
setMarginsBackgroundColor( QColor( "#f9f9f9" ) );
return true;
}
else
{
setMarginWidth( 0, 0 );
setMarginWidth( 1, 0 );
setMarginWidth( 2, 0 );
return false;
}
}

void QgsCodeEditor::enableFolding( bool folding )
void QgsCodeEditor::setFoldingVisible( bool folding )
{
mFolding = folding;
if ( folding )
{
setFolding( QsciScintilla::PlainFoldStyle );
@@ -104,7 +110,6 @@ void QgsCodeEditor::enableFolding( bool folding )
bool QgsCodeEditor::isFixedPitch( const QFont& font )
{
const QFontInfo fi( font );
qDebug() << fi.family() << fi.fixedPitch();
return fi.fixedPitch();
}

@@ -1,5 +1,6 @@
/***************************************************************************
qgscodeeditor.h - description
qgscodeeditor.h - A base code editor for QGIS and plugins. Provides
a base editor using QScintilla for editors
--------------------------------------
Date : 06-Oct-2013
Copyright : (C) 2013 by Salvatore Larosa
@@ -25,7 +26,7 @@ class QWidget;

/** \ingroup gui
* A text editor based on QScintilla2.
* \note added in 2.1
* \note added in 2.6
*/
class GUI_EXPORT QgsCodeEditor : public QsciScintilla
{
@@ -39,20 +40,25 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
* @param title The title to show in the code editor dialog
* @param folding False: Enable margin for code editor
* @param margin False: Enable folding for code editor
* @note added in 2.1
* @note added in 2.6
*/
QgsCodeEditor( QWidget *parent = 0, QString title = "" , bool folding = false, bool margin = false );
~QgsCodeEditor();

/** Enable folding
/** Set the widget title */
void setTitle( QString );

/** Set margin visible state
* @param margin Set margin in the editor
*/
bool enableMargin( bool margin );
void setMarginVisible( bool margin );
bool marginVisible() { return mMargin; }

/** Enable margin
/** Set folding visible state
* @param folding Set folding in the editor
*/
void enableFolding( bool folding );
void setFoldingVisible( bool folding );
bool foldingVisible() { return mFolding; }

protected:

@@ -1,6 +1,6 @@
/***************************************************************************
qgscodeeditorpython.cpp - description
--------------------------------------
qgscodeeditorpython.cpp - A Python editor based on QScintilla
--------------------------------------
Date : 06-Oct-2013
Copyright : (C) 2013 by Salvatore Larosa
Email : lrssvtml (at) gmail (dot) com
@@ -26,12 +26,12 @@
#include <Qsci/qscilexerpython.h>

QgsCodeEditorPython::QgsCodeEditorPython( QWidget *parent, const QList<QString> &filenames )
: QgsCodeEditor( parent ),
mAPISFilesList( filenames )
: QgsCodeEditor( parent )
, mAPISFilesList( filenames )
{
if ( !parent )
{
setTitle( "Qscintilla2 Python Editor" );
setTitle( tr( "Qscintilla2 Python Editor" ) );
}
setSciLexerPython();
}
@@ -105,14 +105,10 @@ void QgsCodeEditorPython::setSciLexerPython()
}
setLexer( pyLexer );

enableMargin( true );
enableFolding( true );
setMarginVisible( true );
setFoldingVisible( true );
}

void QgsCodeEditorPython::setTitle( QString title )
{
setWindowTitle( title );
}

void QgsCodeEditorPython::loadAPIs( const QList<QString> &filenames )
{
@@ -121,13 +117,13 @@ void QgsCodeEditorPython::loadAPIs( const QList<QString> &filenames )
setSciLexerPython();
}

void QgsCodeEditorPython::loadScript( const QString &script )
bool QgsCodeEditorPython::loadScript( const QString &script )
{
QgsDebugMsg( QString( "The script file: %1" ).arg( script ) );
QFile file( script );
if ( !file.open( QIODevice::ReadOnly ) )
{
QMessageBox::information( 0, "error", file.errorString() );
return false;
}

QTextStream in( &file );
@@ -136,4 +132,5 @@ void QgsCodeEditorPython::loadScript( const QString &script )
file.close();

setSciLexerPython();
return true;
}
@@ -1,5 +1,5 @@
/***************************************************************************
qgscodeeditorpython.h - description
qgscodeeditorpython.h - A Python editor based on QScintilla
--------------------------------------
Date : 06-Oct-2013
Copyright : (C) 2013 by Salvatore Larosa
@@ -20,9 +20,9 @@


/** \ingroup gui
* A Python editor based on QScintilla2. Adds syntax highlghiting and
* A Python editor based on QScintilla2. Adds syntax highlighting and
* code autocompletion.
* \note added in 2.1
* \note added in 2.6
*/
class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
{
@@ -34,14 +34,11 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
*
* @param parent The parent QWidget
* @param filenames The list of apis files to load for the python lexer
* @note added in 2.1
* @note added in 2.6
*/
QgsCodeEditorPython( QWidget *parent = 0 , const QList<QString> &filenames = QList<QString>() );
~QgsCodeEditorPython();

/** Set the widget title */
void setTitle( QString );

/** Load APIs from one or more files
* @param filenames The list of apis files to load for the python lexer
*/
@@ -50,7 +47,7 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
/** Load a script file
* @param script The script file to load
*/
void loadScript( const QString &script );
bool loadScript( const QString &script );

private:
//QgsCodeEditor *mSciWidget;
@@ -1,5 +1,5 @@
/***************************************************************************
qgscodeeditorsql.cpp - description
qgscodeeditorsql.cpp - A SQL editor based on QScintilla
--------------------------------------
Date : 06-Oct-2013
Copyright : (C) 2013 by Salvatore Larosa
@@ -22,14 +22,15 @@
#include <Qsci/qscilexersql.h>


QgsCodeEditorSQL::QgsCodeEditorSQL( QWidget *parent ) : QgsCodeEditor( parent )
QgsCodeEditorSQL::QgsCodeEditorSQL( QWidget *parent )
: QgsCodeEditor( parent )
{
if ( !parent )
{
setTitle( "Qscintilla2 SQL Editor" );
setTitle( tr( "Qscintilla2 SQL Editor" ) );
}
enableMargin( false );
enableFolding( true );
setMarginVisible( false );
setFoldingVisible( true );
setSciLexerSQL();
}

@@ -44,18 +45,3 @@ void QgsCodeEditorSQL::setSciLexerSQL()

setLexer( sqlLexer );
}

void QgsCodeEditorSQL::setTitle( QString title )
{
setWindowTitle( title );
}

void QgsCodeEditorSQL::showMargin( bool withMargin )
{
enableMargin( withMargin );
}

void QgsCodeEditorSQL::showFolding( bool withFolding )
{
enableFolding( withFolding );
}
@@ -1,5 +1,5 @@
/***************************************************************************
qgscodeeditorsql.h - description
qgscodeeditorsql.h - A SQL editor based on QScintilla
--------------------------------------
Date : 06-Oct-2013
Copyright : (C) 2013 by Salvatore Larosa
@@ -20,9 +20,9 @@


/** \ingroup gui
* A SQL editor based on QScintilla2. Adds syntax highlghiting and
* A SQL editor based on QScintilla2. Adds syntax highlighting and
* code autocompletion.
* \note added in 2.1
* \note added in 2.6
*/
class GUI_EXPORT QgsCodeEditorSQL : public QgsCodeEditor
{
@@ -32,12 +32,6 @@ class GUI_EXPORT QgsCodeEditorSQL : public QgsCodeEditor
QgsCodeEditorSQL( QWidget *parent = 0 );
~QgsCodeEditorSQL();

void setTitle( QString );

void showMargin( bool withMargin );

void showFolding( bool withFolding );

private:
//QgsCodeEditor *mSciWidget;
//QWidget *mWidget;

0 comments on commit b2ff718

Please sign in to comment.