Skip to content

Commit

Permalink
Fixes #3665. Allow html display and clickable links for class comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Feb 5, 2016
1 parent 5f95f7e commit e3b00ab
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
8 changes: 6 additions & 2 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -1396,12 +1396,16 @@ QString Component::getParameterDisplayStringFromExtendsParameters(QString parame
*/
void Component::updateToolTip()
{
QString comment = mpComponentInfo->getComment().replace("\\\"", "\"");
OMCProxy *pOMCProxy = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy();
comment = pOMCProxy->makeDocumentationUriToFileName(comment);

if (mIsInheritedComponent || mComponentType == Component::Port) {
setToolTip(tr("<b>%1</b> %2<br/>%3<br /><br />Component declared in %4").arg(mpComponentInfo->getClassName())
.arg(mpComponentInfo->getName()).arg(mpComponentInfo->getComment())
.arg(mpComponentInfo->getName()).arg(comment)
.arg(mpReferenceComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure()));
} else {
setToolTip(tr("<b>%1</b> %2<br/>%3").arg(mpComponentInfo->getClassName()).arg(mpComponentInfo->getName()).arg(mpComponentInfo->getComment()));
setToolTip(tr("<b>%1</b> %2<br/>%3").arg(mpComponentInfo->getClassName()).arg(mpComponentInfo->getName()).arg(comment));
}
}

Expand Down
22 changes: 21 additions & 1 deletion OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -482,8 +482,14 @@ void ComponentParameters::setUpDialog()
mpComponentClassNameTextBox = new Label(mpComponent->getComponentInfo()->getClassName());
// Component comment
mpComponentClassCommentLabel = new Label(Helper::comment);
mpComponentClassCommentTextBox = new Label(mpComponent->getLibraryTreeItem() ? mpComponent->getLibraryTreeItem()->mClassInformation.comment : "");
mpComponentClassCommentTextBox = new Label;
mpComponentClassCommentTextBox->setTextFormat(Qt::RichText);
mpComponentClassCommentTextBox->setTextInteractionFlags(mpComponentClassCommentTextBox->textInteractionFlags()
| Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
if (mpComponent->getLibraryTreeItem()) {
mpComponentClassCommentTextBox->setText(mpComponent->getLibraryTreeItem()->mClassInformation.comment);
}
connect(mpComponentClassCommentTextBox, SIGNAL(linkActivated(QString)), SLOT(commentLinkClicked(QString)));
QGridLayout *pComponentClassGroupBoxLayout = new QGridLayout;
pComponentClassGroupBoxLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pComponentClassGroupBoxLayout->addWidget(mpComponentClassNameLabel, 0, 0);
Expand Down Expand Up @@ -860,6 +866,20 @@ Parameter* ComponentParameters::findParameter(const QString &parameter, Qt::Case
return 0;
}

void ComponentParameters::commentLinkClicked(QString link)
{
QUrl linkUrl(link);
if (linkUrl.scheme().compare("modelica") == 0) {
link = link.remove("modelica://");
LibraryTreeItem *pLibraryTreeItem = mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem(link);
if (pLibraryTreeItem) {
mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->showModelWidget(pLibraryTreeItem);
}
} else {
QDesktopServices::openUrl(link);
}
}

/*!
* \brief ComponentParameters::updateComponentParameters
* Slot activated when mpOkButton clicked signal is raised.\n
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Component/ComponentProperties.h
Expand Up @@ -163,6 +163,7 @@ class ComponentParameters : public QDialog
Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive) const;
Parameter* findParameter(const QString &parameter, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive) const;
public slots:
void commentLinkClicked(QString link);
void updateComponentParameters();
};

Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -3269,7 +3269,7 @@ AboutOMEditWidget::AboutOMEditWidget(MainWindow *pMainWindow)
.append("Initially developed by <b>Adeel Asghar</b> and <b>Sonia Tariq</b> as part of their final master thesis.");
Label *pAboutTextLabel = new Label;
pAboutTextLabel->setTextFormat(Qt::RichText);
pAboutTextLabel->setTextInteractionFlags(pAboutTextLabel->textInteractionFlags() |Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
pAboutTextLabel->setTextInteractionFlags(pAboutTextLabel->textInteractionFlags() | Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
pAboutTextLabel->setOpenExternalLinks(true);
pAboutTextLabel->setFont(QFont(Helper::systemFontInfo.family(), Helper::systemFontInfo.pointSize() - 4 + MAC_FONT_FACTOR));
pAboutTextLabel->setWordWrap(true);
Expand Down
6 changes: 5 additions & 1 deletion OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -781,7 +781,11 @@ QStringList OMCProxy::searchClassNames(QString searchText, bool findInText)
*/
OMCInterface::getClassInformation_res OMCProxy::getClassInformation(QString className)
{
return mpOMCInterface->getClassInformation(className);
OMCInterface::getClassInformation_res classInformation = mpOMCInterface->getClassInformation(className);
QString comment = classInformation.comment.replace("\\\"", "\"");
comment = makeDocumentationUriToFileName(comment);
classInformation.comment = comment;
return classInformation;
}

/*!
Expand Down

0 comments on commit e3b00ab

Please sign in to comment.