27 #include "../../../common/STLUtils.h" 28 #include "../../../maptools/Utils.h" 39 #define TD_KM "KILOMETRE" 41 #define TD_DG "DEGREE" 43 #define SD_KM QObject::tr("Kilometers") 44 #define SD_MT QObject::tr("Meters") 45 #define SD_DG QObject::tr("Degrees") 46 #define SD_FT QObject::tr("Feet") 60 QFontMetrics fm(font);
86 if (displayUnit ==
TD_KM)
89 if (displayUnit ==
TD_MT)
92 if (displayUnit ==
TD_DG)
109 QFontMetrics fm(font);
123 int GetMinimumHeaderWidth(
const QPaintDevice* device,
const QFont& font,
const std::vector<double>& intervals,
const std::vector<double>& values,
const bool& printer)
125 QFontMetrics fm(font);
127 int iniValue = fm.width(QString::number(values[0])),
128 finalValue = fm.width(QString::number(values[values.size() - 1])),
131 int minW = (iniValue / 2) + (finalValue / 2) + rulerPixels;
143 int GetMinimumScaleWidth(
const QPaintDevice* device,
const std::vector<double>& intervals,
const bool& printer)
159 QFontMetrics fm(font);
161 QString value = QString(
"1 : %1 ( %2 )").arg(factor).arg(unit);
163 int pixelsWide = fm.width(value);
180 int GetMinimumWidth(
const QPaintDevice* device,
const QFont& headerFont,
const QFont& footerFont,
const std::vector<double>& intervals,
const std::vector<double>& values,
const QString& unit,
181 const int& factor,
const bool& printer)
186 if (headerW > footerW)
202 int GetMinimumHeight(
const QPaintDevice* device,
const QFont& headerFont,
const QFont& footerFont,
const int& rulerHeightMM,
203 const bool& numericScaleVisible,
const bool& printer)
211 int h = hh + sh + h_margin;
233 QSize
GetComponentSize(
const QPaintDevice* device,
const QFont& headerFont,
const QFont& footerFont,
const int& heightMM,
const std::vector<double>& intervals,
234 const std::vector<double>& values,
const bool& printer,
const bool& numericScaleVisible,
const QString& unit,
const int& factor)
236 return QSize(
GetMinimumWidth(device, headerFont, footerFont, intervals, values, unit, factor, printer) + 1,
237 GetMinimumHeight(device, headerFont, footerFont, heightMM, numericScaleVisible, printer) + 1);
250 QPixmap*
GetDashedScale(
const QPaintDevice* device,
const int& heightMM,
const std::vector<double>& intervals,
const bool& beginsBlack,
const QColor& color,
const bool& printer)
255 QPixmap* pix =
new QPixmap(w + 1, h + 1);
257 pix->fill(Qt::transparent);
261 QRect rect(0, 0, w, h);
263 p.fillRect(rect, Qt::white);
269 for (
size_t i = (beginsBlack) ? 0 : 1; i < intervals.size() - 1; i+=2)
274 QPoint topLeft(x, 0),
275 bottomRight(next_x, h);
277 QRect r(topLeft, bottomRight);
279 p.fillRect(r, color);
297 QPixmap*
GetDoubleDashedScale(
const QPaintDevice* device,
const int& heightMM,
const std::vector<double> intervals,
const bool& beginsBlack,
const QColor& color,
const bool& printer)
300 double hMM = (heightMM <= 1) ? 2 : heightMM;
305 QPixmap* p1 =
GetDashedScale(device, static_cast<int>(hMM / 2), intervals, beginsBlack, color, printer);
306 QPixmap* p2 =
GetDashedScale(device, static_cast<int>(hMM / 2), intervals, !beginsBlack, color, printer);
308 QPixmap* pix =
new QPixmap(p1->width(), p1->height() + p2->height() - 1);
312 p.setCompositionMode(QPainter::CompositionMode_SourceOver);
314 p.drawPixmap(0, 0, *p1);
315 p.drawPixmap(0, p1->height() - 1, *p2);
332 QPixmap*
GetRulerScale(
const QPaintDevice* device,
const double& heightMM,
const std::vector<double>& intervals,
const QColor& color,
const bool& printer)
334 int hMM =
static_cast<int>(heightMM);
344 QPixmap* pix =
new QPixmap(w + 1, h + 1);
346 pix->fill(Qt::transparent);
357 p.drawLine(0, y, xf, y);
359 for (
size_t i = 0; i < intervals.size(); i++)
363 p.drawLine(ini, 0, ini, y);
379 double dx = www / 9.;
380 long idx =
static_cast<long>(
dx);
392 idx =
static_cast<long>(
dx);
395 idx =
static_cast<long>(dx * 10.);
407 idx =
static_cast<long>(
dx);
430 void GetIntervals(
const int& breaks, std::vector<double>& values, std::vector<double>& intervals,
const int& unitsPerInterval,
const double& factor)
433 double gapMM = 10 * gap / factor;
437 values.push_back(value);
439 intervals.push_back(interval);
441 for (
int i = 1; i < breaks; i++)
446 values.push_back(value);
447 intervals.push_back(interval);
464 QPixmap*
MakeHeader(
const QPaintDevice* device,
const QFont& font,
const QColor& color,
const std::vector<double>& intervals,
const std::vector<double>& values,
const bool& showAllValues,
465 const bool& printer,
int& pixmapOffset,
const bool& toLong)
470 QPixmap* pix =
new QPixmap(w+1, h+1);
472 pix->fill(Qt::transparent);
474 QFontMetrics fm(font);
477 sub_h = fm.height() + 1;
479 std::vector<QPixmap*> sub_pixs;
485 for (
size_t i = 0; i < values.size(); i++)
487 QString v = (toLong) ? QString::number(static_cast<long>(values[i])) : QString::number(values[i]);
493 QPixmap* sub_pix =
new QPixmap(sub_w + 1, sub_h + 1);
495 sub_pix->fill(Qt::transparent);
501 p.drawText(QRect(0, 0, sub_w, sub_h), Qt::AlignLeft, v);
503 sub_pixs.push_back(sub_pix);
508 pixmapOffset = (sub_pixs[0]->width() / 2);
514 QPixmap* sub_pix = sub_pixs[0];
515 QRect rec = sub_pix->rect();
517 p.drawPixmap(rec, *sub_pix);
521 sub_pix = sub_pixs[values.size() - 1];
522 rec = sub_pix->rect();
526 QPoint c(offset, rec.height() / 2);
530 p.drawPixmap(rec, *sub_pix);
536 for (
size_t i = 1; i < intervals.size() - 1; i++)
538 sub_pix = sub_pixs[i];
539 rec = sub_pix->rect();
543 QPoint c(offset, rec.height() / 2);
547 p.drawPixmap(rec, *sub_pix);
564 QPixmap*
MakeFooter(
const int& factor,
const QString& unit,
const QFont& font,
const QColor& color)
566 QFontMetrics fm(font);
568 QString value = QString(
"1 : %1 ( %2 )").arg(factor).arg(unit);
570 int pixelsWide = fm.width(value),
571 pixelsHigh = fm.height();
573 QPixmap* pix =
new QPixmap(pixelsWide + 1, pixelsHigh + 1);
575 pix->fill(Qt::transparent);
584 p.drawText(QRect(0, 0, pixelsWide, pixelsHigh), Qt::AlignLeft, value);
607 void RepaintWidget(QPaintDevice* device,
const QFont& headerFont,
const QColor& headerColor,
const bool& allHeaderVisible,
const QColor& rulerColor,
const std::vector<double>& intervals,
608 const std::vector<double>& values,
const int& heightMM,
const bool& showNumericScale,
const QFont& footerFont,
const QColor& footerColor,
const QString& unit,
const double& factor,
614 QPixmap* header =
MakeHeader(device, headerFont, headerColor, intervals, values, allHeaderVisible, printer, pixOffset, (unit !=
SD_DG));
616 QPixmap* gScale =
nullptr;
618 QPixmap* footer =
nullptr;
623 gScale =
GetDashedScale(device, heightMM, intervals,
false, rulerColor, printer);
627 gScale =
GetDashedScale(device, heightMM, intervals,
true, rulerColor, printer);
631 gScale =
GetRulerScale(device, heightMM, intervals, rulerColor, printer);
646 if (showNumericScale)
647 footer =
MakeFooter(static_cast<int>(factor), unit, footerFont, footerColor);
651 int centerX = device->width() / 2,
652 centerY = header->height() / 2;
655 QRect hR = header->rect();
656 hR.moveCenter(QPoint(centerX, centerY));
657 p.drawPixmap(hR, *header);
661 int x = hR.x() + pixOffset,
662 y = hR.height() + margin;
664 QRect sR = gScale->rect();
666 sR.moveTo(QPoint(x, y));
668 p.drawPixmap(sR, *gScale);
672 if (footer !=
nullptr)
674 QRect fR = footer->rect();
677 y = header->height() + margin + gScale->height() + margin + (fR.height() / 2);
679 fR.moveCenter(QPoint(x, y));
681 p.drawPixmap(fR, *footer);
701 if (fromUnit ==
TD_MT)
704 if (fromUnit ==
TD_DG)
730 if (fromUnit ==
TD_KM)
733 return w * (12. * 25.4);
747 if (unitPtr ==
nullptr)
752 if (displayUnit == toUnit)
755 double w =
ToMeters(unitPtr->getName(), env, srid);
761 return (w / 111133.);
766 return w / (12. * 25.4);
775 bool CompareUnit(
const QString& scaleUnit,
const int& displaySRID)
779 if (unitPtr ==
nullptr)
784 return (dsUnit == scaleUnit);
800 vw = display.width(),
801 dpiX = (printer) ? display.physicalDpiX() : display.logicalDpiX(),
802 dpiY = (printer) ? display.physicalDpiY() : display.logicalDpiY(),
803 dotsPerMillimeter = (dpiX > dpiY) ? dpiX / 25.4 : dpiY / 25.4,
804 vwMM = vw / dotsPerMillimeter;
806 double scale = 10 * ww / vwMM;
811 void GetScalesIcons(QMap<int, QIcon>& icons, QStringList& typesNames,
const QPaintDevice* device,
const QColor& color)
813 std::vector<double> intervals;
815 intervals.push_back(0);
816 intervals.push_back(2.);
817 intervals.push_back(4.);
822 QPixmap* pix =
GetRulerScale(device, 2., intervals, color,
false);
824 typesNames.append(QObject::tr(
"Ruler"));
831 typesNames.append(QObject::tr(
"Dashed"));
838 typesNames.append(QObject::tr(
"Dashed begins black"));
844 typesNames.append(QObject::tr(
"Double dashed"));
851 typesNames.append(QObject::tr(
"Double dashed begins black"));
859 QFrame(parent, Qt::SubWindow),
860 m_bckGround(nullptr),
861 m_footerFont(QFont(
"times", 5)),
862 m_showNumericScale(true),
865 m_numberOfIntervals(3),
867 m_rulerColor(Qt::black),
869 m_interactionEnabled(interactive),
871 m_headerColor(m_rulerColor),
872 m_headerFont(m_footerFont),
873 m_headerAllVisible(true),
875 m_footerColor(m_rulerColor),
880 setAttribute(Qt::WA_TranslucentBackground);
962 sr = QFrame::geometry();
969 int newCenterX = dr.center().x(),
970 newCenterY = dr.height() - (sr.height() / 2) - twoMM;
972 sr.moveCenter(QPoint(newCenterX, newCenterY));
974 QFrame::setGeometry(sr);
981 if (unitPtr ==
nullptr)
991 setAttribute(Qt::WA_TransparentForMouseEvents, !state);
1112 RepaintWidget(
m_bckGround,
m_headerFont,
m_headerColor,
m_headerAllVisible,
m_rulerColor,
m_intervals,
m_values,
m_rulerHeightMM,
m_showNumericScale,
m_footerFont,
m_footerColor,
1126 QFrame::paintEvent(event);
1133 QFrame::closeEvent(event);
static te::dt::Date dx(2010, 12, 31)
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
double getWidth() const
It returns the envelope width.
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
boost::shared_ptr< UnitOfMeasure > UnitOfMeasurePtr
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
TEMAPEXPORT te::gm::Envelope GetWorldBoxInPlanar(const te::gm::Envelope &worldBox, int srid)
It gets the requested envelope on a UTM planar projection.