void QgsAtlasCompositionWidget::on_mAtlasFilenameExpressionButton_clicked()
{
  QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
  if ( !atlasMap || !atlasMap->coverageLayer() )
  {
    return;
  }

  QScopedPointer<QgsExpressionContext> context( mComposition->createExpressionContext() );
  QgsExpressionBuilderDialog exprDlg( atlasMap->coverageLayer(), mAtlasFilenamePatternEdit->text(), this, "generic", *context );
  exprDlg.setWindowTitle( tr( "Expression based filename" ) );

  if ( exprDlg.exec() == QDialog::Accepted )
  {
    QString expression =  exprDlg.expressionText();
    if ( !expression.isEmpty() )
    {
      //set atlas filename expression
      mAtlasFilenamePatternEdit->setText( expression );
      if ( ! atlasMap->setFilenamePattern( expression ) )
      {
        //expression could not be set
        QMessageBox::warning( this
                              , tr( "Could not evaluate filename pattern" )
                              , tr( "Could not set filename pattern as '%1'.\nParser error:\n%2" )
                              .arg( expression,
                                    atlasMap->filenamePatternErrorString() )
                            );
      }
    }
  }
}
void QgsComposerPictureWidget::on_mPictureExpressionButton_clicked()
{
  if ( !mPicture )
  {
    return;
  }

  QgsVectorLayer* vl = 0;
  QgsComposition* composition = mPicture->composition();

  if ( composition )
  {
    QgsAtlasComposition* atlasMap = &composition->atlasComposition();
    if ( atlasMap )
    {
      vl = atlasMap->coverageLayer();
    }
  }

  QgsExpressionBuilderDialog exprDlg( vl, mPictureExpressionLineEdit->text(), this );
  exprDlg.setWindowTitle( tr( "Expression based image path" ) );
  if ( exprDlg.exec() == QDialog::Accepted )
  {
    QString expression =  exprDlg.expressionText();
    if ( !expression.isEmpty() )
    {
      mPictureExpressionLineEdit->setText( expression );
      setPictureExpression();
    }
  }
}
Example #3
0
QString QgsComposerPicture::evalPictureExpression()
{
  //generate filename for picture
  if ( mSourceExpression.size() > 0 && mUseSourceExpression )
  {
    if ( ! mPictureExpr )
    {
      return QString();
    }

    QVariant filenameRes;
    QgsAtlasComposition* atlas = &( mComposition->atlasComposition() );
    if ( atlas->enabled() )
    {
      //expression needs to be evaluated considering the current atlas feature
      filenameRes = mPictureExpr->evaluate( atlas->currentFeature(),
                                            atlas->coverageLayer()->pendingFields() );
    }
    else
    {
      filenameRes = mPictureExpr->evaluate();
    }

    if ( mPictureExpr->hasEvalError() )
    {
      QgsMessageLog::logMessage( tr( "Picture expression eval error: %1" ).arg( mPictureExpr->evalErrorString() ), tr( "Composer" ) );
    }

    return filenameRes.toString();
  }
  else
  {
    return QString();
  }
}
void QgsAtlasCompositionWidget::on_mAtlasFilenameExpressionButton_clicked()
{
  QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
  if ( !atlasMap || !atlasMap->coverageLayer() )
  {
    return;
  }

  QgsExpressionBuilderDialog exprDlg( atlasMap->coverageLayer(), mAtlasFilenamePatternEdit->text(), this );
  exprDlg.setWindowTitle( tr( "Expression based filename" ) );
  if ( exprDlg.exec() == QDialog::Accepted )
  {
    QString expression =  exprDlg.expressionText();
    if ( !expression.isEmpty() )
    {
      // will emit a textChanged signal
      mAtlasFilenamePatternEdit->setText( expression );
    }
  }
}
Example #5
0
QgsVectorLayer* QgsComposerItemBaseWidget::atlasCoverageLayer() const
{
  QgsAtlasComposition* atlasMap = atlasComposition();

  if ( atlasMap && atlasMap->enabled() )
  {
    return atlasMap->coverageLayer();
  }

  return 0;
}
void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterButton_clicked()
{
  QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
  if ( !atlasMap || !atlasMap->coverageLayer() )
  {
    return;
  }

  QgsExpressionBuilderDialog exprDlg( atlasMap->coverageLayer(), mAtlasFeatureFilterEdit->text(), this );
  exprDlg.setWindowTitle( tr( "Expression based filter" ) );
  if ( exprDlg.exec() == QDialog::Accepted )
  {
    QString expression =  exprDlg.expressionText();
    if ( !expression.isEmpty() )
    {
      mAtlasFeatureFilterEdit->setText( expression );
      atlasMap->setFeatureFilter( mAtlasFeatureFilterEdit->text() );
      updateAtlasFeatures();
    }
  }
}
Example #7
0
void QgsComposerMapWidget::toggleAtlasScalingOptionsByLayerType()
{
  if ( !mComposerMap )
  {
    return;
  }

  //get composition
  QgsComposition* composition = mComposerMap->composition();
  if ( !composition )
  {
    return;
  }

  QgsAtlasComposition* atlas = &composition->atlasComposition();

  QgsVectorLayer* coverageLayer = atlas->coverageLayer();
  if ( !coverageLayer )
  {
    return;
  }

  switch ( atlas->coverageLayer()->wkbType() )
  {
    case QGis::WKBPoint:
    case QGis::WKBPoint25D:
    case QGis::WKBMultiPoint:
    case QGis::WKBMultiPoint25D:
      //For point layers buffer setting makes no sense, so set "fixed scale" on and disable margin control
      mAtlasFixedScaleRadio->setChecked( true );
      mAtlasMarginRadio->setEnabled( false );
      mAtlasPredefinedScaleRadio->setEnabled( false );
      break;
    default:
      //Not a point layer, so enable changes to fixed scale control
      mAtlasMarginRadio->setEnabled( true );
      mAtlasPredefinedScaleRadio->setEnabled( true );
  }
}
void QgsAtlasCompositionWidget::updateGuiElements()
{
  blockAllSignals( true );
  QgsAtlasComposition *atlasMap = &mComposition->atlasComposition();

  mUseAtlasCheckBox->setCheckState( atlasMap->enabled() ? Qt::Checked : Qt::Unchecked );
  mConfigurationGroup->setEnabled( atlasMap->enabled() );
  mOutputGroup->setEnabled( atlasMap->enabled() );

  mAtlasCoverageLayerComboBox->setLayer( atlasMap->coverageLayer() );
  mPageNameWidget->setLayer( atlasMap->coverageLayer() );
  mPageNameWidget->setField( atlasMap->pageNameExpression() );

  mAtlasSortFeatureKeyComboBox->setLayer( atlasMap->coverageLayer() );
  mAtlasSortFeatureKeyComboBox->setField( atlasMap->sortKeyAttributeName() );

  mAtlasFilenamePatternEdit->setText( atlasMap->filenamePattern() );
  mAtlasHideCoverageCheckBox->setCheckState( atlasMap->hideCoverage() ? Qt::Checked : Qt::Unchecked );

  mAtlasSingleFileCheckBox->setCheckState( atlasMap->singleFile() ? Qt::Checked : Qt::Unchecked );
  mAtlasFilenamePatternEdit->setEnabled( !atlasMap->singleFile() );
  mAtlasFilenameExpressionButton->setEnabled( !atlasMap->singleFile() );

  mAtlasSortFeatureCheckBox->setCheckState( atlasMap->sortFeatures() ? Qt::Checked : Qt::Unchecked );
  mAtlasSortFeatureDirectionButton->setEnabled( atlasMap->sortFeatures() );
  mAtlasSortFeatureKeyComboBox->setEnabled( atlasMap->sortFeatures() );

  mAtlasSortFeatureDirectionButton->setArrowType( atlasMap->sortAscending() ? Qt::UpArrow : Qt::DownArrow );
  mAtlasFeatureFilterEdit->setText( atlasMap->featureFilter() );

  mAtlasFeatureFilterCheckBox->setCheckState( atlasMap->filterFeatures() ? Qt::Checked : Qt::Unchecked );
  mAtlasFeatureFilterEdit->setEnabled( atlasMap->filterFeatures() );
  mAtlasFeatureFilterButton->setEnabled( atlasMap->filterFeatures() );

  mAtlasFileFormat->setCurrentIndex( mAtlasFileFormat->findText( atlasMap->fileFormat() ) );

  blockAllSignals( false );
}
Example #9
0
void QgsComposerObject::prepareDataDefinedExpressions() const
{
  //use atlas coverage layer if set
  QgsVectorLayer* atlasLayer = 0;
  if ( mComposition )
  {
    QgsAtlasComposition* atlas = &mComposition->atlasComposition();
    if ( atlas && atlas->enabled() )
    {
      atlasLayer = atlas->coverageLayer();
    }
  }

  //prepare all QgsDataDefineds
  QMap< DataDefinedProperty, QgsDataDefined* >::const_iterator it = mDataDefinedProperties.constBegin();
  if ( it != mDataDefinedProperties.constEnd() )
  {
    it.value()->prepareExpression( atlasLayer );
  }
}
Example #10
0
void QgsCompositionWidget::populateDataDefinedButtons()
{
  if ( !mComposition )
  {
    return;
  }

  QgsVectorLayer* vl = 0;
  QgsAtlasComposition* atlas = &mComposition->atlasComposition();

  if ( atlas && atlas->enabled() )
  {
    vl = atlas->coverageLayer();
  }

  Q_FOREACH ( QgsDataDefinedButton* button, findChildren< QgsDataDefinedButton* >() )
  {
    button->blockSignals( true );
    button->registerGetExpressionContextCallback( &_getExpressionContext, mComposition );
  }
Example #11
0
void QgsCompositionWidget::populateDataDefinedButtons()
{
  if ( !mComposition )
  {
    return;
  }

  QgsVectorLayer* vl = 0;
  QgsAtlasComposition* atlas = &mComposition->atlasComposition();

  if ( atlas && atlas->enabled() )
  {
    vl = atlas->coverageLayer();
  }

  mPaperSizeDDBtn->blockSignals( true );
  mPaperWidthDDBtn->blockSignals( true );
  mPaperHeightDDBtn->blockSignals( true );
  mNumPagesDDBtn->blockSignals( true );
  mPaperOrientationDDBtn->blockSignals( true );

  mPaperSizeDDBtn->init( vl, mComposition->dataDefinedProperty( QgsComposerObject::PresetPaperSize ),
                         QgsDataDefinedButton::String, QgsDataDefinedButton::paperSizeDesc() );
  mPaperWidthDDBtn->init( vl, mComposition->dataDefinedProperty( QgsComposerObject::PaperWidth ),
                          QgsDataDefinedButton::Double, QgsDataDefinedButton::doublePosDesc() );
  mPaperHeightDDBtn->init( vl, mComposition->dataDefinedProperty( QgsComposerObject::PaperHeight ),
                           QgsDataDefinedButton::Double, QgsDataDefinedButton::doublePosDesc() );
  mNumPagesDDBtn->init( vl, mComposition->dataDefinedProperty( QgsComposerObject::NumPages ),
                        QgsDataDefinedButton::Int, QgsDataDefinedButton::intPosOneDesc() );
  mPaperOrientationDDBtn->init( vl, mComposition->dataDefinedProperty( QgsComposerObject::PaperOrientation ),
                                QgsDataDefinedButton::String, QgsDataDefinedButton::paperOrientationDesc() );

  //initial state of controls - disable related controls when dd buttons are active
  mPaperSizeComboBox->setEnabled( !mPaperSizeDDBtn->isActive() );

  mPaperSizeDDBtn->blockSignals( false );
  mPaperWidthDDBtn->blockSignals( false );
  mPaperHeightDDBtn->blockSignals( false );
  mNumPagesDDBtn->blockSignals( false );
  mPaperOrientationDDBtn->blockSignals( false );
}
void QgsAtlasCompositionWidget::updateGuiElements()
{
  QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
  if ( atlasMap->enabled() )
  {
    mUseAtlasCheckBox->setCheckState( Qt::Checked );
  }
  else
  {
    mUseAtlasCheckBox->setCheckState( Qt::Unchecked );
  }

  mAtlasCoverageLayerComboBox->setLayer( atlasMap->coverageLayer() );
  mAtlasSortFeatureKeyComboBox->setField( atlasMap->sortKeyAttributeName() );
  mAtlasFilenamePatternEdit->setText( atlasMap->filenamePattern() );
  mAtlasHideCoverageCheckBox->setCheckState( atlasMap->hideCoverage() ? Qt::Checked : Qt::Unchecked );
  mAtlasSingleFileCheckBox->setCheckState( atlasMap->singleFile() ? Qt::Checked : Qt::Unchecked );
  mAtlasSortFeatureCheckBox->setCheckState( atlasMap->sortFeatures() ? Qt::Checked : Qt::Unchecked );
  mAtlasSortFeatureDirectionButton->setArrowType( atlasMap->sortAscending() ? Qt::UpArrow : Qt::DownArrow );
  mAtlasFeatureFilterEdit->setText( atlasMap->featureFilter() );
  mAtlasFeatureFilterCheckBox->setCheckState( atlasMap->filterFeatures() ? Qt::Checked : Qt::Unchecked );
}