Skip to content

Commit

Permalink
feat: R syntax highlighter in analysis panel controls (#5538)
Browse files Browse the repository at this point in the history
* init r language highlighter

* rename lavaan bound contorls to r lang

* add special number case

* also enable highlighter for R syntax text area

* fix strings format and also styles

* add rsyntaxhighlighter quickitem, to make non jasp textareas highlighted easily
  • Loading branch information
shun2wang authored Sep 5, 2024
1 parent 3e14bd4 commit 89f12d8
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 129 deletions.
7 changes: 7 additions & 0 deletions Desktop/components/JASP/Widgets/ComputeColumnWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import QtQuick 2.7
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.3
import JASP.Controls 1.0 as JaspControls
import JASP

import "FilterConstructor"

Expand Down Expand Up @@ -103,6 +104,12 @@ FocusScope
TextArea
{
id: computeColumnEdit

RSyntaxHighlighterQuick
{
textDocument: computeColumnEdit.textDocument
}


anchors.top: parent.top
anchors.left: parent.left
Expand Down
11 changes: 11 additions & 0 deletions Desktop/components/JASP/Widgets/FilterWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import QtQuick 2.12
import QtQuick.Controls 2.12
import JASP.Controls 1.0 as JaspControls
import "FilterConstructor"
import JASP

FocusScope
{
Expand Down Expand Up @@ -302,6 +303,11 @@ FocusScope

TextArea
{
RSyntaxHighlighterQuick
{
textDocument: filterGeneratedEdit.textDocument
}

id: filterGeneratedEdit
anchors.top: filterGeneratedBox.top
anchors.left: resetAllGeneratedFilters.right
Expand Down Expand Up @@ -347,6 +353,11 @@ FocusScope
TextArea
{

RSyntaxHighlighterQuick
{
textDocument: filterEdit.textDocument
}

id: filterEdit
height: contentHeight + 30
selectByMouse: true
Expand Down
12 changes: 12 additions & 0 deletions Desktop/components/JASP/Widgets/RCommanderWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ Window

TextArea
{
RSyntaxHighlighterQuick
{
textDocument: outputWindow.textDocument
}

id: outputWindow
text: rCmd.output
font: jaspTheme.fontRCode
Expand Down Expand Up @@ -192,6 +197,13 @@ Window

TextArea
{

RSyntaxHighlighterQuick
{
textDocument: codeEntry.textDocument
}


id: codeEntry
font: jaspTheme.fontRCode
color: jaspTheme.textEnabled
Expand Down
5 changes: 3 additions & 2 deletions Desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@
#include <iostream>

#include "log.h"
#include "dirs.h"
#include "timers.h"
#include "appinfo.h"
#include "tempfiles.h"
#include "processinfo.h"
#include "columnutils.h"

#include "mainwindow.h"

#include "analysisform.h"
Expand All @@ -46,6 +45,7 @@
#include "controls/comboboxbase.h"
#include "controls/textinputbase.h"
#include "controls/componentslistbase.h"
#include "controls/rsyntaxhighlighter.h"
#include "controls/factorsformbase.h"
#include "controls/inputlistbase.h"
#include "controls/textareabase.h"
Expand Down Expand Up @@ -180,6 +180,7 @@ MainWindow::MainWindow(QApplication * application) : QObject(application), _appl
qmlRegisterType<ComboBoxBase> ("JASP", 1, 0, "ComboBoxBase" );
qmlRegisterType<RadioButtonBase> ("JASP", 1, 0, "RadioButtonBase" );
qmlRegisterType<RadioButtonsGroupBase> ("JASP", 1, 0, "RadioButtonsGroupBase" );
qmlRegisterType<RSyntaxHighlighterQuick> ("JASP", 1, 0, "RSyntaxHighlighterQuick" );
qmlRegisterType<ComponentsListBase> ("JASP", 1, 0, "ComponentsListBase" );
qmlRegisterType<FactorsFormBase> ("JASP", 1, 0, "FactorsFormBase" );
qmlRegisterType<InputListBase> ("JASP", 1, 0, "InputListBase" );
Expand Down
6 changes: 3 additions & 3 deletions QMLComponents/boundcontrols/boundcontrolcsemtextarea.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef BOUNDCONTROLCSEMTEXTAREA_H
#define BOUNDCONTROLCSEMTEXTAREA_H

#include "boundcontrollavaantextarea.h"
#include "boundcontrolrlangtextarea.h"

class BoundControlCSemTextArea : public BoundControlLavaanTextArea
class BoundControlCSemTextArea : public BoundControlRlangTextArea
{
public:
using BoundControlLavaanTextArea::BoundControlLavaanTextArea;
using BoundControlRlangTextArea::BoundControlRlangTextArea;

protected:
const char * _checkSyntaxRFunctionName() override { return "jaspSem:::checkCSemModel"; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
// <http://www.gnu.org/licenses/>.
//

#include "boundcontrollavaantextarea.h"
#include "boundcontrolrlangtextarea.h"
#include "controls/textareabase.h"
#include "log.h"
#include "columnencoder.h"
#include "analysisform.h"
#include <QQuickTextDocument>

BoundControlLavaanTextArea::BoundControlLavaanTextArea(TextAreaBase *textArea)
BoundControlRlangTextArea::BoundControlRlangTextArea(TextAreaBase *textArea)
: BoundControlTextArea(textArea)
{

Expand All @@ -32,14 +32,14 @@ BoundControlLavaanTextArea::BoundControlLavaanTextArea(TextAreaBase *textArea)
if (textDocumentQQuick)
{
QTextDocument* doc = textDocumentQQuick->textDocument();
_lavaanHighlighter = new LavaanSyntaxHighlighter(doc);
_rLangHighlighter = new RSyntaxHighlighter(doc);
//connect(doc, &QTextDocument::contentsChanged, this, &BoundQMLTextArea::contentsChangedHandler);
}
else
Log::log() << "No document object found!" << std::endl;
}

void BoundControlLavaanTextArea::bindTo(const Json::Value &value)
void BoundControlRlangTextArea::bindTo(const Json::Value &value)
{
if (value.type() != Json::objectValue) return;
BoundControlBase::bindTo(value);
Expand All @@ -50,7 +50,7 @@ void BoundControlLavaanTextArea::bindTo(const Json::Value &value)

}

Json::Value BoundControlLavaanTextArea::createJson() const
Json::Value BoundControlRlangTextArea::createJson() const
{
Json::Value result;
std::string text = _textArea->text().toStdString();
Expand All @@ -62,7 +62,7 @@ Json::Value BoundControlLavaanTextArea::createJson() const
return result;
}

bool BoundControlLavaanTextArea::isJsonValid(const Json::Value &value) const
bool BoundControlRlangTextArea::isJsonValid(const Json::Value &value) const
{
if (!value.isObject()) return false;
if (!value["modelOriginal"].isString()) return false;
Expand All @@ -73,7 +73,7 @@ bool BoundControlLavaanTextArea::isJsonValid(const Json::Value &value) const
return true;
}

void BoundControlLavaanTextArea::checkSyntax()
void BoundControlRlangTextArea::checkSyntax()
{
QString text = _textArea->text();

Expand Down Expand Up @@ -103,7 +103,7 @@ void BoundControlLavaanTextArea::checkSyntax()

}

QString BoundControlLavaanTextArea::rScriptDoneHandler(const QString & result)
QString BoundControlRlangTextArea::rScriptDoneHandler(const QString & result)
{
if (!result.isEmpty())
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
// <http://www.gnu.org/licenses/>.
//

#ifndef BOUNDCONTROLLAVAANTEXTAREA_H
#define BOUNDCONTROLLAVAANTEXTAREA_H
#ifndef BOUNDCONTROLRLANGTEXTAREA_H
#define BOUNDCONTROLRLANGTEXTAREA_H

#include "boundcontroltextarea.h"
#include "controls/lavaansyntaxhighlighter.h"
#include "controls/rsyntaxhighlighter.h"

class BoundControlLavaanTextArea : public BoundControlTextArea
class BoundControlRlangTextArea : public BoundControlTextArea
{
public:
BoundControlLavaanTextArea(TextAreaBase* textArea);
BoundControlRlangTextArea(TextAreaBase* textArea);

bool isJsonValid(const Json::Value& optionValue) const override;
Json::Value createJson() const override;
Expand All @@ -35,12 +35,12 @@ class BoundControlLavaanTextArea : public BoundControlTextArea
QString rScriptDoneHandler(const QString &result) override;

protected:
LavaanSyntaxHighlighter* _lavaanHighlighter = nullptr;
RSyntaxHighlighter* _rLangHighlighter = nullptr;

std::set<std::string> _usedColumnNames;
QString _textEncoded;
virtual const char * _checkSyntaxRFunctionName() { return "jaspSem:::checkLavaanModel"; }

};

#endif // BOUNDCONTROLLAVAANTEXTAREA_H
#endif // BOUNDCONTROLRLANGTEXTAREA_H
1 change: 1 addition & 0 deletions QMLComponents/components/JASP/Controls/Form.qml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ AnalysisForm
width: parent.width
height: visible ? 100 * preferencesModel.uiScale : 0
text: form.rSyntaxText
textType: JASPControl.TextTypeRcode
isBound: false
onApplyRequest: form.sendRSyntax(text)

Expand Down
64 changes: 0 additions & 64 deletions QMLComponents/controls/lavaansyntaxhighlighter.cpp

This file was deleted.

43 changes: 0 additions & 43 deletions QMLComponents/controls/lavaansyntaxhighlighter.h

This file was deleted.

Loading

0 comments on commit 89f12d8

Please sign in to comment.