Skip to content

Commit 7d712ac

Browse files
committedDec 29, 2013
[composer] Add action for showing/hiding rulers
1 parent 37b48bd commit 7d712ac

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed
 

‎src/app/composer/qgscomposer.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
175175
mActionShowGuides->setCheckable( true );
176176
mActionSnapGuides->setCheckable( true );
177177
mActionSmartGuides->setCheckable( true );
178+
mActionShowRulers->setCheckable( true );
178179

179180
#ifdef Q_WS_MAC
180181
mActionQuit->setText( tr( "Close" ) );
@@ -267,6 +268,8 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
267268
viewMenu->addAction( mActionSnapGuides );
268269
viewMenu->addAction( mActionSmartGuides );
269270
viewMenu->addAction( mActionClearGuides );
271+
viewMenu->addSeparator();
272+
viewMenu->addAction( mActionShowRulers );
270273

271274
// Panel and toolbar submenus
272275
mPanelMenu = new QMenu( tr( "Panels" ), this );
@@ -374,16 +377,27 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
374377
mViewLayout->setMargin( 0 );
375378
mHorizontalRuler = new QgsComposerRuler( QgsComposerRuler::Horizontal );
376379
mVerticalRuler = new QgsComposerRuler( QgsComposerRuler::Vertical );
377-
QWidget* fake = new QWidget();
378-
fake->setAttribute( Qt::WA_NoMousePropagation );
379-
fake->setBackgroundRole( QPalette::Window );
380-
fake->setFixedSize( 20, 20 );
381-
mViewLayout->addWidget( fake, 0, 0 );
380+
mRulerLayoutFix = new QWidget();
381+
mRulerLayoutFix->setAttribute( Qt::WA_NoMousePropagation );
382+
mRulerLayoutFix->setBackgroundRole( QPalette::Window );
383+
mRulerLayoutFix->setFixedSize( mVerticalRuler->rulerSize(), mHorizontalRuler->rulerSize() );
384+
mViewLayout->addWidget( mRulerLayoutFix, 0, 0 );
382385
mViewLayout->addWidget( mHorizontalRuler, 0, 1 );
383386
mViewLayout->addWidget( mVerticalRuler, 1, 0 );
384387
createComposerView();
385388
mViewFrame->setLayout( mViewLayout );
386389

390+
//initial state of rulers
391+
QSettings myQSettings;
392+
bool showRulers = myQSettings.value( "/Composer/showRulers", true ).toBool();
393+
mActionShowRulers->blockSignals( true );
394+
mActionShowRulers->setChecked( showRulers );
395+
mHorizontalRuler->setVisible( showRulers );
396+
mVerticalRuler->setVisible( showRulers );
397+
mRulerLayoutFix->setVisible( showRulers );
398+
mActionShowRulers->blockSignals( false );
399+
connect( mActionShowRulers, SIGNAL( triggered( bool ) ), this, SLOT( toggleRulers( bool ) ) );
400+
387401
//init undo/redo buttons
388402
mComposition = new QgsComposition( mQgis->mapCanvas()->mapRenderer() );
389403

@@ -878,6 +892,17 @@ void QgsComposer::on_mActionClearGuides_triggered()
878892
}
879893
}
880894

895+
void QgsComposer::toggleRulers( bool checked )
896+
{
897+
//show or hide rulers
898+
mHorizontalRuler->setVisible( checked );
899+
mVerticalRuler->setVisible( checked );
900+
mRulerLayoutFix->setVisible( checked );
901+
902+
QSettings myQSettings;
903+
myQSettings.setValue( "/Composer/showRulers", checked );
904+
}
905+
881906
void QgsComposer::on_mActionExportAsPDF_triggered()
882907
{
883908
if ( !mComposition || !mView )

‎src/app/composer/qgscomposer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
306306
//!Enable or disable smart guides
307307
void on_mActionSmartGuides_triggered( bool checked );
308308

309+
//!Show/hide rulers
310+
void toggleRulers( bool checked );
311+
309312
//!Clear guides
310313
void on_mActionClearGuides_triggered();
311314

@@ -435,6 +438,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
435438
QGridLayout* mViewLayout;
436439
QgsComposerRuler* mHorizontalRuler;
437440
QgsComposerRuler* mVerticalRuler;
441+
QWidget* mRulerLayoutFix;
438442

439443
//! Current composition
440444
QgsComposition *mComposition;

‎src/gui/qgscomposerruler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class GUI_EXPORT QgsComposerRuler: public QWidget
2929
void setComposition( QgsComposition* c ) { mComposition = c; }
3030
QgsComposition* composition() { return mComposition; }
3131

32+
int rulerSize() { return mRulerMinSize; }
33+
3234
protected:
3335
void paintEvent( QPaintEvent* event );
3436
void mouseMoveEvent( QMouseEvent* event );

‎src/ui/qgscomposerbase.ui

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
<bool>true</bool>
2222
</property>
2323
<layout class="QGridLayout" name="gridLayout">
24-
<property name="margin">
24+
<property name="leftMargin">
25+
<number>0</number>
26+
</property>
27+
<property name="topMargin">
28+
<number>0</number>
29+
</property>
30+
<property name="rightMargin">
31+
<number>0</number>
32+
</property>
33+
<property name="bottomMargin">
2534
<number>0</number>
2635
</property>
2736
<item row="0" column="0">
@@ -796,7 +805,7 @@
796805
<property name="text">
797806
<string>Pan Composer</string>
798807
</property>
799-
</action>
808+
</action>
800809
<action name="mActionOptions">
801810
<property name="icon">
802811
<iconset resource="../../images/images.qrc">
@@ -808,7 +817,18 @@
808817
<property name="menuRole">
809818
<enum>QAction::PreferencesRole</enum>
810819
</property>
811-
</action>
820+
</action>
821+
<action name="mActionShowRulers">
822+
<property name="text">
823+
<string>Show Rulers</string>
824+
</property>
825+
<property name="toolTip">
826+
<string>Show rulers</string>
827+
</property>
828+
<property name="shortcut">
829+
<string>Ctrl+R</string>
830+
</property>
831+
</action>
812832
</widget>
813833
<resources>
814834
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)
Please sign in to comment.