Skip to content

Commit

Permalink
Clean up code editor code and API. Add tr() and fix spelling.
Browse files Browse the repository at this point in the history
Moved show/hide folding and margin methods to base class.
  • Loading branch information
NathanW2 committed Jul 16, 2014
1 parent 93fb9db commit b2ff718
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 81 deletions.
12 changes: 10 additions & 2 deletions python/gui/qgscodeeditor.sip
Expand Up @@ -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();
};
4 changes: 1 addition & 3 deletions python/gui/qgscodeeditorpython.sip
Expand Up @@ -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 changes: 0 additions & 7 deletions python/gui/qgscodeeditorsql.sip
Expand Up @@ -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 );

};
29 changes: 17 additions & 12 deletions src/gui/qgscodeeditor.cpp
@@ -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
Expand All @@ -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() )
{
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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();
}

Expand Down
20 changes: 13 additions & 7 deletions src/gui/qgscodeeditor.h
@@ -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
Expand All @@ -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
{
Expand All @@ -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:

Expand Down
23 changes: 10 additions & 13 deletions src/gui/qgscodeeditorpython.cpp
@@ -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
Expand All @@ -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();
}
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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 );
Expand All @@ -136,4 +132,5 @@ void QgsCodeEditorPython::loadScript( const QString &script )
file.close();

setSciLexerPython();
return true;
}
13 changes: 5 additions & 8 deletions src/gui/qgscodeeditorpython.h
@@ -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
Expand All @@ -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
{
Expand All @@ -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
*/
Expand All @@ -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;
Expand Down
26 changes: 6 additions & 20 deletions src/gui/qgscodeeditorsql.cpp
@@ -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
Expand All @@ -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();
}

Expand All @@ -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 );
}
12 changes: 3 additions & 9 deletions src/gui/qgscodeeditorsql.h
@@ -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
Expand All @@ -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
{
Expand All @@ -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;
Expand Down

0 comments on commit b2ff718

Please sign in to comment.