Skip to content

Commit

Permalink
[FEATURE]: move/rotate/change label edit tools to interactively chang…
Browse files Browse the repository at this point in the history
…e data defined label properties

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14697 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 17, 2010
1 parent 535b533 commit 1ae742e
Show file tree
Hide file tree
Showing 30 changed files with 1,721 additions and 82 deletions.
3 changes: 3 additions & 0 deletions images/images.qrc
Expand Up @@ -123,6 +123,7 @@
<file>themes/default/mActionCaptureLine.png</file>
<file>themes/default/mActionCapturePoint.png</file>
<file>themes/default/mActionCapturePolygon.png</file>
<file>themes/default/mActionChangeLabelProperties.png</file>
<file>themes/default/mActionCheckQgisVersion.png</file>
<file>themes/default/mActionCollapseTree.png</file>
<file>themes/default/mActionComposerManager.png</file>
Expand Down Expand Up @@ -168,6 +169,7 @@
<file>themes/default/mActionMergeFeatures.png</file>
<file>themes/default/mActionMergeFeatureAttributes.png</file>
<file>themes/default/mActionMoveFeature.png</file>
<file>themes/default/mActionMoveLabel.png</file>
<file>themes/default/mActionMoveItemContent.png</file>
<file>themes/default/mActionMoveItemsToBottom.png</file>
<file>themes/default/mActionMoveItemsToTop.png</file>
Expand All @@ -191,6 +193,7 @@
<file>themes/default/mActionRemoveLayer.png</file>
<file>themes/default/mActionRemoveSelectedFeature.png</file>
<file>themes/default/mActionReshape.png</file>
<file>themes/default/mActionRotateLabel.png</file>
<file>themes/default/mActionRotatePointSymbols.png</file>
<file>themes/default/mActionSaveAsPDF.png</file>
<file>themes/default/mActionSaveAsSVG.png</file>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mActionMoveLabel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mActionRotateLabel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions python/core/qgsmaprenderer.sip
Expand Up @@ -25,11 +25,32 @@ public:
virtual void drawLabeling( QgsRenderContext& context ) = 0;
//! called when we're done with rendering
virtual void exit() = 0;
//! return infos about labels at a given (map) position
//! @note: this method was added in version 1.7
virtual QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p )= 0;


//! called when passing engine among map renderers
virtual QgsLabelingEngineInterface* clone() = 0;
};

struct QgsLabelPosition
{
%TypeHeaderCode
#include <qgsmaprenderer.h>
%End
QgsLabelPosition( int id, double r, const QVector< QgsPoint >& corners, const QgsRectangle& rect, double w, double h, const QString& layer, bool upside_down );
QgsLabelPosition();
int featureId;
double rotation;
QVector< QgsPoint > cornerPoints;
QgsRectangle labelRect;
double width;
double height;
QString layerID;
bool upsideDown;
};


/**
* \class QgsMapRenderer
Expand Down
4 changes: 4 additions & 0 deletions python/core/qgspoint.sip
Expand Up @@ -77,6 +77,10 @@ public:
@note added in QGIS 1.5*/
double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint& minDistPoint /Out/) const;

/**Calculates azimut between this point and other one (clockwise in degree, starting from north)
@note: this function has been added in version 1.7*/
double azimuth( const QgsPoint& other );

//! equality operator
bool operator==(const QgsPoint &other);

Expand Down
6 changes: 6 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -28,6 +28,7 @@ SET(QGIS_APP_SRCS
qgsidentifyresults.cpp
qgsfeatureaction.cpp
qgslabeldialog.cpp
qgslabelpropertydialog.cpp
qgslabelengineconfigdialog.cpp
qgslabelinggui.cpp
qgslabelpreview.cpp
Expand All @@ -37,17 +38,21 @@ SET(QGIS_APP_SRCS
qgsmaptooladdring.cpp
qgsmaptoolannotation.cpp
qgsmaptoolcapture.cpp
qgsmaptoolchangelabelproperties.cpp
qgsmaptooldeletering.cpp
qgsmaptooldeletepart.cpp
qgsmaptooldeletevertex.cpp
qgsmaptooledit.cpp
qgsmaptoolformannotation.cpp
qgsmaptoolidentify.cpp
qgsmaptoollabel.cpp
qgsmaptoolmeasureangle.cpp
qgsmaptoolmovefeature.cpp
qgsmaptoolmovelabel.cpp
qgsmaptoolmovevertex.cpp
qgsmaptoolnodetool.cpp
qgsmaptoolreshape.cpp
qgsmaptoolrotatelabel.cpp
qgsmaptoolrotatepointsymbols.cpp
qgsmaptoolselect.cpp
qgsmaptoolselectrectangle.cpp
Expand Down Expand Up @@ -175,6 +180,7 @@ SET (QGIS_APP_MOC_HDRS
qgsidentifyresults.h
qgsfeatureaction.h
qgslabeldialog.h
qgslabelpropertydialog.h
qgsmanageconnectionsdialog.h
qgsmaptoolidentify.h
qgsmaptoolsplitfeatures.h
Expand Down
55 changes: 54 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -212,6 +212,9 @@
#include "qgsmaptoolzoom.h"
#include "qgsmaptoolsimplify.h"
#include "qgsmeasuretool.h"
#include "qgsmaptoolmovelabel.h"
#include "qgsmaptoolrotatelabel.h"
#include "qgsmaptoolchangelabelproperties.h"

//
// Conditional Includes
Expand Down Expand Up @@ -580,6 +583,8 @@ QgisApp::~QgisApp()
delete mMapTools.mDeletePart;
delete mMapTools.mAddIsland;
delete mMapTools.mNodeTool;
delete mMapTools.mMoveLabel;
delete mMapTools.mChangeLabelProperties;

delete mPythonUtils;

Expand Down Expand Up @@ -1229,6 +1234,18 @@ void QgisApp::createActions()
mActionAbout->setMenuRole( QAction::AboutRole ); // put in application menu on Mac OS X
connect( mActionAbout, SIGNAL( triggered() ), this, SLOT( about() ) );

mActionMoveLabel = new QAction( getThemeIcon( "mActionMoveLabel.png" ), tr( "Move Label" ), this );
mActionMoveLabel->setStatusTip( tr( "Move labels interactively" ) );
connect( mActionMoveLabel, SIGNAL( triggered() ), this, SLOT( moveLabel() ) );

mActionRotateLabel = new QAction( getThemeIcon( "mActionRotateLabel.png" ), tr( "Rotate Label" ), this );
mActionRotateLabel->setStatusTip( tr( "Rotate labels interactively" ) );
connect( mActionRotateLabel, SIGNAL( triggered() ), this, SLOT( rotateLabel() ) );

mActionChangeLabelProperties = new QAction( getThemeIcon( "mActionChangeLabelProperties.png" ), tr( "Change label" ), this );
mActionChangeLabelProperties->setStatusTip( tr( "Change label properties" ) );
connect( mActionChangeLabelProperties, SIGNAL( triggered() ), this, SLOT( changeLabelProperties() ) );

mActionStyleManagerV2 = new QAction( tr( "Style manager..." ), this );
shortcuts->registerAction( mActionStyleManagerV2 );
mActionStyleManagerV2->setStatusTip( tr( "Show style manager V2" ) );
Expand Down Expand Up @@ -1349,6 +1366,12 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionNodeTool );
mActionRotatePointSymbols->setCheckable( true );
mMapToolGroup->addAction( mActionRotatePointSymbols );
mActionMoveLabel->setCheckable( true );
mMapToolGroup->addAction( mActionMoveLabel );
mActionRotateLabel->setCheckable( true );
mMapToolGroup->addAction( mActionRotateLabel );
mActionChangeLabelProperties->setCheckable( true );
mMapToolGroup->addAction( mActionChangeLabelProperties );
}

void QgisApp::createMenus()
Expand Down Expand Up @@ -1606,7 +1629,7 @@ void QgisApp::createMenus()
// don't add it yet, wait for a plugin
mDatabaseMenu = new QMenu( tr( "&Database" ) );


// Raster Menu

mRasterMenu = menuBar()->addMenu( tr( "&Raster" ) );
Expand Down Expand Up @@ -1843,6 +1866,15 @@ void QgisApp::createToolBars()
mHelpToolBar->addAction( mActionHelpContents );
mHelpToolBar->addAction( QWhatsThis::createAction() );
mToolbarMenu->addAction( mHelpToolBar->toggleViewAction() );

//Label Toolbar
mLabelToolBar = addToolBar( tr( "Label" ) );
mLabelToolBar->setIconSize( myIconSize );
mLabelToolBar->setObjectName( "Label" );
mLabelToolBar->addAction( mActionMoveLabel );
mLabelToolBar->addAction( mActionRotateLabel );
mLabelToolBar->addAction( mActionChangeLabelProperties );
mToolbarMenu->addAction( mLabelToolBar->toggleViewAction() );
}

void QgisApp::createStatusBar()
Expand Down Expand Up @@ -2245,6 +2277,12 @@ void QgisApp::createCanvasTools()
mMapTools.mNodeTool->setAction( mActionNodeTool );
mMapTools.mRotatePointSymbolsTool = new QgsMapToolRotatePointSymbols( mMapCanvas );
mMapTools.mRotatePointSymbolsTool->setAction( mActionRotatePointSymbols );
mMapTools.mMoveLabel = new QgsMapToolMoveLabel( mMapCanvas );
mMapTools.mMoveLabel->setAction( mActionMoveLabel );
mMapTools.mRotateLabel = new QgsMapToolRotateLabel( mMapCanvas );
mMapTools.mRotateLabel->setAction( mActionRotateLabel );
mMapTools.mChangeLabelProperties = new QgsMapToolChangeLabelProperties( mMapCanvas );
mMapTools.mChangeLabelProperties->setAction( mActionChangeLabelProperties );
//ensure that non edit tool is initialised or we will get crashes in some situations
mNonEditMapTool = mMapTools.mPan;
}
Expand Down Expand Up @@ -4250,6 +4288,21 @@ bool QgisApp::loadAnnotationItemsFromProject( const QDomDocument& doc )
return true;
}

void QgisApp::moveLabel()
{
mMapCanvas->setMapTool( mMapTools.mMoveLabel );
}

void QgisApp::rotateLabel()
{
mMapCanvas->setMapTool( mMapTools.mRotateLabel );
}

void QgisApp::changeLabelProperties()
{
mMapCanvas->setMapTool( mMapTools.mChangeLabelProperties );
}

QList<QgsAnnotationItem*> QgisApp::annotationItems()
{
QList<QgsAnnotationItem*> itemList;
Expand Down
15 changes: 15 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -757,6 +757,13 @@ class QgisApp : public QMainWindow

bool loadAnnotationItemsFromProject( const QDomDocument& doc );

//! Activates the move label tool
void moveLabel();
//! Activates rotate label tool
void rotateLabel();
//! Activates label property tool
void changeLabelProperties();

signals:
/** emitted when a key is pressed and we want non widget sublasses to be able
to pick up on this (e.g. maplayer) */
Expand Down Expand Up @@ -866,6 +873,7 @@ class QgisApp : public QMainWindow
QToolBar *mAttributesToolBar;
QToolBar *mPluginToolBar;
QToolBar *mHelpToolBar;
QToolBar *mLabelToolBar;

// actions for menus and toolbars -----------------

Expand Down Expand Up @@ -1002,6 +1010,10 @@ class QgisApp : public QMainWindow
QAction *mActionHelpSeparator2;
QAction *mActionAbout;

QAction *mActionMoveLabel;
QAction *mActionRotateLabel;
QAction *mActionChangeLabelProperties;

QAction *mActionUseRendererV2;
QAction *mActionStyleManagerV2;

Expand Down Expand Up @@ -1069,6 +1081,9 @@ class QgisApp : public QMainWindow
QgsMapTool* mAnnotation;
QgsMapTool* mFormAnnotation;
QgsMapTool* mTextAnnotation;
QgsMapTool* mMoveLabel;
QgsMapTool* mRotateLabel;
QgsMapTool* mChangeLabelProperties;
} mMapTools;

QgsMapTool *mNonEditMapTool;
Expand Down
76 changes: 76 additions & 0 deletions src/app/qgsmaptoolchangelabelproperties.cpp
@@ -0,0 +1,76 @@
/***************************************************************************
qgsmaptoolchangelabelproperties.cpp
---------------------------------
begin : 2010-11-11
copyright : (C) 2010 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsmaptoolchangelabelproperties.h"
#include "qgslabelpropertydialog.h"
#include "qgsmapcanvas.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"

QgsMapToolChangeLabelProperties::QgsMapToolChangeLabelProperties( QgsMapCanvas* canvas ): QgsMapToolLabel( canvas )
{
}

QgsMapToolChangeLabelProperties::~QgsMapToolChangeLabelProperties()
{
}

void QgsMapToolChangeLabelProperties::canvasPressEvent( QMouseEvent * e )
{
deleteRubberBands();

if ( !labelAtPosition( e, mCurrentLabelPos ) )
{
return;
}

QgsVectorLayer* vlayer = currentLayer();
if ( !vlayer || !vlayer->isEditable() )
{
return;
}

createRubberBands();
}

void QgsMapToolChangeLabelProperties::canvasReleaseEvent( QMouseEvent * e )
{
QgsVectorLayer* vlayer = currentLayer();
if ( mLabelRubberBand && mCanvas && vlayer )
{
QgsLabelPropertyDialog d( mCurrentLabelPos.layerID, mCurrentLabelPos.featureId, mCanvas->mapRenderer() );
if ( d.exec() == QDialog::Accepted )
{
const QgsAttributeMap& changes = d.changedProperties();
if ( changes.size() > 0 )
{
vlayer->beginEditCommand( tr( "Label properties changed" ) );

QgsAttributeMap::const_iterator changeIt = changes.constBegin();
for ( ; changeIt != changes.constEnd(); ++changeIt )
{
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value(), false );
}

vlayer->endEditCommand();
mCanvas->refresh();
}
}
deleteRubberBands();
}
}

34 changes: 34 additions & 0 deletions src/app/qgsmaptoolchangelabelproperties.h
@@ -0,0 +1,34 @@
/***************************************************************************
qgsmaptoolchangelabelproperties.h
---------------------------------
begin : 2010-11-11
copyright : (C) 2010 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSMAPTOOLCHANGELABELPROPERTIES_H
#define QGSMAPTOOLCHANGELABELPROPERTIES_H

#include "qgsmaptoollabel.h"

class QgsMapToolChangeLabelProperties: public QgsMapToolLabel
{
public:
QgsMapToolChangeLabelProperties( QgsMapCanvas* canvas );
~QgsMapToolChangeLabelProperties();

virtual void canvasPressEvent( QMouseEvent * e );
virtual void canvasReleaseEvent( QMouseEvent * e );

};

#endif // QGSMAPTOOLCHANGELABEL_H

0 comments on commit 1ae742e

Please sign in to comment.