Skip to content

Commit 44e543c

Browse files
committedJul 20, 2014
Merge pull request #1507 from NathanW2/code_editor
Code editor using QScintilla. Thanks to Salvatore Larosa for the initial work.
2 parents 4e2afeb + b2ff718 commit 44e543c

16 files changed

+603
-61
lines changed
 

‎python/gui/gui.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
%Import QtCore/QtCoremod.sip
66
%Import QtGui/QtGuimod.sip
77
%Import QtXml/QtXmlmod.sip
8+
%Import Qsci/qscimod4.sip
89

910
%Import core/core.sip
1011

@@ -19,6 +20,9 @@
1920
%Include qgsattributeforminterface.sip
2021
%Include qgsbusyindicatordialog.sip
2122
%Include qgscollapsiblegroupbox.sip
23+
%Include qgscodeeditor.sip
24+
%Include qgscodeeditorpython.sip
25+
%Include qgscodeeditorsql.sip
2226
%Include qgscolorbutton.sip
2327
%Include qgscolordialog.sip
2428
%Include qgscomposerview.sip

‎python/gui/qgscodeeditor.sip

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class QgsCodeEditor: QsciScintilla
2+
{
3+
%TypeHeaderCode
4+
#include <qgscodeeditor.h>
5+
%End
6+
7+
public:
8+
QgsCodeEditor( QWidget *parent /TransferThis/ = 0, QString title = "" , bool folding = false, bool margin = false );
9+
~QgsCodeEditor();
10+
11+
/** Set margin visible state
12+
* @param margin Set margin in the editor
13+
*/
14+
void setMarginVisible( bool margin );
15+
bool marginVisible();
16+
17+
/** Set folding visible state
18+
* @param folding Set folding in the editor
19+
*/
20+
void setFoldingVisible( bool folding);
21+
bool foldingVisible();
22+
};

‎python/gui/qgscodeeditorpython.sip

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class QgsCodeEditorPython: QgsCodeEditor
2+
{
3+
%TypeHeaderCode
4+
#include <qgscodeeditorpython.h>
5+
%End
6+
7+
public:
8+
QgsCodeEditorPython( QWidget *parent /TransferThis/ = 0, const QList<QString> &filenames = QList<QString>() );
9+
~QgsCodeEditorPython();
10+
11+
void loadAPIs(const QList<QString> &filenames );
12+
13+
bool loadScript( const QString &script );
14+
15+
};

‎python/gui/qgscodeeditorsql.sip

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class QgsCodeEditorSQL: QgsCodeEditor
2+
{
3+
%TypeHeaderCode
4+
#include <qgscodeeditorsql.h>
5+
%End
6+
7+
public:
8+
QgsCodeEditorSQL( QWidget *parent /TransferThis/ = 0 );
9+
~QgsCodeEditorSQL();
10+
};

‎src/app/qgsprojectproperties.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
463463
grpPythonMacros->setChecked( !pythonMacros.isEmpty() );
464464
if ( !pythonMacros.isEmpty() )
465465
{
466-
ptePythonMacros->setPlainText( pythonMacros );
466+
ptePythonMacros->setText( pythonMacros );
467467
}
468468
else
469469
{
@@ -867,7 +867,7 @@ void QgsProjectProperties::apply()
867867
QgsProject::instance()->writeEntry( "DefaultStyles", "/RandomColors", cbxStyleRandomColors->isChecked() );
868868

869869
// store project macros
870-
QString pythonMacros = ptePythonMacros->toPlainText();
870+
QString pythonMacros = ptePythonMacros->text();
871871
if ( !grpPythonMacros->isChecked() || pythonMacros.isEmpty() )
872872
{
873873
pythonMacros = QString::null;
@@ -1467,7 +1467,7 @@ void QgsProjectProperties::editSymbol( QComboBox* cbo )
14671467
void QgsProjectProperties::resetPythonMacros()
14681468
{
14691469
grpPythonMacros->setChecked( false );
1470-
ptePythonMacros->setPlainText( "def openProject():\n pass\n\n" \
1470+
ptePythonMacros->setText( "def openProject():\n pass\n\n" \
14711471
"def saveProject():\n pass\n\n" \
14721472
"def closeProject():\n pass\n" );
14731473
}

‎src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ TARGET_LINK_LIBRARIES(qgis_core
731731
${QT_QTNETWORK_LIBRARY}
732732
${QT_QTSVG_LIBRARY}
733733
${QT_QTWEBKIT_LIBRARY}
734+
${QSCINTILLA_LIBRARY}
734735

735736
${PROJ_LIBRARY}
736737
${GEOS_LIBRARY}

‎src/gui/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ qgscharacterselectdialog.cpp
126126
qgscollapsiblegroupbox.cpp
127127
qgscolorbutton.cpp
128128
qgscolordialog.cpp
129+
qgscodeeditor.cpp
130+
qgscodeeditorpython.cpp
131+
qgscodeeditorsql.cpp
129132
qgscomposerruler.cpp
130133
qgscomposerview.cpp
131134
qgsprevieweffect.cpp
@@ -316,6 +319,9 @@ qgsblendmodecombobox.h
316319
qgsbusyindicatordialog.h
317320
qgscharacterselectdialog.h
318321
qgscollapsiblegroupbox.h
322+
qgscodeeditor.h
323+
qgscodeeditorpython.h
324+
qgscodeeditorsql.h
319325
qgscolordialog.h
320326
qgsprevieweffect.h
321327
qgscomposerruler.h
@@ -668,6 +674,7 @@ TARGET_LINK_LIBRARIES(qgis_gui
668674

669675
IF(WIN32)
670676
ADD_DEFINITIONS(-DQWT_DLL)
677+
ADD_DEFINITIONS(-DQSCINTILLA_DLL)
671678
ENDIF(WIN32)
672679

673680
# install

‎src/gui/qgscodeeditor.cpp

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/***************************************************************************
2+
qgscodeeditor.cpp - A base code editor for QGIS and plugins. Provides
3+
a base editor using QScintilla for editors
4+
--------------------------------------
5+
Date : 06-Oct-2013
6+
Copyright : (C) 2013 by Salvatore Larosa
7+
Email : lrssvtml (at) gmail (dot) com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include "qgscodeeditor.h"
18+
19+
#include <QSettings>
20+
#include <QWidget>
21+
#include <QFont>
22+
#include <QDebug>
23+
24+
QgsCodeEditor::QgsCodeEditor( QWidget *parent, QString title, bool folding, bool margin )
25+
: QsciScintilla( parent )
26+
, mWidgetTitle( title )
27+
, mFolding( folding )
28+
, mMargin( margin )
29+
{
30+
if ( !parent && mWidgetTitle.isEmpty() )
31+
{
32+
setWindowTitle( "QScintilla2 Text Editor" );
33+
setMinimumSize( 800, 300 );
34+
}
35+
else
36+
{
37+
setWindowTitle( mWidgetTitle );
38+
}
39+
setSciWidget();
40+
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
41+
}
42+
43+
QgsCodeEditor::~QgsCodeEditor()
44+
{
45+
}
46+
47+
void QgsCodeEditor::setSciWidget()
48+
{
49+
setUtf8( true );
50+
setCaretLineVisible( true );
51+
setCaretLineBackgroundColor( QColor( "#fcf3ed" ) );
52+
53+
setBraceMatching( QsciScintilla::SloppyBraceMatch );
54+
setMatchedBraceBackgroundColor( QColor( "#b7f907" ) );
55+
// whether margin will be shown
56+
setMarginVisible( mMargin );
57+
// whether margin will be shown
58+
setFoldingVisible( mFolding );
59+
// indentation
60+
setAutoIndent( true );
61+
setIndentationWidth( 4 );
62+
setTabIndents( true );
63+
setBackspaceUnindents( true );
64+
setTabWidth( 4 );
65+
// autocomplete
66+
setAutoCompletionThreshold( 2 );
67+
setAutoCompletionSource( QsciScintilla::AcsAPIs );
68+
}
69+
70+
void QgsCodeEditor::setTitle( QString title )
71+
{
72+
setWindowTitle( title );
73+
}
74+
75+
void QgsCodeEditor::setMarginVisible( bool margin )
76+
{
77+
mMargin = margin;
78+
if ( margin )
79+
{
80+
QFont marginFont( "Courier", 10 );
81+
setMarginLineNumbers( 1, true );
82+
setMarginsFont( marginFont );
83+
setMarginWidth( 1, "00000" );
84+
setMarginsForegroundColor( QColor( "#3E3EE3" ) );
85+
setMarginsBackgroundColor( QColor( "#f9f9f9" ) );
86+
}
87+
else
88+
{
89+
setMarginWidth( 0, 0 );
90+
setMarginWidth( 1, 0 );
91+
setMarginWidth( 2, 0 );
92+
}
93+
}
94+
95+
void QgsCodeEditor::setFoldingVisible( bool folding )
96+
{
97+
mFolding = folding;
98+
if ( folding )
99+
{
100+
setFolding( QsciScintilla::PlainFoldStyle );
101+
setFoldMarginColors( QColor( "#f4f4f4" ), QColor( "#f4f4f4" ) );
102+
}
103+
else
104+
{
105+
setFolding( QsciScintilla::NoFoldStyle );
106+
}
107+
}
108+
109+
// Settings for font and fontsize
110+
bool QgsCodeEditor::isFixedPitch( const QFont& font )
111+
{
112+
const QFontInfo fi( font );
113+
return fi.fixedPitch();
114+
}
115+
116+
QFont QgsCodeEditor::getMonospaceFont()
117+
{
118+
QFont font( "monospace" );
119+
if ( isFixedPitch( font ) )
120+
{
121+
return font;
122+
}
123+
font.setStyleHint( QFont::Monospace );
124+
if ( isFixedPitch( font ) )
125+
{
126+
return font;
127+
}
128+
font.setStyleHint( QFont::TypeWriter );
129+
if ( isFixedPitch( font ) )
130+
{
131+
return font;
132+
}
133+
font.setFamily( "courier" );
134+
if ( isFixedPitch( font ) )
135+
{
136+
return font;
137+
}
138+
return font;
139+
}

‎src/gui/qgscodeeditor.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/***************************************************************************
2+
qgscodeeditor.h - A base code editor for QGIS and plugins. Provides
3+
a base editor using QScintilla for editors
4+
--------------------------------------
5+
Date : 06-Oct-2013
6+
Copyright : (C) 2013 by Salvatore Larosa
7+
Email : lrssvtml (at) gmail (dot) com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#ifndef QGSCODEEDITOR_H
18+
#define QGSCODEEDITOR_H
19+
20+
#include <QString>
21+
// qscintilla includes
22+
#include <Qsci/qsciapis.h>
23+
24+
25+
class QWidget;
26+
27+
/** \ingroup gui
28+
* A text editor based on QScintilla2.
29+
* \note added in 2.6
30+
*/
31+
class GUI_EXPORT QgsCodeEditor : public QsciScintilla
32+
{
33+
Q_OBJECT
34+
35+
public:
36+
/**
37+
* Construct a new code editor.
38+
*
39+
* @param parent The parent QWidget
40+
* @param title The title to show in the code editor dialog
41+
* @param folding False: Enable margin for code editor
42+
* @param margin False: Enable folding for code editor
43+
* @note added in 2.6
44+
*/
45+
QgsCodeEditor( QWidget *parent = 0, QString title = "" , bool folding = false, bool margin = false );
46+
~QgsCodeEditor();
47+
48+
/** Set the widget title */
49+
void setTitle( QString );
50+
51+
/** Set margin visible state
52+
* @param margin Set margin in the editor
53+
*/
54+
void setMarginVisible( bool margin );
55+
bool marginVisible() { return mMargin; }
56+
57+
/** Set folding visible state
58+
* @param folding Set folding in the editor
59+
*/
60+
void setFoldingVisible( bool folding );
61+
bool foldingVisible() { return mFolding; }
62+
63+
protected:
64+
65+
bool isFixedPitch( const QFont& font );
66+
67+
QFont getMonospaceFont();
68+
69+
private:
70+
71+
void setSciWidget();
72+
73+
QString mWidgetTitle;
74+
bool mFolding;
75+
bool mMargin;
76+
};
77+
78+
#endif

‎src/gui/qgscodeeditorpython.cpp

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/***************************************************************************
2+
qgscodeeditorpython.cpp - A Python editor based on QScintilla
3+
--------------------------------------
4+
Date : 06-Oct-2013
5+
Copyright : (C) 2013 by Salvatore Larosa
6+
Email : lrssvtml (at) gmail (dot) com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgsapplication.h"
17+
#include "qgscodeeditorpython.h"
18+
#include "qgslogger.h"
19+
20+
#include <QWidget>
21+
#include <QString>
22+
#include <QFont>
23+
#include <QFileInfo>
24+
#include <QMessageBox>
25+
#include <QTextStream>
26+
#include <Qsci/qscilexerpython.h>
27+
28+
QgsCodeEditorPython::QgsCodeEditorPython( QWidget *parent, const QList<QString> &filenames )
29+
: QgsCodeEditor( parent )
30+
, mAPISFilesList( filenames )
31+
{
32+
if ( !parent )
33+
{
34+
setTitle( tr( "Qscintilla2 Python Editor" ) );
35+
}
36+
setSciLexerPython();
37+
}
38+
39+
QgsCodeEditorPython::~QgsCodeEditorPython()
40+
{
41+
}
42+
43+
void QgsCodeEditorPython::setSciLexerPython()
44+
{
45+
// current line
46+
setCaretWidth( 2 );
47+
48+
setEdgeMode( QsciScintilla::EdgeLine );
49+
setEdgeColumn( 80 );
50+
setEdgeColor( QColor( "#FF0000" ) );
51+
52+
setWhitespaceVisibility( QsciScintilla::WsVisibleAfterIndent );
53+
54+
QFont font = getMonospaceFont();
55+
font.setPointSize( 10 );
56+
57+
QsciLexerPython* pyLexer = new QsciLexerPython();
58+
pyLexer->setDefaultFont( font );
59+
pyLexer->setFont( font, 1 ); // comment
60+
pyLexer->setFont( font, 3 ); // singlequotes
61+
pyLexer->setFont( font, 4 ); // doublequotes
62+
pyLexer->setFont( font, 6 ); // triplequotes
63+
pyLexer->setColor( Qt::red, 1 ); // comment color
64+
pyLexer->setColor( Qt::darkGreen, 5 ); // keyword color
65+
pyLexer->setColor( Qt::darkBlue, 15 ); // decorator color
66+
67+
QsciAPIs* apis = new QsciAPIs( pyLexer );
68+
69+
// check if the file is a prepared apis file.
70+
//QString mPapFileName = QFileInfo( mAPISFilesList[0] ).fileName();
71+
//QString isPapFile = mPapFileName.right( 3 );
72+
//QgsDebugMsg( QString( "file extension: %1" ).arg( isPapFile ) );
73+
74+
if ( mAPISFilesList.isEmpty() )
75+
{
76+
mPapFile = QgsApplication::pkgDataPath() + "/python/qsci_apis/pyqgis.pap";
77+
apis->loadPrepared( mPapFile );
78+
}
79+
else if ( mAPISFilesList.length() == 1 && mAPISFilesList[0].right( 3 ) == "pap" )
80+
{
81+
if ( !QFileInfo( mAPISFilesList[0] ).exists() )
82+
{
83+
QgsDebugMsg( QString( "The apis file %1 not found" ).arg( mAPISFilesList[0] ) );
84+
return;
85+
}
86+
mPapFile = mAPISFilesList[0];
87+
apis->loadPrepared( mPapFile );
88+
}
89+
else
90+
{
91+
for ( int i = 0; i < mAPISFilesList.size(); i++ )
92+
{
93+
if ( !QFileInfo( mAPISFilesList[i] ).exists() )
94+
{
95+
QgsDebugMsg( QString( "The apis file %1 was not found" ).arg( mAPISFilesList[i] ) );
96+
return;
97+
}
98+
else
99+
{
100+
apis->load( mAPISFilesList[i] );
101+
}
102+
}
103+
apis->prepare();
104+
pyLexer->setAPIs( apis );
105+
}
106+
setLexer( pyLexer );
107+
108+
setMarginVisible( true );
109+
setFoldingVisible( true );
110+
}
111+
112+
113+
void QgsCodeEditorPython::loadAPIs( const QList<QString> &filenames )
114+
{
115+
mAPISFilesList = filenames;
116+
//QgsDebugMsg( QString( "The apis files: %1" ).arg( mAPISFilesList[0] ) );
117+
setSciLexerPython();
118+
}
119+
120+
bool QgsCodeEditorPython::loadScript( const QString &script )
121+
{
122+
QgsDebugMsg( QString( "The script file: %1" ).arg( script ) );
123+
QFile file( script );
124+
if ( !file.open( QIODevice::ReadOnly ) )
125+
{
126+
return false;
127+
}
128+
129+
QTextStream in( &file );
130+
131+
setText( in.readAll() );
132+
file.close();
133+
134+
setSciLexerPython();
135+
return true;
136+
}

‎src/gui/qgscodeeditorpython.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/***************************************************************************
2+
qgscodeeditorpython.h - A Python editor based on QScintilla
3+
--------------------------------------
4+
Date : 06-Oct-2013
5+
Copyright : (C) 2013 by Salvatore Larosa
6+
Email : lrssvtml (at) gmail (dot) com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSCODEEDITORPYTHON_H
17+
#define QGSCODEEDITORPYTHON_H
18+
19+
#include "qgscodeeditor.h"
20+
21+
22+
/** \ingroup gui
23+
* A Python editor based on QScintilla2. Adds syntax highlighting and
24+
* code autocompletion.
25+
* \note added in 2.6
26+
*/
27+
class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
28+
{
29+
Q_OBJECT
30+
31+
public:
32+
/**
33+
* Construct a new Python editor.
34+
*
35+
* @param parent The parent QWidget
36+
* @param filenames The list of apis files to load for the python lexer
37+
* @note added in 2.6
38+
*/
39+
QgsCodeEditorPython( QWidget *parent = 0 , const QList<QString> &filenames = QList<QString>() );
40+
~QgsCodeEditorPython();
41+
42+
/** Load APIs from one or more files
43+
* @param filenames The list of apis files to load for the python lexer
44+
*/
45+
void loadAPIs( QList<QString> const &filenames );
46+
47+
/** Load a script file
48+
* @param script The script file to load
49+
*/
50+
bool loadScript( const QString &script );
51+
52+
private:
53+
//QgsCodeEditor *mSciWidget;
54+
//QWidget *mWidget;
55+
void setSciLexerPython();
56+
57+
QList<QString> mAPISFilesList;
58+
QString mPapFile;
59+
60+
};
61+
62+
#endif

‎src/gui/qgscodeeditorsql.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/***************************************************************************
2+
qgscodeeditorsql.cpp - A SQL editor based on QScintilla
3+
--------------------------------------
4+
Date : 06-Oct-2013
5+
Copyright : (C) 2013 by Salvatore Larosa
6+
Email : lrssvtml (at) gmail (dot) com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgsapplication.h"
17+
#include "qgscodeeditorsql.h"
18+
19+
#include <QWidget>
20+
#include <QString>
21+
#include <QFont>
22+
#include <Qsci/qscilexersql.h>
23+
24+
25+
QgsCodeEditorSQL::QgsCodeEditorSQL( QWidget *parent )
26+
: QgsCodeEditor( parent )
27+
{
28+
if ( !parent )
29+
{
30+
setTitle( tr( "Qscintilla2 SQL Editor" ) );
31+
}
32+
setMarginVisible( false );
33+
setFoldingVisible( true );
34+
setSciLexerSQL();
35+
}
36+
37+
QgsCodeEditorSQL::~QgsCodeEditorSQL()
38+
{
39+
}
40+
41+
void QgsCodeEditorSQL::setSciLexerSQL()
42+
{
43+
QsciLexerSQL* sqlLexer = new QsciLexerSQL();
44+
sqlLexer->setDefaultFont( QFont( "Sans", 10 ) );
45+
46+
setLexer( sqlLexer );
47+
}

‎src/gui/qgscodeeditorsql.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/***************************************************************************
2+
qgscodeeditorsql.h - A SQL editor based on QScintilla
3+
--------------------------------------
4+
Date : 06-Oct-2013
5+
Copyright : (C) 2013 by Salvatore Larosa
6+
Email : lrssvtml (at) gmail (dot) com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSCODEEDITORSQL_H
17+
#define QGSCODEEDITORSQL_H
18+
19+
#include "qgscodeeditor.h"
20+
21+
22+
/** \ingroup gui
23+
* A SQL editor based on QScintilla2. Adds syntax highlighting and
24+
* code autocompletion.
25+
* \note added in 2.6
26+
*/
27+
class GUI_EXPORT QgsCodeEditorSQL : public QgsCodeEditor
28+
{
29+
Q_OBJECT
30+
31+
public:
32+
QgsCodeEditorSQL( QWidget *parent = 0 );
33+
~QgsCodeEditorSQL();
34+
35+
private:
36+
//QgsCodeEditor *mSciWidget;
37+
//QWidget *mWidget;
38+
void setSciLexerSQL();
39+
};
40+
41+
#endif

‎src/gui/qgsexpressionbuilderwidget.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
3232

3333
mValueGroupBox->hide();
3434
mLoadGroupBox->hide();
35-
highlighter = new QgsExpressionHighlighter( txtExpressionString->document() );
35+
// highlighter = new QgsExpressionHighlighter( txtExpressionString->document() );
3636

3737
mModel = new QStandardItemModel( );
3838
mProxyModel = new QgsExpressionItemSearchProxy();
@@ -158,7 +158,7 @@ void QgsExpressionBuilderWidget::on_expressionTree_doubleClicked( const QModelIn
158158
return;
159159

160160
// Insert the expression text.
161-
txtExpressionString->insertPlainText( item->getExpressionText() );
161+
txtExpressionString->insert( item->getExpressionText() );
162162
txtExpressionString->setFocus();
163163
}
164164

@@ -185,7 +185,7 @@ void QgsExpressionBuilderWidget::loadFieldNames( const QgsFields& fields )
185185
fieldNames << fieldName;
186186
registerItem( "Fields and Values", fieldName, " \"" + fieldName + "\" ", "", QgsExpressionItem::Field );
187187
}
188-
highlighter->addFields( fieldNames );
188+
// highlighter->addFields( fieldNames );
189189
}
190190

191191
void QgsExpressionBuilderWidget::fillFieldValues( int fieldIndex, int countLimit )
@@ -289,17 +289,17 @@ void QgsExpressionBuilderWidget::setGeomCalculator( const QgsDistanceArea & da )
289289

290290
QString QgsExpressionBuilderWidget::expressionText()
291291
{
292-
return txtExpressionString->toPlainText();
292+
return txtExpressionString->text();
293293
}
294294

295295
void QgsExpressionBuilderWidget::setExpressionText( const QString& expression )
296296
{
297-
txtExpressionString->setPlainText( expression );
297+
txtExpressionString->setText( expression );
298298
}
299299

300300
void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
301301
{
302-
QString text = txtExpressionString->toPlainText();
302+
QString text = txtExpressionString->text();
303303

304304
// If the string is empty the expression will still "fail" although
305305
// we don't show the user an error as it will be confusing.
@@ -392,14 +392,14 @@ void QgsExpressionBuilderWidget::on_lblPreview_linkActivated( QString link )
392392

393393
void QgsExpressionBuilderWidget::on_mValueListWidget_itemDoubleClicked( QListWidgetItem *item )
394394
{
395-
txtExpressionString->insertPlainText( " " + item->text() + " " );
395+
txtExpressionString->insert( " " + item->text() + " " );
396396
txtExpressionString->setFocus();
397397
}
398398

399399
void QgsExpressionBuilderWidget::operatorButtonClicked()
400400
{
401401
QPushButton* button = dynamic_cast<QPushButton*>( sender() );
402-
txtExpressionString->insertPlainText( " " + button->text() + " " );
402+
txtExpressionString->insert( " " + button->text() + " " );
403403
txtExpressionString->setFocus();
404404
}
405405

‎src/ui/qgsexpressionbuilder.ui

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -441,37 +441,9 @@
441441
<bool>true</bool>
442442
</property>
443443
<layout class="QGridLayout" name="gridLayout">
444-
<property name="leftMargin">
445-
<number>0</number>
446-
</property>
447-
<property name="topMargin">
448-
<number>9</number>
449-
</property>
450-
<property name="rightMargin">
451-
<number>0</number>
452-
</property>
453-
<property name="bottomMargin">
444+
<property name="margin">
454445
<number>0</number>
455446
</property>
456-
<item row="0" column="0" colspan="2">
457-
<widget class="QTextEdit" name="txtExpressionString">
458-
<property name="sizePolicy">
459-
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
460-
<horstretch>0</horstretch>
461-
<verstretch>0</verstretch>
462-
</sizepolicy>
463-
</property>
464-
<property name="minimumSize">
465-
<size>
466-
<width>0</width>
467-
<height>32</height>
468-
</size>
469-
</property>
470-
<property name="cursor" stdset="0">
471-
<cursorShape>IBeamCursor</cursorShape>
472-
</property>
473-
</widget>
474-
</item>
475447
<item row="1" column="0">
476448
<widget class="QLabel" name="label_2">
477449
<property name="sizePolicy">
@@ -533,6 +505,9 @@
533505
</property>
534506
</widget>
535507
</item>
508+
<item row="0" column="0" colspan="2">
509+
<widget class="QgsCodeEditorSQL" name="txtExpressionString" native="true"/>
510+
</item>
536511
</layout>
537512
</widget>
538513
</item>
@@ -554,6 +529,12 @@
554529
<extends>QLineEdit</extends>
555530
<header>qgsfilterlineedit.h</header>
556531
</customwidget>
532+
<customwidget>
533+
<class>QgsCodeEditorSQL</class>
534+
<extends>QWidget</extends>
535+
<header>qgscodeeditorsql.h</header>
536+
<container>1</container>
537+
</customwidget>
557538
</customwidgets>
558539
<resources/>
559540
<connections/>

‎src/ui/qgsprojectpropertiesbase.ui

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
</sizepolicy>
192192
</property>
193193
<property name="currentIndex">
194-
<number>0</number>
194+
<number>5</number>
195195
</property>
196196
<widget class="QWidget" name="mProjOpts_01">
197197
<layout class="QVBoxLayout" name="verticalLayout_6">
@@ -211,8 +211,8 @@
211211
<rect>
212212
<x>0</x>
213213
<y>0</y>
214-
<width>683</width>
215-
<height>779</height>
214+
<width>684</width>
215+
<height>783</height>
216216
</rect>
217217
</property>
218218
<layout class="QVBoxLayout" name="verticalLayout_8">
@@ -798,8 +798,8 @@
798798
<rect>
799799
<x>0</x>
800800
<y>0</y>
801-
<width>683</width>
802-
<height>779</height>
801+
<width>238</width>
802+
<height>43</height>
803803
</rect>
804804
</property>
805805
<layout class="QVBoxLayout" name="verticalLayout_7">
@@ -848,8 +848,8 @@
848848
<rect>
849849
<x>0</x>
850850
<y>0</y>
851-
<width>683</width>
852-
<height>779</height>
851+
<width>684</width>
852+
<height>783</height>
853853
</rect>
854854
</property>
855855
<layout class="QVBoxLayout" name="verticalLayout_10">
@@ -920,8 +920,8 @@
920920
<rect>
921921
<x>0</x>
922922
<y>0</y>
923-
<width>683</width>
924-
<height>779</height>
923+
<width>684</width>
924+
<height>783</height>
925925
</rect>
926926
</property>
927927
<layout class="QVBoxLayout" name="verticalLayout_12">
@@ -1289,7 +1289,7 @@
12891289
<x>0</x>
12901290
<y>0</y>
12911291
<width>667</width>
1292-
<height>1570</height>
1292+
<height>1391</height>
12931293
</rect>
12941294
</property>
12951295
<layout class="QVBoxLayout" name="verticalLayout_13">
@@ -2003,8 +2003,8 @@
20032003
<rect>
20042004
<x>0</x>
20052005
<y>0</y>
2006-
<width>166</width>
2007-
<height>114</height>
2006+
<width>684</width>
2007+
<height>783</height>
20082008
</rect>
20092009
</property>
20102010
<layout class="QVBoxLayout" name="verticalLayout_17">
@@ -2027,14 +2027,7 @@
20272027
</property>
20282028
<layout class="QVBoxLayout" name="verticalLayout_16">
20292029
<item>
2030-
<widget class="QPlainTextEdit" name="ptePythonMacros">
2031-
<property name="documentTitle">
2032-
<string notr="true"/>
2033-
</property>
2034-
<property name="plainText">
2035-
<string/>
2036-
</property>
2037-
</widget>
2030+
<widget class="QgsCodeEditorPython" name="ptePythonMacros" native="true"/>
20382031
</item>
20392032
</layout>
20402033
</widget>
@@ -2109,6 +2102,12 @@
21092102
<header>qgsprojectionselector.h</header>
21102103
<container>1</container>
21112104
</customwidget>
2105+
<customwidget>
2106+
<class>QgsCodeEditorPython</class>
2107+
<extends>QWidget</extends>
2108+
<header>qgscodeeditorpython.h</header>
2109+
<container>1</container>
2110+
</customwidget>
21122111
</customwidgets>
21132112
<tabstops>
21142113
<tabstop>buttonBox</tabstop>
@@ -2200,10 +2199,10 @@
22002199
<tabstop>mWCSUrlLineEdit</tabstop>
22012200
<tabstop>scrollArea_6</tabstop>
22022201
<tabstop>grpPythonMacros</tabstop>
2203-
<tabstop>ptePythonMacros</tabstop>
22042202
</tabstops>
22052203
<resources>
22062204
<include location="../../images/images.qrc"/>
2205+
<include location="../../images/images.qrc"/>
22072206
</resources>
22082207
<connections>
22092208
<connection>

0 commit comments

Comments
 (0)
Please sign in to comment.