Esempio n. 1
0
void DisplayGroup::addChild( Property* child, int index )
{
    Display* display = qobject_cast<Display*>( child );
    if( !display )
    {
        Display::addChild( child, index );
        return;
    }
    if( index < 0 || index > numChildren() )
    {
        index = numChildren();
    }
    int disp_index = index - Display::numChildren();
    if( disp_index < 0 )
    {
        disp_index = 0;
    }
    if( model_ )
    {
        model_->beginInsert( this, index );
    }

    displays_.insert( disp_index, display );
    Q_EMIT displayAdded( display );
    child_indexes_valid_ = false;
    display->setModel( model_ );
    display->setParent( this );

    if( model_ )
    {
        model_->endInsert();
    }
    Q_EMIT childListChanged( this );
}
Esempio n. 2
0
Display* DisplayGroup::takeDisplay( Display* child )
{
    Display* result = NULL;
    int num_displays = displays_.size();
    for( int i = 0; i < num_displays; i++ )
    {
        if( displays_.at( i ) == child )
        {
            if( model_ )
            {
                model_->beginRemove( this, Display::numChildren() + i, 1 );
            }
//      printf("  displaygroup3 displays_.takeAt( %d )\n", i );
            result = displays_.takeAt( i );
            Q_EMIT displayRemoved( result );
            result->setParent( NULL );
            result->setModel( NULL );
            child_indexes_valid_ = false;
            if( model_ )
            {
                model_->endRemove();
            }
            Q_EMIT childListChanged( this );
            break;
        }
    }
    return result;
}
Esempio n. 3
0
void Property::removeChildren( int start_index, int count )
{
  if( count < 0 )
  {
    count = children_.size() - start_index;
  }

  if( count == 0 )
    return;

  if( model_ )
  {
    model_->beginRemove( this, start_index, count );
  }
  // Destroy my children.
  for( int i = start_index; i < start_index + count; i++ )
  {
    Property* child = children_.at( i );
    child->setParent( NULL ); // prevent child destructor from calling getParent()->takeChild().
    delete child;
  }
  children_.erase( children_.begin() + start_index, children_.begin() + start_index + count );
  child_indexes_valid_ = false;
  if( model_ )
  {
    model_->endRemove();
  }
  Q_EMIT childListChanged( this );
}
Esempio n. 4
0
void Property::addChild( Property* child, int index )
{
  if( !child )
  {
    return;
  }
  int num_children = children_.size();
  if( index < 0 || index > num_children )
  {
    index = num_children;
  }
  if( model_ )
  {
    model_->beginInsert( this, index );
  }

  children_.insert( index, child );
  child_indexes_valid_ = false;
  child->setModel( model_ );
  child->parent_ = this;

  if( model_ )
  {
    model_->endInsert();
  }

  Q_EMIT childListChanged( this );
}
Esempio n. 5
0
void DisplayGroup::addDisplay( Display* child )
{
    if( model_ )
    {
        model_->beginInsert( this, numChildren(), 1 );
    }
    addDisplayWithoutSignallingModel( child );
    if( model_ )
    {
        model_->endInsert();
    }
    Q_EMIT childListChanged( this );
}
Esempio n. 6
0
Property* Property::takeChildAt( int index )
{
  if( index < 0 || index >= children_.size() )
  {
    return NULL;
  }
  if( model_ )
  {
    model_->beginRemove( this, index, 1 );
  }
  Property* child = children_.takeAt( index );
  child->setModel( NULL );
  child->parent_ = NULL;
  child_indexes_valid_ = false;
  if( model_ )
  {
    model_->endRemove();
  }
  Q_EMIT childListChanged( this );
  return child;
}
Esempio n. 7
0
void DisplayGroup::removeAllDisplays()
{
    int num_non_display_children = Display::numChildren();

    if( model_ )
    {
        model_->beginRemove( this, num_non_display_children, displays_.size() );
    }
    for( int i = displays_.size() - 1; i >= 0; i-- )
    {
//    printf("  displaygroup2 displays_.takeAt( %d )\n", i );
        Display* child = displays_.takeAt( i );
        Q_EMIT displayRemoved( child );
        child->setParent( NULL ); // prevent child destructor from calling getParent()->takeChild().
        delete child;
    }
    if( model_ )
    {
        model_->endRemove();
    }
    Q_EMIT childListChanged( this );
}
Esempio n. 8
0
Property* DisplayGroup::takeChildAt( int index )
{
    if( index < Display::numChildren() )
    {
        return Display::takeChildAt( index );
    }
    int disp_index = index - Display::numChildren();
    if( model_ )
    {
        model_->beginRemove( this, index, 1 );
    }
//  printf("  displaygroup5 displays_.takeAt( %d ) ( index = %d )\n", disp_index, index );
    Display* child = displays_.takeAt( disp_index );
    Q_EMIT displayRemoved( child );
    child->setModel( NULL );
    child->setParent( NULL );
    child_indexes_valid_ = false;
    if( model_ )
    {
        model_->endRemove();
    }
    Q_EMIT childListChanged( this );
    return child;
}
Esempio n. 9
0
void Property::moveChild( int from_index, int to_index )
{
  children_.move( from_index, to_index );
  child_indexes_valid_ = false;
  Q_EMIT childListChanged( this );
}