src/terraview/Utils.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 terraview/Utils.cpp
22 
23  \brief Utility routines for the TerraView Application Framework module.
24 */
25 
26 // TerraLib
27 #include <terralib/Version.h>
32 #include <terralib/xml/Reader.h>
34 #include "Utils.h"
35 
36 // STL
37 #include <cassert>
38 #include <fstream>
39 #include <memory>
40 
41 // Boost
42 #include <boost/property_tree/xml_parser.hpp>
43 #include <boost/property_tree/ptree.hpp>
44 #include <boost/property_tree/json_parser.hpp>
45 #include <boost/algorithm/string/replace.hpp>
46 #include <boost/filesystem.hpp>
47 #include <boost/format.hpp>
48 #include <boost/version.hpp>
49 
50 #include <QApplication>
51 #include <QSettings>
52 
53 
54 void GetProjectInformationsFromSettings(QString& defaultAuthor, int& maxSaved)
55 {
56  QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
57 
58  sett.beginGroup("projects");
59  defaultAuthor = sett.value("author_name").toString();
60  maxSaved = sett.value("recents_history_size").toInt();
61  sett.endGroup();
62 }
63 
64 void SaveProjectInformationsOnSettings(const QString& defaultAuthor, const int& maxSaved)
65 {
66  QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
67 
68  sett.beginGroup("projects");
69  sett.setValue("author_name", defaultAuthor);
70  sett.setValue("recents_history_size", maxSaved);
71  sett.endGroup();
72 }
73 
74 void SaveOpenLastProjectOnSettings(bool openLast)
75 {
76  QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
77 
78  sett.setValue("projects/openLastDataSource", openLast);
79 }
80 
82 {
83  QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
84 
85  QVariant variant = sett.value("projects/openLastDataSource");
86 
87  // If the option was never edited
88  if(variant.isNull() || !variant.isValid())
89  return true;
90 
91  return variant.toBool();
92 }
93 
94 void WriteDefaultProjectFile(const QString& fileName)
95 {
96  boost::property_tree::ptree p;
97 
98  std::string schema_location = te::core::FindInTerraLibPath("share/terralib/schemas/terralib/qt/af/project.xsd");
99 
100  //Header
101  p.add("Project.<xmlattr>.xmlns:xsd", "http://www.w3.org/2001/XMLSchema-instance");
102  p.add("Project.<xmlattr>.xmlns:te_map", "http://www.terralib.org/schemas/maptools");
103  p.add("Project.<xmlattr>.xmlns:te_qt_af", "http://www.terralib.org/schemas/qt/af");
104  p.add("Project.<xmlattr>.xmlns", "http://www.terralib.org/schemas/qt/af");
105  p.add("Project.<xmlattr>.xsd:schemaLocation", "http://www.terralib.org/schemas/qt/af " + schema_location);
106  p.add("Project.<xmlattr>.version", TERRALIB_VERSION_STRING);
107 
108  //Contents
109  p.add("Project.Title", "Default project");
110  p.add("Project.Author", "");
111  p.add("Project.ComponentList", "");
112  p.add("Project.te_map:LayerList", "");
113 
114  //Store file
115 #if BOOST_VERSION > 105600
116  boost::property_tree::xml_writer_settings<std::string> settings('\t', 1);
117 #else
118  boost::property_tree::xml_writer_settings<char> settings('\t', 1);
119 #endif
120  boost::property_tree::write_xml(fileName.toUtf8().data(), p, std::locale(), settings);
121 }
122 
This class models a XML reader object.
This file is a wrapper around platform specific include files.
bool GetOpenLastProjectFromSettings()
void GetProjectInformationsFromSettings(QString &defaultAuthor, int &maxSaved)
This is a proxy file for the real terralib_version.h file.
void SaveOpenLastProjectOnSettings(bool openLast)
te::gm::Polygon * p
This class models a XML writer object.
This file contains several utility functions for dealing with Boost containers and algorithms...
This is the abstract factory for XML readers.
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
void WriteDefaultProjectFile(const QString &fileName)
Writes the default project file.
void SaveProjectInformationsOnSettings(const QString &defaultAuthor, const int &maxSaved)
This is the abstract factory for XML writers.