27 #include "../../common/UserApplicationSettings.h" 
   28 #include "../../dataaccess/serialization/xml/Serializer.h" 
   29 #include "../../maptools/AbstractLayer.h" 
   30 #include "../../plugin/PluginManager.h" 
   31 #include "../../plugin/PluginInfo.h" 
   32 #include "../../serialization/maptools/Layer.h" 
   33 #include "../../xml/Reader.h" 
   34 #include "../../xml/ReaderFactory.h" 
   35 #include "../../xml/Writer.h" 
   48 #include <boost/filesystem.hpp> 
   49 #include <boost/format.hpp> 
   50 #include <boost/property_tree/ptree.hpp> 
   51 #include <boost/algorithm/string/replace.hpp> 
   54 #include <QtCore/QSettings> 
   55 #include <QtCore/QString> 
   56 #include <QtGui/QApplication> 
   57 #include <QtGui/QAction> 
   58 #include <QtGui/QMainWindow> 
   59 #include <QtGui/QMessageBox> 
   60 #include <QtGui/QToolBar> 
   64   boost::filesystem::path furi(uri);
 
   66   if (!boost::filesystem::exists(furi) || !boost::filesystem::is_regular_file(furi))   
 
   67     throw Exception((boost::format(
TR_QT_AF(
"Could not read project file: %1%.")) % uri).str());
 
   73   if(!xmlReader->next())
 
   74     throw Exception((boost::format(
TR_QT_AF(
"Could not read project information in the file: %1%.")) % uri).str());
 
   77     throw Exception((boost::format(
TR_QT_AF(
"Error reading the document %1%, the start element wasn't found.")) % uri).str());
 
   79   if(xmlReader->getElementLocalName() != 
"Project")
 
   80     throw Exception((boost::format(
TR_QT_AF(
"The first tag in the document %1% is not 'Project'.")) % uri).str());
 
   92   std::auto_ptr<Project> project(
new Project);
 
  129   std::vector<std::string> invalidLayers;
 
  141       invalidLayers.push_back(layer->getTitle());
 
  151   project->setProjectAsChanged(
false);
 
  153   if(!invalidLayers.empty())
 
  155     QString message(QObject::tr(
"The following layers are invalid and will not be added to TerraView"));
 
  158     for(std::size_t i = 0; i <invalidLayers.size(); ++i)
 
  161       message += invalidLayers[i].c_str();
 
  169   return project.release();
 
  174   std::ofstream fout(uri.c_str(), std::ios_base::trunc);
 
  185   const char* te_env = getenv(
"TERRALIB_DIR");
 
  188     throw Exception(
TR_QT_AF(
"Environment variable \"TERRALIB_DIR\" not found.\nTry to set it before run the application."));
 
  190   std::string schema_loc(te_env);
 
  191   schema_loc += 
"/schemas/terralib";
 
  197   boost::replace_all(schema_loc, 
" ", 
"%20");
 
  199   schema_loc = 
"file:///" + schema_loc;
 
  201   writer.
writeAttribute(
"xmlns:xsd", 
"http://www.w3.org/2001/XMLSchema-instance");
 
  202   writer.
writeAttribute(
"xmlns:te_da", 
"http://www.terralib.org/schemas/dataaccess");
 
  203   writer.
writeAttribute(
"xmlns:te_map", 
"http://www.terralib.org/schemas/maptools");
 
  204   writer.
writeAttribute(
"xmlns:te_qt_af", 
"http://www.terralib.org/schemas/common/af");
 
  208   writer.
writeAttribute(
"xmlns:xlink", 
"http://www.w3.org/1999/xlink");
 
  210   writer.
writeAttribute(
"xmlns", 
"http://www.terralib.org/schemas/qt/af");
 
  211   writer.
writeAttribute(
"xsd:schemaLocation", 
"http://www.terralib.org/schemas/qt/af " + schema_loc + 
"/qt/af/project.xsd");
 
  224   for(std::list<te::map::AbstractLayerPtr>::const_iterator it = project.
getTopLayers().begin();
 
  227     lserial.
write(it->get(), writer);
 
  243   p.get_child(
"UserSettings.MostRecentProject.<xmlattr>.xlink:href").put_value(prjFiles.at(0).toStdString());
 
  244   p.get_child(
"UserSettings.MostRecentProject.<xmlattr>.title").put_value(prjTitles.at(0).toStdString());
 
  246   if(prjFiles.size() > 1)
 
  248     boost::property_tree::ptree recPrjs;
 
  250     for(
int i=1; i<prjFiles.size(); i++)
 
  252       boost::property_tree::ptree prj;
 
  254       prj.add(
"<xmlattr>.xlink:href", prjFiles.at(i).toStdString());
 
  255       prj.add(
"<xmlattr>.title", prjTitles.at(i).toStdString());
 
  257       recPrjs.add_child(
"Project", prj);
 
  260     p.put_child(
"UserSettings.RecentProjects", recPrjs);
 
  265   boost::property_tree::ptree plgs;
 
  266   std::vector<std::string> plugins;
 
  267   std::vector<std::string>::iterator it;
 
  270   for(it=plugins.begin(); it!=plugins.end(); ++it)
 
  273       boost::property_tree::ptree plg;
 
  275       plgs.add_child(
"Plugin", plg);
 
  278   p.put_child(
"UserSettings.EnabledPlugins", plgs);
 
  295   ApplicationPlugins::getInstance().getAllSettings().get_child(
"Plugins").erase(
"Plugin");
 
  296   boost::property_tree::ptree& p = ApplicationPlugins::getInstance().getAllSettings();
 
  298   std::vector<std::string> plugins;
 
  299   std::vector<std::string>::iterator it;
 
  302   for(it=plugins.begin(); it!=plugins.end(); ++it)
 
  305     boost::property_tree::ptree plg;
 
  307     std::string plgFileName = info.
m_folder + 
"/" + info.
m_name + 
".teplg";
 
  309     plg.add(
"Name", info.
m_name);
 
  310     plg.add(
"Path.<xmlattr>.xlink:href", plgFileName);
 
  312     p.add_child(
"Plugins.Plugin", plg);
 
  316   boost::property_tree::xml_writer_settings<char> settings(
'\t', 1);
 
  317   boost::property_tree::write_xml(ApplicationPlugins::getInstance().getFileName(), p, std::locale(), settings);
 
  322   sett.beginGroup(bar->objectName());
 
  324   sett.setValue(
"name", bar->objectName());
 
  326   sett.beginWriteArray(
"Actions");
 
  328   QList<QAction*> acts = bar->actions();
 
  330   for(
int i=0; i<acts.size(); i++)
 
  332     sett.setArrayIndex(i);
 
  333     sett.setValue(
"action", acts.at(i)->objectName());
 
  344   std::vector<QToolBar*>::const_iterator it;
 
  345   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  347   sett.beginGroup(
"toolbars");
 
  349   for (it = bars.begin(); it != bars.end(); ++it)
 
  353     sett.remove(bar->objectName());
 
  363   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  365   sett.beginGroup(
"toolbars");
 
  374   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  376   sett.beginGroup(
"toolbars");
 
  377   sett.remove(bar->objectName());
 
  383   std::vector<QToolBar*> bars;
 
  385   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  387   sett.beginGroup(
"toolbars");
 
  388   QStringList lst = sett.childGroups();
 
  390   QStringList::iterator it;
 
  392   for(it=lst.begin(); it != lst.end(); ++it)
 
  398     QString grName = sett.value(
"name").toString();
 
  400     int size = sett.beginReadArray(
"Actions");
 
  402     QToolBar* toolbar = 
new QToolBar(barsParent);
 
  403     toolbar->setObjectName(grName);
 
  404     toolbar->setWindowTitle(grName);
 
  406     for(
int i=0; i<size; i++)
 
  408       sett.setArrayIndex(i);
 
  409       QString act = sett.value(
"action").toString();
 
  413         toolbar->addSeparator();
 
  417         QAction* a = ApplicationController::getInstance().findAction(act);
 
  420           toolbar->addAction(a);
 
  427     bars.push_back(toolbar);
 
  437   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  439   sett.beginGroup(
"mainWindow");
 
  440   sett.setValue(
"geometry", mainWindow->saveGeometry());
 
  441   sett.setValue(
"windowState", mainWindow->saveState());
 
  447   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  449   sett.beginGroup(
"mainWindow");
 
  450   mainWindow->restoreGeometry(sett.value(
"geometry").toByteArray());
 
  451   mainWindow->restoreState(sett.value(
"windowState").toByteArray());
 
  457   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  459   sett.beginGroup(
"projects");
 
  460   defaultAuthor = sett.value(
"default author").toString();
 
  461   maxSaved = sett.value(
"maximum saved").toInt();
 
  467   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  469   sett.beginGroup(
"projects");
 
  470   sett.setValue(
"default author", defaultAuthor);
 
  471   sett.setValue(
"maximum saved", maxSaved);
 
  477   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  479   sett.setValue(
"projects/last datasource used", dsType);
 
  484   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  486   sett.setValue(
"projects/openLastDataSource", openLast);
 
  491   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  493   return sett.value(
"projects/last datasource used").toString();
 
  498   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  500   QVariant variant = sett.value(
"projects/openLastDataSource");
 
  503   if(variant.isNull() || !variant.isValid())
 
  506   return variant.toBool();
 
  511   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  513   sett.beginGroup(
"toolbars");
 
  515   sett.beginGroup(
"File Tool Bar");
 
  516   sett.setValue(
"name", 
"File Tool Bar");
 
  517   sett.beginWriteArray(
"Actions");
 
  518   sett.setArrayIndex(0);
 
  519   sett.setValue(
"action", 
"File.New Project");
 
  520   sett.setArrayIndex(1);
 
  521   sett.setValue(
"action", 
"File.Open Project");
 
  522   sett.setArrayIndex(2);
 
  523   sett.setValue(
"action", 
"File.Save Project");
 
  524   sett.setArrayIndex(3);
 
  525   sett.setValue(
"action", 
"");
 
  526   sett.setArrayIndex(4);
 
  527   sett.setValue(
"action", 
"Project.New Folder");
 
  528   sett.setArrayIndex(5);
 
  529   sett.setValue(
"action", 
"Project.Add Layer.All Sources");
 
  533   sett.beginGroup(
"View Tool Bar");
 
  534   sett.setValue(
"name", 
"View Tool Bar");
 
  535   sett.beginWriteArray(
"Actions");
 
  536   sett.setArrayIndex(0);
 
  537   sett.setValue(
"action", 
"View.Layer Explorer");
 
  538   sett.setArrayIndex(1);
 
  539   sett.setValue(
"action", 
"View.Map Display");
 
  540   sett.setArrayIndex(2);
 
  541   sett.setValue(
"action", 
"View.Data Table");
 
  542   sett.setArrayIndex(3);
 
  543   sett.setValue(
"action", 
"View.Style Explorer");
 
  547   sett.beginGroup(
"Map Tool Bar");
 
  548   sett.setValue(
"name", 
"Map Tool Bar");
 
  549   sett.beginWriteArray(
"Actions");  
 
  550   sett.setArrayIndex(0);
 
  551   sett.setValue(
"action", 
"Map.Draw");
 
  552   sett.setArrayIndex(1);
 
  553   sett.setValue(
"action", 
"Map.Previous Extent");
 
  554   sett.setArrayIndex(2);
 
  555   sett.setValue(
"action", 
"Map.Next Extent");
 
  556   sett.setArrayIndex(3);
 
  557   sett.setValue(
"action", 
"Map.Zoom Extent");
 
  558   sett.setArrayIndex(4);
 
  559   sett.setValue(
"action", 
"");
 
  560   sett.setArrayIndex(5);
 
  561   sett.setValue(
"action", 
"Map.Zoom In");
 
  562   sett.setArrayIndex(6);
 
  563   sett.setValue(
"action", 
"Map.Zoom Out");
 
  564   sett.setArrayIndex(7);
 
  565   sett.setValue(
"action", 
"Map.Pan");
 
  566   sett.setArrayIndex(8);
 
  567   sett.setValue(
"action", 
"");
 
  568   sett.setArrayIndex(9);
 
  569   sett.setValue(
"action", 
"Map.Info");
 
  570   sett.setArrayIndex(10);
 
  571   sett.setValue(
"action", 
"Map.Selection");
 
  577   sett.beginGroup(
"projects");
 
  579   sett.setValue(
"default author", 
"");
 
  580   sett.setValue(
"maximum saved", 
"8");
 
  587   QString result(windowTitle);
 
  591     if(result.at(result.count()-1) != 
'*')
 
  596     if(result.at(result.count()-1) == 
'*')
 
  597       result.remove((result.count()-1), 1);
 
  605   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  606   QString hexColor = sett.value(
"display/defaultDisplayColor").toString();  
 
  608   defaultColor.setNamedColor(hexColor);
 
  609   if(!defaultColor.isValid())
 
  617   QString sty(
"alternate-background-color: ");
 
  618   sty += 
"rgb(" + QString::number(secondaryColor.red()) + 
", " + QString::number(secondaryColor.green());
 
  619   sty += 
", " + QString::number(secondaryColor.blue()) + 
")";
 
  620   sty += 
";background-color: rgb(" + QString::number(primaryColor.red()) + 
", " + QString::number(primaryColor.green());
 
  621   sty += 
", " + QString::number(primaryColor.blue()) + 
");";
 
  628   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  631   pColor.setNamedColor(sett.value(
"table/primaryColor").toString());
 
  633   sColor.setNamedColor(sett.value(
"table/secondaryColor").toString());
 
  635   if(!pColor.isValid())
 
  637   if(!sColor.isValid())
 
  645   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  646   bool isChecked = sett.value(
"table/tableAlternateColors").toBool();
 
  653   QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
 
  655   sett.beginGroup(
"toolbars");
 
  656   QStringList lst = sett.childGroups();
 
  657   QStringList::iterator it;
 
  659   for(it=lst.begin(); it!=lst.end(); ++it)
 
  661     int size = sett.beginReadArray(*it+
"/Actions");
 
  663     for(
int i=0; i<size; i++)
 
  665       sett.setArrayIndex(i);
 
  667       QString v = sett.value(
"action").toString(); 
 
  669       if (v == act->objectName())
 
  671         ApplicationController::getInstance().getToolBar(*it)->addAction(act);
 
virtual void writeStartDocument(const std::string &encoding, const std::string &standalone)
 
The basic information about a plugin. 
 
TEQTAFEXPORT void AddToolBarToSettings(QToolBar *bar)
Update settings with a new tool bar. 
 
An exception class for the TerraLib Application Framework. 
 
const std::string & getAuthor() const 
It gets the author of the project. 
 
TEDATAACCESSEXPORT void Save(const std::string &fileName)
 
TEQTAFEXPORT bool GetAlternateRowColorsFromSettings()
 
te::map::AbstractLayer * read(te::xml::Reader &reader) const 
 
This class models a XML reader object. 
 
TEQTAFEXPORT void RemoveToolBarFromSettings(QToolBar *bar)
Removes a tool bar from the settings. 
 
Utility routines for the TerraLib Application Framework module. 
 
TEQTAFEXPORT void UpdateToolBarsInTheSettings()
Update the existing tool bars. 
 
The base API for controllers of TerraLib applications. 
 
static te::xml::Reader * make()
It creates a new XML reader using the dafault implementation. 
 
const boost::property_tree::ptree & getAllSettings() const 
It return a reading reference to the internal settings. 
 
virtual bool next()=0
It gets the next event to be read. 
 
TEQTAFEXPORT QString UnsavedStar(const QString windowTitle, bool isUnsaved)
Unsaved star. 
 
std::string getValue(const std::string &key)
It returns the value for a given key or empty. 
 
static ApplicationController & getInstance()
It gives access to the controller singleton. 
 
TEQTAFEXPORT void SaveProjectInformationsOnSettings(const QString &defaultAuthor, const int &maxSaved)
 
TEQTAFEXPORT Project * ReadProject(const std::string &uri)
Reads and return a te::qt::af::Project from the file. 
 
QString GetStyleSheetFromColors(QColor primaryColor, QColor secondaryColor)
 
TEQTAFEXPORT void SaveDataSourcesFile()
Saves data sources file. 
 
TEQTAFEXPORT QColor GetDefaultDisplayColorFromSettings()
 
virtual void writeStartElement(const std::string &qName)
 
virtual void writeAttribute(const std::string &attName, const std::string &value)
 
This class models the concept of a project for the TerraLib Application Framework. 
 
void setFileName(const std::string &fName)
It sets the filename where the project will be saved. 
 
virtual std::string getElementValue() const =0
It returns the element data value in the case of VALUE node. 
 
virtual void writeEndElement(const std::string &qName)
 
TEQTAFEXPORT void SaveState(QMainWindow *mainWindow)
 
void AddToolbarAndActions(QToolBar *bar, QSettings &sett)
 
TEQTAFEXPORT void RestoreState(QMainWindow *mainWindow)
 
const std::string & getTitle() const 
It gets the title of the project. 
 
TEQTAFEXPORT void SaveLastDatasourceOnSettings(const QString &dsType)
 
A singleton for managing the application plugins. 
 
TEQTAFEXPORT QString GetStyleSheetFromColors(QColor primaryColor, QColor secondaryColor)
 
TEQTAFEXPORT void UpdateUserSettings(const QStringList &prjFiles, const QStringList &prjTitles, const std::string &userConfigFile)
Updates user settings file section about information of the projects. 
 
std::vector< QToolBar * > getToolBars() const 
Return the list of registered toolbars. 
 
virtual void writeElement(const std::string &qName, const std::string &value)
 
const std::list< te::map::AbstractLayerPtr > & getTopLayers() const 
It gets all the top layers of the project (folder and single layers). 
 
void changed()
This method can be used by clients to inform manually that the internal state has changed...
 
TEQTAFEXPORT void CreateDefaultSettings()
Creates a default QSettings. 
 
TEQTAFEXPORT bool GetOpenLastProjectFromSettings()
 
TEQTAFEXPORT void Save(const Project &project, const std::string &uri)
Saves the informations of the project in the uri file. 
 
void write(const te::map::AbstractLayer *alayer, te::xml::Writer &writer) const 
 
TEQTAFEXPORT QString GetStyleSheetFromSettings()
 
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
 
#define TR_QT_AF(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
 
static Layer & getInstance()
It returns a reference to the singleton instance. 
 
virtual NodeType getNodeType() const =0
It return the type of node read. 
 
std::string m_name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
 
This class models the concept of a project for the TerraLib Application Framework. 
 
TEQTAFEXPORT QString GetLastDatasourceFromSettings()
 
std::string m_folder
The plugin folder (where the plugin is installed). 
 
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node. 
 
TEQTAFEXPORT void UpdateApplicationPlugins()
Update plugins file. 
 
TEQTAFEXPORT void SaveOpenLastProjectOnSettings(bool openLast)
 
TEQTAFEXPORT std::vector< QToolBar * > ReadToolBarsFromSettings(QWidget *barsParent=0)
Returns a vector of tool bars registered in the QSettings. 
 
TEQTAFEXPORT void GetProjectInformationsFromSettings(QString &defaultAuthor, int &maxSaved)
 
TEQTAFEXPORT void AddActionToCustomToolbars(QAction *act)
Check QSettings for existance of act and adds it if necessary. 
 
This class models a XML writer object.