Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #1507 from NathanW2/code_editor
Code editor using QScintilla. Thanks to Salvatore Larosa for the initial work.
- Loading branch information
Showing
16 changed files
with
603 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class QgsCodeEditor: QsciScintilla | ||
{ | ||
%TypeHeaderCode | ||
#include <qgscodeeditor.h> | ||
%End | ||
|
||
public: | ||
QgsCodeEditor( QWidget *parent /TransferThis/ = 0, QString title = "" , bool folding = false, bool margin = false ); | ||
~QgsCodeEditor(); | ||
|
||
/** Set margin visible state | ||
* @param margin Set margin in the editor | ||
*/ | ||
void setMarginVisible( bool margin ); | ||
bool marginVisible(); | ||
|
||
/** Set folding visible state | ||
* @param folding Set folding in the editor | ||
*/ | ||
void setFoldingVisible( bool folding); | ||
bool foldingVisible(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class QgsCodeEditorPython: QgsCodeEditor | ||
{ | ||
%TypeHeaderCode | ||
#include <qgscodeeditorpython.h> | ||
%End | ||
|
||
public: | ||
QgsCodeEditorPython( QWidget *parent /TransferThis/ = 0, const QList<QString> &filenames = QList<QString>() ); | ||
~QgsCodeEditorPython(); | ||
|
||
void loadAPIs(const QList<QString> &filenames ); | ||
|
||
bool loadScript( const QString &script ); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class QgsCodeEditorSQL: QgsCodeEditor | ||
{ | ||
%TypeHeaderCode | ||
#include <qgscodeeditorsql.h> | ||
%End | ||
|
||
public: | ||
QgsCodeEditorSQL( QWidget *parent /TransferThis/ = 0 ); | ||
~QgsCodeEditorSQL(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/*************************************************************************** | ||
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 | ||
Email : lrssvtml (at) gmail (dot) com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgscodeeditor.h" | ||
|
||
#include <QSettings> | ||
#include <QWidget> | ||
#include <QFont> | ||
#include <QDebug> | ||
|
||
QgsCodeEditor::QgsCodeEditor( QWidget *parent, QString title, bool folding, bool margin ) | ||
: QsciScintilla( parent ) | ||
, mWidgetTitle( title ) | ||
, mFolding( folding ) | ||
, mMargin( margin ) | ||
{ | ||
if ( !parent && mWidgetTitle.isEmpty() ) | ||
{ | ||
setWindowTitle( "QScintilla2 Text Editor" ); | ||
setMinimumSize( 800, 300 ); | ||
} | ||
else | ||
{ | ||
setWindowTitle( mWidgetTitle ); | ||
} | ||
setSciWidget(); | ||
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); | ||
} | ||
|
||
QgsCodeEditor::~QgsCodeEditor() | ||
{ | ||
} | ||
|
||
void QgsCodeEditor::setSciWidget() | ||
{ | ||
setUtf8( true ); | ||
setCaretLineVisible( true ); | ||
setCaretLineBackgroundColor( QColor( "#fcf3ed" ) ); | ||
|
||
setBraceMatching( QsciScintilla::SloppyBraceMatch ); | ||
setMatchedBraceBackgroundColor( QColor( "#b7f907" ) ); | ||
// whether margin will be shown | ||
setMarginVisible( mMargin ); | ||
// whether margin will be shown | ||
setFoldingVisible( mFolding ); | ||
// indentation | ||
setAutoIndent( true ); | ||
setIndentationWidth( 4 ); | ||
setTabIndents( true ); | ||
setBackspaceUnindents( true ); | ||
setTabWidth( 4 ); | ||
// autocomplete | ||
setAutoCompletionThreshold( 2 ); | ||
setAutoCompletionSource( QsciScintilla::AcsAPIs ); | ||
} | ||
|
||
void QgsCodeEditor::setTitle( QString title ) | ||
{ | ||
setWindowTitle( title ); | ||
} | ||
|
||
void QgsCodeEditor::setMarginVisible( bool margin ) | ||
{ | ||
mMargin = margin; | ||
if ( margin ) | ||
{ | ||
QFont marginFont( "Courier", 10 ); | ||
setMarginLineNumbers( 1, true ); | ||
setMarginsFont( marginFont ); | ||
setMarginWidth( 1, "00000" ); | ||
setMarginsForegroundColor( QColor( "#3E3EE3" ) ); | ||
setMarginsBackgroundColor( QColor( "#f9f9f9" ) ); | ||
} | ||
else | ||
{ | ||
setMarginWidth( 0, 0 ); | ||
setMarginWidth( 1, 0 ); | ||
setMarginWidth( 2, 0 ); | ||
} | ||
} | ||
|
||
void QgsCodeEditor::setFoldingVisible( bool folding ) | ||
{ | ||
mFolding = folding; | ||
if ( folding ) | ||
{ | ||
setFolding( QsciScintilla::PlainFoldStyle ); | ||
setFoldMarginColors( QColor( "#f4f4f4" ), QColor( "#f4f4f4" ) ); | ||
} | ||
else | ||
{ | ||
setFolding( QsciScintilla::NoFoldStyle ); | ||
} | ||
} | ||
|
||
// Settings for font and fontsize | ||
bool QgsCodeEditor::isFixedPitch( const QFont& font ) | ||
{ | ||
const QFontInfo fi( font ); | ||
return fi.fixedPitch(); | ||
} | ||
|
||
QFont QgsCodeEditor::getMonospaceFont() | ||
{ | ||
QFont font( "monospace" ); | ||
if ( isFixedPitch( font ) ) | ||
{ | ||
return font; | ||
} | ||
font.setStyleHint( QFont::Monospace ); | ||
if ( isFixedPitch( font ) ) | ||
{ | ||
return font; | ||
} | ||
font.setStyleHint( QFont::TypeWriter ); | ||
if ( isFixedPitch( font ) ) | ||
{ | ||
return font; | ||
} | ||
font.setFamily( "courier" ); | ||
if ( isFixedPitch( font ) ) | ||
{ | ||
return font; | ||
} | ||
return font; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*************************************************************************** | ||
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 | ||
Email : lrssvtml (at) gmail (dot) com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSCODEEDITOR_H | ||
#define QGSCODEEDITOR_H | ||
|
||
#include <QString> | ||
// qscintilla includes | ||
#include <Qsci/qsciapis.h> | ||
|
||
|
||
class QWidget; | ||
|
||
/** \ingroup gui | ||
* A text editor based on QScintilla2. | ||
* \note added in 2.6 | ||
*/ | ||
class GUI_EXPORT QgsCodeEditor : public QsciScintilla | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
/** | ||
* Construct a new code editor. | ||
* | ||
* @param parent The parent QWidget | ||
* @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.6 | ||
*/ | ||
QgsCodeEditor( QWidget *parent = 0, QString title = "" , bool folding = false, bool margin = false ); | ||
~QgsCodeEditor(); | ||
|
||
/** Set the widget title */ | ||
void setTitle( QString ); | ||
|
||
/** Set margin visible state | ||
* @param margin Set margin in the editor | ||
*/ | ||
void setMarginVisible( bool margin ); | ||
bool marginVisible() { return mMargin; } | ||
|
||
/** Set folding visible state | ||
* @param folding Set folding in the editor | ||
*/ | ||
void setFoldingVisible( bool folding ); | ||
bool foldingVisible() { return mFolding; } | ||
|
||
protected: | ||
|
||
bool isFixedPitch( const QFont& font ); | ||
|
||
QFont getMonospaceFont(); | ||
|
||
private: | ||
|
||
void setSciWidget(); | ||
|
||
QString mWidgetTitle; | ||
bool mFolding; | ||
bool mMargin; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.