Skip to content

Commit 2d6cbd6

Browse files
committedOct 6, 2017
Restore ability to show/hide selection bounds
1 parent 1f94b82 commit 2d6cbd6

File tree

8 files changed

+77
-28
lines changed

8 files changed

+77
-28
lines changed
 

‎python/core/layout/qgslayoutcontext.sip

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ class QgsLayoutContext
136136
%Docstring
137137
Sets whether the page grid should be ``visible``.
138138
.. seealso:: gridVisible()
139+
%End
140+
141+
bool boundingBoxesVisible() const;
142+
%Docstring
143+
Returns true if the item bounding boxes should be drawn.
144+
.. seealso:: setBoundingBoxesVisible()
145+
:rtype: bool
146+
%End
147+
148+
void setBoundingBoxesVisible( bool visible );
149+
%Docstring
150+
Sets whether the item bounding boxes should be ``visible``.
151+
.. seealso:: boundingBoxesVisible()
139152
%End
140153

141154
};

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
141141
connect( mActionShowGuides, &QAction::triggered, this, &QgsLayoutDesignerDialog::showGuides );
142142
connect( mActionSnapGuides, &QAction::triggered, this, &QgsLayoutDesignerDialog::snapToGuides );
143143

144+
connect( mActionShowBoxes, &QAction::triggered, this, &QgsLayoutDesignerDialog::showBoxes );
145+
144146
mView = new QgsLayoutView();
145147
//mView->setMapCanvas( mQgis->mapCanvas() );
146148
mView->setContentsMargins( 0, 0, 0, 0 );
@@ -341,6 +343,7 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
341343
mActionSnapGrid->setChecked( mLayout->snapper().snapToGrid() );
342344
mActionShowGuides->setChecked( mLayout->guides().visible() );
343345
mActionSnapGuides->setChecked( mLayout->snapper().snapToGuides() );
346+
mActionShowBoxes->setChecked( mLayout->context().boundingBoxesVisible() );
344347

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

439+
void QgsLayoutDesignerDialog::showBoxes( bool visible )
440+
{
441+
mLayout->context().setBoundingBoxesVisible( visible );
442+
mView->mouseHandles()->update();
443+
}
444+
436445
void QgsLayoutDesignerDialog::snapToGrid( bool enabled )
437446
{
438447
mLayout->snapper().setSnapToGrid( enabled );

‎src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
121121
*/
122122
void showGrid( bool visible );
123123

124+
/**
125+
* Toggles whether the item bounding boxes should be \a visible.
126+
*/
127+
void showBoxes( bool visible );
128+
124129
/**
125130
* Toggles whether snapping to the page grid is \a enabled.
126131
*/

‎src/core/layout/qgslayoutcontext.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,13 @@ void QgsLayoutContext::setGridVisible( bool visible )
8787
{
8888
mGridVisible = visible;
8989
}
90+
91+
bool QgsLayoutContext::boundingBoxesVisible() const
92+
{
93+
return mBoundingBoxesVisible;
94+
}
95+
96+
void QgsLayoutContext::setBoundingBoxesVisible( bool visible )
97+
{
98+
mBoundingBoxesVisible = visible;
99+
}

‎src/core/layout/qgslayoutcontext.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ class CORE_EXPORT QgsLayoutContext
151151
*/
152152
void setGridVisible( bool visible );
153153

154+
/**
155+
* Returns true if the item bounding boxes should be drawn.
156+
* \see setBoundingBoxesVisible()
157+
*/
158+
bool boundingBoxesVisible() const;
159+
160+
/**
161+
* Sets whether the item bounding boxes should be \a visible.
162+
* \see boundingBoxesVisible()
163+
*/
164+
void setBoundingBoxesVisible( bool visible );
165+
154166
private:
155167

156168
Flags mFlags = 0;
@@ -161,6 +173,7 @@ class CORE_EXPORT QgsLayoutContext
161173
QgsLayoutMeasurementConverter mMeasurementConverter;
162174

163175
bool mGridVisible = false;
176+
bool mBoundingBoxesVisible = true;
164177

165178

166179
};

‎src/gui/layout/qgslayoutmousehandles.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ void QgsLayoutMouseHandles::paint( QPainter *painter, const QStyleOptionGraphics
5656
}
5757
#endif
5858

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

66-
if ( mIsResizing || mIsDragging /*|| mComposition->boundingBoxesVisible()*/ )
66+
if ( mIsResizing || mIsDragging || mLayout->context().boundingBoxesVisible() )
6767
{
6868
//draw dotted boxes around selected items
6969
drawSelectedItemBounds( painter );

‎src/ui/layout/qgslayoutdesignerbase.ui

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<addaction name="mActionClearGuides"/>
132132
<addaction name="separator"/>
133133
<addaction name="mActionShowRulers"/>
134+
<addaction name="mActionShowBoxes"/>
134135
<addaction name="separator"/>
135136
<addaction name="mToolbarMenu"/>
136137
<addaction name="mPanelsMenu"/>
@@ -436,6 +437,20 @@
436437
<string>Ctrl+Shift+Z</string>
437438
</property>
438439
</action>
440+
<action name="mActionShowBoxes">
441+
<property name="checkable">
442+
<bool>true</bool>
443+
</property>
444+
<property name="text">
445+
<string>Show Bounding Boxes</string>
446+
</property>
447+
<property name="toolTip">
448+
<string>Show bounding boxes</string>
449+
</property>
450+
<property name="shortcut">
451+
<string>Ctrl+Shift+B</string>
452+
</property>
453+
</action>
439454
</widget>
440455
<resources>
441456
<include location="../../../images/images.qrc"/>
@@ -465,32 +480,6 @@
465480
<include location="../../../images/images.qrc"/>
466481
<include location="../../../images/images.qrc"/>
467482
<include location="../../../images/images.qrc"/>
468-
<include location="../../../images/images.qrc"/>
469-
<include location="../../../images/images.qrc"/>
470-
<include location="../../../images/images.qrc"/>
471-
<include location="../../../images/images.qrc"/>
472-
<include location="../../../images/images.qrc"/>
473-
<include location="../../../images/images.qrc"/>
474-
<include location="../../../images/images.qrc"/>
475-
<include location="../../../images/images.qrc"/>
476-
<include location="../../../images/images.qrc"/>
477-
<include location="../../../images/images.qrc"/>
478-
<include location="../../../images/images.qrc"/>
479-
<include location="../../../images/images.qrc"/>
480-
<include location="../../../images/images.qrc"/>
481-
<include location="../../../images/images.qrc"/>
482-
<include location="../../../images/images.qrc"/>
483-
<include location="../../../images/images.qrc"/>
484-
<include location="../../../images/images.qrc"/>
485-
<include location="../../../images/images.qrc"/>
486-
<include location="../../../images/images.qrc"/>
487-
<include location="../../../images/images.qrc"/>
488-
<include location="../../../images/images.qrc"/>
489-
<include location="../../../images/images.qrc"/>
490-
<include location="../../../images/images.qrc"/>
491-
<include location="../../../images/images.qrc"/>
492-
<include location="../../../images/images.qrc"/>
493-
<include location="../../../images/images.qrc"/>
494483
</resources>
495484
<connections/>
496485
</ui>

‎tests/src/core/testqgslayoutcontext.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class TestQgsLayoutContext: public QObject
3737
void layer();
3838
void dpi();
3939
void renderContextFlags();
40+
void boundingBoxes();
4041

4142
private:
4243
QString mReport;
@@ -158,5 +159,14 @@ void TestQgsLayoutContext::renderContextFlags()
158159
QVERIFY( ( flags & QgsRenderContext::ForceVectorOutput ) );
159160
}
160161

162+
void TestQgsLayoutContext::boundingBoxes()
163+
{
164+
QgsLayoutContext context;
165+
context.setBoundingBoxesVisible( false );
166+
QVERIFY( !context.boundingBoxesVisible() );
167+
context.setBoundingBoxesVisible( true );
168+
QVERIFY( context.boundingBoxesVisible() );
169+
}
170+
161171
QGSTEST_MAIN( TestQgsLayoutContext )
162172
#include "testqgslayoutcontext.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.