Skip to content
Permalink
Browse files

Allow selection of a polygon symbol for the overview frame

  • Loading branch information
mhugent committed Jul 10, 2012
1 parent 7a349a9 commit 53fc584a7231d9024be84e3b3f8dfabc29a89bff
@@ -18,6 +18,9 @@
#include "qgscomposermapwidget.h"
#include "qgscomposeritemwidget.h"
#include "qgsmaprenderer.h"
#include "qgssymbolv2.h"
#include "qgssymbolv2propertiesdialog.h"
#include "qgssymbollayerv2utils.h"
#include <QColorDialog>
#include <QFontDialog>

@@ -484,6 +487,7 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
mFrameStyleComboBox->blockSignals( b );
mFrameWidthSpinBox->blockSignals( b );
mOverviewFrameMapComboBox->blockSignals( b );
mOverviewFrameStyleButton->blockSignals( b );
}

void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
@@ -590,6 +594,19 @@ void QgsComposerMapWidget::on_mOverviewFrameMapComboBox_currentIndexChanged( con
mComposerMap->update();
}

void QgsComposerMapWidget::on_mOverviewFrameStyleButton_clicked()
{
if ( !mComposerMap )
{
return;
}
QgsSymbolV2PropertiesDialog d( mComposerMap->overviewFrameMapSymbol(), 0, this );
if ( d.exec() == QDialog::Accepted )
{
updateOverviewSymbolMarker();
}
}

void QgsComposerMapWidget::on_mGridCheckBox_toggled( bool state )
{
if ( !mComposerMap )
@@ -967,3 +984,12 @@ void QgsComposerMapWidget::initAnnotationDirectionBox( QComboBox* c, QgsComposer
c->setCurrentIndex( c->findText( tr( "Horizontal" ) ) );
}
}

void QgsComposerMapWidget::updateOverviewSymbolMarker()
{
if ( mComposerMap )
{
QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mComposerMap->overviewFrameMapSymbol(), mOverviewFrameStyleButton->iconSize() );
mOverviewFrameStyleButton->setIcon( icon );
}
}
@@ -44,6 +44,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
void on_mKeepLayerListCheckBox_stateChanged( int state );
void on_mDrawCanvasItemsCheckBox_stateChanged( int state );
void on_mOverviewFrameMapComboBox_currentIndexChanged( const QString& text );
void on_mOverviewFrameStyleButton_clicked();

void on_mXMinLineEdit_editingFinished();
void on_mXMaxLineEdit_editingFinished();
@@ -105,6 +106,8 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase

void initAnnotationPositionBox( QComboBox* c, QgsComposerMap::GridAnnotationPosition pos );
void initAnnotationDirectionBox( QComboBox* c, QgsComposerMap::GridAnnotationDirection dir );

void updateOverviewSymbolMarker();
};

#endif
@@ -46,6 +46,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
{
mComposition = composition;
mOverviewFrameMapSymbol = new QgsFillSymbolV2();

//mId = mComposition->composerMapItems().size();
int maxId = -1;
@@ -92,6 +93,9 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ),
mMapCanvas( 0 ), mDrawCanvasItems( true )
{

mOverviewFrameMapSymbol = new QgsFillSymbolV2();

//Offset
mXOffset = 0.0;
mYOffset = 0.0;
@@ -110,6 +114,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )

QgsComposerMap::~QgsComposerMap()
{
delete mOverviewFrameMapSymbol;
}

void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const QSize& size, int dpi )
@@ -756,7 +761,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mPreviewMode = Rectangle;
}

mOverviewFrameMapId = itemElem.attribute( "overviewFrameMap", "-1" ).toInt();
setOverviewFrameMap( itemElem.attribute( "overviewFrameMap", "-1" ).toInt() );

//extent
QDomNodeList extentNodeList = itemElem.elementsByTagName( "Extent" );
@@ -1570,6 +1575,12 @@ void QgsComposerMap::setOverviewFrameMap( int mapId )
update();
}

void QgsComposerMap::setOverviewFrameMapSymbol( QgsFillSymbolV2* symbol )
{
delete mOverviewFrameMapSymbol;
mOverviewFrameMapSymbol = symbol;
}

void QgsComposerMap::transformShift( double& xShift, double& yShift ) const
{
double mmToMapUnits = 1.0 / mapUnitsToMM();
@@ -1881,7 +1892,7 @@ void QgsComposerMap::sortGridLinesOnBorders( const QList< QPair< double, QLineF

void QgsComposerMap::drawOverviewMapExtent( QPainter* p )
{
if ( mOverviewFrameMapId == -1 )
if ( mOverviewFrameMapId == -1 || !mComposition )
{
return;
}
@@ -1896,11 +1907,41 @@ void QgsComposerMap::drawOverviewMapExtent( QPainter* p )
QgsRectangle thisExtent = extent();
QgsRectangle intersectRect = thisExtent.intersect( &otherExtent );

p->setPen( QPen( Qt::red ) ); //todo: make appearance configurable
QgsRenderContext context;
context.setPainter( p );
if ( mPreviewMode == Rectangle )
{
return;
}
else if ( mComposition->plotStyle() == QgsComposition::Preview )
{
context.setScaleFactor( 1.0 );
context.setRasterScaleFactor( /*96.0*/ mComposition->printResolution() / 25.4 );
}
else //print
{
context.setScaleFactor( 1.0 );
double rasterScaleFactor = mComposition->printResolution() / 25.4;
context.setRasterScaleFactor( rasterScaleFactor );
}

QPolygonF polygon;
double x = ( intersectRect.xMinimum() - thisExtent.xMinimum() ) / thisExtent.width() * rect().width();
double y = ( thisExtent.yMaximum() - intersectRect.yMaximum() ) / thisExtent.height() * rect().height();
double width = intersectRect.width() / thisExtent.width() * rect().width();
double height = intersectRect.height() / thisExtent.height() * rect().height();
polygon << QPointF( x, y ) << QPointF( x + width, y ) << QPointF( x + width, y + height ) << QPointF( x, y + height );

QList<QPolygonF> rings; //empty list
mOverviewFrameMapSymbol->startRender( context );
mOverviewFrameMapSymbol->renderPolygon( polygon, &rings, 0, context );
mOverviewFrameMapSymbol->stopRender( context );

/*p->setPen( QPen( Qt::red ) ); //todo: make appearance configurable
p->setBrush( QBrush( QColor( 255, 0, 0, 100 ) ) );
double x = ( intersectRect.xMinimum() - thisExtent.xMinimum() ) / thisExtent.width() * rect().width();
double y = ( thisExtent.yMaximum() - intersectRect.yMaximum() ) / thisExtent.height() * rect().height();
double width = intersectRect.width() / thisExtent.width() * rect().width();
double height = intersectRect.height() / thisExtent.height() * rect().height();
p->drawRect( QRectF( x, y, width, height ) );
p->drawRect( QRectF( x, y, width, height ) );*/
}
@@ -29,6 +29,7 @@ class QDomNode;
class QDomDocument;
class QGraphicsView;
class QPainter;
class QgsFillSymbolV2;

/** \ingroup MapComposer
* \class QgsComposerMap
@@ -296,6 +297,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
@note: this function was added in version 1.9*/
int overviewFrameMapId() const { return mOverviewFrameMapId; }

void setOverviewFrameMapSymbol( QgsFillSymbolV2* symbol );
QgsFillSymbolV2* overviewFrameMapSymbol() { return mOverviewFrameMapSymbol; }

signals:
void extentChanged();

@@ -348,6 +352,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem

/**Id of map which displays its extent rectangle into this composer map (overview map functionality). -1 if not present*/
int mOverviewFrameMapId;
/**Drawing style for overview farme*/
QgsFillSymbolV2* mOverviewFrameMapSymbol;

/**Establishes signal/slot connection for update in case of layer change*/
void connectUpdateSlot();
@@ -230,6 +230,20 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="mFrameStyleLabel_2">
<property name="text">
<string>Frame style</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="mOverviewFrameStyleButton">
<property name="text">
<string>Change...</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">

0 comments on commit 53fc584

Please sign in to comment.
You can’t perform that action at this time.