Skip to content

Commit

Permalink
[Feature] Freeze-thaw labeling tool, with on-the-fly transformation s…
Browse files Browse the repository at this point in the history
…upport.
  • Loading branch information
dakcarto committed Jul 17, 2012
1 parent 298632e commit 83764a6
Show file tree
Hide file tree
Showing 16 changed files with 755 additions and 10 deletions.
2 changes: 2 additions & 0 deletions images/images.qrc
Expand Up @@ -77,6 +77,7 @@
<file>themes/default/mActionFileSmall.png</file>
<file>themes/default/mActionFolder.png</file>
<file>themes/default/mActionFormAnnotation.png</file>
<file>themes/default/mActionFreezeLabels.png</file>
<file>themes/default/mActionFromSelectedFeature.png</file>
<file>themes/default/mActionFullHistogramStretch.png</file>
<file>themes/default/mActionGroupItems.png</file>
Expand Down Expand Up @@ -143,6 +144,7 @@
<file>themes/default/mActionSelectRectangle.png</file>
<file>themes/default/mActionShowAllLayers.png</file>
<file>themes/default/mActionShowBookmarks.png</file>
<file>themes/default/mActionShowFrozenLabels.png</file>
<file>themes/default/mActionShowPluginManager.png</file>
<file>themes/default/mActionSimplify.png</file>
<file>themes/default/mActionSplitFeatures.png</file>
Expand Down
Binary file added images/themes/default/mActionFreezeLabels.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -55,6 +55,7 @@ SET(QGIS_APP_SRCS
qgsmaptooledit.cpp
qgsmaptoolfeatureaction.cpp
qgsmaptoolformannotation.cpp
qgsmaptoolfreezelabels.cpp
qgsmaptoolidentify.cpp
qgsmaptoollabel.cpp
qgsmaptoolmeasureangle.cpp
Expand Down Expand Up @@ -203,6 +204,7 @@ SET (QGIS_APP_MOC_HDRS
qgsmaptooldeletering.h
qgsmaptooldeletevertex.h
qgsmaptoolfeatureaction.h
qgsmaptoolfreezelabels.h
qgsmaptoolidentify.h
qgsmaptoolmeasureangle.h
qgsmaptoolmovefeature.h
Expand Down
31 changes: 29 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -231,6 +231,7 @@
#include "qgsmaptoolzoom.h"
#include "qgsmaptoolsimplify.h"
#include "qgsmeasuretool.h"
#include "qgsmaptoolfreezelabels.h"
#include "qgsmaptoolmovelabel.h"
#include "qgsmaptoolrotatelabel.h"
#include "qgsmaptoolchangelabelproperties.h"
Expand Down Expand Up @@ -709,6 +710,7 @@ QgisApp::~QgisApp()
delete mMapTools.mAddPart;
delete mMapTools.mNodeTool;
delete mMapTools.mRotatePointSymbolsTool;
delete mMapTools.mFreezeLabels;
delete mMapTools.mMoveLabel;
delete mMapTools.mRotateLabel;
delete mMapTools.mChangeLabelProperties;
Expand Down Expand Up @@ -974,6 +976,8 @@ void QgisApp::createActions()
connect( mActionAbout, SIGNAL( triggered() ), this, SLOT( about() ) );
connect( mActionSponsors, SIGNAL( triggered() ), this, SLOT( sponsors() ) );

connect( mActionShowFrozenLabels, SIGNAL( toggled( bool ) ), this, SLOT( showFrozenLabels( bool ) ) );
connect( mActionFreezeLabels, SIGNAL( triggered() ), this, SLOT( freezeLabels() ) );
connect( mActionMoveLabel, SIGNAL( triggered() ), this, SLOT( moveLabel() ) );
connect( mActionRotateLabel, SIGNAL( triggered() ), this, SLOT( rotateLabel() ) );
connect( mActionChangeLabelProperties, SIGNAL( triggered() ), this, SLOT( changeLabelProperties() ) );
Expand Down Expand Up @@ -1083,6 +1087,7 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionMergeFeatureAttributes );
mMapToolGroup->addAction( mActionNodeTool );
mMapToolGroup->addAction( mActionRotatePointSymbols );
mMapToolGroup->addAction( mActionFreezeLabels );
mMapToolGroup->addAction( mActionMoveLabel );
mMapToolGroup->addAction( mActionRotateLabel );
mMapToolGroup->addAction( mActionChangeLabelProperties );
Expand Down Expand Up @@ -1612,6 +1617,8 @@ void QgisApp::setTheme( QString theThemeName )
mActionFormAnnotation->setIcon( QgsApplication::getThemeIcon( "/mActionFormAnnotation.png" ) );
mActionTextAnnotation->setIcon( QgsApplication::getThemeIcon( "/mActionTextAnnotation.png" ) );
mActionLabeling->setIcon( QgsApplication::getThemeIcon( "/mActionLabeling.png" ) );
mActionShowFrozenLabels->setIcon( QgsApplication::getThemeIcon( "/mActionShowFrozenLabels.png" ) );
mActionFreezeLabels->setIcon( QgsApplication::getThemeIcon( "/mActionFreezeLabels.png" ) );
mActionMoveLabel->setIcon( QgsApplication::getThemeIcon( "/mActionMoveLabel.png" ) );
mActionRotateLabel->setIcon( QgsApplication::getThemeIcon( "/mActionRotateLabel.png" ) );
mActionChangeLabelProperties->setIcon( QgsApplication::getThemeIcon( "/mActionChangeLabelProperties.png" ) );
Expand Down Expand Up @@ -1778,6 +1785,8 @@ void QgisApp::createCanvasTools()
mMapTools.mNodeTool->setAction( mActionNodeTool );
mMapTools.mRotatePointSymbolsTool = new QgsMapToolRotatePointSymbols( mMapCanvas );
mMapTools.mRotatePointSymbolsTool->setAction( mActionRotatePointSymbols );
mMapTools.mFreezeLabels = new QgsMapToolFreezeLabels( mMapCanvas );
mMapTools.mFreezeLabels->setAction( mActionFreezeLabels );
mMapTools.mMoveLabel = new QgsMapToolMoveLabel( mMapCanvas );
mMapTools.mMoveLabel->setAction( mActionMoveLabel );
mMapTools.mRotateLabel = new QgsMapToolRotateLabel( mMapCanvas );
Expand Down Expand Up @@ -4137,6 +4146,17 @@ bool QgisApp::loadAnnotationItemsFromProject( const QDomDocument& doc )
return true;
}

void QgisApp::showFrozenLabels( bool show )
{
qobject_cast<QgsMapToolFreezeLabels*>( mMapTools.mFreezeLabels )->showFrozenLabels( show );
}

void QgisApp::freezeLabels()
{
mActionShowFrozenLabels->setChecked( true );
mMapCanvas->setMapTool( mMapTools.mFreezeLabels );
}

void QgisApp::moveLabel()
{
mMapCanvas->setMapTool( mMapTools.mMoveLabel );
Expand Down Expand Up @@ -6557,7 +6577,7 @@ void QgisApp::legendLayerSelectionChanged( void )

void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
{
bool enableMove = false, enableRotate = false, enableChange = false;
bool enableMove = false, enableRotate = false, enableFreeze = false, enableChange = false;

QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it != layers.end(); it++ )
Expand All @@ -6568,6 +6588,11 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
continue;

int colX, colY, colAng;
enableFreeze =
enableFreeze ||
( qobject_cast<QgsMapToolFreezeLabels*>( mMapTools.mFreezeLabels ) &&
qobject_cast<QgsMapToolFreezeLabels*>( mMapTools.mFreezeLabels )->layerCanFreeze( vlayer, colX, colY ) );

enableMove =
enableMove ||
( qobject_cast<QgsMapToolMoveLabel*>( mMapTools.mMoveLabel ) &&
Expand All @@ -6582,10 +6607,11 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )

enableChange = true;

if ( enableMove && enableRotate && enableChange )
if ( enableFreeze && enableMove && enableRotate && enableChange )
break;
}

mActionFreezeLabels->setEnabled( enableFreeze );
mActionMoveLabel->setEnabled( enableMove );
mActionRotateLabel->setEnabled( enableRotate );
mActionChangeLabelProperties->setEnabled( enableChange );
Expand Down Expand Up @@ -6632,6 +6658,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionMergeFeatureAttributes->setEnabled( false );
mActionRotatePointSymbols->setEnabled( false );

mActionFreezeLabels->setEnabled( false );
mActionMoveLabel->setEnabled( false );
mActionRotateLabel->setEnabled( false );
mActionChangeLabelProperties->setEnabled( false );
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -309,6 +309,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QAction *actionAbout() { return mActionAbout; }
QAction *actionSponsors() { return mActionSponsors; }

QAction *actionShowFrozenLabels() { return mActionShowFrozenLabels; }

//! Menus
QMenu *fileMenu() { return mFileMenu; }
QMenu *editMenu() { return mEditMenu; }
Expand Down Expand Up @@ -852,6 +854,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow

bool loadAnnotationItemsFromProject( const QDomDocument& doc );

//! Toggles whether to show frozen labels
void showFrozenLabels( bool show );
//! Activates freeze labels tool
void freezeLabels();
//! Activates the move label tool
void moveLabel();
//! Activates rotate label tool
Expand Down Expand Up @@ -1056,6 +1062,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool* mAnnotation;
QgsMapTool* mFormAnnotation;
QgsMapTool* mTextAnnotation;
QgsMapTool* mFreezeLabels;
QgsMapTool* mMoveLabel;
QgsMapTool* mRotateLabel;
QgsMapTool* mChangeLabelProperties;
Expand Down

0 comments on commit 83764a6

Please sign in to comment.