コード例 #1
0
QgsExpressionContext* QgsAggregateCalculator::createContext() const
{
  QgsExpressionContext* context = new QgsExpressionContext();
  context->appendScope( QgsExpressionContextUtils::globalScope() );
  context->appendScope( QgsExpressionContextUtils::projectScope() );
  context->appendScope( QgsExpressionContextUtils::layerScope( mLayer ) );
  return context;
}
コード例 #2
0
ファイル: qgslayout.cpp プロジェクト: NathanW2/QGIS
QgsExpressionContext QgsLayout::createExpressionContext() const
{
  QgsExpressionContext context = QgsExpressionContext();
  context.appendScope( QgsExpressionContextUtils::globalScope() );
  context.appendScope( QgsExpressionContextUtils::projectScope( mProject ) );
  context.appendScope( QgsExpressionContextUtils::layoutScope( this ) );
  return context;
}
コード例 #3
0
ファイル: qgslayout.cpp プロジェクト: exlimit/QGIS
QgsExpressionContext QgsLayout::createExpressionContext() const
{
  QgsExpressionContext context = QgsExpressionContext();
  context.appendScope( QgsExpressionContextUtils::globalScope() );
  context.appendScope( QgsExpressionContextUtils::projectScope( mProject ) );
  context.appendScope( QgsExpressionContextUtils::layoutScope( this ) );
#if 0 //TODO
  if ( mAtlasComposition.enabled() )
  {
    context.appendScope( QgsExpressionContextUtils::atlasScope( &mAtlasComposition ) );
  }
#endif
  return context;
}
コード例 #4
0
ファイル: qgscomposerobject.cpp プロジェクト: AM7000000/QGIS
QgsExpressionContext* QgsComposerObject::createExpressionContext() const
{
  QgsExpressionContext* context = nullptr;
  if ( mComposition )
  {
    context = mComposition->createExpressionContext();
  }
  else
  {
    context = new QgsExpressionContext();
    context->appendScope( QgsExpressionContextUtils::globalScope() );
    context->appendScope( QgsExpressionContextUtils::projectScope() );
  }
  return context;
}
コード例 #5
0
QgsExpressionContext QgsGraduatedSymbolRendererWidget::createExpressionContext() const
{
  QgsExpressionContext expContext;
  expContext << QgsExpressionContextUtils::globalScope()
  << QgsExpressionContextUtils::projectScope( QgsProject::instance() )
  << QgsExpressionContextUtils::atlasScope( nullptr );

  if ( mContext.mapCanvas() )
  {
    expContext << QgsExpressionContextUtils::mapSettingsScope( mContext.mapCanvas()->mapSettings() )
    << new QgsExpressionContextScope( mContext.mapCanvas()->expressionContextScope() );
  }
  else
  {
    expContext << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() );
  }

  if ( vectorLayer() )
    expContext << QgsExpressionContextUtils::layerScope( vectorLayer() );

  // additional scopes
  Q_FOREACH ( const QgsExpressionContextScope& scope, mContext.additionalExpressionContextScopes() )
  {
    expContext.appendScope( new QgsExpressionContextScope( scope ) );
  }

  return expContext;
}
コード例 #6
0
QgsExpressionContext *QgsComposerAttributeTableV2::createExpressionContext() const
{
  QgsExpressionContext* context = QgsComposerTableV2::createExpressionContext();

  if ( mSource == LayerAttributes )
  {
    context->appendScope( QgsExpressionContextUtils::layerScope( mVectorLayer ) );
  }

  return context;
}
コード例 #7
0
ファイル: qgscomposerframe.cpp プロジェクト: V17nika/QGIS
QgsExpressionContext QgsComposerFrame::createExpressionContext() const
{
  if ( !mMultiFrame )
    return QgsComposerItem::createExpressionContext();

  //start with multiframe's context
  QgsExpressionContext context = mMultiFrame->createExpressionContext();
  //add frame's individual context
  context.appendScope( QgsExpressionContextUtils::composerItemScope( this ) );

  return context;
}
コード例 #8
0
QgsExpressionContext QgsAttributeActionPropertiesDialog::createExpressionContext() const
{
  QgsExpressionContext context = mLayer->createExpressionContext();

  Q_FOREACH ( QCheckBox* cb, mActionScopeCheckBoxes )
  {
    if ( cb->isChecked() )
    {
      QgsActionScope actionScope = QgsApplication::actionScopeRegistry()->actionScope( cb->property( "ActionScopeName" ).toString() );
      context.appendScope( new QgsExpressionContextScope( actionScope.expressionContextScope() ) );
    }
  }

  return context;
}
コード例 #9
0
QgsExpressionContext QgsAtlasComposition::createExpressionContext()
{
  QgsExpressionContext expressionContext;
  expressionContext << QgsExpressionContextUtils::globalScope()
  << QgsExpressionContextUtils::projectScope();
  if ( mComposition )
    expressionContext << QgsExpressionContextUtils::compositionScope( mComposition );

  expressionContext.appendScope( QgsExpressionContextUtils::atlasScope( this ) );
  if ( mCoverageLayer )
    expressionContext.lastScope()->setFields( mCoverageLayer->fields() );
  if ( mComposition && mComposition->atlasMode() != QgsComposition::AtlasOff )
    expressionContext.lastScope()->setFeature( mCurrentFeature );

  return expressionContext;
}
コード例 #10
0
QgsExpressionContext QgsLayoutAtlas::createExpressionContext()
{
  QgsExpressionContext expressionContext;
  expressionContext << QgsExpressionContextUtils::globalScope();
  if ( mLayout )
    expressionContext << QgsExpressionContextUtils::projectScope( mLayout->project() )
                      << QgsExpressionContextUtils::layoutScope( mLayout );

  expressionContext.appendScope( QgsExpressionContextUtils::atlasScope( this ) );

  if ( mCoverageLayer )
    expressionContext.lastScope()->setFields( mCoverageLayer->fields() );

  if ( mLayout && mEnabled )
    expressionContext.lastScope()->setFeature( mCurrentFeature );

  return expressionContext;
}
コード例 #11
0
ファイル: qgscomposeritem.cpp プロジェクト: exlimit/QGIS
QgsExpressionContext QgsComposerItem::createExpressionContext() const
{
  QgsExpressionContext context = QgsComposerObject::createExpressionContext();
  context.appendScope( QgsExpressionContextUtils::composerItemScope( this ) );
  return context;
}
コード例 #12
0
void TestQgsProjectStorage::testMemoryStorage()
{
  QString dataDir( TEST_DATA_DIR ); // defined in CmakeLists.txt
  QString layerPath = dataDir + "/points.shp";
  QgsVectorLayer *layer1 = new QgsVectorLayer( layerPath, QStringLiteral( "points" ), QStringLiteral( "ogr" ) );
  QVERIFY( layer1->isValid() );

  MemoryStorage *memStorage = new MemoryStorage;

  QgsApplication::projectStorageRegistry()->registerProjectStorage( memStorage );

  QVERIFY( QgsApplication::projectStorageRegistry()->projectStorages().contains( memStorage ) );

  QCOMPARE( memStorage->listProjects( QString() ).count(), 0 );

  QgsProject prj1;
  prj1.setTitle( "best project ever" );
  prj1.addMapLayer( layer1 );
  prj1.setFileName( "memory:project1" );

  // let's use the aux storage as well - so that the project will include aux database as well
  int fldCnt0 = layer1->fields().count();
  QgsAuxiliaryLayer *layerAux = prj1.auxiliaryStorage()->createAuxiliaryLayer( layer1->fields().at( 0 ), layer1 );
  layer1->setAuxiliaryLayer( layerAux );
  layerAux->addAttribute( QgsField( "fld_aux", QVariant::Int ) );
  layerAux->commitChanges();
  QCOMPARE( fldCnt0, 6 );
  QCOMPARE( layer1->fields().count(), 7 );

  bool writeOk = prj1.write();

  QVERIFY( writeOk );
  QCOMPARE( memStorage->listProjects( QString() ).count(), 1 );

  QVERIFY( prj1.absoluteFilePath().isEmpty() );
  QCOMPARE( prj1.baseName(), QString( "project1" ) );
  QVERIFY( prj1.lastModified().secsTo( QDateTime::currentDateTime() ) < 1 );

  // read the project back

  QgsProject prj2;
  prj2.setFileName( "memory:project1" );
  bool readOk = prj2.read();

  QVERIFY( readOk );
  QCOMPARE( prj2.mapLayers().count(), 1 );
  QCOMPARE( prj2.title(), QString( "best project ever" ) );

  // let's check that our stuff from auxiliary database got stored written and read
  QgsVectorLayer *prj2layer1 = qobject_cast<QgsVectorLayer *>( prj2.mapLayers().constBegin().value() );
  QVERIFY( prj2layer1 );
  QCOMPARE( prj2layer1->fields().count(), 7 );
  QCOMPARE( prj2layer1->fields().at( 6 ).name(), QString( "auxiliary_storage_fld_aux" ) );

  // test project-related variables for project storage
  QgsExpressionContext expressionContext;
  expressionContext.appendScope( QgsExpressionContextUtils::projectScope( &prj2 ) );
  QCOMPARE( QgsExpression( "@project_path" ).evaluate( &expressionContext ).toString(), QString( "memory:project1" ) );
  QCOMPARE( QgsExpression( "@project_basename" ).evaluate( &expressionContext ).toString(), QString( "project1" ) );

  // test access of non-existent project

  QgsProject prj3;
  prj3.setFileName( "memory:nooooooooo!" );
  bool readInvalidOk = prj3.read();
  QVERIFY( !readInvalidOk );

  // test metadata access

  QgsProjectStorage::Metadata meta1;
  bool readMetaOk = memStorage->readProjectStorageMetadata( "memory:project1", meta1 );
  QVERIFY( readMetaOk );
  QCOMPARE( meta1.name, QString( "project1" ) );
  QVERIFY( meta1.lastModified.secsTo( QDateTime::currentDateTime() ) < 1 );

  QgsProjectStorage::Metadata metaX;
  bool readMetaInvalidOk = memStorage->readProjectStorageMetadata( "memory:projectXYZ", metaX );
  QVERIFY( !readMetaInvalidOk );

  // test removal

  bool removeInvalidOk = memStorage->removeProject( "memory:projectXYZ" );
  QVERIFY( !removeInvalidOk );
  QCOMPARE( memStorage->listProjects( QString() ).count(), 1 );

  bool removeOk = memStorage->removeProject( "memory:project1" );
  QVERIFY( removeOk );
  QCOMPARE( memStorage->listProjects( QString() ).count(), 0 );

  QgsApplication::projectStorageRegistry()->unregisterProjectStorage( memStorage );
}