Skip to content

Commit

Permalink
Fixes for bugs #1376 #1377 #1378
Browse files Browse the repository at this point in the history
- Added the timestamp and sequence numbers to messages shown in messages window.
- Changed the simulation code so that if there is a message from simulation result it will always be displayed.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7392 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Dec 14, 2010
1 parent 13ce359 commit 446bde0
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 96 deletions.
17 changes: 12 additions & 5 deletions OMEdit/OMEditGUI/LibraryWidget.cpp
Expand Up @@ -157,8 +157,6 @@ void ModelicaTree::deleteNode(ModelicaTreeNode *item)
pMainWindow->mpProjectTabs->mRemovedTabsList.removeOne(pCurrentTab);
}
}
// Delete the complete tree node now
//delete item;
}

void ModelicaTree::removeChildNodes(ModelicaTreeNode *item)
Expand All @@ -170,8 +168,9 @@ void ModelicaTree::removeChildNodes(ModelicaTreeNode *item)
ModelicaTreeNode *treeNode = dynamic_cast<ModelicaTreeNode*>(item->child(i));
deleteNode(treeNode);
}
// Delete the node from list as well
mModelicaTreeNodesList.removeOne(item);
// remove the items from the tree as well
if (item->childCount())
qDeleteAll(item->takeChildren());
}

void ModelicaTree::addNode(QString name, int type, QString parentName, QString parentStructure)
Expand Down Expand Up @@ -271,6 +270,14 @@ void ModelicaTree::renameClass()

void ModelicaTree::checkModelicaModel()
{
// validate the modelica text before checking the model
ProjectTab *pCurrentTab = mpParentLibraryWidget->mpParentMainWindow->mpProjectTabs->getCurrentTab();
if (pCurrentTab)
{
if (!pCurrentTab->mpModelicaEditor->validateText())
return;
}

CheckModelWidget *widget = new CheckModelWidget(mpParentLibraryWidget->mSelectedModelicaNode->mName,
mpParentLibraryWidget->mSelectedModelicaNode->mNameStructure,
mpParentLibraryWidget->mpParentMainWindow);
Expand Down Expand Up @@ -332,7 +339,7 @@ bool ModelicaTree::deleteNodeTriggered(ModelicaTreeNode *node)
}
else
{
pMainWindow->mpMessageWidget->printGUIInfoMessage(GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED)
pMainWindow->mpMessageWidget->printGUIErrorMessage(GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED)
.arg(pMainWindow->mpOMCProxy->getResult())
.append("while deleting " + treeNode->mName));
return false;
Expand Down
82 changes: 80 additions & 2 deletions OMEdit/OMEditGUI/MessageWidget.cpp
Expand Up @@ -41,6 +41,12 @@
#include "MessageWidget.h"
#include "mainwindow.h"

//! @class MessageWidget
//! @brief It creates a tab based messages window.
//! It contains three tabs four tabs General, Info, Warning and Error.

//! Constructor
//! @param pParent defines a parent to the new instanced object. pParent is the MainWindow object.
MessageWidget::MessageWidget(MainWindow *pParent)
: QTabWidget(pParent)
{
Expand All @@ -61,35 +67,49 @@ MessageWidget::MessageWidget(MainWindow *pParent)
setObjectName(tr("MessagesTab"));
}

//! Calls the GeneralMessage::printGUIMessage
//! @param message is the string that is passed.
void MessageWidget::printGUIMessage(QString message)
{
mpGeneralMessages->printGUIMessage(message);
}

//! Calls the InfoMessage::printGUIMessage
//! @param message is the string that is passed.
void MessageWidget::printGUIInfoMessage(QString message)
{
mpInfoMessages->printGUIMessage(message);
}

//! Calls the WarningMessage::printGUIMessage
//! @param message is the string that is passed.
void MessageWidget::printGUIWarningMessage(QString message)
{
mpWarningMessages->printGUIMessage(message);
}

//! Calls the ErrorMessage::printGUIMessage
//! @param message is the string that is passed.
void MessageWidget::printGUIErrorMessage(QString message)
{
mpErrorMessages->printGUIMessage(message);
}

//! @class Messages
//! @brief It is the base class for all types of messages.

//! Constructor
//! @param pParent defines a parent to the new instanced object. pParent is the MessageWidget object.
Messages::Messages(MessageWidget *pParent)
: QTextEdit(pParent)
: QTextEdit(pParent), mMessageCounter(0)
{
setReadOnly(true);
setObjectName(tr("MessagesTextBox"));

mpMessageWidget = pParent;
}

//! Reimplementation of sizeHint function. Defines the minimum height for QTextEdit.
QSize Messages::sizeHint() const
{
QSize size = QTextEdit::sizeHint();
Expand All @@ -98,32 +118,90 @@ QSize Messages::sizeHint() const
return size;
}

//! Displays the message.
//! @param message is the string that is displayed.
void Messages::printGUIMessage(QString message)
{
append(message);
append(message + tr("\n"));
mpMessageWidget->setCurrentWidget(this);
}

//! @class GeneralMessages
//! @brief This class is inherited from Messages. It is used to display general messages.

//! Constructor
//! @param pParent defines a parent to the new instanced object. pParent is the MessageWidget object.
GeneralMessages::GeneralMessages(MessageWidget *pParent)
: Messages(pParent)
{
setTextColor("BLACK");
}

//! Reimplementation of Messages::printGUIMessage function.
void GeneralMessages::printGUIMessage(QString message)
{
append(message);
}

//! @class InfoMessages
//! @brief This class is inherited from Messages. It is used to display info messages.

//! Constructor
//! @param pParent defines a parent to the new instanced object. pParent is the MessageWidget object.
InfoMessages::InfoMessages(MessageWidget *pParent)
: Messages(pParent)
{
setTextColor("GREEN");
}

//! Reimplementation of Messages::printGUIMessage function.
void InfoMessages::printGUIMessage(QString message)
{
mMessageCounter++;
append(QString("---- Info ").append(QString::number(mMessageCounter)).append(" : ")
.append(QTime::currentTime().toString()).append(" ----"));

Messages::printGUIMessage(message);
}

//! @class WarningMessages
//! @brief This class is inherited from Messages. It is used to display warning messages.

//! Constructor
//! @param pParent defines a parent to the new instanced object. pParent is the MessageWidget object.
WarningMessages::WarningMessages(MessageWidget *pParent)
: Messages(pParent)
{
setTextColor("ORANGE");
}

//! Reimplementation of Messages::printGUIMessage function.
void WarningMessages::printGUIMessage(QString message)
{
mMessageCounter++;
append(QString("---- Warning ").append(QString::number(mMessageCounter)).append(" : ")
.append(QTime::currentTime().toString()).append(" ----"));

Messages::printGUIMessage(message);
}

//! @class ErrorMessages
//! @brief This class is inherited from Messages. It is used to display error messages.

//! Constructor
//! @param pParent defines a parent to the new instanced object. pParent is the MessageWidget object.
ErrorMessages::ErrorMessages(MessageWidget *pParent)
: Messages(pParent)
{
setTextColor("RED");
}

//! Reimplementation of Messages::printGUIMessage function.
void ErrorMessages::printGUIMessage(QString message)
{
mMessageCounter++;
append(QString("---- Error ").append(QString::number(mMessageCounter)).append(" : ")
.append(QTime::currentTime().toString()).append(" ----"));

Messages::printGUIMessage(message);
}
6 changes: 6 additions & 0 deletions OMEdit/OMEditGUI/MessageWidget.h
Expand Up @@ -77,34 +77,40 @@ class Messages : public QTextEdit
void printGUIMessage(QString message);

MessageWidget *mpMessageWidget;
protected:
int mMessageCounter;
};

class GeneralMessages : public Messages
{
Q_OBJECT
public:
GeneralMessages(MessageWidget *pParent=0);
void printGUIMessage(QString message);
};

class InfoMessages : public Messages
{
Q_OBJECT
public:
InfoMessages(MessageWidget *pParent=0);
void printGUIMessage(QString message);
};

class WarningMessages : public Messages
{
Q_OBJECT
public:
WarningMessages(MessageWidget *pParent=0);
void printGUIMessage(QString message);
};

class ErrorMessages : public Messages
{
Q_OBJECT
public:
ErrorMessages(MessageWidget *pParent=0);
void printGUIMessage(QString message);
};

#endif // MESSAGEWIDGET_H
82 changes: 43 additions & 39 deletions OMEdit/OMEditGUI/ModelicaEditor.cpp
Expand Up @@ -95,45 +95,6 @@ QString ModelicaEditor::getModelName()
return modelName;
}

bool ModelicaEditor::validateModelicaText()
{
if (document()->isModified())
{
// if the user makes few mistakes in the text then dont let him change the perspective
if (!emit focusOut())
{
MainWindow *pMainWindow = mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow;
QMessageBox *msgBox = new QMessageBox(pMainWindow);
msgBox->setWindowTitle(QString(Helper::applicationName).append(" - Error"));
msgBox->setIcon(QMessageBox::Critical);
msgBox->setText(GUIMessages::getMessage(GUIMessages::ERROR_IN_MODELICA_TEXT)
.arg(pMainWindow->mpOMCProxy->getResult()));
msgBox->setText(msgBox->text().append(GUIMessages::getMessage(GUIMessages::UNDO_OR_FIX_ERRORS)));
msgBox->addButton(tr("Undo changes"), QMessageBox::AcceptRole);
msgBox->addButton(tr("Let me fix errors"), QMessageBox::RejectRole);

int answer = msgBox->exec();

switch (answer)
{
case QMessageBox::AcceptRole:
document()->setModified(false);
// revert back to last valid block
setText(mLastValidText);
return true;
case QMessageBox::RejectRole:
document()->setModified(true);
return false;
default:
// should never be reached
document()->setModified(true);
return false;
}
}
}
return true;
}

void ModelicaEditor::findText(const QString &text, bool forward)
{
QTextCursor currentTextCursor = textCursor();
Expand Down Expand Up @@ -180,6 +141,49 @@ void ModelicaEditor::findText(const QString &text, bool forward)
}
}

bool ModelicaEditor::validateText()
{
if (document()->isModified())
{
// if the user makes few mistakes in the text then dont let him change the perspective
if (!emit focusOut())
{
MainWindow *pMainWindow = mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow;
QMessageBox *msgBox = new QMessageBox(pMainWindow);
msgBox->setWindowTitle(QString(Helper::applicationName).append(" - Error"));
msgBox->setIcon(QMessageBox::Critical);
msgBox->setText(GUIMessages::getMessage(GUIMessages::ERROR_IN_MODELICA_TEXT)
.arg(pMainWindow->mpOMCProxy->getResult()));
msgBox->setText(msgBox->text().append(GUIMessages::getMessage(GUIMessages::UNDO_OR_FIX_ERRORS)));
msgBox->addButton(tr("Undo changes"), QMessageBox::AcceptRole);
msgBox->addButton(tr("Let me fix errors"), QMessageBox::RejectRole);

int answer = msgBox->exec();

switch (answer)
{
case QMessageBox::AcceptRole:
document()->setModified(false);
// revert back to last valid block
setText(mLastValidText);
return true;
case QMessageBox::RejectRole:
document()->setModified(true);
return false;
default:
// should never be reached
document()->setModified(true);
return false;
}
}
else
{
document()->setModified(false);
}
}
return true;
}

void ModelicaEditor::hideFindWidget()
{
mpFindWidget->hide();
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/ModelicaEditor.h
Expand Up @@ -44,8 +44,8 @@ class ModelicaEditor : public QTextEdit
public:
ModelicaEditor(ProjectTab *pParent = 0);
QString getModelName();
bool validateModelicaText();
void findText(const QString &text, bool forward);
bool validateText();

ProjectTab *mpParentProjectTab;
QString mLastValidText;
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/OMCProxy.cpp
Expand Up @@ -47,7 +47,7 @@
#include <omniORB4/CORBA.h>

//! @class OMCProxy
//! @brief The OMCProxy is a singleton class. It contains the reference of the CORBA object used to communicate with the OpenModelica Compiler.
//! @brief It contains the reference of the CORBA object used to communicate with the OpenModelica Compiler.

//! Constructor
//! @param mOMC is the CORBA object.
Expand Down

0 comments on commit 446bde0

Please sign in to comment.