Skip to content

Commit d5d7b9e

Browse files
committed
Merge branch 'master' of https://github.com/OpenModelica/OMEdit
Conflicts: OMEdit/OMEditGUI/MainWindow.cpp
2 parents a8c6795 + e4bab47 commit d5d7b9e

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

OMEdit/OMEditGUI/Editors/TLMEditor.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "TLMEditor.h"
3333

3434
TLMEditor::TLMEditor(ModelWidget *pModelWidget)
35-
: BaseEditor(pModelWidget)
35+
: BaseEditor(pModelWidget), mTextChanged(false)
3636
{
3737
connect(this, SIGNAL(focusOut()), mpModelWidget, SLOT(TLMEditorTextChanged()));
3838
}
@@ -54,20 +54,41 @@ void TLMEditor::showContextMenu(QPoint point)
5454
void TLMEditor::contentsHasChanged(int position, int charsRemoved, int charsAdded)
5555
{
5656
Q_UNUSED(position);
57-
if (mpModelWidget->isVisible())
58-
{
59-
if (charsRemoved == 0 && charsAdded == 0)
57+
if (mpModelWidget->isVisible()) {
58+
if (charsRemoved == 0 && charsAdded == 0) {
6059
return;
61-
mpModelWidget->setModelModified();
60+
}
61+
/* if user is changing the text. */
62+
if (!mForceSetPlainText) {
63+
mpModelWidget->setModelModified();
64+
mTextChanged = true;
65+
}
6266
}
6367
}
6468

65-
bool TLMEditor::TLMEditorFocusChanged()
69+
bool TLMEditor::validateMetaModelText()
6670
{
67-
emit focusOut();
71+
if (mTextChanged) {
72+
emit focusOut();
73+
}
6874
return true;
6975
}
7076

77+
/*!
78+
* \brief TLMEditor::setPlainText
79+
* Reimplementation of QPlainTextEdit::setPlainText method.
80+
* Makes sure we dont update if the passed text is same.
81+
* \param text the string to set.
82+
*/
83+
void TLMEditor::setPlainText(const QString &text)
84+
{
85+
if (text != mpPlainTextEdit->toPlainText()) {
86+
mForceSetPlainText = true;
87+
mpPlainTextEdit->setPlainText(text);
88+
mForceSetPlainText = false;
89+
}
90+
}
91+
7192
//! @class TLMHighlighter
7293
//! @brief A syntax highlighter for TLMEditor.
7394

OMEdit/OMEditGUI/Editors/TLMEditor.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ class TLMEditor : public BaseEditor
4747
Q_OBJECT
4848
public:
4949
TLMEditor(ModelWidget *pModelWidget);
50-
bool TLMEditorFocusChanged();
50+
bool validateMetaModelText();
51+
void setPlainText(const QString &text);
52+
private:
53+
bool mForceSetPlainText;
54+
bool mTextChanged;
5155
signals:
5256
bool focusOut();
5357
private slots:

OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ void LibraryTreeWidget::openTLMFile(QFileInfo fileInfo, bool showProgress)
19511951
}
19521952
}
19531953
// create a LibraryTreeNode for new loaded TLM file.
1954-
LibraryTreeNode *pLibraryTreeNode = addLibraryTreeNode(LibraryTreeNode::TLM, fileInfo.completeBaseName(), false);
1954+
LibraryTreeNode *pLibraryTreeNode = addLibraryTreeNode(LibraryTreeNode::TLM, fileInfo.completeBaseName(), true);
19551955
if (pLibraryTreeNode) {
19561956
pLibraryTreeNode->setSaveContentsType(LibraryTreeNode::SaveInOneFile);
19571957
pLibraryTreeNode->setIsSaved(true);

OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,15 +2237,17 @@ ModelWidget::ModelWidget(LibraryTreeNode* pLibraryTreeNode, ModelWidgetContainer
22372237
" <!-- Parameters for the simulation -->\n"
22382238
" <SimulationParams StartTime=\"0\" StopTime=\"1\" />\n"
22392239
"</Model>").arg(mpLibraryTreeNode->getName());
2240-
mpEditor->getPlainTextEdit()->setPlainText(defaultMetaModelText);
2240+
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpEditor);
2241+
pTLMEditor->setPlainText(defaultMetaModelText);
22412242
} else {
22422243
QFile file(mpLibraryTreeNode->getFileName());
22432244
if (!file.open(QIODevice::ReadOnly)) {
22442245
QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error),
22452246
GUIMessages::getMessage(GUIMessages::ERROR_OPENING_FILE).arg(mpLibraryTreeNode->getFileName())
22462247
.arg(file.errorString()), Helper::ok);
22472248
} else {
2248-
mpEditor->getPlainTextEdit()->setPlainText(QString(file.readAll()));
2249+
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpEditor);
2250+
pTLMEditor->setPlainText(QString(file.readAll()));
22492251
file.close();
22502252
}
22512253
}
@@ -2846,7 +2848,7 @@ void ModelWidget::showDiagramView(bool checked)
28462848
return;
28472849
}
28482850
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpEditor);
2849-
if (pTLMEditor && !pTLMEditor->TLMEditorFocusChanged()) {
2851+
if (pTLMEditor && !pTLMEditor->validateMetaModelText()) {
28502852
mpTextViewToolButton->setChecked(true);
28512853
return;
28522854
}

0 commit comments

Comments
 (0)