WMSLayerDisplay.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2016 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/ws/ogc/wms/qt/WMSLayerDisplay.cpp
22 
23  \brief A display QFrame to draw previews for WMS data.
24 
25  \author Emerson Moraes
26 */
27 
28 #include "WMSLayerDisplay.h"
29 
30 //TerraLib
31 #include "../../../core/Utils.h"
32 
33 // STL
34 #include <cassert>
35 
36 // Qt
37 #include <QResizeEvent>
38 
40  : QFrame(parent, f)
41 {
42 
43 }
44 
46 
48 {
49  if(m_canvas.get() == nullptr)
50  {
51  m_canvas.reset(new te::qt::widgets::Canvas(width(), height()));
52  }
53 
54  if(response.m_size == 0 || response.m_format.empty())
55  {
56  return;
57  }
58 
60 
61  m_canvas->drawImage(const_cast<char*>(response.m_buffer.c_str()), (std::size_t) response.m_size, imageType);
62 
63  repaint();
64 }
65 
67 {
68  if(m_canvas.get() == nullptr)
69  m_canvas.reset(new te::qt::widgets::Canvas(width(), height()));
70 
71  m_canvas->setBackgroundColor(te::color::RGBAColor(255, 255, 255, 0));
72  m_canvas->clear();
73 
74  repaint();
75 }
76 
78 {
79  if(m_canvas.get() == nullptr)
80  return;
81 
82  QPainter painter(this);
83 
84  painter.drawPixmap(0, 0, *(m_canvas->getPixmap()));
85 
86  painter.end();
87 }
88 
90 {
91  assert(e);
92 
93  if(m_canvas.get() == nullptr)
94  return;
95 
96  m_canvas->resize(e->size().width(), e->size().height());
97 
98  QFrame::resizeEvent(e);
99 }
ImageType
This enum specifies the possible input and output image formats supported by the canvas API...
WMSLayerDisplay(QWidget *parent=0, Qt::WindowFlags f=0)
TEWSCOREEXPORT te::map::ImageType FormatToImageType(const std::string &format)
This function gets an ImageType Enum according to an image format string (e.g. image/png).
std::unique_ptr< te::qt::widgets::Canvas > m_canvas
The WMSGetMapResponse WMS 1.3.0 struct.
A display QFrame to draw previews for WMS data.
void draw(const te::ws::ogc::wms::WMSGetMapResponse &response)
Draws a WMSGetMapResponse in the preview Canvas.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57