Skip to content
Permalink
Browse files

[FEATURE]: move/rotate/change label edit tools to interactively chang…

…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
mhugent committed Nov 17, 2010
1 parent 535b533 commit 1ae742e086c4fdcc1e8b5b90cb806548ceb095ae
@@ -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>
@@ -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>
@@ -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>
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
@@ -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);

@@ -28,6 +28,7 @@ SET(QGIS_APP_SRCS
qgsidentifyresults.cpp
qgsfeatureaction.cpp
qgslabeldialog.cpp
qgslabelpropertydialog.cpp
qgslabelengineconfigdialog.cpp
qgslabelinggui.cpp
qgslabelpreview.cpp
@@ -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
@@ -175,6 +180,7 @@ SET (QGIS_APP_MOC_HDRS
qgsidentifyresults.h
qgsfeatureaction.h
qgslabeldialog.h
qgslabelpropertydialog.h
qgsmanageconnectionsdialog.h
qgsmaptoolidentify.h
qgsmaptoolsplitfeatures.h
@@ -212,6 +212,9 @@
#include "qgsmaptoolzoom.h"
#include "qgsmaptoolsimplify.h"
#include "qgsmeasuretool.h"
#include "qgsmaptoolmovelabel.h"
#include "qgsmaptoolrotatelabel.h"
#include "qgsmaptoolchangelabelproperties.h"

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

delete mPythonUtils;

@@ -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" ) );
@@ -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()
@@ -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" ) );
@@ -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()
@@ -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;
}
@@ -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;
@@ -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) */
@@ -866,6 +873,7 @@ class QgisApp : public QMainWindow
QToolBar *mAttributesToolBar;
QToolBar *mPluginToolBar;
QToolBar *mHelpToolBar;
QToolBar *mLabelToolBar;

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

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

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

QAction *mActionUseRendererV2;
QAction *mActionStyleManagerV2;

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

QgsMapTool *mNonEditMapTool;
@@ -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();
}
}

@@ -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.
You can’t perform that action at this time.