QGIS API Documentation 3.39.0-Master (bca3cdb6021)
Loading...
Searching...
No Matches
qgscodeeditorr.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgscodeeditorr.cpp - A R stats editor based on QScintilla
3 --------------------------------------
4 Date : October 2022
5 Copyright : (C) 2022 by Nyall Dawson
6 Email : nyall dot dawson 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 "qgscodeeditorr.h"
18
19#include <QWidget>
20#include <QString>
21#include <QFont>
22#include <Qsci/qscilexerjson.h>
23
24
25QgsCodeEditorR::QgsCodeEditorR( QWidget *parent, Mode mode )
26 : QgsCodeEditor( parent,
27 QString(),
28 false,
29 false,
30 QgsCodeEditor::Flag::CodeFolding,
31 mode )
32{
33 if ( !parent )
34 {
35 setTitle( tr( "R Editor" ) );
36 }
38}
39
44
46{
47 QgsQsciLexerR *lexer = new QgsQsciLexerR( this );
48
49 QFont font = lexerFont();
50 lexer->setDefaultFont( font );
51 lexer->setFont( font, -1 );
52
53 font.setItalic( true );
54 lexer->setFont( font, QgsQsciLexerR::Comment );
55
59
60 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Default ), QgsQsciLexerR::Default );
61 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::CommentLine ), QgsQsciLexerR::Comment );
62 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Keyword ), QgsQsciLexerR::Kword );
63 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Method ), QgsQsciLexerR::BaseKword );
64 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Class ), QgsQsciLexerR::OtherKword );
65 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Number ), QgsQsciLexerR::Number );
66 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QgsQsciLexerR::String );
67 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QgsQsciLexerR::String2 );
68 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Operator ), QgsQsciLexerR::Operator );
69 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Identifier ), QgsQsciLexerR::Identifier );
70 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Tag ), QgsQsciLexerR::Infix );
71 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::UnknownTag ), QgsQsciLexerR::InfixEOL );
72 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Tag ), QgsQsciLexerR::Backticks );
73 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::SingleQuote ), QgsQsciLexerR::RawString );
74 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::SingleQuote ), QgsQsciLexerR::RawString2 );
75 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Decoration ), QgsQsciLexerR::EscapeSequence );
76
77 setLexer( lexer );
80}
81
83QgsQsciLexerR::QgsQsciLexerR( QObject *parent )
84 : QsciLexer( parent )
85{
86
87}
88
89const char *QgsQsciLexerR::language() const
90{
91 return "r";
92}
93
94const char *QgsQsciLexerR::lexer() const
95{
96 return nullptr;
97}
98
99int QgsQsciLexerR::lexerId() const
100{
101 return QsciScintillaBase::SCLEX_R;
102}
103
104QString QgsQsciLexerR::description( int style ) const
105{
106 switch ( style )
107 {
108 case Default:
109 return tr( "Default" );
110 case Comment:
111 return tr( "Comment" );
112 case Kword:
113 return tr( "Keyword" );
114 case BaseKword:
115 return tr( "Base Keyword" );
116 case OtherKword:
117 return tr( "Other Keyword" );
118 case Number:
119 return tr( "Number" );
120 case String:
121 return tr( "String" );
122 case String2:
123 return tr( "String 2" );
124 case Operator:
125 return tr( "Operator" );
126 case Identifier:
127 return tr( "Identifier" );
128 case Infix:
129 return tr( "Infix" );
130 case InfixEOL:
131 return tr( "Infix EOL" );
132 case Backticks:
133 return tr( "Backticks" );
134 case RawString:
135 return tr( "Raw String" );
136 case RawString2:
137 return tr( "Raw String 2" );
138 case EscapeSequence:
139 return tr( "Escape Sequence" );
140 }
141 return QString();
142}
143
144const char *QgsQsciLexerR::keywords( int set ) const
145{
146 switch ( set )
147 {
148 case 1:
149 return "if else repeat while function for in next break TRUE FALSE NULL NA Inf NaN";
150
151 case 2:
152 return "abbreviate abline abs acf acos acosh addmargins aggregate agrep alarm alias alist all anova any aov aperm append apply approx "
153 "approxfun apropos ar args arima array arrows asin asinh assign assocplot atan atanh attach attr attributes autoload autoloader "
154 "ave axis backsolve barplot basename beta bindtextdomain binomial biplot bitmap bmp body box boxplot bquote break browser builtins "
155 "bxp by bzfile c call cancor capabilities casefold cat category cbind ccf ceiling character charmatch chartr chol choose chull "
156 "citation class close cm cmdscale codes coef coefficients col colnames colors colorspaces colours comment complex confint " //#spellok
157 "conflicts contour contrasts contributors convolve cophenetic coplot cor cos cosh cov covratio cpgram crossprod cummax cummin "
158 "cumprod cumsum curve cut cutree cycle data dataentry date dbeta dbinom dcauchy dchisq de debug debugger decompose delay deltat "
159 "demo dendrapply density deparse deriv det detach determinant deviance dexp df dfbeta dfbetas dffits dgamma dgeom dget dhyper "
160 "diag diff diffinv difftime digamma dim dimnames dir dirname dist dlnorm dlogis dmultinom dnbinom dnorm dotchart double dpois "
161 "dput drop dsignrank dt dump dunif duplicated dweibull dwilcox eapply ecdf edit effects eigen emacs embed end environment eval "
162 "evalq example exists exp expression factanal factor factorial family fft fifo file filter find fitted fivenum fix floor flush "
163 "for force formals format formula forwardsolve fourfoldplot frame frequency ftable function gamma gaussian gc gcinfo gctorture "
164 "get getenv geterrmessage gettext gettextf getwd gl glm globalenv gray grep grey grid gsub gzcon gzfile hat hatvalues hcl "
165 "hclust head heatmap help hist history hsv httpclient iconv iconvlist identical identify if ifelse image influence inherits "
166 "integer integrate interaction interactive intersect invisible isoreg jitter jpeg julian kappa kernapply kernel kmeans knots "
167 "kronecker ksmooth labels lag lapply layout lbeta lchoose lcm legend length letters levels lfactorial lgamma library licence "
168 "license line lines list lm load loadhistory loadings local locator loess log logb logical loglin lowess ls lsfit machine mad "
169 "mahalanobis makepredictcall manova mapply match matlines matplot matpoints matrix max mean median medpolish menu merge "
170 "message methods mget min missing mode monthplot months mosaicplot mtext mvfft names napredict naprint naresid nargs nchar "
171 "ncol next nextn ngettext nlevels nlm nls noquote nrow numeric objects offset open optim optimise optimize options order "
172 "ordered outer pacf page pairlist pairs palette par parse paste pbeta pbinom pbirthday pcauchy pchisq pdf pentagamma person "
173 "persp pexp pf pgamma pgeom phyper pi pico pictex pie piechart pipe plclust plnorm plogis plot pmatch pmax pmin pnbinom png "
174 "pnorm points poisson poly polygon polym polyroot postscript power ppoints ppois ppr prcomp predict preplot pretty princomp "
175 "print prmatrix prod profile profiler proj promax prompt provide psigamma psignrank pt ptukey punif pweibull pwilcox q qbeta "
176 "qbinom qbirthday qcauchy qchisq qexp qf qgamma qgeom qhyper qlnorm qlogis qnbinom qnorm qpois qqline qqnorm qqplot qr "
177 "qsignrank qt qtukey quantile quarters quasi quasibinomial quasipoisson quit qunif quote qweibull qwilcox rainbow range "
178 "rank raw rbeta rbind rbinom rcauchy rchisq readline real recover rect reformulate regexpr relevel remove reorder rep repeat "
179 "replace replicate replications require reshape resid residuals restart return rev rexp rf rgamma rgb rgeom rhyper rle rlnorm "
180 "rlogis rm rmultinom rnbinom rnorm round row rownames rowsum rpois rsignrank rstandard rstudent rt rug runif runmed rweibull "
181 "rwilcox sample sapply save savehistory scale scan screen screeplot sd search searchpaths seek segments seq sequence serialize "
182 "setdiff setequal setwd shell sign signif sin single sinh sink smooth solve sort source spectrum spline splinefun split sprintf "
183 "sqrt stack stars start stderr stdin stdout stem step stepfun stl stop stopifnot str strftime strheight stripchart strptime "
184 "strsplit strtrim structure strwidth strwrap sub subset substitute substr substring sum summary sunflowerplot supsmu svd sweep "
185 "switch symbols symnum system t table tabulate tail tan tanh tapply tempdir tempfile termplot terms tetragamma text time title "
186 "toeplitz tolower topenv toupper trace traceback transform trigamma trunc truncate try ts tsdiag tsp typeof unclass undebug "
187 "union unique uniroot unix unlink unlist unname unserialize unsplit unstack untrace unz update upgrade url var varimax vcov "
188 "vector version vi vignette warning warnings weekdays weights which while window windows with write wsbrowser xedit xemacs "
189 "xfig xinch xor xtabs xyinch yinch zapsmall";
190
191 case 3:
192 return "acme aids aircondit amis aml banking barchart barley beaver bigcity boot brambles breslow bs bwplot calcium cane capability "
193 "cav censboot channing city claridge cloth cloud coal condense contourplot control corr darwin densityplot dogs dotplot ducks "
194 "empinf envelope environmental ethanol fir frets gpar grav gravity grob hirose histogram islay knn larrows levelplot llines "
195 "logit lpoints lsegments lset ltext lvqinit lvqtest manaus melanoma melanoma motor multiedit neuro nitrofen nodal ns nuclear "
196 "oneway parallel paulsen poisons polar qq qqmath remission rfs saddle salinity shingle simplex singer somgrid splom stripplot "
197 "survival tau tmd tsboot tuna unit urine viewport wireframe wool xyplot";
198 }
199
200 return nullptr;
201}
202
ScriptLanguage
Scripting languages.
Definition qgis.h:4153
@ DoubleQuote
Double quote color.
@ CommentLine
Line comment color.
@ SingleQuote
Single quote color.
QgsCodeEditorR(QWidget *parent=nullptr, QgsCodeEditor::Mode mode=QgsCodeEditor::Mode::ScriptEditor)
Constructor for QgsCodeEditorR.
void initializeLexer() override
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
Qgis::ScriptLanguage language() const override
Returns the associated scripting language.
A text editor based on QScintilla2.
Mode
Code editor modes.
void runPostLexerConfigurationTasks()
Performs tasks which must be run after a lexer has been set for the widget.
void setTitle(const QString &title)
Set the widget title.
Flag
Flags controlling behavior of code editor.
void setLineNumbersVisible(bool visible)
Sets whether line numbers should be visible in the editor.
QFont lexerFont() const
Returns the font to use in the lexer.
QColor lexerColor(QgsCodeEditorColorScheme::ColorRole role) const
Returns the color to use in the lexer for the specified role.