From b2ff71868ab7ebdfb73834a83f5de1da6cce9ff2 Mon Sep 17 00:00:00 2001 From: Nathan Woodrow Date: Wed, 16 Jul 2014 22:51:27 +1000 Subject: [PATCH] Clean up code editor code and API. Add tr() and fix spelling. Moved show/hide folding and margin methods to base class. --- python/gui/qgscodeeditor.sip | 12 ++++++++++-- python/gui/qgscodeeditorpython.sip | 4 +--- python/gui/qgscodeeditorsql.sip | 7 ------- src/gui/qgscodeeditor.cpp | 29 +++++++++++++++++------------ src/gui/qgscodeeditor.h | 20 +++++++++++++------- src/gui/qgscodeeditorpython.cpp | 23 ++++++++++------------- src/gui/qgscodeeditorpython.h | 13 +++++-------- src/gui/qgscodeeditorsql.cpp | 26 ++++++-------------------- src/gui/qgscodeeditorsql.h | 12 +++--------- 9 files changed, 65 insertions(+), 81 deletions(-) diff --git a/python/gui/qgscodeeditor.sip b/python/gui/qgscodeeditor.sip index 1cbfdc6b5ee..6fd85fb370f 100644 --- a/python/gui/qgscodeeditor.sip +++ b/python/gui/qgscodeeditor.sip @@ -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(); }; diff --git a/python/gui/qgscodeeditorpython.sip b/python/gui/qgscodeeditorpython.sip index 97f4ef7e248..a6db0ca1ebb 100644 --- a/python/gui/qgscodeeditorpython.sip +++ b/python/gui/qgscodeeditorpython.sip @@ -8,10 +8,8 @@ class QgsCodeEditorPython: QgsCodeEditor QgsCodeEditorPython( QWidget *parent /TransferThis/ = 0, const QList &filenames = QList() ); ~QgsCodeEditorPython(); - void setTitle( QString ); - void loadAPIs(const QList &filenames ); - void loadScript( const QString &script ); + bool loadScript( const QString &script ); }; diff --git a/python/gui/qgscodeeditorsql.sip b/python/gui/qgscodeeditorsql.sip index 078f68fbd11..0e601728c30 100644 --- a/python/gui/qgscodeeditorsql.sip +++ b/python/gui/qgscodeeditorsql.sip @@ -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 ); - }; diff --git a/src/gui/qgscodeeditor.cpp b/src/gui/qgscodeeditor.cpp index b5c4937f1ab..1394cd7a5a0 100644 --- a/src/gui/qgscodeeditor.cpp +++ b/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 @@ -21,10 +22,10 @@ #include 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(); } diff --git a/src/gui/qgscodeeditor.h b/src/gui/qgscodeeditor.h index a07e49718a8..457f86a7ed1 100644 --- a/src/gui/qgscodeeditor.h +++ b/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 @@ -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: diff --git a/src/gui/qgscodeeditorpython.cpp b/src/gui/qgscodeeditorpython.cpp index 7695829a711..006c9837184 100644 --- a/src/gui/qgscodeeditorpython.cpp +++ b/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 @@ -26,12 +26,12 @@ #include QgsCodeEditorPython::QgsCodeEditorPython( QWidget *parent, const QList &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 &filenames ) { @@ -121,13 +117,13 @@ void QgsCodeEditorPython::loadAPIs( const QList &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; } diff --git a/src/gui/qgscodeeditorpython.h b/src/gui/qgscodeeditorpython.h index 54eefb68f62..f869bd025ce 100644 --- a/src/gui/qgscodeeditorpython.h +++ b/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 @@ -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 &filenames = QList() ); ~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; diff --git a/src/gui/qgscodeeditorsql.cpp b/src/gui/qgscodeeditorsql.cpp index 2b099c2c690..e1d50173446 100644 --- a/src/gui/qgscodeeditorsql.cpp +++ b/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 @@ -22,14 +22,15 @@ #include -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 ); -} diff --git a/src/gui/qgscodeeditorsql.h b/src/gui/qgscodeeditorsql.h index 3cca94eb9f8..62e3a64c555 100644 --- a/src/gui/qgscodeeditorsql.h +++ b/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 @@ -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;