Skip to content

Commit

Permalink
Followup 3a1d47
Browse files Browse the repository at this point in the history
- Fix dialog tab order
- Avoid use of hardcoded enum int conversion
- Remove some unneeded implicit casts
- Doc tweaks
  • Loading branch information
nyalldawson committed Jan 12, 2016
1 parent 4af65e6 commit 9dccce8
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 318 deletions.
29 changes: 20 additions & 9 deletions python/core/symbology-ng/qgssymbolv2.sip
Expand Up @@ -19,27 +19,38 @@ class QgsSymbolV2

public:

/**
* The unit of the output
*/
enum OutputUnit
{
MM,
MapUnit,
Mixed, //mixed units in symbol layers
Pixel
MM = 0, //!< The output shall be in millimeters
MapUnit, //!< The output shall be in map unitx
Mixed, //!< Mixed units in symbol layers
Pixel, //!< The output shall be in pixels
Percentage, //!< The ouput shall be a percentage of another measurement (eg canvas size, feature size)
};

typedef QList<QgsSymbolV2::OutputUnit> OutputUnitList;

/**
* Type of the symbol
*/
enum SymbolType
{
Marker,
Line,
Fill
Marker, //!< Marker symbol
Line, //!< Line symbol
Fill, //!< Fill symbol
Hybrid //!< Hybrid symbol
};

/**
* Scale method
*/
enum ScaleMethod
{
ScaleArea,
ScaleDiameter
ScaleArea, //!< Calculate scale by the area
ScaleDiameter //!< Calculate scale by the diameter
};

enum RenderHint
Expand Down
19 changes: 10 additions & 9 deletions src/app/qgsdecorationcopyright.cpp
Expand Up @@ -116,24 +116,25 @@ void QgsDecorationCopyright::render( QPainter * theQPainter )
// Set margin according to selected units
switch ( mMarginUnit )
{
case 0: // Millimetres
case QgsSymbolV2::MM:
{
int myPixelsInchX = theQPainter->device()->logicalDpiX();
int myPixelsInchY = theQPainter->device()->logicalDpiY();
myXOffset = int(( float( myPixelsInchX ) * INCHES_TO_MM ) * float( mMarginHorizontal ) );
myYOffset = int(( float( myPixelsInchY ) * INCHES_TO_MM ) * float( mMarginVertical ) );
myXOffset = myPixelsInchX * INCHES_TO_MM * mMarginHorizontal;
myYOffset = myPixelsInchY * INCHES_TO_MM * mMarginVertical;
break;
}
case 3: // Pixels

case QgsSymbolV2::Pixel:
myXOffset = mMarginHorizontal;
myYOffset = mMarginVertical;
break;
case 4: // Percentage
myXOffset = int(( float( myWidth - size.width() )
/ 100. ) * float( mMarginHorizontal ) );
myYOffset = int(( float( myHeight - size.height() )
/ 100. ) * float( mMarginVertical ) );

case QgsSymbolV2::Percentage:
myXOffset = (( myWidth - size.width() ) / 100. ) * mMarginHorizontal;
myYOffset = (( myHeight - size.height() ) / 100. ) * mMarginVertical;
break;

default: // Use default of top left
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsdecorationitem.h
Expand Up @@ -24,6 +24,8 @@

class QPainter;

#define INCHES_TO_MM 0.0393700787402

class APP_EXPORT QgsDecorationItem: public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -85,7 +87,6 @@ class APP_EXPORT QgsDecorationItem: public QObject
Placement mPlacement;
//! Units used for the decoration placement margin
QgsSymbolV2::OutputUnit mMarginUnit;
const double INCHES_TO_MM = 0.0393700787402;

QString mName;
QString mNameConfig;
Expand Down
19 changes: 10 additions & 9 deletions src/app/qgsdecorationnortharrow.cpp
Expand Up @@ -145,24 +145,25 @@ void QgsDecorationNorthArrow::render( QPainter * theQPainter )
int myYOffset = 0;
switch ( mMarginUnit )
{
case 0: // Millimetres
case QgsSymbolV2::MM:
{
int myPixelsInchX = theQPainter->device()->logicalDpiX();
int myPixelsInchY = theQPainter->device()->logicalDpiY();
myXOffset = int(( float( myPixelsInchX ) * INCHES_TO_MM ) * float( mMarginHorizontal ) );
myYOffset = int(( float( myPixelsInchY ) * INCHES_TO_MM ) * float( mMarginVertical ) );
myXOffset = myPixelsInchX * INCHES_TO_MM * mMarginHorizontal;
myYOffset = myPixelsInchY * INCHES_TO_MM * mMarginVertical;
break;
}
case 3: // Pixels

case QgsSymbolV2::Pixel:
myXOffset = mMarginHorizontal - 5; // Minus 5 to shift tight into corner
myYOffset = mMarginVertical - 5;
break;
case 4: // Percentage
myXOffset = int((( float( myWidth ) - float( myQPixmap.width() ) )
/ 100. ) * float( mMarginHorizontal ) );
myYOffset = int((( float( myHeight ) - float( myQPixmap.height() ) )
/ 100. ) * float( mMarginVertical ) );

case QgsSymbolV2::Percentage:
myXOffset = (( myWidth - myQPixmap.width() ) / 100. ) * mMarginHorizontal;
myYOffset = (( myHeight - myQPixmap.height() ) / 100. ) * mMarginVertical;
break;

default: // Use default of top left
break;
}
Expand Down
24 changes: 13 additions & 11 deletions src/app/qgsdecorationscalebar.cpp
Expand Up @@ -256,31 +256,33 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
// Set margin according to selected units
switch ( mMarginUnit )
{
case 0: // Millimetres
case QgsSymbolV2::MM:
{
int myPixelsInchX = theQPainter->device()->logicalDpiX();
int myPixelsInchY = theQPainter->device()->logicalDpiY();
myOriginX = int(( float( myPixelsInchX ) * INCHES_TO_MM ) * float( mMarginHorizontal ) );
myOriginY = int(( float( myPixelsInchY ) * INCHES_TO_MM ) * float( mMarginVertical ) );
myOriginX = myPixelsInchX * INCHES_TO_MM * mMarginHorizontal;
myOriginY = myPixelsInchY * INCHES_TO_MM * mMarginVertical;
break;
}
case 3: // Pixels

case QgsSymbolV2::Pixel:
myOriginX = mMarginHorizontal - 5.; // Minus 5 to shift tight into corner
myOriginY = mMarginVertical - 5.;
break;
case 4: // Percentage

case QgsSymbolV2::Percentage:
{
float myMarginDoubledW = float( myMarginW * 2 );
float myMarginDoubledH = float( myMarginH * 2 );
myOriginX = int((( float( myCanvasWidth - myMarginDoubledW ) - myTotalScaleBarWidth )
/ 100. ) * float( mMarginHorizontal ) );
myOriginY = int((( float( myCanvasHeight - myMarginDoubledH ) )
/ 100. ) * float( mMarginVertical ) );
float myMarginDoubledW = myMarginW * 2.0;
float myMarginDoubledH = myMarginH * 2.0;
myOriginX = (( myCanvasWidth - myMarginDoubledW - myTotalScaleBarWidth ) / 100. ) * mMarginHorizontal;
myOriginY = (( myCanvasHeight - myMarginDoubledH ) / 100. ) * mMarginVertical;
break;
}

default: // Use default of top left
break;
}

//Determine the origin of scale bar depending on placement selected
switch ( mPlacement )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbolv2.h
Expand Up @@ -61,7 +61,7 @@ class CORE_EXPORT QgsSymbolV2
MapUnit, //!< The output shall be in map unitx
Mixed, //!< Mixed units in symbol layers
Pixel, //!< The output shall be in pixels
Percentage //!< The ouput shall be in percentage of canvas
Percentage, //!< The ouput shall be a percentage of another measurement (eg canvas size, feature size)
};

typedef QList<OutputUnit> OutputUnitList;
Expand Down

0 comments on commit 9dccce8

Please sign in to comment.