示例#1
0
void OSLineEdit2::onEditingFinished() {
  if (m_modelObject && (m_set || m_setOptionalStringReturn || m_setVoidReturn)) {
    if (m_text != this->text().toStdString()) {
      m_text = this->text().toStdString();
      auto result = false;
      if (m_set) {
        result = (*m_set)(m_text);
      }
      else if (m_setOptionalStringReturn) {
        auto optionalStringReturn = (*m_setOptionalStringReturn)(m_text);
        if (optionalStringReturn) {
          result = true; // TODO
        }
        result = true;
      }
      else if (m_setVoidReturn) {
        (*m_setVoidReturn)(m_text);
        result = true;
      }
      if (!result){
        //restore
        onModelObjectChange();
      }
      else {
        emit inFocus(true, hasData());
        adjustWidth();
      }
    }
  }
}
示例#2
0
void OSDoubleEdit2::completeBind() {

  // only let one of autosize/autocalculate
  if ((m_isAutosized && m_isAutocalculated) || 
      (m_isAutosized && m_autocalculate) || 
      (m_isAutocalculated && m_autosize)) 
  {
    LOG_AND_THROW("A field can only be autosized or autocalculated, it cannot be both.");
  }

  setEnabled(true);

  bool isConnected = false;
  isConnected = connect( this, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()) );
  OS_ASSERT(isConnected);

  isConnected = connect( m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(),SIGNAL(onChange()),
                         this,SLOT(onModelObjectChange()) );
  OS_ASSERT(isConnected);

  isConnected = connect( m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(),SIGNAL(onRemoveFromWorkspace(Handle)),
                         this,SLOT(onModelObjectRemove(Handle)) );
  OS_ASSERT(isConnected);

  refreshTextAndLabel();
}
示例#3
0
void OSCheckBox2::bind(model::ModelObject & modelObject,
                       BoolGetter get,
                       boost::optional<BoolSetter> set,
                       boost::optional<NoFailAction> reset,
                       boost::optional<BasicQuery> isDefaulted)
{
  m_modelObject = modelObject;
  m_get = get;
  m_set = set;
  m_reset = reset;
  m_isDefaulted = isDefaulted;

  setEnabled(true);

  connect( m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(),SIGNAL(onChange()),
           this,SLOT(onModelObjectChange()) );

  connect( m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(),SIGNAL(onRemoveFromWorkspace(Handle)),
           this,SLOT(onModelObjectRemove(Handle)) );

  connect( this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)) );

  bool checked = (*m_get)();

  this->setChecked(checked);
}
void OSLoadNamePixmapLineEdit::completeBind() {

  setIcon();

  bool isConnected = false;

  isConnected = connect( m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(),SIGNAL(onChange()),
                         this,SLOT(onModelObjectChange()) );
  OS_ASSERT(isConnected);
}
示例#5
0
void OSLineEdit2::onEditingFinished() {
  if(m_modelObject && m_set) {
    if (m_text != this->text().toStdString()) {
      m_text = this->text().toStdString();
      bool result = (*m_set)(m_text);
      if (!result){
        //restore
        onModelObjectChange();
      }
      else {
        adjustWidth();
      }
    }
  }
}
示例#6
0
void OSLineEdit::bind(model::ModelObject & modelObject, const char * property)
{
  m_modelObject = modelObject;

  m_property = property;

  setEnabled(true);

  connect(m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(), &openstudio::model::detail::ModelObject_Impl::onChange, this, &OSLineEdit::onModelObjectChange);

  connect(m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(), &openstudio::model::detail::ModelObject_Impl::onRemoveFromWorkspace, this, &OSLineEdit::onModelObjectRemove);

  connect(this, &OSLineEdit::editingFinished, this, &OSLineEdit::onEditingFinished);

  onModelObjectChange();
}
示例#7
0
void OSDoubleEdit::bind(model::ModelObject& modelObject,
                          const char* property,
                          const boost::optional<std::string>& isDefaultedProperty,
                          const boost::optional<std::string>& isAutosizedProperty,
                          const boost::optional<std::string>& isAutocalculatedProperty)
{
  m_modelObject = modelObject;
  m_property = property;
  m_isDefaultedProperty = isDefaultedProperty;
  m_isAutosizedProperty = isAutosizedProperty;
  m_isAutocalculatedProperty = isAutocalculatedProperty;

  // only let one of autosize/autocalculate
  if (isAutosizedProperty && isAutocalculatedProperty) {
    LOG_AND_THROW("A field can only be autosized or autocalculated, it cannot be both.");
  }

  // check for attribute existence
  StringVector attributeNames = modelObject.attributeNames();
  StringVector::const_iterator anb(attributeNames.begin()),ane(attributeNames.end());
  BOOST_ASSERT(std::find(anb,ane,m_property) != ane);
  if (m_isDefaultedProperty) {
    BOOST_ASSERT(std::find(anb,ane,*m_isDefaultedProperty) != ane);
  }
  if (m_isAutosizedProperty) {
    BOOST_ASSERT(std::find(anb,ane,*m_isAutosizedProperty) != ane);
  }
  if (m_isAutocalculatedProperty) {
    BOOST_ASSERT(std::find(anb,ane,*m_isAutocalculatedProperty) != ane);
  }

  setEnabled(true);

  bool isConnected = false;
  isConnected = connect( this, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()) );
  BOOST_ASSERT(isConnected);

  isConnected = connect( m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(),SIGNAL(onChange()),
                         this,SLOT(onModelObjectChange()) );
  BOOST_ASSERT(isConnected);

  isConnected = connect( m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(),SIGNAL(onRemoveFromWorkspace(Handle)),
                         this,SLOT(onModelObjectRemove(Handle)) );
  BOOST_ASSERT(isConnected);

  refreshTextAndLabel();
}
示例#8
0
void OSCheckBox::bind(model::ModelObject & modelObject, const char * property)
{
  m_modelObject = modelObject;

  m_property = property;

  setEnabled(true);

  connect( m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(),SIGNAL(onChange()),
           this,SLOT(onModelObjectChange()) );

  connect( m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(),SIGNAL(onRemoveFromWorkspace(Handle)),
           this,SLOT(onModelObjectRemove(Handle)) );

  connect( this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)) );

  bool checked = m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>()->property(m_property.c_str()).toBool();

  this->setChecked(checked);
}