ScaleWidget.cpp File Reference
#include "ScaleWidget.h"
#include "../../../common/STLUtils.h"
#include "../../../maptools/Utils.h"
#include "../Utils.h"
#include "MapDisplay.h"
#include <QFont>
#include <QIcon>
#include <QMap>
#include <QPainter>

Go to the source code of this file.

Macros

#define SD_DG   QObject::tr("Degrees")
 
#define SD_FT   QObject::tr("Feet")
 
#define SD_KM   QObject::tr("Kilometers")
 
#define SD_MT   QObject::tr("Meters")
 
#define TD_DG   "DEGREE"
 
#define TD_FT   "FEET"
 
#define TD_KM   "KILOMETRE"
 Definitions. More...
 
#define TD_MT   "METRE"
 

Functions

double GetScale (const te::qt::widgets::MapDisplay &display, const QString &unit, const bool &printer)
 Returns the scaling factor of the current visualized area in the display. More...
 
void GetScalesIcons (QMap< int, QIcon > &icons, QStringList &typesNames, const QPaintDevice *device, const QColor &color)
 Returns icons and the respective names for the types of rulers that can be used to present the graphic scale. More...
 
Internally methods.

Methods used internally by the ScaleWidget objects.

int CalculateHeaderHeight (const QFont &font)
 Returns the height needed to show the header section. More...
 
int CalculateScaleHeight (const QPaintDevice *device, const int &heightMM, const bool &printer)
 Returns the height needed to show the ruler section. More...
 
QString GetScaleUnit (const std::string &displayUnit)
 Returns the unit in the formatting being used. More...
 
int CalculateFooterHeight (const QFont &font, const bool &visible)
 Returns the height needed to show the footer section. More...
 
int GetMinimumHeaderWidth (const QPaintDevice *device, const QFont &font, const std::vector< double > &intervals, const std::vector< double > &values, const bool &printer)
 Returns the minimum width required to draw the header section. More...
 
int GetMinimumScaleWidth (const QPaintDevice *device, const std::vector< double > &intervals, const bool &printer)
 Returns the minimum width required to draw the ruler section. More...
 
int GetMinimumFooterWidth (const QFont &font, const QString &unit, const int &factor)
 Returns the minimum width required to draw the footer section. More...
 
int GetMinimumWidth (const QPaintDevice *device, const QFont &headerFont, const QFont &footerFont, const std::vector< double > &intervals, const std::vector< double > &values, const QString &unit, const int &factor, const bool &printer)
 Returns the minimum width in pixels required by the widget. More...
 
int GetMinimumHeight (const QPaintDevice *device, const QFont &headerFont, const QFont &footerFont, const int &rulerHeightMM, const bool &numericScaleVisible, const bool &printer)
 Returns the minimum height in pixels required by the widget. More...
 
QSize GetComponentSize (const QPaintDevice *device, const QFont &headerFont, const QFont &footerFont, const int &heightMM, const std::vector< double > &intervals, const std::vector< double > &values, const bool &printer, const bool &numericScaleVisible, const QString &unit, const int &factor)
 Returns the minimum dimensions required to draw the widget. More...
 
QPixmap * GetDashedScale (const QPaintDevice *device, const int &heightMM, const std::vector< double > &intervals, const bool &beginsBlack, const QColor &color, const bool &printer)
 Returns a pixmap with the ruler representation of the graphic scale. More...
 
QPixmap * GetDoubleDashedScale (const QPaintDevice *device, const int &heightMM, const std::vector< double > intervals, const bool &beginsBlack, const QColor &color, const bool &printer)
 Returns a representation of two dashed scales one on top of the other with opposite begining intervals. More...
 
QPixmap * GetRulerScale (const QPaintDevice *device, const double &heightMM, const std::vector< double > &intervals, const QColor &color, const bool &printer)
 Returns a ruler representation graphic scale. More...
 
double GetSweetGapValue (const double &factor)
 Returns a rounded value of interval in unit measure. More...
 
void GetIntervals (const int &breaks, std::vector< double > &values, std::vector< double > &intervals, const int &unitsPerInterval, const double &factor)
 Returns the calculated intervals in millimeters and in unit of measure. More...
 
QPixmap * MakeHeader (const QPaintDevice *device, const QFont &font, const QColor &color, const std::vector< double > &intervals, const std::vector< double > &values, const bool &showAllValues, const bool &printer, int &pixmapOffset, const bool &toLong)
 Returns a pixmap with the header section of the graphic scale. More...
 
QPixmap * MakeFooter (const int &factor, const QString &unit, const QFont &font, const QColor &color)
 Returns a pixmap with the footer section of the graphic scale. More...
 
void RepaintWidget (QPaintDevice *device, const QFont &headerFont, const QColor &headerColor, const bool &allHeaderVisible, const QColor &rulerColor, const std::vector< double > &intervals, const std::vector< double > &values, const int &heightMM, const bool &showNumericScale, const QFont &footerFont, const QColor &footerColor, const QString &unit, const double &factor, const bool &printer, const te::qt::widgets::ScaleWidget::ScaleTypes &type)
 Repaints the widget. More...
 
double ToMeters (const std::string &fromUnit, const te::gm::Envelope &env, const int &srid)
 Returns the width of env in meters. More...
 
double GetWidthInUnit (const QString &toUnit, const te::gm::Envelope &env, const int &srid)
 Returns the width of the env, that is in meters, to the destination unit of measure. More...
 
bool CompareUnit (const QString &scaleUnit, const int &displaySRID)
 Comparies the scale unit and the display unit and returns true if it is and false otherwise. More...
 

Macro Definition Documentation

#define SD_DG   QObject::tr("Degrees")

Definition at line 45 of file ScaleWidget.cpp.

Referenced by GetScaleUnit(), GetWidthInUnit(), and RepaintWidget().

#define SD_FT   QObject::tr("Feet")

Definition at line 46 of file ScaleWidget.cpp.

Referenced by GetScaleUnit().

#define SD_KM   QObject::tr("Kilometers")

Definition at line 43 of file ScaleWidget.cpp.

Referenced by GetScaleUnit(), and GetWidthInUnit().

#define SD_MT   QObject::tr("Meters")

Definition at line 44 of file ScaleWidget.cpp.

Referenced by GetScaleUnit(), and GetWidthInUnit().

#define TD_DG   "DEGREE"

Definition at line 41 of file ScaleWidget.cpp.

Referenced by GetScaleUnit(), and ToMeters().

#define TD_FT   "FEET"

Definition at line 42 of file ScaleWidget.cpp.

#define TD_KM   "KILOMETRE"

Definitions.

Definition at line 39 of file ScaleWidget.cpp.

Referenced by GetScaleUnit(), and ToMeters().

#define TD_MT   "METRE"

Definition at line 40 of file ScaleWidget.cpp.

Referenced by GetScaleUnit(), and ToMeters().

Function Documentation

int CalculateFooterHeight ( const QFont &  font,
const bool visible 
)

Returns the height needed to show the footer section.

Parameters
fontThe font to be used.
visibleTrue if the footer is visible and false otherwise.
Returns
The minimum height needed to show the footer section.

Definition at line 104 of file ScaleWidget.cpp.

Referenced by GetMinimumHeight().

int CalculateHeaderHeight ( const QFont &  font)

Returns the height needed to show the header section.

Parameters
fontThe font to be used.
Returns

Definition at line 58 of file ScaleWidget.cpp.

Referenced by GetMinimumHeight(), and MakeHeader().

int CalculateScaleHeight ( const QPaintDevice *  device,
const int heightMM,
const bool printer 
)

Returns the height needed to show the ruler section.

Parameters
deviceDevice to draw.
heightMMThe ruler height in millimeters.
printerTrue if the device is a printer.
Returns
The minimum height needed to show the ruler section.

Definition at line 72 of file ScaleWidget.cpp.

References te::qt::widgets::MillimetersToPixels().

Referenced by GetDashedScale(), GetMinimumHeight(), and GetRulerScale().

bool CompareUnit ( const QString &  scaleUnit,
const int displaySRID 
)

Comparies the scale unit and the display unit and returns true if it is and false otherwise.

Parameters
scaleUnitThe scale unit selected.
displaySRIDSRID being used in the display.
Returns
True if the units are equals and false otherwise.

Definition at line 775 of file ScaleWidget.cpp.

References te::common::Singleton< SpatialReferenceSystemManager >::getInstance(), and GetScaleUnit().

Referenced by GetScale().

QSize GetComponentSize ( const QPaintDevice *  device,
const QFont &  headerFont,
const QFont &  footerFont,
const int heightMM,
const std::vector< double > &  intervals,
const std::vector< double > &  values,
const bool printer,
const bool numericScaleVisible,
const QString &  unit,
const int factor 
)

Returns the minimum dimensions required to draw the widget.

Parameters
deviceDevice to draw.
headerFontFont of the header section.
footerFontFont of the footer section.
heightMMThe height of the ruler in millimeters.
intervalsValues of the intervals in millimeters.
valuesValues fo the intervals in the unit of measure being used.
printerTrue if the device is a printer.
numericScaleVisibleVisibility of the footer section.
unitThe unit fo mesaure being used.
factorScaling factor.
Returns
The minimum dimensions required to draw the widget.

Definition at line 233 of file ScaleWidget.cpp.

References GetMinimumHeight(), and GetMinimumWidth().

Referenced by te::qt::widgets::ScaleWidget::redoWidget().

QPixmap* GetDashedScale ( const QPaintDevice *  device,
const int heightMM,
const std::vector< double > &  intervals,
const bool beginsBlack,
const QColor &  color,
const bool printer 
)

Returns a pixmap with the ruler representation of the graphic scale.

Parameters
deviceDevice to draw.
heightMMThe height of the ruler in millimeters.
intervalsValues of the intervals in millimeters.
beginsBlackTrue if the first interval must be colored, false otherwise.
colorThe color to be used.
printerTrue if the device is a printer.
Returns
A pixmap with the ruler representation of the graphic scale.

Definition at line 250 of file ScaleWidget.cpp.

References CalculateScaleHeight(), GetMinimumScaleWidth(), te::qt::widgets::MillimetersToPixels(), and p.

Referenced by GetDoubleDashedScale(), GetScalesIcons(), and RepaintWidget().

QPixmap* GetDoubleDashedScale ( const QPaintDevice *  device,
const int heightMM,
const std::vector< double >  intervals,
const bool beginsBlack,
const QColor &  color,
const bool printer 
)

Returns a representation of two dashed scales one on top of the other with opposite begining intervals.

Parameters
deviceDevice to draw.
heightMMThe height of the ruler in millimeters.
intervalsValues of the intervals in millimeters.
beginsBlackTrue if the first interval must be colored, false otherwise.
colorThe color to be used.
printerTrue if the device is a printer.
Returns
A representation of two dashed scales one on top of the other with opposite begining intervals.

Definition at line 297 of file ScaleWidget.cpp.

References GetDashedScale(), and p.

Referenced by GetScalesIcons(), and RepaintWidget().

void GetIntervals ( const int breaks,
std::vector< double > &  values,
std::vector< double > &  intervals,
const int unitsPerInterval,
const double &  factor 
)

Returns the calculated intervals in millimeters and in unit of measure.

Parameters
breaksNumber of values that determines the intervals on the ruler.
[out]valuesValues of the intervals in the current unit of measure.
[out]intervalsValues of intervals in millimeters.
unitsPerIntervalNumber of units of scaling will be used in intervals.
factorScaling factor.

Definition at line 430 of file ScaleWidget.cpp.

References GetSweetGapValue().

Referenced by te::qt::widgets::ScaleWidget::redoWidget().

int GetMinimumFooterWidth ( const QFont &  font,
const QString &  unit,
const int factor 
)

Returns the minimum width required to draw the footer section.

Parameters
fontThe font to be used.
unitThe unit of measure being used.
factorScaling factor.
Returns
The minimum width required to draw the footer section.

Definition at line 157 of file ScaleWidget.cpp.

Referenced by GetMinimumWidth().

int GetMinimumHeaderWidth ( const QPaintDevice *  device,
const QFont &  font,
const std::vector< double > &  intervals,
const std::vector< double > &  values,
const bool printer 
)

Returns the minimum width required to draw the header section.

Parameters
deviceDevice to draw.
fontThe font to be used.
intervalsIntervals in millimeters.
valuesIntervals in the selected unit of measure.
printerTrue if the device is a printer.
Returns
The minimum width required to draw the header section.

Definition at line 123 of file ScaleWidget.cpp.

References te::qt::widgets::MillimetersToPixels().

Referenced by GetMinimumWidth(), and MakeHeader().

int GetMinimumHeight ( const QPaintDevice *  device,
const QFont &  headerFont,
const QFont &  footerFont,
const int rulerHeightMM,
const bool numericScaleVisible,
const bool printer 
)

Returns the minimum height in pixels required by the widget.

Parameters
deviceDevice to draw.
headerFontFont of the header section.
footerFontFont of the footer section.
rulerHeightMMThe height of the ruler in millimeters.
numericScaleVisibleVisibility of the footer section.
printerTrue if the device is a printer.
Returns
The minimum height in pixels required by the widget.

Definition at line 202 of file ScaleWidget.cpp.

References CalculateFooterHeight(), CalculateHeaderHeight(), CalculateScaleHeight(), and te::qt::widgets::MillimetersToPixels().

Referenced by GetComponentSize().

int GetMinimumScaleWidth ( const QPaintDevice *  device,
const std::vector< double > &  intervals,
const bool printer 
)

Returns the minimum width required to draw the ruler section.

Parameters
deviceDevice to draw.
intervalsIntervals in millimeters.
printerTrue if the device is a printer.
Returns
The minimum width required to draw the ruler section.

Definition at line 143 of file ScaleWidget.cpp.

References te::qt::widgets::MillimetersToPixels().

Referenced by GetDashedScale(), and GetRulerScale().

int GetMinimumWidth ( const QPaintDevice *  device,
const QFont &  headerFont,
const QFont &  footerFont,
const std::vector< double > &  intervals,
const std::vector< double > &  values,
const QString &  unit,
const int factor,
const bool printer 
)

Returns the minimum width in pixels required by the widget.

Parameters
deviceDevice to draw.
headerFontFont of the header section.
footerFontFont of the footer section.
intervalsValues of the intervals in millimeters.
valuesValues fo the intervals in the unit of measure being used.
unitThe unit fo mesaure being used.
factorScaling factor.
printerTrue if the device is a printer.
Returns
The minimum width in pixels required by the widget.

Definition at line 180 of file ScaleWidget.cpp.

References GetMinimumFooterWidth(), and GetMinimumHeaderWidth().

Referenced by GetComponentSize().

QPixmap* GetRulerScale ( const QPaintDevice *  device,
const double &  heightMM,
const std::vector< double > &  intervals,
const QColor &  color,
const bool printer 
)

Returns a ruler representation graphic scale.

Parameters
deviceDevice to draw.
heightMMThe height of the ruler in millimeters.
intervalsValues of the intervals in millimeters.
colorThe color to be used.
printerTrue if the device is a printer.
Returns
A ruler representation graphic scale.

Definition at line 332 of file ScaleWidget.cpp.

References CalculateScaleHeight(), GetMinimumScaleWidth(), te::qt::widgets::MillimetersToPixels(), and p.

Referenced by GetScalesIcons(), and RepaintWidget().

double GetScale ( const te::qt::widgets::MapDisplay display,
const QString &  unit,
const bool printer 
)

Returns the scaling factor of the current visualized area in the display.

Parameters
displayThe display being used.
unitUnit of measure to be used.
printerTrue if the device is a printer.
Returns
The scaling factor of the current visualized area in the display.

Definition at line 795 of file ScaleWidget.cpp.

References CompareUnit(), te::map::MapDisplay::getExtent(), te::map::MapDisplay::getSRID(), te::gm::Envelope::getWidth(), and GetWidthInUnit().

Referenced by te::qt::widgets::ScaleWidget::redoWidget(), and te::qt::widgets::ScaleWidget::updateScaleFactor().

void GetScalesIcons ( QMap< int, QIcon > &  icons,
QStringList &  typesNames,
const QPaintDevice *  device,
const QColor &  color 
)

Returns icons and the respective names for the types of rulers that can be used to present the graphic scale.

Parameters
[out]iconsGenerated icons.
[out]typesNamesGenerated names.
deviceThe device being used.
colorThe color of the ruler.

Definition at line 811 of file ScaleWidget.cpp.

References te::qt::widgets::ScaleWidget::DASHED, te::qt::widgets::ScaleWidget::DASHED_BEGIN_BLACK, te::qt::widgets::ScaleWidget::DOUBLE_DASHED, te::qt::widgets::ScaleWidget::DOUBLE_DASHED_BEGIN_BLACK, GetDashedScale(), GetDoubleDashedScale(), GetRulerScale(), and te::qt::widgets::ScaleWidget::RULER.

Referenced by te::qt::widgets::ScalePropertyBrowser::ScalePropertyBrowser().

QString GetScaleUnit ( const std::string &  displayUnit)

Returns the unit in the formatting being used.

Parameters
displayUnitUnit being used in the display.
Returns
The unit with the name used in the scale object.

Definition at line 84 of file ScaleWidget.cpp.

References SD_DG, SD_FT, SD_KM, SD_MT, TD_DG, TD_KM, and TD_MT.

Referenced by CompareUnit(), GetWidthInUnit(), and te::qt::widgets::ScaleWidget::setUnit().

double GetSweetGapValue ( const double &  factor)

Returns a rounded value of interval in unit measure.

Parameters
factorScaling factor.
Returns
A rounded value of interval in unit measure.
Note
The value, in the most of times, is greater then the measure represented by 1cm.

Definition at line 376 of file ScaleWidget.cpp.

References dx.

Referenced by GetIntervals().

double GetWidthInUnit ( const QString &  toUnit,
const te::gm::Envelope env,
const int srid 
)

Returns the width of the env, that is in meters, to the destination unit of measure.

Parameters
toUnitThe destination unit of measure.
envThe bounding rectangle to be transformed.
sridThe identifier of the projection being used by the display.
Returns
The width of the env, that is in meters, to the destination unit of measure.

Definition at line 743 of file ScaleWidget.cpp.

References te::common::Singleton< SpatialReferenceSystemManager >::getInstance(), GetScaleUnit(), te::gm::Envelope::getWidth(), SD_DG, SD_KM, SD_MT, and ToMeters().

Referenced by GetScale().

QPixmap* MakeFooter ( const int factor,
const QString &  unit,
const QFont &  font,
const QColor &  color 
)

Returns a pixmap with the footer section of the graphic scale.

Parameters
factorScaling factor.
unitUnit of measure being used.
fontFooter font.
colorFooter color.
Returns
A pixmap with the footer section of the graphic scale.

Definition at line 564 of file ScaleWidget.cpp.

References p.

Referenced by RepaintWidget().

QPixmap* MakeHeader ( const QPaintDevice *  device,
const QFont &  font,
const QColor &  color,
const std::vector< double > &  intervals,
const std::vector< double > &  values,
const bool showAllValues,
const bool printer,
int pixmapOffset,
const bool toLong 
)

Returns a pixmap with the header section of the graphic scale.

Parameters
deviceDevice to draw.
fontHeader font.
colorHeader color.
intervalsValues of intervals in millimeters.
valuesValues of intervals in units of measure.
showAllValuesTrue to show intermediary values ont the header section, false otherwise.
printerTrue if the device is a printer.
[out]pixmapOffsetHalf of the width of the first value. This value is returned to be used to draw the ruler section in the correct position.
toLongIf the values of the header are long type values. (If unit is "Degrees" turn off this argument).
Returns
A pixmap with the header section of the graphic scale.

Definition at line 464 of file ScaleWidget.cpp.

References CalculateHeaderHeight(), te::common::FreeContents(), GetMinimumHeaderWidth(), te::qt::widgets::MillimetersToPixels(), and p.

Referenced by RepaintWidget().

void RepaintWidget ( QPaintDevice *  device,
const QFont &  headerFont,
const QColor &  headerColor,
const bool allHeaderVisible,
const QColor &  rulerColor,
const std::vector< double > &  intervals,
const std::vector< double > &  values,
const int heightMM,
const bool showNumericScale,
const QFont &  footerFont,
const QColor &  footerColor,
const QString &  unit,
const double &  factor,
const bool printer,
const te::qt::widgets::ScaleWidget::ScaleTypes type 
)

Repaints the widget.

Parameters
deviceDevice to draw.
headerFontFont of the header section.
headerColorColor of the header section.
allHeaderVisibleTrue to show intermediary values ont the header section, false otherwise.
rulerColorColor of the ruler section.
intervalsValues of intervals in millimeters.
valuesValues of intervals in units of measure.
heightMMHeight of the ruler in millimeters.
showNumericScaleTrue to show the footer section, false otherwise.
footerFontFont of the footer section.
footerColorColor of the footer section.
unitUnit of measure to be used.
factorScaling factor.
printerTrue if the device is a printer.
typeThe type of the ruler to be drawed.

Definition at line 607 of file ScaleWidget.cpp.

References te::qt::widgets::ScaleWidget::CUSTOM, te::qt::widgets::ScaleWidget::DASHED, te::qt::widgets::ScaleWidget::DASHED_BEGIN_BLACK, te::qt::widgets::ScaleWidget::DOUBLE_DASHED, te::qt::widgets::ScaleWidget::DOUBLE_DASHED_BEGIN_BLACK, GetDashedScale(), GetDoubleDashedScale(), GetRulerScale(), MakeFooter(), MakeHeader(), te::qt::widgets::MillimetersToPixels(), p, te::qt::widgets::ScaleWidget::RULER, and SD_DG.

Referenced by te::qt::widgets::ScaleWidget::redoWidget().

double ToMeters ( const std::string &  fromUnit,
const te::gm::Envelope env,
const int srid 
)

Returns the width of env in meters.

Parameters
fromUnitUnit of measure being used by the display.
envThe bounding rectangle to be transformed.
sridThe identifier of the projection being used by the display.
Returns
The width of env in meters.

Definition at line 697 of file ScaleWidget.cpp.

References te::gm::Envelope::getLowerLeftX(), te::gm::Envelope::getLowerLeftY(), te::gm::Envelope::getUpperRightX(), te::gm::Envelope::getUpperRightY(), te::gm::Envelope::getWidth(), te::map::GetWorldBoxInPlanar(), TD_DG, TD_KM, and TD_MT.

Referenced by GetWidthInUnit().