QgsLegendLayerFile::QgsLegendLayerFile( QTreeWidgetItem * theLegendItem, QString theString, QgsMapLayer* theLayer )
    : QgsLegendItem( theLegendItem, theString ), mLyr( theLayer )
{
  // Set the initial visibility flag for layers
  // This user option allows the user to turn off inital drawing of
  // layers when they are added to the map. This is useful when adding
  // many layers and the user wants to adjusty symbology, etc prior to
  // actually viewing the layer.
  QSettings settings;
  bool visible = settings.value( "/qgis/new_layers_visible", true ).toBool();
  mLyr.setVisible( visible );

  // not in overview by default
  mLyr.setInOverview( FALSE );

  mType = LEGEND_LAYER_FILE;

  setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
  setCheckState( 0, Qt::Checked );
  setText( 0, theString );

  // Add check if vector layer when connecting to selectionChanged slot
  // Ticket #811 - racicot
  QgsMapLayer *currentLayer = mLyr.layer();
  QgsVectorLayer *isVectLyr = dynamic_cast < QgsVectorLayer * >( currentLayer );
  if ( isVectLyr )
  {
    connect( mLyr.layer(), SIGNAL( editingStarted() ), this, SLOT( updateLegendItem() ) );
    connect( mLyr.layer(), SIGNAL( editingStopped() ), this, SLOT( updateLegendItem() ) );
  }
  connect( mLyr.layer(), SIGNAL( layerNameChanged() ), this, SLOT( layerNameChanged() ) );
}
Esempio n. 2
0
/*!
  Set the identifier display policy of the legend.
  \param policy new policy.
  \param mode new mode.
  \sa QwtLegend::setDisplayPolicy, QwtLegend::LegendDisplayPolicy
*/
void QwtPlot::setLegendDisplayPolicy(
    QwtLegend::LegendDisplayPolicy policy, int mode)
{
    d_legend->setDisplayPolicy(policy, mode);
    
    for (QwtPlotCurveIterator iter=curveIterator(); iter.current(); ++iter)
        updateLegendItem(iter.currentKey());
}