Skip to content

Commit

Permalink
Restore ability to show/hide selection bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent 1f94b82 commit 2d6cbd6
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 28 deletions.
13 changes: 13 additions & 0 deletions python/core/layout/qgslayoutcontext.sip
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ class QgsLayoutContext
%Docstring
Sets whether the page grid should be ``visible``.
.. seealso:: gridVisible()
%End

bool boundingBoxesVisible() const;
%Docstring
Returns true if the item bounding boxes should be drawn.
.. seealso:: setBoundingBoxesVisible()
:rtype: bool
%End

void setBoundingBoxesVisible( bool visible );
%Docstring
Sets whether the item bounding boxes should be ``visible``.
.. seealso:: boundingBoxesVisible()
%End

};
Expand Down
9 changes: 9 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
connect( mActionShowGuides, &QAction::triggered, this, &QgsLayoutDesignerDialog::showGuides );
connect( mActionSnapGuides, &QAction::triggered, this, &QgsLayoutDesignerDialog::snapToGuides );

connect( mActionShowBoxes, &QAction::triggered, this, &QgsLayoutDesignerDialog::showBoxes );

mView = new QgsLayoutView();
//mView->setMapCanvas( mQgis->mapCanvas() );
mView->setContentsMargins( 0, 0, 0, 0 );
Expand Down Expand Up @@ -341,6 +343,7 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
mActionSnapGrid->setChecked( mLayout->snapper().snapToGrid() );
mActionShowGuides->setChecked( mLayout->guides().visible() );
mActionSnapGuides->setChecked( mLayout->snapper().snapToGuides() );
mActionShowBoxes->setChecked( mLayout->context().boundingBoxesVisible() );

connect( mLayout->undoStack()->stack(), &QUndoStack::canUndoChanged, mActionUndo, &QAction::setEnabled );
connect( mLayout->undoStack()->stack(), &QUndoStack::canRedoChanged, mActionRedo, &QAction::setEnabled );
Expand Down Expand Up @@ -433,6 +436,12 @@ void QgsLayoutDesignerDialog::showGrid( bool visible )
mLayout->pageCollection()->redraw();
}

void QgsLayoutDesignerDialog::showBoxes( bool visible )
{
mLayout->context().setBoundingBoxesVisible( visible );
mView->mouseHandles()->update();
}

void QgsLayoutDesignerDialog::snapToGrid( bool enabled )
{
mLayout->snapper().setSnapToGrid( enabled );
Expand Down
5 changes: 5 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
void showGrid( bool visible );

/**
* Toggles whether the item bounding boxes should be \a visible.
*/
void showBoxes( bool visible );

/**
* Toggles whether snapping to the page grid is \a enabled.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/core/layout/qgslayoutcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,13 @@ void QgsLayoutContext::setGridVisible( bool visible )
{
mGridVisible = visible;
}

bool QgsLayoutContext::boundingBoxesVisible() const
{
return mBoundingBoxesVisible;
}

void QgsLayoutContext::setBoundingBoxesVisible( bool visible )
{
mBoundingBoxesVisible = visible;
}
13 changes: 13 additions & 0 deletions src/core/layout/qgslayoutcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ class CORE_EXPORT QgsLayoutContext
*/
void setGridVisible( bool visible );

/**
* Returns true if the item bounding boxes should be drawn.
* \see setBoundingBoxesVisible()
*/
bool boundingBoxesVisible() const;

/**
* Sets whether the item bounding boxes should be \a visible.
* \see boundingBoxesVisible()
*/
void setBoundingBoxesVisible( bool visible );

private:

Flags mFlags = 0;
Expand All @@ -161,6 +173,7 @@ class CORE_EXPORT QgsLayoutContext
QgsLayoutMeasurementConverter mMeasurementConverter;

bool mGridVisible = false;
bool mBoundingBoxesVisible = true;


};
Expand Down
4 changes: 2 additions & 2 deletions src/gui/layout/qgslayoutmousehandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ void QgsLayoutMouseHandles::paint( QPainter *painter, const QStyleOptionGraphics
}
#endif

if ( true /*|| mLayout->boundingBoxesVisible() TODO */ )
if ( mLayout->context().boundingBoxesVisible() )
{
//draw resize handles around bounds of entire selection
double rectHandlerSize = rectHandlerBorderTolerance();
drawHandles( painter, rectHandlerSize );
}

if ( mIsResizing || mIsDragging /*|| mComposition->boundingBoxesVisible()*/ )
if ( mIsResizing || mIsDragging || mLayout->context().boundingBoxesVisible() )
{
//draw dotted boxes around selected items
drawSelectedItemBounds( painter );
Expand Down
41 changes: 15 additions & 26 deletions src/ui/layout/qgslayoutdesignerbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<addaction name="mActionClearGuides"/>
<addaction name="separator"/>
<addaction name="mActionShowRulers"/>
<addaction name="mActionShowBoxes"/>
<addaction name="separator"/>
<addaction name="mToolbarMenu"/>
<addaction name="mPanelsMenu"/>
Expand Down Expand Up @@ -436,6 +437,20 @@
<string>Ctrl+Shift+Z</string>
</property>
</action>
<action name="mActionShowBoxes">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Show Bounding Boxes</string>
</property>
<property name="toolTip">
<string>Show bounding boxes</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+B</string>
</property>
</action>
</widget>
<resources>
<include location="../../../images/images.qrc"/>
Expand Down Expand Up @@ -465,32 +480,6 @@
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
</resources>
<connections/>
</ui>
10 changes: 10 additions & 0 deletions tests/src/core/testqgslayoutcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TestQgsLayoutContext: public QObject
void layer();
void dpi();
void renderContextFlags();
void boundingBoxes();

private:
QString mReport;
Expand Down Expand Up @@ -158,5 +159,14 @@ void TestQgsLayoutContext::renderContextFlags()
QVERIFY( ( flags & QgsRenderContext::ForceVectorOutput ) );
}

void TestQgsLayoutContext::boundingBoxes()
{
QgsLayoutContext context;
context.setBoundingBoxesVisible( false );
QVERIFY( !context.boundingBoxesVisible() );
context.setBoundingBoxesVisible( true );
QVERIFY( context.boundingBoxesVisible() );
}

QGSTEST_MAIN( TestQgsLayoutContext )
#include "testqgslayoutcontext.moc"

0 comments on commit 2d6cbd6

Please sign in to comment.