Skip to content
Permalink
Browse files

Followup 3a1d47

- 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 9dccce87ee65d92d5124b1e9a6e3b5926ca1e037
@@ -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
@@ -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;
}
@@ -24,6 +24,8 @@

class QPainter;

#define INCHES_TO_MM 0.0393700787402

class APP_EXPORT QgsDecorationItem: public QObject
{
Q_OBJECT
@@ -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;
@@ -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;
}
@@ -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 )
{
@@ -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;

0 comments on commit 9dccce8

Please sign in to comment.
You can’t perform that action at this time.