Skip to content

Commit 47d9307

Browse files
committedJan 5, 2016
Added placement margin to decoration items and updated dialogs.
- North arrow, scalebar, and copyright label updated to include a margin option on placement. - All qgsdecorationitem type dialogs amended so that all widgets sit within a checkable group box for activating/deactivating the item.
1 parent 1340afd commit 47d9307

14 files changed

+1242
-786
lines changed
 

‎src/app/qgsdecorationcopyright.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ QgsDecorationCopyright::QgsDecorationCopyright( QObject* parent )
4646
{
4747
mPlacementLabels << tr( "Bottom Left" ) << tr( "Top Left" )
4848
<< tr( "Top Right" ) << tr( "Bottom Right" );
49+
mMarginHorizontal = 0;
50+
mMarginVertical = 0;
4951

5052
setName( "Copyright Label" );
5153
// initialise default values in the gui
@@ -68,6 +70,8 @@ void QgsDecorationCopyright::projectRead()
6870
QgsProject* prj = QgsProject::instance();
6971
mLabelQString = prj->readEntry( mNameConfig, "/Label", defString );
7072
mPlacementIndex = prj->readNumEntry( mNameConfig, "/Placement", 3 );
73+
mMarginHorizontal = QgsProject::instance()->readNumEntry( mNameConfig, "/MarginH", 0 );
74+
mMarginVertical = QgsProject::instance()->readNumEntry( mNameConfig, "/MarginV", 0 );
7175
mLabelQColor.setNamedColor( prj->readEntry( mNameConfig, "/Color", "#000000" ) ); // default color is black
7276
}
7377

@@ -80,6 +84,8 @@ void QgsDecorationCopyright::saveToProject()
8084
prj->writeEntry( mNameConfig, "/Label", mLabelQString );
8185
prj->writeEntry( mNameConfig, "/Color", mLabelQColor.name() );
8286
prj->writeEntry( mNameConfig, "/Placement", mPlacementIndex );
87+
prj->writeEntry( mNameConfig, "/MarginH", mMarginHorizontal );
88+
prj->writeEntry( mNameConfig, "/MarginV", mMarginVertical );
8389
}
8490

8591
// Slot called when the buffer menu item is activated
@@ -112,28 +118,26 @@ void QgsDecorationCopyright::render( QPainter * theQPainter )
112118
QSizeF size = text.size();
113119

114120
float myXOffset( 0 ), myYOffset( 0 );
121+
122+
myXOffset = int(( float( myWidth - size.width() )
123+
/ 100. ) * float( mMarginHorizontal ) );
124+
myYOffset = int(( float( myHeight - size.height() )
125+
/ 100. ) * float( mMarginVertical ) );
115126
//Determine placement of label from form combo box
116127
switch ( mPlacementIndex )
117128
{
118-
case 0: // Bottom Left
119-
//Define bottom left hand corner start point
120-
myYOffset = myHeight - ( size.height() + 5 );
121-
myXOffset = 5;
129+
case 0: // Bottom Left. myXOffset is set above
130+
myYOffset = myHeight - myYOffset - size.height();
122131
break;
123-
case 1: // Top left
124-
//Define top left hand corner start point
125-
myYOffset = 0;
126-
myXOffset = 5;
132+
case 1: // Top left. Already setup above
127133
break;
128-
case 2: // Top Right
129-
//Define top right hand corner start point
130-
myYOffset = 0;
131-
myXOffset = myWidth - ( size.width() + 5 );
134+
case 2: // Top Right. myYOffset is set above
135+
myXOffset = myWidth - myXOffset - size.width();
132136
break;
133137
case 3: // Bottom Right
134138
//Define bottom right hand corner start point
135-
myYOffset = myHeight - ( size.height() + 5 );
136-
myXOffset = myWidth - ( size.width() + 5 );
139+
myYOffset = myHeight - myYOffset - size.height();
140+
myXOffset = myWidth - myXOffset - size.width();
137141
break;
138142
default:
139143
QgsDebugMsg( QString( "Unknown placement index of %1" ).arg( mPlacementIndex ) );

‎src/app/qgsdecorationcopyright.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class APP_EXPORT QgsDecorationCopyright : public QgsDecorationItem
6060
//! Placement of the copyright label - index and translated label names
6161
int mPlacementIndex;
6262
QStringList mPlacementLabels;
63+
//! enable or disable use of position percentage for placement
64+
int mMarginHorizontal;
65+
int mMarginVertical;
6366

6467
friend class QgsDecorationCopyrightDialog;
6568
};

‎src/app/qgsdecorationcopyrightdialog.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ QgsDecorationCopyrightDialog::QgsDecorationCopyrightDialog( QgsDecorationCopyrig
3333
cboOrientation->hide();
3434
textLabel15->hide();
3535

36-
cboxEnabled->setChecked( mDeco.enabled() );
36+
grpEnable->setChecked( mDeco.enabled() );
3737
// text
3838
txtCopyrightText->setPlainText( mDeco.mLabelQString );
3939
// placement
4040
cboPlacement->clear();
4141
cboPlacement->addItems( mDeco.mPlacementLabels );
4242
cboPlacement->setCurrentIndex( mDeco.mPlacementIndex );
43+
spnHorizontal->setValue( mDeco.mMarginHorizontal );
44+
spnVertical->setValue( mDeco.mMarginVertical );
4345
// color
4446
pbnColorChooser->setColor( mDeco.mLabelQColor );
4547
pbnColorChooser->setContext( "gui" );
@@ -63,7 +65,9 @@ void QgsDecorationCopyrightDialog::on_buttonBox_accepted()
6365
mDeco.mLabelQString = txtCopyrightText->toPlainText();
6466
mDeco.mLabelQColor = pbnColorChooser->color();
6567
mDeco.mPlacementIndex = cboPlacement->currentIndex();
66-
mDeco.setEnabled( cboxEnabled->isChecked() );
68+
mDeco.mMarginHorizontal = spnHorizontal->value();
69+
mDeco.mMarginVertical = spnVertical->value();
70+
mDeco.setEnabled( grpEnable->isChecked() );
6771

6872
accept();
6973
}

‎src/app/qgsdecorationgriddialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ QgsDecorationGridDialog::QgsDecorationGridDialog( QgsDecorationGrid& deco, QWidg
3737
QSettings settings;
3838
// restoreGeometry( settings.value( "/Windows/DecorationGrid/geometry" ).toByteArray() );
3939

40-
chkEnable->setChecked( mDeco.enabled() );
40+
grpEnable->setChecked( mDeco.enabled() );
4141

4242
// mXMinLineEdit->setValidator( new QDoubleValidator( mXMinLineEdit ) );
4343

@@ -67,7 +67,7 @@ void QgsDecorationGridDialog::updateGuiElements()
6767
{
6868
// blockAllSignals( true );
6969

70-
chkEnable->setChecked( mDeco.enabled() );
70+
grpEnable->setChecked( mDeco.enabled() );
7171

7272
mIntervalXEdit->setText( QString::number( mDeco.gridIntervalX() ) );
7373
mIntervalYEdit->setText( QString::number( mDeco.gridIntervalY() ) );
@@ -109,7 +109,7 @@ void QgsDecorationGridDialog::updateGuiElements()
109109
void QgsDecorationGridDialog::updateDecoFromGui()
110110
{
111111
mDeco.setDirty( false );
112-
mDeco.setEnabled( chkEnable->isChecked() );
112+
mDeco.setEnabled( grpEnable->isChecked() );
113113

114114
mDeco.setGridIntervalX( mIntervalXEdit->text().toDouble() );
115115
mDeco.setGridIntervalY( mIntervalYEdit->text().toDouble() );

‎src/app/qgsdecorationnortharrow.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ QgsDecorationNorthArrow::QgsDecorationNorthArrow( QObject* parent )
6161
mAutomatic = true;
6262
mPlacementLabels << tr( "Bottom Left" ) << tr( "Top Left" )
6363
<< tr( "Top Right" ) << tr( "Bottom Right" );
64+
mMarginHorizontal = 0;
65+
mMarginVertical = 0;
6466

6567
setName( "North Arrow" );
6668
projectRead();
@@ -76,6 +78,8 @@ void QgsDecorationNorthArrow::projectRead()
7678
mRotationInt = QgsProject::instance()->readNumEntry( mNameConfig, "/Rotation", 0 );
7779
mPlacementIndex = QgsProject::instance()->readNumEntry( mNameConfig, "/Placement", 0 );
7880
mAutomatic = QgsProject::instance()->readBoolEntry( mNameConfig, "/Automatic", true );
81+
mMarginHorizontal = QgsProject::instance()->readNumEntry( mNameConfig, "/MarginH", 0 );
82+
mMarginVertical = QgsProject::instance()->readNumEntry( mNameConfig, "/MarginV", 0 );
7983
}
8084

8185
void QgsDecorationNorthArrow::saveToProject()
@@ -84,6 +88,8 @@ void QgsDecorationNorthArrow::saveToProject()
8488
QgsProject::instance()->writeEntry( mNameConfig, "/Rotation", mRotationInt );
8589
QgsProject::instance()->writeEntry( mNameConfig, "/Placement", mPlacementIndex );
8690
QgsProject::instance()->writeEntry( mNameConfig, "/Automatic", mAutomatic );
91+
QgsProject::instance()->writeEntry( mNameConfig, "/MarginH", mMarginHorizontal );
92+
QgsProject::instance()->writeEntry( mNameConfig, "/MarginV", mMarginVertical );
8793
}
8894

8995
// Slot called when the buffer menu item is activated
@@ -140,28 +146,34 @@ void QgsDecorationNorthArrow::render( QPainter * theQPainter )
140146

141147
//QgsDebugMsg("Rendering north arrow at " + mPlacementLabels.at(mPlacementIndex));
142148

149+
// Calculate the margin percentage values
150+
int myPercentageWidth = int((( float( myWidth ) - float( myQPixmap.width() ) )
151+
/ 100. ) * float( mMarginHorizontal ) );
152+
int myPercentageHeight = int((( float( myHeight ) - float( myQPixmap.height() ) )
153+
/ 100. ) * float( mMarginVertical ) );
154+
143155
//Determine placement of label from form combo box
144156
switch ( mPlacementIndex )
145157
{
146158
case 0: // Bottom Left
147-
theQPainter->translate( 0, myHeight - myQPixmap.height() );
159+
theQPainter->translate( myPercentageWidth, myHeight - myPercentageHeight - myQPixmap.height() );
148160
break;
149161
case 1: // Top Left
150-
//no need to translate for TL corner because we're already at the origin
151-
theQPainter->translate( 0, 0 );
162+
theQPainter->translate( myPercentageWidth, myPercentageHeight );
152163
break;
153164
case 2: // Top Right
154-
theQPainter->translate( myWidth - myQPixmap.width(), 0 );
165+
theQPainter->translate( myWidth - myPercentageWidth - myQPixmap.width(), myPercentageHeight );
155166
break;
156167
case 3: // Bottom Right
157-
theQPainter->translate( myWidth - myQPixmap.width(),
158-
myHeight - myQPixmap.height() );
168+
theQPainter->translate( myWidth - myPercentageWidth - myQPixmap.width(),
169+
myHeight - myPercentageHeight - myQPixmap.height() );
159170
break;
160171
default:
161172
{
162173
//QgsDebugMsg("Unable to determine where to put north arrow so defaulting to top left");
163174
}
164175
}
176+
165177
//rotate the canvas by the north arrow rotation amount
166178
theQPainter->rotate( mRotationInt );
167179
//Now we can actually do the drawing, and draw a smooth north arrow even when rotated

‎src/app/qgsdecorationnortharrow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class APP_EXPORT QgsDecorationNorthArrow: public QgsDecorationItem
6868
// The placement index and translated text
6969
int mPlacementIndex;
7070
QStringList mPlacementLabels;
71+
//! margin values
72+
int mMarginHorizontal;
73+
int mMarginVertical;
7174

7275
friend class QgsDecorationNorthArrowDialog;
7376
};

‎src/app/qgsdecorationnortharrowdialog.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ QgsDecorationNorthArrowDialog::QgsDecorationNorthArrowDialog( QgsDecorationNorth
3939
cboPlacement->clear();
4040
cboPlacement->addItems( mDeco.mPlacementLabels );
4141
cboPlacement->setCurrentIndex( mDeco.mPlacementIndex );
42+
spinHorizontal->setValue( mDeco.mMarginHorizontal );
43+
spinVertical->setValue( mDeco.mMarginVertical );
4244

4345
// enabled
44-
cboxShow->setChecked( mDeco.enabled() );
46+
grpEnable->setChecked( mDeco.enabled() );
4547

4648
// automatic
4749
cboxAutomatic->setChecked( mDeco.mAutomatic );
@@ -62,8 +64,10 @@ void QgsDecorationNorthArrowDialog::on_buttonBox_accepted()
6264
{
6365
mDeco.mRotationInt = sliderRotation->value();
6466
mDeco.mPlacementIndex = cboPlacement->currentIndex();
65-
mDeco.setEnabled( cboxShow->isChecked() );
67+
mDeco.setEnabled( grpEnable->isChecked() );
6668
mDeco.mAutomatic = cboxAutomatic->isChecked();
69+
mDeco.mMarginHorizontal = spinHorizontal->value();
70+
mDeco.mMarginVertical = spinVertical->value();
6771

6872
accept();
6973
}

‎src/app/qgsdecorationscalebar.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ QgsDecorationScaleBar::QgsDecorationScaleBar( QObject* parent )
5757
mPlacementIndex = 1;
5858
mStyleLabels << tr( "Tick Down" ) << tr( "Tick Up" )
5959
<< tr( "Bar" ) << tr( "Box" );
60+
mMarginHorizontal = 0;
61+
mMarginVertical = 0;
6062

6163
setName( "Scale Bar" );
6264
projectRead();
@@ -79,6 +81,8 @@ void QgsDecorationScaleBar::projectRead()
7981
int myGreenInt = QgsProject::instance()->readNumEntry( mNameConfig, "/ColorGreenPart", 0 );
8082
int myBlueInt = QgsProject::instance()->readNumEntry( mNameConfig, "/ColorBluePart", 0 );
8183
mColor = QColor( myRedInt, myGreenInt, myBlueInt );
84+
mMarginHorizontal = QgsProject::instance()->readNumEntry( mNameConfig, "/MarginH", 0 );
85+
mMarginVertical = QgsProject::instance()->readNumEntry( mNameConfig, "/MarginV", 0 );
8286
}
8387

8488
void QgsDecorationScaleBar::saveToProject()
@@ -92,6 +96,8 @@ void QgsDecorationScaleBar::saveToProject()
9296
QgsProject::instance()->writeEntry( mNameConfig, "/ColorRedPart", mColor.red() );
9397
QgsProject::instance()->writeEntry( mNameConfig, "/ColorGreenPart", mColor.green() );
9498
QgsProject::instance()->writeEntry( mNameConfig, "/ColorBluePart", mColor.blue() );
99+
QgsProject::instance()->writeEntry( mNameConfig, "/MarginH", mMarginHorizontal );
100+
QgsProject::instance()->writeEntry( mNameConfig, "/MarginV", mMarginVertical );
95101
}
96102

97103

@@ -133,7 +139,6 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
133139
// Hard coded sizes
134140
int myMajorTickSize = 8;
135141
int myTextOffsetX = 3;
136-
int myMargin = 20;
137142

138143
QSettings settings;
139144
QGis::UnitType myPreferredUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
@@ -252,26 +257,34 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
252257
//Calculate total width of scale bar and label
253258
double myTotalScaleBarWidth = myScaleBarWidth + myFontWidth;
254259

255-
//determine the origin of scale bar depending on placement selected
256-
int myOriginX = myMargin;
257-
int myOriginY = myMargin;
260+
//Calculate percentage page width for use in placing item
261+
int myMarginW = 10;
262+
int myMarginH = 20;
263+
float myMarginDoubledW = float( myMarginW * 2 );
264+
float myMarginDoubledH = float( myMarginH * 2 );
265+
int myOriginX = int((( float( myCanvasWidth - myMarginDoubledW ) - myTotalScaleBarWidth )
266+
/ 100. ) * float( mMarginHorizontal ) );
267+
int myOriginY = int((( float( myCanvasHeight - myMarginDoubledH ) )
268+
/ 100. ) * float( mMarginVertical ) );
269+
270+
//Determine the origin of scale bar depending on placement selected
258271
switch ( mPlacementIndex )
259272
{
260273
case 0: // Bottom Left
261-
myOriginX = myMargin;
262-
myOriginY = myCanvasHeight - myMargin;
274+
myOriginX += myMarginW;
275+
myOriginY = myCanvasHeight - myOriginY - myMarginH;
263276
break;
264277
case 1: // Top Left
265-
myOriginX = myMargin;
266-
myOriginY = myMargin;
278+
myOriginX += myMarginW;
279+
myOriginY += myMarginH;
267280
break;
268281
case 2: // Top Right
269-
myOriginX = myCanvasWidth - (( int ) myTotalScaleBarWidth ) - myMargin;
270-
myOriginY = myMargin;
282+
myOriginX = myCanvasWidth - myOriginX - myMarginW - (( int ) myTotalScaleBarWidth );
283+
myOriginY += myMarginH;
271284
break;
272285
case 3: // Bottom Right
273-
myOriginX = myCanvasWidth - (( int ) myTotalScaleBarWidth ) - myMargin;
274-
myOriginY = myCanvasHeight - myMargin;
286+
myOriginX = myCanvasWidth - myOriginX - myMarginW - (( int ) myTotalScaleBarWidth );
287+
myOriginY = myCanvasHeight - myOriginY - myMarginH;
275288
break;
276289
default:
277290
QgsDebugMsg( "Unable to determine where to put scale bar so defaulting to top left" );

‎src/app/qgsdecorationscalebar.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class APP_EXPORT QgsDecorationScaleBar: public QgsDecorationItem
6262
QStringList mStyleLabels;
6363
//! The scale bar color
6464
QColor mColor;
65+
//! Margin percentage values
66+
int mMarginHorizontal;
67+
int mMarginVertical;
6568

6669
friend class QgsDecorationScaleBarDialog;
6770
};

‎src/app/qgsdecorationscalebardialog.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ QgsDecorationScaleBarDialog::QgsDecorationScaleBarDialog( QgsDecorationScaleBar&
5050
cboPlacement->clear();
5151
cboPlacement->addItems( mDeco.mPlacementLabels );
5252
cboPlacement->setCurrentIndex( mDeco.mPlacementIndex );
53+
spnHorizontal->setValue( mDeco.mMarginHorizontal );
54+
spnVertical->setValue( mDeco.mMarginVertical );
5355

54-
chkEnable->setChecked( mDeco.enabled() );
56+
grpEnable->setChecked( mDeco.enabled() );
5557

5658
cboStyle->clear();
5759
cboStyle->addItems( mDeco.mStyleLabels );
@@ -77,9 +79,11 @@ void QgsDecorationScaleBarDialog::on_buttonBox_helpRequested()
7779
void QgsDecorationScaleBarDialog::on_buttonBox_accepted()
7880
{
7981
mDeco.mPlacementIndex = cboPlacement->currentIndex();
82+
mDeco.mMarginHorizontal = spnHorizontal->value();
83+
mDeco.mMarginVertical = spnVertical->value();
8084
mDeco.mPreferredSize = spnSize->value();
8185
mDeco.mSnapping = chkSnapping->isChecked();
82-
mDeco.setEnabled( chkEnable->isChecked() );
86+
mDeco.setEnabled( grpEnable->isChecked() );
8387
mDeco.mStyleIndex = cboStyle->currentIndex();
8488
mDeco.mColor = pbnChangeColor->color();
8589

‎src/ui/qgsdecorationcopyrightdialog.ui

Lines changed: 253 additions & 126 deletions
Large diffs are not rendered by default.

‎src/ui/qgsdecorationgriddialog.ui

Lines changed: 297 additions & 287 deletions
Large diffs are not rendered by default.

‎src/ui/qgsdecorationnortharrowdialog.ui

Lines changed: 240 additions & 140 deletions
Large diffs are not rendered by default.

‎src/ui/qgsdecorationscalebardialog.ui

Lines changed: 361 additions & 192 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.