Skip to content

Commit

Permalink
Show the library version information in the documentation view (#7883)
Browse files Browse the repository at this point in the history
* Show the library version information in the documentation view

* Do not fetch the information twice.
  • Loading branch information
adeas31 committed Sep 9, 2021
1 parent ef894ab commit 675fe85
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 42 deletions.
10 changes: 10 additions & 0 deletions OMEdit/OMEditLIB/Modeling/Commands.cpp
Expand Up @@ -33,7 +33,9 @@

#include "Commands.h"
#include "MainWindow.h"
#include "DocumentationWidget.h"

#include <QDockWidget>
#include <QMessageBox>
#include <functional>

Expand Down Expand Up @@ -1277,6 +1279,10 @@ void UpdateCoOrdinateSystemCommand::redoInternal()
QString versionAnnotation = QString("annotate=version(\"%1\")").arg(mNewVersion);
if (pOMCProxy->addClassAnnotation(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), versionAnnotation)) {
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->mClassInformation.version = mNewVersion;
// if documentation view is visible then update it
if (MainWindow::instance()->getDocumentationDockWidget()->isVisible()) {
MainWindow::instance()->getDocumentationWidget()->showDocumentation(mpGraphicsView->getModelWidget()->getLibraryTreeItem());
}
}
// uses annotation
pOMCProxy->addClassAnnotation(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), mNewUsesAnnotationString);
Expand Down Expand Up @@ -1317,6 +1323,10 @@ void UpdateCoOrdinateSystemCommand::undo()
QString versionAnnotation = QString("annotate=version(\"%1\")").arg(mOldVersion);
if (pOMCProxy->addClassAnnotation(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), versionAnnotation)) {
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->mClassInformation.version = mOldVersion;
// if documentation view is visible then update it
if (MainWindow::instance()->getDocumentationDockWidget()->isVisible()) {
MainWindow::instance()->getDocumentationWidget()->showDocumentation(mpGraphicsView->getModelWidget()->getLibraryTreeItem());
}
}
// uses annotation
pOMCProxy->addClassAnnotation(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), mOldUsesAnnotationString);
Expand Down
66 changes: 63 additions & 3 deletions OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -70,6 +70,9 @@ LibraryTreeItem::LibraryTreeItem()
OMCInterface::getClassInformation_res classInformation;
setClassInformation(classInformation);
setFileName("");
mVersionDate = "";
mVersionBuild = "";
mDateModified = "";
setReadOnly(false);
setIsSaved(false);
setSaveContentsType(LibraryTreeItem::SaveInOneFile);
Expand Down Expand Up @@ -169,6 +172,11 @@ void LibraryTreeItem::setClassInformation(OMCInterface::getClassInformation_res
if (mLibraryType == LibraryTreeItem::Modelica) {
mClassInformation = classInformation;
setFileName(classInformation.fileName);
if (!mIsRootItem) {
mVersionDate = MainWindow::instance()->getOMCProxy()->getNamedAnnotation(mNameStructure, "versionDate");
mVersionBuild = MainWindow::instance()->getOMCProxy()->getNamedAnnotation(mNameStructure, "versionBuild", StringHandler::Integer);
mDateModified = MainWindow::instance()->getOMCProxy()->getNamedAnnotation(mNameStructure, "dateModified");
}
setReadOnly(classInformation.fileReadOnly);
// set save contents type
if (isFilePathValid()) {
Expand Down Expand Up @@ -208,6 +216,58 @@ void LibraryTreeItem::setClassInformation(OMCInterface::getClassInformation_res
}
}

/*!
* \brief LibraryTreeItem::getVersion
* \return
*/
const QString &LibraryTreeItem::getVersion() const
{
if (mClassInformation.version.isEmpty() && mpParentLibraryTreeItem && !mpParentLibraryTreeItem->isRootItem()) {
return mpParentLibraryTreeItem->getVersion();
} else {
return mClassInformation.version;
}
}

/*!
* \brief LibraryTreeItem::getVersionDate
* \return
*/
const QString &LibraryTreeItem::getVersionDate() const
{
if (mVersionDate.isEmpty() && mpParentLibraryTreeItem && !mpParentLibraryTreeItem->isRootItem()) {
return mpParentLibraryTreeItem->getVersionDate();
} else {
return mVersionDate;
}
}

/*!
* \brief LibraryTreeItem::getVersionBuild
* \return
*/
const QString &LibraryTreeItem::getVersionBuild() const
{
if (mVersionBuild.isEmpty() && mpParentLibraryTreeItem && !mpParentLibraryTreeItem->isRootItem()) {
return mpParentLibraryTreeItem->getVersionBuild();
} else {
return mVersionBuild;
}
}

/*!
* \brief LibraryTreeItem::getDateModified
* \return
*/
const QString &LibraryTreeItem::getDateModified() const
{
if (mDateModified.isEmpty() && mpParentLibraryTreeItem && !mpParentLibraryTreeItem->isRootItem()) {
return mpParentLibraryTreeItem->getDateModified();
} else {
return mDateModified;
}
}

/*!
* \brief LibraryTreeItem::isFilePathValid
* Returns true if file path is valid file location and not modelica class name.
Expand Down Expand Up @@ -3403,9 +3463,9 @@ void LibraryTreeView::openInformationDialog()
QVBoxLayout *pLayout = new QVBoxLayout;
pLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pLayout->addWidget(pHeadingLabel);
pLayout->addWidget(new Label(tr("Version : %1").arg(MainWindow::instance()->getOMCProxy()->getVersion(pLibraryTreeItem->getNameStructure()))));
pLayout->addWidget(new Label(tr("Version Date : %1").arg(MainWindow::instance()->getOMCProxy()->getVersionDateAnnotation(pLibraryTreeItem->getNameStructure()))));
pLayout->addWidget(new Label(tr("Version Build : %1").arg(MainWindow::instance()->getOMCProxy()->getVersionBuildAnnotation(pLibraryTreeItem->getNameStructure()))));
pLayout->addWidget(new Label(tr("Version : %1").arg(pLibraryTreeItem->getVersion())));
pLayout->addWidget(new Label(tr("Version Date : %1").arg(pLibraryTreeItem->getVersionDate())));
pLayout->addWidget(new Label(tr("Version Build : %1").arg(pLibraryTreeItem->getVersionBuild())));
pInformationDialog->setLayout(pLayout);
pInformationDialog->exec();
}
Expand Down
7 changes: 7 additions & 0 deletions OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.h
Expand Up @@ -97,6 +97,10 @@ class LibraryTreeItem : public QObject
void setClassInformation(OMCInterface::getClassInformation_res classInformation);
void setFileName(QString fileName) {mFileName = fileName;}
const QString& getFileName() const {return mFileName;}
const QString& getVersion() const;
const QString& getVersionDate() const;
const QString& getVersionBuild() const;
const QString& getDateModified() const;
bool isFilePathValid();
void setReadOnly(bool readOnly) {mReadOnly = readOnly;}
bool isReadOnly() {return mReadOnly;}
Expand Down Expand Up @@ -204,6 +208,9 @@ class LibraryTreeItem : public QObject
QString mParentName;
QString mNameStructure;
QString mFileName;
QString mVersionDate;
QString mVersionBuild;
QString mDateModified;
bool mReadOnly;
bool mIsSaved;
SaveContentsType mSaveContentsType;
Expand Down
75 changes: 41 additions & 34 deletions OMEdit/OMEditLIB/OMC/OMCProxy.cpp
Expand Up @@ -1450,6 +1450,22 @@ QString OMCProxy::getDocumentationAnnotation(LibraryTreeItem *pLibraryTreeItem)
docElement.remove(QRegExp("<html>|</html>|<HTML>|</HTML>|<head>|</head>|<HEAD>|</HEAD>|<body>|</body>|<BODY>|</BODY>"));
doc += docElement;
}

QString version = pLibraryTreeItem->getVersion();
QString versionDate = pLibraryTreeItem->getVersionDate();
QString versionBuild = pLibraryTreeItem->getVersionBuild();
QString dateModified = pLibraryTreeItem->getDateModified();
if (!version.isEmpty()) {
if (!versionDate.isEmpty()) {
version += QString(", %1").arg(versionDate);
}
if (!versionBuild.isEmpty()) {
version += QString(", build %1").arg(versionBuild);
if (!dateModified.isEmpty()) {
version += QString(" (%1)").arg(dateModified);
}
}
}
QString documentation = QString("<html>\n"
" <head>\n"
" <style>\n"
Expand All @@ -1462,14 +1478,19 @@ QString OMCProxy::getDocumentationAnnotation(LibraryTreeItem *pLibraryTreeItem)
" </head>\n"
" <body>\n"
" %6\n"
" <hr />"
" Filename: %7<br />"
" Version: %8<br />"
" </body>\n"
"</html>")
.arg(Helper::systemFontInfo.family())
.arg(Helper::systemFontInfo.pointSize())
.arg(Helper::monospacedFontInfo.family())
.arg(Helper::monospacedFontInfo.pointSize())
.arg(infoHeader)
.arg(doc);
.arg(Helper::systemFontInfo.family())
.arg(Helper::systemFontInfo.pointSize())
.arg(Helper::monospacedFontInfo.family())
.arg(Helper::monospacedFontInfo.pointSize())
.arg(infoHeader)
.arg(doc)
.arg(pLibraryTreeItem->getFileName())
.arg(version);
documentation = makeDocumentationUriToFileName(documentation);
/*! @note We convert modelica:// to modelica:///.
* This tells QWebview that these links doesn't have any host.
Expand Down Expand Up @@ -2800,39 +2821,25 @@ QList<QString> OMCProxy::getDerivedUnits(QString baseUnit)
return result;
}

QString OMCProxy::getVersionDateAnnotation(QString className)
{
sendCommand("getNamedAnnotation(" + className + ", versionDate)");
return StringHandler::unparse(StringHandler::removeFirstLastCurlBrackets(getResult()));
}

QString OMCProxy::getVersionBuildAnnotation(QString className)
{
sendCommand("getNamedAnnotation(" + className + ", versionBuild)");
return StringHandler::removeFirstLastCurlBrackets(getResult());
}

/*!
Gets the DocumentationClass annotation.
\param className - the name of the class.
\return true/false.
*/
bool OMCProxy::getDocumentationClassAnnotation(QString className)
{
sendCommand("getNamedAnnotation(" + className + ", DocumentationClass)");
return StringHandler::unparseBool(StringHandler::removeFirstLastCurlBrackets(getResult()));
}

/*!
* \brief OMCProxy::getCommandLineOptionsAnnotation
* Reads the __OpenModelica_commandLineOptions annotation from the class.
* \brief OMCProxy::getNamedAnnotation
* Returns the named annotation from the class.
* \param className
* \param annotation
* \param type
* \return
*/
QString OMCProxy::getCommandLineOptionsAnnotation(QString className)
QString OMCProxy::getNamedAnnotation(const QString &className, const QString &annotation, StringHandler::ResultType type)
{
sendCommand("getNamedAnnotation(" + className + ", __OpenModelica_commandLineOptions)");
return StringHandler::unparse(StringHandler::removeFirstLastCurlBrackets(getResult()));
sendCommand(QString("getNamedAnnotation(%1, %2)").arg(className, annotation));
QString result = StringHandler::removeFirstLastCurlBrackets(getResult());
switch (type) {
case StringHandler::Integer:
return result;
case StringHandler::String:
default:
return StringHandler::unparse(result);
}
}

/*!
Expand Down
4 changes: 1 addition & 3 deletions OMEdit/OMEditLIB/OMC/OMCProxy.h
Expand Up @@ -234,9 +234,7 @@ class OMCProxy : public QObject
QString getDerivedClassModifierValue(QString className, QString modifierName);
OMCInterface::convertUnits_res convertUnits(QString from, QString to);
QList<QString> getDerivedUnits(QString baseUnit);
QString getVersionDateAnnotation(QString className);
QString getVersionBuildAnnotation(QString className);
bool getDocumentationClassAnnotation(QString className);
QString getNamedAnnotation(const QString &className, const QString &annotation, StringHandler::ResultType type = StringHandler::String);
QString getCommandLineOptionsAnnotation(QString className);
QList<QString> getAnnotationNamedModifiers(QString className, QString annotation);
QString getAnnotationModifierValue(QString className, QString annotation, QString modifier);
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditLIB/Simulation/SimulationDialog.cpp
Expand Up @@ -703,7 +703,7 @@ void SimulationDialog::initializeFields(bool isReSimulate, SimulationOptions sim
// if ignoreCommandLineOptionsAnnotation flag is not set then read the __OpenModelica_commandLineOptions annotation
if (!OptionsDialog::instance()->getSimulationPage()->getIgnoreCommandLineOptionsAnnotationCheckBox()->isChecked()) {
QStringList additionalTranslationFlagsList;
QString commandLineOptions = MainWindow::instance()->getOMCProxy()->getCommandLineOptionsAnnotation(mClassName);
QString commandLineOptions = MainWindow::instance()->getOMCProxy()->getNamedAnnotation(mClassName, "__OpenModelica_commandLineOptions");
QStringList commandLineOptionsList = commandLineOptions.split(" ");
foreach (QString commandLineOption, commandLineOptionsList) {
QStringList commandLineOptionList = commandLineOption.split("=");
Expand Down Expand Up @@ -1692,7 +1692,7 @@ void SimulationDialog::saveTranslationFlagsAnnotation()
}
// old translation flags
QString oldCommandLineOptions = QString("__OpenModelica_commandLineOptions(\"%1\")")
.arg(MainWindow::instance()->getOMCProxy()->getCommandLineOptionsAnnotation(mpLibraryTreeItem->getNameStructure()));
.arg(MainWindow::instance()->getOMCProxy()->getNamedAnnotation(mpLibraryTreeItem->getNameStructure(), "__OpenModelica_commandLineOptions"));
// new translation flags
QString newCommandLineOptions = QString("__OpenModelica_commandLineOptions(\"%1\")").arg(mpTranslationFlagsWidget->commandLineOptions());
// if we have ModelWidget for class then put the change on undo stack.
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/Util/StringHandler.h
Expand Up @@ -69,6 +69,7 @@ class StringHandler : public QObject
OMEditInfo /* used internally by OMEdit to mark message blue. */
};
enum TLMCausality { TLMBidirectional, TLMInput, TLMOutput };
enum ResultType {String, Integer};
static QString getTLMCausality(int causality);
enum TLMDomain { Mechanical, Electric, Hydraulic, Pneumatic, Magnetic, Signal };
static QString getTLMDomain(int domain);
Expand Down

0 comments on commit 675fe85

Please sign in to comment.