Skip to content

Commit

Permalink
[FEATURE][composer] Add view menu option to hide bounding boxes
Browse files Browse the repository at this point in the history
This allows users to hide the bounding boxes for selected items
within a composition. It's a handy feature for allowing interaction
with items while previewing exactly how they will look when the
composition is exported, without large boxes blocking the view.
  • Loading branch information
nyalldawson committed Oct 31, 2014
1 parent a57080c commit 7b537f6
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 5 deletions.
14 changes: 14 additions & 0 deletions python/core/composer/qgscomposition.sip
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,20 @@ class QgsComposition : QGraphicsScene
* @note Added in QGIS 2.5
*/
int snapTolerance() const;

/**Sets whether selection bounding boxes should be shown in the composition
* @param boundsVisible set to true to show selection bounding box
* @see boundingBoxesVisible
* @note added in QGIS 2.7
*/
void setBoundingBoxesVisible( const bool boundsVisible );

/**Returns whether selection bounding boxes should be shown in the composition
* @returns true if selection bounding boxes should be shown
* @see setBoundingBoxesVisible
* @note added in QGIS 2.7
*/
bool boundingBoxesVisible() const;

/**Returns pointer to undo/redo command storage*/
QUndoStack* undoStack();
Expand Down
13 changes: 13 additions & 0 deletions src/app/composer/qgscomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mActionSnapGuides->setCheckable( true );
mActionSmartGuides->setCheckable( true );
mActionShowRulers->setCheckable( true );
mActionShowBoxes->setCheckable( true );

mActionAtlasPreview->setCheckable( true );

Expand Down Expand Up @@ -332,6 +333,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
viewMenu->addAction( mActionSmartGuides );
viewMenu->addAction( mActionClearGuides );
viewMenu->addSeparator();
viewMenu->addAction( mActionShowBoxes );
viewMenu->addAction( mActionShowRulers );

// Panel and toolbar submenus
Expand Down Expand Up @@ -1192,6 +1194,15 @@ void QgsComposer::on_mActionSmartGuides_triggered( bool checked )
}
}

void QgsComposer::on_mActionShowBoxes_triggered( bool checked )
{
//show or hide bounding boxes
if ( mComposition )
{
mComposition->setBoundingBoxesVisible( checked );
}
}

void QgsComposer::on_mActionClearGuides_triggered()
{
//clear guide lines
Expand Down Expand Up @@ -3155,6 +3166,8 @@ void QgsComposer::restoreGridSettings()
mActionShowGuides->setChecked( mComposition->snapLinesVisible() );
mActionSnapGuides->setChecked( mComposition->alignmentSnap() );
mActionSmartGuides->setChecked( mComposition->smartGuidesEnabled() );
//general view settings
mActionShowBoxes->setChecked( mComposition->boundingBoxesVisible() );
}

void QgsComposer::deleteItemWidgets()
Expand Down
3 changes: 3 additions & 0 deletions src/app/composer/qgscomposer.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//!Enable or disable smart guides
void on_mActionSmartGuides_triggered( bool checked );

//!Show/hide bounding boxes
void on_mActionShowBoxes_triggered( bool checked );

//!Show/hide rulers
void toggleRulers( bool checked );

Expand Down
17 changes: 12 additions & 5 deletions src/core/composer/qgscomposermousehandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ void QgsComposerMouseHandles::paint( QPainter* painter, const QStyleOptionGraphi
return;
}

//draw resize handles around bounds of entire selection
double rectHandlerSize = rectHandlerBorderTolerance();
drawHandles( painter, rectHandlerSize );
if ( mComposition->boundingBoxesVisible() )
{
//draw resize handles around bounds of entire selection
double rectHandlerSize = rectHandlerBorderTolerance();
drawHandles( painter, rectHandlerSize );
}

//draw dotted boxes around selected items
drawSelectedItemBounds( painter );
if ( mIsResizing || mIsDragging || mComposition->boundingBoxesVisible() )
{
//draw dotted boxes around selected items
drawSelectedItemBounds( painter );
}
}

void QgsComposerMouseHandles::drawHandles( QPainter* painter, double rectHandlerSize )
Expand Down Expand Up @@ -589,6 +595,7 @@ void QgsComposerMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent* event
{
mIsDragging = false;
mIsResizing = false;
update();
return;
}

Expand Down
16 changes: 16 additions & 0 deletions src/core/composer/qgscomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void QgsComposition::init()
mGuidesVisible = true;
mSmartGuides = true;
mSnapTolerance = 0;
mBoundingBoxesVisible = true;
mSelectionHandles = 0;
mActiveItemCommand = 0;
mActiveMultiFrameCommand = 0;
Expand Down Expand Up @@ -215,6 +216,7 @@ void QgsComposition::loadDefaults()
mSnapGridOffsetX = settings.value( "/Composer/defaultSnapGridOffsetX", 0 ).toDouble();
mSnapGridOffsetY = settings.value( "/Composer/defaultSnapGridOffsetY", 0 ).toDouble();
mSnapTolerance = settings.value( "/Composer/defaultSnapTolerancePixels", 5 ).toInt();
mBoundingBoxesVisible = settings.value( "/Composer/showBoundingBoxes", true ).toBool();
}

void QgsComposition::updateBounds()
Expand Down Expand Up @@ -2142,6 +2144,20 @@ void QgsComposition::setGridStyle( const GridStyle s )
updatePaperItems();
}

void QgsComposition::setBoundingBoxesVisible( const bool boundsVisible )
{
mBoundingBoxesVisible = boundsVisible;

//save to settings
QSettings settings;
settings.setValue( "/Composer/showBoundingBoxes", mBoundingBoxesVisible );

if ( mSelectionHandles )
{
mSelectionHandles->update();
}
}

void QgsComposition::updateSettings()
{
//load new composer setting values
Expand Down
15 changes: 15 additions & 0 deletions src/core/composer/qgscomposition.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,20 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
*/
int snapTolerance() const { return mSnapTolerance; }

/**Sets whether selection bounding boxes should be shown in the composition
* @param boundsVisible set to true to show selection bounding box
* @see boundingBoxesVisible
* @note added in QGIS 2.7
*/
void setBoundingBoxesVisible( const bool boundsVisible );

/**Returns whether selection bounding boxes should be shown in the composition
* @returns true if selection bounding boxes should be shown
* @see setBoundingBoxesVisible
* @note added in QGIS 2.7
*/
bool boundingBoxesVisible() const { return mBoundingBoxesVisible; }

/**Returns pointer to undo/redo command storage*/
QUndoStack* undoStack() { return mUndoStack; }

Expand Down Expand Up @@ -742,6 +756,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
/**Arbitraty snap lines (horizontal and vertical)*/
QList< QGraphicsLineItem* > mSnapLines;

bool mBoundingBoxesVisible;
QgsComposerMouseHandles* mSelectionHandles;

QUndoStack* mUndoStack;
Expand Down
11 changes: 11 additions & 0 deletions src/ui/qgscomposerbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,17 @@
<string>Atlas &amp;Settings</string>
</property>
</action>
<action name="mActionShowBoxes">
<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="../../python/plugins/fTools/resources.qrc"/>
Expand Down

0 comments on commit 7b537f6

Please sign in to comment.