Skip to content

Commit

Permalink
Added the component attributes widget.
Browse files Browse the repository at this point in the history
Updated the Modelica Documentation view.
Added the status bar to project tab.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7096 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Nov 18, 2010
1 parent af2a3cd commit ad219ab
Show file tree
Hide file tree
Showing 31 changed files with 783 additions and 325 deletions.
13 changes: 11 additions & 2 deletions OMEdit/OMEditGUI/Component.cpp
Expand Up @@ -60,7 +60,6 @@ Component::Component(QString value, QString name, QString className, QPointF pos
getClassComponents(mClassName, mType);
createSelectionBox();
createActions();
connect(mpIconPropertiesAction, SIGNAL(triggered()), SLOT(openIconProperties()));
}
// if component is a diagram
else if (mType == StringHandler::DIAGRAM)
Expand Down Expand Up @@ -190,7 +189,6 @@ Component::Component(Component *pComponent, QString name, QPointF position, int
copyClassComponents(pComponent);
createSelectionBox();
createActions();
connect(mpIconPropertiesAction, SIGNAL(triggered()), SLOT(openIconProperties()));
}
// if component is a diagram
else if (mType == StringHandler::DIAGRAM)
Expand Down Expand Up @@ -350,8 +348,12 @@ void Component::createSelectionBox()

void Component::createActions()
{
// Icon Attributes Action
mpIconAttributesAction = new QAction(tr("Attributes"), this);
connect(mpIconAttributesAction, SIGNAL(triggered()), SLOT(openIconAttributes()));
// Icon Properties Action
mpIconPropertiesAction = new QAction(QIcon(":/Resources/icons/tool.png"), tr("Properties"), this);
connect(mpIconPropertiesAction, SIGNAL(triggered()), SLOT(openIconProperties()));
}

void Component::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Expand Down Expand Up @@ -406,6 +408,7 @@ void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
if (pComponent->mType == StringHandler::ICON)
{
menu.addSeparator();
menu.addAction(pComponent->mpIconAttributesAction);
menu.addAction(pComponent->mpIconPropertiesAction);
}
menu.exec(event->screenPos());
Expand Down Expand Up @@ -694,6 +697,12 @@ void Component::openIconProperties()
iconProperties->show();
}

void Component::openIconAttributes()
{
IconAttributes *iconAttributes = new IconAttributes(this, mpGraphicsView->mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow);
iconAttributes->show();
}

QString Component::getName()
{
return mName;
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Component.h
Expand Up @@ -78,6 +78,7 @@ class Component : public ShapeAnnotation
CornerItem *mpBottomLeftCornerItem;
CornerItem *mpBottomRightCornerItem;
QAction *mpIconPropertiesAction;
QAction *mpIconAttributesAction;

void createActions();
public:
Expand Down Expand Up @@ -156,6 +157,7 @@ public slots:
void rotateAntiClockwise();
void resetRotation();
void openIconProperties();
void openIconAttributes();
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
Expand Down
60 changes: 51 additions & 9 deletions OMEdit/OMEditGUI/ComponentsProperties.cpp
Expand Up @@ -45,17 +45,19 @@ ComponentsProperties::ComponentsProperties(QString value)
this->mIsStream = false;
this->mIsReplaceable = false;

this->mVariabilityMap.insert("constant", "Constant");
this->mVariabilityMap.insert("constant", "constant");
this->mVariabilityMap.insert("discrete", "discrete");
this->mVariabilityMap.insert("parameter", "parameter");
this->mVariabilityMap.insert("unspecified", "Default");
this->mVariabilityMap.insert("unspecified", "default");
this->mVariability.clear();

this->mIsInner = false;
this->mIsOuter = false;

this->mCasualityMap.insert("input", "Input");
this->mCasualityMap.insert("output", "Output");
this->mCasualityMap.insert("unspecified", "None");
this->mCasualityMap.insert("input", "input");
this->mCasualityMap.insert("output", "output");
this->mCasualityMap.insert("unspecified", "none");
this->mCasuality.clear();

parseString(value);
}
Expand Down Expand Up @@ -84,7 +86,7 @@ void ComponentsProperties::parseString(QString value)
return;

if (list.size() > 3)
this->mIsProtected = StringHandler::removeFirstLastQuotes(list.at(3)).compare("protected");
this->mIsProtected = StringHandler::removeFirstLastQuotes(list.at(3)).contains("protected");
else
return;

Expand Down Expand Up @@ -114,7 +116,7 @@ void ComponentsProperties::parseString(QString value)
QMap<QString, QString>::iterator variability_it;
for (variability_it = this->mVariabilityMap.begin(); variability_it != this->mVariabilityMap.end(); ++variability_it)
{
if (variability_it.key() == StringHandler::removeFirstLastQuotes(list.at(7 + index)));
if (variability_it.key().compare(StringHandler::removeFirstLastQuotes(list.at(7 + index))) == 0)
{
this->mVariability = variability_it.value();
break;
Expand All @@ -137,7 +139,7 @@ void ComponentsProperties::parseString(QString value)
QMap<QString, QString>::iterator casuality_it;
for (casuality_it = this->mCasualityMap.begin(); casuality_it != this->mCasualityMap.end(); ++casuality_it)
{
if (casuality_it.key() == StringHandler::removeFirstLastQuotes(list.at(9 + index)));
if (casuality_it.key().compare(StringHandler::removeFirstLastQuotes(list.at(9 + index))) == 0)
{
this->mCasuality = casuality_it.value();
break;
Expand All @@ -158,5 +160,45 @@ QString ComponentsProperties::getName()

QString ComponentsProperties::getComment()
{
return mComment;
return StringHandler::removeFirstLastQuotes(mComment);
}

QString ComponentsProperties::getVariablity()
{
return mVariability;
}

bool ComponentsProperties::getProtected()
{
return mIsProtected;
}

bool ComponentsProperties::getFlow()
{
return mIsFlow;
}

bool ComponentsProperties::getFinal()
{
return mIsFinal;
}

bool ComponentsProperties::getReplaceable()
{
return mIsReplaceable;
}

QString ComponentsProperties::getCasuality()
{
return mCasuality;
}

bool ComponentsProperties::getInner()
{
return mIsInner;
}

bool ComponentsProperties::getOuter()
{
return mIsOuter;
}
8 changes: 8 additions & 0 deletions OMEdit/OMEditGUI/ComponentsProperties.h
Expand Up @@ -45,6 +45,14 @@ class ComponentsProperties
QString getClassName();
QString getName();
QString getComment();
QString getVariablity();
bool getProtected();
bool getFlow();
bool getFinal();
bool getReplaceable();
QString getCasuality();
bool getInner();
bool getOuter();
private:
QString mClassName;
QString mName;
Expand Down
62 changes: 57 additions & 5 deletions OMEdit/OMEditGUI/DocumentationWidget.cpp
Expand Up @@ -59,6 +59,11 @@ DocumentationWidget::DocumentationWidget(MainWindow *pParent)
setLayout(verticalLayout);
}

DocumentationWidget::~DocumentationWidget()
{
delete mpDocumentationViewer;
}

void DocumentationWidget::show(QString className)
{
mpHeadingLabel->setText(className);
Expand All @@ -78,34 +83,57 @@ void DocumentationWidget::show(QString className)
documentation = StringHandler::removeFirstLastCurlBrackets(documentation);
documentation = StringHandler::removeFirstLastQuotes(documentation);
documentation = documentation.replace("\\\"", "\"");
mpDocumentationViewer->setHtml(documentation);
documentation = documentation.replace("Modelica://", "Modelica:/");
mpDocumentationViewer->setHtml(documentation, mpDocumentationViewer->getBaseUrl());
setVisible(true);
}

DocumentationViewer::DocumentationViewer(DocumentationWidget *pParent)
: QWebView(pParent)
{
mpParent = pParent;
mpParentDocumentationWidget = pParent;
// set the base url for documentation.
setBaseUrl(Helper::documentationBaseUrl);
// set page font settings
settings()->setFontFamily(QWebSettings::StandardFont, "Verdana");
settings()->setFontSize(QWebSettings::DefaultFontSize, 10);
// set page links settings
page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);

connect(this, SIGNAL(linkClicked(QUrl)), SLOT(ProcessRequest(QUrl)));
connect(this, SIGNAL(linkClicked(QUrl)), SLOT(processLinkClick(QUrl)));
connect(this->page(), SIGNAL(linkHovered(QString,QString,QString)), SLOT(processLinkHover(QString,QString,QString)));
}

void DocumentationViewer::setBaseUrl(QString url)
{
mBaseUrl.setUrl(url);
}

QUrl DocumentationViewer::getBaseUrl()
{
return mBaseUrl;
}

void DocumentationViewer::ProcessRequest(QUrl url)
void DocumentationViewer::processLinkClick(QUrl url)
{
//! @todo
/* Send all http requests to desktop services for now. If we need to display web pages then we will change it,
but for now else portion is never reached. */

// if url contains http or mailto: send it to desktop services
if ((url.toString().toLower().contains("http")) or (url.toString().toLower().contains("mailto:")))
if ((url.toString().startsWith("http")) or (url.toString().startsWith("mailto:")))
{
QDesktopServices::openUrl(url);
}
// if the user has clicked on some Modelica Links like Modelica://
else if (url.toString().startsWith("Modelica"))
{
// remove Modelica:// from link
QString className;
className = url.toString().mid(10, url.toString().length() - 1);
// send the new className to DocumentationWidget
mpParentDocumentationWidget->show(className);
}
// if it is normal http request then check if its not redirected to https
else
{
Expand All @@ -129,3 +157,27 @@ void DocumentationViewer::requestFinished()

reply->deleteLater();
}

void DocumentationViewer::processLinkHover(QString link, QString title, QString textContent)
{
Q_UNUSED(title);
Q_UNUSED(textContent);

if (link.isEmpty())
mpParentDocumentationWidget->mpParentMainWindow->statusBar->clearMessage();
else
mpParentDocumentationWidget->mpParentMainWindow->statusBar->showMessage(link);
}

void DocumentationViewer::mousePressEvent(QMouseEvent *event)
{
// dont allow right click on Documentation Viewer
if (event->button() == Qt::LeftButton)
{
QWebView::mousePressEvent(event);
}
else if (event->button() == Qt::RightButton)
{
event->ignore();
}
}
12 changes: 10 additions & 2 deletions OMEdit/OMEditGUI/DocumentationWidget.h
Expand Up @@ -47,6 +47,7 @@ class DocumentationWidget : public QWidget

public:
DocumentationWidget(MainWindow *pParent = 0);
~DocumentationWidget();
void show(QString className);

MainWindow *mpParentMainWindow;
Expand All @@ -58,13 +59,20 @@ class DocumentationWidget : public QWidget
class DocumentationViewer : public QWebView
{
Q_OBJECT
private:
QUrl mBaseUrl;
public:
DocumentationViewer(DocumentationWidget *pParent);
void setBaseUrl(QString url);
QUrl getBaseUrl();

DocumentationWidget *mpParent;
DocumentationWidget *mpParentDocumentationWidget;
public slots:
void ProcessRequest(QUrl url);
void processLinkClick(QUrl url);
void requestFinished();
void processLinkHover(QString link, QString title, QString textContent);
protected:
virtual void mousePressEvent(QMouseEvent *event);
};

#endif // DOCUMENTATIONWIDGET_H
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/EllipseAnnotation.cpp
Expand Up @@ -108,7 +108,7 @@ EllipseAnnotation::EllipseAnnotation(QString shape, Component *pParent)
QMap<QString, Qt::PenStyle>::iterator it;
for (it = this->mLinePatternsMap.begin(); it != this->mLinePatternsMap.end(); ++it)
{
if (it.key() == linePattern)
if (it.key().compare(linePattern) == 0)
{
this->mLinePattern = it.value();
break;
Expand All @@ -121,7 +121,7 @@ EllipseAnnotation::EllipseAnnotation(QString shape, Component *pParent)
QMap<QString, Qt::BrushStyle>::iterator fill_it;
for (fill_it = this->mFillPatternsMap.begin(); fill_it != this->mFillPatternsMap.end(); ++fill_it)
{
if (fill_it.key() == fillPattern)
if (fill_it.key().compare(fillPattern) == 0)
{
this->mFillPattern = fill_it.value();
break;
Expand Down
14 changes: 13 additions & 1 deletion OMEdit/OMEditGUI/Helper.cpp
Expand Up @@ -34,7 +34,7 @@
#include "Helper.h"

QString Helper::applicationName = "OMEdit";
QString Helper::applicationVersion = "0.0.2";
QString Helper::applicationVersion = "1.0";
QString Helper::applicationIntroText = "Open Modelica Connection Editor";
QString Helper::OpenModelicaHome = getenv("OPENMODELICAHOME");
QString Helper::omcServerName = "OMEdit";
Expand All @@ -47,6 +47,13 @@ QString Helper::tmpPath = QString(getenv("OPENMODELICAHOME")).append(QString("/t
// Don't randomize the path as then it becomes annoying to remove all dirs
QString Helper::tmpPath = QString("/tmp/OMEdit");
#endif
// We need to replace the back slashes(\) with forward slash(/), since QWebView baseurl doesn't handle it.
QString Helper::documentationBaseUrl = QString(getenv("OPENMODELICALIBRARY")).replace("\\", "/").append(QString("/Modelica/Images/"));
QString Helper::readOnly = QString("Read-Only");
QString Helper::writeAble = QString("Writeable");
QString Helper::iconView = QString("Icon View");
QString Helper::diagramView = QString("Diagram View");
QString Helper::modelicaTextView = QString("Modelica Text View");
int Helper::viewWidth = 2000;
int Helper::viewHeight = 2000;
qreal Helper::globalIconXScale = 0.15;
Expand All @@ -55,6 +62,7 @@ qreal Helper::globalDiagramXScale = 1.0;
qreal Helper::globalDiagramYScale = 1.0;
int Helper::treeIndentation = 13;
QSize Helper::iconSize = QSize(20, 20);
QSize Helper::buttonIconSize = QSize(20, 20);
int Helper::headingFontSize = 18;

QString Helper::ModelicaSimulationMethods = "DASSL,DASSL2,Euler,Runge-Kutta";
Expand Down Expand Up @@ -109,6 +117,10 @@ QString GUIMessages::getMessage(int type)
return "The Annotations for the component %1 (%2) are not correct. Unable to add component.";
case SAVED_MODEL:
return "Saved %1 %2. File : '%3'";
case COMMENT_SAVE_ERROR:
return "Following Error has occurred while saving component comment. \n\n %1.";
case ATTRIBUTES_SAVE_ERROR:
return "Following Error has occurred while saving component attributes. \n\n %1.";
default:
return "";
}
Expand Down

0 comments on commit ad219ab

Please sign in to comment.