本文整理汇总了C++中QgsVectorLayer类的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer类的具体用法?C++ QgsVectorLayer怎么用?C++ QgsVectorLayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QgsVectorLayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QDialog
RgExportDlg::RgExportDlg( QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl )
{
// create base widgets;
setWindowTitle( tr( "Export feature" ) );
QVBoxLayout *v = new QVBoxLayout( this );
QHBoxLayout *h = new QHBoxLayout();
QLabel *l = new QLabel( tr( "Select destination layer" ), this );
h->addWidget( l );
mcbLayers = new QComboBox( this );
h->addWidget( mcbLayers );
v->addLayout( h );
QDialogButtonBox *bb = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
connect( bb, SIGNAL( accepted() ), this, SLOT( on_buttonBox_accepted() ) );
connect( bb, SIGNAL( rejected() ), this, SLOT( on_buttonBox_rejected() ) );
v->addWidget( bb );
//fill list of layers
mcbLayers->insertItem( 0, tr( "New temporary layer" ), QVariant( "-1" ) );
QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin();
for ( ; layer_it != mapLayers.end(); ++layer_it )
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer_it.value() );
if ( !vl )
continue;
if ( vl->geometryType() != QGis::Line )
continue;
mcbLayers->insertItem( 0, vl->name(), QVariant( vl->id() ) );
}
} // RgSettingsDlg::RgSettingsDlg()
示例2: changeLayer
void QgsComposerAttributeTableWidget::changeLayer( QgsMapLayer *layer )
{
if ( !mComposerTable )
{
return;
}
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer );
if ( !vl )
{
return;
}
QgsComposition* composition = mComposerTable->composition();
if ( composition )
{
composition->beginMultiFrameCommand( mComposerTable, tr( "Table layer changed" ) );
}
mComposerTable->setVectorLayer( vl );
mComposerTable->update();
if ( composition )
{
composition->endMultiFrameCommand();
}
if ( vl->geometryType() == QGis::NoGeometry )
{
//layer has no geometry, so uncheck & disable controls which require geometry
mShowOnlyVisibleFeaturesCheckBox->setChecked( false );
mShowOnlyVisibleFeaturesCheckBox->setEnabled( false );
}
else
{
mShowOnlyVisibleFeaturesCheckBox->setEnabled( true );
}
}
示例3: cacheJoinLayer
void QgsVectorLayerJoinBuffer::cacheJoinLayer( QgsVectorJoinInfo& joinInfo )
{
//memory cache not required or already done
if ( !joinInfo.memoryCache || joinInfo.cachedAttributes.size() > 0 )
{
return;
}
QgsVectorLayer* cacheLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( joinInfo.joinLayerId ) );
if ( cacheLayer )
{
int joinFieldIndex = cacheLayer->pendingFields().indexFromName( joinInfo.joinFieldName );
joinInfo.cachedAttributes.clear();
QgsFeatureIterator fit = cacheLayer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ) );
QgsFeature f;
while ( fit.nextFeature( f ) )
{
const QgsAttributes& attrs = f.attributes();
joinInfo.cachedAttributes.insert( attrs[joinFieldIndex].toString(), attrs );
}
}
}
示例4: sourceLayer
void QgsComposerAttributeTableV2::resetColumns()
{
QgsVectorLayer* source = sourceLayer();
if ( !source )
{
return;
}
//remove existing columns
qDeleteAll( mColumns );
mColumns.clear();
//rebuild columns list from vector layer fields
int idx = 0;
Q_FOREACH ( const QgsField& field, source->fields() )
{
QString currentAlias = source->attributeDisplayName( idx );
QgsComposerTableColumn* col = new QgsComposerTableColumn;
col->setAttribute( field.name() );
col->setHeading( currentAlias );
mColumns.append( col );
idx++;
}
}
示例5: addLayerProjectSettings
void QgsServerProjectParser::addLayerProjectSettings( QDomElement& layerElem, QDomDocument& doc, QgsMapLayer* currentLayer ) const
{
if ( !currentLayer )
{
return;
}
if ( currentLayer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vLayer = static_cast<QgsVectorLayer*>( currentLayer );
const QSet<QString>& excludedAttributes = vLayer->excludeAttributesWMS();
QString displayField = vLayer->displayField();
//attributes
QDomElement attributesElem = doc.createElement( "Attributes" );
const QgsFields& layerFields = vLayer->pendingFields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
const QgsField& field = layerFields[idx];
if ( excludedAttributes.contains( field.name() ) )
{
continue;
}
// field alias in case of displayField
if ( field.name() == displayField )
{
displayField = vLayer->attributeDisplayName( idx );
}
QDomElement attributeElem = doc.createElement( "Attribute" );
attributeElem.setAttribute( "name", field.name() );
attributeElem.setAttribute( "type", QVariant::typeToName( field.type() ) );
attributeElem.setAttribute( "typeName", field.typeName() );
QString alias = vLayer->attributeAlias( idx );
if ( !alias.isEmpty() )
{
attributeElem.setAttribute( "alias", alias );
}
//edit type to text
attributeElem.setAttribute( "editType", vLayer->editorWidgetV2( idx ) );
attributeElem.setAttribute( "comment", field.comment() );
attributeElem.setAttribute( "length", field.length() );
attributeElem.setAttribute( "precision", field.precision() );
attributesElem.appendChild( attributeElem );
}
//displayfield
layerElem.setAttribute( "displayField", displayField );
layerElem.appendChild( attributesElem );
}
}
示例6: readFieldName
int QgsSymbol::readFieldName( QDomNode &synode, QString name, const QgsVectorLayer &vl )
{
QDomNode node = synode.namedItem( name + "name" );
if ( !node.isNull() )
{
const QgsFieldMap &fields = vl.pendingFields();
QString name = node.toElement().text();
for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); it++ )
if ( it->name() == name )
return it.key();
return -1;
}
node = synode.namedItem( name );
return node.isNull() ? -1 : node.toElement().text().toInt();
}
示例7: toggleAllItems
void QgsSymbolLegendNode::toggleAllItems()
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
if ( !vlayer || !vlayer->renderer() )
return;
const QgsLegendSymbolList symbolList = vlayer->renderer()->legendSymbolItems();
for ( const auto &item : symbolList )
{
vlayer->renderer()->checkLegendSymbolItem( item.ruleKey(), ! vlayer->renderer()->legendSymbolItemChecked( item.ruleKey() ) );
}
emit dataChanged();
vlayer->triggerRepaint();
}
示例8: sourceModel
bool QgsMapLayerProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
{
if ( mFilters.testFlag( All ) && mExceptList.isEmpty() )
return true;
QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
QgsMapLayer* layer = static_cast<QgsMapLayer*>( index.internalPointer() );
if ( !layer )
return false;
if ( mExceptList.contains( layer ) )
return false;
// layer type
if (( mFilters.testFlag( RasterLayer ) && layer->type() == QgsMapLayer::RasterLayer ) ||
( mFilters.testFlag( VectorLayer ) && layer->type() == QgsMapLayer::VectorLayer ) ||
( mFilters.testFlag( PluginLayer ) && layer->type() == QgsMapLayer::PluginLayer ) )
return true;
// geometry type
bool detectGeometry = mFilters.testFlag( NoGeometry ) ||
mFilters.testFlag( PointLayer ) ||
mFilters.testFlag( LineLayer ) ||
mFilters.testFlag( PolygonLayer ) ||
mFilters.testFlag( HasGeometry );
if ( detectGeometry && layer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer );
if ( vl )
{
if ( mFilters.testFlag( HasGeometry ) && vl->hasGeometryType() )
return true;
if ( mFilters.testFlag( NoGeometry ) && vl->geometryType() == QGis::NoGeometry )
return true;
if ( mFilters.testFlag( PointLayer ) && vl->geometryType() == QGis::Point )
return true;
if ( mFilters.testFlag( LineLayer ) && vl->geometryType() == QGis::Line )
return true;
if ( mFilters.testFlag( PolygonLayer ) && vl->geometryType() == QGis::Polygon )
return true;
}
}
return false;
}
示例9: fetchLayerPoint
int QgsMapToolCapture::fetchLayerPoint( const QgsPointLocator::Match &match, QgsPoint &layerPoint )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
QgsVectorLayer *sourceLayer = match.layer();
if ( match.isValid() && match.hasVertex() && sourceLayer &&
( sourceLayer->crs() == vlayer->crs() ) )
{
QgsFeature f;
QgsFeatureRequest request;
request.setFilterFid( match.featureId() );
bool fetched = match.layer()->getFeatures( request ).nextFeature( f );
if ( fetched )
{
QgsVertexId vId;
if ( !f.geometry().vertexIdFromVertexNr( match.vertexIndex(), vId ) )
return 2;
layerPoint = f.geometry().constGet()->vertexAt( vId );
// ZM support depends on the target layer
if ( !QgsWkbTypes::hasZ( vlayer->wkbType() ) )
{
layerPoint.dropZValue();
}
if ( !QgsWkbTypes::hasM( vlayer->wkbType() ) )
{
layerPoint.dropMValue();
}
return 0;
}
else
{
return 2;
}
}
else
{
return 1;
}
}
示例10: createAuxiliaryFields
bool QgsMapToolLabel::createAuxiliaryFields( LabelDetails &details, QgsPalIndexes &indexes ) const
{
bool newAuxiliaryLayer = false;
QgsVectorLayer *vlayer = details.layer;
QString providerId = details.pos.providerID;
if ( !vlayer || !vlayer->labelsEnabled() )
return false;
if ( !vlayer->auxiliaryLayer() )
{
QgsNewAuxiliaryLayerDialog dlg( vlayer );
dlg.exec();
newAuxiliaryLayer = true;
}
if ( !vlayer->auxiliaryLayer() )
return false;
for ( const QgsPalLayerSettings::Property &p : qgis::as_const( mPalProperties ) )
{
int index = -1;
// always use the default activated property
QgsProperty prop = details.settings.dataDefinedProperties().property( p );
if ( prop.propertyType() == QgsProperty::FieldBasedProperty && prop.isActive() )
{
index = vlayer->fields().lookupField( prop.field() );
}
else
{
index = QgsAuxiliaryLayer::createProperty( p, vlayer );
}
indexes[p] = index;
}
details.settings = vlayer->labeling()->settings( providerId );
return newAuxiliaryLayer;
}
示例11: needTemporaryImage
bool QgsMapRendererJob::needTemporaryImage( QgsMapLayer* ml )
{
if ( ml->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
if ( vl->rendererV2() && vl->rendererV2()->forceRasterRender() )
{
//raster rendering is forced for this layer
return true;
}
if ( mSettings.testFlag( QgsMapSettings::UseAdvancedEffects ) &&
(( vl->blendMode() != QPainter::CompositionMode_SourceOver )
|| ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver )
|| ( vl->layerTransparency() != 0 ) ) )
{
//layer properties require rasterisation
return true;
}
}
return false;
}
示例12: addLayerProjectSettings
void QgsServerProjectParser::addLayerProjectSettings( QDomElement& layerElem, QDomDocument& doc, QgsMapLayer* currentLayer ) const
{
if ( !currentLayer )
{
return;
}
// Layer tree name
QDomElement treeNameElem = doc.createElement( "TreeName" );
QDomText treeNameText = doc.createTextNode( currentLayer->name() );
treeNameElem.appendChild( treeNameText );
layerElem.appendChild( treeNameElem );
if ( currentLayer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vLayer = static_cast<QgsVectorLayer*>( currentLayer );
const QSet<QString>& excludedAttributes = vLayer->excludeAttributesWms();
int displayFieldIdx = -1;
QString displayField = "maptip";
QgsExpression exp( vLayer->displayExpression() );
if ( exp.isField() )
{
displayField = static_cast<const QgsExpression::NodeColumnRef*>( exp.rootNode() )->name();
displayFieldIdx = vLayer->fieldNameIndex( displayField );
}
//attributes
QDomElement attributesElem = doc.createElement( "Attributes" );
const QgsFields& layerFields = vLayer->pendingFields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
QgsField field = layerFields.at( idx );
if ( excludedAttributes.contains( field.name() ) )
{
continue;
}
// field alias in case of displayField
if ( idx == displayFieldIdx )
{
displayField = vLayer->attributeDisplayName( idx );
}
QDomElement attributeElem = doc.createElement( "Attribute" );
attributeElem.setAttribute( "name", field.name() );
attributeElem.setAttribute( "type", QVariant::typeToName( field.type() ) );
attributeElem.setAttribute( "typeName", field.typeName() );
QString alias = vLayer->attributeAlias( idx );
if ( !alias.isEmpty() )
{
attributeElem.setAttribute( "alias", alias );
}
//edit type to text
attributeElem.setAttribute( "editType", vLayer->editFormConfig()->widgetType( idx ) );
attributeElem.setAttribute( "comment", field.comment() );
attributeElem.setAttribute( "length", field.length() );
attributeElem.setAttribute( "precision", field.precision() );
attributesElem.appendChild( attributeElem );
}
//displayfield
layerElem.setAttribute( "displayField", displayField );
//geometry type
layerElem.setAttribute( "geometryType", QgsWkbTypes::displayString( vLayer->wkbType() ) );
layerElem.appendChild( attributesElem );
}
}
示例13: QgsDebugMsg
void QgsQuickPrint::scalePointSymbols( int theScaleFactor, SymbolScalingType theDirection )
{
if ( 0 >= theScaleFactor )
{
QgsDebugMsg( "invalid scale factor" );
return;
}
QStringList myLayerSet = mpMapRenderer->layerSet();
QStringListIterator myLayerIterator( myLayerSet );
while ( myLayerIterator.hasNext() )
{
QString myLayerId = myLayerIterator.next();
QgsDebugMsg( "Scaling point symbols for print for " + myLayerId );
QgsMapLayer * mypLayer =
QgsMapLayerRegistry::instance()->mapLayer( myLayerId );
if ( mypLayer )
{
QgsVectorLayer *mypVectorLayer =
qobject_cast<QgsVectorLayer *>( mypLayer );
if ( mypVectorLayer )
{
const QgsRenderer* mypRenderer = mypVectorLayer->renderer();
const QList<QgsSymbol*> mySymbolList = mypRenderer->symbols();
//
// Single symbol
//
if ( 1 == mySymbolList.size() )
{
QgsSymbol * mypSymbol = mySymbolList.at( 0 );
if ( mypSymbol->type() == QGis::Point )
{
if ( theDirection == ScaleUp )
{
mypSymbol->setPointSize( mypSymbol->pointSize() * theScaleFactor );
}
else //Scale Down
{
mypSymbol->setPointSize( mypSymbol->pointSize() / theScaleFactor );
}
}
}
else //class breaks
{
QListIterator<QgsSymbol *> myIterator( mySymbolList );
while ( myIterator.hasNext() )
{
QgsSymbol * mypSymbol = myIterator.next();
if ( mypSymbol->type() == QGis::Point )
{
if ( theDirection == ScaleUp )
{
mypSymbol->setPointSize( mypSymbol->pointSize() * theScaleFactor );
}
else //Scale Down
{
mypSymbol->setPointSize( mypSymbol->pointSize() / theScaleFactor );
}
}
} //symbol loop
} //class breaks
} //if vectorlayer
} //if maplayer
} //layer iterator
}
示例14: myPrinter
//.........这里部分代码省略.........
// drawn into it will appear squashed), but a different origin.
QRect myOriginalViewport = myPrintPainter.viewport(); //for restoring later
myOriginX += myMapDimensionX + myHorizontalSpacing;
myPrintPainter.setViewport( myOriginX,
myOriginY,
myOriginalViewport.width(),
myOriginalViewport.height() );
//draw a rectangale around the legend frame
//@TODO make this user settable
if ( 0 == 1 ) //put some real logic here
{
myPrintPainter.drawRect( 0, 0, myLegendDimensionX, myLegendDimensionY );
}
//get font metric and other vars needed
QFontMetrics myLegendFontMetrics( myLegendFont, &myPrinter );
int myLegendFontHeight = myLegendFontMetrics.height();
int myLegendXPos = 0;
int myLegendYPos = 0;
int myLegendSpacer = myLegendFontHeight / 2; //for vertical and horizontal spacing
int myLegendVerticalSpacer = myLegendFontHeight / 3; //for vertical between rows
int myIconWidth = myLegendFontHeight;
myPrintPainter.setFont( myLegendFont );
QStringList myLayerSet = mpMapRenderer->layerSet();
QStringListIterator myLayerIterator( myLayerSet );
//second clause below is to prevent legend spilling out the bottom
while ( myLayerIterator.hasNext() &&
myLegendYPos < myLegendDimensionY )
{
QString myLayerId = myLayerIterator.next();
QgsMapLayer * mypLayer =
QgsMapLayerRegistry::instance()->mapLayer( myLayerId );
if ( mypLayer )
{
QgsVectorLayer *mypVectorLayer =
qobject_cast<QgsVectorLayer *>( mypLayer );
// TODO: add support for symbology-ng renderers
if ( mypVectorLayer && mypVectorLayer->renderer() )
{
QString myLayerName = mypVectorLayer->name();
QIcon myIcon;
QPixmap myPixmap( QSize( myIconWidth, myIconWidth ) ); //square
//based on code from qgslegendlayer.cpp - see that file for more info
const QgsRenderer* mypRenderer = mypVectorLayer->renderer();
const QList<QgsSymbol*> mySymbolList = mypRenderer->symbols();
//
// Single symbol
//
double widthScale = ( myPrinter.logicalDpiX() + myPrinter.logicalDpiY() ) / 2.0 / 25.4;
if ( 1 == mySymbolList.size() )
{
QgsSymbol * mypSymbol = mySymbolList.at( 0 );
myPrintPainter.setPen( mypSymbol->pen() );
myPrintPainter.setBrush( mypSymbol->brush() );
myLegendXPos = 0 ;
if ( mypSymbol->type() == QGis::Point )
{
QImage myImage;
myImage = mypSymbol->getPointSymbolAsImage( widthScale );
myPrintPainter.drawImage( myLegendXPos, myLegendYPos, myImage );
}
else if ( mypSymbol->type() == QGis::Line )
{
myPrintPainter.drawLine( myLegendXPos, myLegendYPos,
myLegendXPos + myIconWidth,
myLegendYPos + myIconWidth );
示例15: makeGraph
void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPoint >& additionalPoints,
QVector< QgsPoint >& tiedPoint ) const
{
QgsVectorLayer *vl = mVectorLayer;
if ( vl == NULL )
return;
int featureCount = ( int ) vl->featureCount() * 2;
int step = 0;
QgsCoordinateTransform ct;
ct.setSourceCrs( vl->crs() );
if ( builder->coordinateTransformationEnabled() )
{
ct.setDestCRS( builder->destinationCrs() );
}
else
{
ct.setDestCRS( vl->crs() );
}
tiedPoint = QVector< QgsPoint >( additionalPoints.size(), QgsPoint( 0.0, 0.0 ) );
TiePointInfo tmpInfo;
tmpInfo.mLength = std::numeric_limits<double>::infinity();
QVector< TiePointInfo > pointLengthMap( additionalPoints.size(), tmpInfo );
QVector< TiePointInfo >::iterator pointLengthIt;
//Graph's points;
QVector< QgsPoint > points;
QgsFeatureIterator fit = vl->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() ) );
// begin: tie points to the graph
QgsAttributeList la;
QgsFeature feature;
while ( fit.nextFeature( feature ) )
{
QgsMultiPolyline mpl;
if ( feature.constGeometry()->wkbType() == QGis::WKBMultiLineString )
mpl = feature.constGeometry()->asMultiPolyline();
else if ( feature.constGeometry()->wkbType() == QGis::WKBLineString )
mpl.push_back( feature.constGeometry()->asPolyline() );
QgsMultiPolyline::iterator mplIt;
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
{
QgsPoint pt1, pt2;
bool isFirstPoint = true;
QgsPolyline::iterator pointIt;
for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
{
pt2 = ct.transform( *pointIt );
points.push_back( pt2 );
if ( !isFirstPoint )
{
int i = 0;
for ( i = 0; i != additionalPoints.size(); ++i )
{
TiePointInfo info;
if ( pt1 == pt2 )
{
info.mLength = additionalPoints[ i ].sqrDist( pt1 );
info.mTiedPoint = pt1;
}
else
{
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(),
pt2.x(), pt2.y(), info.mTiedPoint );
}
if ( pointLengthMap[ i ].mLength > info.mLength )
{
Q_UNUSED( info.mTiedPoint );
info.mFirstPoint = pt1;
info.mLastPoint = pt2;
pointLengthMap[ i ] = info;
tiedPoint[ i ] = info.mTiedPoint;
}
}
}
pt1 = pt2;
isFirstPoint = false;
}
}
emit buildProgress( ++step, featureCount );
}
// end: tie points to graph
// add tied point to graph
int i = 0;
for ( i = 0; i < tiedPoint.size(); ++i )
{
if ( tiedPoint[ i ] != QgsPoint( 0.0, 0.0 ) )
{
points.push_back( tiedPoint [ i ] );
//.........这里部分代码省略.........