コード例 #1
0
Qt::ItemFlags QgsLegendModel::flags( const QModelIndex &index ) const
{
    Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    if ( !index.isValid() )
    {
        flags |= Qt::ItemIsDropEnabled;
        return flags;
    }

    QStandardItem* item = itemFromIndex( index );
    QgsComposerLegendItem* cItem = dynamic_cast<QgsComposerLegendItem*>( item );

    if ( cItem )
    {
        QgsComposerLegendItem::ItemType type = cItem->itemType();
        if ( type == QgsComposerLegendItem::GroupItem )
        {
            flags |= Qt::ItemIsDragEnabled;
            flags |= Qt::ItemIsDropEnabled;
        }
        else if ( type == QgsComposerLegendItem::LayerItem )
        {
            flags |= Qt::ItemIsDragEnabled;
        }
    }
    if ( index.column() == 1 && item )
    {
        // Style
        QStandardItem* firstColumnItem = 0;
        if ( item->parent() )
        {
            firstColumnItem = item->parent()->child( index.row(), 0 );
        }
        else
        {
            firstColumnItem = QgsLegendModel::item( index.row(), 0 );
        }
        cItem = dynamic_cast<QgsComposerLegendItem*>( firstColumnItem );

        if ( cItem )
        {
            if ( cItem->itemType() == QgsComposerLegendItem::GroupItem ||
                    cItem->itemType() == QgsComposerLegendItem::LayerItem )
            {
                flags |= Qt::ItemIsEditable;
            }
        }
    }
    return flags;
}
コード例 #2
0
Qt::ItemFlags QgsLegendModel::flags( const QModelIndex &index ) const
{
  Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
  if ( !index.isValid() )
  {
    flags |= Qt::ItemIsDropEnabled;
    return flags;
  }

  QStandardItem* item = itemFromIndex( index );
  QgsComposerLegendItem* cItem = dynamic_cast<QgsComposerLegendItem*>( item );

  if ( cItem )
  {
    QgsComposerLegendItem::ItemType type = cItem->itemType();
    if ( type == QgsComposerLegendItem::GroupItem )
    {
      flags |= Qt::ItemIsDragEnabled;
      flags |= Qt::ItemIsDropEnabled;
    }
    else if ( type == QgsComposerLegendItem::LayerItem )
    {
      flags |= Qt::ItemIsDragEnabled;
    }
  }
  return flags;
}
コード例 #3
0
void QgsLegendModel::updateItem( QStandardItem* item )
{
  if ( !item )
  {
    return;
  }

  //only layer items are supported for update
  QgsComposerLegendItem* cItem = dynamic_cast<QgsComposerLegendItem*>( item );
  if ( ! cItem )
  {
    return;
  }

  QgsComposerLegendItem::ItemType type = cItem->itemType();
  if ( type == QgsComposerLegendItem::LayerItem )
  {
    updateLayer( cItem );
  }
}
コード例 #4
0
void QgsComposerLegend::drawGroupItem( QPainter* p, QgsComposerGroupItem* groupItem, double& currentYCoord, double& maxXCoord )
{
  if ( !p || !groupItem )
  {
    return;
  }

  currentYCoord += mLayerSpace;
  currentYCoord += fontAscentMillimeters( mGroupFont );

  p->setPen( QColor( 0, 0, 0 ) );
  drawText( p, mBoxSpace, currentYCoord, groupItem->text(), mGroupFont );

  //maximum x-coordinate of current item
  double currentMaxXCoord = 2 * mBoxSpace + textWidthMillimeters( mGroupFont, groupItem->text() );
  maxXCoord = qMax( currentMaxXCoord, maxXCoord );

  //children can be other group items or layer items
  int numChildItems = groupItem->rowCount();
  QStandardItem* currentChildItem = 0;

  for ( int i = 0; i < numChildItems; ++i )
  {
    currentChildItem = groupItem->child( i );
    QgsComposerLegendItem* currentLegendItem = dynamic_cast<QgsComposerLegendItem*>( currentChildItem );
    QgsComposerLegendItem::ItemType type = currentLegendItem->itemType();
    if ( type == QgsComposerLegendItem::GroupItem )
    {
      drawGroupItem( p, dynamic_cast<QgsComposerGroupItem*>( currentLegendItem ), currentYCoord, currentMaxXCoord );
      maxXCoord = qMax( currentMaxXCoord, maxXCoord );
    }
    else if ( type == QgsComposerLegendItem::LayerItem )
    {
      drawLayerItem( p, dynamic_cast<QgsComposerLayerItem*>( currentLegendItem ), currentYCoord, currentMaxXCoord );
      maxXCoord = qMax( currentMaxXCoord, maxXCoord );
    }
  }
}
コード例 #5
0
QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
{
  QSizeF size;
  double maxXCoord = 0;



  //go through model...
  QStandardItem* rootItem = mLegendModel.invisibleRootItem();
  if ( !rootItem )
  {
    return size;
  }


  if ( painter )
  {
    painter->save();
    drawBackground( painter );
    painter->setPen( QPen( QColor( 0, 0, 0 ) ) );
  }

  int numLayerItems = rootItem->rowCount();
  QStandardItem* currentLayerItem = 0;
  double currentYCoordinate = mBoxSpace;

  //font metrics

  //draw title
  currentYCoordinate += fontAscentMillimeters( mTitleFont );
  if ( painter )
  {
    painter->setPen( QColor( 0, 0, 0 ) );
    drawText( painter, mBoxSpace, currentYCoordinate, mTitle, mTitleFont );
  }

  maxXCoord = 2 * mBoxSpace + textWidthMillimeters( mTitleFont, mTitle );

  double currentItemMaxX = 0; //maximum x-coordinate for current item
  for ( int i = 0; i < numLayerItems; ++i )
  {
    currentLayerItem = rootItem->child( i );
    QgsComposerLegendItem* currentLegendItem = dynamic_cast<QgsComposerLegendItem*>( currentLayerItem );
    if ( currentLegendItem )
    {
      QgsComposerLegendItem::ItemType type = currentLegendItem->itemType();
      if ( type == QgsComposerLegendItem::GroupItem )
      {
        drawGroupItem( painter, dynamic_cast<QgsComposerGroupItem*>( currentLegendItem ), currentYCoordinate, currentItemMaxX );
        maxXCoord = qMax( maxXCoord, currentItemMaxX );
      }
      else if ( type == QgsComposerLegendItem::LayerItem )
      {
        drawLayerItem( painter, dynamic_cast<QgsComposerLayerItem*>( currentLegendItem ), currentYCoordinate, currentItemMaxX );
        maxXCoord = qMax( maxXCoord, currentItemMaxX );
      }
    }
  }

  currentYCoordinate += mBoxSpace;

  size.setHeight( currentYCoordinate );
  size.setWidth( maxXCoord );

  //adjust box if width or height is to small
  if ( painter && currentYCoordinate > rect().height() )
  {
    setSceneRect( QRectF( transform().dx(), transform().dy(), rect().width(), currentYCoordinate ) );
  }
  if ( painter && maxXCoord > rect().width() )
  {
    setSceneRect( QRectF( transform().dx(), transform().dy(), maxXCoord, rect().height() ) );
  }

  if ( painter )
  {
    painter->restore();

    //draw frame and selection boxes if necessary
    drawFrame( painter );
    if ( isSelected() )
    {
      drawSelectionBoxes( painter );
    }
  }

  return size;
}