Skip to content

Commit

Permalink
- update the icon in tree when iconView of model is changed.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23799 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Dec 16, 2014
1 parent dd83af3 commit e89c071
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
33 changes: 12 additions & 21 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -91,21 +91,7 @@ void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
value = index.data(Qt::DecorationRole);
if (value.isValid()) {
if (value.type() == QVariant::Icon) {
QPixmap componentPixmap;
LibraryTreeWidget *pLibraryTreeWidget = 0;
if (parent() && (pLibraryTreeWidget = qobject_cast<LibraryTreeWidget*>(parent()))) {
LibraryTreeNode *pLibraryTreeNode = static_cast<LibraryTreeNode*>(index.internalPointer());
LibraryComponent *pLibraryComponent = pLibraryTreeWidget->getLibraryComponentObject(pLibraryTreeNode->getNameStructure());
if (pLibraryComponent) {
int libraryIconSize = pLibraryTreeWidget->getMainWindow()->getOptionsDialog()->getGeneralSettingsPage()->getLibraryIconSizeSpinBox()->value();
componentPixmap = pLibraryComponent->getComponentPixmap(QSize(libraryIconSize, libraryIconSize));
}
}
if (componentPixmap.isNull()) {
icon = qvariant_cast<QIcon>(value);
} else {
icon = QIcon(componentPixmap);
}
icon = qvariant_cast<QIcon>(value);
decorationRect = QRect(QPoint(0, 0), icon.actualSize(option.decorationSize, iconMode, iconState));
} else {
pixmap = decoration(opt, value);
Expand Down Expand Up @@ -2015,16 +2001,19 @@ void LibraryTreeWidget::loadLibraryComponent(LibraryTreeNode *pLibraryTreeNode)
{
OMCProxy *pOMCProxy = mpMainWindow->getOMCProxy();
QString result = pOMCProxy->getIconAnnotation(pLibraryTreeNode->getNameStructure());
LibraryComponent *libComponent = new LibraryComponent(result, pLibraryTreeNode->getNameStructure(), pOMCProxy);
int libraryIconSize = mpMainWindow->getOptionsDialog()->getGeneralSettingsPage()->getLibraryIconSizeSpinBox()->value();
QPixmap pixmap = libComponent->getComponentPixmap(QSize(libraryIconSize, libraryIconSize));
LibraryComponent *pLibraryComponent = getLibraryComponentObject(pLibraryTreeNode->getNameStructure());
if (pLibraryComponent) {
mLibraryComponentsList.removeOne(pLibraryComponent);
}
pLibraryComponent = new LibraryComponent(result, pLibraryTreeNode->getNameStructure(), pOMCProxy);
QPixmap pixmap = pLibraryComponent->getComponentPixmap(iconSize());
// if the component does not have icon annotation check if it has non standard dymola annotation or not.
if (pixmap.isNull()) {
pOMCProxy->sendCommand("getNamedAnnotation(" + pLibraryTreeNode->getNameStructure() + ", __Dymola_DocumentationClass)");
if (StringHandler::unparseBool(StringHandler::removeFirstLastCurlBrackets(pOMCProxy->getResult())) || pLibraryTreeNode->isDocumentationClass()) {
result = pOMCProxy->getIconAnnotation("Modelica.Icons.Information");
libComponent = new LibraryComponent(result, pLibraryTreeNode->getNameStructure(), pOMCProxy);
pixmap = libComponent->getComponentPixmap(QSize(libraryIconSize, libraryIconSize));
pLibraryComponent = new LibraryComponent(result, pLibraryTreeNode->getNameStructure(), pOMCProxy);
pixmap = pLibraryComponent->getComponentPixmap(iconSize());
// if still the pixmap is null for some unknown reasons then used the pre defined image
if (pixmap.isNull()) {
pLibraryTreeNode->setIcon(0, QIcon(":/Resources/icons/info-icon.svg"));
Expand All @@ -2033,8 +2022,10 @@ void LibraryTreeWidget::loadLibraryComponent(LibraryTreeNode *pLibraryTreeNode)
// if the component does not have non standard dymola annotation as well.
pLibraryTreeNode->setIcon(0, pLibraryTreeNode->getModelicaNodeIcon());
}
} else {
pLibraryTreeNode->setIcon(0, QIcon(pixmap));
}
addLibraryComponentObject(libComponent);
addLibraryComponentObject(pLibraryComponent);
}

void LibraryTreeWidget::mouseDoubleClickEvent(QMouseEvent *event)
Expand Down
10 changes: 3 additions & 7 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -1141,17 +1141,13 @@ void GraphicsView::addClassAnnotation()
}
annotationString.append(")");
// add the class annotation to model through OMC
if (pMainWindow->getOMCProxy()->addClassAnnotation(mpModelWidget->getLibraryTreeNode()->getNameStructure(), annotationString))
{
if (pMainWindow->getOMCProxy()->addClassAnnotation(mpModelWidget->getLibraryTreeNode()->getNameStructure(), annotationString)) {
mpModelWidget->setModelModified();
/* When something is added/changed in the icon layer then update the LibraryTreeNode in the Library Browser */
if (mViewType == StringHandler::Icon)
{
if (mViewType == StringHandler::Icon) {
pMainWindow->getLibraryTreeWidget()->loadLibraryComponent(mpModelWidget->getLibraryTreeNode());
}
}
else
{
} else {
pMainWindow->getMessagesWidget()->addGUIMessage(new MessageItem("", false, 0, 0, 0, 0,
tr("Error in class annotation ") + pMainWindow->getOMCProxy()->getResult(),
Helper::scriptingKind, Helper::errorLevel, 0));
Expand Down
8 changes: 2 additions & 6 deletions OMEdit/OMEditGUI/Options/OptionsDialog.cpp
Expand Up @@ -416,11 +416,7 @@ void OptionsDialog::saveGeneralSettings()
// save user customizations
mpSettings->setValue("userCustomizations", mpGeneralSettingsPage->getPreserveUserCustomizations());
// save library icon size
int libraryIconSize = mpGeneralSettingsPage->getLibraryIconSizeSpinBox()->value();
mpSettings->setValue("libraryIconSize", libraryIconSize);
if (mpMainWindow->getLibraryTreeWidget()->iconSize().width() != libraryIconSize) {
mpMainWindow->getLibraryTreeWidget()->setIconSize(QSize(libraryIconSize, libraryIconSize));
}
mpSettings->setValue("libraryIconSize", mpGeneralSettingsPage->getLibraryIconSizeSpinBox()->value());
// save show protected classes
mpSettings->setValue("showProtectedClasses", mpGeneralSettingsPage->getShowProtectedClasses());
// show/hide the protected classes
Expand Down Expand Up @@ -901,7 +897,7 @@ GeneralSettingsPage::GeneralSettingsPage(OptionsDialog *pParent)
// Libraries Browser group box
mpLibrariesBrowserGroupBox = new QGroupBox(tr("Libraries Browser"));
// library icon size
mpLibraryIconSizeLabel = new Label(tr("Library Icon Size:"));
mpLibraryIconSizeLabel = new Label(tr("Library Icon Size: *"));
mpLibraryIconSizeSpinBox = new QSpinBox;
mpLibraryIconSizeSpinBox->setMinimum(16);
mpLibraryIconSizeSpinBox->setValue(24);
Expand Down

0 comments on commit e89c071

Please sign in to comment.