All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LocalImagePropertyItem.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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 #include "LocalImagePropertyItem.h"
29 
30 #include "../../../se/Config.h"
31 #include "../../../se/ExternalGraphic.h"
32 #include "../../../xlink/SimpleLink.h"
33 
34 
35 // Qt
36 #include <QtGui/QDialog>
37 #include <QtGui/QFileDialog>
38 #include <QtGui/QGridLayout>
39 #include <QtGui/QImageReader>
40 #include <QtGui/QMessageBox>
41 #include <QtGui/QScrollArea>
42 #include <QtGui/QPushButton>
43 
44 #include "../../../../../third-party/qt/propertybrowser/qtpropertybrowser.h"
45 
46 // STL
47 #include <cassert>
48 
49 
50 te::qt::widgets::LocalImagePropertyItem::LocalImagePropertyItem(QtTreePropertyBrowser* pb, QColor c) : te::qt::widgets::AbstractPropertyItem(pb, c) ,
51  m_eg(new te::se::ExternalGraphic), m_update(false)
52 {
53  //build property browser basic fill
54  QtProperty* localImgProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Local Image"));
55 
56  //dlg
57  m_imgProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_strDlgManager->addProperty(tr("Image"));
58  te::qt::widgets::AbstractPropertyManager::getInstance().m_strDlgManager->setValue(m_imgProperty, QString("0"));
59  connect(te::qt::widgets::AbstractPropertyManager::getInstance().m_dlgFactory, SIGNAL(internalDlg(QWidget *, QtProperty *)), this, SLOT(setDlg(QWidget *, QtProperty *)));
60  localImgProperty->addSubProperty(m_imgProperty);
61 
62  addProperty(localImgProperty, tr("Local Image"), QColor(255, 190, 160));
63 }
64 
66 {
67 }
68 
70 {
71  assert(eg);
72 
73  delete m_eg;
74 
75  m_eg = eg->clone();
76 
77  updateUi();
78 }
79 
81 {
82  return m_eg->clone();
83 }
84 
86 {
87  // Updating path
88  const te::xl::SimpleLink* link = m_eg->getOnlineResource();
89  assert(link);
90  QString path = link->getHref().c_str();
91 
93 }
94 
95 void te::qt::widgets::LocalImagePropertyItem::valueChanged(QtProperty* p, const QString &value)
96 {
97 
98 }
99 
100 void te::qt::widgets::LocalImagePropertyItem::setDlg(QWidget *parent, QtProperty * prop)
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.toStdString());
134  m_eg->setOnlineResource(link);
135 
136  // Updating external graphic format
137  QString f(QImageReader::imageFormat(path));
138  m_eg->setFormat("image/" + f.toStdString()); // It's correct?!
139 
140  emit externalGraphicChanged();
141 
142  updateUi();
143 }
void setHref(const std::string &href)
Definition: SimpleLink.cpp:45
void updateUi()
Updates the widget form based on internal mark element.
ExternalGraphic * clone() const
It creates a new copy of this object.
const std::string & getHref() const
Definition: SimpleLink.cpp:50
The ExternalGraphic allows a reference to be made to an external graphic file with a Web URL or to in...
Simple link.
Definition: SimpleLink.h:48
te::se::ExternalGraphic * getExternalGraphic() const
Gets the configured mark element.
LocalImagePropertyItem(QtTreePropertyBrowser *pb, QColor c=QColor())
Constructor.
A concrete renderer based on Qt4 for conversion of Symbology Enconding External Graphic elements to a...
A widget used to define the main property items that can be used to describe a se object...
void setExternalGraphic(const te::se::ExternalGraphic *eg)
Sets a mark element to this widget.
void setDlg(QWidget *parent, QtProperty *prop)
A widget used to define a local image graphic for a se symbolizer.
void addProperty(QtProperty *property, const QString &id, QColor c)
static AbstractPropertyManager & getInstance()
It returns a reference to the singleton instance.
virtual void valueChanged(QtProperty *p, const QString &value)