Skip to content

Commit

Permalink
Merge ad6773e into 5d47ea4
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Jun 7, 2018
2 parents 5d47ea4 + ad6773e commit 4fd6251
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 51 deletions.
24 changes: 12 additions & 12 deletions src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.cpp
Expand Up @@ -240,9 +240,9 @@ bool CellmlTextViewWidgetEditingWidget::handleEditorKeyPressEvent(QKeyEvent *pEv
// editor

EditorWidget::EditorWidgetEditorWidget *editor = editorWidget()->editor();
int lineNumber, columnNumber;
int line, column;

editor->getCursorPosition(&lineNumber, &columnNumber);
editor->getCursorPosition(&line, &column);

// Check whether some text is selected

Expand Down Expand Up @@ -339,29 +339,29 @@ bool CellmlTextViewWidgetEditingWidget::handleEditorKeyPressEvent(QKeyEvent *pEv

// Reselect the text/lines

if ((lineNumber == lineFrom) && (columnNumber == columnFrom))
if ((line == lineFrom) && (column == columnFrom))
editor->setSelection(lineTo, columnTo, lineFrom, columnFrom);
else
editor->setSelection(lineFrom, columnFrom, lineTo, columnTo);
} else {
// No text is selected, so simply (un)comment the current line

bool commentLine = !editor->text(lineNumber).trimmed().startsWith(SingleLineCommentString);
bool commentLine = !editor->text(line).trimmed().startsWith(SingleLineCommentString);

if (commentOrUncommentLine(editor, lineNumber, commentLine)) {
if (commentOrUncommentLine(editor, line, commentLine)) {
if (commentLine) {
// We commented the line, so our position will be fine
// unless we were at the beginning of the line, in which
// case we need to update it

if (!columnNumber)
editor->QsciScintilla::setCursorPosition(lineNumber, columnNumber+SingleLineCommentLength);
if (!column)
editor->QsciScintilla::setCursorPosition(line, column+SingleLineCommentLength);
} else {
// We uncommented the line, so go back to our original
// position (since uncommenting the line will have shifted
// it a bit)

editor->QsciScintilla::setCursorPosition(lineNumber, columnNumber-SingleLineCommentLength);
editor->QsciScintilla::setCursorPosition(line, column-SingleLineCommentLength);
}
}
}
Expand Down Expand Up @@ -895,15 +895,15 @@ void CellmlTextViewWidget::reformat(const QString &pFileName)

if (data && parse(pFileName, true)) {
EditorWidget::EditorWidget *editor = data->editingWidget()->editorWidget();
int cursorLine;
int cursorColumn;
int line;
int column;

editor->cursorPosition(cursorLine, cursorColumn);
editor->cursorPosition(line, column);

mConverter.execute(Core::serialiseDomDocument(mParser.domDocument()));

editor->setContents(mConverter.output(), true);
editor->setCursorPosition(cursorLine, cursorColumn);
editor->setCursorPosition(line, column);
}
}

Expand Down
38 changes: 19 additions & 19 deletions src/plugins/editing/RawCellMLView/src/rawcellmlviewwidget.cpp
Expand Up @@ -115,38 +115,38 @@ void RawCellmlViewWidget::initialize(const QString &pFileName, bool pUpdate)
{
// Retrieve the editing widget associated with the given file, if any

CellMLEditingView::CellmlEditingViewWidget *newEditingWidget = mEditingWidgets.value(pFileName);
CellMLEditingView::CellmlEditingViewWidget *editingWidget = mEditingWidgets.value(pFileName);

if (!newEditingWidget) {
if (!editingWidget) {
// No editing widget exists for the given file, so create one

QByteArray fileContents;

Core::readFileContentsFromFile(pFileName, fileContents);

newEditingWidget = new CellMLEditingView::CellmlEditingViewWidget(fileContents,
!Core::FileManager::instance()->isReadableAndWritable(pFileName),
new QsciLexerXML(this),
parentWidget());
editingWidget = new CellMLEditingView::CellmlEditingViewWidget(fileContents,
!Core::FileManager::instance()->isReadableAndWritable(pFileName),
new QsciLexerXML(this),
parentWidget());

// Update our viewer whenever necessary

connect(newEditingWidget->editorWidget(), &EditorWidget::EditorWidget::textChanged,
connect(editingWidget->editorWidget(), &EditorWidget::EditorWidget::textChanged,
this, &RawCellmlViewWidget::updateViewer);
connect(newEditingWidget->editorWidget(), &EditorWidget::EditorWidget::cursorPositionChanged,
connect(editingWidget->editorWidget(), &EditorWidget::EditorWidget::cursorPositionChanged,
this, &RawCellmlViewWidget::updateViewer);

// Keep track of our editing widget

mEditingWidgets.insert(pFileName, newEditingWidget);
mEditingWidgets.insert(pFileName, editingWidget);
}

// Update our editing widget, if required

if (pUpdate) {
CellMLEditingView::CellmlEditingViewWidget *oldEditingWidget = mEditingWidget;

mEditingWidget = newEditingWidget;
mEditingWidget = editingWidget;

// Load our settings, if needed, or reset our editing widget using the
// 'old' one
Expand All @@ -155,12 +155,12 @@ void RawCellmlViewWidget::initialize(const QString &pFileName, bool pUpdate)
QSettings settings;

settings.beginGroup(mSettingsGroup);
newEditingWidget->loadSettings(&settings);
editingWidget->loadSettings(&settings);
settings.endGroup();

mNeedLoadingSettings = false;
} else {
newEditingWidget->updateSettings(oldEditingWidget);
editingWidget->updateSettings(oldEditingWidget);
}

// Update our viewer
Expand All @@ -174,13 +174,13 @@ void RawCellmlViewWidget::initialize(const QString &pFileName, bool pUpdate)
// our 'old' editing widget (see CentralWidget::updateGui()),
// which is clearly not what we want...

setFocusProxy(newEditingWidget->editorWidget());
setFocusProxy(editingWidget->editorWidget());

newEditingWidget->editorWidget()->setFocus();
editingWidget->editorWidget()->setFocus();
} else {
// Hide our 'new' editing widget

newEditingWidget->hide();
editingWidget->hide();
}
}

Expand Down Expand Up @@ -306,17 +306,17 @@ void RawCellmlViewWidget::reformat(const QString &pFileName)
CellMLEditingView::CellmlEditingViewWidget *editingWidget = mEditingWidgets.value(pFileName);

if (editingWidget && validate(pFileName, true)) {
int cursorLine;
int cursorColumn;
int line;
int column;

editingWidget->editorWidget()->cursorPosition(cursorLine, cursorColumn);
editingWidget->editorWidget()->cursorPosition(line, column);

QDomDocument domDocument;

domDocument.setContent(editingWidget->editorWidget()->contents());

editingWidget->editorWidget()->setContents(Core::serialiseDomDocument(domDocument), true);
editingWidget->editorWidget()->setCursorPosition(cursorLine, cursorColumn);
editingWidget->editorWidget()->setCursorPosition(line, column);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/editing/RawSEDMLView/src/rawsedmlviewwidget.cpp
Expand Up @@ -286,17 +286,17 @@ void RawSedmlViewWidget::reformat(const QString &pFileName)
SEDMLEditingView::SedmlEditingViewWidget *editingWidget = mEditingWidgets.value(pFileName);

if (editingWidget && validate(pFileName, true)) {
int cursorLine;
int cursorColumn;
int line;
int column;

editingWidget->editorWidget()->cursorPosition(cursorLine, cursorColumn);
editingWidget->editorWidget()->cursorPosition(line, column);

QDomDocument domDocument;

domDocument.setContent(editingWidget->editorWidget()->contents());

editingWidget->editorWidget()->setContents(Core::serialiseDomDocument(domDocument), true);
editingWidget->editorWidget()->setCursorPosition(cursorLine, cursorColumn);
editingWidget->editorWidget()->setCursorPosition(line, column);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/plugins/miscellaneous/Core/src/corecliutils.h
Expand Up @@ -35,6 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QByteArray>
#include <QCoreApplication>
#include <QDomDocument>
#include <QSet>
#include <QSourceLocation>
#include <QSslError>
#include <QUrl>
Expand All @@ -61,6 +62,12 @@ typedef QList<double> QDoubleList;

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

typedef QSet<bool> QBoolSet;
typedef QSet<int> QIntSet;
typedef QSet<double> QDoubleSet;

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

QBoolList CORE_EXPORT qVariantListToBoolList(const QVariantList &pVariantList);
QVariantList CORE_EXPORT qBoolListToVariantList(const QBoolList &pBoolList);

Expand Down
Expand Up @@ -336,12 +336,8 @@ void QScintillaWidget::selectWordAt(int pLine, int pColumn)
int startPosition = SendScintilla(SCI_WORDSTARTPOSITION, position, true);
int endPosition = SendScintilla(SCI_WORDENDPOSITION, position, true);

if (endPosition-startPosition > 0) {
setSelection(SendScintilla(SCI_LINEFROMPOSITION, startPosition),
SendScintilla(SCI_GETCOLUMN, startPosition),
SendScintilla(SCI_LINEFROMPOSITION, endPosition),
SendScintilla(SCI_GETCOLUMN, endPosition));
}
if (endPosition-startPosition > 0)
SendScintilla(SCI_SETSEL, startPosition, endPosition);
}

//==============================================================================
Expand Down
18 changes: 9 additions & 9 deletions src/plugins/widget/EditorWidget/src/editorwidget.cpp
Expand Up @@ -196,15 +196,6 @@ void EditorWidget::updateSettings(EditorWidget *pEditorWidget)

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

EditorWidgetEditorWidget * EditorWidget::editor() const
{
// Return our editor

return mEditor;
}

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

bool EditorWidget::handleEditorKeyPressEvent(QKeyEvent *pEvent)
{
Q_UNUSED(pEvent);
Expand Down Expand Up @@ -522,6 +513,15 @@ void EditorWidget::setZoomLevel(int pZoomLevel)

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

EditorWidgetEditorWidget * EditorWidget::editor() const
{
// Return our editor

return mEditor;
}

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

EditorWidgetFindReplaceWidget * EditorWidget::findReplace()
{
// Return our find/replace widget
Expand Down
1 change: 0 additions & 1 deletion src/plugins/widget/EditorWidget/src/editorwidget.h
Expand Up @@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

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

//#include "corecliutils.h"
#include "editorwidgetglobal.h"
#include "widget.h"

Expand Down

0 comments on commit 4fd6251

Please sign in to comment.