void QgsVectorLayerProperties::apply()
{
  if ( labelingDialog )
    labelingDialog->apply();

  //
  // Set up sql subset query if applicable
  //
  grpSubset->setEnabled( true );

  if ( txtSubsetSQL->toPlainText() != layer->subsetString() )
  {
    // set the subset sql for the layer
    layer->setSubsetString( txtSubsetSQL->toPlainText() );
    mMetadataFilled = false;
  }

  // set up the scale based layer visibility stuff....
  layer->toggleScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
  layer->setMinimumScale( 1.0 / cbMinimumScale->scale() );
  layer->setMaximumScale( 1.0 / cbMaximumScale->scale() );

  // provider-specific options
  if ( layer->dataProvider() )
  {
    if ( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SetEncoding )
    {
      layer->dataProvider()->setEncoding( cboProviderEncoding->currentText() );
      layer->updateFieldMap();
    }
  }

  // update the display field
  if ( htmlRadio->isChecked() )
  {
    layer->setDisplayField( htmlMapTip->toPlainText() );
  }

  if ( fieldComboRadio->isChecked() )
  {
    layer->setDisplayField( displayFieldComboBox->currentText() );
  }

  actionDialog->apply();

  if ( labelDialog )
    labelDialog->apply();
  layer->enableLabels( labelCheckBox->isChecked() );
  layer->setLayerName( displayName() );

  QSet<QString> excludeAttributesWMS, excludeAttributesWFS;

  // Apply fields settings
  mFieldsPropertiesDialog->apply();

  if ( layer->isUsingRendererV2() )
  {
    QgsRendererV2PropertiesDialog* dlg =
      static_cast<QgsRendererV2PropertiesDialog*>( widgetStackRenderers->currentWidget() );
    dlg->apply();
  }
  else
  {
    QgsSingleSymbolDialog *sdialog =
      qobject_cast < QgsSingleSymbolDialog * >( widgetStackRenderers->currentWidget() );
    QgsGraduatedSymbolDialog *gdialog =
      qobject_cast < QgsGraduatedSymbolDialog * >( widgetStackRenderers->currentWidget() );
    QgsContinuousColorDialog *cdialog =
      qobject_cast < QgsContinuousColorDialog * >( widgetStackRenderers->currentWidget() );
    QgsUniqueValueDialog* udialog =
      qobject_cast< QgsUniqueValueDialog * >( widgetStackRenderers->currentWidget() );

    if ( sdialog )
    {
      sdialog->apply();
    }
    else if ( gdialog )
    {
      gdialog->apply();
    }
    else if ( cdialog )
    {
      cdialog->apply();
    }
    else if ( udialog )
    {
      udialog->apply();
    }
    layer->setTransparency( static_cast < unsigned int >( 255 - sliderTransparency->value() ) );

  }

  //apply diagram settings
  diagramPropertiesDialog->apply();

  //apply overlay dialogs
  for ( QList<QgsApplyDialog*>::iterator it = mOverlayDialogs.begin(); it != mOverlayDialogs.end(); ++it )
  {
    ( *it )->apply();
  }

  //layer title and abstract
  layer->setTitle( mLayerTitleLineEdit->text() );
  layer->setAbstract( mLayerAbstractTextEdit->toPlainText() );

  // update symbology
  emit refreshLegend( layer->id(), QgsLegendItem::DontChange );

  //no need to delete the old one, maplayer will do it if needed
  layer->setCacheImage( 0 );

  layer->triggerRepaint();
  // notify the project we've made a change
  QgsProject::instance()->dirty( true );
}
Exemplo n.º 2
0
void QgsVectorLayerProperties::apply()
{
  labelingDialog->apply();

  //
  // Set up sql subset query if applicable
  //
  grpSubset->setEnabled( true );

  if ( txtSubsetSQL->toPlainText() != layer->subsetString() )
  {
    // set the subset sql for the layer
    layer->setSubsetString( txtSubsetSQL->toPlainText() );
    mMetadataFilled = false;
  }

  // set up the scale based layer visibility stuff....
  layer->toggleScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
  layer->setMinimumScale( 1.0 / cbMinimumScale->scale() );
  layer->setMaximumScale( 1.0 / cbMaximumScale->scale() );

  // provider-specific options
  if ( layer->dataProvider() )
  {
    if ( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SetEncoding )
    {
      layer->dataProvider()->setEncoding( cboProviderEncoding->currentText() );
    }
  }

  // update the display field
  if ( htmlRadio->isChecked() )
  {
    layer->setDisplayField( htmlMapTip->toPlainText() );
  }

  if ( fieldComboRadio->isChecked() )
  {
    layer->setDisplayField( displayFieldComboBox->currentText() );
  }

  layer->setEditForm( leEditForm->text() );
  layer->setEditFormInit( leEditFormInit->text() );

  actionDialog->apply();

  labelDialog->apply();
  layer->enableLabels( labelCheckBox->isChecked() );
  layer->setLayerName( displayName() );

  for ( int i = 0; i < tblAttributes->rowCount(); i++ )
  {
    int idx = tblAttributes->item( i, attrIdCol )->text().toInt();

    QPushButton *pb = qobject_cast<QPushButton *>( tblAttributes->cellWidget( i, attrEditTypeCol ) );
    if ( !pb )
      continue;

    QgsVectorLayer::EditType editType = editTypeFromButtonText( pb->text() );
    layer->setEditType( idx, editType );

    switch ( editType )
    {
      case QgsVectorLayer::ValueMap:
        if ( mValueMaps.contains( idx ) )
        {
          QMap<QString, QVariant> &map = layer->valueMap( idx );
          map.clear();
          map = mValueMaps[idx];
        }
        break;

      case QgsVectorLayer::EditRange:
      case QgsVectorLayer::SliderRange:
      case QgsVectorLayer::DialRange:
        if ( mRanges.contains( idx ) )
        {
          layer->range( idx ) = mRanges[idx];
        }
        break;

      case QgsVectorLayer::CheckBox:
        if ( mCheckedStates.contains( idx ) )
        {
          layer->setCheckedState( idx, mCheckedStates[idx].first, mCheckedStates[idx].second );
        }
        break;

      case QgsVectorLayer::ValueRelation:
        if ( mValueRelationData.contains( idx ) )
        {
          layer->valueRelation( idx ) = mValueRelationData[idx];
        }
        break;

      case QgsVectorLayer::LineEdit:
      case QgsVectorLayer::UniqueValues:
      case QgsVectorLayer::UniqueValuesEditable:
      case QgsVectorLayer::Classification:
      case QgsVectorLayer::FileName:
      case QgsVectorLayer::Enumeration:
      case QgsVectorLayer::Immutable:
      case QgsVectorLayer::Hidden:
      case QgsVectorLayer::TextEdit:
      case QgsVectorLayer::Calendar:
      case QgsVectorLayer::UuidGenerator:
        break;
    }
  }

  if ( layer->isUsingRendererV2() )
  {
    QgsRendererV2PropertiesDialog* dlg =
      static_cast<QgsRendererV2PropertiesDialog*>( widgetStackRenderers->currentWidget() );
    dlg->apply();
  }
  else
  {
    QgsSingleSymbolDialog *sdialog =
      qobject_cast < QgsSingleSymbolDialog * >( widgetStackRenderers->currentWidget() );
    QgsGraduatedSymbolDialog *gdialog =
      qobject_cast < QgsGraduatedSymbolDialog * >( widgetStackRenderers->currentWidget() );
    QgsContinuousColorDialog *cdialog =
      qobject_cast < QgsContinuousColorDialog * >( widgetStackRenderers->currentWidget() );
    QgsUniqueValueDialog* udialog =
      qobject_cast< QgsUniqueValueDialog * >( widgetStackRenderers->currentWidget() );

    if ( sdialog )
    {
      sdialog->apply();
    }
    else if ( gdialog )
    {
      gdialog->apply();
    }
    else if ( cdialog )
    {
      cdialog->apply();
    }
    else if ( udialog )
    {
      udialog->apply();
    }
    layer->setTransparency( static_cast < unsigned int >( 255 - sliderTransparency->value() ) );

  }

  //apply diagram settings
  diagramPropertiesDialog->apply();

  //apply overlay dialogs
  for ( QList<QgsApplyDialog*>::iterator it = mOverlayDialogs.begin(); it != mOverlayDialogs.end(); ++it )
  {
    ( *it )->apply();
  }

  //layer title and abstract
  layer->setTitle( mLayerTitleLineEdit->text() );
  layer->setAbstract( mLayerAbstractTextEdit->toPlainText() );

  // update symbology
  emit refreshLegend( layer->id(), false );

  //no need to delete the old one, maplayer will do it if needed
  layer->setCacheImage( 0 );

  layer->triggerRepaint();
  // notify the project we've made a change
  QgsProject::instance()->dirty( true );

}
void QgsVectorLayerProperties::apply()
{
  //
  // Set up sql subset query if applicable
  //
#ifdef HAVE_POSTGRESQL
  //see if we are dealing with a pg layer here
  if ( layer->providerType() == "postgres" )
  {
    grpSubset->setEnabled( true );
    // set the subset sql for the layer
    layer->setSubsetString( txtSubsetSQL->toPlainText() );
    // update the metadata with the updated sql subset
    QString myStyle = QgsApplication::reportStyleSheet();
    teMetadata->clear();
    teMetadata->document()->setDefaultStyleSheet( myStyle );
    teMetadata->setHtml( metadata() );
    // update the extents of the layer (fetched from the provider)
    layer->updateExtents();
  }
#endif
  // set up the scale based layer visibility stuff....
  layer->toggleScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
  layer->setMinimumScale( spinMinimumScale->value() );
  layer->setMaximumScale( spinMaximumScale->value() );

  // update the display field
  layer->setDisplayField( displayFieldComboBox->currentText() );

  actionDialog->apply();

  labelDialog->apply();
  layer->enableLabels( labelCheckBox->isChecked() );
  layer->setLayerName( displayName() );

  for ( int i = 0; i < tblAttributes->rowCount(); i++ )
  {
    int idx = tblAttributes->item( i, 0 )->text().toInt();
    const QgsField &field = layer->pendingFields()[idx];

    QComboBox *cb = dynamic_cast<QComboBox*>( tblAttributes->cellWidget( i, 6 ) );
    if ( !cb )
      continue;

    QgsVectorLayer::EditType editType = ( QgsVectorLayer::EditType ) cb->itemData( cb->currentIndex() ).toInt();
    layer->setEditType( idx, editType );

    QString value = tblAttributes->item( i, 7 ) ? tblAttributes->item( i, 7 )->text() : QString::null;

    if ( editType == QgsVectorLayer::ValueMap )
    {
      QMap<QString, QVariant> &map = layer->valueMap( idx );
      map.clear();

      if ( !value.isEmpty() )
      {
        QStringList values = value.split( ";" );
        for ( int j = 0; j < values.size(); j++ )
        {
          QStringList args = values[j].split( "=" );
          QVariant value;

          if ( args.size() == 1 || ( args.size() == 2 && args[0] == args[1] ) )
          {
            QgsDebugMsg( QString( "idx:%1 key:%2 value:%2" ).arg( idx ).arg( args[0] ) );
            value = args[0];
          }
          else if ( args.size() == 2 )
          {
            QgsDebugMsg( QString( "idx:%1 key:%2 value:%3" ).arg( idx ).arg( args[0] ).arg( args[1] ) );
            value = args[1];

          }

          if ( value.canConvert( field.type() ) )
          {
            map.insert( args[0], value );
          }
        }
      }
    }
    else if ( editType == QgsVectorLayer::EditRange ||
              editType == QgsVectorLayer::SliderRange )
    {
      QStringList values = value.split( ";" );

      if ( values.size() == 3 )
      {
        QVariant min  = values[0];
        QVariant max  = values[1];
        QVariant step = values[2];

        if ( min.canConvert( field.type() ) &&
             max.canConvert( field.type() ) &&
             step.canConvert( field.type() ) )
        {
          min.convert( field.type() );
          max.convert( field.type() );
          step.convert( field.type() );
          layer->range( idx ) = QgsVectorLayer::RangeData( min, max, step );
        }
      }
    }
  }

  QgsSingleSymbolDialog *sdialog =
    dynamic_cast < QgsSingleSymbolDialog * >( widgetStackRenderers->currentWidget() );
  QgsGraduatedSymbolDialog *gdialog =
    dynamic_cast < QgsGraduatedSymbolDialog * >( widgetStackRenderers->currentWidget() );
  QgsContinuousColorDialog *cdialog =
    dynamic_cast < QgsContinuousColorDialog * >( widgetStackRenderers->currentWidget() );
  QgsUniqueValueDialog* udialog =
    dynamic_cast< QgsUniqueValueDialog * >( widgetStackRenderers->currentWidget() );

  if ( sdialog )
  {
    sdialog->apply();
  }
  else if ( gdialog )
  {
    gdialog->apply();
  }
  else if ( cdialog )
  {
    cdialog->apply();
  }
  else if ( udialog )
  {
    udialog->apply();
  }
  layer->setTransparency( static_cast < unsigned int >( 255 - sliderTransparency->value() ) );

  // update symbology
  emit refreshLegend( layer->getLayerID(), false );

  layer->triggerRepaint();
  // notify the project we've made a change
  QgsProject::instance()->dirty( true );

}