Skip to content

Commit

Permalink
- Create only one editor object. Use the BaseEditor class.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25246 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Mar 25, 2015
1 parent 4c0cb13 commit c9556dc
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 158 deletions.
15 changes: 6 additions & 9 deletions OMEdit/OMEditGUI/Editors/ModelicaTextEditor.cpp
Expand Up @@ -549,11 +549,10 @@ void ModelicaTextEditor::setLineWrapping()
//! @brief A syntax highlighter for ModelicaEditor.

//! Constructor
ModelicaTextHighlighter::ModelicaTextHighlighter(ModelicaTextSettings *pSettings, MainWindow *pMainWindow, QTextDocument *pParent)
ModelicaTextHighlighter::ModelicaTextHighlighter(ModelicaTextSettings *pSettings, QTextDocument *pParent)
: QSyntaxHighlighter(pParent)
{
mpModelicaTextSettings = pSettings;
mpMainWindow = pMainWindow;
initializeSettings();
}

Expand Down Expand Up @@ -737,17 +736,15 @@ void ModelicaTextHighlighter::highlightMultiLine(const QString &text)
void ModelicaTextHighlighter::highlightBlock(const QString &text)
{
/* Only highlight the text if user has enabled the syntax highlighting */
if (mpMainWindow) /* mpMainWindow is 0 for the ModelicaTextHighlighter used by ModelicaTextEditorPage in OptionsDialog */
if (!mpMainWindow->getOptionsDialog()->getModelicaTextEditorPage()->getSyntaxHighlightingCheckbox()->isChecked())
return;
if (!mpModelicaTextSettings->getOptionsDialog()->getModelicaTextEditorPage()->getSyntaxHighlightingCheckbox()->isChecked()) {
return;
}
setCurrentBlockState(0);
setFormat(0, text.length(), mpModelicaTextSettings->getTextRuleColor());
foreach (const HighlightingRule &rule, mHighlightingRules)
{
foreach (const HighlightingRule &rule, mHighlightingRules) {
QRegExp expression(rule.mPattern);
int index = expression.indexIn(text);
while (index >= 0)
{
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, rule.mFormat);
index = expression.indexIn(text, index + length);
Expand Down
3 changes: 1 addition & 2 deletions OMEdit/OMEditGUI/Editors/ModelicaTextEditor.h
Expand Up @@ -106,14 +106,13 @@ class ModelicaTextHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
ModelicaTextHighlighter(ModelicaTextSettings *pSettings, MainWindow *pMainWindow, QTextDocument *pParent = 0);
ModelicaTextHighlighter(ModelicaTextSettings *pSettings, QTextDocument *pParent = 0);
void initializeSettings();
void highlightMultiLine(const QString &text);
protected:
virtual void highlightBlock(const QString &text);
private:
ModelicaTextSettings *mpModelicaTextSettings;
MainWindow *mpMainWindow;
struct HighlightingRule
{
QRegExp mPattern;
Expand Down
3 changes: 1 addition & 2 deletions OMEdit/OMEditGUI/Editors/TLMEditor.cpp
Expand Up @@ -54,11 +54,10 @@ void TLMEditor::setLineWrapping()
//! @brief A syntax highlighter for TLMEditor.

//! Constructor
TLMHighlighter::TLMHighlighter(ModelicaTextSettings *pSettings, MainWindow *pMainWindow, QTextDocument *pParent)
TLMHighlighter::TLMHighlighter(ModelicaTextSettings *pSettings, QTextDocument *pParent)
: QSyntaxHighlighter(pParent)
{
mpModelicaTextSettings = pSettings;
mpMainWindow = pMainWindow;
initializeSettings();
}

Expand Down
3 changes: 1 addition & 2 deletions OMEdit/OMEditGUI/Editors/TLMEditor.h
Expand Up @@ -56,14 +56,13 @@ class TLMHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
TLMHighlighter(ModelicaTextSettings *pSettings, MainWindow *pMainWindow, QTextDocument *pParent = 0);
TLMHighlighter(ModelicaTextSettings *pSettings, QTextDocument *pParent = 0);
void initializeSettings();
void highlightMultiLine(const QString &text);
protected:
virtual void highlightBlock(const QString &text);
private:
ModelicaTextSettings *mpModelicaTextSettings;
MainWindow *mpMainWindow;
struct HighlightingRule
{
QRegExp mPattern;
Expand Down
99 changes: 52 additions & 47 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -710,54 +710,59 @@ void MainWindow::openResultFiles(QStringList fileNames)
void MainWindow::simulate(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget())
{
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
if (pLibraryTreeNode->getModelWidget()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pModelicaTextEditor && !pModelicaTextEditor->validateModelicaText()) {
return;
}
}
mpSimulationDialog->directSimulate(pLibraryTreeNode, false, false);
}

void MainWindow::simulateWithTransformationalDebugger(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget())
{
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
if (pLibraryTreeNode->getModelWidget()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pModelicaTextEditor && !pModelicaTextEditor->validateModelicaText()) {
return;
}
}
mpSimulationDialog->directSimulate(pLibraryTreeNode, true, false);
}

void MainWindow::simulateWithAlgorithmicDebugger(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget())
{
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
if (pLibraryTreeNode->getModelWidget()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pModelicaTextEditor && !pModelicaTextEditor->validateModelicaText()) {
return;
}
}
mpSimulationDialog->directSimulate(pLibraryTreeNode, false, true);
}

void MainWindow::simulationSetup(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget())
{
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
if (pLibraryTreeNode->getModelWidget()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pModelicaTextEditor && !pModelicaTextEditor->validateModelicaText()) {
return;
}
}
mpSimulationDialog->show(pLibraryTreeNode, false, SimulationOptions());
}

void MainWindow::instantiatesModel(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget())
{
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
if (pLibraryTreeNode->getModelWidget()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pModelicaTextEditor && !pModelicaTextEditor->validateModelicaText()) {
return;
}
}
// set the status message.
mpStatusBar->showMessage(QString(Helper::instantiateModel).append(" ").append(pLibraryTreeNode->getNameStructure()));
Expand All @@ -778,10 +783,11 @@ void MainWindow::instantiatesModel(LibraryTreeNode *pLibraryTreeNode)
void MainWindow::checkModel(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget())
{
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
if (pLibraryTreeNode->getModelWidget()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pModelicaTextEditor && !pModelicaTextEditor->validateModelicaText()) {
return;
}
}
// set the status message.
mpStatusBar->showMessage(QString(Helper::checkModel).append(" ").append(pLibraryTreeNode->getNameStructure()));
Expand All @@ -801,25 +807,23 @@ void MainWindow::checkModel(LibraryTreeNode *pLibraryTreeNode)
void MainWindow::checkAllModels(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget())
{
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
if (pLibraryTreeNode->getModelWidget()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pModelicaTextEditor && !pModelicaTextEditor->validateModelicaText()) {
return;
}
}
// set the status message.
mpStatusBar->showMessage(QString(Helper::checkModel).append(" ").append(pLibraryTreeNode->getNameStructure()));
// show the progress bar
mpProgressBar->setRange(0, 0);
showProgressBar();
QString checkModelResult = mpOMCProxy->checkAllModelsRecursive(pLibraryTreeNode->getNameStructure());
if (checkModelResult.length())
{
if (checkModelResult.length()) {
QString windowTitle = QString(Helper::checkModel).append(" - ").append(pLibraryTreeNode->getName());
InformationDialog *pInformationDialog = new InformationDialog(windowTitle, checkModelResult, false, this);
pInformationDialog->show();
}
else
{
} else {
mpMessagesWidget->addGUIMessage(MessageItem("", false, 0, 0, 0, 0, "Check of " + pLibraryTreeNode->getName() + " failed.",
Helper::scriptingKind, Helper::notificationLevel));
}
Expand All @@ -832,10 +836,11 @@ void MainWindow::checkAllModels(LibraryTreeNode *pLibraryTreeNode)
void MainWindow::exportModelFMU(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget())
{
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
if (pLibraryTreeNode->getModelWidget()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pModelicaTextEditor && !pModelicaTextEditor->validateModelicaText()) {
return;
}
}
// set the status message.
mpStatusBar->showMessage(tr("Exporting model as FMU"));
Expand All @@ -859,18 +864,18 @@ void MainWindow::exportModelFMU(LibraryTreeNode *pLibraryTreeNode)
void MainWindow::exportModelXML(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget())
{
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
if (pLibraryTreeNode->getModelWidget()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pModelicaTextEditor && !pModelicaTextEditor->validateModelicaText()) {
return;
}
}
// set the status message.
mpStatusBar->showMessage(tr("Exporting model as XML"));
// show the progress bar
mpProgressBar->setRange(0, 0);
showProgressBar();
if (mpOMCProxy->translateModelXML(pLibraryTreeNode->getNameStructure()))
{
if (mpOMCProxy->translateModelXML(pLibraryTreeNode->getNameStructure())) {
mpMessagesWidget->addGUIMessage(MessageItem("", false, 0, 0, 0, 0, GUIMessages::getMessage(GUIMessages::XML_GENERATED)
.arg(mpOMCProxy->changeDirectory()).arg(pLibraryTreeNode->getNameStructure()),
Helper::scriptingKind, Helper::notificationLevel));
Expand All @@ -885,7 +890,8 @@ void MainWindow::exportModelFigaro(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget()) {
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pModelicaTextEditor && !pModelicaTextEditor->validateModelicaText()) {
return;
}
}
Expand All @@ -896,16 +902,18 @@ void MainWindow::exportModelFigaro(LibraryTreeNode *pLibraryTreeNode)
void MainWindow::exportModelToOMNotebook(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget())
{
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
if (pLibraryTreeNode->getModelWidget()) {
ModelicaTextEditor *pModelicaTextEditor = dynamic_cast<ModelicaTextEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pModelicaTextEditor && !pModelicaTextEditor->validateModelicaText()) {
return;
}
}
QString omnotebookFileName = StringHandler::getSaveFileName(this, QString(Helper::applicationName).append(" - ").append(Helper::exportToOMNotebook),
NULL, Helper::omnotebookFileTypes, NULL, "onb", &pLibraryTreeNode->getName());
// if user cancels the operation. or closes the export dialog box.
if (omnotebookFileName.isEmpty())
if (omnotebookFileName.isEmpty()) {
return;
}
// create a progress bar
int endtime = 6; // since in total we do six things while exporting to OMNotebook
int value = 1;
Expand Down Expand Up @@ -1153,9 +1161,8 @@ void MainWindow::focusSearchClassWidget(bool visible)
void MainWindow::showFindReplaceDialog()
{
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
if (pModelWidget)
{
mpFindReplaceDialog->setTextEdit(pModelWidget->getModelicaTextEditor());
if (pModelWidget) {
mpFindReplaceDialog->setTextEdit(pModelWidget->getEditor());
mpFindReplaceDialog->show();
mpFindReplaceDialog->raise();
mpFindReplaceDialog->activateWindow();
Expand All @@ -1165,9 +1172,8 @@ void MainWindow::showFindReplaceDialog()
void MainWindow::showGotoLineNumberDialog()
{
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
if (pModelWidget)
{
GotoLineDialog *pGotoLineWidget = new GotoLineDialog(pModelWidget->getModelicaTextEditor(), this);
if (pModelWidget) {
GotoLineDialog *pGotoLineWidget = new GotoLineDialog(pModelWidget->getEditor(), this);
pGotoLineWidget->show();
}
}
Expand All @@ -1176,8 +1182,7 @@ void MainWindow::showGotoLineNumberDialog()
void MainWindow::openRecentFile()
{
QAction *pAction = qobject_cast<QAction*>(sender());
if (pAction)
{
if (pAction) {
QStringList dataList = pAction->data().toStringList();
mpLibraryTreeWidget->openFile(dataList.at(0), dataList.at(1), true, true);
}
Expand Down

0 comments on commit c9556dc

Please sign in to comment.