Exemplo n.º 1
0
void OSIntegerEdit::refreshTextAndLabel() {
  if (m_modelObject) {
    QString textValue;
    ModelObject modelObject = m_modelObject.get();
    std::stringstream ss;

    if (m_isAutosizedProperty) {
      Attribute autosized = modelObject.getAttribute(*m_isAutosizedProperty).get();
      if (autosized.valueAsBoolean()) {
        textValue = QString("autosize");
      }
    }

    if (m_isAutocalculatedProperty) {
      Attribute autocalculated = modelObject.getAttribute(*m_isAutocalculatedProperty).get();
      if (autocalculated.valueAsBoolean()) {
        textValue = QString("autocalculate");
      }
    }

    OptionalAttribute attribute = modelObject.getAttribute(m_property);
    if (attribute) {
      int value = attribute->valueAsInteger();
      if (m_isScientific) {
        ss << std::scientific;
      }
      else {
        ss << std::fixed;
      }
      if (m_precision) {
        ss << std::setprecision(*m_precision);
      }
      ss << value;
      textValue = toQString(ss.str());
      ss.str("");
    }

    this->setText(textValue);

    if (m_isDefaultedProperty) {
      Attribute defaulted = modelObject.getAttribute(*m_isDefaultedProperty).get();
      if (defaulted.valueAsBoolean()) {
        this->setStyleSheet("color:green");
      }
      else {
        this->setStyleSheet("color:black");
      }
    }
  }
}
Exemplo n.º 2
0
TEST_F(ModelFixture, ModelObject_Attributes)
{
  Model model;

  OptionalWorkspaceObject oObject = model.addObject(IdfObject(IddObjectType::OS_Version));
  ASSERT_TRUE(oObject);
  ModelObject version = oObject->cast<ModelObject>();
  StringVector versionAttributeNames = version.attributeNames();
  ASSERT_EQ(static_cast<unsigned>(3),versionAttributeNames.size());
  EXPECT_EQ("iddObjectType",versionAttributeNames[0]);
  EXPECT_EQ("handle",versionAttributeNames[1]);
  EXPECT_EQ("name",versionAttributeNames[2]);

  EXPECT_FALSE(version.getAttribute("N a m e"));
}