Skip to content

Commit

Permalink
[gui] Remove deprecated labeling properties tab for new projects or o…
Browse files Browse the repository at this point in the history
…lder 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', '/')
  • Loading branch information
dakcarto committed Sep 1, 2013
1 parent 63fa7e2 commit cae08e4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
39 changes: 39 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1899,6 +1899,12 @@ void QgisApp::setupConnections()
connect( this, SIGNAL( projectRead() ),
this, SLOT( fileOpenedOKAfterLaunch() ) );

// handle deprecated labels in project for QGIS 2.0
connect( this, SIGNAL( newProject() ),
this, SLOT( checkForDeprecatedLabelsInProject() ) );
connect( this, SIGNAL( projectRead() ),
this, SLOT( checkForDeprecatedLabelsInProject() ) );

//
// Do we really need this ??? - its already connected to the esc key...TS
//
Expand Down Expand Up @@ -4602,6 +4608,39 @@ void QgisApp::saveAsVectorFileGeneral( bool saveOnlySelection )
delete dialog;
}

void QgisApp::checkForDeprecatedLabelsInProject()
{
bool ok;
QgsProject::instance()->readBoolEntry( "DeprecatedLabels", "/Enabled", false, &ok );
if ( ok ) // project already flagged (regardless of project property value)
{
return;
}

if ( QgsMapLayerRegistry::instance()->count() > 0 )
{
bool depLabelsUsed = false;
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it != layers.end(); it++ )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() );
if ( !vl )
{
continue;
}

depLabelsUsed = vl->hasLabelsEnabled();
if ( depLabelsUsed )
{
break;
}
}
if ( depLabelsUsed )
{
QgsProject::instance()->writeEntry( "DeprecatedLabels", "/Enabled", true );
}
}
}

void QgisApp::layerProperties()
{
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1038,6 +1038,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! shows label settings dialog (for labeling-ng)
void labeling();

/** Check if deprecated labels are used in project, and flag projects that use them (QGIS 2.0)
*/
void checkForDeprecatedLabelsInProject();

//! save current vector layer
void saveAsFile();
void saveSelectionAsVectorFile();
Expand Down
27 changes: 22 additions & 5 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -267,7 +267,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(

QgsVectorLayerProperties::~QgsVectorLayerProperties()
{
if ( layer->hasGeometryType() )
if ( mOptsPage_LabelsOld && layer->hasGeometryType() )
{
disconnect( labelDialog, SIGNAL( labelSourceSet() ), this, SLOT( setLabelCheckBox() ) );
}
Expand Down Expand Up @@ -412,6 +412,20 @@ void QgsVectorLayerProperties::syncToLayer( void )
mFieldsPropertiesDialog->init();

QObject::connect( labelCheckBox, SIGNAL( clicked( bool ) ), this, SLOT( enableLabelOptions( bool ) ) );

// delete deprecated labels tab if not already used by project
// NOTE: this is not ideal, but a quick fix for QGIS 2.0 release
bool ok;
bool dl = QgsProject::instance()->readBoolEntry( "DeprecatedLabels", "/Enabled", false, &ok );
if ( !ok || ( ok && !dl ) ) // project not flagged or set to use deprecated labels
{
if ( mOptsPage_LabelsOld )
{
disconnect( labelDialog, SIGNAL( labelSourceSet() ), this, SLOT( setLabelCheckBox() ) );
delete mOptsPage_LabelsOld;
mOptsPage_LabelsOld = 0;
}
}
} // reset()


Expand Down Expand Up @@ -462,10 +476,13 @@ void QgsVectorLayerProperties::apply()

actionDialog->apply();

if ( labelDialog )
labelDialog->apply();
layer->enableLabels( labelCheckBox->isChecked() );
layer->setLayerName( mLayerOrigNameLineEdit->text() );
if ( mOptsPage_LabelsOld )
{
if ( labelDialog )
labelDialog->apply();
layer->enableLabels( labelCheckBox->isChecked() );
layer->setLayerName( mLayerOrigNameLineEdit->text() );
}

// Apply fields settings
mFieldsPropertiesDialog->apply();
Expand Down

0 comments on commit cae08e4

Please sign in to comment.