本文整理汇总了C++中QgsVectorLayer::isModified方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::isModified方法的具体用法?C++ QgsVectorLayer::isModified怎么用?C++ QgsVectorLayer::isModified使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::isModified方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateIcon
void QgsLegendLayer::updateIcon()
{
QPixmap newIcon( getOriginalPixmap() );
QgsMapLayer* theLayer = layer();
//overview
// FIXME: overview icon is missing
/*
if ( theFile->isInOverview() )
{
// Overlay the overview icon on the default icon
QPixmap myPixmap = QgsApplication::getThemePixmap( "/mIconOverview.png" );
QPainter p( &newIcon );
p.drawPixmap( 0, 0, myPixmap );
p.end();
}*/
//editable
if ( theLayer->isEditable() )
{
QPixmap myPixmap;
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( theLayer );
if ( vlayer->isModified() )
{
myPixmap = QgsApplication::getThemePixmap( "/mIconEditableEdits.png" );
}
else
{
myPixmap = QgsApplication::getThemePixmap( "/mIconEditable.png" );
}
// use editable icon instead of the layer's type icon
newIcon = myPixmap;
// Overlay the editable icon on the default icon
/*QPainter p( &newIcon );
p.drawPixmap( 0, 0, myPixmap );
p.end();*/
}
// TODO: projection error icon?
QIcon theIcon( newIcon );
QgsLegend* l = legend();
if ( l )
{
l->blockSignals( true ); //prevent unnecessary canvas redraw
}
setIcon( 0, theIcon );
if ( l )
{
l->blockSignals( false );
}
}
示例2: layersModified
bool QgsLayerTreeUtils::layersModified( const QList<QgsLayerTreeLayer *> &layerNodes )
{
const auto constLayerNodes = layerNodes;
for ( QgsLayerTreeLayer *layerNode : constLayerNodes )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layerNode->layer() );
if ( !vl )
continue;
if ( vl->isEditable() && vl->isModified() )
return true;
}
return false;
}
示例3: addToPopupMenu
void QgsLegendLayer::addToPopupMenu( QMenu& theMenu )
{
QgsMapLayer *lyr = layer();
QAction *toggleEditingAction = QgisApp::instance()->actionToggleEditing();
QAction *saveLayerEditsAction = QgisApp::instance()->actionSaveActiveLayerEdits();
QAction *allEditsAction = QgisApp::instance()->actionAllEdits();
// zoom to layer extent
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionZoomToLayer.svg" ),
tr( "&Zoom to Layer Extent" ), legend(), SLOT( legendLayerZoom() ) );
if ( lyr->type() == QgsMapLayer::RasterLayer )
{
theMenu.addAction( tr( "&Zoom to Best Scale (100%)" ), legend(), SLOT( legendLayerZoomNative() ) );
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( lyr );
if ( rasterLayer && rasterLayer->rasterType() != QgsRasterLayer::Palette )
{
theMenu.addAction( tr( "&Stretch Using Current Extent" ), legend(), SLOT( legendLayerStretchUsingCurrentExtent() ) );
}
}
// show in overview
QAction* showInOverviewAction = theMenu.addAction( tr( "&Show in Overview" ), this, SLOT( showInOverview() ) );
showInOverviewAction->setCheckable( true );
showInOverviewAction->blockSignals( true );
showInOverviewAction->setChecked( mLyr.isInOverview() );
showInOverviewAction->blockSignals( false );
// remove from canvas
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionRemoveLayer.svg" ), tr( "&Remove" ), QgisApp::instance(), SLOT( removeLayer() ) );
// duplicate layer
QAction* duplicateLayersAction = theMenu.addAction( QgsApplication::getThemeIcon( "/mActionDuplicateLayer.svg" ), tr( "&Duplicate" ), QgisApp::instance(), SLOT( duplicateLayers() ) );
// set layer crs
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set Layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );
// assign layer crs to project
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionSetProjectCRS.png" ), tr( "Set &Project CRS from Layer" ), QgisApp::instance(), SLOT( setProjectCRSFromLayer() ) );
theMenu.addSeparator();
if ( lyr->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( lyr );
// attribute table
theMenu.addAction( QgsApplication::getThemeIcon( "/mActionOpenTable.png" ), tr( "&Open Attribute Table" ),
QgisApp::instance(), SLOT( attributeTable() ) );
// allow editing
int cap = vlayer->dataProvider()->capabilities();
if ( cap & QgsVectorDataProvider::EditingCapabilities )
{
if ( toggleEditingAction )
{
theMenu.addAction( toggleEditingAction );
toggleEditingAction->setChecked( vlayer->isEditable() );
}
if ( saveLayerEditsAction && vlayer->isModified() )
{
theMenu.addAction( saveLayerEditsAction );
}
}
if ( allEditsAction->isEnabled() )
{
theMenu.addAction( allEditsAction );
}
// disable duplication of memory layers
if ( vlayer->storageType() == "Memory storage" && legend()->selectedLayers().count() == 1 )
{
duplicateLayersAction->setEnabled( false );
}
// save as vector file
theMenu.addAction( tr( "Save As..." ), QgisApp::instance(), SLOT( saveAsFile() ) );
// save selection as vector file
QAction* saveSelectionAsAction = theMenu.addAction( tr( "Save Selection As..." ), QgisApp::instance(), SLOT( saveSelectionAsVectorFile() ) );
if ( vlayer->selectedFeatureCount() == 0 )
{
saveSelectionAsAction->setEnabled( false );
}
if ( !vlayer->isEditable() && vlayer->dataProvider()->supportsSubsetString() && vlayer->vectorJoins().isEmpty() )
theMenu.addAction( tr( "&Filter..." ), QgisApp::instance(), SLOT( layerSubsetString() ) );
//show number of features in legend if requested
QAction* showNFeaturesAction = new QAction( tr( "Show Feature Count" ), &theMenu );
showNFeaturesAction->setCheckable( true );
showNFeaturesAction->setChecked( mShowFeatureCount );
QObject::connect( showNFeaturesAction, SIGNAL( toggled( bool ) ), this, SLOT( setShowFeatureCount( bool ) ) );
theMenu.addAction( showNFeaturesAction );
theMenu.addSeparator();
}
示例4: data
QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
{
if ( !index.isValid() )
return QVariant();
if ( QgsLayerTreeModelLegendNode* sym = index2symnode( index ) )
{
if ( role == Qt::CheckStateRole && !testFlag( AllowSymbologyChangeState ) )
return QVariant();
return sym->data( role );
}
QgsLayerTreeNode* node = index2node( index );
if ( role == Qt::DisplayRole || role == Qt::EditRole )
{
if ( QgsLayerTree::isGroup( node ) )
return QgsLayerTree::toGroup( node )->name();
else if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
QString name = nodeLayer->layerName();
if ( nodeLayer->customProperty( "showFeatureCount", 0 ).toInt() && role == Qt::DisplayRole )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( nodeLayer->layer() );
if ( vlayer && vlayer->pendingFeatureCount() >= 0 )
name += QString( " [%1]" ).arg( vlayer->pendingFeatureCount() );
}
return name;
}
}
else if ( role == Qt::DecorationRole && index.column() == 0 )
{
if ( QgsLayerTree::isGroup( node ) )
return iconGroup();
else if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
// if there's just on legend entry that should be embedded in layer - do that!
if ( testFlag( ShowSymbology ) && mSymbologyNodes[nodeLayer].count() == 1 && mSymbologyNodes[nodeLayer][0]->isEmbeddedInParent() )
return mSymbologyNodes[nodeLayer][0]->data( Qt::DecorationRole );
QgsMapLayer* layer = QgsLayerTree::toLayer( node )->layer();
if ( !layer )
return QVariant();
if ( layer->type() == QgsMapLayer::RasterLayer )
{
if ( testFlag( ShowRasterPreviewIcon ) )
{
QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( layer );
return QIcon( rlayer->previewAsPixmap( QSize( 32, 32 ) ) );
}
else
return QgsLayerItem::iconRaster();
}
else if ( layer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vlayer = static_cast<QgsVectorLayer*>( layer );
if ( vlayer->isEditable() )
{
if ( vlayer->isModified() )
return QIcon( QgsApplication::getThemePixmap( "/mIconEditableEdits.png" ) );
else
return QIcon( QgsApplication::getThemePixmap( "/mIconEditable.png" ) );
}
if ( vlayer->geometryType() == QGis::Point )
return QgsLayerItem::iconPoint();
else if ( vlayer->geometryType() == QGis::Line )
return QgsLayerItem::iconLine();
else if ( vlayer->geometryType() == QGis::Polygon )
return QgsLayerItem::iconPolygon();
else if ( vlayer->geometryType() == QGis::NoGeometry )
return QgsLayerItem::iconTable();
}
return QgsLayerItem::iconDefault();
}
}
else if ( role == Qt::CheckStateRole )
{
if ( !testFlag( AllowNodeChangeVisibility ) )
return QVariant();
if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
if ( nodeLayer->layer() && nodeLayer->layer()->type() == QgsMapLayer::VectorLayer )
{
if ( qobject_cast<QgsVectorLayer*>( nodeLayer->layer() )->geometryType() == QGis::NoGeometry )
return QVariant(); // do not show checkbox for non-spatial tables
}
return nodeLayer->isVisible();
}
else if ( QgsLayerTree::isGroup( node ) )
{
QgsLayerTreeGroup* nodeGroup = QgsLayerTree::toGroup( node );
return nodeGroup->isVisible();
}
}
else if ( role == Qt::FontRole )
//.........这里部分代码省略.........
示例5: data
QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
{
if ( !index.isValid() || index.column() > 1 )
return QVariant();
if ( QgsLayerTreeModelLegendNode* sym = index2legendNode( index ) )
return legendNodeData( sym, role );
QgsLayerTreeNode* node = index2node( index );
if ( role == Qt::DisplayRole || role == Qt::EditRole )
{
if ( QgsLayerTree::isGroup( node ) )
return QgsLayerTree::toGroup( node )->name();
if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
QString name = nodeLayer->layerName();
if ( nodeLayer->customProperty( "showFeatureCount", 0 ).toInt() && role == Qt::DisplayRole )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( nodeLayer->layer() );
if ( vlayer && vlayer->featureCount() >= 0 )
name += QString( " [%1]" ).arg( vlayer->featureCount() );
}
return name;
}
}
else if ( role == Qt::DecorationRole && index.column() == 0 )
{
if ( QgsLayerTree::isGroup( node ) )
return iconGroup();
if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
QgsMapLayer *layer = nodeLayer->layer();
if ( !layer )
return QVariant();
// icons possibly overriding default icon
if ( layer->type() == QgsMapLayer::RasterLayer )
{
if ( testFlag( ShowRasterPreviewIcon ) )
{
QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( layer );
return QIcon( QPixmap::fromImage( rlayer->previewAsImage( QSize( 32, 32 ) ) ) );
}
else
{
return QgsLayerItem::iconRaster();
}
}
QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer*>( layer );
QIcon icon;
// if there's just on legend entry that should be embedded in layer - do that!
if ( testFlag( ShowLegend ) && legendEmbeddedInParent( nodeLayer ) )
{
icon = legendIconEmbeddedInParent( nodeLayer );
}
else if ( vlayer && layer->type() == QgsMapLayer::VectorLayer )
{
if ( vlayer->geometryType() == QGis::Point )
icon = QgsLayerItem::iconPoint();
else if ( vlayer->geometryType() == QGis::Line )
icon = QgsLayerItem::iconLine();
else if ( vlayer->geometryType() == QGis::Polygon )
icon = QgsLayerItem::iconPolygon();
else if ( vlayer->geometryType() == QGis::NoGeometry )
icon = QgsLayerItem::iconTable();
else
icon = QgsLayerItem::iconDefault();
}
if ( vlayer && vlayer->isEditable() )
{
QPixmap pixmap( icon.pixmap( 16, 16 ) );
QPainter painter( &pixmap );
painter.drawPixmap( 0, 0, 16, 16, QgsApplication::getThemePixmap( vlayer->isModified() ? "/mIconEditableEdits.png" : "/mIconEditable.png" ) );
painter.end();
icon = QIcon( pixmap );
}
return icon;
}
}
else if ( role == Qt::CheckStateRole )
{
if ( !testFlag( AllowNodeChangeVisibility ) )
return QVariant();
if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
if ( nodeLayer->layer() && nodeLayer->layer()->type() == QgsMapLayer::VectorLayer )
{
//.........这里部分代码省略.........
示例6: createContextMenu
QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
{
QMenu* menu = new QMenu;
QgsLayerTreeViewDefaultActions* actions = mView->defaultActions();
QModelIndex idx = mView->currentIndex();
if ( !idx.isValid() )
{
// global menu
menu->addAction( actions->actionAddGroup( menu ) );
// TODO: expand all, collapse all
// TODO: update drawing order
}
else if ( QgsLayerTreeNode* node = mView->layerTreeModel()->index2node( idx ) )
{
// layer or group selected
if ( QgsLayerTree::isGroup( node ) )
{
menu->addAction( actions->actionZoomToGroup( mCanvas, menu ) );
menu->addAction( actions->actionRemoveGroupOrLayer( menu ) );
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ),
tr( "&Set Group CRS" ), QgisApp::instance(), SLOT( legendGroupSetCRS() ) );
menu->addAction( actions->actionRenameGroupOrLayer( menu ) );
if ( mView->selectedNodes( true ).count() >= 2 )
menu->addAction( actions->actionGroupSelected( menu ) );
menu->addAction( actions->actionAddGroup( menu ) );
}
else if ( QgsLayerTree::isLayer( node ) )
{
QgsMapLayer* layer = QgsLayerTree::toLayer( node )->layer();
menu->addAction( actions->actionZoomToLayer( mCanvas, menu ) );
menu->addAction( actions->actionShowInOverview( menu ) );
if ( layer && layer->type() == QgsMapLayer::RasterLayer )
{
menu->addAction( tr( "&Zoom to Best Scale (100%)" ), QgisApp::instance(), SLOT( legendLayerZoomNative() ) );
QgsRasterLayer* rasterLayer = qobject_cast<QgsRasterLayer *>( layer );
if ( rasterLayer && rasterLayer->rasterType() != QgsRasterLayer::Palette )
menu->addAction( tr( "&Stretch Using Current Extent" ), QgisApp::instance(), SLOT( legendLayerStretchUsingCurrentExtent() ) );
}
menu->addAction( actions->actionRemoveGroupOrLayer( menu ) );
// duplicate layer
QAction* duplicateLayersAction = menu->addAction( QgsApplication::getThemeIcon( "/mActionDuplicateLayer.svg" ), tr( "&Duplicate" ), QgisApp::instance(), SLOT( duplicateLayers() ) );
// set layer scale visibility
menu->addAction( tr( "&Set Layer Scale Visibility" ), QgisApp::instance(), SLOT( setLayerScaleVisibility() ) );
// set layer crs
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set Layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );
// assign layer crs to project
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetProjectCRS.png" ), tr( "Set &Project CRS from Layer" ), QgisApp::instance(), SLOT( setProjectCRSFromLayer() ) );
menu->addSeparator();
if ( layer && layer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer );
QAction *toggleEditingAction = QgisApp::instance()->actionToggleEditing();
QAction *saveLayerEditsAction = QgisApp::instance()->actionSaveActiveLayerEdits();
QAction *allEditsAction = QgisApp::instance()->actionAllEdits();
// attribute table
menu->addAction( QgsApplication::getThemeIcon( "/mActionOpenTable.png" ), tr( "&Open Attribute Table" ),
QgisApp::instance(), SLOT( attributeTable() ) );
// allow editing
int cap = vlayer->dataProvider()->capabilities();
if ( cap & QgsVectorDataProvider::EditingCapabilities )
{
if ( toggleEditingAction )
{
menu->addAction( toggleEditingAction );
toggleEditingAction->setChecked( vlayer->isEditable() );
}
if ( saveLayerEditsAction && vlayer->isModified() )
{
menu->addAction( saveLayerEditsAction );
}
}
if ( allEditsAction->isEnabled() )
menu->addAction( allEditsAction );
// disable duplication of memory layers
if ( vlayer->storageType() == "Memory storage" && mView->selectedLayerNodes().count() == 1 )
duplicateLayersAction->setEnabled( false );
// save as vector file
//.........这里部分代码省略.........
示例7: if
//.........这里部分代码省略.........
{
menu->addAction( actions->actionMoveToTop( menu ) );
}
QAction *checkAll = actions->actionCheckAndAllParents( menu );
if ( checkAll )
menu->addAction( checkAll );
if ( mView->selectedNodes( true ).count() >= 2 )
menu->addAction( actions->actionGroupSelected( menu ) );
menu->addSeparator();
if ( vlayer )
{
QAction *toggleEditingAction = QgisApp::instance()->actionToggleEditing();
QAction *saveLayerEditsAction = QgisApp::instance()->actionSaveActiveLayerEdits();
QAction *allEditsAction = QgisApp::instance()->actionAllEdits();
// attribute table
menu->addAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionOpenTable.svg" ) ), tr( "&Open Attribute Table" ),
QgisApp::instance(), SLOT( attributeTable() ) );
// allow editing
int cap = vlayer->dataProvider()->capabilities();
if ( cap & QgsVectorDataProvider::EditingCapabilities )
{
if ( toggleEditingAction )
{
menu->addAction( toggleEditingAction );
toggleEditingAction->setChecked( vlayer->isEditable() );
toggleEditingAction->setEnabled( true );
}
if ( saveLayerEditsAction && vlayer->isModified() )
{
menu->addAction( saveLayerEditsAction );
}
}
if ( allEditsAction->isEnabled() )
menu->addAction( allEditsAction );
// disable duplication of memory layers
if ( vlayer->storageType() == QLatin1String( "Memory storage" ) && mView->selectedLayerNodes().count() == 1 )
duplicateLayersAction->setEnabled( false );
if ( vlayer->dataProvider()->supportsSubsetString() )
{
QAction *action = menu->addAction( tr( "&Filter…" ), QgisApp::instance(), SLOT( layerSubsetString() ) );
action->setEnabled( !vlayer->isEditable() );
}
}
menu->addSeparator();
if ( layer && layer->isSpatial() )
{
// set layer scale visibility
menu->addAction( tr( "&Set Layer Scale Visibility…" ), QgisApp::instance(), SLOT( setLayerScaleVisibility() ) );
if ( !layer->isInScaleRange( mCanvas->scale() ) )
menu->addAction( tr( "Zoom to &Visible Scale" ), QgisApp::instance(), SLOT( zoomToLayerScale() ) );
QMenu *menuSetCRS = new QMenu( tr( "Set CRS" ), menu );
// set layer crs
QAction *actionSetLayerCrs = new QAction( tr( "Set Layer CRS…" ), menuSetCRS );