Skip to content

Commit

Permalink
Use the colors from settings for simulation output (#9870)
Browse files Browse the repository at this point in the history
Fixes #9855
  • Loading branch information
adeas31 committed Dec 6, 2022
1 parent c55c8cc commit 7dc99cd
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/OMS/OMSSimulationOutputWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void OMSSimulationOutputWidget::simulationProcessError(QProcess::ProcessError er
void OMSSimulationOutputWidget::writeSimulationOutput(const QString &output, StringHandler::SimulationMessageType type)
{
QTextCharFormat textCharFormat;
textCharFormat.setForeground(StringHandler::getSimulationMessageTypeColor(type));
textCharFormat.setForeground(OptionsDialog::instance()->getMessagesPage()->getColor(type));
mpSimulationOutputPlainTextEdit->appendOutput(output, textCharFormat);
}

Expand Down
24 changes: 24 additions & 0 deletions OMEdit/OMEditLIB/Options/OptionsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5793,6 +5793,30 @@ void MessagesPage::setErrorPickColorButtonIcon()
mpErrorColorButton->setIcon(pixmap);
}

/*!
* \brief MessagesPage::getColor
* Returns the color based on the error type.
* \param type
* \return
*/
QColor MessagesPage::getColor(const StringHandler::SimulationMessageType type) const
{
switch (type) {
case StringHandler::OMEditInfo:
return Qt::blue;
case StringHandler::SMWarning:
return getWarningColor();
case StringHandler::Error:
case StringHandler::Assert:
return getErrorColor();
case StringHandler::Debug:
case StringHandler::Info:
case StringHandler::Unknown:
default:
return getNotificationColor();
}
}

void MessagesPage::pickNotificationColor()
{
QColor color = QColorDialog::getColor(getNotificationColor());
Expand Down
8 changes: 5 additions & 3 deletions OMEdit/OMEditLIB/Options/OptionsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "Util/Helper.h"
#include "Util/Utilities.h"
#include "Util/StringHandler.h"

#include <QFontComboBox>
#include <QStackedWidget>
Expand Down Expand Up @@ -721,14 +722,15 @@ class MessagesPage : public QWidget
QFontComboBox* getFontFamilyComboBox() {return mpFontFamilyComboBox;}
DoubleSpinBox* getFontSizeSpinBox() {return mpFontSizeSpinBox;}
void setNotificationColor(QColor color) {mNotificaitonColor = color;}
QColor getNotificationColor() {return mNotificaitonColor;}
QColor getNotificationColor() const {return mNotificaitonColor;}
void setNotificationPickColorButtonIcon();
void setWarningColor(QColor color) {mWarningColor = color;}
QColor getWarningColor() {return mWarningColor;}
QColor getWarningColor() const {return mWarningColor;}
void setWarningPickColorButtonIcon();
void setErrorColor(QColor color) {mErrorColor = color;}
QColor getErrorColor() {return mErrorColor;}
QColor getErrorColor() const {return mErrorColor;}
void setErrorPickColorButtonIcon();
QColor getColor(const StringHandler::SimulationMessageType type) const;
private:
OptionsDialog *mpOptionsDialog;
QGroupBox *mpGeneralGroupBox;
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Simulation/SimulationOutputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ QVariant SimulationMessageModel::data(const QModelIndex &index, int role) const
variant = toolTip;
break;
case Qt::ForegroundRole:
variant = StringHandler::getSimulationMessageTypeColor(pSimulationMessage->mType);
variant = OptionsDialog::instance()->getMessagesPage()->getColor(pSimulationMessage->mType);
break;
case Qt::TextAlignmentRole:
variant = QVariant(Qt::AlignLeft | Qt::AlignTop);
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Simulation/SimulationOutputWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ void SimulationOutputWidget::writeSimulationMessage(SimulationMessage *pSimulati
mpSimulationOutputTextBrowser->setTextCursor(textCursor);
/* set the text color */
QTextCharFormat charFormat = mpSimulationOutputTextBrowser->currentCharFormat();
charFormat.setForeground(StringHandler::getSimulationMessageTypeColor(pSimulationMessage->mType));
charFormat.setForeground(OptionsDialog::instance()->getMessagesPage()->getColor(pSimulationMessage->mType));
mpSimulationOutputTextBrowser->setCurrentCharFormat(charFormat);
/* append the output */
/* write the error message */
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditLIB/TLM/FetchInterfaceDataDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "FetchInterfaceDataDialog.h"
#include "Util/Helper.h"
#include "Options/OptionsDialog.h"
#include "Util/OutputPlainTextEdit.h"
#include "Modeling/LibraryTreeWidget.h"
#include "Modeling/ModelWidgetContainer.h"
Expand Down Expand Up @@ -148,7 +149,7 @@ void FetchInterfaceDataDialog::managerProcessStarted()
void FetchInterfaceDataDialog::writeManagerOutput(QString output, StringHandler::SimulationMessageType type)
{
QTextCharFormat format;
format.setForeground(StringHandler::getSimulationMessageTypeColor(type));
format.setForeground(OptionsDialog::instance()->getMessagesPage()->getColor(type));
mpOutputTextBox->appendOutput(output, format);
}

Expand Down
5 changes: 3 additions & 2 deletions OMEdit/OMEditLIB/TLM/TLMCoSimulationOutputWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "MainWindow.h"
#include "Util/Utilities.h"
#include "Util/Helper.h"
#include "Options/OptionsDialog.h"
#include "Util/OutputPlainTextEdit.h"
#include "TLMCoSimulationThread.h"
#include "TLMCoSimulationDialog.h"
Expand Down Expand Up @@ -242,7 +243,7 @@ void TLMCoSimulationOutputWidget::managerProcessStarted()
void TLMCoSimulationOutputWidget::writeManagerOutput(QString output, StringHandler::SimulationMessageType type)
{
QTextCharFormat format;
format.setForeground(StringHandler::getSimulationMessageTypeColor(type));
format.setForeground(OptionsDialog::instance()->getMessagesPage()->getColor(type));
mpManagerOutputTextBox->appendOutput(output, format);
}

Expand Down Expand Up @@ -282,7 +283,7 @@ void TLMCoSimulationOutputWidget::monitorProcessStarted()
void TLMCoSimulationOutputWidget::writeMonitorOutput(QString output, StringHandler::SimulationMessageType type)
{
QTextCharFormat format;
format.setForeground(StringHandler::getSimulationMessageTypeColor(type));
format.setForeground(OptionsDialog::instance()->getMessagesPage()->getColor(type));
mpMonitorOutputTextBox->appendOutput(output, format);
}

Expand Down
18 changes: 0 additions & 18 deletions OMEdit/OMEditLIB/Util/StringHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,24 +1723,6 @@ QString StringHandler::getSimulationMessageTypeString(StringHandler::SimulationM
}
}

QColor StringHandler::getSimulationMessageTypeColor(StringHandler::SimulationMessageType type)
{
switch (type) {
case StringHandler::OMEditInfo:
return Qt::blue;
case StringHandler::SMWarning:
case StringHandler::Error:
case StringHandler::Assert:
return Qt::red;
case StringHandler::Debug:
case StringHandler::Info:
case StringHandler::Unknown:
default:
return Qt::black;
break;
}
}

/*!
* \brief StringHandler::makeClassNameRelative
* Removes the first characters matching with droppedClassName from draggedClassName.
Expand Down
1 change: 0 additions & 1 deletion OMEdit/OMEditLIB/Util/StringHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class StringHandler : public QObject
#endif
static StringHandler::SimulationMessageType getSimulationMessageType(QString type);
static QString getSimulationMessageTypeString(StringHandler::SimulationMessageType type);
static QColor getSimulationMessageTypeColor(StringHandler::SimulationMessageType type);
static QString makeClassNameRelative(QString draggedClassName, QString droppedClassName);
static QString toCamelCase(QString str);
static QMap<int, int> getLeadingSpaces(QString contents);
Expand Down

0 comments on commit 7dc99cd

Please sign in to comment.