Esempio n. 1
0
QModelIndex QgsLayerTreeModel::index( int row, int column, const QModelIndex &parent ) const
{
  if ( column != 0 || row < 0 || row >= rowCount( parent ) )
    return QModelIndex();

  QgsLayerTreeNode* n = index2node( parent );

  if ( !n )
  {
    QgsLayerTreeModelLegendNode* sym = index2symnode( parent );
    Q_ASSERT( sym );
    return QModelIndex(); // have no children
  }

  if ( !n || column != 0 || row >= rowCount( parent ) )
    return QModelIndex();

  if ( testFlag( ShowSymbology ) && QgsLayerTree::isLayer( n ) )
  {
    QgsLayerTreeLayer* nL = QgsLayerTree::toLayer( n );
    Q_ASSERT( mSymbologyNodes.contains( nL ) );
    return createIndex( row, column, static_cast<QObject*>( mSymbologyNodes[nL].at( row ) ) );
  }

  return createIndex( row, column, static_cast<QObject*>( n->children().at( row ) ) );
}
Esempio n. 2
0
QModelIndex QgsLayerTreeModel::parent( const QModelIndex &child ) const
{
  if ( !child.isValid() )
    return QModelIndex();

  QgsLayerTreeNode* n = index2node( child );

  QgsLayerTreeNode* parentNode = 0;

  if ( !n )
  {
    QgsLayerTreeModelLegendNode* sym = index2symnode( child );
    Q_ASSERT( sym );
    parentNode = sym->parent();
  }
  else
    parentNode = n->parent(); // must not be null
  Q_ASSERT( parentNode );

  QgsLayerTreeNode* grandParentNode = parentNode->parent();
  if ( !grandParentNode )
    return QModelIndex();  // root node -> invalid index

  int row = grandParentNode->children().indexOf( parentNode );
  Q_ASSERT( row >= 0 );
  return createIndex( row, 0, static_cast<QObject*>( parentNode ) );
}
Esempio n. 3
0
QModelIndex QgsLayerTreeModel::indexOfParentLayerTreeNode( QgsLayerTreeNode* parentNode ) const
{
    Q_ASSERT( parentNode );

    QgsLayerTreeNode* grandParentNode = parentNode->parent();
    if ( !grandParentNode )
        return QModelIndex();  // root node -> invalid index

    int row = grandParentNode->children().indexOf( parentNode );
    Q_ASSERT( row >= 0 );

    return createIndex( row, 0, static_cast<QObject*>( parentNode ) );
}
Esempio n. 4
0
void QgsLayerTreeView::modelRowsInserted( QModelIndex index, int start, int end )
{
  QgsLayerTreeNode* parentNode = layerTreeModel()->index2node( index );
  if ( !parentNode )
    return;

  if ( QgsLayerTree::isLayer( parentNode ) )
    return; // layers have only symbology nodes (no expanded/collapsed handling)

  QList<QgsLayerTreeNode*> children = parentNode->children();
  for ( int i = start; i <= end; ++i )
  {
    updateExpandedStateFromNode( children[i] );
  }

  // make sure we still have correct current layer
  onCurrentChanged();
}
Esempio n. 5
0
int QgsLayerTreeModel::rowCount( const QModelIndex &parent ) const
{
    if ( QgsLayerTreeModelLegendNode* nodeLegend = index2legendNode( parent ) )
        return legendNodeRowCount( nodeLegend );

    QgsLayerTreeNode* n = index2node( parent );
    if ( !n )
        return 0;

    if ( QgsLayerTree::isLayer( n ) )
    {
        if ( !testFlag( ShowLegend ) )
            return 0;

        return legendRootRowCount( QgsLayerTree::toLayer( n ) );
    }

    return n->children().count();
}
Esempio n. 6
0
QModelIndex QgsLayerTreeModel::index( int row, int column, const QModelIndex &parent ) const
{
    if ( column < 0 || column >= columnCount( parent ) ||
            row < 0 || row >= rowCount( parent ) )
        return QModelIndex();

    if ( QgsLayerTreeModelLegendNode* nodeLegend = index2legendNode( parent ) )
        return legendNodeIndex( row, column, nodeLegend );

    QgsLayerTreeNode *n = index2node( parent );
    if ( !n )
        return QModelIndex(); // have no children

    if ( testFlag( ShowLegend ) && QgsLayerTree::isLayer( n ) )
    {
        return legendRootIndex( row, column, QgsLayerTree::toLayer( n ) );
    }

    return createIndex( row, column, static_cast<QObject*>( n->children().at( row ) ) );
}
Esempio n. 7
0
int QgsLayerTreeModel::rowCount( const QModelIndex &parent ) const
{
  if ( index2symnode( parent ) )
  {
    return 0; // they are leaves
  }

  QgsLayerTreeNode* n = index2node( parent );

  if ( parent.isValid() && parent.column() != 0 )
    return 0;

  if ( QgsLayerTree::isLayer( n ) )
  {
    QgsLayerTreeLayer* nL = QgsLayerTree::toLayer( n );

    return mSymbologyNodes[nL].count();
  }

  return n->children().count();
}
Esempio n. 8
0
int QgsLayerTreeModel::rowCount( const QModelIndex &parent ) const
{
  if ( index2legendNode( parent ) )
    return 0; // they are leaves

  QgsLayerTreeNode* n = index2node( parent );
  if ( !n )
    return 0;

  if ( QgsLayerTree::isLayer( n ) )
  {
    if ( !testFlag( ShowLegend ) )
      return 0;

    QgsLayerTreeLayer* nL = QgsLayerTree::toLayer( n );
    if ( mLegendNodes[nL].count() == 1 && mLegendNodes[nL][0]->isEmbeddedInParent() )
      return 0;

    return mLegendNodes[nL].count();
  }

  return n->children().count();
}
Esempio n. 9
0
int QgsLayerTreeModel::rowCount( const QModelIndex &parent ) const
{
  if ( index2legendNode( parent ) )
  {
    return 0; // they are leaves
  }

  QgsLayerTreeNode* n = index2node( parent );

  if ( parent.isValid() && parent.column() != 0 )
    return 0;

  if ( QgsLayerTree::isLayer( n ) )
  {
    QgsLayerTreeLayer* nL = QgsLayerTree::toLayer( n );

    if ( mLegendNodes[nL].count() == 1 && mLegendNodes[nL][0]->isEmbeddedInParent() )
      return 0;

    return mLegendNodes[nL].count();
  }

  return n->children().count();
}