LocalImagePropertyItem.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/se/LocalImagePropertyItem.h
22 
23  \brief A widget used to define a local image graphic for a se symbolizer.
24 */
25 
26 // TerraLib
27 #include "../../../se/Config.h"
28 #include "../../../se/ExternalGraphic.h"
29 #include "../../../xlink/SimpleLink.h"
30 #include "../propertybrowser/AbstractPropertyManager.h"
31 #include "LocalImagePropertyItem.h"
33 
34 // STL
35 #include <cassert>
36 
37 // Qt
38 #include <QDialog>
39 #include <QFileDialog>
40 #include <QGridLayout>
41 #include <QImageReader>
42 #include <QMessageBox>
43 #include <QScrollArea>
44 #include <QPushButton>
45 
46 // QtPropertyBrowser
47 #include <QtPropertyBrowser/QtTreePropertyBrowser>
48 #include <QtPropertyBrowser/QtVariantPropertyManager>
49 
50 
51 te::qt::widgets::LocalImagePropertyItem::LocalImagePropertyItem(QtTreePropertyBrowser* pb, QColor c) : te::qt::widgets::AbstractPropertyItem(pb, c) ,
52  m_eg(new te::se::ExternalGraphic), m_update(false)
53 {
54  //build property browser basic fill
55  QtProperty* localImgProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Local Image"));
56 
57  //dlg
58  m_imgProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_strDlgManager->addProperty(tr("Image"));
59  te::qt::widgets::AbstractPropertyManager::getInstance().m_strDlgManager->setValue(m_imgProperty, QString("0"));
60  connect(te::qt::widgets::AbstractPropertyManager::getInstance().m_dlgFactory, SIGNAL(internalDlg(QWidget *, QtProperty *)), this, SLOT(setDlg(QWidget *, QtProperty *)));
61  localImgProperty->addSubProperty(m_imgProperty);
62 
63  addProperty(localImgProperty, tr("Local Image"), QColor(255, 190, 160));
64 }
65 
67 
69 {
70  assert(eg);
71 
72  delete m_eg;
73 
74  m_eg = eg->clone();
75 
76  updateUi();
77 }
78 
80 {
81  return m_eg->clone();
82 }
83 
85 {
86  // Updating path
88  assert(link);
89  QString path = link->getHref().c_str();
90 
92 }
93 
95  QtProperty* /*p*/, const QString& /*value*/)
96 {
97 
98 }
99 
101 {
102  if(prop == m_imgProperty)
103  {
104  m_dlg = parent;
105 
106  connect(m_dlg, SIGNAL(showDlg()), this, SLOT(showImgDlg()));
107  }
108 }
109 
111 {
112  // Bulding the filter string
113  QString filter = tr("Images") + " ( ";
114  QList<QByteArray> formats = QImageReader::supportedImageFormats();
115  for(int i = 0; i < formats.size() - 1; ++i)
116  filter += "*." + formats[i] + " ";
117  filter += ")";
118 
119  QString path = QFileDialog::getOpenFileName(this, tr("Select an Image File"), "", filter);
120  if(path.isNull())
121  return;
122 
123  // Try load image
124  QImage img;
125  if(!img.load(path))
126  {
127  QMessageBox::critical(this, tr("Error"), tr("The selected image cannot be loaded."));
128  return;
129  }
130 
131  // Updating external graphic path
133  link->setHref(path.toUtf8().data());
134  m_eg->setOnlineResource(link);
135 
136  // Updating external graphic format
137  QString f(QImageReader::imageFormat(path));
138  m_eg->setFormat("image/" + std::string(f.toUtf8().data())); // It's correct?!
139 
140  emit externalGraphicChanged();
141 
142  updateUi();
143 }
A widget used to define the main property items that can be used to describe a se object...
te::se::ExternalGraphic * m_eg
Mark element that will be configured by this widget.
A widget used to define a local image graphic for a se symbolizer.
void setDlg(QWidget *parent, QtProperty *prop)
const te::xl::SimpleLink * getOnlineResource() const
The ExternalGraphic allows a reference to be made to an external graphic file with a Web URL or to in...
who udp maintains data bases showing who s shell tcp cmd syslog udp printer tcp spooler printer udp spooler videotex tcp videotex videotex udp videotex talk tcp like tenex link
ExternalGraphic * clone() const
It creates a new copy of this object.
virtual void valueChanged(QtProperty *p, const QString &value)
static AbstractPropertyManager & getInstance()
It returns a reference to the singleton instance.
te::se::ExternalGraphic * getExternalGraphic() const
Gets the configured mark element.
URI C++ Library.
Definition: Attributes.h:37
void externalGraphicChanged()
This signal is emitted when the internal external graphic element is changed.
void addProperty(QtProperty *property, const QString &id, QColor c)
void setExternalGraphic(const te::se::ExternalGraphic *eg)
Sets a mark element to this widget.
A concrete renderer based on Qt4 for conversion of Symbology Enconding External Graphic elements to a...
LocalImagePropertyItem(QtTreePropertyBrowser *pb, QColor c=QColor())
Constructor.
void setFormat(const std::string &f)
void setOnlineResource(te::xl::SimpleLink *onlineResource)
void updateUi()
Updates the widget form based on internal mark element.