Beispiel #1
0
void OSComboBox::bind(model::ModelObject & modelObject, const char * property)
{
  m_modelObject = modelObject;

  m_property = property;

  m_dataSource.reset();

  clear();

  // Connections

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

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

  isConnected = connect( this, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(onCurrentIndexChanged(const QString&)) );
  OS_ASSERT(isConnected);

  // Populate choices

  std::string valuesPropertyName = m_property;
  valuesPropertyName.append("Values");

  QVariant variant = m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>()->property(valuesPropertyName.c_str());

  OS_ASSERT( variant.canConvert<std::vector<std::string> >() );

  m_values = variant.value<std::vector<std::string> >();

  this->blockSignals(true);

  for( std::vector<std::string>::iterator it = m_values.begin();
       it < m_values.end();
       it++ )
  {
    addItem(QString::fromStdString(*it));
  }

  // Initialize

  onModelObjectChanged();

  this->blockSignals(false);

  setEnabled(true);
}
Beispiel #2
0
void OSComboBox2::onCurrentIndexChanged(const QString & text)
{
  OS_ASSERT(m_modelObject);
  OS_ASSERT(m_set); // should only be enabled if there is a setter

  std::string value = text.toStdString();
  (*m_set)(value);

  // test if property changed
  OptionalString oValue;
  if (m_get) {
    oValue = (*m_get)();
  }
  else {
    OS_ASSERT(m_getOptional);
    oValue = (*m_getOptional)();
  }
  std::string actualValue;
  if (oValue) {
    actualValue = *oValue;
  }

  if (!istringEqual(actualValue, value)) {
    // failed, reset combo box
    onModelObjectChanged();
  }
}
Beispiel #3
0
void OSComboBox2::completeBind() {
  OS_ASSERT(m_modelObject);
  OS_ASSERT(m_choices);

  // Connections

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

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

  isConnected = connect( this, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(onCurrentIndexChanged(const QString&)) );
  OS_ASSERT(isConnected);

  // Populate choices
  m_values = (*m_choices)();
  if (m_getOptional) {
    // can be blank
    m_values.insert(m_values.begin(),std::string());
  }

  this->blockSignals(true);

  for( std::vector<std::string>::iterator it = m_values.begin();
       it < m_values.end();
       it++ )
  {
    addItem(QString::fromStdString(*it));
  }

  // Initialize

  onModelObjectChanged();

  this->blockSignals(false);

  setEnabled(true);
}
Beispiel #4
0
void OSComboBox2::onEditTextChanged(const QString & text)
{
  OS_ASSERT(m_modelObject);

  if( m_choiceConcept )
  {
    std::string value = text.toStdString();

    this->blockSignals(true);
    m_choiceConcept->set(value);
    onModelObjectChanged(); // will be sure to display actual value
    this->blockSignals(false);
  }
}
Beispiel #5
0
void OSComboBox2::completeBind() {
  if (m_modelObject) {
    // connections
    connect(m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>().get(), &openstudio::model::detail::ModelObject_Impl::onChange, this, &OSComboBox2::onModelObjectChanged);

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

    connect(this, static_cast<void (OSComboBox2::*)(const QString &)>(&OSComboBox2::currentIndexChanged), this, &OSComboBox2::onCurrentIndexChanged);

    bool isConnected = false;

    if (isEditable())
    {
      isConnected = connect(this, SIGNAL(editTextChanged(const QString&)), this, SLOT(onEditTextChanged(const QString&)));
      OS_ASSERT(isConnected);
    }

    // isConnected = connect( m_modelObject->model().getImpl<openstudio::model::detail::Model_Impl>().get(),
    //                        SIGNAL(addWorkspaceObject(const WorkspaceObject&, const openstudio::IddObjectType&, const openstudio::UUID&)),
    //                        this,
    //                        SLOT(onChoicesRefreshTrigger()) );
    // OS_ASSERT(isConnected);

    // isConnected = connect( m_modelObject->model().getImpl<openstudio::model::detail::Model_Impl>().get(),
    //                        SIGNAL(removeWorkspaceObject(const WorkspaceObject&, const openstudio::IddObjectType&, const openstudio::UUID&)),
    //                        this,
    //                        SLOT(onChoicesRefreshTrigger()) );
    // OS_ASSERT(isConnected);

    // if this is too burdensome, implement Workspace_Impl onNameChange() signal and uncomment the above two connections.
    // (IdfObject_Impl already has onNameChange(); Workspace_Impl::onChange() includes object addition and removal.)
    connect(m_modelObject->model().getImpl<openstudio::model::detail::Model_Impl>().get(), &openstudio::model::detail::Model_Impl::onChange, this, &OSComboBox2::onChoicesRefreshTrigger);

    // populate choices
    // ETH@20140228 - With extension of this class to choices of ModelObjects, and beyond,
    // do we need to figure out some way to signal when the choices have changed? Or maybe
    // controllers will be able to sense that and trigger an unbind(), (re-)bind?
    m_values = m_choiceConcept->choices();
    this->blockSignals(true);

    for( const auto & value : m_values )
    {
      addItem(QString::fromStdString(value));
    }

    // initialize
    onModelObjectChanged();
  }
  else if (m_dataSource) {
Beispiel #6
0
void OSComboBox2::onCurrentIndexChanged(const QString & text)
{
  emit inFocus(true, hasData());

  OS_ASSERT(m_modelObject);

  if( m_choiceConcept )
  {
    std::string value = text.toStdString();

    this->blockSignals(true);
    m_choiceConcept->set(value);
    onModelObjectChanged(); // will be sure to display actual value
    this->blockSignals(false);
  }
}
Beispiel #7
0
void OSComboBox2::onChoicesRefreshTrigger() {
  if( m_choiceConcept )
  {
    m_values = m_choiceConcept->choices();
    this->blockSignals(true);

    clear();
    for( const auto & value : m_values )
    {
      addItem(QString::fromStdString(value));
    }

    // re-initialize
    onModelObjectChanged();

    this->blockSignals(false);
    setEnabled(true);
  }
}
Beispiel #8
0
void OSComboBox::onCurrentIndexChanged(const QString & text)
{
  OS_ASSERT(m_modelObject);

  // does this version ever work?
  bool test = m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>()->setProperty(m_property.c_str(),text);

  if (!test){
    // try a std::string
    QVariant textString = QVariant::fromValue(toString(text));
    test = m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>()->setProperty(m_property.c_str(),textString);
  }

  // test if property changed
  QVariant variant = m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>()->property(m_property.c_str());
  OS_ASSERT( variant.canConvert<std::string>() );
  std::string value = variant.value<std::string>();

  if (!istringEqual(value, toString(text))){
    // failed, reset combo box
    onModelObjectChanged();
  }
}