• 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
GeoDataTreeModel.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 2010 Thibaut Gridel <tgridel@free.fr>
9 //
10 
11 
12 // Own
13 #include "GeoDataTreeModel.h"
14 
15 // Qt
16 #include <QModelIndex>
17 #include <QFile>
18 #include <QList>
19 #include <QPixmap>
20 #include <QItemSelectionModel>
21 
22 // Marble
23 #include "GeoDataObject.h"
24 #include "GeoDataDocument.h"
25 #include "GeoDataContainer.h"
26 #include "GeoDataExtendedData.h"
27 #include "GeoDataPlacemark.h"
28 #include "GeoDataStyle.h"
29 #include "GeoDataTypes.h"
30 #include "FileManager.h"
31 #include "MarbleDebug.h"
32 #include "MarblePlacemarkModel.h"
33 
34 using namespace Marble;
35 
36 class GeoDataTreeModel::Private {
37  public:
38  Private( QAbstractItemModel* model );
39  ~Private();
40 
41  void checkParenting( GeoDataObject *object );
42 
43  GeoDataDocument* m_rootDocument;
44  bool m_ownsRootDocument;
45  QItemSelectionModel m_selectionModel;
46 };
47 
48 GeoDataTreeModel::Private::Private( QAbstractItemModel *model ) :
49  m_rootDocument( new GeoDataDocument ),
50  m_ownsRootDocument( true ),
51  m_selectionModel( model )
52 {
53  // nothing to do
54 }
55 
56 GeoDataTreeModel::Private::~Private()
57 {
58  if ( m_ownsRootDocument ) {
59  delete m_rootDocument;
60  }
61 }
62 
63 void GeoDataTreeModel::Private::checkParenting( GeoDataObject *object )
64 {
65  GeoDataContainer *container;
66  if( object->nodeType() == GeoDataTypes::GeoDataDocumentType
67  || object->nodeType() == GeoDataTypes::GeoDataFolderType ) {
68  container = static_cast<GeoDataContainer*>( object );
69  foreach( GeoDataFeature *child, container->featureList() ) {
70  if ( child->parent() != container ) {
71  qWarning() << "Parenting mismatch for " << child->name();
72  Q_ASSERT( 0 );
73  }
74  }
75  }
76 }
77 
78 GeoDataTreeModel::GeoDataTreeModel( QObject *parent )
79  : QAbstractItemModel( parent ),
80  d( new Private( this ) )
81 {
82 }
83 
84 GeoDataTreeModel::~GeoDataTreeModel()
85 {
86  delete d;
87 }
88 
89 bool GeoDataTreeModel::hasChildren( const QModelIndex &parent ) const
90 {
91  GeoDataObject *parentItem;
92  if ( parent.column() > 0 ) {
93  return false;
94  }
95 
96  if ( !parent.isValid() ) {
97  parentItem = d->m_rootDocument;
98  } else {
99  parentItem = static_cast<GeoDataObject*>( parent.internalPointer() );
100  }
101 
102  if ( !parentItem ) {
103  return false;
104  }
105 
106  if ( parentItem->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
107  GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( parentItem );
108  return dynamic_cast<GeoDataMultiGeometry*>( placemark->geometry() );
109  }
110 
111  if ( parentItem->nodeType() == GeoDataTypes::GeoDataFolderType
112  || parentItem->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
113  GeoDataContainer *container = static_cast<GeoDataContainer*>( parentItem );
114  return container->size();
115  }
116 
117  if ( parentItem->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) {
118  GeoDataMultiGeometry *geometry = static_cast<GeoDataMultiGeometry*>( parentItem );
119  return geometry->size();
120  }
121 
122  return false;
123 }
124 
125 int GeoDataTreeModel::rowCount( const QModelIndex &parent ) const
126 {
127 // mDebug() << "rowCount";
128  GeoDataObject *parentItem;
129  if ( parent.column() > 0 ) {
130 // mDebug() << "rowCount bad column";
131  return 0;
132  }
133 
134  if ( !parent.isValid() ) {
135 // mDebug() << "rowCount root parent";
136  parentItem = d->m_rootDocument;
137  } else {
138  parentItem = static_cast<GeoDataObject*>( parent.internalPointer() );
139  }
140 
141  if ( !parentItem ) {
142 // mDebug() << "rowCount bad parent";
143  return 0;
144  }
145 
146  if ( parentItem->nodeType() == GeoDataTypes::GeoDataFolderType
147  || parentItem->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
148  GeoDataContainer *container = static_cast<GeoDataContainer*>( parentItem );
149 // mDebug() << "rowCount " << type << "(" << parentItem << ") =" << container->size();
150  return container->size();
151 // } else {
152 // mDebug() << "rowCount bad container " << container;
153  }
154 
155  if ( parentItem->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
156  GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( parentItem );
157  if ( dynamic_cast<GeoDataMultiGeometry*>( placemark->geometry() ) ) {
158 // mDebug() << "rowCount " << type << "(" << parentItem << ") = 1";
159  return 1;
160  }
161  }
162 
163  if ( parentItem->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) {
164  GeoDataMultiGeometry *geometry = static_cast<GeoDataMultiGeometry*>( parentItem );
165 // mDebug() << "rowCount " << parent << " " << type << " " << geometry->size();
166  return geometry->size();
167 // } else {
168 // mDebug() << "rowCount bad geometry " << geometry;
169  }
170 
171 // mDebug() << "rowcount end";
172  return 0;//parentItem->childCount();
173 }
174 
175 QVariant GeoDataTreeModel::headerData(int section, Qt::Orientation orientation,
176  int role) const
177 {
178  if ( role == Qt::DisplayRole && orientation == Qt::Horizontal )
179  {
180  switch ( section ) {
181  case 0:
182  return tr("Name");
183  break;
184  case 1:
185  return tr("Type");
186  break;
187  case 2:
188  return tr("Popularity");
189  break;
190  case 3:
191  return tr("PopIndex", "Popularity index");
192  break;
193  }
194  }
195  return QVariant();
196 }
197 
198 QVariant GeoDataTreeModel::data( const QModelIndex &index, int role ) const
199 {
200 // mDebug() << "data";
201  if ( !index.isValid() )
202  return QVariant();
203 
204  GeoDataObject *object = static_cast<GeoDataObject*>( index.internalPointer() );
205  if ( role == Qt::DisplayRole ) {
206 
207  if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
208  GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( object );
209  if ( index.column() == 0 ){
210  return QVariant( placemark->name() );
211  }
212  else if ( index.column() == 1 ){
213  return QVariant( placemark->nodeType() );
214  }
215  else if ( index.column() == 2 ){
216  return QVariant( placemark->popularity() );
217  }
218  else if ( index.column() == 3 ){
219  return QVariant( placemark->zoomLevel() );
220  }
221  }
222  if ( object->nodeType() == GeoDataTypes::GeoDataFolderType
223  || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
224  GeoDataFeature *feature = static_cast<GeoDataFeature*>( object );
225  if ( index.column() == 0 ){
226  return QVariant( feature->name() );
227  }
228  else if ( index.column() == 1 ){
229  return QVariant( feature->nodeType() );
230  }
231  }
232 
233  GeoDataGeometry *geometry = dynamic_cast<GeoDataGeometry*>( object );
234  if ( geometry && index.column() == 1 ){
235  return QVariant( geometry->nodeType() );
236  }
237 
238  GeoDataObject *item = dynamic_cast<GeoDataObject*>( object );
239  if ( item && index.column() == 1 ){
240  return QVariant( item->nodeType() );
241  }
242 
243  }
244  else if ( role == Qt::CheckStateRole
245  && index.column() == 0 ) {
246  if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
247  GeoDataPlacemark *feature = static_cast<GeoDataPlacemark*>( object );
248  const char* type = feature->geometry()->nodeType();
249  if ( type == GeoDataTypes::GeoDataLineStringType
250  || type == GeoDataTypes::GeoDataPolygonType
251  || type == GeoDataTypes::GeoDataLinearRingType
252  || type == GeoDataTypes::GeoDataMultiGeometryType
253  || type == GeoDataTypes::GeoDataTrackType
254  ) {
255  if ( feature->isGloballyVisible() ) {
256  return QVariant( Qt::Checked );
257  } else if ( feature->isVisible() ) {
258  return QVariant( Qt::PartiallyChecked );
259  } else {
260  return QVariant( Qt::Unchecked );
261  }
262  }
263  } else if ( object->nodeType() == GeoDataTypes::GeoDataFolderType
264  || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
265  GeoDataFeature *feature = static_cast<GeoDataFeature*>( object );
266  if ( feature->isGloballyVisible() ) {
267  return QVariant( Qt::Checked );
268  } else if ( feature->isVisible() ) {
269  return QVariant( Qt::PartiallyChecked );
270  } else {
271  return QVariant( Qt::Unchecked );
272  }
273  }
274  }
275  else if ( role == Qt::DecorationRole
276  && index.column() == 0 ) {
277  if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType
278  || object->nodeType() == GeoDataTypes::GeoDataFolderType
279  || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
280  GeoDataFeature *feature = static_cast<GeoDataFeature*>( object );
281  return QVariant(feature->style()->iconStyle().icon());
282  }
283  } else if ( role == Qt::ToolTipRole
284  && index.column() == 0 ) {
285  if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType
286  || object->nodeType() == GeoDataTypes::GeoDataFolderType
287  || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
288  GeoDataFeature *feature = static_cast<GeoDataFeature*>( object );
289  return QVariant( feature->description() );
290  }
291  } else if ( role == MarblePlacemarkModel::ObjectPointerRole ) {
292  return qVariantFromValue( object );
293  } else if ( role == MarblePlacemarkModel::PopularityIndexRole ) {
294  if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
295  GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( object );
296  return QVariant( placemark->zoomLevel() );
297  }
298  } else if ( role == MarblePlacemarkModel::PopularityRole ) {
299  if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
300  GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( object );
301  return QVariant( placemark->popularity() );
302  }
303  } else if ( role == MarblePlacemarkModel::CoordinateRole ) {
304  if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
305  GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( object );
306  return qVariantFromValue( placemark->coordinate() );
307  }
308  }
309 
310  return QVariant();
311 }
312 
313 QModelIndex GeoDataTreeModel::index( int row, int column, const QModelIndex &parent ) const
314 {
315 // mDebug() << "index";
316  if ( !hasIndex( row, column, parent ) ) {
317 // mDebug() << "index bad index";
318  return QModelIndex();
319  }
320 
321  GeoDataObject *parentItem;
322 
323  if ( !parent.isValid() )
324  parentItem = d->m_rootDocument;
325  else
326  parentItem = static_cast<GeoDataObject*>( parent.internalPointer() );
327 
328  if ( !parentItem ) {
329 // mDebug() << "index bad parent";
330  return QModelIndex();
331  }
332 
333  GeoDataObject *childItem = 0;
334 
335 
336  if ( parentItem->nodeType() == GeoDataTypes::GeoDataFolderType
337  || parentItem->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
338  GeoDataContainer *container = static_cast<GeoDataContainer*>( parentItem );
339  childItem = container->child( row );
340  return createIndex( row, column, childItem );
341  }
342 
343  if ( parentItem->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
344  GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>( parentItem );
345  childItem = placemark->geometry();
346  if ( dynamic_cast<GeoDataMultiGeometry*>( childItem ) ) {
347  return createIndex( row, column, childItem );
348  }
349  }
350 
351  if ( parentItem->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) {
352  GeoDataMultiGeometry *geometry = static_cast<GeoDataMultiGeometry*>( parentItem );
353  childItem = geometry->child( row );
354  return createIndex( row, column, childItem );
355  }
356 
357  return QModelIndex();
358 }
359 
360 QModelIndex GeoDataTreeModel::parent( const QModelIndex &index ) const
361 {
362 // mDebug() << "parent";
363  if ( !index.isValid() ) {
364 // mDebug() << "parent bad index";
365  return QModelIndex();
366  }
367 
368 
369  GeoDataObject *childObject = static_cast<GeoDataObject*>( index.internalPointer() );
370  if ( childObject ) {
371 
373  GeoDataObject *parentObject = childObject->parent();
374  if ( parentObject == d->m_rootDocument )
375  {
376  return QModelIndex();
377  }
378 
379  GeoDataObject *greatParentObject = parentObject->parent();
380 
381  // Avoid crashing when there is no grandparent
382  if ( greatParentObject == 0 )
383  {
384  return QModelIndex();
385  }
386 
387  // greatParent can be a container
388  if ( greatParentObject->nodeType() == GeoDataTypes::GeoDataFolderType
389  || greatParentObject->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
390  GeoDataContainer *greatparentContainer = static_cast<GeoDataContainer*>( greatParentObject );
391  GeoDataFeature *parentFeature = static_cast<GeoDataFeature*>( parentObject );
392 // mDebug() << "parent " << childObject->nodeType() << "(" << childObject << ") = "
393 // << parentObject->nodeType() << "[" << greatparentContainer->childPosition( parentFeature ) << "](" << parentObject << ")";
394  return createIndex( greatparentContainer->childPosition( parentFeature ), 0, parentObject );
395  }
396 
397  // greatParent can be a placemark
398  if ( greatParentObject->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) {
399 // GeoDataPlacemark *greatparentPlacemark = static_cast<GeoDataPlacemark*>( greatParentObject );
400 // mDebug() << "parent " << childObject->nodeType() << "(" << childObject << ") = "
401 // << parentObject->nodeType() << "[0](" << parentObject << ")";
402  return createIndex( 0, 0, parentObject );
403  }
404 
405  // greatParent can be a multigeometry
406  if ( greatParentObject->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) {
407  GeoDataMultiGeometry *greatparentMultiGeo = static_cast<GeoDataMultiGeometry*>( greatParentObject );
408  GeoDataGeometry *parentGeometry = static_cast<GeoDataGeometry*>( parentObject );
409 // mDebug() << "parent " << childObject->nodeType() << "(" << childObject << ") = "
410 // << parentObject->nodeType() << "[" << greatParentItem->childPosition( parentGeometry ) << "](" << parentObject << ")";
411  return createIndex( greatparentMultiGeo->childPosition( parentGeometry ), 0, parentObject );
412  }
413  }
414 
415 // mDebug() << "parent unknown index";
416  return QModelIndex();
417 }
418 
419 int GeoDataTreeModel::columnCount( const QModelIndex & ) const
420 {
421  return 4;
422 }
423 
424 bool GeoDataTreeModel::setData ( const QModelIndex & index, const QVariant & value, int role )
425 {
426  if ( !index.isValid() )
427  return false;
428 
429  GeoDataObject *object = static_cast<GeoDataObject*>( index.internalPointer() );
430  if ( role == Qt::CheckStateRole ) {
431  if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType
432  || object->nodeType() == GeoDataTypes::GeoDataFolderType
433  || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
434  GeoDataFeature *feature = static_cast<GeoDataFeature*>( object );
435  feature->setVisible( value.toBool() );
436  mDebug() << "setData " << feature->name() << " " << value.toBool();
437  updateFeature( feature );
438  return true;
439  }
440  } else if ( role == Qt::EditRole ) {
441  if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType
442  || object->nodeType() == GeoDataTypes::GeoDataFolderType
443  || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
444  GeoDataFeature *feature = static_cast<GeoDataFeature*>( object );
445  feature->setName( value.toString() );
446  mDebug() << "setData " << feature->name() << " " << value.toString();
447  updateFeature( feature );
448  return true;
449  }
450  }
451 
452  return false;
453 }
454 
455 Qt::ItemFlags GeoDataTreeModel::flags ( const QModelIndex & index ) const
456 {
457  if ( !index.isValid() )
458  return Qt::NoItemFlags;
459 
460  GeoDataObject *object = static_cast<GeoDataObject*>( index.internalPointer() );
461  if ( object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
462  GeoDataDocument *document = static_cast<GeoDataDocument*>( object );
463  if( document->documentRole() == UserDocument ) {
464  return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEditable;
465  }
466  }
467  if( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType
468  || object->nodeType() == GeoDataTypes::GeoDataFolderType ) {
469  GeoDataFeature *feature = static_cast<GeoDataFeature*>( object );
470  GeoDataObject *parent = feature->parent();
471  while( parent->nodeType() != GeoDataTypes::GeoDataDocumentType ) {
472  parent = parent->parent();
473  }
474  GeoDataDocument *document = static_cast<GeoDataDocument*>( parent );
475  if( document->documentRole() == UserDocument ) {
476  return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEditable;;
477  }
478  }
479 
480  if ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType
481  || object->nodeType() == GeoDataTypes::GeoDataFolderType
482  || object->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
483  return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
484  }
485  return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
486 }
487 
488 
489 QModelIndex GeoDataTreeModel::index( GeoDataObject *object )
490 {
491  //It first runs bottom-top, storing every ancestor of the object, and
492  //then goes top-down retrieving the QModelIndex of every ancestor until reaching the
493  //index of the requested object.
494  //The TreeModel contains: Documents, Folders, Placemarks, MultiGeometries
495  //and Geometries that are children of MultiGeometries
496  //You can not call this function with an element that does not belong to the tree
497 
498  Q_ASSERT( ( object->nodeType() == GeoDataTypes::GeoDataFolderType )
499  || ( object->nodeType() == GeoDataTypes::GeoDataDocumentType )
500  || ( object->nodeType() == GeoDataTypes::GeoDataPlacemarkType )
501  || ( ( object->nodeType() == GeoDataTypes::GeoDataLineStringType )
502  && ( object->parent()->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) )
503  || ( ( object->nodeType() == GeoDataTypes::GeoDataLinearRingType )
504  && ( object->parent()->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) )
505  || ( ( object->nodeType() == GeoDataTypes::GeoDataPointType )
506  && ( object->parent()->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) )
507  || ( ( object->nodeType() == GeoDataTypes::GeoDataPolygonType )
508  && ( object->parent()->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) )
509  || ( object->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) );
510 
511 
512  QList< GeoDataObject* > ancestors;
513 
514  GeoDataObject *itup = object; //Iterator to reach the top of the GeoDataDocument (bottom-up)
515 
516  while ( itup && ( itup != d->m_rootDocument ) ) {//We reach up to the rootDocument
517 
518  ancestors.append( itup );
519  itup = itup->parent() ;
520  }
521 
522  QModelIndex itdown;
523  if ( !ancestors.isEmpty() ) {
524 
525  itdown = index( d->m_rootDocument->childPosition( static_cast<GeoDataFeature*>( ancestors.last() ) ),0,QModelIndex());//Iterator to go top down
526 
527  GeoDataObject *parent;
528 
529  while ( ( ancestors.size() > 1 ) ) {
530 
531  parent = static_cast<GeoDataObject*>( ancestors.last() );
532 
533  if ( ( parent->nodeType() == GeoDataTypes::GeoDataFolderType )
534  || ( parent->nodeType() == GeoDataTypes::GeoDataDocumentType ) ) {
535 
536  ancestors.removeLast();
537  itdown = index( static_cast<GeoDataContainer*>(parent)->childPosition( static_cast<GeoDataFeature*>( ancestors.last() ) ) , 0, itdown );
538  } else if ( ( parent->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) ) {
539  //The only child of the model is a Geometry or MultiGeometry object
540  //If it is a geometry object, we should be on the bottom of the list
541  ancestors.removeLast();
542  if( ancestors.last()->nodeType() == GeoDataTypes::GeoDataMultiGeometryType )
543  itdown = index( 0 , 0, itdown );
544  else
545  itdown = QModelIndex();
546 
547  } else if ( ( parent->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) ) {
548  //The child is one of the geometry children of MultiGeometry
549  ancestors.removeLast();
550  itdown = index( static_cast<GeoDataMultiGeometry*>(parent)->childPosition( static_cast<GeoDataGeometry*>(ancestors.last()) ) , 0, itdown );
551  }
552  else { //If the element is not found on the tree, it will be added under m_rootDocument
553  itdown = QModelIndex();
554  break;
555  }
556  }
557  }
558  return itdown;
559 }
560 
561 QItemSelectionModel *GeoDataTreeModel::selectionModel()
562 {
563  return &d->m_selectionModel;
564 }
565 
566 int GeoDataTreeModel::addFeature( GeoDataContainer *parent, GeoDataFeature *feature, int row )
567 {
568  if ( parent && feature ) {
569 
570  QModelIndex modelindex = index( parent );
571  //index(GeoDataObject*) returns QModelIndex() if parent == m_rootDocument
572  //or if parent is not found on the tree.
573  //We must check that we are in top of the tree (then QModelIndex() is
574  //the right parent to insert the child object) or that we have a valid QModelIndex
575 
576  if( ( parent == d->m_rootDocument ) || modelindex.isValid() )
577  {
578  if( row < 0 || row > parent->size()) {
579  row = parent->size();
580  }
581  beginInsertRows( modelindex , row , row );
582  parent->insert( feature, row );
583  d->checkParenting( parent );
584  endInsertRows();
585  emit added(feature);
586  }
587  else
588  qWarning() << "GeoDataTreeModel::addFeature (parent " << parent << " - feature" << feature << ") : parent not found on the TreeModel";
589  }
590  else
591  qWarning() << "Null pointer in call to GeoDataTreeModel::addFeature (parent " << parent << " - feature" << feature << ")";
592  return row; //-1 if it failed, the relative index otherwise.
593 }
594 
595 int GeoDataTreeModel::addDocument( GeoDataDocument *document )
596 {
597  return addFeature( d->m_rootDocument, document );
598 }
599 
600 bool GeoDataTreeModel::removeFeature( GeoDataContainer *parent, int row )
601 {
602  if ( row<parent->size() ) {
603  beginRemoveRows( index( parent ), row , row );
604  GeoDataFeature *feature = parent->child( row );
605  parent->remove( row );
606  emit removed(feature);
607  endRemoveRows();
608  return true;
609  }
610  return false; //Tried to remove a row that is not contained in the parent.
611 }
612 
613 int GeoDataTreeModel::removeFeature( const GeoDataFeature *feature )
614 {
615  if ( feature && ( feature!=d->m_rootDocument ) ) {
616 
617  //We check to see we are not removing the
618  //top level element m_rootDocument
619 
620  GeoDataObject *parent = static_cast< GeoDataObject* >( feature->parent() );
621 
622  if ( ( parent->nodeType() == GeoDataTypes::GeoDataFolderType )
623  || ( parent->nodeType() == GeoDataTypes::GeoDataDocumentType ) ) {
624 
625  int row = static_cast< GeoDataContainer* >( feature->parent() )->childPosition( feature );
626  if ( row != -1 ) {
627  bool removed = removeFeature( static_cast< GeoDataContainer* >( feature->parent() ) , row );
628  if( removed ) {
629  return row;
630  }
631  }
632  //The feature is not contained in the parent it points to
633  }
634  }
635  return -1; //We can not remove the rootDocument
636 }
637 
638 void GeoDataTreeModel::updateFeature( GeoDataFeature *feature )
639 {
640  GeoDataContainer *container = static_cast<GeoDataContainer*>( feature->parent() );
641  int index = removeFeature( feature );
642  Q_ASSERT( index != -1 );
643  addFeature( container, feature, index );
644 }
645 
646 void GeoDataTreeModel::removeDocument( int index )
647 {
648  removeFeature( d->m_rootDocument, index );
649 }
650 
651 void GeoDataTreeModel::removeDocument( GeoDataDocument *document )
652 {
653  removeFeature( document );
654 }
655 
656 void GeoDataTreeModel::update()
657 {
658 // mDebug() << "updating GeoDataTreeModel";
659  beginResetModel();
660  endResetModel();
661 }
662 
663 void GeoDataTreeModel::setRootDocument( GeoDataDocument* document )
664 {
665  beginResetModel();
666  if ( d->m_ownsRootDocument ) {
667  delete d->m_rootDocument;
668  }
669 
670  d->m_ownsRootDocument = ( document == 0 );
671  d->m_rootDocument = document ? document : new GeoDataDocument;
672  endResetModel();
673 }
674 
675 GeoDataDocument * GeoDataTreeModel::rootDocument()
676 {
677  return d->m_rootDocument;
678 }
679 
680 #include "GeoDataTreeModel.moc"
GeoDataDocument.h
Marble::GeoDataGeometry::nodeType
virtual const char * nodeType() const
Provides type information for downcasting a GeoData.
Definition: GeoDataGeometry.cpp:77
Marble::GeoDataTypes::GeoDataMultiGeometryType
const char * GeoDataMultiGeometryType
Definition: GeoDataTypes.cpp:56
FileManager.h
Marble::GeoDataTreeModel::addFeature
int addFeature(GeoDataContainer *parent, GeoDataFeature *feature, int row=-1)
Definition: GeoDataTreeModel.cpp:566
Marble::GeoDataTypes::GeoDataLinearRingType
const char * GeoDataLinearRingType
Definition: GeoDataTypes.cpp:48
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:64
Marble::GeoDataTypes::GeoDataPointType
const char * GeoDataPointType
Definition: GeoDataTypes.cpp:64
Marble::GeoDataContainer::child
GeoDataFeature * child(int)
returns the requested child item
Definition: GeoDataContainer.cpp:132
Marble::GeoDataTypes::GeoDataPolygonType
const char * GeoDataPolygonType
Definition: GeoDataTypes.cpp:65
Marble::GeoDataTreeModel::rootDocument
GeoDataDocument * rootDocument()
Definition: GeoDataTreeModel.cpp:675
GeoDataContainer.h
Marble::GeoDataTreeModel::setRootDocument
void setRootDocument(GeoDataDocument *document)
Sets the root document to use.
Definition: GeoDataTreeModel.cpp:663
Marble::GeoDataMultiGeometry::child
GeoDataGeometry * child(int)
returns the requested child item
Definition: GeoDataMultiGeometry.cpp:154
Marble::GeoDataObject
A base class for all geodata objects.
Definition: GeoDataObject.h:48
Marble::GeoDataTreeModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: GeoDataTreeModel.cpp:419
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:47
Marble::GeoDataTypes::GeoDataPlacemarkType
const char * GeoDataPlacemarkType
Definition: GeoDataTypes.cpp:62
Marble::GeoDataTypes::GeoDataDocumentType
const char * GeoDataDocumentType
Definition: GeoDataTypes.cpp:34
Marble::GeoDataTreeModel::removeFeature
bool removeFeature(GeoDataContainer *parent, int index)
Definition: GeoDataTreeModel.cpp:600
Marble::GeoDataObject::parent
virtual GeoDataObject * parent() const
Provides the parent of the object in GeoDataContainers.
Definition: GeoDataObject.cpp:65
GeoDataStyle.h
Marble::GeoDataFeature::isVisible
bool isVisible() const
Return whether this feature is visible or not.
Definition: GeoDataFeature.cpp:581
Marble::GeoDataContainer
A base class that can hold GeoDataFeatures.
Definition: GeoDataContainer.h:47
Marble::GeoDataFeature::description
QString description() const
Return the text description of the feature.
Definition: GeoDataFeature.cpp:513
Marble::GeoDataPlacemark::coordinate
GeoDataCoordinates coordinate(const QDateTime &dateTime=QDateTime(), bool *iconAtCoordinates=0) const
Return the coordinates of the placemark at time dateTime as a GeoDataCoordinates. ...
Definition: GeoDataPlacemark.cpp:78
Marble::GeoDataFeature::style
const GeoDataStyle * style() const
Return the style assigned to the placemark.
Definition: GeoDataFeature.cpp:624
Marble::GeoDataTreeModel::~GeoDataTreeModel
~GeoDataTreeModel()
Destroys the GeoDataModel.
Definition: GeoDataTreeModel.cpp:84
Marble::GeoDataTreeModel::data
QVariant data(const QModelIndex &index, int role) const
Definition: GeoDataTreeModel.cpp:198
Marble::GeoDataFeature::zoomLevel
int zoomLevel() const
Return the popularity index of the placemark.
Definition: GeoDataFeature.cpp:707
GeoDataExtendedData.h
Marble::GeoDataTreeModel::added
void added(GeoDataObject *object)
QObject
Marble::MarblePlacemarkModel::ObjectPointerRole
The pointer to a specific object.
Definition: MarblePlacemarkModel.h:62
Marble::GeoDataPlacemark::geometry
GeoDataGeometry * geometry() const
The geometry of the GeoDataPlacemark is to be rendered to the marble map along with the icon at the c...
Definition: GeoDataPlacemark.cpp:63
Marble::GeoDataTreeModel::GeoDataTreeModel
GeoDataTreeModel(QObject *parent=0)
Creates a new GeoDataTreeModel.
Definition: GeoDataTreeModel.cpp:78
MarbleDebug.h
Marble::GeoDataMultiGeometry::size
int size() const
Definition: GeoDataMultiGeometry.cpp:64
Marble::GeoDataTreeModel::addDocument
int addDocument(GeoDataDocument *document)
Definition: GeoDataTreeModel.cpp:595
Marble::GeoDataObject::nodeType
virtual const char * nodeType() const =0
Provides type information for downcasting a GeoNode.
Marble::GeoDataFeature::popularity
qint64 popularity() const
Return the popularity of the feature.
Definition: GeoDataFeature.cpp:718
Marble::GeoDataTreeModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Definition: GeoDataTreeModel.cpp:424
Marble::GeoDataTreeModel::hasChildren
virtual bool hasChildren(const QModelIndex &parent) const
Definition: GeoDataTreeModel.cpp:89
Marble::GeoDataFeature::setName
void setName(const QString &value)
Set a new name for this feature.
Definition: GeoDataFeature.cpp:485
Marble::GeoDataTreeModel::removeDocument
void removeDocument(int index)
Definition: GeoDataTreeModel.cpp:646
Marble::UserDocument
Definition: GeoDataDocument.h:42
GeoDataObject.h
Marble::GeoDataTypes::GeoDataFolderType
const char * GeoDataFolderType
Definition: GeoDataTypes.cpp:38
Marble::GeoDataDocument::documentRole
DocumentRole documentRole() const
Definition: GeoDataDocument.cpp:57
Marble::GeoDataTreeModel::removed
void removed(GeoDataObject *object)
insert and remove row don't trigger any signal that proxies forward this signal will refresh geometry...
Marble::GeoDataStyle::iconStyle
GeoDataIconStyle & iconStyle() const
Return the icon style of this style.
Definition: GeoDataStyle.cpp:113
Marble::GeoDataTreeModel::update
void update()
Definition: GeoDataTreeModel.cpp:656
Marble::GeoDataTreeModel::parent
QModelIndex parent(const QModelIndex &index) const
Definition: GeoDataTreeModel.cpp:360
Marble::GeoDataContainer::size
int size() const
size of the container
Definition: GeoDataContainer.cpp:179
Marble::GeoDataContainer::insert
void insert(GeoDataFeature *other, int index)
Definition: GeoDataContainer.cpp:158
Marble::GeoDataTypes::GeoDataLineStringType
const char * GeoDataLineStringType
Definition: GeoDataTypes.cpp:49
MarblePlacemarkModel.h
Marble::MarblePlacemarkModel::PopularityRole
The popularity.
Definition: MarblePlacemarkModel.h:61
Marble::GeoDataTreeModel::updateFeature
void updateFeature(GeoDataFeature *feature)
Definition: GeoDataTreeModel.cpp:638
GeoDataPlacemark.h
GeoDataTreeModel.h
Marble::GeoDataContainer::childPosition
int childPosition(const GeoDataFeature *child) const
returns the position of an item in the list
Definition: GeoDataContainer.cpp:145
Marble::GeoDataFeature::isGloballyVisible
bool isGloballyVisible() const
Return whether this feature is visible or not in the context of its parenting.
Definition: GeoDataFeature.cpp:592
QAbstractItemModel
Marble::GeoDataIconStyle::icon
QImage icon() const
Definition: GeoDataIconStyle.cpp:99
Marble::MarblePlacemarkModel::PopularityIndexRole
The popularity index.
Definition: MarblePlacemarkModel.h:60
Marble::GeoDataFeature::setVisible
void setVisible(bool value)
Set a new value for visibility.
Definition: GeoDataFeature.cpp:586
Marble::MarblePlacemarkModel::CoordinateRole
The GeoDataCoordinates coordinate.
Definition: MarblePlacemarkModel.h:53
Marble::GeoDataTreeModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: GeoDataTreeModel.cpp:175
Marble::GeoDataFeature
A base class for all geodata features.
Definition: GeoDataFeature.h:55
Marble::GeoDataFeature::name
QString name() const
The name of the feature.
Definition: GeoDataFeature.cpp:480
Marble::GeoDataContainer::featureList
QVector< GeoDataFeature * > featureList() const
A convenience function that returns all features in this container.
Definition: GeoDataContainer.cpp:124
Marble::GeoDataContainer::remove
void remove(int index)
Definition: GeoDataContainer.cpp:173
Marble::GeoDataMultiGeometry
Definition: GeoDataMultiGeometry.h:33
Marble::GeoDataTreeModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: GeoDataTreeModel.cpp:313
Marble::GeoDataTreeModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const
Definition: GeoDataTreeModel.cpp:455
Marble::GeoDataTreeModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Return the number of Items in the Model.
Definition: GeoDataTreeModel.cpp:125
GeoDataTypes.h
Marble::GeoDataMultiGeometry::childPosition
int childPosition(GeoDataGeometry *child)
returns the position of an item in the list
Definition: GeoDataMultiGeometry.cpp:167
Marble::GeoDataTypes::GeoDataTrackType
const char * GeoDataTrackType
Definition: GeoDataTypes.cpp:77
Marble::GeoDataFeature::nodeType
virtual const char * nodeType() const
Provides type information for downcasting a GeoData.
Definition: GeoDataFeature.cpp:94
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::GeoDataTreeModel::selectionModel
QItemSelectionModel * selectionModel()
Definition: GeoDataTreeModel.cpp:561
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 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