• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • lib
  • marble
FileManager.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2006-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 //
11 
12 #include "FileManager.h"
13 
14 #include <QDir>
15 #include <QFileInfo>
16 #include <QTime>
17 #include <QMessageBox>
18 
19 #include "FileLoader.h"
20 #include "MarbleDebug.h"
21 #include "MarbleModel.h"
22 #include "GeoDataTreeModel.h"
23 
24 #include "GeoDataDocument.h"
25 #include "GeoDataLatLonAltBox.h"
26 #include "GeoDataStyle.h"
27 
28 
29 using namespace Marble;
30 
31 namespace Marble
32 {
33 class FileManagerPrivate
34 {
35 public:
36  FileManagerPrivate( MarbleModel* model, FileManager* parent )
37  : m_model( model ),
38  q( parent )
39  {
40  }
41 
42  ~FileManagerPrivate()
43  {
44  foreach ( FileLoader *loader, m_loaderList ) {
45  if ( loader ) {
46  loader->wait();
47  }
48  }
49  }
50 
51  void appendLoader( FileLoader *loader );
52  void closeFile( const QString &key );
53  void cleanupLoader( FileLoader *loader );
54 
55  MarbleModel* const m_model;
56 
57  FileManager * const q;
58  QList<FileLoader*> m_loaderList;
59  QHash < QString, GeoDataDocument* > m_fileItemHash;
60  GeoDataLatLonBox m_latLonBox;
61  QTime m_timer;
62 };
63 }
64 
65 FileManager::FileManager( MarbleModel *model, QObject *parent )
66  : QObject( parent )
67  , d( new FileManagerPrivate( model, this ) )
68 {
69 }
70 
71 
72 FileManager::~FileManager()
73 {
74  delete d;
75 }
76 
77 void FileManager::addFile( const QString& filepath, const QString& property, GeoDataStyle* style, DocumentRole role, bool recenter )
78 {
79  if( d->m_fileItemHash.contains( filepath ) ) {
80  return; // already loaded
81  }
82 
83  foreach ( const FileLoader *loader, d->m_loaderList ) {
84  if ( loader->path() == filepath )
85  return; // currently loading
86  }
87 
88  mDebug() << "adding container:" << filepath;
89  mDebug() << "Starting placemark loading timer";
90  d->m_timer.start();
91  FileLoader* loader = new FileLoader( this, d->m_model, recenter, filepath, property, style, role );
92  d->appendLoader( loader );
93 }
94 
95 void FileManager::addFile( const QStringList& filepaths, const QStringList& propertyList, const QList<GeoDataStyle*>& styles, DocumentRole role )
96 {
97  for (int i = 0 ; i < filepaths.size(); ++i ) {
98  addFile( filepaths.at(i), propertyList.at(i), styles.at(i), role );
99  }
100 }
101 
102 void FileManager::addData( const QString &name, const QString &data, DocumentRole role )
103 {
104  FileLoader* loader = new FileLoader( this, d->m_model, data, name, role );
105  d->appendLoader( loader );
106 }
107 
108 void FileManagerPrivate::appendLoader( FileLoader *loader )
109 {
110  QObject::connect( loader, SIGNAL(loaderFinished(FileLoader*)),
111  q, SLOT(cleanupLoader(FileLoader*)) );
112 
113  m_loaderList.append( loader );
114  loader->start();
115 }
116 
117 void FileManager::removeFile( const QString& key )
118 {
119  foreach ( FileLoader *loader, d->m_loaderList ) {
120  if ( loader->path() == key ) {
121  disconnect( loader, 0, this, 0 );
122  loader->wait();
123  d->m_loaderList.removeAll( loader );
124  delete loader->document();
125  return;
126  }
127  }
128 
129  if( d->m_fileItemHash.contains( key ) ) {
130  d->closeFile( key );
131  }
132 
133  mDebug() << "could not identify " << key;
134 }
135 
136 void FileManagerPrivate::closeFile( const QString& key )
137 {
138  mDebug() << "FileManager::closeFile " << key;
139  if( m_fileItemHash.contains( key ) ) {
140  GeoDataDocument *doc = m_fileItemHash.value( key );
141  m_model->treeModel()->removeDocument( doc );
142  emit q->fileRemoved( key );
143  delete doc;
144  m_fileItemHash.remove( key );
145  }
146 }
147 
148 void FileManager::saveFile( GeoDataDocument *document )
149 {
150  Q_UNUSED(document)
151 }
152 
153 void FileManager::closeFile( GeoDataDocument *document )
154 {
155  QHash < QString, GeoDataDocument* >::iterator itpoint = d->m_fileItemHash.begin();
156  QHash < QString, GeoDataDocument* >::iterator const endpoint = d->m_fileItemHash.end();
157  for (; itpoint != endpoint; ++itpoint ) {
158  if( d->m_fileItemHash.value( itpoint.key() ) == document ) {
159  d->closeFile( itpoint.key() );
160  return;
161  }
162  }
163 }
164 
165 int FileManager::size() const
166 {
167  return d->m_fileItemHash.size();
168 }
169 
170 GeoDataDocument * FileManager::at( const QString &key )
171 {
172  if ( d->m_fileItemHash.contains( key ) ) {
173  return d->m_fileItemHash.value( key );
174  }
175  return 0;
176 }
177 
178 void FileManagerPrivate::cleanupLoader( FileLoader* loader )
179 {
180  GeoDataDocument *doc = loader->document();
181  m_loaderList.removeAll( loader );
182  if ( loader->isFinished() ) {
183  if ( doc ) {
184  if ( doc->name().isEmpty() && !doc->fileName().isEmpty() )
185  {
186  QFileInfo file( doc->fileName() );
187  doc->setName( file.baseName() );
188  }
189  m_model->treeModel()->addDocument( doc );
190  m_fileItemHash.insert( loader->path(), doc );
191  emit q->fileAdded( loader->path() );
192  if( loader->recenter() ) {
193  m_latLonBox |= doc->latLonAltBox();
194  }
195  }
196  if ( !loader->error().isEmpty() ) {
197  QMessageBox errorBox;
198  errorBox.setWindowTitle( QObject::tr("File Parsing Error"));
199  errorBox.setText( loader->error() );
200  errorBox.setIcon( QMessageBox::Warning );
201  errorBox.exec();
202  qWarning() << "File Parsing error " << loader->error();
203  }
204  delete loader;
205  }
206  if ( m_loaderList.isEmpty() )
207  {
208  mDebug() << "Finished loading all placemarks " << m_timer.elapsed();
209 
210  if ( !m_latLonBox.isEmpty() ) {
211  emit q->centeredDocument( m_latLonBox );
212  }
213  m_latLonBox.clear();
214  }
215 }
216 
217 #include "FileManager.moc"
GeoDataDocument.h
FileManager.h
Marble::FileLoader::path
QString path() const
Definition: FileLoader.cpp:123
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:64
Marble::FileManager::~FileManager
~FileManager()
Destroys the file manager.
Definition: FileManager.cpp:72
Marble::FileLoader::document
GeoDataDocument * document()
Definition: FileLoader.cpp:128
Marble::FileManager::saveFile
void saveFile(GeoDataDocument *document)
Definition: FileManager.cpp:148
MarbleModel.h
This file contains the headers for MarbleModel.
GeoDataStyle.h
Marble::FileLoader
Definition: FileLoader.h:25
FileLoader.h
QObject
MarbleDebug.h
Marble::FileLoader::error
QString error() const
Definition: FileLoader.cpp:133
Marble::GeoDataStyle
an addressable style group
Definition: GeoDataStyle.h:55
Marble::FileManager::addData
void addData(const QString &name, const QString &data, DocumentRole role)
add Data containing KML code as string
Definition: FileManager.cpp:102
Marble::GeoDataFeature::setName
void setName(const QString &value)
Set a new name for this feature.
Definition: GeoDataFeature.cpp:485
Marble::FileManager
This class is responsible for loading the different files into Geodata model.
Definition: FileManager.h:36
Marble::FileManager::removeFile
void removeFile(const QString &fileName)
removes an existing file from the manager
Definition: FileManager.cpp:117
Marble::FileManager::size
int size() const
Definition: FileManager.cpp:165
Marble::FileManager::closeFile
void closeFile(GeoDataDocument *document)
Definition: FileManager.cpp:153
Marble::GeoDataContainer::latLonAltBox
GeoDataLatLonAltBox latLonAltBox() const
A convenience function that returns the LatLonAltBox of all placemarks in this container.
Definition: GeoDataContainer.cpp:53
Marble::FileManager::addFile
void addFile(const QString &fileName, const QString &property, GeoDataStyle *style, DocumentRole role, bool recenter=false)
Loads a new file into the manager.
Definition: FileManager.cpp:77
GeoDataTreeModel.h
Marble::FileLoader::recenter
bool recenter() const
Definition: FileLoader.cpp:236
Marble::FileManager::FileManager
FileManager(MarbleModel *model, QObject *parent=0)
Creates a new file manager.
Definition: FileManager.cpp:65
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:96
Marble::GeoDataDocument::fileName
QString fileName() const
The filename of the document.
Definition: GeoDataDocument.cpp:77
Marble::FileManager::at
GeoDataDocument * at(const QString &key)
Definition: FileManager.cpp:170
GeoDataLatLonAltBox.h
Marble::GeoDataFeature::name
QString name() const
The name of the feature.
Definition: GeoDataFeature.cpp:480
Marble::GeoDataContainer::remove
void remove(int index)
Definition: GeoDataContainer.cpp:173
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::DocumentRole
DocumentRole
Definition: GeoDataDocument.h:39
Marble::GeoDataLatLonBox
A class that defines a 2D bounding box for geographic data.
Definition: GeoDataLatLonBox.h:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:49 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal