Skip to content

Commit

Permalink
Merge 507781c into a5ec7ae
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Dec 20, 2018
2 parents a5ec7ae + 507781c commit ccff989
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 64 deletions.
1 change: 1 addition & 0 deletions doc/downloads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var jsonData = { "versions": [
"changes": [
{ "change": "<strong>General:</strong> upgraded to Qt 5.12.0 LTS (see issue <a href=\"https://github.com/opencor/opencor/issues/1910\">#1910</a>)." },
{ "change": "<strong>COMBINE support:</strong> now recognise files that have a master attribute of \"1\" rather than \"true\" (see issue <a href=\"https://github.com/opencor/opencor/issues/1912\">#1912</a>)." },
{ "change": "<strong>CellML Text view:</strong> improved Unicode support (see issue <a href=\"https://github.com/opencor/opencor/issues/1926\">#1926</a>)." },
{ "change": "<strong>Third-party libraries:</strong> upgraded <a href=\"http://www.llvm.org/\">LLVM</a>+<a href=\"http://clang.llvm.org/\">Clang</a> to version 7.0.1 (see issue <a href=\"https://github.com/opencor/opencor/issues/1917\">#1917</a>). Upgraded <a href=\"https://www.mesa3d.org/\">Mesa</a> to version 18.2.7 (see issue <a href=\"https://github.com/opencor/opencor/issues/1918\">#1918</a>). Upgraded the <a href=\"http://computation.llnl.gov/projects/sundials\">SUNDIALS</a> library to version 4.0.0 (see issue <a href=\"https://github.com/opencor/opencor/issues/1919\">#1919</a>)." }
]
},
Expand Down
9 changes: 9 additions & 0 deletions doc/whatIsNew.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
var jsonData = { "versions": [
{ "anchor": "latest", "description": "Latest snapshot", "day": 11, "month": 12, "year": 2018,
"categories": [
{ "name": "Editing",
"entries": [
{ "type": "subCategory", "name": "CellML Text view",
"entries": [
{ "type": "improved", "description": "Unicode support." }
]
}
]
},
{ "name": "Support",
"entries": [
{ "type": "subCategory", "name": "COMBINE support",
Expand Down
1 change: 1 addition & 0 deletions src/plugins/editing/CellMLTextView/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_plugin(CellMLTextView
src/cellmltextviewwidget.cpp
HEADERS_MOC
src/cellmltextviewconverter.h
src/cellmltextviewlexer.h
src/cellmltextviewparser.h
src/cellmltextviewplugin.h
src/cellmltextviewscanner.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ void CellmlTextViewLexer::styleText(int pBytesStart, int pBytesEnd)
if (editor()->SendScintilla(QsciScintillaBase::SCI_GETENDSTYLED) != pBytesEnd)
qFatal("FATAL ERROR | %s:%d: the styling of the text must be incremental.", __FILE__, __LINE__);
#endif

// Let people know that we are done with our styling

emit done();
}

//==============================================================================
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/editing/CellMLTextView/src/cellmltextviewlexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace CellMLTextView {

class CellmlTextViewLexer : public QsciLexerCustom
{
Q_OBJECT

public:
enum {
Default,
Expand Down Expand Up @@ -99,6 +101,9 @@ class CellmlTextViewLexer : public QsciLexerCustom

int fullTextBytesPosition(int pPosition) const;
int textBytesPosition(const QString &pText, int pPosition) const;

signals:
void done();
};

//==============================================================================
Expand Down
138 changes: 76 additions & 62 deletions src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,18 @@ void CellmlTextViewWidget::initialize(const QString &pFileName, bool pUpdate)
// The conversion was successful, so we can apply our CellML Text
// lexer to our editor

editingWidget->editorWidget()->setLexer(new CellmlTextViewLexer(this));
CellmlTextViewLexer *lexer = new CellmlTextViewLexer(this);

editingWidget->editorWidget()->setLexer(lexer);

// Update our viewer whenever necessary
// Note: normally, we would update our viewer when the text has
// changed or the cursor position has changed. However, when
// it comes to the text being changed, we need to make sure
// that the styling is done, hence checking for the lexer to
// be done...

connect(editingWidget->editorWidget(), &EditorWidget::EditorWidget::textChanged,
connect(lexer, &CellmlTextViewLexer::done,
this, &CellmlTextViewWidget::updateViewer);
connect(editingWidget->editorWidget(), &EditorWidget::EditorWidget::cursorPositionChanged,
this, &CellmlTextViewWidget::updateViewer);
Expand Down Expand Up @@ -997,6 +1004,19 @@ bool CellmlTextViewWidget::parse(const QString &pFileName, bool pOnlyErrors)

//==============================================================================

bool CellmlTextViewWidget::isComment(int pPosition) const
{
// Return whether we have a single or multiline comment at the given
// position

int style = mEditingWidget->editorWidget()->styleAt(pPosition);

return (style == CellmlTextViewLexer::SingleLineComment)
|| (style == CellmlTextViewLexer::MultilineComment);
}

//==============================================================================

QString CellmlTextViewWidget::partialStatement(int pPosition,
int &pFromPosition,
int &pToPosition) const
Expand Down Expand Up @@ -1124,87 +1144,81 @@ QString CellmlTextViewWidget::endOfPiecewiseStatement(int &pPosition) const

//==============================================================================

QString CellmlTextViewWidget::statement(int pPosition) const
void CellmlTextViewWidget::updateViewer()
{
// Retrieve the (partial) statement around the given position
// Make sure that we still have an editing widget (i.e. it hasn't been
// closed since the signal was emitted) and that its editor allows us to
// handle connections

int fromPosition;
int toPosition;
if ( !mEditingWidget
|| !mEditingWidget->editorWidget()->handleEditorChanges()) {
return;
}

QString currentStatement = partialStatement(pPosition, fromPosition, toPosition);
// Make sure that our current position is not within a comment

// Check, using our CellML Text parser, whether our (partial) statement
// contains something that we can recognise
int position = mEditingWidget->editorWidget()->currentPosition();
QString currentStatement = QString();

CellmlTextViewParser parser;
if (!isComment(position)) {
// Retrieve the (partial) statement around our current position

if (parser.execute(currentStatement, false)) {
if (parser.statementType() == CellmlTextViewParser::PiecewiseSel) {
// We are at the beginning of a piecewise statement, so retrieve its
// end
int fromPosition;
int toPosition;

currentStatement += endOfPiecewiseStatement(toPosition);
} else if ( (parser.statementType() == CellmlTextViewParser::PiecewiseCase)
|| (parser.statementType() == CellmlTextViewParser::PiecewiseOtherwise)) {
// We are in the middle of a piecewise statement, so retrieve both
// its beginning and end
currentStatement = partialStatement(position, fromPosition, toPosition);

currentStatement = beginningOfPiecewiseStatement(fromPosition)+currentStatement+endOfPiecewiseStatement(toPosition);
} else if (parser.statementType() == CellmlTextViewParser::PiecewiseEndSel) {
// We are at the beginning of a piecewise statement, so retrieve its
// beginning
// Check, using our CellML Text parser, whether our (partial) statement
// contains something that we can recognise

currentStatement = beginningOfPiecewiseStatement(fromPosition)+currentStatement;
}
CellmlTextViewParser parser;

// Skip spaces and comments to determine the real start of our current
// statement
if (parser.execute(currentStatement, false)) {
if (parser.statementType() == CellmlTextViewParser::PiecewiseSel) {
// We are at the beginning of a piecewise statement, so retrieve
// its end

EditorWidget::EditorWidget *editor = mEditingWidget->editorWidget();
int shift = 0;
int style;
currentStatement += endOfPiecewiseStatement(toPosition);
} else if ( (parser.statementType() == CellmlTextViewParser::PiecewiseCase)
|| (parser.statementType() == CellmlTextViewParser::PiecewiseOtherwise)) {
// We are in the middle of a piecewise statement, so retrieve
// both its beginning and end

forever {
style = editor->styleAt(fromPosition);
currentStatement = beginningOfPiecewiseStatement(fromPosition)+currentStatement+endOfPiecewiseStatement(toPosition);
} else if (parser.statementType() == CellmlTextViewParser::PiecewiseEndSel) {
// We are at the beginning of a piecewise statement, so retrieve
// its beginning

if ( (style == CellmlTextViewLexer::SingleLineComment)
|| (style == CellmlTextViewLexer::MultilineComment)
|| currentStatement[shift].isSpace()) {
++fromPosition;
++shift;
} else {
break;
currentStatement = beginningOfPiecewiseStatement(fromPosition)+currentStatement;
}
}

// Make sure that we are within our current statement

return ((pPosition >= fromPosition) && (pPosition < toPosition))?
editor->textInRange(fromPosition, toPosition):
QString();
} else {
// Our current statement doesn't contain something that we can recognise
// Skip spaces and comments to determine the real start of our
// current statement

return QString();
}
}
int shift = 0;

//==============================================================================
forever {
if (isComment(fromPosition) || currentStatement[shift].isSpace()) {
fromPosition += QString(currentStatement[shift]).toUtf8().size();

void CellmlTextViewWidget::updateViewer()
{
// Make sure that we still have an editing widget (i.e. it hasn't been
// closed since the signal was emitted) and that its editor allows us to
// handle connections
++shift;
} else {
break;
}
}

if ( !mEditingWidget
|| !mEditingWidget->editorWidget()->handleEditorChanges()) {
return;
}
// Make sure that we are within our current statement

// Retrieve the statement, if any, around our current position
currentStatement = ((position >= fromPosition) && (position < toPosition))?
mEditingWidget->editorWidget()->textInRange(fromPosition, toPosition):
QString();
} else {
// Our current statement doesn't contain something that we can
// recognise

QString currentStatement = statement(mEditingWidget->editorWidget()->currentPosition());
currentStatement = QString();
}
}

// Update the contents of our viewer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,12 @@ class CellmlTextViewWidget : public Core::ViewWidget
bool parse(const QString &pFileName, QString &pExtra);
bool parse(const QString &pFileName, bool pOnlyErrors = false);

bool isComment(int pPosition) const;

QString partialStatement(int pPosition, int &pFromPosition,
int &pToPosition) const;
QString beginningOfPiecewiseStatement(int &pPosition) const;
QString endOfPiecewiseStatement(int &pPosition) const;
QString statement(int pPosition) const;

private slots:
void updateViewer();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/widget/EditorWidget/src/editorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ int EditorWidget::styleAt(int pPosition) const
// Return the style used at the given position

return int(mEditor->SendScintilla(QsciScintilla::SCI_GETSTYLEAT,
mEditor->text().left(pPosition).toUtf8().length()));
pPosition));
}

//==============================================================================
Expand Down

0 comments on commit ccff989

Please sign in to comment.