Changeset 9c31adbf in OpenModelica


Ignore:
Timestamp:
2020-10-19T23:04:15+02:00 (3 years ago)
Author:
Adrian Pop <adrian.pop@…>
Branches:
Added-citation-metadata, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, master, omlib-staging
Children:
42da8451, 5a43137
Parents:
45d9b444
git-author:
Adeel Asghar <adeel.asghar@…> (10/19/20 18:09:40)
git-committer:
Adrian Pop <adrian.pop@…> (10/19/20 23:04:15)
Message:

Set the default place holder text for replaceable

Fixes ticket:6127

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OMEdit/OMEditLIB/Element/ElementProperties.cpp

    rc7e992f r9c31adbf  
    180180        mpValueComboBox->lineEdit()->setPlaceholderText(value);
    181181      } else {
    182         mpValueComboBox->lineEdit()->setText(value);
    183         mpValueComboBox->lineEdit()->setModified(valueModified);
     182        // update the value combobox index when setting the value on the line edit
     183        bool state = mpValueComboBox->blockSignals(true);
     184        int index = mpValueComboBox->findData(value);
     185        if (index > -1) {
     186          mpValueComboBox->setCurrentIndex(index);
     187          mpValueComboBox->lineEdit()->setText(value);
     188          mpValueComboBox->lineEdit()->setModified(valueModified);
     189        }
     190        mpValueComboBox->blockSignals(state);
    184191      }
    185192      if (adjustSize) {
     
    311318  OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
    312319  QString className = mpComponent->getComponentInfo()->getClassName();
    313   QString constrainedByClassName = "$Any";
     320  QString constrainedByClassName = QStringLiteral("$Any");
    314321  QString replaceable = "", replaceableText = "";
    315322  QStringList enumerationLiterals, replaceableChoices;
     
    343350    case Parameter::ReplaceableComponent:
    344351    case Parameter::ReplaceableClass:
    345       {
    346352      constrainedByClassName = mpComponent->getComponentInfo()->getConstrainedByClassName();
    347353      mpValueComboBox = new QComboBox;
    348354      mpValueComboBox->setEditable(true);
    349       if (!mDefaultValue.isEmpty()) {
    350         mpValueComboBox->addItem(mDefaultValue, mDefaultValue);
    351         mpValueComboBox->lineEdit()->setPlaceholderText(mDefaultValue);
    352       }
    353       else {
    354         if (mValueType == Parameter::ReplaceableClass) {
    355           QString str = (pOMCProxy->getClassInformation(className)).comment;
    356           if (!str.isEmpty()) {
    357             str = " - " + str;
    358           }
    359           replaceableText =  className + str;
    360           mpValueComboBox->addItem(replaceableText, replaceableText);
    361           mpValueComboBox->lineEdit()->setPlaceholderText(replaceableText);
    362         }
    363         else {
    364           replaceable = "redeclare " + className + " " + mpComponent->getName();
    365           mpValueComboBox->addItem(replaceable, replaceable);
    366           mpValueComboBox->lineEdit()->setPlaceholderText(replaceable);
    367         }
    368       }
    369 
    370       if (constrainedByClassName.contains("$Any")) {
     355      mpValueComboBox->addItem("", "");
     356
     357      if (constrainedByClassName.contains(QStringLiteral("$Any"))) {
    371358        constrainedByClassName = className;
    372359      }
     
    374361      replaceableChoices = pOMCProxy->getAllSubtypeOf(constrainedByClassName, mpComponent->getComponentInfo()->getParentClassName());
    375362      for (i = 0 ; i < replaceableChoices.size(); i++) {
    376         if (className != replaceableChoices[i]) // filter out the default
    377         {
    378           if (mValueType == Parameter::ReplaceableClass) {
    379             if (i < replaceableChoices.size() - 1) // skip the last one
    380             {
    381               replaceable = "redeclare " + mpComponent->getComponentInfo()->getRestriction() + " " + mpComponent->getName() + " = " + replaceableChoices[i];
    382               QString str = (pOMCProxy->getClassInformation(replaceableChoices[i])).comment;
    383               if (!str.isEmpty()) {
    384                 str = " - " + str;
    385               }
    386               replaceableText = replaceableChoices[i] + str;
    387               mpValueComboBox->addItem(replaceableText, replaceable);
     363        if (mValueType == Parameter::ReplaceableClass) {
     364          if (i < replaceableChoices.size() - 1) { // skip the last one
     365            replaceable = QString("redeclare %1 %2 = %3").arg(mpComponent->getComponentInfo()->getRestriction(), mpComponent->getName(), replaceableChoices[i]);
     366            QString str = (pOMCProxy->getClassInformation(replaceableChoices[i])).comment;
     367            if (!str.isEmpty()) {
     368              str = " - " + str;
    388369            }
    389           }
    390           else {
    391             replaceable = "redeclare " + replaceableChoices[i] + " " + mpComponent->getName();
    392             replaceableText = replaceable;
     370            replaceableText = replaceableChoices[i] + str;
    393371            mpValueComboBox->addItem(replaceableText, replaceable);
    394372          }
     373        } else {
     374          replaceable = QString("redeclare %1 %2").arg(replaceableChoices[i], mpComponent->getName());
     375          mpValueComboBox->addItem(replaceable, replaceable);
    395376        }
    396377      }
    397378
    398       // add a way to remove the modifiers
    399       mpValueComboBox->addItem("[remove modifier]", "");
    400 
    401379      connect(mpValueComboBox, SIGNAL(currentIndexChanged(int)), SLOT(valueComboBoxChanged(int)));
    402       }
    403380      break;
    404381
     
    10341011    pParameter->setSaveSelectorFilter(saveSelectorFilter);
    10351012    pParameter->setSaveSelectorCaption(saveSelectorCaption);
    1036     QString componentDefinedInClass = pComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure();
    1037     QString value = pComponent->getComponentInfo()->getParameterValue(pOMCProxy, componentDefinedInClass);
    1038     pParameter->setValueWidget(value, true, pParameter->getUnit());
     1013    if (pParameter->getValueType() == Parameter::ReplaceableClass) {
     1014      QString className = pComponent->getComponentInfo()->getClassName();
     1015      QString comment = "";
     1016      if (pComponent->getLibraryTreeItem()) {
     1017        comment = pComponent->getLibraryTreeItem()->mClassInformation.comment;
     1018      } else {
     1019        comment = (pOMCProxy->getClassInformation(className)).comment;
     1020      }
     1021      pParameter->setValueWidget(comment.isEmpty() ? className : QString("%1 - %2").arg(className, comment), true, pParameter->getUnit());
     1022    } else if (pParameter->getValueType() == Parameter::ReplaceableComponent) {
     1023      pParameter->setValueWidget(QString("redeclare %1 %2").arg(pComponent->getComponentInfo()->getClassName(), pComponent->getName()), true, pParameter->getUnit());
     1024    } else {
     1025      QString componentDefinedInClass = pComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure();
     1026      QString value = pComponent->getComponentInfo()->getParameterValue(pOMCProxy, componentDefinedInClass);
     1027      pParameter->setValueWidget(value, true, pParameter->getUnit());
     1028    }
    10391029    if (showStartAttribute) {
    10401030      pParameter->setValueWidget(start, true, pParameter->getUnit());
Note: See TracChangeset for help on using the changeset viewer.