CharEncodingMenuWidget.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/layer/utils/CharEncodingMenuWidget.cpp
22 
23  \brief This file defines a class for a CharEncodingMenuWidget.
24 */
25 
26 // TerraLib
27 #include "../../../../dataaccess/utils/Utils.h"
28 #include "CharEncodingMenuWidget.h"
29 
30 // Qt
31 #include <QActionGroup>
32 
34 {
35  //create menu
36  m_menu = new QMenu(tr("Char Encoding"), this);
37 
38  //create action group
39  m_actGroup = new QActionGroup(this);
40 
41  std::vector<std::string> etNames = te::core::CharEncoding::getEncodingList();
42 
43  for (std::size_t t = 0; t < etNames.size(); ++t)
44  {
45  //create actions
46  QAction* act = new QAction(etNames[t].c_str(), this);
47 
48  act->setData(QVariant(etNames[t].c_str()));
49  act->setCheckable(true);
50 
51  //add actions to menu
52  m_menu->addAction(act);
53  m_actGroup->addAction(act);
54 
55  //connections
56  connect(act, SIGNAL(triggered()), this, SLOT(onEncodingClicked()));
57  }
58 }
59 
61 
63 {
64  m_layer = layer;
65 
66  std::string etName = te::core::CharEncoding::getEncodingName(m_layer->getEncoding());
67 
68  QList<QAction*> actions = m_actGroup->actions();
69  QList<QAction*>::iterator it = actions.begin();
70 
71  while (it != actions.end())
72  {
73  std::string etCurName = (*it)->data().toString().toUtf8().data();
74 
75  if (etCurName == etName)
76  {
77  (*it)->setChecked(true);
78 
79  break;
80  }
81 
82  ++it;
83  }
84 
86 }
87 
89 {
90  return m_menu;
91 }
92 
94 {
96 
97  QList<QAction*> actions = m_actGroup->actions();
98  QList<QAction*>::iterator it = actions.begin();
99 
100  while (it != actions.end())
101  {
102  if (ds->getType() == "OGR")
103  (*it)->setEnabled(true);
104  else
105  (*it)->setEnabled(false);
106 
107  ++it;
108  }
109 }
110 
112 {
113  QAction* act = dynamic_cast<QAction*>(sender());
114 
115  if (act)
116  {
117  std::string etName = act->data().toString().toUtf8().data();
118 
119  std::vector<std::string> etNames = te::core::CharEncoding::getEncodingList();
120 
121  for (std::size_t t = 0; t < etNames.size(); ++t)
122  {
123  if (etName == etNames[t])
124  {
125  m_layer->setEncoding(te::core::CharEncoding::getEncodingType(etName));
126  }
127  }
128  }
129 }
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void setLayer(te::map::AbstractLayerPtr layer)
Set the layer that can be used.
boost::shared_ptr< DataSource > DataSourcePtr
CharEncodingMenuWidget(QWidget *parent=0, Qt::WindowFlags f=0)
static te::dt::Date ds(2010, 01, 01)
te::map::AbstractLayerPtr m_layer
Selected Layer.
static std::string getEncodingName(EncodingType et)
Retrive a string from a given character encoding type enum.
This file defines a class for a CharEncodingMenuWidget.
static te::core::EncodingType getEncodingType(const std::string &name)
Retrive an EncodingType from a given character encoding name.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
static std::vector< std::string > getEncodingList()
Retrive a vector of string with all available encoding types name.