Skip to content

Commit

Permalink
Open edit component (#11423)
Browse files Browse the repository at this point in the history
* Take qualify path from main model and not from component in edit
rediclare model

* Add ligoc for inheritable. Add null check.
  • Loading branch information
MaksKBV committed Nov 14, 2023
1 parent 9bf037a commit 37638a7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
11 changes: 10 additions & 1 deletion OMEdit/OMEditLIB/Element/ElementProperties.cpp
Expand Up @@ -867,7 +867,16 @@ void Parameter::editRedeclareClassButtonClicked()
}
}
// get type as qualified path
const QString qualifiedType = MainWindow::instance()->getOMCProxy()->qualifyPath(mpModelInstanceElement->getParentModel()->getName(), type);
if ((mpModelInstanceElement == NULL) ||
(mpModelInstanceElement->getTopLevelExtendElement() == NULL) ||
(mpModelInstanceElement->getTopLevelExtendElement()->getParentModel() == NULL) ||
(mpModelInstanceElement->getTopLevelExtendElement()->getParentModel()->getName() == NULL))
{
QMessageBox::critical(MainWindow::instance(), QString("%1 - %2").arg(Helper::applicationName, Helper::error),
tr("Unable to find the redeclare class."), Helper::ok);
}

const QString qualifiedType = MainWindow::instance()->getOMCProxy()->qualifyPath(mpModelInstanceElement->getTopLevelExtendElement()->getParentModel()->getName(), type);
// if we fail to find the type
if (qualifiedType.isEmpty()) {
QMessageBox::critical(MainWindow::instance(), QString("%1 - %2").arg(Helper::applicationName, Helper::error),
Expand Down
15 changes: 11 additions & 4 deletions OMEdit/OMEditLIB/Modeling/Model.cpp
Expand Up @@ -1731,17 +1731,24 @@ namespace ModelInstance
deserialize_impl(jsonObject);
}

Element *Element::getTopLevelExtendElement() const
{
Element *pElement = mpParentModel->getParentElement();
while (pElement && pElement->getParentModel() && pElement->getParentModel()->getParentElement()) {
pElement = pElement->getParentModel()->getParentElement();
}

return pElement;
}

/*!
* \brief Element::getTopLevelExtendName
* Returns the top level extend name where the element is located.
* \return
*/
QString Element::getTopLevelExtendName() const
{
Element *pElement = mpParentModel->getParentElement();
while (pElement && pElement->getParentModel() && pElement->getParentModel()->getParentElement()) {
pElement = pElement->getParentModel()->getParentElement();
}
Element *pElement = getTopLevelExtendElement();

if (pElement->getModel()) {
return pElement->getModel()->getName();
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/Modeling/Model.h
Expand Up @@ -636,6 +636,7 @@ namespace ModelInstance

Model *getParentModel() const {return mpParentModel;}
QString getTopLevelExtendName() const;
Element *getTopLevelExtendElement() const;
void setModel(Model *pModel) {mpModel = pModel;}
Model *getModel() const {return mpModel;}
Modifier *getModifier() const {return mpModifier;}
Expand Down

0 comments on commit 37638a7

Please sign in to comment.