QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgscodeeditorsql.cpp
Go to the documentation of this file.
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 <QLabel>
23 #include <Qsci/qscilexersql.h>
24 
25 
27  : QgsCodeEditor( parent )
28 {
29  if ( !parent )
30  {
31  setTitle( tr( "SQL Editor" ) );
32  }
33  setMarginVisible( false );
34  setFoldingVisible( true );
35  setAutoCompletionCaseSensitivity( false );
36  setSciLexerSQL();
37 }
38 
40 {
41 }
42 
51 class QgsCaseInsensitiveLexerSQL: public QsciLexerSQL
52 {
53  public:
55  explicit QgsCaseInsensitiveLexerSQL( QObject *parent = 0 ) : QsciLexerSQL( parent ) {}
56 
57  bool caseSensitive() const override { return false; }
58 };
59 
60 void QgsCodeEditorSQL::setSciLexerSQL()
61 {
62  QFont font = getMonospaceFont();
63 #ifdef Q_OS_MAC
64  // The font size gotten from getMonospaceFont() is too small on Mac
65  font.setPointSize( QLabel().font().pointSize() );
66 #endif
67  QsciLexerSQL* sqlLexer = new QgsCaseInsensitiveLexerSQL( this );
68  sqlLexer->setDefaultFont( font );
69  sqlLexer->setFont( font, -1 );
70  font.setBold( true );
71  sqlLexer->setFont( font, QsciLexerSQL::Keyword );
72  sqlLexer->setColor( Qt::darkYellow, QsciLexerSQL::DoubleQuotedString ); // fields
73 
74  setLexer( sqlLexer );
75 }
void setPointSize(int pointSize)
A text editor based on QScintilla2.
Definition: qgscodeeditor.h:32
bool caseSensitive() const override
void setFoldingVisible(bool folding)
Set folding visible state.
QFont getMonospaceFont()
void setBold(bool enable)
QgsCodeEditorSQL(QWidget *parent=nullptr)
void setMarginVisible(bool margin)
Set margin visible state.
QgsCaseInsensitiveLexerSQL(QObject *parent=0)
constructor
void setTitle(const QString &title)
Set the widget title.