void OSIntegerEdit2::onEditingFinished() { emit inFocus(true, hasData()); QString text = this->text(); if (text.isEmpty() || m_text == text) return; if (m_modelObject) { std::string str = this->text().toStdString(); boost::regex autore("[aA][uU][tT][oO]"); ModelObject modelObject = m_modelObject.get(); if (str.empty()) { if (m_reset) { (*m_reset)(); } } else if (boost::regex_search(str,autore)) { if (m_isAutosized) { if (m_autosize) { (*m_autosize)(); } else if (m_reset) { (*m_reset)(); } } if (m_isAutocalculated) { if (m_autocalculate) { (*m_autocalculate)(); } else if (m_reset) { (*m_reset)(); } } } else { try { int value = boost::lexical_cast<int>(str); setPrecision(str); if (m_set) { QString text = this->text(); if (text.isEmpty() || m_text == text) return; bool result = (*m_set)(value); if (!result){ //restore refreshTextAndLabel(); } } } catch (...) { // restore refreshTextAndLabel(); } } } }
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(); }
void OSIntegerEdit2::onModelObjectChange() { if (m_modelExtensibleGroup){ if (m_modelExtensibleGroup->empty()){ // this is equivalent to onModelObjectRemove for the extensible group unbind(); return; } } refreshTextAndLabel(); }
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(); }
void OSIntegerEdit2::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); connect(this, &OSIntegerEdit2::editingFinished, this, &OSIntegerEdit2::onEditingFinished); connect(m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(), &openstudio::model::detail::ModelObject_Impl::onChange, this, &OSIntegerEdit2::onModelObjectChange); connect(m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(), &openstudio::model::detail::ModelObject_Impl::onRemoveFromWorkspace, this, &OSIntegerEdit2::onModelObjectRemove); refreshTextAndLabel(); }
void OSIntegerEdit::onModelObjectChange() { refreshTextAndLabel(); }
void OSDoubleEdit::onModelObjectChange() { refreshTextAndLabel(); }
void OSUnsignedEdit::onModelObjectChange() { refreshTextAndLabel(); }