Navigation Menu

Skip to content

Commit

Permalink
activate/deactivate labeling tools
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14798 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 29, 2010
1 parent 978cc79 commit 245a230
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
25 changes: 25 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -584,6 +584,7 @@ QgisApp::~QgisApp()
delete mMapTools.mAddIsland;
delete mMapTools.mNodeTool;
delete mMapTools.mMoveLabel;
delete mMapTools.mRotateLabel;
delete mMapTools.mChangeLabelProperties;

delete mPythonUtils;
Expand Down Expand Up @@ -3955,6 +3956,8 @@ void QgisApp::labeling()
// alter labeling - save the changes
labelGui.layerSettings().writeToLayer( vlayer );

activateDeactivateLayerRelatedActions( layer );

// trigger refresh
if ( mMapCanvas )
{
Expand Down Expand Up @@ -6171,6 +6174,10 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionCaptureLine->setVisible( false );
mActionCapturePolygon->setVisible( false );

mActionMoveLabel->setEnabled( false );
mActionRotateLabel->setEnabled( false );
mActionChangeLabelProperties->setEnabled( false );

return;
}

Expand Down Expand Up @@ -6247,11 +6254,29 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
dprovider->capabilities() & QgsVectorDataProvider::AddFeatures );

mActionMergeFeatureAttributes->setEnabled( layerHasSelection );

if ( layer->customProperty( "labeling" ).toString() == QString( "pal" ) )
{
int colX, colY, colAng;
mActionMoveLabel->setEnabled( qobject_cast<QgsMapToolMoveLabel*>( mMapTools.mMoveLabel ) && qobject_cast<QgsMapToolMoveLabel*>( mMapTools.mMoveLabel )->layerIsMoveable( layer, colX, colY ) );
mActionRotateLabel->setEnabled( qobject_cast<QgsMapToolRotateLabel*>( mMapTools.mRotateLabel ) && qobject_cast<QgsMapToolRotateLabel*>( mMapTools.mMoveLabel )->layerIsRotatable( layer, colAng ) );
mActionChangeLabelProperties->setEnabled( true );
}
else
{
mActionMoveLabel->setEnabled( false );
mActionRotateLabel->setEnabled( false );
mActionChangeLabelProperties->setEnabled( false );
}
}
else
{
mActionMergeFeatures->setEnabled( false );
mActionMergeFeatureAttributes->setEnabled( false );

mActionMoveLabel->setEnabled( false );
mActionRotateLabel->setEnabled( false );
mActionChangeLabelProperties->setEnabled( false );
}

// moving enabled if geometry changes are supported
Expand Down
12 changes: 6 additions & 6 deletions src/app/qgsmaptoolmovelabel.h
Expand Up @@ -35,6 +35,12 @@ class QgsMapToolMoveLabel: public QgsMapToolLabel

virtual void canvasReleaseEvent( QMouseEvent * e );

/**Returns true if layer move can be applied to a layer
@param xCol out: index of the attribute for data defined x coordinate
@param yCol out: index of the attribute for data defined y coordinate
@return true if labels of layer can be moved*/
bool layerIsMoveable( const QgsMapLayer* ml, int& xCol, int& yCol ) const;

protected:
/**Get data defined position of a feature
@param layerId layer identification string
Expand All @@ -47,12 +53,6 @@ class QgsMapToolMoveLabel: public QgsMapToolLabel
@return false if layer does not have data defined label position enabled*/
bool dataDefinedPosition( QgsVectorLayer* vlayer, int featureId, double& x, bool& xSuccess, double& y, bool& ySuccess, int& xCol, int& yCol ) const;

/**Returns true if layer move can be applied to a layer
@param xCol out: index of the attribute for data defined x coordinate
@param yCol out: index of the attribute for data defined y coordinate
@return true if labels of layer can be moved*/
bool layerIsMoveable( const QgsMapLayer* ml, int& xCol, int& yCol ) const;

/**Start point of the move in map coordinates*/
QgsPoint mStartPointMapCoords;

Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsmaptoolrotatelabel.h
Expand Up @@ -33,10 +33,11 @@ class QgsMapToolRotateLabel: public QgsMapToolLabel
virtual void canvasMoveEvent( QMouseEvent * e );
virtual void canvasReleaseEvent( QMouseEvent * e );

protected:
/**Checks if labels in a layer can be rotated
@param rotationCol out: attribute column for data defined label rotation*/
bool layerIsRotatable( const QgsMapLayer* layer, int& rotationCol ) const;

protected:
/**Returns data defined rotation of a feature.
@param rotation out: rotation value
@param rotationSuccess out: false if rotation value is NULL
Expand Down

0 comments on commit 245a230

Please sign in to comment.