コード例 #1
0
 QVariant toQuantityQVariant(const QVariantMap& map,
                             const std::string& valueKey,
                             const std::string& unitsKey)
 {
   Quantity q = createQuantity(map[toQString(valueKey)].toDouble(),map[toQString(unitsKey)].toString().toStdString()).get();
   return QVariant::fromValue<openstudio::Quantity>(q);
 }
コード例 #2
0
bool OSArgument::setStringInternal(QVariant& variant, const std::string& value) {
  bool result = false;
  if (m_type == OSArgumentType::Boolean) {
    if (value == "true") {
      variant.setValue(QString("true"));
      result = true;
    }
    else if (value == "false") {
      variant.setValue(QString("false"));
      result = true;
    }
  } else if (m_type == OSArgumentType::Double) {
    bool test;
    double temp = toQString(value).toDouble(&test);
    if (test){
      variant.setValue(temp);
      result = true;
    }
  } else if (m_type == OSArgumentType::Quantity) {
    OptionalQuantity oq = createQuantity(value);
    if (oq) {
      variant = QVariant::fromValue<openstudio::Quantity>(*oq);
      result = true;
    }
  } else if (m_type == OSArgumentType::Integer) {
    bool test;
    int temp = toQString(value).toInt(&test);
    if (test){
      variant.setValue(temp);
      result = true;
    }
  } else if (m_type == OSArgumentType::String) {
    variant.setValue(toQString(value));
    result = true;
  } else if (m_type == OSArgumentType::Choice) {
    if (std::find(m_choices.begin(), m_choices.end(), value) != m_choices.end()){
      variant.setValue(toQString(value));
      result = true;
    } else {
      // can also set using display name
      StringVector::const_iterator it = std::find(m_choiceDisplayNames.begin(), m_choiceDisplayNames.end(), value);
      if (it != m_choiceDisplayNames.end()) {
        int index = int(it - m_choiceDisplayNames.begin());
        if (index < int(m_choices.size())) {
          variant.setValue(toQString(m_choices[index]));
          result = true;
        }
      }
    }
  } else if (m_type == OSArgumentType::Path) {
    QString temp = toQString(toPath(value));
    if (!temp.isEmpty()){
      variant.setValue(temp);
      result = true;
    }
  }
  return result;
}
コード例 #3
0
ファイル: QuantityFactory.cpp プロジェクト: NREL/OpenStudio
boost::optional<Quantity> QuantityFactorySingleton::createQuantity(const std::string& quantityString) const {
  OptionalQuantity result;
  StringPair strings = decomposeQuantityString(quantityString);
  try {
    double value = boost::lexical_cast<double>(strings.first);
    result = createQuantity(value,strings.second);
  }
  catch (...) {
    LOG(Error,"Unable to create quantity from string '" << quantityString << "'. Returning 0.0.");
  }
  return result;
}