Skip to content

Commit cae08e4

Browse files
committed
[gui] Remove deprecated labeling properties tab for new projects or older ones that don't use them
- Deprecated tab remains active for older projects, if any layer uses them - Deprecated tab an be disabled/enabled via console commands for project entry, e.g.: QgsProject.instance().writeEntry('DeprecatedLabels', '/Enabled', bool) or QgsProject.instance().removeEntry('DeprecatedLabels', '/')
1 parent 63fa7e2 commit cae08e4

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

src/app/qgisapp.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,12 @@ void QgisApp::setupConnections()
18991899
connect( this, SIGNAL( projectRead() ),
19001900
this, SLOT( fileOpenedOKAfterLaunch() ) );
19011901

1902+
// handle deprecated labels in project for QGIS 2.0
1903+
connect( this, SIGNAL( newProject() ),
1904+
this, SLOT( checkForDeprecatedLabelsInProject() ) );
1905+
connect( this, SIGNAL( projectRead() ),
1906+
this, SLOT( checkForDeprecatedLabelsInProject() ) );
1907+
19021908
//
19031909
// Do we really need this ??? - its already connected to the esc key...TS
19041910
//
@@ -4602,6 +4608,39 @@ void QgisApp::saveAsVectorFileGeneral( bool saveOnlySelection )
46024608
delete dialog;
46034609
}
46044610

4611+
void QgisApp::checkForDeprecatedLabelsInProject()
4612+
{
4613+
bool ok;
4614+
QgsProject::instance()->readBoolEntry( "DeprecatedLabels", "/Enabled", false, &ok );
4615+
if ( ok ) // project already flagged (regardless of project property value)
4616+
{
4617+
return;
4618+
}
4619+
4620+
if ( QgsMapLayerRegistry::instance()->count() > 0 )
4621+
{
4622+
bool depLabelsUsed = false;
4623+
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
4624+
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it != layers.end(); it++ )
4625+
{
4626+
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() );
4627+
if ( !vl )
4628+
{
4629+
continue;
4630+
}
4631+
4632+
depLabelsUsed = vl->hasLabelsEnabled();
4633+
if ( depLabelsUsed )
4634+
{
4635+
break;
4636+
}
4637+
}
4638+
if ( depLabelsUsed )
4639+
{
4640+
QgsProject::instance()->writeEntry( "DeprecatedLabels", "/Enabled", true );
4641+
}
4642+
}
4643+
}
46054644

46064645
void QgisApp::layerProperties()
46074646
{

src/app/qgisapp.h

+4
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
10381038
//! shows label settings dialog (for labeling-ng)
10391039
void labeling();
10401040

1041+
/** Check if deprecated labels are used in project, and flag projects that use them (QGIS 2.0)
1042+
*/
1043+
void checkForDeprecatedLabelsInProject();
1044+
10411045
//! save current vector layer
10421046
void saveAsFile();
10431047
void saveSelectionAsVectorFile();

src/app/qgsvectorlayerproperties.cpp

+22-5
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
267267

268268
QgsVectorLayerProperties::~QgsVectorLayerProperties()
269269
{
270-
if ( layer->hasGeometryType() )
270+
if ( mOptsPage_LabelsOld && layer->hasGeometryType() )
271271
{
272272
disconnect( labelDialog, SIGNAL( labelSourceSet() ), this, SLOT( setLabelCheckBox() ) );
273273
}
@@ -412,6 +412,20 @@ void QgsVectorLayerProperties::syncToLayer( void )
412412
mFieldsPropertiesDialog->init();
413413

414414
QObject::connect( labelCheckBox, SIGNAL( clicked( bool ) ), this, SLOT( enableLabelOptions( bool ) ) );
415+
416+
// delete deprecated labels tab if not already used by project
417+
// NOTE: this is not ideal, but a quick fix for QGIS 2.0 release
418+
bool ok;
419+
bool dl = QgsProject::instance()->readBoolEntry( "DeprecatedLabels", "/Enabled", false, &ok );
420+
if ( !ok || ( ok && !dl ) ) // project not flagged or set to use deprecated labels
421+
{
422+
if ( mOptsPage_LabelsOld )
423+
{
424+
disconnect( labelDialog, SIGNAL( labelSourceSet() ), this, SLOT( setLabelCheckBox() ) );
425+
delete mOptsPage_LabelsOld;
426+
mOptsPage_LabelsOld = 0;
427+
}
428+
}
415429
} // reset()
416430

417431

@@ -462,10 +476,13 @@ void QgsVectorLayerProperties::apply()
462476

463477
actionDialog->apply();
464478

465-
if ( labelDialog )
466-
labelDialog->apply();
467-
layer->enableLabels( labelCheckBox->isChecked() );
468-
layer->setLayerName( mLayerOrigNameLineEdit->text() );
479+
if ( mOptsPage_LabelsOld )
480+
{
481+
if ( labelDialog )
482+
labelDialog->apply();
483+
layer->enableLabels( labelCheckBox->isChecked() );
484+
layer->setLayerName( mLayerOrigNameLineEdit->text() );
485+
}
469486

470487
// Apply fields settings
471488
mFieldsPropertiesDialog->apply();

0 commit comments

Comments
 (0)