Skip to content

Commit

Permalink
Merge pull request #2622 from duncan-r/feature4273_and_3756
Browse files Browse the repository at this point in the history
Feature #4273 and #3756
  • Loading branch information
nyalldawson committed Jan 5, 2016
2 parents e961a52 + 47d9307 commit 6051d3a
Show file tree
Hide file tree
Showing 14 changed files with 1,242 additions and 786 deletions.
32 changes: 18 additions & 14 deletions src/app/qgsdecorationcopyright.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ QgsDecorationCopyright::QgsDecorationCopyright( QObject* parent )
{
mPlacementLabels << tr( "Bottom Left" ) << tr( "Top Left" )
<< tr( "Top Right" ) << tr( "Bottom Right" );
mMarginHorizontal = 0;
mMarginVertical = 0;

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

Expand All @@ -80,6 +84,8 @@ void QgsDecorationCopyright::saveToProject()
prj->writeEntry( mNameConfig, "/Label", mLabelQString );
prj->writeEntry( mNameConfig, "/Color", mLabelQColor.name() );
prj->writeEntry( mNameConfig, "/Placement", mPlacementIndex );
prj->writeEntry( mNameConfig, "/MarginH", mMarginHorizontal );
prj->writeEntry( mNameConfig, "/MarginV", mMarginVertical );
}

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

float myXOffset( 0 ), myYOffset( 0 );

myXOffset = int(( float( myWidth - size.width() )
/ 100. ) * float( mMarginHorizontal ) );
myYOffset = int(( float( myHeight - size.height() )
/ 100. ) * float( mMarginVertical ) );
//Determine placement of label from form combo box
switch ( mPlacementIndex )
{
case 0: // Bottom Left
//Define bottom left hand corner start point
myYOffset = myHeight - ( size.height() + 5 );
myXOffset = 5;
case 0: // Bottom Left. myXOffset is set above
myYOffset = myHeight - myYOffset - size.height();
break;
case 1: // Top left
//Define top left hand corner start point
myYOffset = 0;
myXOffset = 5;
case 1: // Top left. Already setup above
break;
case 2: // Top Right
//Define top right hand corner start point
myYOffset = 0;
myXOffset = myWidth - ( size.width() + 5 );
case 2: // Top Right. myYOffset is set above
myXOffset = myWidth - myXOffset - size.width();
break;
case 3: // Bottom Right
//Define bottom right hand corner start point
myYOffset = myHeight - ( size.height() + 5 );
myXOffset = myWidth - ( size.width() + 5 );
myYOffset = myHeight - myYOffset - size.height();
myXOffset = myWidth - myXOffset - size.width();
break;
default:
QgsDebugMsg( QString( "Unknown placement index of %1" ).arg( mPlacementIndex ) );
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsdecorationcopyright.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class APP_EXPORT QgsDecorationCopyright : public QgsDecorationItem
//! Placement of the copyright label - index and translated label names
int mPlacementIndex;
QStringList mPlacementLabels;
//! enable or disable use of position percentage for placement
int mMarginHorizontal;
int mMarginVertical;

friend class QgsDecorationCopyrightDialog;
};
Expand Down
8 changes: 6 additions & 2 deletions src/app/qgsdecorationcopyrightdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ QgsDecorationCopyrightDialog::QgsDecorationCopyrightDialog( QgsDecorationCopyrig
cboOrientation->hide();
textLabel15->hide();

cboxEnabled->setChecked( mDeco.enabled() );
grpEnable->setChecked( mDeco.enabled() );
// text
txtCopyrightText->setPlainText( mDeco.mLabelQString );
// placement
cboPlacement->clear();
cboPlacement->addItems( mDeco.mPlacementLabels );
cboPlacement->setCurrentIndex( mDeco.mPlacementIndex );
spnHorizontal->setValue( mDeco.mMarginHorizontal );
spnVertical->setValue( mDeco.mMarginVertical );
// color
pbnColorChooser->setColor( mDeco.mLabelQColor );
pbnColorChooser->setContext( "gui" );
Expand All @@ -63,7 +65,9 @@ void QgsDecorationCopyrightDialog::on_buttonBox_accepted()
mDeco.mLabelQString = txtCopyrightText->toPlainText();
mDeco.mLabelQColor = pbnColorChooser->color();
mDeco.mPlacementIndex = cboPlacement->currentIndex();
mDeco.setEnabled( cboxEnabled->isChecked() );
mDeco.mMarginHorizontal = spnHorizontal->value();
mDeco.mMarginVertical = spnVertical->value();
mDeco.setEnabled( grpEnable->isChecked() );

accept();
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsdecorationgriddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ QgsDecorationGridDialog::QgsDecorationGridDialog( QgsDecorationGrid& deco, QWidg
QSettings settings;
// restoreGeometry( settings.value( "/Windows/DecorationGrid/geometry" ).toByteArray() );

chkEnable->setChecked( mDeco.enabled() );
grpEnable->setChecked( mDeco.enabled() );

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

Expand Down Expand Up @@ -67,7 +67,7 @@ void QgsDecorationGridDialog::updateGuiElements()
{
// blockAllSignals( true );

chkEnable->setChecked( mDeco.enabled() );
grpEnable->setChecked( mDeco.enabled() );

mIntervalXEdit->setText( QString::number( mDeco.gridIntervalX() ) );
mIntervalYEdit->setText( QString::number( mDeco.gridIntervalY() ) );
Expand Down Expand Up @@ -109,7 +109,7 @@ void QgsDecorationGridDialog::updateGuiElements()
void QgsDecorationGridDialog::updateDecoFromGui()
{
mDeco.setDirty( false );
mDeco.setEnabled( chkEnable->isChecked() );
mDeco.setEnabled( grpEnable->isChecked() );

mDeco.setGridIntervalX( mIntervalXEdit->text().toDouble() );
mDeco.setGridIntervalY( mIntervalYEdit->text().toDouble() );
Expand Down
24 changes: 18 additions & 6 deletions src/app/qgsdecorationnortharrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ QgsDecorationNorthArrow::QgsDecorationNorthArrow( QObject* parent )
mAutomatic = true;
mPlacementLabels << tr( "Bottom Left" ) << tr( "Top Left" )
<< tr( "Top Right" ) << tr( "Bottom Right" );
mMarginHorizontal = 0;
mMarginVertical = 0;

setName( "North Arrow" );
projectRead();
Expand All @@ -76,6 +78,8 @@ void QgsDecorationNorthArrow::projectRead()
mRotationInt = QgsProject::instance()->readNumEntry( mNameConfig, "/Rotation", 0 );
mPlacementIndex = QgsProject::instance()->readNumEntry( mNameConfig, "/Placement", 0 );
mAutomatic = QgsProject::instance()->readBoolEntry( mNameConfig, "/Automatic", true );
mMarginHorizontal = QgsProject::instance()->readNumEntry( mNameConfig, "/MarginH", 0 );
mMarginVertical = QgsProject::instance()->readNumEntry( mNameConfig, "/MarginV", 0 );
}

void QgsDecorationNorthArrow::saveToProject()
Expand All @@ -84,6 +88,8 @@ void QgsDecorationNorthArrow::saveToProject()
QgsProject::instance()->writeEntry( mNameConfig, "/Rotation", mRotationInt );
QgsProject::instance()->writeEntry( mNameConfig, "/Placement", mPlacementIndex );
QgsProject::instance()->writeEntry( mNameConfig, "/Automatic", mAutomatic );
QgsProject::instance()->writeEntry( mNameConfig, "/MarginH", mMarginHorizontal );
QgsProject::instance()->writeEntry( mNameConfig, "/MarginV", mMarginVertical );
}

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

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

// Calculate the margin percentage values
int myPercentageWidth = int((( float( myWidth ) - float( myQPixmap.width() ) )
/ 100. ) * float( mMarginHorizontal ) );
int myPercentageHeight = int((( float( myHeight ) - float( myQPixmap.height() ) )
/ 100. ) * float( mMarginVertical ) );

//Determine placement of label from form combo box
switch ( mPlacementIndex )
{
case 0: // Bottom Left
theQPainter->translate( 0, myHeight - myQPixmap.height() );
theQPainter->translate( myPercentageWidth, myHeight - myPercentageHeight - myQPixmap.height() );
break;
case 1: // Top Left
//no need to translate for TL corner because we're already at the origin
theQPainter->translate( 0, 0 );
theQPainter->translate( myPercentageWidth, myPercentageHeight );
break;
case 2: // Top Right
theQPainter->translate( myWidth - myQPixmap.width(), 0 );
theQPainter->translate( myWidth - myPercentageWidth - myQPixmap.width(), myPercentageHeight );
break;
case 3: // Bottom Right
theQPainter->translate( myWidth - myQPixmap.width(),
myHeight - myQPixmap.height() );
theQPainter->translate( myWidth - myPercentageWidth - myQPixmap.width(),
myHeight - myPercentageHeight - myQPixmap.height() );
break;
default:
{
//QgsDebugMsg("Unable to determine where to put north arrow so defaulting to top left");
}
}

//rotate the canvas by the north arrow rotation amount
theQPainter->rotate( mRotationInt );
//Now we can actually do the drawing, and draw a smooth north arrow even when rotated
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsdecorationnortharrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class APP_EXPORT QgsDecorationNorthArrow: public QgsDecorationItem
// The placement index and translated text
int mPlacementIndex;
QStringList mPlacementLabels;
//! margin values
int mMarginHorizontal;
int mMarginVertical;

friend class QgsDecorationNorthArrowDialog;
};
Expand Down
8 changes: 6 additions & 2 deletions src/app/qgsdecorationnortharrowdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ QgsDecorationNorthArrowDialog::QgsDecorationNorthArrowDialog( QgsDecorationNorth
cboPlacement->clear();
cboPlacement->addItems( mDeco.mPlacementLabels );
cboPlacement->setCurrentIndex( mDeco.mPlacementIndex );
spinHorizontal->setValue( mDeco.mMarginHorizontal );
spinVertical->setValue( mDeco.mMarginVertical );

// enabled
cboxShow->setChecked( mDeco.enabled() );
grpEnable->setChecked( mDeco.enabled() );

// automatic
cboxAutomatic->setChecked( mDeco.mAutomatic );
Expand All @@ -62,8 +64,10 @@ void QgsDecorationNorthArrowDialog::on_buttonBox_accepted()
{
mDeco.mRotationInt = sliderRotation->value();
mDeco.mPlacementIndex = cboPlacement->currentIndex();
mDeco.setEnabled( cboxShow->isChecked() );
mDeco.setEnabled( grpEnable->isChecked() );
mDeco.mAutomatic = cboxAutomatic->isChecked();
mDeco.mMarginHorizontal = spinHorizontal->value();
mDeco.mMarginVertical = spinVertical->value();

accept();
}
Expand Down
37 changes: 25 additions & 12 deletions src/app/qgsdecorationscalebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ QgsDecorationScaleBar::QgsDecorationScaleBar( QObject* parent )
mPlacementIndex = 1;
mStyleLabels << tr( "Tick Down" ) << tr( "Tick Up" )
<< tr( "Bar" ) << tr( "Box" );
mMarginHorizontal = 0;
mMarginVertical = 0;

setName( "Scale Bar" );
projectRead();
Expand All @@ -79,6 +81,8 @@ void QgsDecorationScaleBar::projectRead()
int myGreenInt = QgsProject::instance()->readNumEntry( mNameConfig, "/ColorGreenPart", 0 );
int myBlueInt = QgsProject::instance()->readNumEntry( mNameConfig, "/ColorBluePart", 0 );
mColor = QColor( myRedInt, myGreenInt, myBlueInt );
mMarginHorizontal = QgsProject::instance()->readNumEntry( mNameConfig, "/MarginH", 0 );
mMarginVertical = QgsProject::instance()->readNumEntry( mNameConfig, "/MarginV", 0 );
}

void QgsDecorationScaleBar::saveToProject()
Expand All @@ -92,6 +96,8 @@ void QgsDecorationScaleBar::saveToProject()
QgsProject::instance()->writeEntry( mNameConfig, "/ColorRedPart", mColor.red() );
QgsProject::instance()->writeEntry( mNameConfig, "/ColorGreenPart", mColor.green() );
QgsProject::instance()->writeEntry( mNameConfig, "/ColorBluePart", mColor.blue() );
QgsProject::instance()->writeEntry( mNameConfig, "/MarginH", mMarginHorizontal );
QgsProject::instance()->writeEntry( mNameConfig, "/MarginV", mMarginVertical );
}


Expand Down Expand Up @@ -133,7 +139,6 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
// Hard coded sizes
int myMajorTickSize = 8;
int myTextOffsetX = 3;
int myMargin = 20;

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

//determine the origin of scale bar depending on placement selected
int myOriginX = myMargin;
int myOriginY = myMargin;
//Calculate percentage page width for use in placing item
int myMarginW = 10;
int myMarginH = 20;
float myMarginDoubledW = float( myMarginW * 2 );
float myMarginDoubledH = float( myMarginH * 2 );
int myOriginX = int((( float( myCanvasWidth - myMarginDoubledW ) - myTotalScaleBarWidth )
/ 100. ) * float( mMarginHorizontal ) );
int myOriginY = int((( float( myCanvasHeight - myMarginDoubledH ) )
/ 100. ) * float( mMarginVertical ) );

//Determine the origin of scale bar depending on placement selected
switch ( mPlacementIndex )
{
case 0: // Bottom Left
myOriginX = myMargin;
myOriginY = myCanvasHeight - myMargin;
myOriginX += myMarginW;
myOriginY = myCanvasHeight - myOriginY - myMarginH;
break;
case 1: // Top Left
myOriginX = myMargin;
myOriginY = myMargin;
myOriginX += myMarginW;
myOriginY += myMarginH;
break;
case 2: // Top Right
myOriginX = myCanvasWidth - (( int ) myTotalScaleBarWidth ) - myMargin;
myOriginY = myMargin;
myOriginX = myCanvasWidth - myOriginX - myMarginW - (( int ) myTotalScaleBarWidth );
myOriginY += myMarginH;
break;
case 3: // Bottom Right
myOriginX = myCanvasWidth - (( int ) myTotalScaleBarWidth ) - myMargin;
myOriginY = myCanvasHeight - myMargin;
myOriginX = myCanvasWidth - myOriginX - myMarginW - (( int ) myTotalScaleBarWidth );
myOriginY = myCanvasHeight - myOriginY - myMarginH;
break;
default:
QgsDebugMsg( "Unable to determine where to put scale bar so defaulting to top left" );
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsdecorationscalebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class APP_EXPORT QgsDecorationScaleBar: public QgsDecorationItem
QStringList mStyleLabels;
//! The scale bar color
QColor mColor;
//! Margin percentage values
int mMarginHorizontal;
int mMarginVertical;

friend class QgsDecorationScaleBarDialog;
};
Expand Down
8 changes: 6 additions & 2 deletions src/app/qgsdecorationscalebardialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ QgsDecorationScaleBarDialog::QgsDecorationScaleBarDialog( QgsDecorationScaleBar&
cboPlacement->clear();
cboPlacement->addItems( mDeco.mPlacementLabels );
cboPlacement->setCurrentIndex( mDeco.mPlacementIndex );
spnHorizontal->setValue( mDeco.mMarginHorizontal );
spnVertical->setValue( mDeco.mMarginVertical );

chkEnable->setChecked( mDeco.enabled() );
grpEnable->setChecked( mDeco.enabled() );

cboStyle->clear();
cboStyle->addItems( mDeco.mStyleLabels );
Expand All @@ -77,9 +79,11 @@ void QgsDecorationScaleBarDialog::on_buttonBox_helpRequested()
void QgsDecorationScaleBarDialog::on_buttonBox_accepted()
{
mDeco.mPlacementIndex = cboPlacement->currentIndex();
mDeco.mMarginHorizontal = spnHorizontal->value();
mDeco.mMarginVertical = spnVertical->value();
mDeco.mPreferredSize = spnSize->value();
mDeco.mSnapping = chkSnapping->isChecked();
mDeco.setEnabled( chkEnable->isChecked() );
mDeco.setEnabled( grpEnable->isChecked() );
mDeco.mStyleIndex = cboStyle->currentIndex();
mDeco.mColor = pbnChangeColor->color();

Expand Down
Loading

0 comments on commit 6051d3a

Please sign in to comment.