1717
1818#include " qgscomposermapwidget.h"
1919#include " qgscomposeritemwidget.h"
20- #include " qgscomposermap.h"
2120#include " qgsmaprenderer.h"
2221#include < QColorDialog>
2322#include < QFontDialog>
@@ -47,13 +46,16 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
4746 mGridTypeComboBox ->insertItem ( 0 , tr ( " Solid" ) );
4847 mGridTypeComboBox ->insertItem ( 1 , tr ( " Cross" ) );
4948
50- mAnnotationPositionComboBox ->insertItem ( 0 , tr ( " Inside frame" ) );
51- mAnnotationPositionComboBox ->insertItem ( 1 , tr ( " Outside frame" ) );
49+ insertAnnotationPositionEntries ( mAnnotationPositionLeftComboBox );
50+ insertAnnotationPositionEntries ( mAnnotationPositionRightComboBox );
51+ insertAnnotationPositionEntries ( mAnnotationPositionTopComboBox );
52+ insertAnnotationPositionEntries ( mAnnotationPositionBottomComboBox );
53+
54+ insertAnnotationDirectionEntries ( mAnnotationDirectionComboBoxLeft );
55+ insertAnnotationDirectionEntries ( mAnnotationDirectionComboBoxRight );
56+ insertAnnotationDirectionEntries ( mAnnotationDirectionComboBoxTop );
57+ insertAnnotationDirectionEntries ( mAnnotationDirectionComboBoxBottom );
5258
53- mAnnotationDirectionComboBox ->insertItem ( 0 , tr ( " Horizontal" ) );
54- mAnnotationDirectionComboBox ->insertItem ( 1 , tr ( " Vertical" ) );
55- mAnnotationDirectionComboBox ->insertItem ( 2 , tr ( " Horizontal and Vertical" ) );
56- mAnnotationDirectionComboBox ->insertItem ( 2 , tr ( " Boundary direction" ) );
5759 if ( composerMap )
5860 {
5961 connect ( composerMap, SIGNAL ( itemChanged () ), this , SLOT ( setGuiElementValues () ) );
@@ -344,15 +346,17 @@ void QgsComposerMapWidget::updateGuiElements()
344346
345347 mCrossWidthSpinBox ->setValue ( mComposerMap ->crossLength () );
346348
347- QgsComposerMap::GridAnnotationPosition annotationPos = mComposerMap ->gridAnnotationPosition ();
348- if ( annotationPos == QgsComposerMap::InsideMapFrame )
349- {
350- mAnnotationPositionComboBox ->setCurrentIndex ( mAnnotationPositionComboBox ->findText ( tr ( " Inside frame" ) ) );
351- }
352- else
353- {
354- mAnnotationPositionComboBox ->setCurrentIndex ( mAnnotationPositionComboBox ->findText ( tr ( " Outside frame" ) ) );
355- }
349+ // grid annotation position
350+ initAnnotationPositionBox ( mAnnotationPositionLeftComboBox , mComposerMap ->gridAnnotationPosition ( QgsComposerMap::Left ) );
351+ initAnnotationPositionBox ( mAnnotationPositionRightComboBox , mComposerMap ->gridAnnotationPosition ( QgsComposerMap::Right ) );
352+ initAnnotationPositionBox ( mAnnotationPositionTopComboBox , mComposerMap ->gridAnnotationPosition ( QgsComposerMap::Top ) );
353+ initAnnotationPositionBox ( mAnnotationPositionBottomComboBox , mComposerMap ->gridAnnotationPosition ( QgsComposerMap::Bottom ) );
354+
355+ // grid annotation direction
356+ initAnnotationDirectionBox ( mAnnotationDirectionComboBoxLeft , mComposerMap ->gridAnnotationDirection ( QgsComposerMap::Left ) );
357+ initAnnotationDirectionBox ( mAnnotationDirectionComboBoxRight , mComposerMap ->gridAnnotationDirection ( QgsComposerMap::Right ) );
358+ initAnnotationDirectionBox ( mAnnotationDirectionComboBoxTop , mComposerMap ->gridAnnotationDirection ( QgsComposerMap::Top ) );
359+ initAnnotationDirectionBox ( mAnnotationDirectionComboBoxBottom , mComposerMap ->gridAnnotationDirection ( QgsComposerMap::Bottom ) );
356360
357361 mDistanceToMapFrameSpinBox ->setValue ( mComposerMap ->annotationFrameDistance () );
358362
@@ -365,24 +369,6 @@ void QgsComposerMapWidget::updateGuiElements()
365369 mDrawAnnotationCheckBox ->setCheckState ( Qt::Unchecked );
366370 }
367371
368- QgsComposerMap::GridAnnotationDirection dir = mComposerMap ->gridAnnotationDirection ();
369- if ( dir == QgsComposerMap::Horizontal )
370- {
371- mAnnotationDirectionComboBox ->setCurrentIndex ( mAnnotationDirectionComboBox ->findText ( tr ( " Horizontal" ) ) );
372- }
373- else if ( dir == QgsComposerMap::Vertical )
374- {
375- mAnnotationDirectionComboBox ->setCurrentIndex ( mAnnotationDirectionComboBox ->findText ( tr ( " Vertical" ) ) );
376- }
377- else if ( dir == QgsComposerMap::HorizontalAndVertical )
378- {
379- mAnnotationDirectionComboBox ->setCurrentIndex ( mAnnotationDirectionComboBox ->findText ( tr ( " Horizontal and Vertical" ) ) );
380- }
381- else // BoundaryDirection
382- {
383- mAnnotationDirectionComboBox ->setCurrentIndex ( mAnnotationDirectionComboBox ->findText ( tr ( " Boundary direction" ) ) );
384- }
385-
386372 mCoordinatePrecisionSpinBox ->setValue ( mComposerMap ->gridAnnotationPrecision () );
387373
388374 QPen gridPen = mComposerMap ->gridPen ();
@@ -445,9 +431,15 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
445431 mLineColorButton ->blockSignals ( b );
446432 mDrawAnnotationCheckBox ->blockSignals ( b );
447433 mAnnotationFontButton ->blockSignals ( b );
448- mAnnotationPositionComboBox ->blockSignals ( b );
434+ mAnnotationPositionLeftComboBox ->blockSignals ( b );
435+ mAnnotationPositionRightComboBox ->blockSignals ( b );
436+ mAnnotationPositionTopComboBox ->blockSignals ( b );
437+ mAnnotationPositionBottomComboBox ->blockSignals ( b );
449438 mDistanceToMapFrameSpinBox ->blockSignals ( b );
450- mAnnotationDirectionComboBox ->blockSignals ( b );
439+ mAnnotationDirectionComboBoxLeft ->blockSignals ( b );
440+ mAnnotationDirectionComboBoxRight ->blockSignals ( b );
441+ mAnnotationDirectionComboBoxTop ->blockSignals ( b );
442+ mAnnotationDirectionComboBoxBottom ->blockSignals ( b );
451443 mCoordinatePrecisionSpinBox ->blockSignals ( b );
452444 mDrawCanvasItemsCheckBox ->blockSignals ( b );
453445}
@@ -683,49 +675,120 @@ void QgsComposerMapWidget::on_mDistanceToMapFrameSpinBox_valueChanged( double d
683675 mComposerMap ->endCommand ();
684676}
685677
686- void QgsComposerMapWidget::on_mAnnotationPositionComboBox_currentIndexChanged ( const QString& text )
678+ void QgsComposerMapWidget::on_mAnnotationPositionLeftComboBox_currentIndexChanged ( const QString& text )
679+ {
680+ handleChangedAnnotationPosition ( QgsComposerMap::Left, text );
681+ }
682+
683+ void QgsComposerMapWidget::on_mAnnotationPositionRightComboBox_currentIndexChanged ( const QString& text )
684+ {
685+ handleChangedAnnotationPosition ( QgsComposerMap::Right, text );
686+ }
687+
688+ void QgsComposerMapWidget::on_mAnnotationPositionTopComboBox_currentIndexChanged ( const QString& text )
689+ {
690+ handleChangedAnnotationPosition ( QgsComposerMap::Top, text );
691+ }
692+
693+ void QgsComposerMapWidget::on_mAnnotationPositionBottomComboBox_currentIndexChanged ( const QString& text )
694+ {
695+ handleChangedAnnotationPosition ( QgsComposerMap::Bottom, text );
696+ }
697+
698+ void QgsComposerMapWidget::on_mDrawAnnotationCheckBox_stateChanged ( int state )
687699{
688700 if ( !mComposerMap )
689701 {
690702 return ;
691703 }
692704
693- mComposerMap ->beginCommand ( tr ( " Annotation position changed " ) );
694- if ( text == tr ( " Inside frame " ) )
705+ mComposerMap ->beginCommand ( tr ( " Annotation toggled " ) );
706+ if ( state == Qt::Checked )
695707 {
696- mComposerMap ->setGridAnnotationPosition ( QgsComposerMap::InsideMapFrame );
708+ mComposerMap ->setShowGridAnnotation ( true );
697709 }
698710 else
699711 {
700- mComposerMap ->setGridAnnotationPosition ( QgsComposerMap::OutsideMapFrame );
712+ mComposerMap ->setShowGridAnnotation ( false );
701713 }
702714 mComposerMap ->updateBoundingRect ();
703715 mComposerMap ->update ();
704716 mComposerMap ->endCommand ();
705717}
706718
707- void QgsComposerMapWidget::on_mDrawAnnotationCheckBox_stateChanged ( int state )
719+ void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxLeft_currentIndexChanged ( const QString& text )
720+ {
721+ handleChangedAnnotationDirection ( QgsComposerMap::Left, text );
722+ }
723+
724+ void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxRight_currentIndexChanged ( const QString& text )
725+ {
726+ handleChangedAnnotationDirection ( QgsComposerMap::Right, text );
727+ }
728+
729+ void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxTop_currentIndexChanged ( const QString& text )
730+ {
731+ handleChangedAnnotationDirection ( QgsComposerMap::Top, text );
732+ }
733+
734+ void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxBottom_currentIndexChanged ( const QString& text )
735+ {
736+ handleChangedAnnotationDirection ( QgsComposerMap::Bottom, text );
737+ }
738+
739+ void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged ( int value )
740+ {
741+ if ( !mComposerMap )
742+ {
743+ return ;
744+ }
745+ mComposerMap ->beginCommand ( tr ( " Changed annotation precision" ) );
746+ mComposerMap ->setGridAnnotationPrecision ( value );
747+ mComposerMap ->updateBoundingRect ();
748+ mComposerMap ->update ();
749+ mComposerMap ->endCommand ();
750+ }
751+
752+ void QgsComposerMapWidget::insertAnnotationPositionEntries ( QComboBox* c )
753+ {
754+ c->insertItem ( 0 , tr ( " Inside frame" ) );
755+ c->insertItem ( 1 , tr ( " Outside frame" ) );
756+ c->insertItem ( 2 , tr ( " Disabled" ) );
757+ }
758+
759+ void QgsComposerMapWidget::insertAnnotationDirectionEntries ( QComboBox* c )
760+ {
761+ c->insertItem ( 0 , tr ( " Horizontal" ) );
762+ c->insertItem ( 1 , tr ( " Vertical" ) );
763+ }
764+
765+ void QgsComposerMapWidget::handleChangedAnnotationPosition ( QgsComposerMap::Border border, const QString& text )
708766{
709767 if ( !mComposerMap )
710768 {
711769 return ;
712770 }
713771
714- mComposerMap ->beginCommand ( tr ( " Annotation toggled " ) );
715- if ( state == Qt::Checked )
772+ mComposerMap ->beginCommand ( tr ( " Annotation position changed " ) );
773+ if ( text == tr ( " Inside frame " ) )
716774 {
717- mComposerMap ->setShowGridAnnotation ( true );
775+ mComposerMap ->setGridAnnotationPosition ( QgsComposerMap::InsideMapFrame, border );
718776 }
719- else
777+ else if ( text == tr ( " Disabled " ) )
720778 {
721- mComposerMap ->setShowGridAnnotation ( false );
779+ mComposerMap ->setGridAnnotationPosition ( QgsComposerMap::Disabled, border );
780+ }
781+ else // Outside frame
782+ {
783+ mComposerMap ->setGridAnnotationPosition ( QgsComposerMap::OutsideMapFrame, border );
722784 }
785+
723786 mComposerMap ->updateBoundingRect ();
724787 mComposerMap ->update ();
725788 mComposerMap ->endCommand ();
726789}
727790
728- void QgsComposerMapWidget::on_mAnnotationDirectionComboBox_currentIndexChanged ( const QString& text )
791+ void QgsComposerMapWidget::handleChangedAnnotationDirection ( QgsComposerMap::Border border, const QString& text )
729792{
730793 if ( !mComposerMap )
731794 {
@@ -735,34 +798,51 @@ void QgsComposerMapWidget::on_mAnnotationDirectionComboBox_currentIndexChanged(
735798 mComposerMap ->beginCommand ( tr ( " Changed annotation direction" ) );
736799 if ( text == tr ( " Horizontal" ) )
737800 {
738- mComposerMap ->setGridAnnotationDirection ( QgsComposerMap::Horizontal );
801+ mComposerMap ->setGridAnnotationDirection ( QgsComposerMap::Horizontal, border );
802+ }
803+ else // Vertical
804+ {
805+ mComposerMap ->setGridAnnotationDirection ( QgsComposerMap::Vertical, border );
739806 }
740- else if ( text == tr ( " Vertical" ) )
807+ mComposerMap ->updateBoundingRect ();
808+ mComposerMap ->update ();
809+ mComposerMap ->endCommand ();
810+ }
811+
812+ void QgsComposerMapWidget::initAnnotationPositionBox ( QComboBox* c, QgsComposerMap::GridAnnotationPosition pos )
813+ {
814+ if ( !c )
741815 {
742- mComposerMap -> setGridAnnotationDirection ( QgsComposerMap::Vertical ) ;
816+ return ;
743817 }
744- else if ( text == tr ( " Horizontal and Vertical" ) )
818+
819+ if ( pos == QgsComposerMap::InsideMapFrame )
745820 {
746- mComposerMap -> setGridAnnotationDirection ( QgsComposerMap::HorizontalAndVertical );
821+ c-> setCurrentIndex ( c-> findText ( tr ( " Inside frame " ) ) );
747822 }
748- else // BoundaryDirection
823+ else if ( pos == QgsComposerMap::OutsideMapFrame )
749824 {
750- mComposerMap ->setGridAnnotationDirection ( QgsComposerMap::BoundaryDirection );
825+ c->setCurrentIndex ( c->findText ( tr ( " Outside frame" ) ) );
826+ }
827+ else // disabled
828+ {
829+ c->setCurrentIndex ( c->findText ( tr ( " Disabled" ) ) );
751830 }
752- mComposerMap ->updateBoundingRect ();
753- mComposerMap ->update ();
754- mComposerMap ->endCommand ();
755831}
756832
757- void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged ( int value )
833+ void QgsComposerMapWidget::initAnnotationDirectionBox ( QComboBox* c, QgsComposerMap::GridAnnotationDirection dir )
758834{
759- if ( !mComposerMap )
835+ if ( !c )
760836 {
761837 return ;
762838 }
763- mComposerMap ->beginCommand ( tr ( " Changed annotation precision" ) );
764- mComposerMap ->setGridAnnotationPrecision ( value );
765- mComposerMap ->updateBoundingRect ();
766- mComposerMap ->update ();
767- mComposerMap ->endCommand ();
839+
840+ if ( dir == QgsComposerMap::Vertical )
841+ {
842+ c->setCurrentIndex ( c->findText ( tr ( " Vertical" ) ) );
843+ }
844+ else // horizontal
845+ {
846+ c->setCurrentIndex ( c->findText ( tr ( " Horizontal" ) ) );
847+ }
768848}
0 commit comments