Exemplo n.º 1
0
std::string OSArgument::defaultValueAsString() const
{
  if (!hasDefaultValue()) {
    LOG_AND_THROW("Argument " << name() << " does not have a default value.");
  }
  return printQVariant(m_defaultValue);
}
Exemplo n.º 2
0
std::string OSArgument::print() const {
  std::stringstream ss;

  // name
  ss << name();
  if (!displayName().empty()) {
    ss << " (" << displayName() << ")";
  }
  ss << std::endl;

  // type and required
  ss << type().valueName() << ", ";
  if (required()) {
    ss << "Required";
  }
  else {
    ss << "Optional";
  }
  ss << std::endl;

  // value
  ss << "Value: ";
  if (hasValue()) {
    ss << printValue(false) << " ";
  }
  if (hasDefaultValue()) {
    ss << "(" << printDefaultValue() << ")";
  }
  ss << std::endl;

  if (m_type.value() == OSArgumentType::Choice) {
    ss << "Choices:" << std::endl;
    int dnn = m_choiceDisplayNames.size();
    for (int i = 0, n = m_choices.size(); i < n; ++i) {
      ss << "  " << m_choices[i];
      if ((i < dnn) && (!m_choiceDisplayNames[i].empty())) {
        ss << " (" << m_choiceDisplayNames[i] << ")";
      }
      ss << std::endl;
    }
  }

  if (hasDomain()) {
    ss << m_domainType.valueName() << " Domain: ";
    if (m_domainType == OSDomainType::Interval) {
      OS_ASSERT(m_domain.size() == 2u);
      ss << "[" << printQVariant(m_domain[0]) << ", " << printQVariant(m_domain[1]) << "]" << std::endl;
    }
    else {
      ss << std::endl;
      for (const QVariant& value : m_domain) {
        ss << "  " << printQVariant(value) << std::endl;
      }
    }
  }

  return ss.str();

}
Exemplo n.º 3
0
bool OSArgument::setDefaultValue(const std::string& defaultValue) {
  bool result = setStringInternal(m_defaultValue, defaultValue);
  if (result) {
    OS_ASSERT(hasDefaultValue());
    onChange();
  }
  return result;
}
Exemplo n.º 4
0
std::string OSArgument::printDefaultValue() const {
  std::string result;

  if (hasDefaultValue()) {
    result = printQVariant(m_defaultValue);
  }

  return result;
}
DoublePropertyWizardPane::DoublePropertyWizardPane(PropertyHandlerPtr handler, QObject* target)
    : PropertyWizardPane(handler, target)
{
    auto hdlr = handlerCast<DoublePropertyHandler>();

    // create the layout so that we can add stuff one by one
    auto layout = new QVBoxLayout;

    // add the message
    auto message = "Enter " + hdlr->title();
    message += " [" + hdlr->toString(hdlr->minValue()) + "," + hdlr->toString(hdlr->maxValue()) + "]";
    if (hdlr->hasDefaultValue()) message += " (" + hdlr->toString(hdlr->defaultValue()) + ")";
    message += ":";
    layout->addWidget(new QLabel(message));

    // add the edit field
    auto field = new QLineEdit;
    field->setText(hdlr->toString(hdlr->value()));
    layout->addWidget(field);

    // connect the field to ourselves
    connect(field, SIGNAL(textEdited(const QString&)), this, SLOT(updateValue(const QString&)));

    // finalize the layout and assign it to ourselves
    layout->addStretch();
    setLayout(layout);

    // if the property was never configured, put the default value or a blank in the text field
    if (!isPropertyConfigured())
    {
        if (hdlr->hasDefaultValue())
        {
            field->setText(hdlr->toString(hdlr->defaultValue()));
            hdlr->setValue(hdlr->defaultValue());    // also update the property value
        }
        else
        {
            field->setText("");
        }
    }

    // ensure proper validity state
    emit propertyValidChanged(isValidAndInRange(hdlr, field->text()));
}
Exemplo n.º 6
0
int OSArgument::defaultValueAsInteger() const
{
  if (!hasDefaultValue()) {
    LOG_AND_THROW("This argument does not have a default value set.")
  }
  if (type() != OSArgumentType::Integer) {
    LOG_AND_THROW("This argument is of type " << type().valueName() << ", not of type Integer.");
  }
  return m_defaultValue.toInt();
}
Exemplo n.º 7
0
bool OSArgument::setDefaultValue(double defaultValue) {
  bool result = false;
  if (m_type == OSArgumentType::Double){
    m_defaultValue.setValue(defaultValue);
    OS_ASSERT(hasDefaultValue());
    onChange();
    result = true;
  }
  return result;
}
Exemplo n.º 8
0
bool OSArgument::setDefaultValue(const openstudio::path& defaultValue) {
  bool result = false;
  if (m_type == OSArgumentType::Path){
    m_defaultValue.setValue(toQString(defaultValue));
    OS_ASSERT(hasDefaultValue());
    onChange();
    result = true;
  }
  return result;
}
Exemplo n.º 9
0
bool OSArgument::setDefaultValue(const Quantity& value) {
  bool result = false;
  if (m_type == OSArgumentType::Quantity) {
    m_defaultValue = QVariant::fromValue<openstudio::Quantity>(value);
    OS_ASSERT(hasDefaultValue());
    onChange();
    result = true;
  }
  return result;
}
Exemplo n.º 10
0
openstudio::path OSArgument::defaultValueAsPath() const
{
  if (!hasDefaultValue()) {
    LOG_AND_THROW("This argument does not have a default value set.")
  }
  if (type() != OSArgumentType::Path) {
    LOG_AND_THROW("This argument is of type " << type().valueName() << ", not of type Path.");
  }
  return toPath(m_defaultValue.toString());
}
Exemplo n.º 11
0
Quantity OSArgument::defaultValueAsQuantity() const
{
  if (!hasDefaultValue()) {
    LOG_AND_THROW("This argument does not have a default value set.")
  }
  if (type() != OSArgumentType::Quantity) {
    LOG_AND_THROW("This argument is of type " << type().valueName() << ", not of type Quantity.");
  }
  return m_defaultValue.value<openstudio::Quantity>();
}
Exemplo n.º 12
0
double OSArgument::defaultValueAsDouble() const
{
  if (!hasDefaultValue()) {
    LOG_AND_THROW("This argument does not have a default value set.")
  }
  if (type() != OSArgumentType::Double) {
    LOG_AND_THROW("This argument is of type " << type().valueName() << ", not of type Double.");
  }
  return m_defaultValue.toDouble();
}
Exemplo n.º 13
0
bool OSArgument::defaultValueAsBool() const
{
  if (!hasDefaultValue()) {
    LOG_AND_THROW("This argument does not have a default value set.")
  }
  if (type() != OSArgumentType::Boolean) {
    LOG_AND_THROW("This argument is of type " << type().valueName() << ", not of type Bool.");
  }
  if ("true" == m_defaultValue.toString()){
    return true;
  }
  return false;
}
Exemplo n.º 14
0
bool OSArgument::setDefaultValue(bool defaultValue) {
  bool result = false;
  if (m_type == OSArgumentType::Boolean) {
    if (defaultValue) {
      m_defaultValue.setValue(QString("true"));
    }
    else {
      m_defaultValue.setValue(QString("false"));
    }
    OS_ASSERT(hasDefaultValue());
    onChange();
    result = true;
  }
  return result;
}
Exemplo n.º 15
0
std::string OSArgument::printValue(bool printDefault) const {
  std::string result;

  QVariant toPrint;
  if (hasValue()) {
    toPrint = m_value;
  }
  else if (printDefault && hasDefaultValue()) {
    toPrint = m_defaultValue;
  }

  if (!toPrint.isNull()) {
    result = printQVariant(toPrint);
  }

  return result;
}
Exemplo n.º 16
0
 void OSArgumentRecord_Impl::updatePathData(const openstudio::path& originalBase,
                                            const openstudio::path& newBase)
 {
   if (type() == ruleset::OSArgumentType::Path) {
     openstudio::path temp;
     if (hasValue()) {
       temp = relocatePath(valueAsPath(),originalBase,newBase);
       if (!temp.empty()) {
         setValue(temp);
       }
     }
     if (hasDefaultValue()) {
       temp = relocatePath(defaultValueAsPath(),originalBase,newBase);
       if (!temp.empty()) {
         setDefaultValue(temp);
       }
     }
   }
 }
Exemplo n.º 17
0
folly::Optional<std::pair<SrcKey,TransID>>
updateFuncPrologue(TCA start, ProfTransRec* rec) {
  auto func = rec->func();
  auto nArgs = rec->prologueArgs();

  auto codeLock = lockCode();

  // Smash callers of the old prologue with the address of the new one.
  for (auto toSmash : rec->mainCallers()) {
    smashCall(toSmash, start);
  }

  // If the prologue has a matching guard, then smash its guard-callers as
  // well.
  auto const guard = funcGuardFromPrologue(start, func);
  if (funcGuardMatches(guard, func)) {
    for (auto toSmash : rec->guardCallers()) {
      smashCall(toSmash, guard);
    }
  }
  rec->clearAllCallers();

  // If this prologue has a DV funclet, then invalidate it and return its SrcKey
  // and TransID
  if (nArgs < func->numNonVariadicParams()) {
    auto paramInfo = func->params()[nArgs];
    if (paramInfo.hasDefaultValue()) {
      SrcKey funcletSK(func, paramInfo.funcletOff, false);
      auto funcletTransId = profData()->dvFuncletTransId(func, nArgs);
      if (funcletTransId != kInvalidTransID) {
        invalidateSrcKey(funcletSK);
        return std::make_pair(funcletSK, funcletTransId);
      }
    }
  }

  return folly::none;
}