• 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
PlacemarkLayout.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-2008 Inge Wallin <ingwa@kde.org>
10 // Copyright 2010-2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
11 //
12 
13 #include "PlacemarkLayout.h"
14 
15 #include <QAbstractItemModel>
16 #include <QList>
17 #include <QPoint>
18 #include <QVector>
19 #include <QVectorIterator>
20 #include <QFont>
21 #include <QFontMetrics>
22 #include <QItemSelectionModel>
23 #include <qmath.h>
24 
25 #include "GeoDataPlacemark.h"
26 #include "GeoDataStyle.h"
27 #include "GeoDataTypes.h"
28 
29 #include "MarbleDebug.h"
30 #include "MarbleGlobal.h"
31 #include "PlacemarkLayer.h"
32 #include "MarbleClock.h"
33 #include "MarblePlacemarkModel.h"
34 #include "MarbleDirs.h"
35 #include "ViewportParams.h"
36 #include "TileId.h"
37 #include "TileCoordsPyramid.h"
38 #include "VisiblePlacemark.h"
39 #include "MathHelper.h"
40 
41 namespace Marble
42 {
43 
44 QVector<GeoDataFeature::GeoDataVisualCategory> sortedVisualCategories()
45 {
46  QVector<GeoDataFeature::GeoDataVisualCategory> visualCategories;
47 
48  visualCategories
49  << GeoDataFeature::SmallCity
50  << GeoDataFeature::SmallCountyCapital
51  << GeoDataFeature::SmallStateCapital
52  << GeoDataFeature::SmallNationCapital
53  << GeoDataFeature::MediumCity
54  << GeoDataFeature::MediumCountyCapital
55  << GeoDataFeature::MediumStateCapital
56  << GeoDataFeature::MediumNationCapital
57  << GeoDataFeature::BigCity
58  << GeoDataFeature::BigCountyCapital
59  << GeoDataFeature::BigStateCapital
60  << GeoDataFeature::BigNationCapital
61  << GeoDataFeature::LargeCity
62  << GeoDataFeature::LargeCountyCapital
63  << GeoDataFeature::LargeStateCapital
64  << GeoDataFeature::LargeNationCapital
65  << GeoDataFeature::Nation
66  << GeoDataFeature::Mountain
67  << GeoDataFeature::Volcano
68  << GeoDataFeature::Mons
69  << GeoDataFeature::Valley
70  << GeoDataFeature::Continent
71  << GeoDataFeature::Ocean
72  << GeoDataFeature::OtherTerrain
73  << GeoDataFeature::Crater
74  << GeoDataFeature::Mare
75  << GeoDataFeature::GeographicPole
76  << GeoDataFeature::MagneticPole
77  << GeoDataFeature::ShipWreck
78  << GeoDataFeature::AirPort
79  << GeoDataFeature::Observatory
80  << GeoDataFeature::AccomodationCamping
81  << GeoDataFeature::AccomodationHostel
82  << GeoDataFeature::AccomodationHotel
83  << GeoDataFeature::AccomodationMotel
84  << GeoDataFeature::AccomodationYouthHostel
85  << GeoDataFeature::AmenityLibrary
86  << GeoDataFeature::EducationCollege
87  << GeoDataFeature::EducationSchool
88  << GeoDataFeature::EducationUniversity
89  << GeoDataFeature::FoodBar
90  << GeoDataFeature::FoodBiergarten
91  << GeoDataFeature::FoodCafe
92  << GeoDataFeature::FoodFastFood
93  << GeoDataFeature::FoodPub
94  << GeoDataFeature::FoodRestaurant
95  << GeoDataFeature::HealthDoctors
96  << GeoDataFeature::HealthHospital
97  << GeoDataFeature::HealthPharmacy
98  << GeoDataFeature::MoneyBank
99  << GeoDataFeature::ShoppingBeverages
100  << GeoDataFeature::ShoppingHifi
101  << GeoDataFeature::ShoppingSupermarket
102  << GeoDataFeature::TouristAttraction
103  << GeoDataFeature::TouristCastle
104  << GeoDataFeature::TouristCinema
105  << GeoDataFeature::TouristMonument
106  << GeoDataFeature::TouristMuseum
107  << GeoDataFeature::TouristRuin
108  << GeoDataFeature::TouristTheatre
109  << GeoDataFeature::TouristThemePark
110  << GeoDataFeature::TouristViewPoint
111  << GeoDataFeature::TouristZoo
112  << GeoDataFeature::TransportAerodrome
113  << GeoDataFeature::TransportAirportTerminal
114  << GeoDataFeature::TransportBusStation
115  << GeoDataFeature::TransportBusStop
116  << GeoDataFeature::TransportCarShare
117  << GeoDataFeature::TransportFuel
118  << GeoDataFeature::TransportParking
119  << GeoDataFeature::TransportTrainStation
120  << GeoDataFeature::ReligionPlaceOfWorship
121  << GeoDataFeature::ReligionBahai
122  << GeoDataFeature::ReligionBuddhist
123  << GeoDataFeature::ReligionChristian
124  << GeoDataFeature::ReligionHindu
125  << GeoDataFeature::ReligionJain
126  << GeoDataFeature::ReligionJewish
127  << GeoDataFeature::ReligionShinto
128  << GeoDataFeature::ReligionSikh;
129 
130  qSort( visualCategories );
131 
132  return visualCategories;
133 }
134 
135 
136 PlacemarkLayout::PlacemarkLayout( QAbstractItemModel *placemarkModel,
137  QItemSelectionModel *selectionModel,
138  MarbleClock *clock,
139  QObject* parent )
140  : QObject( parent ),
141  m_selectionModel( selectionModel ),
142  m_clock( clock ),
143  m_acceptedVisualCategories( sortedVisualCategories() ),
144  m_showPlaces( false ),
145  m_showCities( false ),
146  m_showTerrain( false ),
147  m_showOtherPlaces( false ),
148  m_showLandingSites( false ),
149  m_showCraters( false ),
150  m_showMaria( false ),
151  m_maxLabelHeight( 0 ),
152  m_styleResetRequested( true )
153 {
154  m_placemarkModel.setSourceModel( placemarkModel );
155  m_placemarkModel.setDynamicSortFilter( true );
156  m_placemarkModel.setSortRole( MarblePlacemarkModel::PopularityIndexRole );
157  m_placemarkModel.sort( 0, Qt::AscendingOrder );
158 
159  connect( m_selectionModel, SIGNAL( selectionChanged( QItemSelection,
160  QItemSelection) ),
161  this, SLOT(requestStyleReset()) );
162 
163  connect( &m_placemarkModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
164  this, SLOT(resetCacheData()) );
165  connect( &m_placemarkModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
166  this, SLOT(addPlacemarks(QModelIndex,int,int)) );
167  connect( &m_placemarkModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
168  this, SLOT(removePlacemarks(QModelIndex,int,int)) );
169  connect( &m_placemarkModel, SIGNAL(modelReset()),
170  this, SLOT(resetCacheData()) );
171 }
172 
173 PlacemarkLayout::~PlacemarkLayout()
174 {
175  styleReset();
176 }
177 
178 void PlacemarkLayout::setShowPlaces( bool show )
179 {
180  m_showPlaces = show;
181 }
182 
183 void PlacemarkLayout::setShowCities( bool show )
184 {
185  m_showCities = show;
186 }
187 
188 void PlacemarkLayout::setShowTerrain( bool show )
189 {
190  m_showTerrain = show;
191 }
192 
193 void PlacemarkLayout::setShowOtherPlaces( bool show )
194 {
195  m_showOtherPlaces = show;
196 }
197 
198 void PlacemarkLayout::setShowLandingSites( bool show )
199 {
200  m_showLandingSites = show;
201 }
202 
203 void PlacemarkLayout::setShowCraters( bool show )
204 {
205  m_showCraters = show;
206 }
207 
208 void PlacemarkLayout::setShowMaria( bool show )
209 {
210  m_showMaria = show;
211 }
212 
213 void PlacemarkLayout::requestStyleReset()
214 {
215  mDebug() << "Style reset requested.";
216  m_styleResetRequested = true;
217 }
218 
219 void PlacemarkLayout::styleReset()
220 {
221  m_paintOrder.clear();
222  m_labelArea = 0;
223  qDeleteAll( m_visiblePlacemarks );
224  m_visiblePlacemarks.clear();
225  m_maxLabelHeight = maxLabelHeight();
226  m_styleResetRequested = false;
227 }
228 
229 QVector<const GeoDataPlacemark*> PlacemarkLayout::whichPlacemarkAt( const QPoint& curpos )
230 {
231  if ( m_styleResetRequested ) {
232  styleReset();
233  }
234 
235  QVector<const GeoDataPlacemark*> ret;
236 
237  foreach( VisiblePlacemark* mark, m_paintOrder ) {
238  if ( mark->labelRect().contains( curpos )
239  || QRect( mark->symbolPosition(), mark->symbolPixmap().size() ).contains( curpos ) ) {
240  ret.append( mark->placemark() );
241  }
242  }
243 
244  return ret;
245 }
246 
247 int PlacemarkLayout::maxLabelHeight() const
248 {
249  int maxLabelHeight = 0;
250 
251  for ( int i = 0; i < m_placemarkModel.rowCount(); ++i ) {
252  QModelIndex index = m_placemarkModel.index( i, 0 );
253  const GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>(qvariant_cast<GeoDataObject*>(index.data( MarblePlacemarkModel::ObjectPointerRole ) ));
254  if ( placemark ) {
255  const GeoDataStyle* style = placemark->style();
256  QFont labelFont = style->labelStyle().font();
257  int textHeight = QFontMetrics( labelFont ).height();
258  if ( textHeight > maxLabelHeight )
259  maxLabelHeight = textHeight;
260  }
261  }
262 
263  //mDebug() <<"Detected maxLabelHeight: " << maxLabelHeight;
264  return maxLabelHeight;
265 }
266 
268 void PlacemarkLayout::addPlacemarks( QModelIndex parent, int first, int last )
269 {
270  Q_ASSERT( first < m_placemarkModel.rowCount() );
271  Q_ASSERT( last < m_placemarkModel.rowCount() );
272  for( int i=first; i<=last; ++i ) {
273  QModelIndex index = m_placemarkModel.index( i, 0, parent );
274  Q_ASSERT( index.isValid() );
275  const GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>(qvariant_cast<GeoDataObject*>(index.data( MarblePlacemarkModel::ObjectPointerRole ) ));
276  const GeoDataCoordinates coordinates = placemarkIconCoordinates( placemark );
277  if ( !coordinates.isValid() ) {
278  continue;
279  }
280 
281  int zoomLevel = placemark->zoomLevel();
282  TileId key = TileId::fromCoordinates( coordinates, zoomLevel );
283  m_placemarkCache[key].append( placemark );
284  }
285  requestStyleReset();
286  emit repaintNeeded();
287 }
288 
289 void PlacemarkLayout::removePlacemarks( QModelIndex parent, int first, int last )
290 {
291  Q_ASSERT( first < m_placemarkModel.rowCount() );
292  Q_ASSERT( last < m_placemarkModel.rowCount() );
293  for( int i=first; i<=last; ++i ) {
294  QModelIndex index = m_placemarkModel.index( i, 0, parent );
295  Q_ASSERT( index.isValid() );
296  const GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>(qvariant_cast<GeoDataObject*>( index.data( MarblePlacemarkModel::ObjectPointerRole ) ));
297  const GeoDataCoordinates coordinates = placemarkIconCoordinates( placemark );
298  if ( !coordinates.isValid() ) {
299  continue;
300  }
301 
302  int zoomLevel = placemark->zoomLevel();
303  TileId key = TileId::fromCoordinates( coordinates, zoomLevel );
304  m_placemarkCache[key].removeAll( placemark );
305  }
306  emit repaintNeeded();
307 }
308 
309 void PlacemarkLayout::resetCacheData()
310 {
311  const int rowCount = m_placemarkModel.rowCount();
312 
313  m_placemarkCache.clear();
314  requestStyleReset();
315  addPlacemarks( m_placemarkModel.index( 0, 0 ), 0, rowCount );
316  emit repaintNeeded();
317 }
318 
319 QSet<TileId> PlacemarkLayout::visibleTiles( const ViewportParams *viewport ) const
320 {
321  int zoomLevel = qLn( viewport->radius() *4 / 256 ) / qLn( 2.0 );
322 
330  qreal north, south, east, west;
331  viewport->viewLatLonAltBox().boundaries(north, south, east, west);
332  QSet<TileId> tileIdSet;
333  QVector<QRectF> geoRects;
334  if( west <= east ) {
335  geoRects << QRectF(west, north, east - west, south - north);
336  } else {
337  geoRects << QRectF(west, north, M_PI - west, south - north);
338  geoRects << QRectF(-M_PI, north, east + M_PI, south - north);
339  }
340  foreach( QRectF geoRect, geoRects ) {
341  TileId key;
342  QRect rect;
343 
344  key = TileId::fromCoordinates( GeoDataCoordinates(geoRect.left(), north, 0), zoomLevel);
345  rect.setLeft( key.x() );
346  rect.setTop( key.y() );
347 
348  key = TileId::fromCoordinates( GeoDataCoordinates(geoRect.right(), south, 0), zoomLevel);
349  rect.setRight( key.x() );
350  rect.setBottom( key.y() );
351 
352  TileCoordsPyramid pyramid(0, zoomLevel );
353  pyramid.setBottomLevelCoords( rect );
354 
355  for ( int level = pyramid.topLevel(); level <= pyramid.bottomLevel(); ++level ) {
356  QRect const coords = pyramid.coords( level );
357  int x1, y1, x2, y2;
358  coords.getCoords( &x1, &y1, &x2, &y2 );
359  for ( int x = x1; x <= x2; ++x ) {
360  for ( int y = y1; y <= y2; ++y ) {
361  TileId const tileId( 0, level, x, y );
362  tileIdSet.insert(tileId);
363  }
364  }
365  }
366  }
367 
368  return tileIdSet;
369 }
370 
371 QVector<VisiblePlacemark *> PlacemarkLayout::generateLayout( const ViewportParams *viewport )
372 {
373  m_runtimeTrace.clear();
374  if ( m_placemarkModel.rowCount() <= 0 )
375  return QVector<VisiblePlacemark *>();
376 
377  if ( m_styleResetRequested ) {
378  styleReset();
379  }
380 
381  if ( m_maxLabelHeight == 0 ) {
382  return QVector<VisiblePlacemark *>();
383  }
384 
385  const int secnumber = viewport->height() / m_maxLabelHeight + 1;
386  m_rowsection.clear();
387  m_rowsection.resize(secnumber);
388 
389  m_paintOrder.clear();
390  m_labelArea = 0;
391 
396  const QModelIndexList selectedIndexes = m_selectionModel->selection().indexes();
397 
398  for ( int i = 0; i < selectedIndexes.count(); ++i ) {
399  const QModelIndex index = selectedIndexes.at( i );
400  const GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>(qvariant_cast<GeoDataObject*>(index.data( MarblePlacemarkModel::ObjectPointerRole ) ));
401  Q_ASSERT(placemark);
402  const GeoDataCoordinates coordinates = placemarkIconCoordinates( placemark );
403 
404  if ( !coordinates.isValid() ) {
405  continue;
406  }
407 
408  qreal x = 0;
409  qreal y = 0;
410 
411  if ( !viewport->viewLatLonAltBox().contains( coordinates ) ||
412  ! viewport->screenCoordinates( coordinates, x, y ))
413  {
414  delete m_visiblePlacemarks.take( placemark );
415  continue;
416  }
417 
418  if( layoutPlacemark( placemark, x, y, true) ) {
419  // Make sure not to draw more placemarks on the screen than
420  // specified by placemarksOnScreenLimit().
421  if ( placemarksOnScreenLimit( viewport->size() ) )
422  break;
423  }
424 
425  }
426 
430  const QItemSelection selection = m_selectionModel->selection();
431 
432  QList<TileId> tileIdList = visibleTiles( viewport ).toList();
433  qSort( tileIdList );
434  QList<const GeoDataPlacemark*> placemarkList;
435  foreach ( const TileId &tileId, tileIdList ) {
436  placemarkList += m_placemarkCache.value( tileId );
437  }
438 
439  foreach ( const GeoDataPlacemark *placemark, placemarkList ) {
440  const GeoDataCoordinates coordinates = placemarkIconCoordinates( placemark );
441  if ( !coordinates.isValid() ) {
442  continue;
443  }
444 
445  int zoomLevel = placemark->zoomLevel();
446  if ( zoomLevel > 18 ) {
447  break;
448  }
449 
450  qreal x = 0;
451  qreal y = 0;
452 
453  if ( !viewport->viewLatLonAltBox().contains( coordinates ) ||
454  ! viewport->screenCoordinates( coordinates, x, y )) {
455  delete m_visiblePlacemarks.take( placemark );
456  continue;
457  }
458 
459  if ( !placemark->isGloballyVisible() ) {
460  continue;
461  }
462 
463  const GeoDataFeature::GeoDataVisualCategory visualCategory = placemark->visualCategory();
464 
465  // Skip city marks if we're not showing cities.
466  if ( !m_showCities
467  && visualCategory >= GeoDataFeature::SmallCity
468  && visualCategory <= GeoDataFeature::Nation )
469  continue;
470 
471  // Skip terrain marks if we're not showing terrain.
472  if ( !m_showTerrain
473  && visualCategory >= GeoDataFeature::Mountain
474  && visualCategory <= GeoDataFeature::OtherTerrain )
475  continue;
476 
477  // Skip other places if we're not showing other places.
478  if ( !m_showOtherPlaces
479  && visualCategory >= GeoDataFeature::GeographicPole
480  && visualCategory <= GeoDataFeature::Observatory )
481  continue;
482 
483  // Skip landing sites if we're not showing landing sites.
484  if ( !m_showLandingSites
485  && visualCategory >= GeoDataFeature::MannedLandingSite
486  && visualCategory <= GeoDataFeature::UnmannedHardLandingSite )
487  continue;
488 
489  // Skip craters if we're not showing craters.
490  if ( !m_showCraters
491  && visualCategory == GeoDataFeature::Crater )
492  continue;
493 
494  // Skip maria if we're not showing maria.
495  if ( !m_showMaria
496  && visualCategory == GeoDataFeature::Mare )
497  continue;
498 
499  if ( !m_showPlaces
500  && visualCategory >= GeoDataFeature::GeographicPole
501  && visualCategory <= GeoDataFeature::Observatory )
502  continue;
503 
509  bool isSelected = false;
510  foreach ( const QModelIndex &index, selection.indexes() ) {
511  const GeoDataPlacemark *mark = dynamic_cast<GeoDataPlacemark*>(qvariant_cast<GeoDataObject*>(index.data( MarblePlacemarkModel::ObjectPointerRole ) ));
512  if (mark == placemark ) {
513  isSelected = true;
514  break;
515  }
516  }
517  if ( isSelected )
518  continue;
519 
520  if( layoutPlacemark( placemark, x, y, isSelected ) ) {
521  // Make sure not to draw more placemarks on the screen than
522  // specified by placemarksOnScreenLimit().
523  if ( placemarksOnScreenLimit( viewport->size() ) )
524  break;
525  }
526  }
527 
528  m_runtimeTrace = QString("Placemarks: %1 Drawn: %2").arg( placemarkList.count() ).arg( m_paintOrder.size() );
529  return m_paintOrder;
530 }
531 
532 QString PlacemarkLayout::runtimeTrace() const
533 {
534  return m_runtimeTrace;
535 }
536 
537 bool PlacemarkLayout::layoutPlacemark( const GeoDataPlacemark *placemark, qreal x, qreal y, bool selected )
538 {
539  // Choose Section
540 
541  // Find out whether the area around the placemark is covered already.
542  // If there's not enough space free don't add a VisiblePlacemark here.
543  const GeoDataStyle* style = placemark->style();
544 
545  QRectF labelRect;
546  if( !placemark->name().isEmpty() ) {
547  labelRect = roomForLabel( style, x, y, placemark->name() );
548  if ( labelRect.isNull() ) {
549  return false;
550  }
551  }
552 
553  // Find the corresponding visible placemark
554  VisiblePlacemark *mark = m_visiblePlacemarks.value( placemark );
555  if ( !mark ) {
556  // If there is no visible placemark yet for this index,
557  // create a new one...
558  mark = new VisiblePlacemark( placemark );
559  m_visiblePlacemarks.insert( placemark, mark );
560  }
561 
562  // Finally save the label position on the map.
563  QPointF hotSpot = mark->hotSpot();
564 
565  if( mark->selected() != selected ) {
566  mark->setSelected( selected );
567  }
568  mark->setSymbolPosition( QPoint( x - qRound( hotSpot.x() ),
569  y - qRound( hotSpot.y() ) ) );
570  mark->setLabelRect( labelRect );
571 
572  if ( !labelRect.isEmpty() ) {
573  // Add the current placemark to the matching row and its
574  // direct neighbors.
575  int idx = y / m_maxLabelHeight;
576  if ( idx - 1 >= 0 )
577  m_rowsection[ idx - 1 ].append( mark );
578  m_rowsection[ idx ].append( mark );
579  if ( idx + 1 < m_rowsection.size() )
580  m_rowsection[ idx + 1 ].append( mark );
581  }
582 
583  m_paintOrder.append( mark );
584  m_labelArea += labelRect.width() * labelRect.height();
585  return true;
586 }
587 
588 GeoDataCoordinates PlacemarkLayout::placemarkIconCoordinates( const GeoDataPlacemark *placemark ) const
589 {
590  bool ok;
591  GeoDataCoordinates coordinates = placemark->coordinate( m_clock->dateTime(), &ok );
592  if ( !ok && qBinaryFind( m_acceptedVisualCategories, placemark->visualCategory() )
593  != m_acceptedVisualCategories.constEnd() ) {
594  ok = true;
595  }
596 
597  if ( ok ) {
598  return coordinates;
599  }
600 
601  return GeoDataCoordinates();
602 }
603 
604 QRectF PlacemarkLayout::roomForLabel( const GeoDataStyle * style,
605  const qreal x, const qreal y,
606  const QString &labelText ) const
607 {
608  QFont labelFont = style->labelStyle().font();
609  int textHeight = QFontMetrics( labelFont ).height();
610 
611  int textWidth;
612  if ( style->labelStyle().glow() ) {
613  labelFont.setWeight( 75 ); // Needed to calculate the correct pixmap size;
614  textWidth = ( QFontMetrics( labelFont ).width( labelText )
615  + qRound( 2 * s_labelOutlineWidth ) );
616  } else {
617  textWidth = ( QFontMetrics( labelFont ).width( labelText ) );
618  }
619 
620  const QVector<VisiblePlacemark*> currentsec = m_rowsection.at( y / m_maxLabelHeight );
621 
622  if ( style->labelStyle().alignment() == GeoDataLabelStyle::Corner ) {
623  const int symbolWidth = style->iconStyle().icon().width();
624 
625  // Check the four possible positions by going through all of them
626  for( int i=0; i<4; ++i ) {
627  const qreal xPos = ( i/2 == 0 ) ? x + symbolWidth / 2 + 1 :
628  x - symbolWidth / 2 - 1 - textWidth;
629  const qreal yPos = ( i%2 == 0 ) ? y :
630  y - textHeight;
631  const QRectF labelRect = QRectF( xPos, yPos, textWidth, textHeight );
632 
633  // Check if there is another label or symbol that overlaps.
634  bool isRoom = true;
635  QVector<VisiblePlacemark*>::const_iterator beforeItEnd = currentsec.constEnd();
636  for ( QVector<VisiblePlacemark*>::ConstIterator beforeIt = currentsec.constBegin();
637  beforeIt != beforeItEnd;
638  ++beforeIt ) {
639  if ( labelRect.intersects( (*beforeIt)->labelRect()) ) {
640  isRoom = false;
641  break;
642  }
643  }
644 
645  if ( isRoom ) {
646  // claim the place immediately if it hasn't been used yet
647  return labelRect;
648  }
649  }
650  }
651  else if ( style->labelStyle().alignment() == GeoDataLabelStyle::Center ) {
652  bool isRoom = true;
653  QRectF labelRect( x - textWidth / 2, y - textHeight / 2,
654  textWidth, textHeight );
655 
656  // Check if there is another label or symbol that overlaps.
657  QVector<VisiblePlacemark*>::const_iterator beforeItEnd = currentsec.constEnd();
658  for ( QVector<VisiblePlacemark*>::ConstIterator beforeIt = currentsec.constBegin();
659  beforeIt != beforeItEnd; ++beforeIt )
660  {
661  if ( labelRect.intersects( (*beforeIt)->labelRect() ) ) {
662  isRoom = false;
663  break;
664  }
665  }
666 
667  if ( isRoom ) {
668  // claim the place immediately if it hasn't been used yet
669  return labelRect;
670  }
671  }
672 
673  return QRectF(); // At this point there is no space left
674  // for the rectangle anymore.
675 }
676 
677 bool PlacemarkLayout::placemarksOnScreenLimit( const QSize &screenSize ) const
678 {
679  int ratio = ( m_labelArea * 100 ) / ( screenSize.width() * screenSize.height() );
680  return ratio >= 40;
681 }
682 
683 }
684 
685 #include "PlacemarkLayout.moc"
Marble::GeoDataFeature::TouristAttraction
Definition: GeoDataFeature.h:197
Marble::GeoDataFeature::TransportTrainStation
Definition: GeoDataFeature.h:219
TileId.h
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataFeature::LargeCountyCapital
Definition: GeoDataFeature.h:95
Marble::GeoDataFeature::FoodPub
Definition: GeoDataFeature.h:179
Marble::GeoDataFeature::TransportCarShare
Definition: GeoDataFeature.h:213
Marble::VisiblePlacemark::symbolPixmap
const QPixmap & symbolPixmap() const
Returns the pixmap of the place mark symbol.
Definition: VisiblePlacemark.cpp:38
Marble::VisiblePlacemark
A class which represents the visible place marks on a map.
Definition: VisiblePlacemark.h:38
Marble::ViewportParams::size
QSize size() const
Definition: ViewportParams.cpp:260
Marble::GeoDataFeature::AccomodationCamping
Definition: GeoDataFeature.h:160
TileCoordsPyramid.h
Marble::GeoDataLatLonBox::boundaries
void boundaries(qreal &north, qreal &south, qreal &east, qreal &west, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Definition: GeoDataLatLonBox.cpp:198
Marble::GeoDataFeature::ReligionHindu
Definition: GeoDataFeature.h:227
Marble::PlacemarkLayout::repaintNeeded
void repaintNeeded()
Marble::GeoDataFeature::Continent
Definition: GeoDataFeature.h:105
Marble::GeoDataFeature::MediumStateCapital
Definition: GeoDataFeature.h:88
Marble::GeoDataFeature::Mons
Definition: GeoDataFeature.h:103
Marble::GeoDataFeature::SmallNationCapital
Definition: GeoDataFeature.h:85
Marble::GeoDataFeature::TouristViewPoint
Definition: GeoDataFeature.h:205
Marble::PlacemarkLayout::setShowOtherPlaces
void setShowOtherPlaces(bool show)
Definition: PlacemarkLayout.cpp:193
Marble::GeoDataObject
A base class for all geodata objects.
Definition: GeoDataObject.h:48
Marble::GeoDataFeature::Mountain
Definition: GeoDataFeature.h:101
Marble::GeoDataFeature::HealthHospital
Definition: GeoDataFeature.h:184
GeoDataStyle.h
Marble::PlacemarkLayout::setShowCities
void setShowCities(bool show)
Definition: PlacemarkLayout.cpp:183
Marble::GeoDataFeature::Crater
Definition: GeoDataFeature.h:110
PlacemarkLayer.h
Marble::ViewportParams::viewLatLonAltBox
const GeoDataLatLonAltBox & viewLatLonAltBox() const
Definition: ViewportParams.cpp:305
Marble::GeoDataFeature::style
const GeoDataStyle * style() const
Return the style assigned to the placemark.
Definition: GeoDataFeature.cpp:624
Marble::VisiblePlacemark::symbolPosition
const QPoint & symbolPosition() const
Returns the position of the place mark symbol on the map.
Definition: VisiblePlacemark.cpp:60
Marble::VisiblePlacemark::labelRect
const QRectF & labelRect() const
Returns the area covered by the place mark name label on the map.
Definition: VisiblePlacemark.cpp:110
Marble::PlacemarkLayout::runtimeTrace
QString runtimeTrace() const
Definition: PlacemarkLayout.cpp:532
Marble::GeoDataFeature::ReligionPlaceOfWorship
Definition: GeoDataFeature.h:223
Marble::GeoDataFeature::zoomLevel
int zoomLevel() const
Return the popularity index of the placemark.
Definition: GeoDataFeature.cpp:707
Marble::GeoDataFeature::OtherTerrain
Definition: GeoDataFeature.h:107
Marble::GeoDataFeature::ShoppingBeverages
Definition: GeoDataFeature.h:192
Marble::GeoDataFeature::AmenityLibrary
Definition: GeoDataFeature.h:167
Marble::GeoDataFeature::Valley
Definition: GeoDataFeature.h:104
Marble::GeoDataFeature::ReligionBuddhist
Definition: GeoDataFeature.h:225
Marble::GeoDataLatLonAltBox::contains
virtual bool contains(const GeoDataCoordinates &) const
Definition: GeoDataLatLonAltBox.cpp:171
Marble::GeoDataFeature::AirPort
Definition: GeoDataFeature.h:117
QObject
Marble::MarblePlacemarkModel::ObjectPointerRole
The pointer to a specific object.
Definition: MarblePlacemarkModel.h:62
Marble::GeoDataFeature::Nation
Definition: GeoDataFeature.h:98
MarbleDebug.h
Marble::GeoDataFeature::AccomodationMotel
Definition: GeoDataFeature.h:163
Marble::GeoDataFeature::ReligionJain
Definition: GeoDataFeature.h:228
Marble::ViewportParams::height
int height() const
Definition: ViewportParams.cpp:255
Marble::GeoDataFeature::AccomodationYouthHostel
Definition: GeoDataFeature.h:164
Marble::MarbleClock::dateTime
QDateTime dateTime() const
Returns the internal date and time.
Definition: MarbleClock.cpp:110
Marble::GeoDataFeature::LargeStateCapital
Definition: GeoDataFeature.h:96
Marble::s_labelOutlineWidth
static const qreal s_labelOutlineWidth
Definition: VisiblePlacemark.h:29
Marble::GeoDataStyle::labelStyle
GeoDataLabelStyle & labelStyle() const
Return the label style of this style.
Definition: GeoDataStyle.cpp:128
PlacemarkLayout.h
Marble::GeoDataFeature::SmallStateCapital
Definition: GeoDataFeature.h:84
Marble::GeoDataFeature::MediumCountyCapital
Definition: GeoDataFeature.h:87
Marble::GeoDataFeature::MoneyBank
Definition: GeoDataFeature.h:189
Marble::GeoDataFeature::FoodCafe
Definition: GeoDataFeature.h:177
Marble::GeoDataStyle
an addressable style group
Definition: GeoDataStyle.h:55
Marble::GeoDataFeature::AccomodationHostel
Definition: GeoDataFeature.h:161
Marble::GeoDataFeature::MannedLandingSite
Definition: GeoDataFeature.h:126
Marble::GeoDataFeature::ReligionShinto
Definition: GeoDataFeature.h:230
Marble::GeoDataFeature::Volcano
Definition: GeoDataFeature.h:102
MathHelper.h
Marble::GeoDataFeature::TransportAerodrome
Definition: GeoDataFeature.h:209
Marble::GeoDataFeature::AccomodationHotel
Definition: GeoDataFeature.h:162
Marble::GeoDataFeature::Ocean
Definition: GeoDataFeature.h:106
Marble::PlacemarkLayout::setShowPlaces
void setShowPlaces(bool show)
Definition: PlacemarkLayout.cpp:178
MarbleDirs.h
Marble::sortedVisualCategories
QVector< GeoDataFeature::GeoDataVisualCategory > sortedVisualCategories()
Definition: PlacemarkLayout.cpp:44
Marble::GeoDataFeature::TransportBusStation
Definition: GeoDataFeature.h:211
Marble::PlacemarkLayout::removePlacemarks
void removePlacemarks(QModelIndex index, int first, int last)
Definition: PlacemarkLayout.cpp:289
Marble::GeoDataFeature::TouristCinema
Definition: GeoDataFeature.h:199
Marble::ViewportParams::screenCoordinates
bool screenCoordinates(const qreal lon, const qreal lat, qreal &x, qreal &y) const
Get the screen coordinates corresponding to geographical coordinates in the map.
Definition: ViewportParams.cpp:357
Marble::GeoDataFeature::HealthDoctors
Definition: GeoDataFeature.h:183
Marble::GeoDataFeature::ShoppingSupermarket
Definition: GeoDataFeature.h:194
Marble::GeoDataFeature::FoodFastFood
Definition: GeoDataFeature.h:178
Marble::PlacemarkLayout::generateLayout
QVector< VisiblePlacemark * > generateLayout(const ViewportParams *viewport)
Definition: PlacemarkLayout.cpp:371
MarblePlacemarkModel.h
Marble::GeoDataFeature::TouristRuin
Definition: GeoDataFeature.h:202
MarbleGlobal.h
Marble::PlacemarkLayout::whichPlacemarkAt
QVector< const GeoDataPlacemark * > whichPlacemarkAt(const QPoint &pos)
Returns a list of model indexes that are at position pos.
Definition: PlacemarkLayout.cpp:229
GeoDataPlacemark.h
Marble::GeoDataFeature::ReligionBahai
Definition: GeoDataFeature.h:224
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
VisiblePlacemark.h
Marble::GeoDataFeature::isGloballyVisible
bool isGloballyVisible() const
Return whether this feature is visible or not in the context of its parenting.
Definition: GeoDataFeature.cpp:592
Marble::GeoDataFeature::MediumNationCapital
Definition: GeoDataFeature.h:89
QAbstractItemModel
Marble::GeoDataFeature::TransportFuel
Definition: GeoDataFeature.h:214
Marble::GeoDataFeature::BigCity
Definition: GeoDataFeature.h:90
Marble::PlacemarkLayout::PlacemarkLayout
PlacemarkLayout(QAbstractItemModel *placemarkModel, QItemSelectionModel *selectionModel, MarbleClock *clock, QObject *parent=0)
Creates a new place mark layout.
Definition: PlacemarkLayout.cpp:136
Marble::GeoDataLabelStyle::Center
Definition: GeoDataLabelStyle.h:39
Marble::GeoDataFeature::TouristZoo
Definition: GeoDataFeature.h:206
Marble::GeoDataFeature::MagneticPole
Definition: GeoDataFeature.h:115
MarbleClock.h
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::MarblePlacemarkModel::PopularityIndexRole
The popularity index.
Definition: MarblePlacemarkModel.h:60
Marble::GeoDataFeature::LargeCity
Definition: GeoDataFeature.h:94
Marble::GeoDataFeature::TouristTheatre
Definition: GeoDataFeature.h:203
Marble::GeoDataFeature::ReligionSikh
Definition: GeoDataFeature.h:231
Marble::GeoDataFeature::ReligionJewish
Definition: GeoDataFeature.h:229
Marble::GeoDataFeature::BigNationCapital
Definition: GeoDataFeature.h:93
Marble::GeoDataFeature::EducationUniversity
Definition: GeoDataFeature.h:172
Marble::GeoDataFeature::BigCountyCapital
Definition: GeoDataFeature.h:91
Marble::TileId
Definition: TileId.h:27
Marble::PlacemarkLayout::~PlacemarkLayout
~PlacemarkLayout()
Destroys the place mark painter.
Definition: PlacemarkLayout.cpp:173
Marble::PlacemarkLayout::setShowTerrain
void setShowTerrain(bool show)
Definition: PlacemarkLayout.cpp:188
Marble::GeoDataFeature::visualCategory
GeoDataVisualCategory visualCategory() const
Return the symbol index of the placemark.
Definition: GeoDataFeature.cpp:675
Marble::GeoDataFeature::EducationCollege
Definition: GeoDataFeature.h:170
Marble::GeoDataFeature::FoodBar
Definition: GeoDataFeature.h:175
Marble::ViewportParams::radius
int radius() const
Definition: ViewportParams.cpp:195
Marble::GeoDataFeature::UnmannedHardLandingSite
Definition: GeoDataFeature.h:129
Marble::TileId::fromCoordinates
static TileId fromCoordinates(const GeoDataCoordinates &coords, int popularity)
Definition: TileId.cpp:62
Marble::GeoDataLabelStyle::Corner
Definition: GeoDataLabelStyle.h:39
Marble::GeoDataFeature::name
QString name() const
The name of the feature.
Definition: GeoDataFeature.cpp:480
Marble::PlacemarkLayout::setShowCraters
void setShowCraters(bool show)
Definition: PlacemarkLayout.cpp:203
Marble::GeoDataFeature::GeographicPole
Definition: GeoDataFeature.h:114
Marble::VisiblePlacemark::placemark
const GeoDataPlacemark * placemark() const
Returns the index of the place mark model which is associated with this visible place mark...
Definition: VisiblePlacemark.cpp:33
Marble::GeoDataFeature::ReligionChristian
Definition: GeoDataFeature.h:226
Marble::GeoDataFeature::MediumCity
Definition: GeoDataFeature.h:86
Marble::GeoDataFeature::SmallCountyCapital
Definition: GeoDataFeature.h:83
Marble::PlacemarkLayout::setShowMaria
void setShowMaria(bool show)
Definition: PlacemarkLayout.cpp:208
Marble::GeoDataFeature::TouristCastle
Definition: GeoDataFeature.h:198
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
Marble::GeoDataFeature::TransportBusStop
Definition: GeoDataFeature.h:212
Marble::PlacemarkLayout::setShowLandingSites
void setShowLandingSites(bool show)
Definition: PlacemarkLayout.cpp:198
Marble::GeoDataLabelStyle::font
QFont font() const
Return the current font of the label.
Definition: GeoDataLabelStyle.cpp:120
Marble::GeoDataFeature::GeoDataVisualCategory
GeoDataVisualCategory
A categorization of a placemark as defined by ...FIXME.
Definition: GeoDataFeature.h:75
Marble::GeoDataFeature::Observatory
Definition: GeoDataFeature.h:118
GeoDataTypes.h
Marble::GeoDataCoordinates::isValid
bool isValid() const
Returns.
Definition: GeoDataCoordinates.cpp:624
Marble::GeoDataFeature::ShoppingHifi
Definition: GeoDataFeature.h:193
Marble::GeoDataFeature::LargeNationCapital
Definition: GeoDataFeature.h:97
Marble::PlacemarkLayout::addPlacemarks
void addPlacemarks(QModelIndex index, int first, int last)
feed an internal QMap of placemarks with TileId as key when model changes
Definition: PlacemarkLayout.cpp:268
Marble::MarbleClock
Definition: MarbleClock.h:25
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::GeoDataFeature::TouristMuseum
Definition: GeoDataFeature.h:201
Marble::GeoDataFeature::TouristMonument
Definition: GeoDataFeature.h:200
Marble::GeoDataFeature::ShipWreck
Definition: GeoDataFeature.h:116
Marble::GeoDataFeature::HealthPharmacy
Definition: GeoDataFeature.h:185
Marble::GeoDataFeature::Mare
Definition: GeoDataFeature.h:111
Marble::GeoDataFeature::TransportAirportTerminal
Definition: GeoDataFeature.h:210
Marble::PlacemarkLayout::requestStyleReset
void requestStyleReset()
Definition: PlacemarkLayout.cpp:213
Marble::GeoDataFeature::EducationSchool
Definition: GeoDataFeature.h:171
Marble::GeoDataFeature::BigStateCapital
Definition: GeoDataFeature.h:92
Marble::GeoDataFeature::FoodBiergarten
Definition: GeoDataFeature.h:176
Marble::GeoDataFeature::FoodRestaurant
Definition: GeoDataFeature.h:180
Marble::GeoDataFeature::TransportParking
Definition: GeoDataFeature.h:215
Marble::GeoDataFeature::TouristThemePark
Definition: GeoDataFeature.h:204
Marble::PlacemarkLayout::resetCacheData
void resetCacheData()
Definition: PlacemarkLayout.cpp:309
Marble::GeoDataFeature::SmallCity
Definition: GeoDataFeature.h:82
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 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