src/terralib/qt/widgets/canvas/Canvas.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/canvas/Canvas.cpp
22 
23  \brief A canvas built on top of Qt.
24  */
25 
26 // TerraLib
27 #include "../../../color/RGBAColor.h"
28 #include "../../../common/StringUtils.h"
29 #include "../../../geometry.h"
30 #include "../../../maptools/PtMarker.h"
31 #include "../../../raster.h"
32 #include "../Utils.h"
33 #include "Canvas.h"
34 
35 // Qt
36 #include <QBitmap>
37 #include <QBuffer>
38 #include <QImage>
39 #include <QPaintEngine>
40 #include <QPixmap>
41 #include <QPrinter>
42 #include <QResizeEvent>
43 
44 // STL
45 #include <cassert>
46 #include <algorithm>
47 
48 te::qt::widgets::Canvas::Canvas(int w, int h, int devType)
49 : m_painter(nullptr),
50 m_isPainterOwner(true),
51 m_isDeviceOwner(true),
52 m_bgColor(Qt::transparent),
53 m_erase(false),
54 m_ptWidth(1),
55 m_ptColor(Qt::black),
56 m_ptColorFrom(m_ptColor),
57 m_ptImg(nullptr),
58 m_ptImgRotated(nullptr),
59 m_ptSelectionPatternImg(nullptr),
60 m_ptClearPatternImg(nullptr),
61 m_ptRotation(0),
62 m_ptVOffset(0),
63 m_ptHOffset(0),
64 m_lnColor(Qt::transparent),
65 m_lnPen(Qt::blue),
66 m_polyContourColor(Qt::transparent),
67 m_polyContourPen(Qt::gray),
68 m_polyColor(Qt::red),
69 m_polyBrush(Qt::magenta),
70 m_polyImage(nullptr),
71 m_polyRotatedImage(nullptr),
72 m_polyPatternWidth(16),
73 m_txtContourPen(Qt::black),
74 m_txtContourEnabled(false),
75 m_txtBrush(Qt::black),
76 m_txtLetterSpacing(1),
77 m_txtWordSpacing(1),
78 m_txtLineSpacing(1)
79 {
80  m_painter = new QPainter();
81 
82  if(devType == QInternal::Pixmap)
83  {
84  QPixmap* p = new QPixmap(w, h);
85  p->fill(m_bgColor);
86  m_painter->begin(p);
87  }
88  else
89  {
90  QImage* i = new QImage(w, h, QImage::Format_ARGB32_Premultiplied);
91  i->fill(m_bgColor.rgba());
92  m_painter->begin(i);
93  }
94 
95  m_ptPen.setColor(m_ptColor);
96 }
97 
98 te::qt::widgets::Canvas::Canvas(QPaintDevice* device)
99 : m_painter(nullptr),
100 m_isPainterOwner(true),
101 m_isDeviceOwner(false),
102 m_bgColor(Qt::transparent),
103 m_erase(false),
104 m_ptWidth(1),
105 m_ptColor(Qt::black),
107 m_ptImg(nullptr),
108 m_ptImgRotated(nullptr),
109 m_ptSelectionPatternImg(nullptr),
110 m_ptClearPatternImg(nullptr),
111 m_ptRotation(0),
112 m_ptVOffset(0),
113 m_ptHOffset(0),
114 m_lnColor(Qt::transparent),
115 m_lnPen(Qt::blue),
116 m_polyContourColor(Qt::transparent),
117 m_polyContourPen(Qt::gray),
118 m_polyColor(Qt::red),
119 m_polyBrush(Qt::magenta),
120 m_polyImage(nullptr),
121 m_polyRotatedImage(nullptr),
123 m_txtContourPen(Qt::black),
124 m_txtContourEnabled(false),
125 m_txtBrush(Qt::black),
129 {
130  m_painter = new QPainter();
131 
132  m_painter->begin(device);
133 }
134 
136 : m_painter(painter),
137 m_isPainterOwner(false),
138 m_isDeviceOwner(false),
139 m_bgColor(Qt::transparent),
140 m_erase(false),
141 m_ptWidth(1),
142 m_ptColor(Qt::black),
144 m_ptImg(nullptr),
145 m_ptImgRotated(nullptr),
146 m_ptSelectionPatternImg(nullptr),
147 m_ptClearPatternImg(nullptr),
148 m_ptRotation(0),
149 m_ptVOffset(0),
150 m_ptHOffset(0),
151 m_lnColor(Qt::transparent),
152 m_lnPen(Qt::blue),
153 m_polyContourColor(Qt::transparent),
154 m_polyContourPen(Qt::gray),
155 m_polyColor(Qt::red),
156 m_polyBrush(Qt::magenta),
157 m_polyImage(nullptr),
158 m_polyRotatedImage(nullptr),
160 m_txtContourPen(Qt::black),
161 m_txtContourEnabled(false),
162 m_txtBrush(Qt::black),
166 {
167  if(m_painter != nullptr)
168  {
169  m_painterTransform = painter->transform();
170  }
171 }
172 
174 {
175  if(m_isDeviceOwner)
176  {
177  QPaintDevice* device = m_painter->device();
178  m_painter->end();
179  delete device;
180  }
181 
182  if(m_isPainterOwner)
183  {
184  delete m_painter;
185  }
186 
187  delete m_ptImg;
188  delete m_ptImgRotated;
189  delete m_ptClearPatternImg;
191 
192 }
193 
194 void te::qt::widgets::Canvas::setWindow(const double& llx, const double& lly,
195  const double& urx, const double& ury)
196 {
197  double xScale = static_cast<double>(getWidth()) / (urx - llx);
198  double yScale = static_cast<double>(getHeight()) / (ury - lly);
199 
200  m_matrix.reset();
201  m_matrix.scale(xScale, -yScale);
202  m_matrix.translate(-llx, -ury);
203 
204  if(m_isPainterOwner == false)
205  {
206  m_painter->setTransform(m_painterTransform);
207 
208  QTransform transform(m_matrix);
209  m_painter->setTransform(transform, true);
210  }
211  else
212  {
213  m_painter->setMatrix(m_matrix);
214  }
215 }
216 
217 void te::qt::widgets::Canvas::calcAspectRatio(double& llx, double& lly, double& urx, double& ury,
218  const te::map::AlignType hAlign, const te::map::AlignType vAlign)
219 {
220  double ww = urx - llx;
221  double wh = ury - lly;
222 
223  double widthByHeight = static_cast<double>(getWidth()) / static_cast<double>(getHeight());
224 
225  if(widthByHeight > ww / wh)
226  {
227  double v = ww;
228 
229  ww = wh * widthByHeight;
230 
231  if(hAlign == te::map::Left)
232  urx = llx + ww;
233  else if(hAlign == te::map::Right)
234  llx = urx - ww;
235  else // it is center
236  {
237  llx = llx - (ww - v) / 2.0;
238  urx = llx + ww;
239  }
240  }
241  else
242  {
243  double v = wh;
244 
245  wh = ww / widthByHeight;
246 
247  if(vAlign == te::map::Top)
248  lly = ury - wh;
249  else if(vAlign == te::map::Bottom)
250  ury = lly + wh;
251  else // it is center
252  {
253  lly = lly - (wh - v) / 2.0;
254  ury = lly + wh;
255  }
256  }
257 }
258 
260 {
261  calcAspectRatio(envelope->m_llx, envelope->m_lly, envelope->m_urx, envelope->m_ury, hAlign, vAlign);
262 }
263 
265 {
266  m_bgColor = QColor(static_cast<QRgb>(color.getRgba()));
267  m_bgColor.setAlpha(qAlpha(static_cast<QRgb>(color.getRgba())));
268 
269  m_painter->setWorldMatrixEnabled(false);
270  m_painter->fillRect(m_painter->viewport(), m_bgColor);
271  m_painter->setWorldMatrixEnabled(true);
272 }
273 
275 {
276  return te::color::RGBAColor(m_bgColor.red(), m_bgColor.green(), m_bgColor.blue(), m_bgColor.alpha());
277 }
278 
280 {
281  if (!m_painter || !m_painter->device())
282  return;
283 
284  int devType = m_painter->device()->devType();
285 
286  if(devType != QInternal::Image && devType != QInternal::Pixmap)
287  return;
288 
289  QPaintDevice* device = m_painter->device();
290 
291  if(device)
292  {
293  m_painter->end();
294  if(devType == QInternal::Image)
295  static_cast<QImage*>(device)->fill(m_bgColor.rgba());
296  else
297  static_cast<QPixmap*>(device)->fill(m_bgColor);
298  m_painter->begin(device);
299  }
300  m_painter->setMatrix(m_matrix);
301 
302  m_ptPen.setColor(m_ptColor);
303  QRectF rec(QPoint(0., 0.), QPoint(m_ptWidth, m_ptWidth));
304  rec = m_matrix.inverted().mapRect(rec);
305  m_ptPen.setWidthF(rec.width());
306 }
307 
309 {
310  int devType = m_painter->device()->devType();
311 
312  if(devType != QInternal::Image && devType != QInternal::Pixmap)
313  return;
314 
315  if(!m_isDeviceOwner)
316  return;
317 
318  if(devType == QInternal::Pixmap)
319  {
320  QPixmap* pixmap = static_cast<QPixmap*>(m_painter->device());
321  m_painter->end();
322  delete pixmap;
323  pixmap = new QPixmap(w, h);
324  pixmap->fill(m_bgColor);
325  m_painter->begin(pixmap);
326  }
327  else
328  {
329  QImage* image = static_cast<QImage*>(m_painter->device());
330  m_painter->end();
331  delete image;
332  image = new QImage(w, h, QImage::Format_ARGB32_Premultiplied);
333  image->fill(m_bgColor.rgba());
334  m_painter->begin(image);
335  }
336 }
337 
339 {
340  return m_painter->viewport().width();
341 }
342 
344 {
345  return m_painter->viewport().height();
346 }
347 
349 {
350  int geomType = static_cast<int>(geom->getGeomTypeId());
351  switch(geomType)
352  {
357  draw(static_cast<const te::gm::MultiPolygon*>(geom));
358  break;
359 
360  case te::gm::PointType:
361  case te::gm::PointZType:
362  case te::gm::PointMType:
363  case te::gm::PointZMType:
364  draw(static_cast<const te::gm::Point*>(geom));
365  break;
366 
371  draw(static_cast<const te::gm::LineString*>(geom));
372  break;
373 
374  case te::gm::PolygonType:
378  draw(static_cast<const te::gm::Polygon*>(geom));
379  break;
380 
385  draw(static_cast<const te::gm::MultiLineString*>(geom));
386  break;
387 
392  draw(static_cast<const te::gm::MultiPoint*>(geom));
393  break;
394 
399  draw(static_cast<const te::gm::GeometryCollection*>(geom));
400  break;
401 
406  draw(static_cast<const te::gm::MultiSurface*>(geom));
407  break;
408 
409  default:
410  break;
411  }
412 }
413 
415 {
416  m_pt.setX(point->getX());
417  m_pt.setY(point->getY());
418 
419  if(m_ptImg != nullptr)
420  {
421  QRectF rectf(0, 0, m_ptImg->width(), m_ptImg->height());
422  QPointF pc = m_matrix.map(m_pt);
423  pc.setX(pc.x() + m_ptHOffset);
424  pc.setY(pc.y() + m_ptVOffset);
425  rectf.moveCenter(pc);
426 
427  m_painter->setWorldMatrixEnabled(false);
429  m_painter->drawImage(rectf, *m_ptClearPatternImg);
430  else if(!m_erase && m_ptSelectionPatternImg)
431  m_painter->drawImage(rectf, *m_ptSelectionPatternImg);
432  m_painter->setWorldMatrixEnabled(true);
433  }
434  else
435  {
436  if(m_erase)
437  {
438  QPen p(m_ptPen);
439  p.setColor(Qt::black);
440  m_painter->setPen(p);
441  }
442  else
443  m_painter->setPen(m_ptPen);
444  m_painter->drawPoint(m_pt);
445  }
446 }
447 
449 {
450  std::size_t size = mpoint->getNumGeometries();
451 
452  for(std::size_t i = 0; i < size; ++i)
453  draw(static_cast<const te::gm::Point*>(mpoint->getGeometryN(i)));
454 }
455 
457 {
458  if(m_lnPen.brush().style() != Qt::TexturePattern)
459  {
460  const std::size_t nPoints = line->getNPoints();
461  QPolygonF qpol;
462 
463  int lastPointX = 0;
464  int lastPointY = 0;
465 
466  const te::gm::Coord2D* curCoordWorld = line->getCoordinates();
467 
468  int ddx, ddy;
469 
470  for (std::size_t t = 0; t < nPoints; ++t)
471  {
472  double curCoordX, curCoordY;
473  m_matrix.map(curCoordWorld[t].x, curCoordWorld[t].y, &curCoordX, &curCoordY);
474 
475  int intCurCoordX = qRound(curCoordX);
476  int intCurCoordY = qRound(curCoordY);
477 
478  ddx = intCurCoordX - lastPointX;
479  ddy = intCurCoordY - lastPointY;
480 
481  if (ddx != 0 || ddy != 0)
482  {
483  qpol << QPointF(curCoordWorld[t].x, curCoordWorld[t].y);
484 
485  lastPointX = intCurCoordX;
486  lastPointY = intCurCoordY;
487  }
488  }
489 
490  QPen pen(m_lnPen);
491  pen.setColor(m_lnColor);
492  m_painter->setPen(pen);
493  m_painter->setBrush(Qt::NoBrush);
494  m_painter->drawPolyline(qpol);
495  return;
496  }
497 
498  QPointF p1;
499  QPointF p2;
500  bool drawed = false;
501 
502  te::gm::Coord2D* coords = line->getCoordinates();
503  std::size_t size = line->getNPoints();
504 
505  p1.setX(coords[0].x);
506  p1.setY(coords[0].y);
507 
508  for(std::size_t i = 1; i != size; ++i)
509  {
510  p2.setX(coords[i].x);
511  p2.setY(coords[i].y);
512 
513  if(m_erase)
514  {
515  QPen pen(m_lnPen);
516  pen.setColor(Qt::red);
517  if(m_lnPen.brush().style() == Qt::TexturePattern)
518  pen.setCapStyle(Qt::FlatCap); // Qt::RoundCap Qt::FlatCap Qt::SquareCap
519  m_painter->setPen(pen);
520  m_painter->setBrush(Qt::NoBrush);
521  m_painter->drawLine(p1, p2);
522  drawed = true;
523  }
524  if(m_lnPen.brush().style() == Qt::TexturePattern)
525  {
526  int minPixels = 20; // dx and dy is greater than minPixels, then, draw the segment using pattern
527  double alfa;
528  QPoint dp1 = m_matrix.map(p1).toPoint();
529  QPoint dp2 = m_matrix.map(p2).toPoint();
530  int ddx = dp2.x() - dp1.x();
531  int ddy = dp2.y() - dp1.y();
532  if(abs(ddx) <= minPixels && abs(ddy) <= minPixels)
533  {
534  drawed = false;
535  continue;
536  }
537 
538  drawed = true;
539  double dx = p2.x() - p1.x();
540  double dy = p2.y() - p1.y();
541  double distance = sqrt((dx * dx) + (dy * dy));
542  double scale = m_lnPen.widthF() / m_lnPen.brush().textureImage().height();
543 
544  if(ddx == 0.)
545  {
546  if(p2.y() >= p1.y())
547  alfa = 90.;
548  else
549  alfa = 270.;
550  }
551  else if(ddy == 0.)
552  {
553  if(p2.x() >= p1.x())
554  alfa = 0.;
555  else
556  alfa = 180.;
557  }
558  else
559  {
560  alfa = atan(dy / dx) * 180. / 3.14159265;
561  if(dx < 0.)
562  alfa += 180.;
563  else if(alfa < 0 && dy < 0.)
564  alfa += 360.;
565  if(alfa == 360.)
566  alfa = 0.;
567  }
568 
569  QBrush brush(m_lnPen.brush());
570  QPen pen(m_lnPen);
571  pen.setCapStyle(Qt::FlatCap); // Qt::RoundCap Qt::FlatCap Qt::SquareCap
572  QMatrix matrix;
573  matrix.scale(scale, scale);
574  matrix.translate(m_lnPen.brush().textureImage().width() / 2, -m_lnPen.brush().textureImage().height() / 2.);
575  brush.setMatrix(matrix);
576  pen.setBrush(brush);
577  m_painter->setPen(pen);
578 
579  m_painter->save();
580  m_painter->translate(p1);
581  m_painter->rotate(alfa);
582  m_painter->drawLine(0., 0., static_cast<int>(distance), 0.);
583  if(m_lnColor.alpha() != 0)
584  {
585  pen.setBrush(Qt::NoBrush);
586  pen.setColor(m_lnColor);
587  m_painter->setPen(pen);
588  m_painter->drawLine(0., 0., static_cast<int>(distance), 0.);
589  }
590  m_painter->restore();
591  }
592  p1 = p2;
593  }
594  if(drawed == false)
595  {
596  double alfa;
597  QPoint dp1 = m_matrix.map(p1).toPoint();
598  QPoint dp2 = m_matrix.map(p2).toPoint();
599  int ddx = dp2.x() - dp1.x();
600  int ddy = dp2.y() - dp1.y();
601  double dx = p2.x() - p1.x();
602  double dy = p2.y() - p1.y();
603  double distance = sqrt((dx * dx) + (dy * dy));
604  double scale = m_lnPen.widthF() / m_lnPen.brush().textureImage().height();
605 
606  if(ddx == 0.)
607  {
608  if(p2.y() >= p1.y())
609  alfa = 90.;
610  else
611  alfa = 270.;
612  }
613  else if(ddy == 0.)
614  {
615  if(p2.x() >= p1.x())
616  alfa = 0.;
617  else
618  alfa = 180.;
619  }
620  else
621  {
622  alfa = atan(dy / dx) * 180. / 3.14159265;
623  if(dx < 0.)
624  alfa += 180.;
625  else if(alfa < 0 && dy < 0.)
626  alfa += 360.;
627  if(alfa == 360.)
628  alfa = 0.;
629  }
630 
631  QBrush brush(m_lnPen.brush());
632  QPen pen(m_lnPen);
633  pen.setCapStyle(Qt::FlatCap); // Qt::RoundCap Qt::FlatCap Qt::SquareCap
634  QMatrix matrix;
635  matrix.scale(scale, scale);
636  matrix.translate(m_lnPen.brush().textureImage().width() / 2, -m_lnPen.brush().textureImage().height() / 2.);
637  brush.setMatrix(matrix);
638  pen.setBrush(brush);
639  m_painter->setPen(pen);
640 
641  m_painter->save();
642  m_painter->translate(p1);
643  m_painter->rotate(alfa);
644  m_painter->drawLine(0., 0., static_cast<int>(distance), 0.);
645  if(m_lnColor.alpha() != 0)
646  {
647  pen.setBrush(Qt::NoBrush);
648  pen.setColor(m_lnColor);
649  m_painter->setPen(pen);
650  m_painter->drawLine(0., 0., static_cast<int>(distance), 0.);
651  }
652  m_painter->restore();
653  }
654 }
655 
657 {
658  std::size_t size = mline->getNumGeometries();
659 
660  for(size_t i = 0; i < size; ++i)
661  draw(static_cast<const te::gm::LineString*>(mline->getGeometryN(i)));
662 }
663 
665 {
666  const std::size_t nRings = poly->getNumRings();
667 
668  assert(nRings > 0);
669 
670  QPainterPath path;
671 
672  std::vector<te::gm::LinearRing*> rings;
673 
674  const te::gm::Envelope* envelope = poly->getMBR();
675 
676  double llX, llY;
677  m_matrix.map(envelope->getLowerLeftX(), envelope->getLowerLeftY(), &llX, &llY);
678 
679  double urX, urY;
680  m_matrix.map(envelope->getUpperRightX(), envelope->getUpperRightY(), &urX, &urY);
681 
682  int intLLX = qRound(llX);
683  int intLLY = qRound(llY);
684 
685  int intURX = qRound(urX);
686  int intURY = qRound(urY);
687 
688  int ddx, ddy;
689 
690  ddx = intURX - intLLX;
691 
692  if (ddx == 0)
693  {
694  ddy = intURY - intLLY;
695 
696  if (ddy == 0)
697  {
698  path.moveTo(envelope->getLowerLeftX(), envelope->getLowerLeftY());
699  path.lineTo(envelope->getUpperRightX(), envelope->getUpperRightY());
700  }
701  }
702 
703  if (path.isEmpty())
704  {
705  for(std::size_t i = 0; i < nRings; ++i)
706  {
707  te::gm::LinearRing* ring = static_cast<te::gm::LinearRing*>(poly->getRingN(i));
708  rings.push_back(ring);
709 
710  const std::size_t nPoints = ring->getNPoints();
711 
712  int lastPointX = 0;
713  int lastPointY = 0;
714 
715  const te::gm::Coord2D* curCoordWorld = ring->getCoordinates();
716 
717  for (std::size_t t = 0; t < nPoints; ++t)
718  {
719  double curCoordX, curCoordY;
720  m_matrix.map(curCoordWorld[t].x, curCoordWorld[t].y, &curCoordX, &curCoordY);
721 
722  int intCurCoordX = qRound(curCoordX);
723  int intCurCoordY = qRound(curCoordY);
724 
725  ddx = intCurCoordX - lastPointX;
726  ddy = intCurCoordY - lastPointY;
727 
728  if (ddx != 0 || ddy != 0)
729  {
730  if (t == 0)
731  path.moveTo(curCoordWorld[t].x, curCoordWorld[t].y);
732  else
733  path.lineTo(curCoordWorld[t].x, curCoordWorld[t].y);
734 
735  lastPointX = intCurCoordX;
736  lastPointY = intCurCoordY;
737  }
738  }
739  }
740  }
741 
742  if(m_erase)
743  {
744  m_painter->setPen(Qt::NoPen);
745  m_painter->setBrush(Qt::red);
746  m_painter->drawPath(path);
747  }
748  else
749  {
750  // fill polygon
751  m_painter->setPen(Qt::NoPen);
752  if(m_polyImage && m_polyColor.alpha() != 255)
753  {
754  const te::gm::Envelope* envelope = poly->getMBR();
755  QRectF recf(envelope->m_llx, envelope->m_lly, envelope->getWidth(), envelope->getHeight());
756  QPointF pc = m_matrix.map(recf.center());
757  int transx = pc.toPoint().x();
758  int transy = pc.toPoint().y();
759 
760  QMatrix matrix = m_matrix.inverted();
761  double scale = static_cast<double>(m_polyPatternWidth) / static_cast<double>(m_polyImage->width());
762  matrix.scale(scale, scale);
764  {
765  transx = transx % m_polyRotatedImage->width();
766  transy = transy % m_polyRotatedImage->height();
767  matrix.translate(transx, transy);
768  m_polyBrush.setMatrix(matrix);
769  m_polyBrush.setTextureImage(*m_polyRotatedImage);
770  }
771  else
772  {
773  transx = transx % m_polyImage->width();
774  transy = transy % m_polyImage->height();
775  matrix.translate(transx, transy);
776  m_polyBrush.setMatrix(matrix);
777  m_polyBrush.setTextureImage(*m_polyImage);
778  }
779 
780  m_painter->setBrush(m_polyBrush);
781 
782  if(m_polyContourPen.brush().style() == Qt::TexturePattern)
783  m_painter->setPen(Qt::NoPen);
784  else
785  m_painter->setPen(m_polyContourPen);
786 
787  m_painter->drawPath(path);
788  }
789 
790  m_polyDefaultBrush.setMatrix(this->getMatrix().inverted());
791  m_painter->setBrush(m_polyDefaultBrush);
792 
793  if(m_polyContourPen.brush().style() == Qt::TexturePattern)
794  m_painter->setPen(Qt::NoPen);
795  else
796  m_painter->setPen(m_polyContourPen);
797 
798  m_painter->drawPath(path);
799 
800  // draw contour
801  if(m_polyContourPen.brush().style() == Qt::TexturePattern)
802  {
803  std::vector<te::gm::LinearRing*>::iterator it;
804  for(it = rings.begin(); it != rings.end(); ++it)
805  drawContour(*it);
806  }
807  }
808 }
809 
811 {
812  te::gm::Coord2D* coords = line->getCoordinates();
813  std::size_t size = line->getNPoints();
814  if(size <= 1)
815  return;
816 
817  bool drawed = false;
818 
820  m_painter->setPen(m_polyContourPen);
821  m_painter->setBrush(Qt::NoBrush);
822 
823  QPointF p1(coords[0].x, coords[0].y);
824  QPointF p2;
825 
826  for(std::size_t i = 1; i != size; ++i)
827  {
828  p2.setX(coords[i].x);
829  p2.setY(coords[i].y);
830 
831  if(m_polyContourPen.brush().style() != Qt::TexturePattern)
832  {
833  drawed = true;
834  m_painter->drawLine(p1, p2);
835  }
836  else
837  {
838  double alfa, beta;
839  QPointF pf1, pf2;
840  QPoint dp1 = m_matrix.map(p1).toPoint();
841  QPoint dp2 = m_matrix.map(p2).toPoint();
842  int ddx = dp2.x() - dp1.x();
843  int ddy = dp2.y() - dp1.y();
844  if(ddx == 0 && ddy == 0)
845  {
846  drawed = false;
847  continue;
848  }
849 
850  drawed = true;
851  double dx = p2.x() - p1.x();
852  double dy = p2.y() - p1.y();
853  double distance = sqrt((dx * dx) + (dy * dy));
854  double scale = m_polyContourPen.widthF() / m_polyContourPen.brush().textureImage().height();
855 
856  if(ddx == 0.)
857  {
858  if(p2.y() >= p1.y())
859  alfa = 90.;
860  else
861  alfa = 270.;
862  }
863  else if(ddy == 0.)
864  {
865  if(p2.x() >= p1.x())
866  alfa = 0.;
867  else
868  alfa = 180.;
869  }
870  else
871  {
872  alfa = atan(dy / dx) * 180. / 3.14159265;
873  if(dx < 0.)
874  alfa += 180.;
875  else if(alfa < 0 && dy < 0.)
876  alfa += 360.;
877  if(alfa == 360.)
878  alfa = 0.;
879  }
880 
881  if(alfa > 90. && alfa <= 270.)
882  {
883  pf1 = p2;
884  pf2 = p1;
885  beta = alfa + 180.;
886  if(beta > 360.)
887  beta -= 360.;
888  if(beta == 360.)
889  beta = 0.;
890  }
891  else
892  {
893  pf1 = p1;
894  pf2 = p2;
895  beta = alfa;
896  }
897 
898  QBrush brush(m_polyContourPen.brush());
899  QPen pen(m_polyContourPen);
900  pen.setCapStyle(Qt::FlatCap); // Qt::RoundCap Qt::FlatCap Qt::SquareCap
901  QMatrix matrix;
902  matrix.scale(scale, scale);
903  matrix.translate(m_polyContourPen.brush().textureImage().width() / 2, -m_polyContourPen.brush().textureImage().height() / 2.);
904  brush.setMatrix(matrix);
905  pen.setBrush(brush);
906  m_painter->setPen(pen);
907 
908  m_painter->save();
909  m_painter->translate(pf1);
910  m_painter->rotate(beta);
911  m_painter->drawLine(0., 0., static_cast<int>(distance), 0.);
912  if(m_polyContourColor.alpha() != 0)
913  {
914  pen.setBrush(Qt::NoBrush);
915  pen.setColor(m_polyContourColor);
916  m_painter->setPen(pen);
917  m_painter->drawLine(0., 0., static_cast<int>(distance), 0.);
918  }
919  m_painter->restore();
920  }
921  p1 = p2;
922  }
923  if(drawed == false)
924  {
925  double alfa, beta;
926  QPointF pf1, pf2;
927  QPoint dp1 = m_matrix.map(p1).toPoint();
928  QPoint dp2 = m_matrix.map(p2).toPoint();
929  int ddx = dp2.x() - dp1.x();
930  int ddy = dp2.y() - dp1.y();
931  double dx = p2.x() - p1.x();
932  double dy = p2.y() - p1.y();
933  double distance = sqrt((dx * dx) + (dy * dy));
934  double scale = m_polyContourPen.widthF() / m_polyContourPen.brush().textureImage().height();
935 
936  if(ddx == 0.)
937  {
938  if(p2.y() >= p1.y())
939  alfa = 90.;
940  else
941  alfa = 270.;
942  }
943  else if(ddy == 0.)
944  {
945  if(p2.x() >= p1.x())
946  alfa = 0.;
947  else
948  alfa = 180.;
949  }
950  else
951  {
952  alfa = atan(dy / dx) * 180. / 3.14159265;
953  if(dx < 0.)
954  alfa += 180.;
955  else if(alfa < 0 && dy < 0.)
956  alfa += 360.;
957  if(alfa == 360.)
958  alfa = 0.;
959  }
960 
961  if(alfa > 90. && alfa <= 270.)
962  {
963  pf1 = p2;
964  pf2 = p1;
965  beta = alfa + 180.;
966  if(beta > 360.)
967  beta -= 360.;
968  if(beta == 360.)
969  beta = 0.;
970  }
971  else
972  {
973  pf1 = p1;
974  pf2 = p2;
975  beta = alfa;
976  }
977 
978  QBrush brush(m_polyContourPen.brush());
979  QPen pen(m_polyContourPen);
980  pen.setCapStyle(Qt::FlatCap); // Qt::RoundCap Qt::FlatCap Qt::SquareCap
981  QMatrix matrix;
982  matrix.scale(scale, scale);
983  matrix.translate(m_polyContourPen.brush().textureImage().width() / 2, -m_polyContourPen.brush().textureImage().height() / 2.);
984  brush.setMatrix(matrix);
985  pen.setBrush(brush);
986  m_painter->setPen(pen);
987 
988  m_painter->save();
989  m_painter->translate(pf1);
990  m_painter->rotate(beta);
991  m_painter->drawLine(0., 0., static_cast<int>(distance), 0.);
992  if(m_polyContourColor.alpha() != 0)
993  {
994  pen.setBrush(Qt::NoBrush);
995  pen.setColor(m_polyContourColor);
996  m_painter->setPen(pen);
997  m_painter->drawLine(0., 0., static_cast<int>(distance), 0.);
998  }
999  m_painter->restore();
1000  }
1001 }
1002 
1004 {
1005  const std::size_t size = mpoly->getNumGeometries();
1006  for(std::size_t i = 0; i < size; ++i)
1007  draw(static_cast<te::gm::Polygon*>(mpoly->getGeometryN(i)));
1008 }
1009 
1011 {
1012  const std::size_t size = g->getNumGeometries();
1013  for(size_t i = 0; i < size; ++i)
1014  draw(g->getGeometryN(i));
1015 }
1016 
1018 {
1019  const std::size_t size = g->getNumGeometries();
1020  for(size_t i = 0; i < size; ++i)
1021  draw(g->getGeometryN(i));
1022 }
1023 
1024 void te::qt::widgets::Canvas::save(const char* fileName, te::map::ImageType t, int quality, int /*fg*/) const
1025 {
1026  int devType = m_painter->device()->devType();
1027 
1028  if(devType != QInternal::Image && devType != QInternal::Pixmap)
1029  return;
1030 
1031  static_cast<QPixmap*>(m_painter->device())->save(fileName, GetFormat(t), quality);
1032 }
1033 
1034 char* te::qt::widgets::Canvas::getImage(te::map::ImageType t, std::size_t& size, int quality, int /*fg*/) const
1035 {
1036  int devType = m_painter->device()->devType();
1037 
1038  if(devType != QInternal::Image && devType != QInternal::Pixmap)
1039  return nullptr;
1040 
1041  QByteArray bytes;
1042  QBuffer buffer(&bytes);
1043  buffer.open(QIODevice::WriteOnly);
1044 
1045  switch(t)
1046  {
1047  case te::map::PNG:
1048  static_cast<QPixmap*>(m_painter->device())->save(&buffer, Globals::sm_pngFmt);
1049  break;
1050 
1051  case te::map::JPEG:
1052  static_cast<QPixmap*>(m_painter->device())->save(&buffer, Globals::sm_jpegFmt, quality);
1053  break;
1054 
1055  case te::map::GIF:
1056  static_cast<QPixmap*>(m_painter->device())->save(&buffer, Globals::sm_gifFmt);
1057  break;
1058 
1059  case te::map::BMP:
1060  static_cast<QPixmap*>(m_painter->device())->save(&buffer, Globals::sm_bmpFmt);
1061  break;
1062 
1063  case te::map::XPM:
1064  static_cast<QPixmap*>(m_painter->device())->save(&buffer, Globals::sm_xpmFmt);
1065  break;
1066 
1067  case te::map::XBM:
1068  static_cast<QPixmap*>(m_painter->device())->save(&buffer, Globals::sm_xbmFmt);
1069  break;
1070 
1071  default:
1072  return nullptr;
1073  }
1074 
1075  int nbytes = bytes.size();
1076 
1077  char* result = new char[nbytes];
1078 
1079  memcpy(result, bytes.data(), static_cast<size_t>(nbytes));
1080 
1081  size = static_cast<size_t>(nbytes);
1082 
1083  return result;
1084 }
1085 
1086 te::color::RGBAColor** te::qt::widgets::Canvas::getImage(const int x, const int y, const int w, const int h) const
1087 {
1088  int devType = m_painter->device()->devType();
1089 
1090  if(devType != QInternal::Image && devType != QInternal::Pixmap)
1091  return nullptr;
1092 
1093  te::color::RGBAColor** colors = nullptr;
1094  QImage img;
1095  if(devType == QInternal::Pixmap)
1096  img = static_cast<QPixmap*>(m_painter->device())->toImage();
1097  else
1098  img = *(static_cast<QImage*>(m_painter->device()));
1099 
1100  if(x == 0 && y == 0 && w == 0 && y == 0)
1101  {
1102  int width = img.width();
1103  int height = img.height();
1104 
1105  colors = new te::color::RGBAColor*[height];
1106  for(int i = 0; i < height; ++i)
1107  {
1108  colors[i] = new te::color::RGBAColor[width];
1109 
1110  unsigned char* u = img.scanLine(i);
1111 
1112  for(int j = 0; j < width; ++j)
1113  {
1114  QRgb* qrgb = reinterpret_cast<QRgb*>(u + (j << 2));
1115  QRgb value = *qrgb;
1116  te::color::RGBAColor rgba(qRed(value), qGreen(value), qBlue(value), qAlpha(value));
1117  colors[i][j] = rgba;
1118  }
1119  }
1120  }
1121  else
1122  {
1123  img = img.copy(x, y, w, h);
1124 
1125  colors = new te::color::RGBAColor*[h];
1126  for(int i = 0; i < h; ++i)
1127  {
1128  colors[i] = new te::color::RGBAColor[w];
1129 
1130  unsigned char* u = img.scanLine(i);
1131 
1132  for(int j = 0; j < w; ++j)
1133  {
1134  QRgb* qrgba = reinterpret_cast<QRgb*>(u + (j << 2));
1135  QRgb value = *qrgba;
1136  te::color::RGBAColor rgba(qRed(value), qGreen(value), qBlue(value), qAlpha(value));
1137  colors[i][j] = rgba;
1138  }
1139  }
1140  }
1141 
1142  return colors;
1143 }
1144 
1146 {
1147  delete[] img;
1148 }
1149 
1150 void te::qt::widgets::Canvas::drawImage(char* src, std::size_t size, te::map::ImageType t)
1151 {
1152  drawImage(0, 0, src, size, t);
1153 }
1154 
1156 {
1157  drawImage(0, 0, src, w, h);
1158 }
1159 
1160 void te::qt::widgets::Canvas::drawImage(int x, int y, char* src, std::size_t size, te::map::ImageType t)
1161 {
1162  QPixmap pix;
1163 
1164  const char* f = GetFormat(t);
1165  pix.loadFromData(reinterpret_cast<unsigned char*>(src), static_cast<uint>(size), f);
1166 
1167  m_painter->setWorldMatrixEnabled(false);
1168  m_painter->drawPixmap(x, y, pix);
1169  m_painter->setWorldMatrixEnabled(true);
1170 }
1171 
1172 void te::qt::widgets::Canvas::drawImage(int x, int y, te::color::RGBAColor** src, int w, int h)
1173 {
1174  QImage img(w, h, QImage::Format_ARGB32);
1175 
1176  for(int l = 0; l < h; ++l)
1177  {
1178  for(int c = 0; c < w; ++c)
1179  {
1180  QRgb val = qRgba(src[l][c].getRed(), src[l][c].getGreen(), src[l][c].getBlue(), src[l][c].getAlpha());
1181 
1182  img.setPixel(c, l, val);
1183  }
1184  }
1185 
1186  m_painter->setWorldMatrixEnabled(false);
1187  m_painter->drawImage(x, y, img);
1188  m_painter->setWorldMatrixEnabled(true);
1189 }
1190 
1191 void te::qt::widgets::Canvas::drawImage(int x, int y, int w, int h, char* src, std::size_t size, te::map::ImageType t)
1192 {
1193  QPixmap pix;
1194 
1195  const char* f = GetFormat(t);
1196  pix.loadFromData(reinterpret_cast<unsigned char*>(src), static_cast<uint>(size), f);
1197 
1198  m_painter->setWorldMatrixEnabled(false);
1199  m_painter->drawPixmap(x, y, w, h, pix);
1200  m_painter->setWorldMatrixEnabled(true);
1201 }
1202 
1203 void te::qt::widgets::Canvas::drawImage(int x, int y, int w, int h, te::color::RGBAColor** src, int srcw, int srch)
1204 {
1205  QImage img(srcw, srch, QImage::Format_RGB32);
1206 
1207  for(int l = 0; l < srch; ++l)
1208  for(int c = 0; c < srcw; ++c)
1209  img.setPixel(c, l, static_cast<uint>(src[l][c].getRgba()));
1210 
1211  m_painter->setWorldMatrixEnabled(false);
1212  m_painter->drawImage(QRect(x, y, w, h), img, QRect(0, 0, srcw, srch));
1213  m_painter->setWorldMatrixEnabled(true);
1214 }
1215 
1216 void te::qt::widgets::Canvas::drawImage(int x, int y, int w, int h, char* src, std::size_t size, te::map::ImageType t, int sx, int sy, int sw, int sh)
1217 {
1218  QPixmap pix;
1219 
1220  const char* f = GetFormat(t);
1221  pix.loadFromData(reinterpret_cast<unsigned char*>(src), static_cast<uint>(size), f);
1222 
1223  m_painter->setWorldMatrixEnabled(false);
1224  m_painter->drawPixmap(x, y, w, h, pix, sx, sy, sw, sh);
1225  m_painter->setWorldMatrixEnabled(true);
1226 }
1227 
1228 void te::qt::widgets::Canvas::drawImage(int x, int y, int w, int h, te::color::RGBAColor** src, int sx, int sy, int sw, int sh)
1229 {
1230  QImage img(sw, sh, QImage::Format_RGB32);
1231 
1232  int ssh = sy + sh;
1233  int ssw = sx + sw;
1234 
1235  for(int l = sy, li = 0; l < ssh; ++l, ++li)
1236  for(int c = sx, ci = 0; c < ssw; ++c, ++ci)
1237  img.setPixel(ci, li, static_cast<uint>(src[l][c].getRgba()));
1238 
1239  m_painter->setWorldMatrixEnabled(false);
1240  m_painter->drawImage(QRect(x, y, w, h), img, QRect(0, 0, sw, sh));
1241  m_painter->setWorldMatrixEnabled(true);
1242 }
1243 
1244 void te::qt::widgets::Canvas::drawImage(int x, int y, te::rst::Raster* src, int opacity)
1245 {
1246  int sw = static_cast<int>(src->getNumberOfColumns());
1247  int sh = static_cast<int>(src->getNumberOfRows());
1248 
1249  drawImage(x, y, sw, sh, src, 0, 0, sw, sh, opacity);
1250 }
1251 
1252 void te::qt::widgets::Canvas::drawImage(int x, int y, int w, int h, te::rst::Raster* src, int sx, int sy, int sw, int sh, int opacity)
1253 {
1254  // Defines QImage size
1255  int iw = std::min(sw, w);
1256  int ih = std::min(sh, h);
1257 
1258  QImage img(iw, ih, QImage::Format_ARGB32);
1259  double pr, pg, pb;
1260  te::color::RGBAColor* pixel;
1261 
1262  // Checks if undersampling is needed
1263  double sl = std::max(1.0, sh / static_cast<double>(h));
1264  double sr = std::max(1.0, sw / static_cast<double>(w));
1265 
1266  int l, r;
1267  double dl = sy;
1268  for(int li = 0; li < ih; dl += sl, ++li)
1269  {
1270  double dr = sx;
1271  for(int ri = 0; ri < iw; dr += sr, ++ri)
1272  {
1273  r = static_cast<int> (dr);
1274  l = static_cast<int> (dl);
1275  src->getValue(static_cast<unsigned int>(r), static_cast<unsigned int>(l), pr, 0);
1276  src->getValue(static_cast<unsigned int>(r), static_cast<unsigned int>(l), pg, 1);
1277  src->getValue(static_cast<unsigned int>(r), static_cast<unsigned int>(l), pb, 2);
1278 
1279  pixel = new te::color::RGBAColor(static_cast<int>(pr), static_cast<int>(pg), static_cast<int>(pb), opacity);
1280  QRgb val = qRgba(pixel->getRed(), pixel->getGreen(), pixel->getBlue(), pixel->getAlpha());
1281 
1282  img.setPixel(ri, li, val);
1283 
1284  delete pixel;
1285  }
1286  }
1287 
1288  m_painter->setWorldMatrixEnabled(false);
1289  m_painter->drawImage(QRect(x, y, w, h), img, QRect(0, 0, iw, ih));
1290  m_painter->setWorldMatrixEnabled(true);
1291 }
1292 
1294 {
1295  m_painter->setWorldMatrixEnabled(false);
1296  m_painter->drawPoint(x, y);
1297  m_painter->setWorldMatrixEnabled(true);
1298 }
1299 
1301 {
1302  QColor c(static_cast<QRgb>(color.getRgba()));
1303  c.setAlpha(qAlpha(static_cast<QRgb>(color.getRgba())));
1304 
1305  m_painter->setPen(c);
1306 
1307  m_painter->setWorldMatrixEnabled(false);
1308  m_painter->drawPoint(x, y);
1309  m_painter->setWorldMatrixEnabled(true);
1310 }
1311 
1313  const std::string& txt,
1314  float angle,
1315  double anchorX, double anchorY,
1316  int displacementX, int displacementY)
1317 {
1318  QPoint p(x, y);
1319  drawText(p, txt, angle, anchorX, anchorY, displacementX, displacementY);
1320 }
1321 
1323  const std::string& txt,
1324  float angle,
1325  double anchorX, double anchorY,
1326  int displacementX, int displacementY)
1327 {
1328  drawText(p->getX(), p->getY(), txt, angle, anchorX, anchorY, displacementX, displacementY);
1329 }
1330 
1331 void te::qt::widgets::Canvas::drawText(const double& x, const double& y,
1332  const std::string& txt,
1333  float angle,
1334  double anchorX, double anchorY,
1335  int displacementX, int displacementY)
1336 {
1337  QPointF pf(x, y);
1338  pf = m_matrix.map(pf);
1339  QPoint p = pf.toPoint();
1340  drawText(p, txt, angle, anchorX, anchorY, displacementX, displacementY);
1341 }
1342 
1343 te::gm::Polygon* te::qt::widgets::Canvas::getTextBoundary(int x, int y, const std::string& txt, float angle, double anchorX, double anchorY, int displacementX, int displacementY)
1344 {
1345  QPoint p(x, y);
1346  return getTextBoundary(p, txt, angle, anchorX, anchorY, displacementX, displacementY);
1347 }
1348 
1349 te::gm::Polygon* te::qt::widgets::Canvas::getTextBoundary(const te::gm::Point* p, const std::string& txt, float angle, double anchorX, double anchorY, int displacementX, int displacementY)
1350 {
1351  return getTextBoundary(p->getX(), p->getY(), txt, angle, anchorX, anchorY, displacementX, displacementY);
1352 }
1353 
1354 te::gm::Polygon* te::qt::widgets::Canvas::getTextBoundary(const double& x, const double& y, const std::string& txt, float angle, double anchorX, double anchorY, int displacementX, int displacementY)
1355 {
1356  QPointF pf(x, y);
1357  pf = m_matrix.map(pf);
1358  QPoint p = pf.toPoint();
1359  return getTextBoundary(p, txt, angle, anchorX, anchorY, displacementX, displacementY);
1360 }
1361 
1363 {
1364  m_txtBrush.setStyle(Qt::SolidPattern);
1365  QColor cor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
1366  m_txtBrush.setColor(cor);
1367 }
1368 
1370 {
1371  QColor cor(m_txtBrush.color().red(), m_txtBrush.color().green(), m_txtBrush.color().blue(), opacity);
1372  m_txtBrush.setColor(cor);
1373 }
1374 
1375 void te::qt::widgets::Canvas::setFontFamily(const std::string& family)
1376 {
1377  m_font.setFamily(family.c_str());
1378 }
1379 
1381 {
1382  double resolution = 0.0;
1383 
1384  if(m_painter->device()->devType() == QInternal::Printer)
1385  resolution = static_cast<QPrinter*>(m_painter->device())->resolution();
1386  else
1387  resolution = m_painter->device()->logicalDpiY();
1388 
1389  double PointSize = psize * resolution / 72.0;
1390 
1391  m_font.setPointSizeF(PointSize);
1392 }
1393 
1395 {
1396  m_font.setStyle(static_cast<QFont::Style>(style));
1397 }
1398 
1400 {
1401  m_font.setWeight(static_cast<QFont::Weight>(weight));
1402 }
1403 
1405 {
1406  m_font.setStretch(static_cast<int>(stretch));
1407 }
1408 
1410 {
1411  m_font.setUnderline(b);
1412 }
1413 
1415 {
1416  m_font.setOverline(b);
1417 }
1418 
1420 {
1421  m_font.setStrikeOut(b);
1422 }
1423 
1425 {
1426 }
1427 
1429 {
1430 }
1431 
1433 {
1434  QColor cor(static_cast<QRgb>(color.getRgba()));
1435  cor.setAlpha(qAlpha(static_cast<QRgb>(color.getRgba())));
1436  m_txtContourPen.setColor(cor);
1437 }
1438 
1440 {
1442 }
1443 
1445 {
1446  QColor cor(m_txtContourPen.color().red(), m_txtContourPen.color().green(), m_txtContourPen.color().blue(), opacity);
1447  m_txtContourPen.setColor(cor);
1448 }
1449 
1451 {
1452  m_txtContourPen.setWidth(width);
1453 }
1454 
1456 {
1457 }
1458 
1460 {
1461  m_txtLineSpacing = spacing;
1462 }
1463 
1465 {
1466  QColor cor(static_cast<QRgb>(color.getRgba()));
1467  cor.setAlpha(qAlpha(static_cast<QRgb>(color.getRgba())));
1468  if(m_ptColor == cor)
1469  return;
1470 
1471  m_ptColor = cor;
1472  m_ptPen.setColor(m_ptColor);
1473 
1474  if(m_ptColorFrom != m_ptColor && m_ptImg)
1476 }
1477 
1479 {
1480  if(w == m_ptWidth)
1481  return;
1482 
1483  m_ptWidth = w;
1484  QRectF rec(QPoint(0., 0.), QPoint(m_ptWidth, m_ptWidth));
1485  rec = m_matrix.inverted().mapRect(rec);
1486  m_ptPen.setWidthF(rec.width());
1487 
1488  if(m_ptImg)
1489  {
1490  double scale = static_cast<double>(m_ptWidth) / static_cast<double>(m_ptImg->width());
1491  int h = static_cast<int>(m_ptImg->height() * scale);
1492  QImage* ima = new QImage(m_ptImg->scaled(m_ptWidth, h));
1493  delete m_ptImg;
1494  m_ptImg = ima;
1495  }
1497 }
1498 
1500 {
1501  delete m_ptImg;
1502  m_ptImg = nullptr;
1503 
1504  if(pattern == nullptr || ncols == 0 || nrows == 0)
1505  return;
1506 
1507  m_ptImg = GetImage(pattern, ncols, nrows);
1508  int width = m_ptImg->width();
1509  m_ptWidth = width;
1510 
1512 }
1513 
1514 void te::qt::widgets::Canvas::setPointPattern(char* pattern, std::size_t size, te::map::ImageType t)
1515 {
1516  delete m_ptImg;
1517  m_ptImg = nullptr;
1518 
1519  if(pattern == nullptr || size == 0)
1520  return;
1521 
1522  m_ptImg = new QImage();
1523 
1524  const char* format = te::qt::widgets::GetFormat(t);
1525 
1526  if(m_ptImg->loadFromData(reinterpret_cast<const uchar*>(pattern), static_cast<int>(size), format) == false)
1527  {
1528  delete m_ptImg;
1529  m_ptImg = nullptr;
1530  return;
1531  }
1532 
1533  int width = m_ptImg->width();
1534  m_ptWidth = width;
1535 
1537 }
1538 
1540 {
1541  m_ptRotation = angle;
1543 }
1544 
1546 {
1547  if(m_ptImg == nullptr)
1548  return;
1549 
1550  updateAlpha(*m_ptImg, opacity);
1552 }
1553 
1555 {
1556  QColor cor(static_cast<QRgb>(color.getRgba()));
1557  cor.setAlpha(qAlpha(static_cast<QRgb>(color.getRgba())));
1558 
1559  m_lnColor = cor;
1560 }
1561 
1563 {
1564  if(pattern == nullptr)
1565  {
1566  m_lnPen.setBrush(Qt::NoBrush);
1567  return;
1568  }
1569 
1570  QImage* img = GetImage(pattern, ncols, nrows);
1571 
1572  if(img->isNull() == false)
1573  {
1574  QBrush brush;
1575  brush.setTextureImage(*img);
1576  m_lnPen.setBrush(brush);
1577  }
1578  delete img;
1579 }
1580 
1581 void te::qt::widgets::Canvas::setLinePattern(char* pattern, std::size_t size, te::map::ImageType t)
1582 {
1583  if(pattern == nullptr)
1584  {
1585  m_lnPen.setBrush(Qt::NoBrush);
1586  return;
1587  }
1588 
1589  QImage img;
1590 
1591  const char* format = te::qt::widgets::GetFormat(t);
1592 
1593  bool result = img.loadFromData(reinterpret_cast<const uchar*>(pattern), static_cast<int>(size), format);
1594 
1595  if(result && img.isNull() == false)
1596  {
1597  QBrush brush;
1598  brush.setTextureImage(img);
1599  m_lnPen.setBrush(brush);
1600  }
1601 }
1602 
1604 {
1605  QBrush brush = m_lnPen.brush();
1606  QImage img = brush.textureImage();
1607  if(img.isNull())
1608  return;
1609 
1610  QMatrix matrix;
1611  matrix.translate(img.width() / 2, img.height() / 2);
1612  matrix.rotate(angle);
1613  QImage imgRot = img.transformed(matrix);
1614 
1615  brush.setTextureImage(imgRot);
1616  m_lnPen.setBrush(brush);
1617 }
1618 
1620 {
1621  QBrush brush = m_lnPen.brush();
1622  QImage img = brush.textureImage();
1623  if(img.isNull())
1624  return;
1625 
1626  // Updates the alpha channel
1627  updateAlpha(img, opacity);
1628 
1629  brush.setTextureImage(img);
1630  m_lnPen.setBrush(brush);
1631 }
1632 
1634 {
1635  m_lnPen.setStyle(static_cast<Qt::PenStyle>(style));
1636 }
1637 
1638 void te::qt::widgets::Canvas::setLineDashStyle(const std::vector<double>& style)
1639 {
1640  setLineDashStyle(m_lnPen, style);
1641 }
1642 
1644 {
1645  m_lnPen.setCapStyle(static_cast<Qt::PenCapStyle>(style));
1646 }
1647 
1649 {
1650  m_lnPen.setJoinStyle(static_cast<Qt::PenJoinStyle>(style));
1651 }
1652 
1654 {
1655  QRectF rec(QPoint(0., 0.), QPoint(w, w));
1656  rec = m_matrix.inverted().mapRect(rec);
1657  m_lnPen.setWidthF(rec.width());
1658 }
1659 
1661 {
1662  QColor cor(static_cast<QRgb>(color.getRgba()));
1663  cor.setAlpha(qAlpha(static_cast<QRgb>(color.getRgba())));
1664 
1665  QBrush b(cor, Qt::SolidPattern);
1666 
1668 }
1669 
1671 {
1672  m_polyDefaultBrush = color;
1673  m_polyColor = color.color();
1674 }
1675 
1676 
1678 {
1679  if(pattern == nullptr)
1680  {
1681  m_polyBrush.setStyle(Qt::NoBrush);
1682  delete m_polyImage;
1683  delete m_polyRotatedImage;
1684  m_polyImage = nullptr;
1685  m_polyRotatedImage = nullptr;
1686  return;
1687  }
1688 
1689  if(m_polyImage)
1690  delete m_polyImage;
1691 
1692  m_polyImage = GetImage(pattern, ncols, nrows);
1693  if(m_polyImage->isNull())
1694  {
1695  delete m_polyImage;
1696  m_polyImage = nullptr;
1697  }
1698  m_polyPatternWidth = m_polyImage->width();
1699 }
1700 
1702 {
1703  if(pattern == nullptr)
1704  {
1705  m_polyBrush.setStyle(Qt::NoBrush);
1706  delete m_polyImage;
1707  delete m_polyRotatedImage;
1708  m_polyImage = nullptr;
1709  m_polyRotatedImage = nullptr;
1710  return;
1711  }
1712  delete m_polyImage;
1713 
1714  m_polyImage = new QImage();
1715  const char* format = te::qt::widgets::GetFormat(t);
1716  bool result = m_polyImage->loadFromData(reinterpret_cast<const uchar*>(pattern), static_cast<int>(size), format);
1717  if(result == false)
1718  {
1719  delete m_polyImage;
1720  m_polyImage = nullptr;
1721  }
1722 }
1723 
1725 {
1726  m_polyPatternWidth = w;
1727 
1728  if(m_polyPatternWidth == 0.)
1729  m_polyPatternWidth = 1.;
1730 }
1731 
1733 {
1734  if(m_polyImage)
1735  {
1736  QMatrix matrix;
1737  matrix.translate(static_cast<double>(m_polyImage->width()) / 2., static_cast<double>(m_polyImage->height()) / 2.);
1738  matrix.rotate(angle);
1739 
1740  if(m_polyRotatedImage == nullptr)
1741  m_polyRotatedImage = new QImage();
1742  *m_polyRotatedImage = m_polyImage->transformed(matrix);
1743  }
1744 }
1745 
1747 {
1748  QImage img = m_polyBrush.textureImage();
1749  if(img.isNull())
1750  return;
1751 
1752  // Updates the alpha channel
1753  if(m_polyImage)
1754  updateAlpha(*m_polyImage, opacity);
1755  if(m_polyRotatedImage)
1756  updateAlpha(*m_polyRotatedImage, opacity);
1757 }
1758 
1760 {
1761  QColor cor(static_cast<QRgb>(color.getRgba()));
1762  cor.setAlpha(static_cast<int>(qAlpha(static_cast<QRgb>(color.getRgba()))));
1763 
1764  m_polyContourPen.setColor(cor);
1765  m_polyContourColor = cor;
1766 }
1767 
1769 {
1770  if(pattern == nullptr)
1771  {
1772  m_polyContourPen.setBrush(Qt::NoBrush);
1773  return;
1774  }
1775 
1776  QImage* img = GetImage(pattern, ncols, nrows);
1777 
1778  if(img->isNull() == false)
1779  {
1780  QBrush brush;
1781  brush.setTextureImage(*img);
1782  m_polyContourPen.setBrush(brush);
1783  }
1784  delete img;
1785 }
1786 
1788 {
1789  if(pattern == nullptr)
1790  {
1791  m_polyContourPen.setBrush(Qt::NoBrush);
1792  return;
1793  }
1794 
1795  QImage img;
1796 
1797  const char* format = te::qt::widgets::GetFormat(t);
1798 
1799  bool result = img.loadFromData(reinterpret_cast<const uchar*>(pattern), static_cast<int>(size), format);
1800 
1801  if(result && img.isNull() == false)
1802  {
1803  QBrush brush;
1804  brush.setTextureImage(img);
1805  m_polyContourPen.setBrush(brush);
1806  }
1807 }
1808 
1810 {
1811  QRectF rec(QPoint(0., 0.), QPoint(w, w));
1812  rec = m_matrix.inverted().mapRect(rec);
1813  m_polyContourPen.setWidthF(rec.width());
1814 }
1815 
1817 {
1818  QBrush brush = m_polyContourPen.brush();
1819  QImage img = brush.textureImage();
1820  if(img.isNull())
1821  return;
1822 
1823  QMatrix matrix;
1824  matrix.translate(img.width() / 2, img.height() / 2);
1825  matrix.rotate(angle);
1826  QImage imgRot = img.transformed(matrix);
1827 
1828  brush.setTextureImage(imgRot);
1829  m_polyContourPen.setBrush(brush);
1830 }
1831 
1833 {
1834  QBrush brush = m_polyContourPen.brush();
1835  QImage img = brush.textureImage();
1836  if(img.isNull())
1837  return;
1838 
1839  // Updates the alpha channel
1840  updateAlpha(img, opacity);
1841 
1842  brush.setTextureImage(img);
1843  m_polyContourPen.setBrush(brush);
1844 }
1845 
1847 {
1848  m_polyContourPen.setStyle(static_cast<Qt::PenStyle>(style));
1849 }
1850 
1851 void te::qt::widgets::Canvas::setPolygonContourDashStyle(const std::vector<double>& style)
1852 {
1854 }
1855 
1857 {
1858  m_polyContourPen.setCapStyle(static_cast<Qt::PenCapStyle>(style));
1859 }
1860 
1862 {
1863  m_polyContourPen.setJoinStyle(static_cast<Qt::PenJoinStyle>(style));
1864 }
1865 
1867  const std::string& txt,
1868  float angle,
1869  double anchorX, double anchorY,
1870  int displacementX, int displacementY)
1871 {
1872  if(txt.empty())
1873  return;
1874 
1875  m_painter->save();
1876  m_painter->setRenderHint(QPainter::Antialiasing, true);
1877 
1878  double ax, ay; // alignment position
1879  QString qtx(txt.c_str());
1880  QPainterPath path;
1881  QFontMetrics fm(m_font);
1882  QRectF rec(fm.boundingRect(qtx));
1883 
1884  path.addText(0, 0, m_font, qtx);
1885 
1886  ax = p.x() - path.boundingRect().width() * anchorX;
1887  ay = p.y() + path.boundingRect().height() * anchorY;
1888 
1889  m_painter->resetMatrix();
1890 
1891  if (angle != 0.)
1892  {
1893  double textWidth = path.boundingRect().width();
1894  double textHeight = path.boundingRect().height();
1895 
1896  path.translate(-textWidth / 2., textHeight / 2.);
1897 
1898  QTransform transform;
1899  transform.rotate(static_cast<qreal>(angle));
1900 
1901  path = transform.map(path);
1902 
1903  path.translate(textWidth / 2., -textHeight / 2.);
1904  }
1905 
1906  path.translate(ax + displacementX, ay - displacementY);
1907 
1909  {
1910  m_painter->setBrush(Qt::NoBrush);
1911  m_painter->setPen(m_txtContourPen);
1912  m_painter->drawPath(path);
1913  }
1914 
1915  m_painter->setPen(Qt::NoPen);
1916  m_painter->fillPath(path, m_txtBrush);
1917 
1918  m_painter->setMatrix(m_matrix);
1919 
1920  m_painter->restore();
1921 }
1922 
1923 te::gm::Polygon* te::qt::widgets::Canvas::getTextBoundary(const QPoint& p, const std::string& txt, float angle, double anchorX, double anchorY, int displacementX, int displacementY)
1924 {
1925  if(txt.empty())
1926  return nullptr;
1927 
1928  double ax, ay; // alignment position
1929  QString qtx(txt.c_str());
1930  QPainterPath path;
1931 
1932  path.addText(0, 0, m_font, qtx);
1933 
1934  ax = p.x() - path.boundingRect().width() * anchorX;
1935  ay = p.y() + path.boundingRect().height() * anchorY;
1936 
1937  if (angle != 0.)
1938  {
1939  double textWidth = path.boundingRect().width();
1940  double textHeight = path.boundingRect().height();
1941 
1942  path.translate(-textWidth / 2., textHeight / 2.);
1943 
1944  QTransform transform;
1945  transform.rotate(static_cast<qreal>(angle));
1946 
1947  path = transform.map(path);
1948 
1949  path.translate(textWidth / 2., -textHeight / 2.);
1950  }
1951 
1952  path.translate(ax + displacementX, ay - displacementY);
1953 
1954  path = m_matrix.inverted().map(path);
1955 
1956  QPolygonF polf(path.boundingRect());
1957 
1958  //converter QPolygon para te::gm::Polygon. Como fazer isso?
1961  poly->setRingN(0, lr);
1962  lr->setPoint(0, polf.at(0).x(), polf.at(0).y());
1963  lr->setPoint(1, polf.at(1).x(), polf.at(1).y());
1964  lr->setPoint(2, polf.at(2).x(), polf.at(2).y());
1965  lr->setPoint(3, polf.at(3).x(), polf.at(3).y());
1966  return poly;
1967 }
1968 
1970 {
1971  if(m_painter->device()->devType() == QInternal::Pixmap)
1972  return static_cast<QPixmap*>(m_painter->device());
1973  else
1974  return nullptr;
1975 }
1976 
1978 {
1979  if(m_painter->device()->devType() == QInternal::Image)
1980  return static_cast<QImage*>(m_painter->device());
1981  else
1982  return nullptr;
1983 }
1984 
1986 {
1987  return m_painter->device();
1988 }
1989 
1990 void te::qt::widgets::Canvas::setDevice(QPaintDevice* device, bool takeOwnerShip)
1991 {
1992  m_painter->end();
1993 
1994  if(m_isDeviceOwner)
1995  delete m_painter->device();
1996 
1997  m_isDeviceOwner = takeOwnerShip;
1998  m_painter->begin(device);
1999 }
2000 
2002 {
2003  if(m_painter->device()->devType() == QInternal::Printer)
2004  return static_cast<QPrinter*>(m_painter->device())->resolution();
2005  else
2006  return m_painter->device()->logicalDpiX();
2007 }
2008 
2010 {
2011  return m_matrix;
2012 }
2013 
2014 void te::qt::widgets::Canvas::setRenderHint(QPainter::RenderHint hint, bool on)
2015 {
2016  m_painter->setRenderHint(hint, on);
2017 }
2018 
2020 {
2021  return m_painter;
2022 }
2023 
2024 void te::qt::widgets::Canvas::setLineDashStyle(QPen& pen, const std::vector<double>& style)
2025 {
2026  assert(style.size() % 2 == 0);
2027  QVector<qreal> pattern;
2028  for(std::size_t i = 0; i < style.size(); ++i)
2029  pattern << style[i];
2030  pen.setDashPattern(pattern);
2031 }
2032 
2033 void te::qt::widgets::Canvas::updateAlpha(QImage& img, const int& opacity)
2034 {
2035  int o = opacity << 24;
2036  for(int i = 0; i < img.height(); ++i)
2037  {
2038  unsigned char* u = img.scanLine(i);
2039  for(int j = 0; j < img.width(); ++j)
2040  {
2041  QRgb* v = reinterpret_cast<QRgb*>(u + (j << 2));
2042  if(qAlpha(*v) <= opacity)
2043  continue;
2044  *v = *v & 0x00ffffff;
2045  *v = static_cast<unsigned int>(o) | *v;
2046  }
2047  }
2048 }
2049 
2051 {
2052  delete m_ptSelectionPatternImg;
2053  delete m_ptClearPatternImg;
2054  delete m_ptImgRotated;
2055  m_ptSelectionPatternImg = nullptr;
2056  m_ptClearPatternImg = nullptr;
2057  m_ptImgRotated = nullptr;
2058 
2059  if(m_ptImg == nullptr)
2060  return;
2061 
2062  QMatrix m;
2063  m.rotate(m_ptRotation);
2064  m_ptImgRotated = new QImage(m_ptImg->transformed(m));
2065 
2067 
2068  double a = static_cast<double>(m_ptColor.alpha()) / 255.;
2069  double b = static_cast<double>(255 - m_ptColor.alpha()) / 255.;
2070  int width = m_ptImgRotated->width();
2071  int height = m_ptImgRotated->height();
2072  m_ptSelectionPatternImg = new QImage(width, height, QImage::Format_ARGB32);
2073  m_ptClearPatternImg = new QImage(width, height, QImage::Format_ARGB32);
2074  for(int i = 0; i < height; ++i)
2075  {
2076  unsigned char* u = m_ptImgRotated->scanLine(i);
2077  unsigned char* uu = m_ptSelectionPatternImg->scanLine(i);
2078  unsigned char* uuu = m_ptClearPatternImg->scanLine(i);
2079  for(int j = 0; j < width; ++j)
2080  {
2081  QRgb* v = reinterpret_cast<QRgb*>(u + (j << 2));
2082  QRgb* vv = reinterpret_cast<QRgb*>(uu + (j << 2));
2083  QRgb* vvv = reinterpret_cast<QRgb*>(uuu + (j << 2));
2084  if(qAlpha(*v) == 0)
2085  {
2086  *vv = qRgba(0, 0, 0, 0);
2087  *vvv = qRgba(0, 0, 0, 0);
2088  }
2089  else
2090  {
2091  int red = static_cast<int>(static_cast<double>(m_ptColor.red()) * a + static_cast<double>(qRed(*v)) * b);
2092  int green = static_cast<int>(static_cast<double>(m_ptColor.green()) * a + static_cast<double>(qGreen(*v)) * b);
2093  int blue = static_cast<int>(static_cast<double>(m_ptColor.blue()) * a + static_cast<double>(qBlue(*v)) * b);
2094  *vv = qRgba(red, green, blue, qAlpha(*v));
2095  *vvv = qRgba(255, 255, 255, 255);
2096  }
2097  }
2098  }
2099 }
2100 
2102 {
2103  m_painter->setCompositionMode(QPainter::CompositionMode_DestinationOut);
2104  m_erase = true;
2105 }
2106 
2108 {
2109  m_painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
2110  m_erase = false;
2111 }
2112 
2113 void te::qt::widgets::Canvas::setMatrix(const QMatrix& matrix)
2114 {
2115  m_matrix = matrix;
2116 
2117  m_painter->setMatrix(m_matrix);
2118 }
void freeImage(char *img) const
This is the method that you should use to release an image generated by the canvas.
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
Definition: RGBAColor.h:327
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
Definition: CurvePolygon.h:153
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
ImageType
This enum specifies the possible input and output image formats supported by the canvas API...
void setPolygonContourDashStyle(te::map::LineDashStyle style)
It sets the polygon contour dash style.
A canvas built on top of Qt.
void updateAlpha(QImage &img, const int &opacity)
It updates the alpha channel of the given image using the given opacity value.
void setTextStrikeOut(bool b)
It sets the text strike out flag.
void clear()
It clears the canvas content and fills with the background color.
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
void setPointPatternOpacity(int opacity)
It sets the point pattern opacity.
void setDevice(QPaintDevice *device, bool takeOwnerShip)
It sets new device as QPrinter.
te::color::RGBAColor getBackgroundColor() const
It returns the canvas background color.
void setPolygonFillPattern(te::color::RGBAColor **pattern, int ncols, int nrows)
It sets the polygon fill pattern.
void setPolygonPatternWidth(int w)
It sets the polygon pattern width.
void drawText(int x, int y, const std::string &txt, float angle=0.0, double anchorX=0.5, double anchorY=0.5, int displacementX=0, int displacementY=0)
It draws a text.
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:307
void drawImage(char *src, std::size_t size, te::map::ImageType t)
It draws the src image over the canvas.
void drawPixel(int x, int y)
It sets a pixel using the point pen.
QMatrix m_matrix
Matrix that transforms the world coordinate to device coordinate.
Coord2D * getCoordinates() const
It returns a pointer to the internal array of coordinates.
Definition: LineString.h:456
static te::dt::Date dx(2010, 12, 31)
QColor m_bgColor
Canvas background color. Defaults: white fully transparent.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
void setTextContourOpacity(int opacity)
It sets the text contour opacity.
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:317
double m_urx
Upper right corner x-coordinate.
QImage * m_ptSelectionPatternImg
The marker or pattern used to show selection status. The color is mixed with point pattern...
void setPolygonFillColor(const te::color::RGBAColor &color)
It sets the color used to fill the draw of polygon geometries.
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:312
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.
int m_txtLineSpacing
Text multi line spacing.
QPointF m_pt
Point buffer to avoid creating another point instance.
void setTextDecorationColor(const te::color::RGBAColor &color)
It sets the text color for drawing text decoration.
void setLinePattern(te::color::RGBAColor **pattern, int ncols, int nrows)
It sets the line pattern.
QColor m_lnColor
The color used to draw lines.
void setPolygonContourColor(const te::color::RGBAColor &color)
It sets the pen color used to draw the boundary of polygon geometries.
QImage * m_ptClearPatternImg
The marker or pattern used to clear (erase point).
void setNormalMode()
It sets the painter to normal copy source to destination mode.
QColor m_polyColor
The color used to fill polygon (solid, marker or pattern).
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
void setTextOpacity(int opacity)
It sets the text opacity.
QBrush m_polyDefaultBrush
The brush used to fill polygon.
void setTextContourWidth(int width)
It sets the text contour width.
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
void setEraseMode()
It sets the painter to erase mode.
void createPointPatterns()
It creates two patterns. A pattern used to draw selected objects and the other used to erase this pat...
bool m_isDeviceOwner
Tells if canvas is the owner of the paint device.
double m_ptRotation
The point pattern rotation.
void setPointPatternRotation(const double &angle)
It sets the point pattern rotation. Rotation is made ​​from the center of the pattern.
void draw(const te::gm::Geometry *geom)
It draws the geometry on canvas.
QImage * m_polyImage
The pattern image used to fill polygon.
QImage * m_polyRotatedImage
The pattern rotated image used to fill polygon.
QMatrix getMatrix()
It returns the matrix.
unsigned int line
AlignType
This enum contains values to control the alignment of components (like Canvas and MapDisplay)...
QColor m_polyContourColor
The color used to draw polygon contour.
bool m_isPainterOwner
Tells if canvas is the owner of the painter.
LineCapStyle
This enum encodes enumerated values telling how line strings should be capped (at the two ends of the...
int b
Definition: TsRtree.cpp:32
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
void setFontFamily(const std::string &family)
It sets the text font family.
void setTextStretch(std::size_t stretch)
It sets the text stretch.
const char * GetFormat(te::map::ImageType t)
It returns the file format as a NULL terminated string.
void setPointWidth(int w)
It sets the point width. If point has a patterns, this pattern is scaled to width.
void setPolygonContourPatternRotation(const double &angle)
It sets the polygon contour pattern rotation.
void setRenderHint(QPainter::RenderHint hint, bool on=true)
Sets the given render hint on the canvas painter if on is true; otherwise clears the render hint...
void setWindow(const double &llx, const double &lly, const double &urx, const double &ury)
It sets the world (or window) coordinates area (supposing a cartesian reference system).
QBrush m_txtBrush
The brush used to draw texts.
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:50
double m_llx
Lower left corner x-coordinate.
QImage * getImage() const
It returns the internal image used to draw geographical objects.
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
QPaintDevice * getDevice() const
It returns the internal device used to draw geographical objects.
const double & getY() const
It returns the Point y-coordinate value.
Definition: Point.h:152
A point with x and y coordinate values.
Definition: Point.h:50
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
bool m_txtContourEnabled
The flag indicates whether the outline of the text should be drawn.
An Envelope defines a 2D rectangular region.
void setLineWidth(int w)
It sets the line width.
void setPointColor(const te::color::RGBAColor &color)
It sets the point drawing color.
An abstract class for raster data strucutures.
void calcAspectRatio(double &llx, double &lly, double &urx, double &ury, const te::map::AlignType hAlign=te::map::Center, const te::map::AlignType vAlign=te::map::Center)
It calculates the best aspect ratio for world (or window) coordinates area (supposing a cartesian ref...
unsigned int getNumberOfRows() const
Returns the raster number of rows.
void setLineColor(const te::color::RGBAColor &color)
It sets the pen color used to draw line geometries.
void resize(int w, int h)
It adjusts the canvas size (width and height).
void setTextStyle(te::se::Font::FontStyleType style)
It sets the text style.
void setTextContourColor(const te::color::RGBAColor &color)
It sets the text contour (outline) drawing color.
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
Definition: RGBAColor.h:322
void setPolygonContourWidth(int w)
It sets the polygon contour width.
te::gm::Polygon * getTextBoundary(int x, int y, const std::string &txt, float angle=0.0, double anchorX=0.5, double anchorY=0.5, int displacementX=0, int displacementY=0)
It returns the text boundary (its enclose rectangle).
int m_polyPatternWidth
The width used to draw marker or pattern.
void setTextDecorationWidth(int width)
It sets the width for drawing text decoration.
te::gm::Polygon * p
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
Definition: LineString.h:193
QColor m_ptColorFrom
Indicates the color that originated the pattern that shows the status of selection. Used for optmization.
QPen m_lnPen
The pen used to draw lines.
QPen m_polyContourPen
The pen used to draw contour polygon.
void setTextUnderline(bool b)
It sets the text underline flag.
FontStyleType
It defines the style to use for a font.
Definition: Font.h:72
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
void setTextWeight(te::se::Font::FontWeightType weight)
It sets the text weight.
void setLinePatternRotation(const double &angle)
It sets the line pattern rotation. Rotation is made ​​from the center of the pattern.
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
int m_ptVOffset
Vertical offset in pixels (in device coordinate) applied to point pattern or marker.
double m_lly
Lower left corner y-coordinate.
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
QTransform m_painterTransform
This transform holds the original transform of the painter. It is stored to be combined to the canvas...
int getWidth() const
It returns the canvas width.
void setLineCapStyle(te::map::LineCapStyle style)
It sets the line cap style.
MultiLineString is a MultiCurve whose elements are LineStrings.
void setTextOverline(bool b)
It sets the text overline flag.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
LineDashStyle
This enum encodes enumerated values telling how lines should be drawn. e.g. as a plain line or dash l...
LineJoinStyle
This enum encodes enumerated values telling how line strings should be joined (between line segments)...
QPixmap * getPixmap() const
It returns the internal pixmap used to draw geographical objects.
void setPolygonContourCapStyle(te::map::LineCapStyle style)
It sets the polygon contour cap style.
void setTextJustification(int justType)
It sets the text justification for multi line text.
MultiSurface is a class that represents a 2-dimensional GeometryCollection whose elements are surface...
Definition: MultiSurface.h:54
void setTextMultiLineSpacing(int spacing)
It sets the multi line text spacing.
TEQTWIDGETSEXPORT QImage * GetImage(te::color::RGBAColor **img, int width, int height)
It creates a QImage from an RGBA color array.
double m_ury
Upper right corner y-coordinate.
QPen m_ptPen
The pen used to draw points.
int m_ptHOffset
Horizontal offset in pixels (in device coordinate) applied to point pattern or marker.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
void setLinePatternOpacity(int opacity)
It sets the line pattern opacity.
void setPointPattern(te::color::RGBAColor **pattern, int ncols, int nrows)
It sets the point pattern.
int getHeight() const
It returns the canvas height.
void setPolygonContourPattern(te::color::RGBAColor **pattern, int ncols, int nrows)
It sets the pen pattern used to draw the boundary of polygon geometries.
QBrush m_polyBrush
The brush used to fill polygon.
QImage * m_ptImg
The marker or pattern used to point.
int m_ptWidth
The width for point markers and point pattern.
void setTextContourEnabled(bool b)
It controls the display of the text outline.
QImage * m_ptImgRotated
The marker or pattern already with rotation used to draw points.
void setPolygonContourJoinStyle(te::map::LineJoinStyle style)
It sets the polygon contour join style.
void setPolygonPatternRotation(const double &angle)
It sets the polygon pattern rotation.
void save(const char *fileName, te::map::ImageType t, int quality=75, int fg=0) const
It saves the canvas content to a file image in the specified format type.
QPainter * m_painter
The painter used to draw geometric objects.
FontWeightType
It gives the amount of weight or boldness to use for a font.
Definition: Font.h:84
It is a collection of other geometric objects.
void setLineJoinStyle(te::map::LineJoinStyle style)
It sets the line join style.
void drawContour(const te::gm::LineString *line)
It draw the polygon contour.
void setLineDashStyle(te::map::LineDashStyle style)
It sets the line dash style.
void setTextColor(const te::color::RGBAColor &color)
It sets the text drawing color.
double getHeight() const
It returns the envelope height.
const double & getX() const
It returns the Point x-coordinate value.
Definition: Point.h:138
void setTextPointSize(double psize)
It sets the text point Size.
void setBackgroundColor(const te::color::RGBAColor &color)
It sets the canvas background color.
QPen m_txtContourPen
The pen used to draw the text contour.
void setPolygonPatternOpacity(int opacity)
It sets the polygon pattern opacity.
bool m_erase
used for erase operation.
Curve * getRingN(std::size_t i) const
It returns the n-th ring for this curve polygon as a curve.
Definition: CurvePolygon.h:193
void setRingN(std::size_t i, Curve *r)
It sets the informed position ring to the new one.
void setPolygonContourPatternOpacity(int opacity)
It sets the polygon contour pattern opacity.
QColor m_ptColor
The color used to draw point (pixel) or marker.
int getResolution()
It returns the device resolution.