Skip to content
Permalink
Browse files
Implement moving of snapped features together with the snap line
  • Loading branch information
mhugent committed Feb 20, 2013
1 parent 717918d commit 9aa865e0a038cbf41864f230fe61c398cf2dabf8
Showing with 141 additions and 20 deletions.
  1. +2 −0 src/app/composer/qgscomposer.h
  2. +1 −0 src/app/composer/qgscomposerhtmlwidget.cpp
  3. +1 −0 src/app/composer/qgscomposerlabelwidget.cpp
  4. +1 −0 src/app/composer/qgscomposerlegendwidget.cpp
  5. +1 −0 src/app/composer/qgscomposermapwidget.cpp
  6. +1 −0 src/app/composer/qgscomposerpicturewidget.cpp
  7. +1 −0 src/app/composer/qgscomposerscalebarwidget.cpp
  8. +1 −0 src/app/qgisapp.cpp
  9. +1 −0 src/core/composer/qgsaddremoveitemcommand.cpp
  10. +10 −9 src/core/composer/qgsatlascomposition.cpp
  11. +1 −0 src/core/composer/qgscomposerarrow.cpp
  12. +2 −0 src/core/composer/qgscomposerarrow.h
  13. +1 −0 src/core/composer/qgscomposerframe.cpp
  14. +2 −3 src/core/composer/qgscomposeritem.h
  15. +1 −0 src/core/composer/qgscomposerlabel.cpp
  16. +1 −0 src/core/composer/qgscomposerlabel.h
  17. +1 −0 src/core/composer/qgscomposerlegend.cpp
  18. +1 −0 src/core/composer/qgscomposermap.cpp
  19. +1 −0 src/core/composer/qgscomposermap.h
  20. +1 −0 src/core/composer/qgscomposermultiframe.cpp
  21. +1 −0 src/core/composer/qgscomposerpicture.cpp
  22. +2 −0 src/core/composer/qgscomposerpicture.h
  23. +1 −0 src/core/composer/qgscomposerscalebar.cpp
  24. +1 −0 src/core/composer/qgscomposerscalebar.h
  25. +2 −0 src/core/composer/qgscomposershape.h
  26. +1 −0 src/core/composer/qgscomposertable.h
  27. +54 −5 src/core/composer/qgscomposition.cpp
  28. +5 −2 src/core/composer/qgscomposition.h
  29. +1 −0 src/core/composer/qgspaperitem.cpp
  30. +38 −1 src/gui/qgscomposerruler.cpp
  31. +3 −0 src/gui/qgscomposerruler.h
@@ -24,6 +24,8 @@

class QgisApp;
class QgsComposerArrow;
class QgsComposerFrame;
class QgsComposerHtml;
class QgsComposerLabel;
class QgsComposerLegend;
class QgsComposerPicture;
@@ -17,6 +17,7 @@
#include "qgscomposeritemwidget.h"
#include "qgscomposermultiframecommand.h"
#include "qgscomposerhtml.h"
#include "qgscomposition.h"
#include <QFileDialog>
#include <QSettings>

@@ -18,6 +18,7 @@
#include "qgscomposerlabelwidget.h"
#include "qgscomposerlabel.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposition.h"
#include "qgsexpressionbuilderdialog.h"

#include <QColorDialog>
@@ -22,6 +22,7 @@
#include "qgscomposerlegendlayersdialog.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposermap.h"
#include "qgscomposition.h"
#include <QFontDialog>
#include <QColorDialog>

@@ -17,6 +17,7 @@

#include "qgscomposermapwidget.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposition.h"
#include "qgsmaprenderer.h"
#include "qgsstylev2.h"
#include "qgssymbolv2.h"
@@ -20,6 +20,7 @@
#include "qgscomposermap.h"
#include "qgscomposerpicture.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposition.h"
#include <QDoubleValidator>
#include <QFileDialog>
#include <QFileInfo>
@@ -18,6 +18,7 @@
#include "qgscomposeritemwidget.h"
#include "qgscomposermap.h"
#include "qgscomposerscalebar.h"
#include "qgscomposition.h"
#include <QColorDialog>
#include <QFontDialog>
#include <QWidget>
@@ -69,6 +69,7 @@

#include <qgsnetworkaccessmanager.h>
#include <qgsapplication.h>
#include <qgscomposition.h>

#include <QNetworkReply>
#include <QNetworkProxy>
@@ -17,6 +17,7 @@

#include "qgsaddremoveitemcommand.h"
#include "qgscomposeritem.h"
#include "qgscomposition.h"

QgsAddRemoveItemCommand::QgsAddRemoveItemCommand( State s, QgsComposerItem* item, QgsComposition* c, const QString& text, QUndoCommand* parent ):
QUndoCommand( text, parent ), mItem( item ), mComposition( c ), mState( s ), mFirstRun( true )
@@ -19,6 +19,7 @@
#include "qgsatlascomposition.h"
#include "qgsvectorlayer.h"
#include "qgscomposermap.h"
#include "qgscomposition.h"
#include "qgsvectordataprovider.h"
#include "qgsexpression.h"
#include "qgsgeometry.h"
@@ -49,7 +50,7 @@ void QgsAtlasComposition::setCoverageLayer( QgsVectorLayer* layer )
mCoverageLayer = layer;

// update the number of features
QgsExpression::setSpecialColumn( "$numfeatures", QVariant( (int)mFeatureIds.size() ) );
QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )mFeatureIds.size() ) );
}

void QgsAtlasComposition::beginRender()
@@ -213,18 +214,18 @@ void QgsAtlasComposition::prepareForFeature( size_t featureI )
// geometry height is too big
if ( geom_ratio < map_ratio )
{
// extent the bbox's width
double adj_width = ( map_ratio * geom_rect.height() - geom_rect.width() ) / 2.0;
xa1 -= adj_width;
xa2 += adj_width;
// extent the bbox's width
double adj_width = ( map_ratio * geom_rect.height() - geom_rect.width() ) / 2.0;
xa1 -= adj_width;
xa2 += adj_width;
}
// geometry width is too big
else if ( geom_ratio > map_ratio )
{
// extent the bbox's height
double adj_height = (geom_rect.width() / map_ratio - geom_rect.height() ) / 2.0;
ya1 -= adj_height;
ya2 += adj_height;
// extent the bbox's height
double adj_height = ( geom_rect.width() / map_ratio - geom_rect.height() ) / 2.0;
ya1 -= adj_height;
ya2 += adj_height;
}
new_extent = QgsRectangle( xa1, ya1, xa2, ya2 );

@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgscomposerarrow.h"
#include "qgscomposition.h"
#include <QPainter>
#include <QSvgRenderer>

@@ -19,6 +19,8 @@
#define QGSCOMPOSERARROW_H

#include "qgscomposeritem.h"
#include <QBrush>
#include <QPen>

/**An item that draws an arrow between to points*/
class CORE_EXPORT QgsComposerArrow: public QgsComposerItem
@@ -15,6 +15,7 @@

#include "qgscomposerframe.h"
#include "qgscomposermultiframe.h"
#include "qgscomposition.h"

QgsComposerFrame::QgsComposerFrame( QgsComposition* c, QgsComposerMultiFrame* mf, qreal x, qreal y, qreal width, qreal height )
: QgsComposerItem( x, y, width, height, c )
@@ -17,17 +17,16 @@
#ifndef QGSCOMPOSERITEM_H
#define QGSCOMPOSERITEM_H

#include "qgscomposition.h"
#include "qgscomposeritemcommand.h"
#include <QGraphicsRectItem>
#include <QObject>

class QgsComposition;
class QWidget;
class QDomDocument;
class QDomElement;
class QGraphicsLineItem;

class QqsComposition;

/** \ingroup MapComposer
* A item that forms part of a map composition.
*/
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgscomposerlabel.h"
#include "qgscomposition.h"
#include "qgsexpression.h"
#include <QDate>
#include <QDomElement>
@@ -18,6 +18,7 @@
#define QGSCOMPOSERLABEL_H

#include "qgscomposeritem.h"
#include <QFont>

class QgsVectorLayer;
class QgsFeature;
@@ -19,6 +19,7 @@
#include "qgscomposerlegend.h"
#include "qgscomposerlegenditem.h"
#include "qgscomposermap.h"
#include "qgscomposition.h"
#include "qgslogger.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgscomposermap.h"
#include "qgscomposition.h"
#include "qgscoordinatetransform.h"
#include "qgslogger.h"
#include "qgsmaprenderer.h"
@@ -20,6 +20,7 @@
//#include "ui_qgscomposermapbase.h"
#include "qgscomposeritem.h"
#include "qgsrectangle.h"
#include <QFont>
#include <QGraphicsRectItem>

class QgsComposition;
@@ -15,6 +15,7 @@

#include "qgscomposermultiframe.h"
#include "qgscomposerframe.h"
#include "qgscomposition.h"

QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c, bool createUndoCommands ): mComposition( c ), mResizeMode( UseExistingFrames ), mCreateUndoCommands( createUndoCommands )
{
@@ -17,6 +17,7 @@

#include "qgscomposerpicture.h"
#include "qgscomposermap.h"
#include "qgscomposition.h"
#include "qgsproject.h"
#include <QDomDocument>
#include <QDomElement>
@@ -22,6 +22,8 @@
#include <QImage>
#include <QSvgRenderer>

class QgsComposerMap;

/** \ingroup MapComposer
* A composer class that displays svg files or raster format (jpg, png, ...)
* */
@@ -16,6 +16,7 @@

#include "qgscomposerscalebar.h"
#include "qgscomposermap.h"
#include "qgscomposition.h"
#include "qgsdistancearea.h"
#include "qgsscalebarstyle.h"
#include "qgsdoubleboxscalebarstyle.h"
@@ -17,6 +17,7 @@
#define QGSCOMPOSERSCALEBAR_H

#include "qgscomposeritem.h"
#include <QFont>
#include <QPen>
#include <QColor>

@@ -19,6 +19,8 @@
#define QGSCOMPOSERSHAPE_H

#include "qgscomposeritem.h"
#include <QBrush>
#include <QPen>

/**A composer items that draws common shapes (ellipse, triangle, rectangle)*/
class CORE_EXPORT QgsComposerShape: public QgsComposerItem
@@ -19,6 +19,7 @@
#define QGSCOMPOSERTABLE_H

#include "qgscomposeritem.h"
#include "qgscomposition.h"
#include "qgsfeature.h"
#include <QSet>

@@ -17,7 +17,6 @@
#include <stdexcept>

#include "qgscomposition.h"
#include "qgscomposeritem.h"
#include "qgscomposerarrow.h"
#include "qgscomposerframe.h"
#include "qgscomposerhtml.h"
@@ -1077,25 +1076,28 @@ void QgsComposition::removeSnapLine( QGraphicsLineItem* line )
delete line;
}

QGraphicsLineItem* QgsComposition::nearestSnapLine( bool horizontal, double x, double y, double tolerance )
QGraphicsLineItem* QgsComposition::nearestSnapLine( bool horizontal, double x, double y, double tolerance,
QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode> >& snappedItems )
{
bool xDirection = doubleNear( y, 0.0 );
double minSqrDist = DBL_MAX;
QGraphicsLineItem* item = 0;
double currentXCoord = 0;
double currentYCoord = 0;
double currentSqrDist = 0;
double sqrTolerance = tolerance * tolerance;

snappedItems.clear();

QList< QGraphicsLineItem* >::const_iterator it = mSnapLines.constBegin();
for ( ; it != mSnapLines.constEnd(); ++it )
{
if ( horizontal )
bool itemHorizontal = doubleNear(( *it )->line().y2() - ( *it )->line().y1(), 0 );
if ( horizontal && itemHorizontal )
{
currentYCoord = ( *it )->line().y1();
currentSqrDist = ( y - currentYCoord ) * ( y - currentYCoord );
}
else
else if ( !itemHorizontal )
{
currentXCoord = ( *it )->line().x1();
currentSqrDist = ( x - currentXCoord ) * ( x - currentXCoord );
@@ -1108,6 +1110,53 @@ QGraphicsLineItem* QgsComposition::nearestSnapLine( bool horizontal, double x, d
}
}

double itemTolerance = 0.0000001;
if ( item )
{
//go through all the items to find items snapped to this snap line
QList<QGraphicsItem *> itemList = items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
QgsComposerItem* currentItem = dynamic_cast<QgsComposerItem*>( *itemIt );
if ( !currentItem || currentItem->type() == QgsComposerItem::ComposerPaper )
{
continue;
}

if ( horizontal )
{
if ( doubleNear( currentYCoord, currentItem->transform().dy() + currentItem->rect().top(), itemTolerance ) )
{
snappedItems.append( qMakePair( currentItem, QgsComposerItem::UpperMiddle ) );
}
else if ( doubleNear( currentYCoord, currentItem->transform().dy() + currentItem->rect().center().y(), itemTolerance ) )
{
snappedItems.append( qMakePair( currentItem, QgsComposerItem::Middle ) );
}
else if ( doubleNear( currentYCoord, currentItem->transform().dy() + currentItem->rect().bottom(), itemTolerance ) )
{
snappedItems.append( qMakePair( currentItem, QgsComposerItem::LowerMiddle ) );
}
}
else
{
if ( doubleNear( currentXCoord, currentItem->transform().dx(), itemTolerance ) )
{
snappedItems.append( qMakePair( currentItem, QgsComposerItem::MiddleLeft ) );
}
else if ( doubleNear( currentXCoord, currentItem->transform().dx() + currentItem->rect().center().x(), itemTolerance ) )
{
snappedItems.append( qMakePair( currentItem, QgsComposerItem::Middle ) );
}
else if ( doubleNear( currentXCoord, currentItem->transform().dx() + currentItem->rect().width(), itemTolerance ) )
{
snappedItems.append( qMakePair( currentItem, QgsComposerItem::MiddleRight ) );
}
}
}
}

return item;
}

@@ -16,11 +16,14 @@
#ifndef QGSCOMPOSITION_H
#define QGSCOMPOSITION_H

#include "qgscomposeritem.h"
#include <memory>

#include <QDomDocument>
#include <QGraphicsScene>
#include <QLinkedList>
#include <QList>
#include <QPair>
#include <QSet>
#include <QUndoStack>
#include <QPrinter>
@@ -30,8 +33,8 @@
#include "qgscomposeritemcommand.h"
#include "qgsatlascomposition.h"


class QgsComposerFrame;
class QgsComposerItem;
class QgsComposerMap;
class QgsPaperItem;
class QGraphicsRectItem;
@@ -264,7 +267,7 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
/**Remove custom snap line (and delete the object)*/
void removeSnapLine( QGraphicsLineItem* line );
/**Get nearest snap line*/
QGraphicsLineItem* nearestSnapLine( bool horizontal, double x, double y, double tolerance );
QGraphicsLineItem* nearestSnapLine( bool horizontal, double x, double y, double tolerance, QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode > >& snappedItems );

/**Allocates new item command and saves initial state in it
@param item target item
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgspaperitem.h"
#include "qgscomposition.h"
#include <QPainter>

QgsPaperItem::QgsPaperItem( QgsComposition* c ): QgsComposerItem( c, false )
Loading

0 comments on commit 9aa865e

Please sign in to comment.