Skip to content

Commit

Permalink
Show item size in status bar when creating a new item
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 10, 2018
1 parent b95363c commit 1402f76
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
%Include layertree/qgslayertreeembeddedconfigwidget.sip
%Include layertree/qgslayertreeembeddedwidgetregistry.sip
%Include layout/qgslayoutviewmouseevent.sip
%Include layout/qgslayoutviewrubberband.sip
%Include raster/qgsrasterrendererwidget.sip
%Include symbology/qgssymbolwidgetcontext.sip
%Include qgisinterface.sip
Expand Down Expand Up @@ -295,6 +294,7 @@
%Include layout/qgslayoutruler.sip
%Include layout/qgslayoutunitscombobox.sip
%Include layout/qgslayoutview.sip
%Include layout/qgslayoutviewrubberband.sip
%Include layout/qgslayoutviewtool.sip
%Include layout/qgslayoutviewtooladditem.sip
%Include layout/qgslayoutviewtooladdnodeitem.sip
Expand Down
12 changes: 11 additions & 1 deletion python/gui/layout/qgslayoutviewrubberband.sip
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@



class QgsLayoutViewRubberBand
class QgsLayoutViewRubberBand : QObject
{
%Docstring
QgsLayoutViewRubberBand is an abstract base class for temporary rubber band items
Expand Down Expand Up @@ -109,6 +109,16 @@ Sets the ``pen`` used for drawing the rubber band.
.. seealso:: :py:func:`pen`

.. seealso:: :py:func:`setBrush`
%End

signals:

void sizeChanged( const QString &size );
%Docstring
Emitted when the size of the rubber band is changed. The ``size``
argument gives a translated string describing the new rubber band size,
with a format which differs per subclass (e.g. rectangles may describe
a size using width and height, while circles may describe a size by radius).
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ SET(QGIS_GUI_MOC_HDRS
layout/qgslayoutruler.h
layout/qgslayoutunitscombobox.h
layout/qgslayoutview.h
layout/qgslayoutviewrubberband.h
layout/qgslayoutviewtool.h
layout/qgslayoutviewtooladditem.h
layout/qgslayoutviewtooladdnodeitem.h
Expand Down Expand Up @@ -804,7 +805,6 @@ SET(QGIS_GUI_HDRS

layout/qgslayoutreportsectionlabel.h
layout/qgslayoutviewmouseevent.h
layout/qgslayoutviewrubberband.h

raster/qgsrasterrendererwidget.h

Expand Down
6 changes: 6 additions & 0 deletions src/gui/layout/qgslayoutviewrubberband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ void QgsLayoutViewRectangularRubberBand::update( QPointF position, Qt::KeyboardM
QTransform t;
t.translate( newRect.x(), newRect.y() );
mRubberBandItem->setTransform( t );

emit sizeChanged( tr( "width: %1 %3 height: %2 %3" ).arg( newRect.width() ).arg( newRect.height() ).arg( QgsUnitTypes::toAbbreviatedString( layout()->units() ) ) );
}

QRectF QgsLayoutViewRectangularRubberBand::finish( QPointF position, Qt::KeyboardModifiers modifiers )
Expand Down Expand Up @@ -234,6 +236,8 @@ void QgsLayoutViewEllipticalRubberBand::update( QPointF position, Qt::KeyboardMo
QTransform t;
t.translate( newRect.x(), newRect.y() );
mRubberBandItem->setTransform( t );

emit sizeChanged( tr( "width: %1 %3 height: %2 %3" ).arg( newRect.width() ).arg( newRect.height() ).arg( QgsUnitTypes::toAbbreviatedString( layout()->units() ) ) );
}

QRectF QgsLayoutViewEllipticalRubberBand::finish( QPointF position, Qt::KeyboardModifiers modifiers )
Expand Down Expand Up @@ -309,6 +313,8 @@ void QgsLayoutViewTriangleRubberBand::update( QPointF position, Qt::KeyboardModi
QTransform t;
t.translate( newRect.x(), newRect.y() );
mRubberBandItem->setTransform( t );

emit sizeChanged( tr( "width: %1 %3 height: %2 %3" ).arg( newRect.width() ).arg( newRect.height() ).arg( QgsUnitTypes::toAbbreviatedString( layout()->units() ) ) );
}

QRectF QgsLayoutViewTriangleRubberBand::finish( QPointF position, Qt::KeyboardModifiers modifiers )
Expand Down
15 changes: 14 additions & 1 deletion src/gui/layout/qgslayoutviewrubberband.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "qgis_sip.h"
#include <QBrush>
#include <QPen>
#include <QObject>

class QgsLayoutView;
class QGraphicsRectItem;
Expand All @@ -35,9 +36,11 @@ class QgsLayout;
* in various shapes, for use within QgsLayoutView widgets.
* \since QGIS 3.0
*/
class GUI_EXPORT QgsLayoutViewRubberBand
class GUI_EXPORT QgsLayoutViewRubberBand : public QObject
{

Q_OBJECT

#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
if ( dynamic_cast<QgsLayoutViewMouseEvent *>( sipCpp ) )
Expand Down Expand Up @@ -120,6 +123,16 @@ class GUI_EXPORT QgsLayoutViewRubberBand
*/
void setPen( const QPen &pen );

signals:

/**
* Emitted when the size of the rubber band is changed. The \a size
* argument gives a translated string describing the new rubber band size,
* with a format which differs per subclass (e.g. rectangles may describe
* a size using width and height, while circles may describe a size by radius).
*/
void sizeChanged( const QString &size );

protected:

/**
Expand Down
4 changes: 4 additions & 0 deletions src/gui/layout/qgslayoutviewtooladditem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ void QgsLayoutViewToolAddItem::layoutPressEvent( QgsLayoutViewMouseEvent *event
mRubberBand.reset( QgsGui::layoutItemGuiRegistry()->createItemRubberBand( mItemMetadataId, view() ) );
if ( mRubberBand )
{
connect( mRubberBand.get(), &QgsLayoutViewRubberBand::sizeChanged, this, [ = ]( const QString & size )
{
view()->pushStatusMessage( size );
} );
mRubberBand->start( event->snappedPoint(), event->modifiers() );
}
}
Expand Down

0 comments on commit 1402f76

Please sign in to comment.