Пример #1
0
void QgsGraduatedSymbolRendererWidget::on_methodComboBox_currentIndexChanged( int idx )
{
  toggleMethodWidgets( idx );
  if ( idx == 0 )
  {
    mRenderer->setGraduatedMethod( QgsGraduatedSymbolRenderer::GraduatedColor );
    QgsColorRamp* ramp = btnColorRamp->colorRamp();

    if ( !ramp )
    {
      QMessageBox::critical( this, tr( "Error" ), tr( "No color ramp defined." ) );
      return;
    }
    mRenderer->setSourceColorRamp( ramp );
    reapplyColorRamp();
  }
  else
  {
    lblColorRamp->setVisible( false );
    btnColorRamp->setVisible( false );
    lblSize->setVisible( true );
    minSizeSpinBox->setVisible( true );
    lblSize->setVisible( true );
    maxSizeSpinBox->setVisible( true );
    mSizeUnitWidget->setVisible( true );

    mRenderer->setGraduatedMethod( QgsGraduatedSymbolRenderer::GraduatedSize );
    reapplySizes();
  }
}
Пример #2
0
void QgsGraduatedSymbolRendererWidget::updateUiFromRenderer( bool updateCount )
{
  disconnectUpdateHandlers();

  updateGraduatedSymbolIcon();

  // update UI from the graduated renderer (update combo boxes, view)
  if ( mRenderer->mode() < cboGraduatedMode->count() )
    cboGraduatedMode->setCurrentIndex( mRenderer->mode() );

  // Only update class count if different - otherwise typing value gets very messy
  int nclasses = mRenderer->ranges().count();
  if ( nclasses && updateCount )
    spinGraduatedClasses->setValue( mRenderer->ranges().count() );

  // set column
  QString attrName = mRenderer->classAttribute();
  mExpressionWidget->setField( attrName );
  mHistogramWidget->setSourceFieldExp( attrName );

  // set source symbol
  if ( mRenderer->sourceSymbol() )
  {
    delete mGraduatedSymbol;
    mGraduatedSymbol = mRenderer->sourceSymbol()->clone();
    updateGraduatedSymbolIcon();
  }

  mModel->setRenderer( mRenderer );
  viewGraduated->setModel( mModel );

  if ( mGraduatedSymbol )
  {
    mSizeUnitWidget->blockSignals( true );
    mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
    mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
    mSizeUnitWidget->blockSignals( false );
  }

  // set source color ramp
  methodComboBox->blockSignals( true );
  if ( mRenderer->graduatedMethod() == QgsGraduatedSymbolRenderer::GraduatedColor )
  {
    methodComboBox->setCurrentIndex( 0 );
    if ( mRenderer->sourceColorRamp() )
    {
      btnColorRamp->setColorRamp( mRenderer->sourceColorRamp() );
    }
  }
  else
  {
    methodComboBox->setCurrentIndex( 1 );
    if ( !mRenderer->ranges().isEmpty() ) // avoid overiding default size with zeros
    {
      minSizeSpinBox->setValue( mRenderer->minSymbolSize() );
      maxSizeSpinBox->setValue( mRenderer->maxSymbolSize() );
    }
  }
  toggleMethodWidgets( methodComboBox->currentIndex() );
  methodComboBox->blockSignals( false );

  QgsRendererRangeLabelFormat labelFormat = mRenderer->labelFormat();
  txtLegendFormat->setText( labelFormat.format() );
  spinPrecision->setValue( labelFormat.precision() );
  cbxTrimTrailingZeroes->setChecked( labelFormat.trimTrailingZeroes() );

  viewGraduated->resizeColumnToContents( 0 );
  viewGraduated->resizeColumnToContents( 1 );
  viewGraduated->resizeColumnToContents( 2 );

  mHistogramWidget->refresh();

  connectUpdateHandlers();
  emit widgetChanged();
}
void QgsGraduatedSymbolRendererWidget::updateUiFromRenderer( bool updateCount )
{
  disconnectUpdateHandlers();
  updateGraduatedSymbolIcon();
  spinSymmetryPointForOtherMethods->setShowClearButton( false );

  // update UI from the graduated renderer (update combo boxes, view)
  if ( cboGraduatedMode->findData( mRenderer->mode() ) >= 0 )
  {
    cboGraduatedMode->setCurrentIndex( cboGraduatedMode->findData( mRenderer->mode() ) );
  }

  // symmetric classification
  const QgsGraduatedSymbolRenderer::Mode cboMode = static_cast< QgsGraduatedSymbolRenderer::Mode >( cboGraduatedMode->currentData().toInt() );
  switch ( cboMode )
  {
    case QgsGraduatedSymbolRenderer::EqualInterval:
    case QgsGraduatedSymbolRenderer::StdDev:
    {
      mGroupBoxSymmetric->setVisible( true );
      cbxAstride->setVisible( true );
      cboSymmetryPointForPretty->setVisible( false );
      spinSymmetryPointForOtherMethods->setVisible( true );
      spinSymmetryPointForOtherMethods->setValue( mRenderer->symmetryPoint() );
      break;
    }

    case QgsGraduatedSymbolRenderer::Pretty:
    {
      mGroupBoxSymmetric->setVisible( true );
      cbxAstride->setVisible( true );
      spinSymmetryPointForOtherMethods->setVisible( false );
      cboSymmetryPointForPretty->setVisible( true );
      cboSymmetryPointForPretty->clear();
      cboSymmetryPointForPretty->addItems( mRenderer->listForCboPrettyBreaks() );
      // replace the combobox on the good old value
      cboSymmetryPointForPretty->setCurrentText( QString::number( mRenderer->symmetryPoint(), 'f', 2 ) );
      break;
    }

    case QgsGraduatedSymbolRenderer::Quantile:
    case QgsGraduatedSymbolRenderer::Jenks:
    case QgsGraduatedSymbolRenderer::Custom:
    {
      mGroupBoxSymmetric->setVisible( false );
      cbxAstride->setVisible( false );
      cboSymmetryPointForPretty->setVisible( false );
      spinSymmetryPointForOtherMethods->setVisible( false );
      spinSymmetryPointForOtherMethods->setValue( mRenderer->symmetryPoint() );
      break;
    }
  }

  if ( mRenderer->useSymmetricMode() )
  {
    mGroupBoxSymmetric->setChecked( true );
    spinSymmetryPointForOtherMethods->setEnabled( true );
    cbxAstride->setEnabled( true );
    cboSymmetryPointForPretty->setEnabled( true );
  }
  else
  {
    mGroupBoxSymmetric->setChecked( false );
    spinSymmetryPointForOtherMethods->setEnabled( false );
    cbxAstride->setEnabled( false );
    cboSymmetryPointForPretty->setEnabled( false );
  }

  if ( mRenderer->astride() )
    cbxAstride->setChecked( true );
  else
    cbxAstride->setChecked( false );

  // Only update class count if different - otherwise typing value gets very messy
  int nclasses = mRenderer->ranges().count();
  if ( nclasses && updateCount )
    spinGraduatedClasses->setValue( mRenderer->ranges().count() );

  // set column
  QString attrName = mRenderer->classAttribute();
  mExpressionWidget->setField( attrName );
  mHistogramWidget->setSourceFieldExp( attrName );

  // set source symbol
  if ( mRenderer->sourceSymbol() )
  {
    mGraduatedSymbol.reset( mRenderer->sourceSymbol()->clone() );
    updateGraduatedSymbolIcon();
  }

  mModel->setRenderer( mRenderer.get() );
  viewGraduated->setModel( mModel );

  if ( mGraduatedSymbol )
  {
    mSizeUnitWidget->blockSignals( true );
    mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
    mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
    mSizeUnitWidget->blockSignals( false );
  }

  // set source color ramp
  methodComboBox->blockSignals( true );
  if ( mRenderer->graduatedMethod() == QgsGraduatedSymbolRenderer::GraduatedColor )
  {
    methodComboBox->setCurrentIndex( 0 );
    if ( mRenderer->sourceColorRamp() )
    {
      btnColorRamp->setColorRamp( mRenderer->sourceColorRamp() );
    }
  }
  else
  {
    methodComboBox->setCurrentIndex( 1 );
    if ( !mRenderer->ranges().isEmpty() ) // avoid overriding default size with zeros
    {
      minSizeSpinBox->setValue( mRenderer->minSymbolSize() );
      maxSizeSpinBox->setValue( mRenderer->maxSymbolSize() );
    }
  }
  toggleMethodWidgets( methodComboBox->currentIndex() );
  methodComboBox->blockSignals( false );

  QgsRendererRangeLabelFormat labelFormat = mRenderer->labelFormat();
  txtLegendFormat->setText( labelFormat.format() );
  spinPrecision->setValue( labelFormat.precision() );
  cbxTrimTrailingZeroes->setChecked( labelFormat.trimTrailingZeroes() );

  viewGraduated->resizeColumnToContents( 0 );
  viewGraduated->resizeColumnToContents( 1 );
  viewGraduated->resizeColumnToContents( 2 );

  mHistogramWidget->refresh();

  connectUpdateHandlers();
  emit widgetChanged();
}