QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *parent, Qt::WFlags fl ) : QDialog( parent, fl ) , mMapCanvas( mapCanvas ) { setupUi( this ); connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) ); connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) ); connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) ); connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) ); connect( projectionSelector, SIGNAL( sridSelected( QString ) ), this, SLOT( setMapUnitsToCurrentProjection() ) ); /////////////////////////////////////////////////////////// // Properties stored in map canvas's QgsMapRenderer // these ones are propagated to QgsProject by a signal QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer(); QGis::UnitType myUnit = myRenderer->mapUnits(); setMapUnits( myUnit ); // we need to initialize it, since the on_cbxProjectionEnabled_stateChanged() // callback triggered by setChecked() might use it. mProjectSrsId = myRenderer->destinationCrs().srsid(); //see if the user wants on the fly projection enabled bool myProjectionEnabled = myRenderer->hasCrsTransformEnabled(); cbxProjectionEnabled->setChecked( myProjectionEnabled ); QgsDebugMsg( "Read project CRSID: " + QString::number( mProjectSrsId ) ); projectionSelector->setSelectedCrsId( mProjectSrsId ); projectionSelector->setEnabled( myProjectionEnabled ); /////////////////////////////////////////////////////////// // Properties stored in QgsProject title( QgsProject::instance()->title() ); // get the manner in which the number of decimal places in the mouse // position display is set (manual or automatic) bool automaticPrecision = QgsProject::instance()->readBoolEntry( "PositionPrecision", "/Automatic" ); if ( automaticPrecision ) { radAutomatic->setChecked( true ); spinBoxDP->setDisabled( true ); labelDP->setDisabled( true ); } else { radManual->setChecked( true ); } cbxAbsolutePath->setCurrentIndex( QgsProject::instance()->readBoolEntry( "Paths", "/Absolute", true ) ? 0 : 1 ); int dp = QgsProject::instance()->readNumEntry( "PositionPrecision", "/DecimalPlaces" ); spinBoxDP->setValue( dp ); QString format = QgsProject::instance()->readEntry( "PositionPrecision", "/DegreeFormat", "D" ); if ( format == "DM" ) radDM->setChecked( true ); else if ( format == "DMS" ) radDMS->setChecked( true ); else radD->setChecked( true ); //get the color selections and set the button color accordingly int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorRedPart", 255 ); int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 ); int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorBluePart", 0 ); int myAlphaInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorAlphaPart", 255 ); QColor myColor = QColor( myRedInt, myGreenInt, myBlueInt, myAlphaInt ); pbnSelectionColor->setColor( myColor ); //get the color for map canvas background and set button color accordingly (default white) myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 ); myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 ); myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 ); myColor = QColor( myRedInt, myGreenInt, myBlueInt ); pbnCanvasColor->setColor( myColor ); //get project scales QStringList myScales = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" ); if ( !myScales.isEmpty() ) { QStringList::const_iterator scaleIt = myScales.constBegin(); for ( ; scaleIt != myScales.constEnd(); ++scaleIt ) { QListWidgetItem* newItem = new QListWidgetItem( lstScales ); newItem->setText( *scaleIt ); newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable ); lstScales->addItem( newItem ); } } grpProjectScales->setChecked( QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" ) ); QgsMapLayer* currentLayer = 0; QStringList noIdentifyLayerIdList = QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" ); const QMap<QString, QgsMapLayer*> &mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); if ( mMapCanvas->currentLayer() ) { mLayerSrsId = mMapCanvas->currentLayer()->crs().srsid(); } else if ( mapLayers.size() > 0 ) { mLayerSrsId = mapLayers.begin().value()->crs().srsid(); } else { mLayerSrsId = mProjectSrsId; } twIdentifyLayers->setColumnCount( 3 ); twIdentifyLayers->horizontalHeader()->setVisible( true ); twIdentifyLayers->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Layer" ) ) ); twIdentifyLayers->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Type" ) ) ); twIdentifyLayers->setHorizontalHeaderItem( 2, new QTableWidgetItem( tr( "Identifiable" ) ) ); twIdentifyLayers->setRowCount( mapLayers.size() ); twIdentifyLayers->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents ); int i = 0; for ( QMap<QString, QgsMapLayer*>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); it++, i++ ) { currentLayer = it.value(); QTableWidgetItem *twi = new QTableWidgetItem( QString::number( i ) ); twIdentifyLayers->setVerticalHeaderItem( i, twi ); twi = new QTableWidgetItem( currentLayer->name() ); twi->setData( Qt::UserRole, it.key() ); twi->setFlags( twi->flags() & ~Qt::ItemIsEditable ); twIdentifyLayers->setItem( i, 0, twi ); QString type; if ( currentLayer->type() == QgsMapLayer::VectorLayer ) { type = tr( "Vector" ); } else if ( currentLayer->type() == QgsMapLayer::RasterLayer ) { QgsRasterLayer *rl = qobject_cast<QgsRasterLayer *>( currentLayer ); if ( rl && rl->providerType() == "wms" ) { type = tr( "WMS" ); } else { type = tr( "Raster" ); } } twi = new QTableWidgetItem( type ); twi->setFlags( twi->flags() & ~Qt::ItemIsEditable ); twIdentifyLayers->setItem( i, 1, twi ); QCheckBox *cb = new QCheckBox(); cb->setChecked( !noIdentifyLayerIdList.contains( currentLayer->id() ) ); twIdentifyLayers->setCellWidget( i, 2, cb ); } grpOWSServiceCapabilities->setChecked( QgsProject::instance()->readBoolEntry( "WMSServiceCapabilities", "/", false ) ); mWMSTitle->setText( QgsProject::instance()->readEntry( "WMSServiceTitle", "/" ) ); mWMSContactOrganization->setText( QgsProject::instance()->readEntry( "WMSContactOrganization", "/", "" ) ); mWMSContactPerson->setText( QgsProject::instance()->readEntry( "WMSContactPerson", "/", "" ) ); mWMSContactMail->setText( QgsProject::instance()->readEntry( "WMSContactMail", "/", "" ) ); mWMSContactPhone->setText( QgsProject::instance()->readEntry( "WMSContactPhone", "/", "" ) ); mWMSAbstract->setPlainText( QgsProject::instance()->readEntry( "WMSServiceAbstract", "/", "" ) ); mWMSOnlineResourceLineEdit->setText( QgsProject::instance()->readEntry( "WMSOnlineResource", "/", "" ) ); mWMSUrlLineEdit->setText( QgsProject::instance()->readEntry( "WMSUrl", "/", "" ) ); bool ok; QStringList values; mWMSExtMinX->setValidator( new QDoubleValidator( mWMSExtMinX ) ); mWMSExtMinY->setValidator( new QDoubleValidator( mWMSExtMinY ) ); mWMSExtMaxX->setValidator( new QDoubleValidator( mWMSExtMaxX ) ); mWMSExtMaxY->setValidator( new QDoubleValidator( mWMSExtMaxY ) ); values = QgsProject::instance()->readListEntry( "WMSExtent", "/", &ok ); grpWMSExt->setChecked( ok && values.size() == 4 ); if ( grpWMSExt->isChecked() ) { mWMSExtMinX->setText( values[0] ); mWMSExtMinY->setText( values[1] ); mWMSExtMaxX->setText( values[2] ); mWMSExtMaxY->setText( values[3] ); } values = QgsProject::instance()->readListEntry( "WMSCrsList", "/", &ok ); grpWMSList->setChecked( ok && values.size() > 0 ); if ( grpWMSList->isChecked() ) { mWMSList->addItems( values ); } else { values = QgsProject::instance()->readListEntry( "WMSEpsgList", "/", &ok ); grpWMSList->setChecked( ok && values.size() > 0 ); if ( grpWMSList->isChecked() ) { QStringList list; foreach ( QString value, values ) { list << QString( "EPSG:%1" ).arg( value ); } mWMSList->addItems( list ); }
QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *parent, Qt::WFlags fl ) : QDialog( parent, fl ), mMapCanvas( mapCanvas ) { setupUi( this ); connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) ); connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) ); connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) ); connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) ); connect( projectionSelector, SIGNAL( sridSelected( QString ) ), this, SLOT( setMapUnitsToCurrentProjection() ) ); /////////////////////////////////////////////////////////// // Properties stored in map canvas's QgsMapRenderer // these ones are propagated to QgsProject by a signal QgsMapRenderer* myRender = mMapCanvas->mapRenderer(); QGis::UnitType myUnit = myRender->mapUnits(); setMapUnits( myUnit ); //see if the user wants on the fly projection enabled bool myProjectionEnabled = myRender->hasCrsTransformEnabled(); cbxProjectionEnabled->setChecked( myProjectionEnabled ); btnGrpMapUnits->setEnabled( !myProjectionEnabled ); long myCRSID = myRender->destinationSrs().srsid(); QgsDebugMsg( "Read project CRSID: " + QString::number( myCRSID ) ); projectionSelector->setSelectedCrsId( myCRSID ); /////////////////////////////////////////////////////////// // Properties stored in QgsProject title( QgsProject::instance()->title() ); // get the manner in which the number of decimal places in the mouse // position display is set (manual or automatic) bool automaticPrecision = QgsProject::instance()->readBoolEntry( "PositionPrecision", "/Automatic" ); if ( automaticPrecision ) { radAutomatic->setChecked( true ); spinBoxDP->setDisabled( true ); labelDP->setDisabled( true ); } else { radManual->setChecked( true ); } cbxAbsolutePath->setCurrentIndex( QgsProject::instance()->readBoolEntry( "Paths", "/Absolute", true ) ? 0 : 1 ); int dp = QgsProject::instance()->readNumEntry( "PositionPrecision", "/DecimalPlaces" ); spinBoxDP->setValue( dp ); //get the color selections and set the button color accordingly int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorRedPart", 255 ); int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 ); int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorBluePart", 0 ); int myAlphaInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorAlphaPart", 255 ); QColor myColor = QColor( myRedInt, myGreenInt, myBlueInt, myAlphaInt ); pbnSelectionColor->setColor( myColor ); //get the color for map canvas background and set button color accordingly (default white) myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 ); myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 ); myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 ); myColor = QColor( myRedInt, myGreenInt, myBlueInt ); pbnCanvasColor->setColor( myColor ); QgsMapLayer* currentLayer = 0; QStringList noIdentifyLayerIdList = QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" ); const QMap<QString, QgsMapLayer*> &mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); twIdentifyLayers->setColumnCount( 3 ); twIdentifyLayers->horizontalHeader()->setVisible( true ); twIdentifyLayers->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Layer" ) ) ); twIdentifyLayers->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Type" ) ) ); twIdentifyLayers->setHorizontalHeaderItem( 2, new QTableWidgetItem( tr( "Identifiable" ) ) ); twIdentifyLayers->setRowCount( mapLayers.size() ); twIdentifyLayers->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents ); int i = 0; for ( QMap<QString, QgsMapLayer*>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); it++, i++ ) { currentLayer = it.value(); QTableWidgetItem *twi = new QTableWidgetItem( QString::number( i ) ); twIdentifyLayers->setVerticalHeaderItem( i, twi ); twi = new QTableWidgetItem( currentLayer->name() ); twi->setData( Qt::UserRole, it.key() ); twi->setFlags( twi->flags() & ~Qt::ItemIsEditable ); twIdentifyLayers->setItem( i, 0, twi ); QString type; if ( currentLayer->type() == QgsMapLayer::VectorLayer ) { type = tr( "Vector" ); } else if ( currentLayer->type() == QgsMapLayer::RasterLayer ) { QgsRasterLayer *rl = qobject_cast<QgsRasterLayer *>( currentLayer ); if ( rl && rl->providerKey() == "wms" ) { type = tr( "WMS" ); } else { type = tr( "Raster" ); } } twi = new QTableWidgetItem( type ); twi->setFlags( twi->flags() & ~Qt::ItemIsEditable ); twIdentifyLayers->setItem( i, 1, twi ); QCheckBox *cb = new QCheckBox(); cb->setChecked( !noIdentifyLayerIdList.contains( currentLayer->getLayerID() ) ); twIdentifyLayers->setCellWidget( i, 2, cb ); } restoreState(); }