예제 #1
0
void QgsLabelingWidget::labelModeChanged( int index )
{
  if ( index < 0 )
    return;

  if ( index == 2 )
  {
    if ( mWidget )
      mStackedWidget->removeWidget( mWidget );

    delete mWidget;
    mWidget = nullptr;

    QgsRuleBasedLabelingWidget* ruleWidget = new QgsRuleBasedLabelingWidget( mLayer, mCanvas, this );
    ruleWidget->setDockMode( dockMode() );
    connect( ruleWidget, SIGNAL( showPanel( QgsPanelWidget* ) ), this, SLOT( openPanel( QgsPanelWidget* ) ) );
    connect( ruleWidget, SIGNAL( widgetChanged() ), this, SIGNAL( widgetChanged() ) );
    mWidget = ruleWidget;
    mStackedWidget->addWidget( mWidget );
    mStackedWidget->setCurrentWidget( mWidget );
  }
  else
  {

    if ( index == 3 )
예제 #2
0
void QgsLabelingWidget::labelModeChanged( int index )
{
  if ( mWidget )
    mStackedWidget->removeWidget( mWidget );

  delete mWidget;
  mWidget = nullptr;

  if ( index < 0 )
    return;

  if ( index == 2 )
  {
    QgsRuleBasedLabelingWidget *ruleWidget = new QgsRuleBasedLabelingWidget( mLayer, mCanvas, this );
    ruleWidget->setDockMode( dockMode() );
    connect( ruleWidget, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );
    connect( ruleWidget, &QgsRuleBasedLabelingWidget::widgetChanged, this, &QgsLabelingWidget::widgetChanged );
    mWidget = ruleWidget;
    mStackedWidget->addWidget( mWidget );
    mStackedWidget->setCurrentWidget( mWidget );
  }
  else if ( index == 1 || index == 3 )
  {
    if ( mLayer->labeling() && mLayer->labeling()->type() == QLatin1String( "simple" ) )
      mSimpleSettings.reset( new QgsPalLayerSettings( mLayer->labeling()->settings() ) );
    else
      mSimpleSettings.reset( new QgsPalLayerSettings() );

    QgsLabelingGui *simpleWidget = new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings, this );
    simpleWidget->setDockMode( dockMode() );
    connect( simpleWidget, &QgsTextFormatWidget::widgetChanged, this, &QgsLabelingWidget::widgetChanged );

    if ( index == 3 )
      simpleWidget->setLabelMode( QgsLabelingGui::ObstaclesOnly );
    else
      simpleWidget->setLabelMode( static_cast< QgsLabelingGui::LabelMode >( index ) );

    mWidget = simpleWidget;
    mStackedWidget->addWidget( mWidget );
    mStackedWidget->setCurrentWidget( mWidget );
  }
  emit widgetChanged();
}
void QgsPresetColorRampWidget::mButtonAddColor_clicked()
{
  if ( dockMode() )
  {
    mTreeColors->addColor( QgsRecentColorScheme::lastUsedColor(), QgsSymbolLayerUtils::colorToName( QgsRecentColorScheme::lastUsedColor() ), true );

    QgsCompoundColorWidget *colorWidget = new QgsCompoundColorWidget( this, QgsRecentColorScheme::lastUsedColor(), QgsCompoundColorWidget::LayoutVertical );
    colorWidget->setPanelTitle( tr( "Select Color" ) );
    colorWidget->setAllowOpacity( true );
    connect( colorWidget, &QgsCompoundColorWidget::currentColorChanged, this, &QgsPresetColorRampWidget::newColorChanged );
    openPanel( colorWidget );
  }
  else
  {
    QColor newColor = QgsColorDialog::getColor( QColor(), this->parentWidget(), tr( "Select Color" ), true );
    if ( !newColor.isValid() )
    {
      return;
    }
    activateWindow();

    mTreeColors->addColor( newColor, QgsSymbolLayerUtils::colorToName( newColor ) );
  }
}
예제 #4
0
void QgsLabelingWidget::labelModeChanged( int index )
{
  if ( mWidget )
    mStackedWidget->removeWidget( mWidget );

  delete mWidget;
  mWidget = nullptr;

  if ( index < 0 )
    return;

  if ( index == 2 )
  {
    // note - QgsRuleBasedLabelingWidget handles conversion of existing non-rule based labels to rule based
    QgsRuleBasedLabelingWidget *ruleWidget = new QgsRuleBasedLabelingWidget( mLayer, mCanvas, this );
    ruleWidget->setDockMode( dockMode() );
    connect( ruleWidget, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );
    connect( ruleWidget, &QgsRuleBasedLabelingWidget::widgetChanged, this, &QgsLabelingWidget::widgetChanged );
    mWidget = ruleWidget;
    mStackedWidget->addWidget( mWidget );
    mStackedWidget->setCurrentWidget( mWidget );
  }
  else if ( index == 1 || index == 3 )
  {
    mSimpleSettings.reset();
    if ( mLayer->labeling() && mLayer->labeling()->type() == QLatin1String( "simple" ) )
    {
      mSimpleSettings.reset( new QgsPalLayerSettings( mLayer->labeling()->settings() ) );
    }
    else if ( mLayer->labeling() && mLayer->labeling()->type() == QLatin1String( "rule-based" ) )
    {
      // changing from rule-based to simple labels... grab first rule, and copy settings
      const QgsRuleBasedLabeling *rl = static_cast<const QgsRuleBasedLabeling *>( mLayer->labeling() );
      if ( const QgsRuleBasedLabeling::Rule *rootRule = rl->rootRule() )
      {
        if ( const QgsRuleBasedLabeling::Rule *firstChild = rootRule->children().value( 0 ) )
        {
          if ( firstChild->settings() )
            mSimpleSettings.reset( new QgsPalLayerSettings( *firstChild->settings() ) );
        }
      }
    }

    if ( !mSimpleSettings )
      mSimpleSettings.reset( new QgsPalLayerSettings() );

    QgsLabelingGui *simpleWidget = new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings, this );
    simpleWidget->setDockMode( dockMode() );
    connect( simpleWidget, &QgsTextFormatWidget::widgetChanged, this, &QgsLabelingWidget::widgetChanged );
    connect( simpleWidget, &QgsLabelingGui::auxiliaryFieldCreated, this, &QgsLabelingWidget::auxiliaryFieldCreated );

    if ( index == 3 )
      simpleWidget->setLabelMode( QgsLabelingGui::ObstaclesOnly );
    else
      simpleWidget->setLabelMode( static_cast< QgsLabelingGui::LabelMode >( index ) );

    mWidget = simpleWidget;
    mStackedWidget->addWidget( mWidget );
    mStackedWidget->setCurrentWidget( mWidget );
  }
  emit widgetChanged();
}