bool QgsTransaction::addLayer( QgsVectorLayer* layer ) { if ( !layer ) return false; if ( layer->isEditable() ) return false; //test if provider supports transactions if ( !layer->dataProvider() || ( layer->dataProvider()->capabilities() & QgsVectorDataProvider::TransactionSupport ) == 0 ) return false; if ( layer->dataProvider()->transaction() ) return false; //connection string not compatible if ( QgsDataSourceURI( layer->source() ).connectionInfo( false ) != mConnString ) { QgsDebugMsg( QString( "Couldn't start transaction because connection string for layer %1 : '%2' does not match '%3'" ).arg( layer->id(), QgsDataSourceURI( layer->source() ).connectionInfo( false ), mConnString ) ); return false; } connect( this, SIGNAL( afterRollback() ), layer->dataProvider(), SIGNAL( dataChanged() ) ); connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( onLayersDeleted( QStringList ) ) ); mLayers.insert( layer ); if ( mTransactionActive ) layer->dataProvider()->setTransaction( this ); return true; }
QgsStatisticalSummaryDockWidget::QgsStatisticalSummaryDockWidget( QWidget *parent ) : QgsDockWidget( parent ) , mLayer( nullptr ) { setupUi( this ); mFieldExpressionWidget->registerExpressionContextGenerator( this ); mLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer ); mFieldExpressionWidget->setFilters( QgsFieldProxyModel::Numeric | QgsFieldProxyModel::String | QgsFieldProxyModel::Date ); mLayerComboBox->setLayer( mLayerComboBox->layer( 0 ) ); mFieldExpressionWidget->setLayer( mLayerComboBox->layer( 0 ) ); connect( mLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( layerChanged( QgsMapLayer* ) ) ); connect( mFieldExpressionWidget, SIGNAL( fieldChanged( QString ) ), this, SLOT( refreshStatistics() ) ); connect( mSelectedOnlyCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( refreshStatistics() ) ); connect( mButtonRefresh, SIGNAL( clicked( bool ) ), this, SLOT( refreshStatistics() ) ); connect( QgsProject::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersRemoved( QStringList ) ) ); QSettings settings; Q_FOREACH ( QgsStatisticalSummary::Statistic stat, mDisplayStats ) { QAction* action = new QAction( QgsStatisticalSummary::displayName( stat ), mOptionsToolButton ); action->setCheckable( true ); bool checked = settings.value( QStringLiteral( "/StatisticalSummaryDock/checked_%1" ).arg( stat ), true ).toBool(); action->setChecked( checked ); action->setData( stat ); mStatsActions.insert( stat, action ); connect( action, SIGNAL( triggered( bool ) ), this, SLOT( statActionTriggered( bool ) ) ); mOptionsToolButton->addAction( action ); }
QgsAtlasComposition::QgsAtlasComposition( QgsComposition* composition ) : mComposition( composition ) , mEnabled( false ) , mHideCoverage( false ) , mFilenamePattern( "'output_'||$feature" ) , mCoverageLayer( 0 ) , mSingleFile( false ) , mSortFeatures( false ) , mSortAscending( true ) , mCurrentFeatureNo( 0 ) , mFilterFeatures( false ) { // declare special columns with a default value QgsExpression::setSpecialColumn( "$page", QVariant(( int )1 ) ); QgsExpression::setSpecialColumn( "$feature", QVariant(( int )0 ) ); QgsExpression::setSpecialColumn( "$numpages", QVariant(( int )1 ) ); QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )0 ) ); QgsExpression::setSpecialColumn( "$atlasfeatureid", QVariant(( int )0 ) ); QgsExpression::setSpecialColumn( "$atlasfeature", QVariant::fromValue( QgsFeature() ) ); QgsExpression::setSpecialColumn( "$atlasgeometry", QVariant::fromValue( QgsGeometry() ) ); //listen out for layer removal connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) ); }
//introduced in 1.8 void QgsMapLayerRegistry::removeMapLayers( QStringList theLayerIds ) { if ( theLayerIds.isEmpty() ) { return; } emit layersWillBeRemoved( theLayerIds ); foreach ( const QString &myId, theLayerIds ) { QgsMapLayer* lyr = mMapLayers[myId]; if ( mOwnedLayers.contains( lyr ) ) { emit layerWillBeRemoved( myId ); if ( lyr == mRedliningLayer ) { mRedliningLayer = nullptr; } else if ( lyr == mGpsRoutesLayer ) { mGpsRoutesLayer = nullptr; } delete lyr; mOwnedLayers.remove( lyr ); } mMapLayers.remove( myId ); emit layerRemoved( myId ); }
QgsGeometryCheckerSetupTab::QgsGeometryCheckerSetupTab( QgisInterface* iface , QWidget *parent ) : QWidget( parent ), mIface( iface ) { ui.setupUi( this ); ui.progressBar->hide(); ui.labelStatus->hide(); ui.comboBoxInputLayer->setFilters( QgsMapLayerProxyModel::HasGeometry ); mRunButton = ui.buttonBox->addButton( tr( "Run" ), QDialogButtonBox::ActionRole ); mAbortButton = new QPushButton( tr( "Abort" ) ); mRunButton->setEnabled( false ); connect( mRunButton, SIGNAL( clicked() ), this, SLOT( runChecks() ) ); connect( ui.comboBoxInputLayer, SIGNAL( currentIndexChanged( int ) ), this, SLOT( validateInput() ) ); connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( updateLayers() ) ); connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( updateLayers() ) ); connect( ui.radioButtonOutputNew, SIGNAL( toggled( bool ) ), ui.lineEditOutput, SLOT( setEnabled( bool ) ) ); connect( ui.radioButtonOutputNew, SIGNAL( toggled( bool ) ), ui.pushButtonOutputBrowse, SLOT( setEnabled( bool ) ) ); connect( ui.buttonGroupOutput, SIGNAL( buttonClicked( int ) ), this, SLOT( validateInput() ) ); connect( ui.pushButtonOutputBrowse, SIGNAL( clicked() ), this, SLOT( selectOutputFile() ) ); connect( ui.lineEditOutput, SIGNAL( textChanged( QString ) ), this, SLOT( validateInput() ) ); connect( ui.checkBoxSliverPolygons, SIGNAL( toggled( bool ) ), ui.widgetSliverThreshold, SLOT( setEnabled( bool ) ) ); connect( ui.checkBoxSliverArea, SIGNAL( toggled( bool ) ), ui.doubleSpinBoxSliverArea, SLOT( setEnabled( bool ) ) ); updateLayers(); Q_FOREACH ( const QgsGeometryCheckFactory* factory, QgsGeometryCheckFactoryRegistry::getCheckFactories() ) { factory->restorePrevious( ui ); }
QgsMapLayerModel::QgsMapLayerModel( QList<QgsMapLayer *> layers, QObject *parent ) : QAbstractItemModel( parent ) , mLayersChecked( QMap<QString, Qt::CheckState>() ) , mItemCheckable( false ) { connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) ); addLayers( layers ); }
//introduced in 1.8 void QgsMapLayerRegistry::removeMapLayers( QStringList theLayerIds ) { emit layersWillBeRemoved( theLayerIds ); foreach ( const QString &myId, theLayerIds ) { emit layerWillBeRemoved( myId ); delete mMapLayers[myId]; mMapLayers.remove( myId ); }
QgsSnappingUtils::QgsSnappingUtils( QObject* parent ) : QObject( parent ) , mCurrentLayer( 0 ) , mSnapToMapMode( SnapCurrentLayer ) , mStrategy( IndexHybrid ) , mDefaultType( QgsPointLocator::Vertex ) , mDefaultTolerance( 10 ) , mDefaultUnit( QgsTolerance::Pixels ) , mSnapOnIntersection( false ) { connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( onLayersWillBeRemoved( QStringList ) ) ); }
QgsLayerTreeRegistryBridge::QgsLayerTreeRegistryBridge( QgsLayerTreeGroup *root, QObject *parent ) : QObject( parent ) , mRoot( root ) , mEnabled( true ) , mInsertionPointGroup( root ) , mInsertionPointIndex( 0 ) { connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( layersAdded( QList<QgsMapLayer*> ) ) ); connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersWillBeRemoved( QStringList ) ) ); connect( mRoot, SIGNAL( willRemoveChildren( QgsLayerTreeNode*, int, int ) ), this, SLOT( groupWillRemoveChildren( QgsLayerTreeNode*, int, int ) ) ); connect( mRoot, SIGNAL( removedChildren( QgsLayerTreeNode*, int, int ) ), this, SLOT( groupRemovedChildren() ) ); }
QgsAtlasComposition::QgsAtlasComposition( QgsComposition* composition ) : mComposition( composition ) , mEnabled( false ) , mHideCoverage( false ) , mFilenamePattern( QStringLiteral( "'output_'||@atlas_featurenumber" ) ) , mCoverageLayer( nullptr ) , mSingleFile( false ) , mSortFeatures( false ) , mSortAscending( true ) , mCurrentFeatureNo( 0 ) , mFilterFeatures( false ) { //listen out for layer removal connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) ); }
//introduced in 1.8 void QgsMapLayerRegistry::removeMapLayers( QStringList theLayerIds ) { emit layersWillBeRemoved( theLayerIds ); foreach ( const QString &myId, theLayerIds ) { QgsMapLayer* lyr = mMapLayers[myId]; emit layerWillBeRemoved( myId ); if ( mOwnedLayers.contains( lyr ) ) { delete lyr; mOwnedLayers.remove( lyr ); } mMapLayers.remove( myId ); emit layerRemoved( myId ); }
QgsSnappingDialog::QgsSnappingDialog( QWidget* parent, QgsMapCanvas* canvas ) : QDialog( parent ) , mMapCanvas( canvas ) , mDock( 0 ) { setupUi( this ); QSettings myQsettings; bool myDockFlag = myQsettings.value( "/qgis/dockSnapping", false ).toBool(); if ( myDockFlag ) { mDock = new QgsSnappingDock( tr( "Snapping and Digitizing Options" ), QgisApp::instance() ); mDock->setAllowedAreas( Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea ); mDock->setWidget( this ); connect( this, SIGNAL( destroyed() ), mDock, SLOT( close() ) ); QgisApp::instance()->addDockWidget( Qt::BottomDockWidgetArea, mDock ); mButtonBox->setVisible( false ); } else { connect( mButtonBox, SIGNAL( accepted() ), this, SLOT( apply() ) ); connect( mButtonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) ); } connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer * > ) ), this, SLOT( addLayers( QList<QgsMapLayer * > ) ) ); connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersWillBeRemoved( QStringList ) ) ); connect( cbxEnableTopologicalEditingCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( on_cbxEnableTopologicalEditingCheckBox_stateChanged( int ) ) ); connect( cbxEnableIntersectionSnappingCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( on_cbxEnableIntersectionSnappingCheckBox_stateChanged( int ) ) ); reload(); QMap< QString, QgsMapLayer *> mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); QMap< QString, QgsMapLayer *>::iterator it; for ( it = mapLayers.begin(); it != mapLayers.end() ; ++it ) { addLayer( it.value() ); } mLayerTreeWidget->setHeaderLabels( QStringList() << "" ); mLayerTreeWidget->resizeColumnToContents( 0 ); mLayerTreeWidget->setColumnWidth( 1, 200 ); //hardcoded for now mLayerTreeWidget->setColumnWidth( 2, 200 ); //hardcoded for now mLayerTreeWidget->resizeColumnToContents( 3 ); mLayerTreeWidget->resizeColumnToContents( 4 ); mLayerTreeWidget->setSortingEnabled( true ); connect( QgsProject::instance(), SIGNAL( snapSettingsChanged() ), this, SLOT( reload() ) ); }
QgsGeometryCheckerResultTab::QgsGeometryCheckerResultTab( QgisInterface* iface, QgsGeometryChecker* checker, QgsFeaturePool *featurePool, QTabWidget* tabWidget, QWidget* parent ) : QWidget( parent ) , mTabWidget( tabWidget ) , mIface( iface ) , mChecker( checker ) , mFeaturePool( featurePool ) { ui.setupUi( this ); mErrorCount = 0; mFixedCount = 0; mCloseable = true; mAttribTableDialog = nullptr; for ( int i = 0, n = mFeaturePool->getLayer()->fields().count(); i < n; ++i ) { ui.comboBoxMergeAttribute->addItem( mFeaturePool->getLayer()->fields().at( i ).name() ); } connect( checker, SIGNAL( errorAdded( QgsGeometryCheckError* ) ), this, SLOT( addError( QgsGeometryCheckError* ) ) ); connect( checker, SIGNAL( errorUpdated( QgsGeometryCheckError*, bool ) ), this, SLOT( updateError( QgsGeometryCheckError*, bool ) ) ); connect( ui.comboBoxMergeAttribute, SIGNAL( currentIndexChanged( int ) ), checker, SLOT( setMergeAttributeIndex( int ) ) ); connect( ui.tableWidgetErrors->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), this, SLOT( onSelectionChanged( QItemSelection, QItemSelection ) ) ); connect( ui.buttonGroupSelectAction, SIGNAL( buttonClicked( int ) ), this, SLOT( highlightErrors() ) ); connect( ui.pushButtonOpenAttributeTable, SIGNAL( clicked() ), this, SLOT( openAttributeTable() ) ); connect( ui.pushButtonFixWithDefault, SIGNAL( clicked() ), this, SLOT( fixErrorsWithDefault() ) ); connect( ui.pushButtonFixWithPrompt, SIGNAL( clicked() ), this, SLOT( fixErrorsWithPrompt() ) ); connect( ui.pushButtonErrorResolutionSettings, SIGNAL( clicked() ), this, SLOT( setDefaultResolutionMethods() ) ); connect( ui.checkBoxHighlight, SIGNAL( clicked() ), this, SLOT( highlightErrors() ) ); connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( checkRemovedLayer( QStringList ) ) ); connect( ui.pushButtonExport, SIGNAL( clicked() ), this, SLOT( exportErrors() ) ); if (( mFeaturePool->getLayer()->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeGeometries ) == 0 ) { ui.pushButtonFixWithDefault->setEnabled( false ); ui.pushButtonFixWithPrompt->setEnabled( false ); } ui.progressBarFixErrors->setVisible( false ); ui.tableWidgetErrors->horizontalHeader()->setSortIndicator( 0, Qt::AscendingOrder ); // Not sure why, but this is needed... ui.tableWidgetErrors->setSortingEnabled( true ); ui.tableWidgetErrors->setSortingEnabled( false ); }
void QgsLayerTreeLayer::attachToLayer() { // layer is not necessarily already loaded QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( mLayerId ); if ( l ) { mLayer = l; mLayerName = l->name(); // make sure we are notified if the layer is removed connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( registryLayersWillBeRemoved( QStringList ) ) ); } else { if ( mLayerName.isEmpty() ) mLayerName = "(?)"; // wait for the layer to be eventually loaded connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( registryLayersAdded( QList<QgsMapLayer*> ) ) ); } }
QgsGeometrySnapperDialog::QgsGeometrySnapperDialog( QgisInterface* iface ): mIface( iface ) { ui.setupUi( this ); mRunButton = ui.buttonBox->addButton( tr( "Run" ), QDialogButtonBox::ActionRole ); ui.buttonBox->button( QDialogButtonBox::Abort )->hide(); mRunButton->setEnabled( false ); ui.progressBar->hide(); setFixedSize( sizeHint() ); setWindowModality( Qt::ApplicationModal ); connect( mRunButton, SIGNAL( clicked() ), this, SLOT( run() ) ); connect( ui.comboBoxInputLayer, SIGNAL( currentIndexChanged( int ) ), this, SLOT( validateInput() ) ); connect( ui.comboBoxReferenceLayer, SIGNAL( currentIndexChanged( int ) ), this, SLOT( validateInput() ) ); connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( updateLayers() ) ); connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( updateLayers() ) ); connect( ui.radioButtonOutputNew, SIGNAL( toggled( bool ) ), ui.lineEditOutput, SLOT( setEnabled( bool ) ) ); connect( ui.radioButtonOutputNew, SIGNAL( toggled( bool ) ), ui.pushButtonOutputBrowse, SLOT( setEnabled( bool ) ) ); connect( ui.buttonGroupOutput, SIGNAL( buttonClicked( int ) ), this, SLOT( validateInput() ) ); connect( ui.pushButtonOutputBrowse, SIGNAL( clicked() ), this, SLOT( selectOutputFile() ) ); connect( ui.lineEditOutput, SIGNAL( textChanged( QString ) ), this, SLOT( validateInput() ) ); updateLayers(); }