Skip to content

Commit b2ff718

Browse files
committedJul 16, 2014
Clean up code editor code and API. Add tr() and fix spelling.
Moved show/hide folding and margin methods to base class.
1 parent 93fb9db commit b2ff718

9 files changed

+65
-81
lines changed
 

‎python/gui/qgscodeeditor.sip

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ class QgsCodeEditor: QsciScintilla
88
QgsCodeEditor( QWidget *parent /TransferThis/ = 0, QString title = "" , bool folding = false, bool margin = false );
99
~QgsCodeEditor();
1010

11-
bool enableMargin( bool margin );
11+
/** Set margin visible state
12+
* @param margin Set margin in the editor
13+
*/
14+
void setMarginVisible( bool margin );
15+
bool marginVisible();
1216

13-
void enableFolding( bool folding);
17+
/** Set folding visible state
18+
* @param folding Set folding in the editor
19+
*/
20+
void setFoldingVisible( bool folding);
21+
bool foldingVisible();
1422
};

‎python/gui/qgscodeeditorpython.sip

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ class QgsCodeEditorPython: QgsCodeEditor
88
QgsCodeEditorPython( QWidget *parent /TransferThis/ = 0, const QList<QString> &filenames = QList<QString>() );
99
~QgsCodeEditorPython();
1010

11-
void setTitle( QString );
12-
1311
void loadAPIs(const QList<QString> &filenames );
1412

15-
void loadScript( const QString &script );
13+
bool loadScript( const QString &script );
1614

1715
};

‎python/gui/qgscodeeditorsql.sip

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,4 @@ class QgsCodeEditorSQL: QgsCodeEditor
77
public:
88
QgsCodeEditorSQL( QWidget *parent /TransferThis/ = 0 );
99
~QgsCodeEditorSQL();
10-
11-
void setTitle( QString );
12-
13-
void showMargin( bool withMargin );
14-
15-
void showFolding( bool withFolding );
16-
1710
};

‎src/gui/qgscodeeditor.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/***************************************************************************
2-
qgscodeeditor.cpp - description
2+
qgscodeeditor.cpp - A base code editor for QGIS and plugins. Provides
3+
a base editor using QScintilla for editors
34
--------------------------------------
45
Date : 06-Oct-2013
56
Copyright : (C) 2013 by Salvatore Larosa
@@ -21,10 +22,10 @@
2122
#include <QDebug>
2223

2324
QgsCodeEditor::QgsCodeEditor( QWidget *parent, QString title, bool folding, bool margin )
24-
: QsciScintilla( parent ),
25-
mWidgetTitle( title ),
26-
mFolding( folding ),
27-
mMargin( margin )
25+
: QsciScintilla( parent )
26+
, mWidgetTitle( title )
27+
, mFolding( folding )
28+
, mMargin( margin )
2829
{
2930
if ( !parent && mWidgetTitle.isEmpty() )
3031
{
@@ -52,9 +53,9 @@ void QgsCodeEditor::setSciWidget()
5253
setBraceMatching( QsciScintilla::SloppyBraceMatch );
5354
setMatchedBraceBackgroundColor( QColor( "#b7f907" ) );
5455
// whether margin will be shown
55-
enableMargin( mMargin );
56+
setMarginVisible( mMargin );
5657
// whether margin will be shown
57-
enableFolding( mFolding );
58+
setFoldingVisible( mFolding );
5859
// indentation
5960
setAutoIndent( true );
6061
setIndentationWidth( 4 );
@@ -66,8 +67,14 @@ void QgsCodeEditor::setSciWidget()
6667
setAutoCompletionSource( QsciScintilla::AcsAPIs );
6768
}
6869

69-
bool QgsCodeEditor::enableMargin( bool margin )
70+
void QgsCodeEditor::setTitle( QString title )
7071
{
72+
setWindowTitle( title );
73+
}
74+
75+
void QgsCodeEditor::setMarginVisible( bool margin )
76+
{
77+
mMargin = margin;
7178
if ( margin )
7279
{
7380
QFont marginFont( "Courier", 10 );
@@ -76,19 +83,18 @@ bool QgsCodeEditor::enableMargin( bool margin )
7683
setMarginWidth( 1, "00000" );
7784
setMarginsForegroundColor( QColor( "#3E3EE3" ) );
7885
setMarginsBackgroundColor( QColor( "#f9f9f9" ) );
79-
return true;
8086
}
8187
else
8288
{
8389
setMarginWidth( 0, 0 );
8490
setMarginWidth( 1, 0 );
8591
setMarginWidth( 2, 0 );
86-
return false;
8792
}
8893
}
8994

90-
void QgsCodeEditor::enableFolding( bool folding )
95+
void QgsCodeEditor::setFoldingVisible( bool folding )
9196
{
97+
mFolding = folding;
9298
if ( folding )
9399
{
94100
setFolding( QsciScintilla::PlainFoldStyle );
@@ -104,7 +110,6 @@ void QgsCodeEditor::enableFolding( bool folding )
104110
bool QgsCodeEditor::isFixedPitch( const QFont& font )
105111
{
106112
const QFontInfo fi( font );
107-
qDebug() << fi.family() << fi.fixedPitch();
108113
return fi.fixedPitch();
109114
}
110115

‎src/gui/qgscodeeditor.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/***************************************************************************
2-
qgscodeeditor.h - description
2+
qgscodeeditor.h - A base code editor for QGIS and plugins. Provides
3+
a base editor using QScintilla for editors
34
--------------------------------------
45
Date : 06-Oct-2013
56
Copyright : (C) 2013 by Salvatore Larosa
@@ -25,7 +26,7 @@ class QWidget;
2526

2627
/** \ingroup gui
2728
* A text editor based on QScintilla2.
28-
* \note added in 2.1
29+
* \note added in 2.6
2930
*/
3031
class GUI_EXPORT QgsCodeEditor : public QsciScintilla
3132
{
@@ -39,20 +40,25 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
3940
* @param title The title to show in the code editor dialog
4041
* @param folding False: Enable margin for code editor
4142
* @param margin False: Enable folding for code editor
42-
* @note added in 2.1
43+
* @note added in 2.6
4344
*/
4445
QgsCodeEditor( QWidget *parent = 0, QString title = "" , bool folding = false, bool margin = false );
4546
~QgsCodeEditor();
4647

47-
/** Enable folding
48+
/** Set the widget title */
49+
void setTitle( QString );
50+
51+
/** Set margin visible state
4852
* @param margin Set margin in the editor
4953
*/
50-
bool enableMargin( bool margin );
54+
void setMarginVisible( bool margin );
55+
bool marginVisible() { return mMargin; }
5156

52-
/** Enable margin
57+
/** Set folding visible state
5358
* @param folding Set folding in the editor
5459
*/
55-
void enableFolding( bool folding );
60+
void setFoldingVisible( bool folding );
61+
bool foldingVisible() { return mFolding; }
5662

5763
protected:
5864

‎src/gui/qgscodeeditorpython.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/***************************************************************************
2-
qgscodeeditorpython.cpp - description
3-
--------------------------------------
2+
qgscodeeditorpython.cpp - A Python editor based on QScintilla
3+
--------------------------------------
44
Date : 06-Oct-2013
55
Copyright : (C) 2013 by Salvatore Larosa
66
Email : lrssvtml (at) gmail (dot) com
@@ -26,12 +26,12 @@
2626
#include <Qsci/qscilexerpython.h>
2727

2828
QgsCodeEditorPython::QgsCodeEditorPython( QWidget *parent, const QList<QString> &filenames )
29-
: QgsCodeEditor( parent ),
30-
mAPISFilesList( filenames )
29+
: QgsCodeEditor( parent )
30+
, mAPISFilesList( filenames )
3131
{
3232
if ( !parent )
3333
{
34-
setTitle( "Qscintilla2 Python Editor" );
34+
setTitle( tr( "Qscintilla2 Python Editor" ) );
3535
}
3636
setSciLexerPython();
3737
}
@@ -105,14 +105,10 @@ void QgsCodeEditorPython::setSciLexerPython()
105105
}
106106
setLexer( pyLexer );
107107

108-
enableMargin( true );
109-
enableFolding( true );
108+
setMarginVisible( true );
109+
setFoldingVisible( true );
110110
}
111111

112-
void QgsCodeEditorPython::setTitle( QString title )
113-
{
114-
setWindowTitle( title );
115-
}
116112

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

124-
void QgsCodeEditorPython::loadScript( const QString &script )
120+
bool QgsCodeEditorPython::loadScript( const QString &script )
125121
{
126122
QgsDebugMsg( QString( "The script file: %1" ).arg( script ) );
127123
QFile file( script );
128124
if ( !file.open( QIODevice::ReadOnly ) )
129125
{
130-
QMessageBox::information( 0, "error", file.errorString() );
126+
return false;
131127
}
132128

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

138134
setSciLexerPython();
135+
return true;
139136
}

‎src/gui/qgscodeeditorpython.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgscodeeditorpython.h - description
2+
qgscodeeditorpython.h - A Python editor based on QScintilla
33
--------------------------------------
44
Date : 06-Oct-2013
55
Copyright : (C) 2013 by Salvatore Larosa
@@ -20,9 +20,9 @@
2020

2121

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

42-
/** Set the widget title */
43-
void setTitle( QString );
44-
4542
/** Load APIs from one or more files
4643
* @param filenames The list of apis files to load for the python lexer
4744
*/
@@ -50,7 +47,7 @@ class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
5047
/** Load a script file
5148
* @param script The script file to load
5249
*/
53-
void loadScript( const QString &script );
50+
bool loadScript( const QString &script );
5451

5552
private:
5653
//QgsCodeEditor *mSciWidget;

‎src/gui/qgscodeeditorsql.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgscodeeditorsql.cpp - description
2+
qgscodeeditorsql.cpp - A SQL editor based on QScintilla
33
--------------------------------------
44
Date : 06-Oct-2013
55
Copyright : (C) 2013 by Salvatore Larosa
@@ -22,14 +22,15 @@
2222
#include <Qsci/qscilexersql.h>
2323

2424

25-
QgsCodeEditorSQL::QgsCodeEditorSQL( QWidget *parent ) : QgsCodeEditor( parent )
25+
QgsCodeEditorSQL::QgsCodeEditorSQL( QWidget *parent )
26+
: QgsCodeEditor( parent )
2627
{
2728
if ( !parent )
2829
{
29-
setTitle( "Qscintilla2 SQL Editor" );
30+
setTitle( tr( "Qscintilla2 SQL Editor" ) );
3031
}
31-
enableMargin( false );
32-
enableFolding( true );
32+
setMarginVisible( false );
33+
setFoldingVisible( true );
3334
setSciLexerSQL();
3435
}
3536

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

4546
setLexer( sqlLexer );
4647
}
47-
48-
void QgsCodeEditorSQL::setTitle( QString title )
49-
{
50-
setWindowTitle( title );
51-
}
52-
53-
void QgsCodeEditorSQL::showMargin( bool withMargin )
54-
{
55-
enableMargin( withMargin );
56-
}
57-
58-
void QgsCodeEditorSQL::showFolding( bool withFolding )
59-
{
60-
enableFolding( withFolding );
61-
}

‎src/gui/qgscodeeditorsql.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgscodeeditorsql.h - description
2+
qgscodeeditorsql.h - A SQL editor based on QScintilla
33
--------------------------------------
44
Date : 06-Oct-2013
55
Copyright : (C) 2013 by Salvatore Larosa
@@ -20,9 +20,9 @@
2020

2121

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

35-
void setTitle( QString );
36-
37-
void showMargin( bool withMargin );
38-
39-
void showFolding( bool withFolding );
40-
4135
private:
4236
//QgsCodeEditor *mSciWidget;
4337
//QWidget *mWidget;

0 commit comments

Comments
 (0)
Please sign in to comment.