本文整理汇总了C++中QgsVectorLayer::setRenderer方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::setRenderer方法的具体用法?C++ QgsVectorLayer::setRenderer怎么用?C++ QgsVectorLayer::setRenderer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::setRenderer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readXML
int QgsUniqueValueRenderer::readXML( const QDomNode& rnode, QgsVectorLayer& vl )
{
mGeometryType = vl.geometryType();
QDomNode classnode = rnode.namedItem( "classificationfield" );
QString classificationField = classnode.toElement().text();
QgsVectorDataProvider* theProvider = vl.dataProvider();
if ( !theProvider )
{
return 1;
}
int classificationId = vl.fieldNameIndex( classificationField );
if ( classificationId == -1 )
{
//go on. Because with joins, it might be the joined layer is not loaded yet
}
setClassificationField( classificationId );
QDomNode symbolnode = rnode.namedItem( "symbol" );
while ( !symbolnode.isNull() )
{
QgsSymbol* msy = new QgsSymbol( mGeometryType );
msy->readXML( symbolnode, &vl );
insertValue( msy->lowerValue(), msy );
symbolnode = symbolnode.nextSibling();
}
updateSymbolAttributes();
vl.setRenderer( this );
return 0;
}
示例2: readXML
int QgsContinuousColorRenderer::readXML( const QDomNode& rnode, QgsVectorLayer& vl )
{
mGeometryType = vl.geometryType();
QDomNode classnode = rnode.namedItem( "classificationfield" );
QString classificationField = classnode.toElement().text();
QgsVectorDataProvider* theProvider = vl.dataProvider();
if ( !theProvider )
{
return 1;
}
int classificationId = vl.fieldNameIndex( classificationField );
if ( classificationId == -1 )
{
//go on. Because with joins, it might be the joined layer is not loaded yet
}
setClassificationField( classificationId );
//polygon outline
QDomNode polyoutlinenode = rnode.namedItem( "polygonoutline" );
QString polyoutline = polyoutlinenode.toElement().text();
if ( polyoutline == "0" )
{
mDrawPolygonOutline = false;
}
else if ( polyoutline == "1" )
{
mDrawPolygonOutline = true;
}
//read the settings for the renderitem of the minimum value
QDomNode lowernode = rnode.namedItem( "lowestsymbol" );
QDomNode lsymbolnode = lowernode.namedItem( "symbol" );
if ( ! lsymbolnode.isNull() )
{
QgsSymbol* lsy = new QgsSymbol( mGeometryType );
lsy->readXML( lsymbolnode, &vl );
setMinimumSymbol( lsy );
}
QDomNode uppernode = rnode.namedItem( "highestsymbol" );
QDomNode usymbolnode = uppernode.namedItem( "symbol" );
if ( ! usymbolnode.isNull() )
{
QgsSymbol* usy = new QgsSymbol( mGeometryType );
usy->readXML( usymbolnode, &vl );
setMaximumSymbol( usy );
}
vl.setRenderer( this );
return 0;
}
示例3: readXML
int QgsGraduatedSymbolRenderer::readXML( const QDomNode& rnode, QgsVectorLayer& vl )
{
mGeometryType = vl.geometryType();
QDomNode modeNode = rnode.namedItem( "mode" );
QString modeValue = modeNode.toElement().text();
QDomNode classnode = rnode.namedItem( "classificationfield" );
QString classificationField = classnode.toElement().text();
QgsVectorDataProvider* theProvider = vl.dataProvider();
if ( !theProvider )
{
return 1;
}
if ( modeValue == "Empty" )
{
mMode = QgsGraduatedSymbolRenderer::Empty;
}
else if ( modeValue == "Quantile" )
{
mMode = QgsGraduatedSymbolRenderer::Quantile;
}
else //default
{
mMode = QgsGraduatedSymbolRenderer::EqualInterval;
}
int classificationId = theProvider->fieldNameIndex( classificationField );
if ( classificationId == -1 )
{
return 2; //@todo: handle gracefully in gui situation where user needs to nominate field
}
setClassificationField( classificationId );
QDomNode symbolnode = rnode.namedItem( "symbol" );
while ( !symbolnode.isNull() )
{
QgsSymbol* sy = new QgsSymbol( mGeometryType );
sy->readXML( symbolnode, &vl );
addSymbol( sy );
symbolnode = symbolnode.nextSibling();
}
updateSymbolAttributes();
vl.setRenderer( this );
return 0;
}
示例4: readXML
int QgsGraduatedSymbolRenderer::readXML( const QDomNode& rnode, QgsVectorLayer& vl )
{
mGeometryType = vl.geometryType();
QDomNode modeNode = rnode.namedItem( "mode" );
QString modeValue = modeNode.toElement().text();
QDomNode classnode = rnode.namedItem( "classificationfield" );
QString classificationField = classnode.toElement().text();
QgsVectorDataProvider* theProvider = vl.dataProvider();
if ( !theProvider )
{
return 1;
}
if ( modeValue == "Empty" )
{
mMode = QgsGraduatedSymbolRenderer::Empty;
}
else if ( modeValue == "Quantile" )
{
mMode = QgsGraduatedSymbolRenderer::Quantile;
}
else //default
{
mMode = QgsGraduatedSymbolRenderer::EqualInterval;
}
int classificationId = vl.fieldNameIndex( classificationField );
if ( classificationId == -1 )
{
//go on. Because with joins, it might be the joined layer is not loaded yet
}
setClassificationField( classificationId );
QDomNode symbolnode = rnode.namedItem( "symbol" );
while ( !symbolnode.isNull() )
{
QgsSymbol* sy = new QgsSymbol( mGeometryType );
sy->readXML( symbolnode, &vl );
addSymbol( sy );
symbolnode = symbolnode.nextSibling();
}
updateSymbolAttributes();
vl.setRenderer( this );
return 0;
}
示例5: main
int main(int argc, char ** argv)
{
// Start the Application
QgsApplication app(argc, argv, true);
QString myPluginsDir = "/home/timlinux/apps/lib/qgis";
QString myLayerPath = "/home/timlinux/gisdata/brazil/BR_Cidades/";
QString myLayerBaseName = "Brasil_Cap";
QString myProviderName = "ogr";
// Instantiate Provider Registry
QgsProviderRegistry::instance(myPluginsDir);
// create a maplayer instance
QgsVectorLayer * mypLayer =
new QgsVectorLayer(myLayerPath, myLayerBaseName, myProviderName);
QgsSingleSymbolRenderer *mypRenderer = new QgsSingleSymbolRenderer(mypLayer->geometryType());
QList <QgsMapCanvasLayer> myLayerSet;
mypLayer->setRenderer(mypRenderer);
if (mypLayer->isValid())
{
qDebug("Layer is valid");
}
else
{
qDebug("Layer is NOT valid");
}
// Add the Vector Layer to the Layer Registry
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer, TRUE);
// Add the Layer to the Layer Set
myLayerSet.append(QgsMapCanvasLayer(mypLayer, TRUE));
// Create the Map Canvas
QgsMapCanvas * mypMapCanvas = new QgsMapCanvas(0, 0);
mypMapCanvas->setExtent(mypLayer->extent());
mypMapCanvas->enableAntiAliasing(true);
mypMapCanvas->setCanvasColor(QColor(255, 255, 255));
mypMapCanvas->freeze(false);
// Set the Map Canvas Layer Set
mypMapCanvas->setLayerSet(myLayerSet);
mypMapCanvas->setVisible(true);
mypMapCanvas->refresh();
// Start the Application Event Loop
return app.exec();
}
示例6: readXML
int QgsSingleSymbolRenderer::readXML( const QDomNode& rnode, QgsVectorLayer& vl )
{
mGeometryType = vl.geometryType();
QgsSymbol* sy = new QgsSymbol( mGeometryType );
QDomNode synode = rnode.namedItem( "symbol" );
if ( synode.isNull() )
{
QgsDebugMsg( "No symbol node in project file's renderitem Dom" );
// XXX abort?
}
else
{
sy->readXML( synode, &vl );
}
updateSymbolAttributes();
//create a renderer and add it to the vector layer
addSymbol( sy );
vl.setRenderer( this );
return 0;
}
示例7: addLayer
void MainWindow::addLayer()
{
QString myLayerPath = "../data";
QString myLayerBaseName = "test";
QString myProviderName = "ogr";
QgsVectorLayer * mypLayer = new QgsVectorLayer(myLayerPath, myLayerBaseName, myProviderName);
if (mypLayer->isValid())
{
qDebug("Layer is valid");
}
else
{
qDebug("Layer is NOT valid");
return;
}
//set up a renderer for the layer
QgsSingleSymbolRenderer *mypRenderer = new QgsSingleSymbolRenderer(mypLayer->geometryType());
QList<QgsMapCanvasLayer> myLayerSet;
mypLayer->setRenderer(mypRenderer);
//
//set up labelling for the layer
//
//get the label instance associated with the layer
QgsLabel * mypLabel;
mypLabel = mypLayer->label();
//and the label attributes associated with the label
QgsLabelAttributes * mypLabelAttributes;
mypLabelAttributes = mypLabel->layerAttributes();
//note in QGIS 1.4 and up you should use mypLabel->labelAttributes rather
//get the field list associated with the layer
//we'll print the names out to console for diagnostic purposes
QgsFieldMap myFields = mypLayer->dataProvider()->fields();
for (unsigned int i = 0; i < myFields.size(); i++ )
{
qDebug("Field Name: " + QString(myFields[i].name()).toLocal8Bit() );
}
//just use the last field's name in the fields list as the label field!
qDebug("set label field to " + QString(myFields[myFields.size()-1].name()).toLocal8Bit());
mypLabel->setLabelField( QgsLabel::Text, myFields.size()-1);
//set the colour of the label text
mypLabelAttributes->setColor(Qt::black);
//create a 'halo' effect around each label so it
//can still be read on dark backgrounds
mypLabelAttributes->setBufferEnabled(true);
mypLabelAttributes->setBufferColor(Qt::yellow);
int myType = QgsLabelAttributes::PointUnits;
mypLabelAttributes->setBufferSize(1,myType);
/*
* Here are a bunch of other things you can set based on values on a database field
* the second parameter in each case would be the field name from which the
* attribute can be retrieved.
mypLabel->setLabelField( QgsLabel::Family, "fontFamily" );
mypLabel->setLabelField( QgsLabel::Bold, "fontIsBold" );
mypLabel->setLabelField( QgsLabel::Italic, "fontIsItalic" );
mypLabel->setLabelField( QgsLabel::Underline, "fontIsUnderlined" );
mypLabel->setLabelField( QgsLabel::Size, "fontSize" );
mypLabel->setLabelField( QgsLabel::BufferSize,"fontBufferSize" );
mypLabel->setLabelField( QgsLabel::XCoordinate, "labelX" );
mypLabel->setLabelField( QgsLabel::YCoordinate, "labelY");
mypLabel->setLabelField( QgsLabel::XOffset, "labelXOffset");
mypLabel->setLabelField( QgsLabel::YOffset, "labelYOffset");
mypLabel->setLabelField( QgsLabel::Alignment, "labelAlignment" );
mypLabel->setLabelField( QgsLabel::Angle, "labelAngle");
*/
//lastly we enable labelling!
mypLayer->enableLabels(true);
// Add the Vector Layer to the Layer Registry
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer, TRUE);
// Add the Layer to the Layer Set
myLayerSet.append(QgsMapCanvasLayer( mypLayer ) );
// set teh canvas to the extent of our layer
mpMapCanvas->setExtent(mypLayer->extent());
// Set the Map Canvas Layer Set
mpMapCanvas->setLayerSet(myLayerSet);
}
示例8: createGroup
void QgsDwgImportDialog::createGroup( QgsLayerTreeGroup *group, const QString &name, const QStringList &layers, bool visible )
{
QgsLayerTreeGroup *layerGroup = group->addGroup( name );
QgsDebugMsg( QStringLiteral( " %1" ).arg( name ) ) ;
Q_ASSERT( layerGroup );
QString layerFilter;
if ( !layers.isEmpty() )
{
QStringList exprlist;
const auto constLayers = layers;
for ( QString layer : constLayers )
{
exprlist.append( QStringLiteral( "'%1'" ).arg( layer.replace( QLatin1String( "'" ), QLatin1String( "''" ) ) ) );
}
layerFilter = QStringLiteral( "layer IN (%1) AND " ).arg( exprlist.join( QStringLiteral( "," ) ) );
}
QgsVectorLayer *l = nullptr;
QgsSymbol *sym = nullptr;
l = layer( layerGroup, layerFilter, QStringLiteral( "hatches" ) );
if ( l )
{
QgsSimpleFillSymbolLayer *sfl = new QgsSimpleFillSymbolLayer();
sfl->setDataDefinedProperty( QgsSymbolLayer::PropertyFillColor, QgsProperty::fromField( QStringLiteral( "color" ) ) );
sfl->setStrokeStyle( Qt::NoPen );
sym = new QgsFillSymbol();
sym->changeSymbolLayer( 0, sfl );
l->setRenderer( new QgsSingleSymbolRenderer( sym ) );
}
l = layer( layerGroup, layerFilter, QStringLiteral( "lines" ) );
if ( l )
{
QgsSimpleLineSymbolLayer *sll = new QgsSimpleLineSymbolLayer();
sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeColor, QgsProperty::fromField( QStringLiteral( "color" ) ) );
sll->setPenJoinStyle( Qt::MiterJoin );
sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeWidth, QgsProperty::fromField( QStringLiteral( "linewidth" ) ) );
// sll->setUseCustomDashPattern( true );
// sll->setCustomDashPatternUnit( QgsSymbolV2::MapUnit );
// sll->setDataDefinedProperty( QgsSymbolLayer::PropertyCustomDash, QgsProperty::fromField( "linetype" ) );
sym = new QgsLineSymbol();
sym->changeSymbolLayer( 0, sll );
sym->setOutputUnit( QgsUnitTypes::RenderMillimeters );
l->setRenderer( new QgsSingleSymbolRenderer( sym ) );
}
l = layer( layerGroup, layerFilter, QStringLiteral( "polylines" ) );
if ( l )
{
sym = new QgsLineSymbol();
QgsSimpleLineSymbolLayer *sll = new QgsSimpleLineSymbolLayer();
sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeColor, QgsProperty::fromField( QStringLiteral( "color" ) ) );
sll->setPenJoinStyle( Qt::MiterJoin );
sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeWidth, QgsProperty::fromField( QStringLiteral( "width" ) ) );
sll->setDataDefinedProperty( QgsSymbolLayer::PropertyLayerEnabled, QgsProperty::fromExpression( QStringLiteral( "width>0" ) ) );
sll->setOutputUnit( QgsUnitTypes::RenderMapUnits );
// sll->setUseCustomDashPattern( true );
// sll->setCustomDashPatternUnit( QgsSymbolV2::MapUnit );
// sll->setDataDefinedProperty( QgsSymbolLayer::PropertyCustomDash, QgsProperty::fromField( "linetype" ) );
sym->changeSymbolLayer( 0, sll );
sll = new QgsSimpleLineSymbolLayer();
sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeColor, QgsProperty::fromField( QStringLiteral( "color" ) ) );
sll->setPenJoinStyle( Qt::MiterJoin );
sll->setDataDefinedProperty( QgsSymbolLayer::PropertyStrokeWidth, QgsProperty::fromField( QStringLiteral( "linewidth" ) ) );
sll->setDataDefinedProperty( QgsSymbolLayer::PropertyLayerEnabled, QgsProperty::fromExpression( QStringLiteral( "width=0" ) ) );
sll->setOutputUnit( QgsUnitTypes::RenderMillimeters );
sym->appendSymbolLayer( sll );
l->setRenderer( new QgsSingleSymbolRenderer( sym ) );
}
l = layer( layerGroup, layerFilter, QStringLiteral( "texts" ) );
if ( l )
{
l->setRenderer( new QgsNullSymbolRenderer() );
QgsTextFormat tf;
tf.setSizeUnit( QgsUnitTypes::RenderMapUnits );
QgsPalLayerSettings pls;
pls.setFormat( tf );
pls.drawLabels = true;
pls.fieldName = QStringLiteral( "text" );
pls.wrapChar = QStringLiteral( "\\P" );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Size, QgsProperty::fromField( QStringLiteral( "height" ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Color, QgsProperty::fromField( QStringLiteral( "color" ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::MultiLineHeight, QgsProperty::fromExpression( QStringLiteral( "CASE WHEN interlin<0 THEN 1 ELSE interlin*1.5 END" ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::PositionX, QgsProperty::fromExpression( QStringLiteral( "$x" ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::PositionY, QgsProperty::fromExpression( QStringLiteral( "$y" ) ) );
// DXF TEXT
// vertical: 0 = Base, 1 = Bottom, 2 = Middle, 3 = Top, default Base
// horizontal: 0 = Left, 1 = Center, 2 = Right, 3 = Aligned (if Base), 4 = Middle (if Base), default Left
//.........这里部分代码省略.........