All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
68 }
69 
71 {
72  assert(eg);
73 
74  delete m_eg;
75 
76  m_eg = eg->clone();
77 
78  updateUi();
79 }
80 
82 {
83  return m_eg->clone();
84 }
85 
87 {
88  // Updating path
89  const te::xl::SimpleLink* link = m_eg->getOnlineResource();
90  assert(link);
91  QString path = link->getHref().c_str();
92 
94 }
95 
96 void te::qt::widgets::LocalImagePropertyItem::valueChanged(QtProperty* p, const QString &value)
97 {
98 
99 }
100 
101 void te::qt::widgets::LocalImagePropertyItem::setDlg(QWidget *parent, QtProperty * prop)
102 {
103  if(prop == m_imgProperty)
104  {
105  m_dlg = parent;
106 
107  connect(m_dlg, SIGNAL(showDlg()), this, SLOT(showImgDlg()));
108  }
109 }
110 
112 {
113  // Bulding the filter string
114  QString filter = tr("Images") + " ( ";
115  QList<QByteArray> formats = QImageReader::supportedImageFormats();
116  for(int i = 0; i < formats.size() - 1; ++i)
117  filter += "*." + formats[i] + " ";
118  filter += ")";
119 
120  QString path = QFileDialog::getOpenFileName(this, tr("Select an Image File"), "", filter);
121  if(path.isNull())
122  return;
123 
124  // Try load image
125  QImage img;
126  if(!img.load(path))
127  {
128  QMessageBox::critical(this, tr("Error"), tr("The selected image cannot be loaded."));
129  return;
130  }
131 
132  // Updating external graphic path
134  link->setHref(path.toStdString());
135  m_eg->setOnlineResource(link);
136 
137  // Updating external graphic format
138  QString f(QImageReader::imageFormat(path));
139  m_eg->setFormat("image/" + f.toStdString()); // It's correct?!
140 
141  emit externalGraphicChanged();
142 
143  updateUi();
144 }
A widget used to define the main property items that can be used to describe a se object...
A widget used to define a local image graphic for a se symbolizer.
void setDlg(QWidget *parent, QtProperty *prop)
The ExternalGraphic allows a reference to be made to an external graphic file with a Web URL or to in...
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.
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 updateUi()
Updates the widget form based on internal mark element.