diff --git a/src/apps/marble-qt/qtmain.cpp b/src/apps/marble-qt/qtmain.cpp index b66ad6326..683702b7d 100644 --- a/src/apps/marble-qt/qtmain.cpp +++ b/src/apps/marble-qt/qtmain.cpp @@ -1,250 +1,254 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2006-2007 Torsten Rahn // Copyright 2007 Inge Wallin // #include #include #include #include #include #include #include #include "QtMainWindow.h" #include "MapThemeManager.h" #include "MarbleDirs.h" #include "MarbleDebug.h" #include "MarbleTest.h" #include "MarbleLocale.h" #include "GeoUriParser.h" #ifdef STATIC_BUILD #include Q_IMPORT_PLUGIN(qjpeg) Q_IMPORT_PLUGIN(qsvg) #endif #ifdef Q_OS_MACX //for getting app bundle path #include #endif using namespace Marble; int main(int argc, char *argv[]) { QApplication app(argc, argv); app.setApplicationName( "Marble Virtual Globe" ); app.setOrganizationName( "KDE" ); app.setOrganizationDomain( "kde.org" ); // Widget translation QString lang = QLocale::system().name().section('_', 0, 0); QTranslator translator; translator.load( "marble-" + lang, MarbleDirs::path(QString("lang") ) ); app.installTranslator(&translator); // For non static builds on mac and win // we need to be sure we can find the qt image // plugins. In mac be sure to look in the // application bundle... #ifdef Q_WS_WIN QApplication::addLibraryPath( QApplication::applicationDirPath() + QDir::separator() + "plugins" ); #endif #ifdef Q_OS_MACX QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus); qDebug("Adding qt image plugins to plugin search path..."); CFURLRef myBundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef myMacPath = CFURLCopyFileSystemPath(myBundleRef, kCFURLPOSIXPathStyle); const char *mypPathPtr = CFStringGetCStringPtr(myMacPath,CFStringGetSystemEncoding()); CFRelease(myBundleRef); CFRelease(myMacPath); QString myPath(mypPathPtr); // if we are not in a bundle assume that the app is built // as a non bundle app and that image plugins will be // in system Qt frameworks. If the app is a bundle // lets try to set the qt plugin search path... if (myPath.contains(".app")) { myPath += "/Contents/plugins"; QApplication::addLibraryPath( myPath ); qDebug( "Added %s to plugin search path", qPrintable( myPath ) ); } #endif QString marbleDataPath; int dataPathIndex=0; QString mapThemeId; QString tour; QString coordinatesString; QString distanceString; QString geoUriString; MarbleGlobal::Profiles profiles = MarbleGlobal::detectProfiles(); QStringList args = QApplication::arguments(); if ( args.contains( "-h" ) || args.contains( "--help" ) ) { qWarning() << "Usage: marble [options] [files]"; qWarning(); qWarning() << "[files] can be zero, one or more .kml and/or .gpx files to load and show."; qWarning(); qWarning() << "general options:"; qWarning() << " --marbledatapath= .... Overwrite the compile-time path to map themes and other data"; qWarning() << " --geo-uri= ............ Show map at given geo uri"; qWarning() << " --latlon= ..... Show map at given lat lon coordinates"; qWarning() << " --distance= ......... Set the distance of the observer to the globe (in km)"; qWarning() << " --map= ................. Use map id (e.g. \"earth/openstreetmap/openstreetmap.dgml\")"; qWarning() << " --tour= .............. Load a KML tour from the given file and play it"; qWarning(); qWarning() << "debug options:"; qWarning() << " --debug-info ............... write (more) debugging information to the console"; qWarning() << " --fps ...................... Show the paint performance (paint rate) in the top left corner"; qWarning() << " --runtimeTrace.............. Show the time spent and other debug info of each layer"; qWarning() << " --tile-id................... Write the identifier of texture tiles on top of them"; qWarning() << " --timedemo ................. Measure the paint performance while moving the map and quit"; + qWarning() << " --debugPolygons .............Display the polygon nodes and their index for debugging"; qWarning(); qWarning() << "profile options (note that marble should automatically detect which profile to use. Override that with the options below):"; qWarning() << " --highresolution ........... Enforce the profile for devices with high resolution (e.g. desktop computers)"; qWarning() << " --nohighresolution ......... Deactivate the profile for devices with high resolution (e.g. desktop computers)"; return 0; } for ( int i = 1; i < args.count(); ++i ) { const QString arg = args.at(i); if ( arg == QLatin1String( "--debug-info" ) ) { MarbleDebug::setEnabled( true ); } else if ( arg.startsWith( QLatin1String( "--marbledatapath=" ), Qt::CaseInsensitive ) ) { marbleDataPath = args.at(i).mid(17); } else if ( arg.compare( QLatin1String( "--marbledatapath" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() ) { dataPathIndex = i + 1; marbleDataPath = args.value( dataPathIndex ); ++i; } else if ( arg == QLatin1String( "--highresolution" ) ) { profiles |= MarbleGlobal::HighResolution; } else if ( arg == QLatin1String( "--nohighresolution" ) ) { profiles &= ~MarbleGlobal::HighResolution; } else if ( arg.startsWith( QLatin1String( "--latlon=" ), Qt::CaseInsensitive ) ) { coordinatesString = arg.mid(9); } else if ( arg.compare( QLatin1String( "--latlon" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() ) { ++i; coordinatesString = args.value( i ); } else if ( arg.compare( QLatin1String( "--geo-uri=" ), Qt::CaseInsensitive ) == 0 ) { geoUriString = arg.mid(10); } else if ( arg.compare( QLatin1String( "--geo-uri" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() ) { ++i; geoUriString = args.value(i); } else if ( arg.startsWith( QLatin1String( "--distance=" ), Qt::CaseInsensitive ) ) { distanceString = arg.mid(11); } else if ( arg.compare( QLatin1String( "--distance" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() ) { ++i; distanceString = args.value( i ); } else if ( arg.startsWith( QLatin1String( "--map=" ), Qt::CaseInsensitive ) ) { mapThemeId = arg.mid(6); } else if ( arg.compare( QLatin1String( "--map" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() ) { ++i; mapThemeId = args.value( i ); } else if ( arg.startsWith( QLatin1String( "--tour=" ), Qt::CaseInsensitive ) ) { tour = arg.mid(7); } else if ( arg.compare( QLatin1String( "--tour" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() ) { ++i; tour = args.value( i ); } } MarbleGlobal::getInstance()->setProfiles( profiles ); MarbleLocale::MeasurementSystem const measurement = (MarbleLocale::MeasurementSystem)QLocale::system().measurementSystem(); MarbleGlobal::getInstance()->locale()->setMeasurementSystem( measurement ); QVariantMap cmdLineSettings; if ( !mapThemeId.isEmpty() ) { cmdLineSettings.insert( QLatin1String("mapTheme"), QVariant(mapThemeId) ); } if ( !coordinatesString.isEmpty() ) { bool success = false; const GeoDataCoordinates coordinates = GeoDataCoordinates::fromString(coordinatesString, success); if ( success ) { QVariantList lonLat; lonLat << QVariant( coordinates.longitude(GeoDataCoordinates::Degree) ) << QVariant( coordinates.latitude(GeoDataCoordinates::Degree) ); cmdLineSettings.insert( QLatin1String("lonlat"), QVariant(lonLat) ); } } if ( !distanceString.isEmpty() ) { bool success = false; const qreal distance = distanceString.toDouble(&success); if ( success ) { cmdLineSettings.insert( QLatin1String("distance"), QVariant(distance) ); } } if ( !tour.isEmpty() ) { cmdLineSettings.insert( QLatin1String("tour"), QVariant(tour) ); } cmdLineSettings.insert( QLatin1String("geo-uri"), QVariant(geoUriString) ); MainWindow *window = new MainWindow( marbleDataPath, cmdLineSettings ); window->setAttribute( Qt::WA_DeleteOnClose, true ); // window->marbleWidget()->rotateTo( 0, 0, -90 ); // window->show(); for ( int i = 1; i < args.count(); ++i ) { const QString arg = args.at(i); if ( arg == "--timedemo" ) { window->resize(900, 640); MarbleTest marbleTest( window->marbleWidget() ); marbleTest.timeDemo(); return 0; } else if( arg == "--fps" ) { window->marbleControl()->marbleWidget()->setShowFrameRate( true ); } else if ( arg == "--tile-id" ) { window->marbleControl()->marbleWidget()->setShowTileId(true); } else if( arg == "--runtimeTrace" ) { window->marbleControl()->marbleWidget()->setShowRuntimeTrace( true ); } + else if( arg == "--debugPolygons" ) { + window->marbleControl()->marbleWidget()->setShowDebugPolygons( true ); + } else if ( i != dataPathIndex && QFile::exists( arg ) ) window->addGeoDataFile( arg ); } return app.exec(); } diff --git a/src/lib/marble/ClipPainter.cpp b/src/lib/marble/ClipPainter.cpp index 50e9243e0..f095a8ba4 100644 --- a/src/lib/marble/ClipPainter.cpp +++ b/src/lib/marble/ClipPainter.cpp @@ -1,1160 +1,1170 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2006-2009 Torsten Rahn // Copyright 2007 Inge Wallin // #include "ClipPainter.h" #include #include "MarbleDebug.h" -// #define DEBUG_DRAW_NODES namespace Marble { class ClipPainterPrivate { public: explicit ClipPainterPrivate( ClipPainter * parent ); ClipPainter * q; // true if clipping is on. bool m_doClip; // The limits qreal m_left; qreal m_right; qreal m_top; qreal m_bottom; // Used in the paint process of vectors.. int m_currentSector; int m_previousSector; // int m_debugNodeCount; QPointF m_currentPoint; QPointF m_previousPoint; inline int sector( const QPointF & point ) const; inline QPointF clipTop( qreal m, const QPointF & point ) const; inline QPointF clipLeft( qreal m, const QPointF & point ) const; inline QPointF clipBottom( qreal m, const QPointF & point ) const; inline QPointF clipRight( qreal m, const QPointF & point ) const; inline void initClipRect(); inline void clipPolyObject ( const QPolygonF & sourcePolygon, QVector & clippedPolyObjects, bool isClosed ); inline void clipMultiple( QPolygonF & clippedPolyObject, QVector & clippedPolyObjects, bool isClosed ); inline void clipOnce( QPolygonF & clippedPolyObject, QVector & clippedPolyObjects, bool isClosed ); inline void clipOnceCorner( QPolygonF & clippedPolyObject, QVector & clippedPolyObjects, const QPointF& corner, const QPointF& point, bool isClosed ) const; inline void clipOnceEdge( QPolygonF & clippedPolyObject, QVector & clippedPolyObjects, const QPointF& point, bool isClosed ) const; void labelPosition( const QPolygonF & polygon, QVector& labelNodes, LabelPositionFlags labelPositionFlags); bool pointAllowsLabel( const QPointF& point ); QPointF interpolateLabelPoint( const QPointF& previousPoint, const QPointF& currentPoint, LabelPositionFlags labelPositionFlags ); static inline qreal _m( const QPointF & start, const QPointF & end ); -#ifdef DEBUG_DRAW_NODES void debugDrawNodes( const QPolygonF & ); -#endif qreal m_labelAreaMargin; + + bool m_debugDrawNodes; }; } using namespace Marble; // #define MARBLE_DEBUG ClipPainter::ClipPainter(QPaintDevice * pd, bool clip) : QPainter( pd ), d( new ClipPainterPrivate( this ) ) { d->initClipRect(); // m_debugNodeCount = 0; d->m_doClip = clip; } ClipPainter::ClipPainter() : d( new ClipPainterPrivate( this ) ) { } ClipPainter::~ClipPainter() { delete d; } void ClipPainter::setScreenClip(bool enable) { d->m_doClip = enable; } bool ClipPainter::hasScreenClip() const { return d->m_doClip; } void ClipPainter::drawPolygon ( const QPolygonF & polygon, Qt::FillRule fillRule ) { if ( d->m_doClip ) { d->initClipRect(); QVector clippedPolyObjects; d->clipPolyObject( polygon, clippedPolyObjects, true ); foreach( const QPolygonF & clippedPolyObject, clippedPolyObjects ) { if ( clippedPolyObject.size() > 2 ) { // mDebug() << "Size: " << clippedPolyObject.size(); QPainter::drawPolygon ( clippedPolyObject, fillRule ); // mDebug() << "done"; - #ifdef DEBUG_DRAW_NODES + if (d->m_debugDrawNodes) { d->debugDrawNodes( clippedPolyObject ); - #endif + } } } } else { QPainter::drawPolygon ( polygon, fillRule ); - #ifdef DEBUG_DRAW_NODES + if (d->m_debugDrawNodes) { d->debugDrawNodes( polygon ); - #endif + } } } void ClipPainter::drawPolyline( const QPolygonF & polygon ) { if ( d->m_doClip ) { d->initClipRect(); QVector clippedPolyObjects; d->clipPolyObject( polygon, clippedPolyObjects, false ); foreach( const QPolygonF & clippedPolyObject, clippedPolyObjects ) { if ( clippedPolyObject.size() > 1 ) { // mDebug() << "Size: " << clippedPolyObject.size(); QPainter::drawPolyline ( clippedPolyObject ); // mDebug() << "done"; - #ifdef DEBUG_DRAW_NODES + if (d->m_debugDrawNodes) { d->debugDrawNodes( clippedPolyObject ); - #endif + } } } } else { QPainter::drawPolyline( polygon ); - #ifdef DEBUG_DRAW_NODES + if (d->m_debugDrawNodes) { d->debugDrawNodes( polygon ); - #endif + } } } void ClipPainter::drawPolyline( const QPolygonF & polygon, QVector& labelNodes, LabelPositionFlags positionFlags) { if ( d->m_doClip ) { d->initClipRect(); QVector clippedPolyObjects; d->clipPolyObject( polygon, clippedPolyObjects, false ); foreach( const QPolygonF & clippedPolyObject, clippedPolyObjects ) { if ( clippedPolyObject.size() > 1 ) { // mDebug() << "Size: " << clippedPolyObject.size(); QPainter::drawPolyline ( clippedPolyObject ); // mDebug() << "done"; - #ifdef DEBUG_DRAW_NODES + if (d->m_debugDrawNodes) { d->debugDrawNodes( clippedPolyObject ); - #endif + } d->labelPosition( clippedPolyObject, labelNodes, positionFlags ); } } } else { QPainter::drawPolyline( polygon ); - #ifdef DEBUG_DRAW_NODES + if (d->m_debugDrawNodes) { d->debugDrawNodes( polygon ); - #endif + } d->labelPosition( polygon, labelNodes, positionFlags ); } } void ClipPainterPrivate::labelPosition( const QPolygonF & polygon, QVector& labelNodes, LabelPositionFlags labelPositionFlags) { bool currentAllowsLabel = false; if ( labelPositionFlags.testFlag( LineCenter ) ) { // The Label at the center of the polyline: int labelPosition = static_cast( polygon.size() / 2.0 ); if ( polygon.size() > 0 ) { if ( labelPosition >= polygon.size() ) { labelPosition = polygon.size() - 1; } labelNodes << polygon.at( labelPosition ); } } if ( polygon.size() > 0 && labelPositionFlags.testFlag( LineStart ) ) { if ( pointAllowsLabel( polygon.first() ) ) { labelNodes << polygon.first(); } // The Label at the start of the polyline: for ( int it = 1; it < polygon.size(); ++it ) { currentAllowsLabel = pointAllowsLabel( polygon.at( it ) ); if ( currentAllowsLabel ) { // As polygon.size() > 0 it's ensured that it-1 exists. QPointF node = interpolateLabelPoint( polygon.at( it -1 ), polygon.at( it ), labelPositionFlags ); if ( node != QPointF( -1.0, -1.0 ) ) { labelNodes << node; } break; } } } if ( polygon.size() > 1 && labelPositionFlags.testFlag( LineEnd ) ) { if ( pointAllowsLabel( polygon.at( polygon.size() - 1 ) ) ) { labelNodes << polygon.at( polygon.size() - 1 ); } // The Label at the end of the polyline: for ( int it = polygon.size() - 2; it > 0; --it ) { currentAllowsLabel = pointAllowsLabel( polygon.at( it ) ); if ( currentAllowsLabel ) { QPointF node = interpolateLabelPoint( polygon.at( it + 1 ), polygon.at( it ), labelPositionFlags ); if ( node != QPointF( -1.0, -1.0 ) ) { labelNodes << node; } break; } } } } bool ClipPainterPrivate::pointAllowsLabel( const QPointF& point ) { if ( point.x() > m_labelAreaMargin && point.x() < q->viewport().width() - m_labelAreaMargin && point.y() > m_labelAreaMargin && point.y() < q->viewport().height() - m_labelAreaMargin ) { return true; } return false; } QPointF ClipPainterPrivate::interpolateLabelPoint( const QPointF& previousPoint, const QPointF& currentPoint, LabelPositionFlags labelPositionFlags ) { qreal m = _m( previousPoint, currentPoint ); if ( previousPoint.x() <= m_labelAreaMargin ) { if ( labelPositionFlags.testFlag( IgnoreXMargin ) ) { return QPointF( -1.0, -1.0 ); } return QPointF( m_labelAreaMargin, previousPoint.y() + ( m_labelAreaMargin - previousPoint.x() ) * m ); } else if ( previousPoint.x() >= q->viewport().width() - m_labelAreaMargin ) { if ( labelPositionFlags.testFlag( IgnoreXMargin ) ) { return QPointF( -1.0, -1.0 ); } return QPointF( q->viewport().width() - m_labelAreaMargin, previousPoint.y() - ( previousPoint.x() - q->viewport().width() + m_labelAreaMargin ) * m ); } if ( previousPoint.y() <= m_labelAreaMargin ) { if ( labelPositionFlags.testFlag( IgnoreYMargin ) ) { return QPointF( -1.0, -1.0 ); } return QPointF( previousPoint.x() + ( m_labelAreaMargin - previousPoint.y() ) / m, m_labelAreaMargin ); } else if ( previousPoint.y() >= q->viewport().height() - m_labelAreaMargin ) { if ( labelPositionFlags.testFlag( IgnoreYMargin ) ) { return QPointF( -1.0, -1.0 ); } return QPointF( previousPoint.x() - ( previousPoint.y() - q->viewport().height() + m_labelAreaMargin ) / m, q->viewport().height() - m_labelAreaMargin ); } // mDebug() << Q_FUNC_INFO << "Previous and current node position are allowed!"; return QPointF( -1.0, -1.0 ); } ClipPainterPrivate::ClipPainterPrivate( ClipPainter * parent ) : m_doClip( true ), m_left(0.0), m_right(0.0), m_top(0.0), m_bottom(0.0), m_currentSector(4), m_previousSector(4), m_currentPoint(QPointF()), m_previousPoint(QPointF()), - m_labelAreaMargin(10.0) + m_labelAreaMargin(10.0), + m_debugDrawNodes(false) { q = parent; } void ClipPainterPrivate::initClipRect () { qreal penHalfWidth = q->pen().widthF() / 2.0 + 1.0; m_left = -penHalfWidth; m_right = (qreal)(q->device()->width()) + penHalfWidth; m_top = -penHalfWidth; m_bottom = (qreal)(q->device()->height()) + penHalfWidth; } qreal ClipPainterPrivate::_m( const QPointF & start, const QPointF & end ) { qreal divisor = end.x() - start.x(); if ( std::fabs( divisor ) < 0.000001 ) { // this is in screencoordinates so the difference // between 0, 0.000001 and -0.000001 isn't visible at all divisor = 0.000001; } return ( end.y() - start.y() ) / divisor; } QPointF ClipPainterPrivate::clipTop( qreal m, const QPointF & point ) const { return QPointF( ( m_top - point.y() ) / m + point.x(), m_top ); } QPointF ClipPainterPrivate::clipLeft( qreal m, const QPointF & point ) const { return QPointF( m_left, ( m_left - point.x() ) * m + point.y() ); } QPointF ClipPainterPrivate::clipBottom( qreal m, const QPointF & point ) const { return QPointF( ( m_bottom - point.y() ) / m + point.x(), m_bottom ); } QPointF ClipPainterPrivate::clipRight( qreal m, const QPointF & point ) const { return QPointF( m_right, ( m_right - point.x() ) * m + point.y() ); } int ClipPainterPrivate::sector( const QPointF & point ) const { // If we think of the image borders as (infinitely long) parallel // lines then the plane is divided into 9 sectors. Each of these // sections is identified by a unique keynumber (currentSector): // // 0 | 1 | 2 // --+---+-- // 3 | 4 | 5 <- sector number "4" represents the onscreen sector / viewport // --+---+-- // 6 | 7 | 8 // // Figure out the section of the current point. int xSector = 1; if ( point.x() < m_left ) xSector = 0; else if ( point.x() > m_right ) xSector = 2; int ySector = 3; if ( point.y() < m_top ) ySector = 0; else if ( point.y() > m_bottom ) ySector = 6; // By adding xSector and ySector we get a // sector number of the values shown in the ASCII-art graph above. return ySector + xSector; } void ClipPainterPrivate::clipPolyObject ( const QPolygonF & polygon, QVector & clippedPolyObjects, bool isClosed ) { // mDebug() << "ClipPainter enabled." ; // Only create a new polyObject as soon as we know for sure that // the current point is on the screen. QPolygonF clippedPolyObject = QPolygonF(); const QVector::const_iterator itStartPoint = polygon.constBegin(); const QVector::const_iterator itEndPoint = polygon.constEnd(); QVector::const_iterator itPoint = itStartPoint; // We use a while loop to be able to cover linestrings as well as linear rings: // Linear rings require to tessellate the path from the last node to the first node // which isn't really convenient to achieve with a for loop ... bool processingLastNode = false; while ( itPoint != itEndPoint ) { m_currentPoint = (*itPoint); // mDebug() << "m_currentPoint.x()" << m_currentPoint.x() << "m_currentPOint.y()" << m_currentPoint.y(); // Figure out the sector of the current point. m_currentSector = sector( m_currentPoint ); // Initialize the variables related to the previous point. if ( itPoint == itStartPoint && processingLastNode == false ) { if ( isClosed ) { m_previousPoint = polygon.last(); // Figure out the sector of the previous point. m_previousSector = sector( m_previousPoint ); } else { m_previousSector = m_currentSector; } } // If the current point reaches a new sector, take care of clipping. if ( m_currentSector != m_previousSector ) { if ( m_currentSector == 4 || m_previousSector == 4 ) { // In this case the current or the previous point is visible on the // screen but not both. Hence we only need to clip once and require // only one interpolation for both cases. clipOnce( clippedPolyObject, clippedPolyObjects, isClosed ); } else { // This case mostly deals with lines that reach from one // sector that is located off screen to another one that // is located off screen. In this situation the line // can get clipped once, twice, or not at all. clipMultiple( clippedPolyObject, clippedPolyObjects, isClosed ); } m_previousSector = m_currentSector; } // If the current point is onscreen, just add it to our final polygon. if ( m_currentSector == 4 ) { clippedPolyObject << m_currentPoint; #ifdef MARBLE_DEBUG ++(m_debugNodeCount); #endif } m_previousPoint = m_currentPoint; // Now let's handle the case where we have a (closed) polygon and where the // last point of the polyline is outside the viewport and the start point // is inside the viewport. This needs special treatment if ( processingLastNode ) { break; } ++itPoint; if ( itPoint == itEndPoint && isClosed ) { itPoint = itStartPoint; processingLastNode = true; } } // Only add the pointer if there's node data available. if ( !clippedPolyObject.isEmpty() ) { clippedPolyObjects << clippedPolyObject; } } void ClipPainterPrivate::clipMultiple( QPolygonF & clippedPolyObject, QVector & clippedPolyObjects, bool isClosed ) { Q_UNUSED( clippedPolyObjects ) Q_UNUSED( isClosed ) // Take care of adding nodes in the image corners if the iterator // traverses off screen sections. qreal m = _m( m_previousPoint, m_currentPoint ); switch ( m_currentSector ) { case 0: if ( m_previousSector == 5 ) { QPointF pointRight = clipRight( m, m_previousPoint ); QPointF pointTop = clipTop( m, m_currentPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); if ( pointRight.y() > m_top ) { clippedPolyObject << pointRight; } else { clippedPolyObject << QPointF( m_right, m_top ); } if ( pointTop.x() >= m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; if ( pointLeft.y() > m_top ) clippedPolyObject << pointLeft; } else if ( m_previousSector == 7 ) { QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointTop = clipTop( m, m_currentPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); if ( pointBottom.x() > m_left ) { clippedPolyObject << pointBottom; } else { clippedPolyObject << QPointF( m_left, m_bottom ); } if ( pointLeft.y() >= m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; if ( pointTop.x() > m_left ) clippedPolyObject << pointTop; } else if ( m_previousSector == 8 ) { QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_previousPoint ); QPointF pointTop = clipTop( m, m_currentPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); if ( pointBottom.x() > m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; if ( pointTop.x() > m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; if ( pointBottom.x() <= m_left && pointLeft.y() >= m_bottom ) clippedPolyObject << QPointF( m_left, m_bottom ); if ( pointTop.x() >= m_right && pointRight.y() <= m_top ) clippedPolyObject << QPointF( m_right, m_top ); } clippedPolyObject << QPointF( m_left, m_top ); break; case 1: if ( m_previousSector == 3 ) { QPointF pointLeft = clipLeft( m, m_previousPoint ); QPointF pointTop = clipTop( m, m_currentPoint ); if ( pointLeft.y() > m_top ) { clippedPolyObject << pointLeft; } else { clippedPolyObject << QPointF( m_left, m_top ); } if ( pointTop.x() > m_left ) clippedPolyObject << pointTop; } else if ( m_previousSector == 5 ) { QPointF pointRight = clipRight( m, m_previousPoint ); QPointF pointTop = clipTop( m, m_currentPoint ); if ( pointRight.y() > m_top ) { clippedPolyObject << pointRight; } else { clippedPolyObject << QPointF( m_right, m_top ); } if ( pointTop.x() < m_right ) clippedPolyObject << pointTop; } else if ( m_previousSector == 6 ) { QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_previousPoint ); QPointF pointTop = clipTop( m, m_currentPoint ); if ( pointBottom.x() > m_left ) clippedPolyObject << pointBottom; if ( pointLeft.y() > m_top && pointLeft.y() <= m_bottom ) clippedPolyObject << pointLeft; if ( pointTop.x() > m_left ) { clippedPolyObject << pointTop; } else { clippedPolyObject << QPointF( m_left, m_top ); } } else if ( m_previousSector == 7 ) { clippedPolyObject << clipBottom( m, m_previousPoint ); clippedPolyObject << clipTop( m, m_currentPoint ); } else if ( m_previousSector == 8 ) { QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_previousPoint ); QPointF pointTop = clipTop( m, m_currentPoint ); if ( pointBottom.x() < m_right ) clippedPolyObject << pointBottom; if ( pointRight.y() > m_top && pointRight.y() <= m_bottom ) clippedPolyObject << pointRight; if ( pointTop.x() < m_right ) { clippedPolyObject << pointTop; } else { clippedPolyObject << QPointF( m_right, m_top ); } } break; case 2: if ( m_previousSector == 3 ) { QPointF pointLeft = clipLeft( m, m_previousPoint ); QPointF pointTop = clipTop( m, m_currentPoint ); QPointF pointRight = clipRight( m, m_currentPoint ); if ( pointLeft.y() > m_top ) { clippedPolyObject << pointLeft; } else { clippedPolyObject << QPointF( m_left, m_top ); } if ( pointTop.x() > m_left && pointTop.x() <= m_right ) clippedPolyObject << pointTop; if ( pointRight.y() > m_top ) clippedPolyObject << pointRight; } else if ( m_previousSector == 7 ) { QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointTop = clipTop( m, m_currentPoint ); QPointF pointRight = clipRight( m, m_currentPoint ); if ( pointBottom.x() < m_right ) { clippedPolyObject << pointBottom; } else { clippedPolyObject << QPointF( m_right, m_bottom ); } if ( pointRight.y() >= m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; if ( pointTop.x() < m_right ) clippedPolyObject << pointTop; } else if ( m_previousSector == 6 ) { QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); QPointF pointTop = clipTop( m, m_currentPoint ); QPointF pointRight = clipRight( m, m_previousPoint ); if ( pointBottom.x() > m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; if ( pointTop.x() > m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; if ( pointBottom.x() >= m_right && pointRight.y() >= m_bottom ) clippedPolyObject << QPointF( m_right, m_bottom ); if ( pointTop.x() <= m_left && pointLeft.y() <= m_top ) clippedPolyObject << QPointF( m_left, m_top ); } clippedPolyObject << QPointF( m_right, m_top ); break; case 3: if ( m_previousSector == 7 ) { QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); if ( pointBottom.x() > m_left ) clippedPolyObject << pointBottom; if ( pointLeft.y() < m_bottom ) { clippedPolyObject << pointLeft; } else { clippedPolyObject << QPointF( m_left, m_bottom ); } } else if ( m_previousSector == 1 ) { QPointF pointTop = clipTop( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); if ( pointTop.x() > m_left ) clippedPolyObject << pointTop; if ( pointLeft.y() > m_top ) { clippedPolyObject << pointLeft; } else { clippedPolyObject << QPointF( m_left, m_top ); } } else if ( m_previousSector == 8 ) { QPointF pointRight = clipRight( m, m_previousPoint ); QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); if ( pointRight.y() < m_bottom ) clippedPolyObject << pointRight; if ( pointBottom.x() > m_left && pointBottom.x() <= m_right ) clippedPolyObject << pointBottom; if ( pointLeft.y() < m_bottom ) { clippedPolyObject << pointLeft; } else { clippedPolyObject << QPointF( m_left, m_bottom ); } } else if ( m_previousSector == 5 ) { clippedPolyObject << clipRight( m, m_previousPoint ); clippedPolyObject << clipLeft( m, m_currentPoint ); } else if ( m_previousSector == 2 ) { QPointF pointRight = clipRight( m, m_previousPoint ); QPointF pointTop = clipTop( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); if ( pointRight.y() > m_top ) clippedPolyObject << pointRight; if ( pointTop.x() > m_left && pointTop.x() <= m_right ) clippedPolyObject << pointTop; if ( pointLeft.y() > m_top ) { clippedPolyObject << pointLeft; } else { clippedPolyObject << QPointF( m_left, m_top ); } } break; case 5: if ( m_previousSector == 7 ) { QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_currentPoint ); if ( pointBottom.x() < m_right ) clippedPolyObject << pointBottom; if ( pointRight.y() < m_bottom ) { clippedPolyObject << pointRight; } else { clippedPolyObject << QPointF( m_right, m_bottom ); } } else if ( m_previousSector == 1 ) { QPointF pointTop = clipTop( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_currentPoint ); if ( pointTop.x() < m_right ) clippedPolyObject << pointTop; if ( pointRight.y() > m_top ) { clippedPolyObject << pointRight; } else { clippedPolyObject << QPointF( m_right, m_top ); } } else if ( m_previousSector == 6 ) { QPointF pointLeft = clipLeft( m, m_previousPoint ); QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_currentPoint ); if ( pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; if ( pointBottom.x() >= m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; if ( pointRight.y() < m_bottom ) { clippedPolyObject << pointRight; } else { clippedPolyObject << QPointF( m_right, m_bottom ); } } else if ( m_previousSector == 3 ) { clippedPolyObject << clipLeft( m, m_previousPoint ); clippedPolyObject << clipRight( m, m_currentPoint ); } else if ( m_previousSector == 0 ) { QPointF pointLeft = clipLeft( m, m_previousPoint ); QPointF pointTop = clipTop( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_currentPoint ); if ( pointLeft.y() > m_top ) clippedPolyObject << pointLeft; if ( pointTop.x() >= m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; if ( pointRight.y() > m_top ) { clippedPolyObject << pointRight; } else { clippedPolyObject << QPointF( m_right, m_top ); } } break; case 6: if ( m_previousSector == 5 ) { QPointF pointRight = clipRight( m, m_previousPoint ); QPointF pointBottom = clipBottom( m, m_currentPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); if ( pointRight.y() < m_bottom ) { clippedPolyObject << pointRight; } else { clippedPolyObject << QPointF( m_right, m_bottom ); } if ( pointBottom.x() >= m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; if ( pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; } else if ( m_previousSector == 1 ) { QPointF pointTop = clipTop( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); QPointF pointBottom = clipBottom( m, m_currentPoint ); if ( pointTop.x() > m_left ) { clippedPolyObject << pointTop; } else { clippedPolyObject << QPointF( m_left, m_top ); } if ( pointLeft.y() > m_top && pointLeft.y() <= m_bottom ) clippedPolyObject << pointLeft; if ( pointBottom.x() > m_left ) clippedPolyObject << pointBottom; } else if ( m_previousSector == 2 ) { QPointF pointTop = clipTop( m, m_currentPoint ); QPointF pointRight = clipRight( m, m_previousPoint ); QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); if ( pointTop.x() > m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; if ( pointBottom.x() > m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; if ( pointBottom.x() >= m_right && pointRight.y() >= m_bottom ) clippedPolyObject << QPointF( m_right, m_bottom ); if ( pointTop.x() <= m_left && pointLeft.y() <= m_top ) clippedPolyObject << QPointF( m_left, m_top ); } clippedPolyObject << QPointF( m_left, m_bottom ); break; case 7: if ( m_previousSector == 3 ) { QPointF pointLeft = clipLeft( m, m_previousPoint ); QPointF pointBottom = clipBottom( m, m_currentPoint ); if ( pointLeft.y() < m_bottom ) { clippedPolyObject << pointLeft; } else { clippedPolyObject << QPointF( m_left, m_bottom ); } if ( pointBottom.x() > m_left ) clippedPolyObject << pointBottom; } else if ( m_previousSector == 5 ) { QPointF pointRight = clipRight( m, m_previousPoint ); QPointF pointBottom = clipBottom( m, m_currentPoint ); if ( pointRight.y() < m_bottom ) { clippedPolyObject << pointRight; } else { clippedPolyObject << QPointF( m_right, m_bottom ); } if ( pointBottom.x() < m_right ) clippedPolyObject << pointBottom; } else if ( m_previousSector == 0 ) { QPointF pointTop = clipTop( m, m_previousPoint ); QPointF pointLeft = clipLeft( m, m_previousPoint ); QPointF pointBottom = clipBottom( m, m_currentPoint ); if ( pointTop.x() > m_left ) clippedPolyObject << pointTop; if ( pointLeft.y() >= m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; if ( pointBottom.x() > m_left ) { clippedPolyObject << pointBottom; } else { clippedPolyObject << QPointF( m_left, m_bottom ); } } else if ( m_previousSector == 1 ) { clippedPolyObject << clipTop( m, m_previousPoint ); clippedPolyObject << clipBottom( m, m_currentPoint ); } else if ( m_previousSector == 2 ) { QPointF pointTop = clipTop( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_previousPoint ); QPointF pointBottom = clipBottom( m, m_currentPoint ); if ( pointTop.x() < m_right ) clippedPolyObject << pointTop; if ( pointRight.y() >= m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; if ( pointBottom.x() < m_right ) { clippedPolyObject << pointBottom; } else { clippedPolyObject << QPointF( m_right, m_bottom ); } } break; case 8: if ( m_previousSector == 3 ) { QPointF pointLeft = clipLeft( m, m_previousPoint ); QPointF pointBottom = clipBottom( m, m_currentPoint ); QPointF pointRight = clipRight( m, m_currentPoint ); if ( pointLeft.y() < m_bottom ) { clippedPolyObject << pointLeft; } else { clippedPolyObject << QPointF( m_left, m_bottom ); } if ( pointBottom.x() > m_left && pointBottom.x() <= m_right ) clippedPolyObject << pointBottom; if ( pointRight.y() < m_bottom ) clippedPolyObject << pointRight; } else if ( m_previousSector == 1 ) { QPointF pointTop = clipTop( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_currentPoint ); QPointF pointBottom = clipBottom( m, m_currentPoint ); if ( pointTop.x() < m_right ) { clippedPolyObject << pointTop; } else { clippedPolyObject << QPointF( m_right, m_top ); } if ( pointRight.y() > m_top && pointRight.y() <= m_bottom ) clippedPolyObject << pointRight; if ( pointBottom.x() < m_right ) clippedPolyObject << pointBottom; } else if ( m_previousSector == 0 ) { QPointF pointTop = clipTop( m, m_currentPoint ); QPointF pointLeft = clipLeft( m, m_currentPoint ); QPointF pointBottom = clipBottom( m, m_previousPoint ); QPointF pointRight = clipRight( m, m_previousPoint ); if ( pointTop.x() > m_left && pointTop.x() < m_right ) clippedPolyObject << pointTop; if ( pointLeft.y() > m_top && pointLeft.y() < m_bottom ) clippedPolyObject << pointLeft; if ( pointBottom.x() > m_left && pointBottom.x() < m_right ) clippedPolyObject << pointBottom; if ( pointRight.y() > m_top && pointRight.y() < m_bottom ) clippedPolyObject << pointRight; if ( pointBottom.x() <= m_left && pointLeft.y() >= m_bottom ) clippedPolyObject << QPointF( m_left, m_bottom ); if ( pointTop.x() >= m_right && pointRight.y() <= m_top ) clippedPolyObject << QPointF( m_right, m_top ); } clippedPolyObject << QPointF( m_right, m_bottom ); break; default: break; } } void ClipPainterPrivate::clipOnceCorner( QPolygonF & clippedPolyObject, QVector & clippedPolyObjects, const QPointF& corner, const QPointF& point, bool isClosed ) const { Q_UNUSED( clippedPolyObjects ) Q_UNUSED( isClosed ) if ( m_currentSector == 4) { // Appearing clippedPolyObject << corner; clippedPolyObject << point; } else { // Disappearing clippedPolyObject << point; clippedPolyObject << corner; } } void ClipPainterPrivate::clipOnceEdge( QPolygonF & clippedPolyObject, QVector & clippedPolyObjects, const QPointF& point, bool isClosed ) const { if ( m_currentSector == 4) { // Appearing if ( !isClosed ) { clippedPolyObject = QPolygonF(); } clippedPolyObject << point; } else { // Disappearing clippedPolyObject << point; if ( !isClosed ) { clippedPolyObjects << clippedPolyObject; } } } void ClipPainterPrivate::clipOnce( QPolygonF & clippedPolyObject, QVector & clippedPolyObjects, bool isClosed ) { // Interpolate border points (linear interpolation) QPointF point; // Calculating the slope. qreal m = _m( m_previousPoint, m_currentPoint ); // Calculate in which sector the end of the line is located that is off screen int offscreenpos = ( m_currentSector == 4 ) ? m_previousSector : m_currentSector; // "Rise over run" for all possible situations . switch ( offscreenpos ) { case 0: // topleft point = clipTop( m, m_previousPoint ); if ( point.x() < m_left ) { point = clipLeft( m, point ); } clipOnceCorner( clippedPolyObject, clippedPolyObjects, QPointF( m_left, m_top ), point, isClosed ); break; case 1: // top point = clipTop( m, m_previousPoint ); clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed ); break; case 2: // topright point = clipTop( m, m_previousPoint ); if ( point.x() > m_right ) { point = clipRight( m, point ); } clipOnceCorner( clippedPolyObject, clippedPolyObjects, QPointF( m_right, m_top ), point, isClosed ); break; case 3: // left point = clipLeft( m, m_previousPoint ); clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed ); break; case 5: // right point = clipRight( m, m_previousPoint ); clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed ); break; case 6: // bottomleft point = clipBottom( m, m_previousPoint ); if ( point.x() < m_left ) { point = clipLeft( m, point ); } clipOnceCorner( clippedPolyObject, clippedPolyObjects, QPointF( m_left, m_bottom ), point, isClosed ); break; case 7: // bottom point = clipBottom( m, m_previousPoint ); clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed ); break; case 8: // bottomright point = clipBottom( m, m_previousPoint ); if ( point.x() > m_right ) { point = clipRight( m, point ); } clipOnceCorner( clippedPolyObject, clippedPolyObjects, QPointF( m_right, m_bottom ), point, isClosed ); break; default: break; } } -#ifdef DEBUG_DRAW_NODES +void ClipPainter::setDebugDrawNodes( bool enabled ) { + d->m_debugDrawNodes = enabled; +} void ClipPainterPrivate::debugDrawNodes( const QPolygonF & polygon ) { q->save(); q->setRenderHint( QPainter::Antialiasing, false ); q->setPen( Qt::red ); - q->setBrush( Qt::transparent ); + q->setBrush(QBrush("#40FF0000")); const QVector::const_iterator itStartPoint = polygon.constBegin(); const QVector::const_iterator itEndPoint = polygon.constEnd(); QVector::const_iterator itPoint = itStartPoint; + int i = 0; + for (; itPoint != itEndPoint; ++itPoint ) { + + ++i; if ( itPoint == itStartPoint || itPoint == itStartPoint + 1 || itPoint == itStartPoint + 2 ) { q->setPen( Qt::darkGreen ); + q->setBrush(QBrush("#4000FF00")); if ( itPoint == itStartPoint ) { - q->drawRect( itPoint->x() - 3.0, itPoint->y() - 3.0 , 6.0, 6.0 ); + q->drawRect( itPoint->x() - 6.0, itPoint->y() - 6.0 , 12.0, 12.0 ); } else if ( itPoint == itStartPoint + 1 ) { - q->drawRect( itPoint->x() - 2.0, itPoint->y() - 2.0 , 4.0, 4.0 ); + q->drawRect( itPoint->x() - 4.0, itPoint->y() - 4.0 , 8.0, 8.0 ); } else { - q->drawRect( itPoint->x() - 1.0, itPoint->y() - 1.0 , 2.0, 2.0 ); + q->drawRect( itPoint->x() - 2.0, itPoint->y() - 2.0 , 4.0, 4.0 ); } q->setPen( Qt::red ); + q->setBrush(QBrush("#40FF0000")); } else if ( itPoint == itEndPoint - 1 || itPoint == itEndPoint - 2 || itPoint == itEndPoint - 3 ) { q->setPen( Qt::blue ); + q->setBrush(QBrush("#400000FF")); if ( itPoint == itEndPoint - 3 ) { - q->drawRect( itPoint->x() - 3.0, itPoint->y() - 3.0 , 6.0, 6.0 ); + q->drawRect( itPoint->x() - 6.0, itPoint->y() - 6.0 , 12.0, 12.0 ); } else if ( itPoint == itEndPoint - 2 ) { - q->drawRect( itPoint->x() - 2.0, itPoint->y() - 2.0 , 4.0, 4.0 ); + q->drawRect( itPoint->x() - 4.0, itPoint->y() - 4.0 , 8.0, 8.0 ); } else { - q->drawRect( itPoint->x() - 1.0, itPoint->y() - 1.0 , 2.0, 2.0 ); + q->drawRect( itPoint->x() - 2.0, itPoint->y() - 2.0 , 4.0, 4.0 ); } q->setPen( Qt::red ); + q->setBrush(QBrush("#400000FF")); } else { - q->drawRect( itPoint->x() - 1.5, itPoint->y() - 1.5 , 3.0, 3.0 ); + q->drawRect( itPoint->x() - 4, itPoint->y() - 4 , 8.0, 8.0 ); } - + q->setFont(QFont("Helvetica", 6)); + q->setPen("black"); + q->drawText(itPoint->x() + 6.0, itPoint->y() + (15 - i%30) , QString::number(i)); } q->restore(); } - -#endif diff --git a/src/lib/marble/ClipPainter.h b/src/lib/marble/ClipPainter.h index 42b73c0f3..f6ff1918c 100644 --- a/src/lib/marble/ClipPainter.h +++ b/src/lib/marble/ClipPainter.h @@ -1,78 +1,80 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2006-2009 Torsten Rahn // Copyright 2007 Inge Wallin // #ifndef MARBLE_CLIPPAINTER_H #define MARBLE_CLIPPAINTER_H #include #include #include "marble_export.h" #include "MarbleGlobal.h" class QPaintDevice; class QPolygonF; namespace Marble { /** * @short A QPainter that does viewport clipping for polygons * * This class introduces fast polygon/polyline clipping for QPainter * to increase the performance. * Clipping is accomplished using an algorithm (by Torsten Rahn) that * processes each polyline once. * To keep things fast each possible scenario of two subsequent * points is implemented case by case in a specialized handler which * creates interpolated points and helper points. */ // The reason for this class is a terrible bug in some versions of the // X Server. Suppose the widget size is, say, 1000 x 1000 and we have // a high zoom so that we want to draw a vector from (-100000, // -100000) to (100000, 100000). Then the X server will create a // bitmap that is at least 100000 x 100000 and in the process eat all // available memory. // // So we introduce the ClipPainter that clips all polylines and polygons // to the area that is actually visible in the viewport. // // @internal class ClipPainterPrivate; class MARBLE_EXPORT ClipPainter : public QPainter { public: ClipPainter(); ClipPainter(QPaintDevice*, bool); ~ClipPainter(); void setScreenClip( bool enable ); bool hasScreenClip() const; void drawPolygon( const QPolygonF &, Qt::FillRule fillRule = Qt::OddEvenFill ); void drawPolyline( const QPolygonF & ); void drawPolyline( const QPolygonF &, QVector& labelNodes, LabelPositionFlags labelPositionFlag = LineCenter ); + void setDebugDrawNodes( bool ); + // void clearNodeCount(){ m_debugNodeCount = 0; } // int nodeCount(){ return m_debugNodeCount; } private: ClipPainterPrivate * const d; }; } #endif diff --git a/src/lib/marble/MarbleMap.cpp b/src/lib/marble/MarbleMap.cpp index b60e08c59..d0efee277 100644 --- a/src/lib/marble/MarbleMap.cpp +++ b/src/lib/marble/MarbleMap.cpp @@ -1,1297 +1,1307 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2006-2009 Torsten Rahn // Copyright 2007 Inge Wallin // Copyright 2008 Carlos Licea // Copyright 2009 Jens-Michael Hoffmann // Copyright 2010-2012 Bernhard Beschow // // Own #include "MarbleMap.h" // Posix #include // Qt #include #include #include #include #include #include // Marble #include "layers/FogLayer.h" #include "layers/FpsLayer.h" #include "layers/GeometryLayer.h" #include "layers/GroundLayer.h" #include "layers/MarbleSplashLayer.h" #include "layers/PlacemarkLayer.h" #include "layers/TextureLayer.h" #include "layers/VectorTileLayer.h" #include "AbstractFloatItem.h" #include "DgmlAuxillaryDictionary.h" #include "FileManager.h" #include "GeoDataTreeModel.h" #include "GeoPainter.h" #include "GeoSceneDocument.h" #include "GeoSceneFilter.h" #include "GeoSceneGeodata.h" #include "GeoSceneHead.h" #include "GeoSceneLayer.h" #include "GeoSceneMap.h" #include "GeoScenePalette.h" #include "GeoSceneSettings.h" #include "GeoSceneVector.h" #include "GeoSceneVectorTileDataset.h" #include "GeoSceneZoom.h" #include "GeoDataDocument.h" #include "GeoDataPlacemark.h" #include "GeoDataFeature.h" #include "GeoDataStyle.h" #include "GeoDataStyleMap.h" #include "LayerManager.h" #include "MapThemeManager.h" #include "MarbleDebug.h" #include "MarbleDirs.h" #include "MarbleModel.h" #include "RenderPlugin.h" #include "SunLocator.h" #include "TileCoordsPyramid.h" #include "TileCreator.h" #include "TileCreatorDialog.h" #include "TileLoader.h" #include "ViewParams.h" #include "ViewportParams.h" namespace Marble { class MarbleMap::CustomPaintLayer : public LayerInterface { public: explicit CustomPaintLayer( MarbleMap *map ) : m_map( map ) { } virtual QStringList renderPosition() const { return QStringList() << "USER_TOOLS"; } virtual bool render( GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer ) { Q_UNUSED( viewport ); Q_UNUSED( renderPos ); Q_UNUSED( layer ); m_map->customPaint( painter ); return true; } virtual qreal zValue() const { return 1.0e6; } RenderState renderState() const { return RenderState( "Custom Map Paint" ); } virtual QString runtimeTrace() const { return "CustomPaint"; } private: MarbleMap *const m_map; }; class MarbleMapPrivate { friend class MarbleWidget; public: explicit MarbleMapPrivate( MarbleMap *parent, MarbleModel *model ); void updateMapTheme(); void updateProperty( const QString &, bool ); void setDocument( QString key ); void updateTileLevel(); MarbleMap *const q; // The model we are showing. MarbleModel *const m_model; bool m_modelIsOwned; // Parameters for the maps appearance. ViewParams m_viewParams; ViewportParams m_viewport; bool m_showFrameRate; + bool m_showDebugPolygons; LayerManager m_layerManager; MarbleSplashLayer m_marbleSplashLayer; MarbleMap::CustomPaintLayer m_customPaintLayer; GeometryLayer m_geometryLayer; FogLayer m_fogLayer; GroundLayer m_groundLayer; TextureLayer m_textureLayer; PlacemarkLayer m_placemarkLayer; VectorTileLayer m_vectorTileLayer; bool m_isLockedToSubSolarPoint; bool m_isSubSolarPointIconVisible; RenderState m_renderState; }; MarbleMapPrivate::MarbleMapPrivate( MarbleMap *parent, MarbleModel *model ) : q( parent ), m_model( model ), m_viewParams(), m_showFrameRate( false ), + m_showDebugPolygons( false ), m_layerManager( model, parent ), m_customPaintLayer( parent ), m_geometryLayer( model->treeModel() ), m_textureLayer( model->downloadManager(), model->pluginManager(), model->sunLocator(), model->groundOverlayModel() ), m_placemarkLayer( model->placemarkModel(), model->placemarkSelectionModel(), model->clock() ), m_vectorTileLayer( model->downloadManager(), model->pluginManager(), model->treeModel() ), m_isLockedToSubSolarPoint( false ), m_isSubSolarPointIconVisible( false ) { m_layerManager.addLayer( &m_fogLayer ); m_layerManager.addLayer( &m_groundLayer ); m_layerManager.addLayer( &m_geometryLayer ); m_layerManager.addLayer( &m_placemarkLayer ); m_layerManager.addLayer( &m_customPaintLayer ); QObject::connect( m_model, SIGNAL(themeChanged(QString)), parent, SLOT(updateMapTheme()) ); QObject::connect( m_model->fileManager(), SIGNAL(fileAdded(QString)), parent, SLOT(setDocument(QString)) ); QObject::connect( &m_placemarkLayer, SIGNAL(repaintNeeded()), parent, SIGNAL(repaintNeeded())); QObject::connect ( &m_layerManager, SIGNAL(pluginSettingsChanged()), parent, SIGNAL(pluginSettingsChanged()) ); QObject::connect ( &m_layerManager, SIGNAL(repaintNeeded(QRegion)), parent, SIGNAL(repaintNeeded(QRegion)) ); QObject::connect ( &m_layerManager, SIGNAL(renderPluginInitialized(RenderPlugin*)), parent, SIGNAL(renderPluginInitialized(RenderPlugin*)) ); QObject::connect ( &m_layerManager, SIGNAL(visibilityChanged(QString,bool)), parent, SLOT(setPropertyValue(QString,bool)) ); QObject::connect( &m_geometryLayer, SIGNAL(repaintNeeded()), parent, SIGNAL(repaintNeeded())); /** * Slot handleHighlight finds all placemarks * that contain the clicked point. * The placemarks under the clicked position may * have their styleUrl set to a style map which * doesn't specify any highlight styleId. Such * placemarks will be fletered out in GeoGraphicsScene * and will not be highlighted. */ QObject::connect( parent, SIGNAL(highlightedPlacemarksChanged(qreal,qreal,GeoDataCoordinates::Unit)), &m_geometryLayer, SLOT(handleHighlight(qreal,qreal,GeoDataCoordinates::Unit)) ); QObject::connect( &m_textureLayer, SIGNAL(tileLevelChanged(int)), parent, SLOT(updateTileLevel()) ); QObject::connect( &m_vectorTileLayer, SIGNAL(tileLevelChanged(int)), parent, SLOT(updateTileLevel()) ); QObject::connect( &m_textureLayer, SIGNAL(repaintNeeded()), parent, SIGNAL(repaintNeeded()) ); QObject::connect( parent, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)), parent, SIGNAL(repaintNeeded()) ); } void MarbleMapPrivate::updateProperty( const QString &name, bool show ) { // earth if ( name == "places" ) { m_placemarkLayer.setShowPlaces( show ); } else if ( name == "cities" ) { m_placemarkLayer.setShowCities( show ); } else if ( name == "terrain" ) { m_placemarkLayer.setShowTerrain( show ); } else if ( name == "otherplaces" ) { m_placemarkLayer.setShowOtherPlaces( show ); } // other planets else if ( name == "landingsites" ) { m_placemarkLayer.setShowLandingSites( show ); } else if ( name == "craters" ) { m_placemarkLayer.setShowCraters( show ); } else if ( name == "maria" ) { m_placemarkLayer.setShowMaria( show ); } else if ( name == "relief" ) { m_textureLayer.setShowRelief( show ); } foreach( RenderPlugin *renderPlugin, m_layerManager.renderPlugins() ) { if ( name == renderPlugin->nameId() ) { if ( renderPlugin->visible() == show ) { break; } renderPlugin->setVisible( show ); break; } } } // ---------------------------------------------------------------- MarbleMap::MarbleMap() : d( new MarbleMapPrivate( this, new MarbleModel( this ) ) ) { // nothing to do } MarbleMap::MarbleMap(MarbleModel *model) : d( new MarbleMapPrivate( this, model ) ) { d->m_modelIsOwned = false; } MarbleMap::~MarbleMap() { MarbleModel *model = d->m_modelIsOwned ? d->m_model : 0; d->m_layerManager.removeLayer( &d->m_customPaintLayer ); d->m_layerManager.removeLayer( &d->m_geometryLayer ); d->m_layerManager.removeLayer( &d->m_fogLayer ); d->m_layerManager.removeLayer( &d->m_placemarkLayer ); d->m_layerManager.removeLayer( &d->m_textureLayer ); d->m_layerManager.removeLayer( &d->m_groundLayer ); delete d; delete model; // delete the model after private data } MarbleModel *MarbleMap::model() const { return d->m_model; } ViewportParams *MarbleMap::viewport() { return &d->m_viewport; } const ViewportParams *MarbleMap::viewport() const { return &d->m_viewport; } void MarbleMap::setMapQualityForViewContext( MapQuality quality, ViewContext viewContext ) { d->m_viewParams.setMapQualityForViewContext( quality, viewContext ); // Update texture map during the repaint that follows: d->m_textureLayer.setNeedsUpdate(); } MapQuality MarbleMap::mapQuality( ViewContext viewContext ) const { return d->m_viewParams.mapQuality( viewContext ); } MapQuality MarbleMap::mapQuality() const { return d->m_viewParams.mapQuality(); } void MarbleMap::setViewContext( ViewContext viewContext ) { if ( d->m_viewParams.viewContext() == viewContext ) { return; } const MapQuality oldQuality = d->m_viewParams.mapQuality(); d->m_viewParams.setViewContext( viewContext ); emit viewContextChanged( viewContext ); if ( d->m_viewParams.mapQuality() != oldQuality ) { // Update texture map during the repaint that follows: d->m_textureLayer.setNeedsUpdate(); emit repaintNeeded(); } } ViewContext MarbleMap::viewContext() const { return d->m_viewParams.viewContext(); } void MarbleMap::setSize( int width, int height ) { setSize( QSize( width, height ) ); } void MarbleMap::setSize( const QSize& size ) { d->m_viewport.setSize( size ); emit visibleLatLonAltBoxChanged( d->m_viewport.viewLatLonAltBox() ); } QSize MarbleMap::size() const { return QSize( d->m_viewport.width(), d->m_viewport.height() ); } int MarbleMap::width() const { return d->m_viewport.width(); } int MarbleMap::height() const { return d->m_viewport.height(); } int MarbleMap::radius() const { return d->m_viewport.radius(); } void MarbleMap::setRadius( int radius ) { const int oldRadius = d->m_viewport.radius(); d->m_viewport.setRadius( radius ); if ( oldRadius != d->m_viewport.radius() ) { emit radiusChanged( radius ); emit visibleLatLonAltBoxChanged( d->m_viewport.viewLatLonAltBox() ); } } int MarbleMap::preferredRadiusCeil( int radius ) { return d->m_textureLayer.preferredRadiusCeil( radius ); } int MarbleMap::preferredRadiusFloor( int radius ) { return d->m_textureLayer.preferredRadiusFloor( radius ); } int MarbleMap::tileZoomLevel() const { return qMax(d->m_textureLayer.tileZoomLevel(), d->m_vectorTileLayer.tileZoomLevel()); } qreal MarbleMap::centerLatitude() const { // Calculate translation of center point const qreal centerLat = d->m_viewport.centerLatitude(); return centerLat * RAD2DEG; } qreal MarbleMap::centerLongitude() const { // Calculate translation of center point const qreal centerLon = d->m_viewport.centerLongitude(); return centerLon * RAD2DEG; } int MarbleMap::minimumZoom() const { if ( d->m_model->mapTheme() ) return d->m_model->mapTheme()->head()->zoom()->minimum(); return 950; } int MarbleMap::maximumZoom() const { if ( d->m_model->mapTheme() ) return d->m_model->mapTheme()->head()->zoom()->maximum(); return 2100; } bool MarbleMap::discreteZoom() const { if ( d->m_model->mapTheme() ) return d->m_model->mapTheme()->head()->zoom()->discrete(); return false; } QVector MarbleMap::whichFeatureAt( const QPoint& curpos ) const { return d->m_placemarkLayer.whichPlacemarkAt( curpos ) + d->m_geometryLayer.whichFeatureAt( curpos, viewport() ); } void MarbleMap::reload() { d->m_textureLayer.reload(); } void MarbleMap::downloadRegion( QVector const & pyramid ) { Q_ASSERT( textureLayer() ); Q_ASSERT( !pyramid.isEmpty() ); QTime t; t.start(); // When downloading a region (the author of these lines thinks) most users probably expect // the download to begin with the low resolution tiles and then procede level-wise to // higher resolution tiles. In order to achieve this, we start requesting downloads of // high resolution tiles and request the low resolution tiles at the end because // DownloadQueueSet (silly name) is implemented as stack. int const first = 0; int tilesCount = 0; for ( int level = pyramid[first].bottomLevel(); level >= pyramid[first].topLevel(); --level ) { QSet tileIdSet; for( int i = 0; i < pyramid.size(); ++i ) { QRect const coords = pyramid[i].coords( level ); mDebug() << "MarbleMap::downloadRegion level:" << level << "tile coords:" << coords; int x1, y1, x2, y2; coords.getCoords( &x1, &y1, &x2, &y2 ); for ( int x = x1; x <= x2; ++x ) { for ( int y = y1; y <= y2; ++y ) { TileId const stackedTileId( 0, level, x, y ); tileIdSet.insert( stackedTileId ); // FIXME: use lazy evaluation to not generate up to 100k tiles in one go // this can take considerable time even on very fast systems // in contrast generating the TileIds on the fly when they are needed // does not seem to affect download speed. } } } QSetIterator i( tileIdSet ); while( i.hasNext() ) { TileId const tileId = i.next(); d->m_textureLayer.downloadStackedTile( tileId ); } tilesCount += tileIdSet.count(); } // Needed for downloading unique tiles only. Much faster than if tiles for each level is downloaded separately int const elapsedMs = t.elapsed(); mDebug() << "MarbleMap::downloadRegion:" << tilesCount << "tiles, " << elapsedMs << "ms"; } bool MarbleMap::propertyValue( const QString& name ) const { bool value; if ( d->m_model->mapTheme() ) { d->m_model->mapTheme()->settings()->propertyValue( name, value ); } else { value = false; mDebug() << "WARNING: Failed to access a map theme! Property: " << name; } return value; } bool MarbleMap::showOverviewMap() const { return propertyValue( "overviewmap" ); } bool MarbleMap::showScaleBar() const { return propertyValue( "scalebar" ); } bool MarbleMap::showCompass() const { return propertyValue( "compass" ); } bool MarbleMap::showGrid() const { return propertyValue( "coordinate-grid" ); } bool MarbleMap::showClouds() const { return d->m_viewParams.showClouds(); } bool MarbleMap::showSunShading() const { return d->m_textureLayer.showSunShading(); } bool MarbleMap::showCityLights() const { return d->m_textureLayer.showCityLights(); } bool MarbleMap::isLockedToSubSolarPoint() const { return d->m_isLockedToSubSolarPoint; } bool MarbleMap::isSubSolarPointIconVisible() const { return d->m_isSubSolarPointIconVisible; } bool MarbleMap::showAtmosphere() const { return d->m_viewParams.showAtmosphere(); } bool MarbleMap::showCrosshairs() const { bool visible = false; QList pluginList = renderPlugins(); QList::const_iterator i = pluginList.constBegin(); QList::const_iterator const end = pluginList.constEnd(); for (; i != end; ++i ) { if ( (*i)->nameId() == "crosshairs" ) { visible = (*i)->visible(); } } return visible; } bool MarbleMap::showPlaces() const { return propertyValue( "places" ); } bool MarbleMap::showCities() const { return propertyValue( "cities" ); } bool MarbleMap::showTerrain() const { return propertyValue( "terrain" ); } bool MarbleMap::showOtherPlaces() const { return propertyValue( "otherplaces" ); } bool MarbleMap::showRelief() const { return propertyValue( "relief" ); } bool MarbleMap::showIceLayer() const { return propertyValue( "ice" ); } bool MarbleMap::showBorders() const { return propertyValue( "borders" ); } bool MarbleMap::showRivers() const { return propertyValue( "rivers" ); } bool MarbleMap::showLakes() const { return propertyValue( "lakes" ); } bool MarbleMap::showFrameRate() const { return d->m_showFrameRate; } bool MarbleMap::showBackground() const { return d->m_layerManager.showBackground(); } quint64 MarbleMap::volatileTileCacheLimit() const { return d->m_textureLayer.volatileCacheLimit(); } void MarbleMap::rotateBy( const qreal& deltaLon, const qreal& deltaLat ) { centerOn( d->m_viewport.centerLongitude() * RAD2DEG + deltaLon, d->m_viewport.centerLatitude() * RAD2DEG + deltaLat ); } void MarbleMap::centerOn( const qreal lon, const qreal lat ) { d->m_viewport.centerOn( lon * DEG2RAD, lat * DEG2RAD ); emit visibleLatLonAltBoxChanged( d->m_viewport.viewLatLonAltBox() ); } void MarbleMap::setCenterLatitude( qreal lat ) { centerOn( centerLongitude(), lat ); } void MarbleMap::setCenterLongitude( qreal lon ) { centerOn( lon, centerLatitude() ); } Projection MarbleMap::projection() const { return d->m_viewport.projection(); } void MarbleMap::setProjection( Projection projection ) { if ( d->m_viewport.projection() == projection ) return; emit projectionChanged( projection ); d->m_viewport.setProjection( projection ); d->m_textureLayer.setProjection( projection ); emit visibleLatLonAltBoxChanged( d->m_viewport.viewLatLonAltBox() ); } bool MarbleMap::screenCoordinates( qreal lon, qreal lat, qreal& x, qreal& y ) const { return d->m_viewport.screenCoordinates( lon * DEG2RAD, lat * DEG2RAD, x, y ); } bool MarbleMap::geoCoordinates( int x, int y, qreal& lon, qreal& lat, GeoDataCoordinates::Unit unit ) const { return d->m_viewport.geoCoordinates( x, y, lon, lat, unit ); } void MarbleMapPrivate::setDocument( QString key ) { if ( !m_model->mapTheme() ) { // Happens if no valid map theme is set or at application startup // if a file is passed via command line parameters and the last // map theme has not been loaded yet /** * @todo Do we need to queue the document and process it once a map * theme becomes available? */ return; } GeoDataDocument* doc = m_model->fileManager()->at( key ); foreach ( const GeoSceneLayer *layer, m_model->mapTheme()->map()->layers() ) { if ( layer->backend() != dgml::dgmlValue_geodata && layer->backend() != dgml::dgmlValue_vector ) continue; // look for documents foreach ( const GeoSceneAbstractDataset *dataset, layer->datasets() ) { const GeoSceneGeodata *data = static_cast( dataset ); QString containername = data->sourceFile(); QString colorize = data->colorize(); if( key == containername ) { if( colorize == "land" ) { m_textureLayer.addLandDocument( doc ); } if( colorize == "sea" ) { m_textureLayer.addSeaDocument( doc ); } // set visibility according to theme property if( !data->property().isEmpty() ) { bool value; m_model->mapTheme()->settings()->propertyValue( data->property(), value ); doc->setVisible( value ); m_model->treeModel()->updateFeature( doc ); } } } } } void MarbleMapPrivate::updateTileLevel() { emit q->tileLevelChanged(q->tileZoomLevel()); } // Used to be paintEvent() void MarbleMap::paint( GeoPainter &painter, const QRect &dirtyRect ) { Q_UNUSED( dirtyRect ); + if (d->m_showDebugPolygons) { + painter.setDebugDrawNodes(true); + } + if ( !d->m_model->mapTheme() ) { mDebug() << "No theme yet!"; d->m_marbleSplashLayer.render( &painter, &d->m_viewport ); return; } QTime t; t.start(); RenderStatus const oldRenderStatus = d->m_renderState.status(); d->m_layerManager.renderLayers( &painter, &d->m_viewport ); d->m_renderState = d->m_layerManager.renderState(); bool const parsing = d->m_model->fileManager()->pendingFiles() > 0; d->m_renderState.addChild( RenderState( "Files", parsing ? WaitingForData : Complete ) ); RenderStatus const newRenderStatus = d->m_renderState.status(); if ( oldRenderStatus != newRenderStatus ) { emit renderStatusChanged( newRenderStatus ); } emit renderStateChanged( d->m_renderState ); if ( d->m_showFrameRate ) { FpsLayer fpsPainter( &t ); fpsPainter.paint( &painter ); } const qreal fps = 1000.0 / (qreal)( t.elapsed() ); emit framesPerSecond( fps ); } void MarbleMap::customPaint( GeoPainter *painter ) { Q_UNUSED( painter ); } QString MarbleMap::mapThemeId() const { return d->m_model->mapThemeId(); } void MarbleMap::setMapThemeId( const QString& mapThemeId ) { d->m_model->setMapThemeId( mapThemeId ); } void MarbleMapPrivate::updateMapTheme() { m_layerManager.removeLayer( &m_textureLayer ); // FIXME Find a better way to do this reset. Maybe connect to themeChanged SIGNAL? m_vectorTileLayer.reset(); m_layerManager.removeLayer( &m_vectorTileLayer ); m_layerManager.removeLayer( &m_groundLayer ); QObject::connect( m_model->mapTheme()->settings(), SIGNAL(valueChanged(QString,bool)), q, SLOT(updateProperty(QString,bool)) ); QObject::connect( m_model->mapTheme()->settings(), SIGNAL(valueChanged(QString,bool)), m_model, SLOT(updateProperty(QString,bool)) ); q->setPropertyValue( "clouds_data", m_viewParams.showClouds() ); m_groundLayer.setColor( m_model->mapTheme()->map()->backgroundColor() ); if ( !m_model->mapTheme()->map()->hasTextureLayers() ) { m_layerManager.addLayer( &m_groundLayer ); } // Check whether there is a texture layer and vectortile layer available: if ( m_model->mapTheme()->map()->hasTextureLayers() ) { const GeoSceneSettings *const settings = m_model->mapTheme()->settings(); const GeoSceneGroup *const textureLayerSettings = settings ? settings->group( "Texture Layers" ) : 0; const GeoSceneGroup *const vectorTileLayerSettings = settings ? settings->group( "VectorTile Layers" ) : 0; bool textureLayersOk = true; bool vectorTileLayersOk = true; // textures will contain texture layers and // vectorTiles vectortile layers QVector textures; QVector vectorTiles; foreach( GeoSceneLayer* layer, m_model->mapTheme()->map()->layers() ){ if ( layer->backend() == dgml::dgmlValue_texture ){ foreach ( const GeoSceneAbstractDataset *pos, layer->datasets() ) { const GeoSceneTextureTileDataset *const texture = dynamic_cast( pos ); if ( !texture ) continue; const QString sourceDir = texture->sourceDir(); const QString installMap = texture->installMap(); const QString role = layer->role(); // If the tiles aren't already there, put up a progress dialog // while creating them. if ( !TileLoader::baseTilesAvailable( *texture ) && !installMap.isEmpty() ) { mDebug() << "Base tiles not available. Creating Tiles ... \n" << "SourceDir: " << sourceDir << "InstallMap:" << installMap; TileCreator *tileCreator = new TileCreator( sourceDir, installMap, (role == "dem") ? "true" : "false" ); tileCreator->setTileFormat( texture->fileFormat().toLower() ); QPointer tileCreatorDlg = new TileCreatorDialog( tileCreator, 0 ); tileCreatorDlg->setSummary( m_model->mapTheme()->head()->name(), m_model->mapTheme()->head()->description() ); tileCreatorDlg->exec(); if ( TileLoader::baseTilesAvailable( *texture ) ) { mDebug() << "Base tiles for" << sourceDir << "successfully created."; } else { qWarning() << "Some or all base tiles for" << sourceDir << "could not be created."; } delete tileCreatorDlg; } if ( TileLoader::baseTilesAvailable( *texture ) ) { textures.append( texture ); } else { qWarning() << "Base tiles for" << sourceDir << "not available. Skipping all texture layers."; textureLayersOk = false; } } } else if ( layer->backend() == dgml::dgmlValue_vectortile ){ foreach ( const GeoSceneAbstractDataset *pos, layer->datasets() ) { const GeoSceneVectorTileDataset *const vectorTile = dynamic_cast( pos ); if ( !vectorTile ) continue; const QString sourceDir = vectorTile->sourceDir(); const QString installMap = vectorTile->installMap(); const QString role = layer->role(); // If the tiles aren't already there, put up a progress dialog // while creating them. if ( !TileLoader::baseTilesAvailable( *vectorTile ) && !installMap.isEmpty() ) { mDebug() << "Base tiles not available. Creating Tiles ... \n" << "SourceDir: " << sourceDir << "InstallMap:" << installMap; TileCreator *tileCreator = new TileCreator( sourceDir, installMap, (role == "dem") ? "true" : "false" ); tileCreator->setTileFormat( vectorTile->fileFormat().toLower() ); QPointer tileCreatorDlg = new TileCreatorDialog( tileCreator, 0 ); tileCreatorDlg->setSummary( m_model->mapTheme()->head()->name(), m_model->mapTheme()->head()->description() ); tileCreatorDlg->exec(); if ( TileLoader::baseTilesAvailable( *vectorTile ) ) { qDebug() << "Base tiles for" << sourceDir << "successfully created."; } else { qDebug() << "Some or all base tiles for" << sourceDir << "could not be created."; } delete tileCreatorDlg; } if ( TileLoader::baseTilesAvailable( *vectorTile ) ) { vectorTiles.append( vectorTile ); } else { qWarning() << "Base tiles for" << sourceDir << "not available. Skipping all texture layers."; vectorTileLayersOk = false; } } } } QString seafile, landfile; if( !m_model->mapTheme()->map()->filters().isEmpty() ) { const GeoSceneFilter *filter= m_model->mapTheme()->map()->filters().first(); if( filter->type() == "colorize" ) { //no need to look up with MarbleDirs twice so they are left null for now QList palette = filter->palette(); foreach (const GeoScenePalette *curPalette, palette ) { if( curPalette->type() == "sea" ) { seafile = MarbleDirs::path( curPalette->file() ); } else if( curPalette->type() == "land" ) { landfile = MarbleDirs::path( curPalette->file() ); } } //look up locations if they are empty if( seafile.isEmpty() ) seafile = MarbleDirs::path( "seacolors.leg" ); if( landfile.isEmpty() ) landfile = MarbleDirs::path( "landcolors.leg" ); } } m_textureLayer.setMapTheme( textures, textureLayerSettings, seafile, landfile ); m_textureLayer.setProjection( m_viewport.projection() ); m_textureLayer.setShowRelief( q->showRelief() ); m_vectorTileLayer.setMapTheme( vectorTiles, vectorTileLayerSettings ); if ( textureLayersOk ) m_layerManager.addLayer( &m_textureLayer ); if ( vectorTileLayersOk ) m_layerManager.addLayer( &m_vectorTileLayer ); } else { m_textureLayer.setMapTheme( QVector(), 0, "", "" ); m_vectorTileLayer.setMapTheme( QVector(), 0 ); } // earth m_placemarkLayer.setShowPlaces( q->showPlaces() ); m_placemarkLayer.setShowCities( q->showCities() ); m_placemarkLayer.setShowTerrain( q->showTerrain() ); m_placemarkLayer.setShowOtherPlaces( q->showOtherPlaces() ); m_placemarkLayer.setShowLandingSites( q->propertyValue("landingsites") ); m_placemarkLayer.setShowCraters( q->propertyValue("craters") ); m_placemarkLayer.setShowMaria( q->propertyValue("maria") ); GeoDataFeature::setDefaultLabelColor( m_model->mapTheme()->map()->labelColor() ); m_placemarkLayer.requestStyleReset(); foreach( RenderPlugin *renderPlugin, m_layerManager.renderPlugins() ) { bool propertyAvailable = false; m_model->mapTheme()->settings()->propertyAvailable( renderPlugin->nameId(), propertyAvailable ); bool propertyValue = false; m_model->mapTheme()->settings()->propertyValue( renderPlugin->nameId(), propertyValue ); if ( propertyAvailable ) { renderPlugin->setVisible( propertyValue ); } } emit q->themeChanged( m_model->mapTheme()->head()->mapThemeId() ); } void MarbleMap::setPropertyValue( const QString& name, bool value ) { mDebug() << "In MarbleMap the property " << name << "was set to " << value; if ( d->m_model->mapTheme() ) { d->m_model->mapTheme()->settings()->setPropertyValue( name, value ); d->m_textureLayer.setNeedsUpdate(); } else { mDebug() << "WARNING: Failed to access a map theme! Property: " << name; } if (d->m_textureLayer.textureLayerCount() == 0) { d->m_layerManager.addLayer( &d->m_groundLayer ); } else { d->m_layerManager.removeLayer( &d->m_groundLayer ); } } void MarbleMap::setShowOverviewMap( bool visible ) { setPropertyValue( "overviewmap", visible ); } void MarbleMap::setShowScaleBar( bool visible ) { setPropertyValue( "scalebar", visible ); } void MarbleMap::setShowCompass( bool visible ) { setPropertyValue( "compass", visible ); } void MarbleMap::setShowAtmosphere( bool visible ) { foreach ( RenderPlugin *plugin, renderPlugins() ) { if ( plugin->nameId() == "atmosphere" ) { plugin->setVisible( visible ); } } d->m_viewParams.setShowAtmosphere( visible ); } void MarbleMap::setShowCrosshairs( bool visible ) { QList pluginList = renderPlugins(); QList::const_iterator i = pluginList.constBegin(); QList::const_iterator const end = pluginList.constEnd(); for (; i != end; ++i ) { if ( (*i)->nameId() == "crosshairs" ) { (*i)->setVisible( visible ); } } } void MarbleMap::setShowClouds( bool visible ) { d->m_viewParams.setShowClouds( visible ); setPropertyValue( "clouds_data", visible ); } void MarbleMap::setShowSunShading( bool visible ) { d->m_textureLayer.setShowSunShading( visible ); } void MarbleMap::setShowCityLights( bool visible ) { d->m_textureLayer.setShowCityLights( visible ); setPropertyValue( "citylights", visible ); } void MarbleMap::setLockToSubSolarPoint( bool visible ) { disconnect( d->m_model->sunLocator(), SIGNAL(positionChanged(qreal,qreal)), this, SLOT(centerOn(qreal,qreal)) ); if( isLockedToSubSolarPoint() != visible ) { d->m_isLockedToSubSolarPoint = visible; } if ( isLockedToSubSolarPoint() ) { connect( d->m_model->sunLocator(), SIGNAL(positionChanged(qreal,qreal)), this, SLOT(centerOn(qreal,qreal)) ); centerOn( d->m_model->sunLocator()->getLon(), d->m_model->sunLocator()->getLat() ); } else if ( visible ) { mDebug() << "Ignoring centering on sun, since the sun plugin is not loaded."; } } void MarbleMap::setSubSolarPointIconVisible( bool visible ) { if ( isSubSolarPointIconVisible() != visible ) { d->m_isSubSolarPointIconVisible = visible; } } void MarbleMap::setShowTileId( bool visible ) { d->m_textureLayer.setShowTileId( visible ); } void MarbleMap::setShowGrid( bool visible ) { setPropertyValue( "coordinate-grid", visible ); } void MarbleMap::setShowPlaces( bool visible ) { setPropertyValue( "places", visible ); } void MarbleMap::setShowCities( bool visible ) { setPropertyValue( "cities", visible ); } void MarbleMap::setShowTerrain( bool visible ) { setPropertyValue( "terrain", visible ); } void MarbleMap::setShowOtherPlaces( bool visible ) { setPropertyValue( "otherplaces", visible ); } void MarbleMap::setShowRelief( bool visible ) { setPropertyValue( "relief", visible ); } void MarbleMap::setShowIceLayer( bool visible ) { setPropertyValue( "ice", visible ); } void MarbleMap::setShowBorders( bool visible ) { setPropertyValue( "borders", visible ); } void MarbleMap::setShowRivers( bool visible ) { setPropertyValue( "rivers", visible ); } void MarbleMap::setShowLakes( bool visible ) { setPropertyValue( "lakes", visible ); } void MarbleMap::setShowFrameRate( bool visible ) { d->m_showFrameRate = visible; } void MarbleMap::setShowRuntimeTrace( bool visible ) { d->m_layerManager.setShowRuntimeTrace( visible ); } +void MarbleMap::setShowDebugPolygons( bool visible) { + d->m_showDebugPolygons = visible; +} + void MarbleMap::setShowBackground( bool visible ) { d->m_layerManager.setShowBackground( visible ); } void MarbleMap::notifyMouseClick( int x, int y ) { qreal lon = 0; qreal lat = 0; const bool valid = geoCoordinates( x, y, lon, lat, GeoDataCoordinates::Radian ); if ( valid ) { emit mouseClickGeoPosition( lon, lat, GeoDataCoordinates::Radian ); } } void MarbleMap::clearVolatileTileCache() { d->m_vectorTileLayer.reset(); d->m_textureLayer.reset(); mDebug() << "Cleared Volatile Cache!"; } void MarbleMap::setVolatileTileCacheLimit( quint64 kilobytes ) { mDebug() << "kiloBytes" << kilobytes; d->m_textureLayer.setVolatileCacheLimit( kilobytes ); } AngleUnit MarbleMap::defaultAngleUnit() const { if ( GeoDataCoordinates::defaultNotation() == GeoDataCoordinates::Decimal ) { return DecimalDegree; } else if ( GeoDataCoordinates::defaultNotation() == GeoDataCoordinates::UTM ) { return UTM; } return DMSDegree; } void MarbleMap::setDefaultAngleUnit( AngleUnit angleUnit ) { if ( angleUnit == DecimalDegree ) { GeoDataCoordinates::setDefaultNotation( GeoDataCoordinates::Decimal ); return; } else if ( angleUnit == UTM ) { GeoDataCoordinates::setDefaultNotation( GeoDataCoordinates::UTM ); return; } GeoDataCoordinates::setDefaultNotation( GeoDataCoordinates::DMS ); } QFont MarbleMap::defaultFont() const { return GeoDataFeature::defaultFont(); } void MarbleMap::setDefaultFont( const QFont& font ) { GeoDataFeature::setDefaultFont( font ); d->m_placemarkLayer.requestStyleReset(); } QList MarbleMap::renderPlugins() const { return d->m_layerManager.renderPlugins(); } QList MarbleMap::floatItems() const { return d->m_layerManager.floatItems(); } AbstractFloatItem * MarbleMap::floatItem( const QString &nameId ) const { foreach ( AbstractFloatItem * floatItem, floatItems() ) { if ( floatItem && floatItem->nameId() == nameId ) { return floatItem; } } return 0; // No item found } QList MarbleMap::dataPlugins() const { return d->m_layerManager.dataPlugins(); } QList MarbleMap::whichItemAt( const QPoint& curpos ) const { return d->m_layerManager.whichItemAt( curpos ); } void MarbleMap::addLayer( LayerInterface *layer ) { d->m_layerManager.addLayer(layer); } void MarbleMap::removeLayer( LayerInterface *layer ) { d->m_layerManager.removeLayer(layer); } RenderStatus MarbleMap::renderStatus() const { return d->m_layerManager.renderState().status(); } RenderState MarbleMap::renderState() const { return d->m_layerManager.renderState(); } QString MarbleMap::addTextureLayer(GeoSceneTextureTileDataset *texture) { return textureLayer()->addTextureLayer(texture); } void MarbleMap::removeTextureLayer(const QString &key) { textureLayer()->removeTextureLayer(key); } // this method will only temporarily "pollute" the MarbleModel class TextureLayer *MarbleMap::textureLayer() const { return &d->m_textureLayer; } } #include "moc_MarbleMap.cpp" diff --git a/src/lib/marble/MarbleMap.h b/src/lib/marble/MarbleMap.h index beb7413a9..f26491ab6 100644 --- a/src/lib/marble/MarbleMap.h +++ b/src/lib/marble/MarbleMap.h @@ -1,744 +1,751 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2006-2008 Torsten Rahn // Copyright 2007 Inge Wallin // Copyright 2009 Jens-Michael Hoffmann // #ifndef MARBLE_MARBLEMAP_H #define MARBLE_MARBLEMAP_H /** @file * This file contains the headers for MarbleMap. * * @author Torsten Rahn * @author Inge Wallin */ #include #include #include #include #include #include "marble_export.h" #include "GeoDataCoordinates.h" // In geodata/data/ #include "RenderState.h" // Qt class QAbstractItemModel; class QItemSelectionModel; namespace Marble { // MarbleMap class MarbleMapPrivate; // Marble class GeoDataLatLonAltBox; class GeoDataFeature; class MarbleModel; class ViewportParams; class GeoPainter; class LayerInterface; class Quaternion; class RenderPlugin; class AbstractDataPlugin; class AbstractDataPluginItem; class AbstractFloatItem; class TextureLayer; class TileCoordsPyramid; class GeoSceneTextureTileDataset; /** * @short A class that can paint a view of the earth. * * FIXME: Change this description when we are done. * * This class can paint a view of the earth or any other globe, * depending on which dataset is used. It can be used to show the * globe in a widget like MarbleWidget does, or on any other * QPaintDevice. * * The projection and other view parameters that control how MarbleMap * paints the map is given through the class ViewParams. If the * programmer wants to allow the user to control the map, he/she has * to provide a way for the user to interact with it. An example of * this can be seen in the class MarbleWidgetInputHandler, that lets * the user control a MarbleWidget that uses MarbleMap internally. * * The MarbleMap needs to be provided with a data model to * work. This model is contained in the MarbleModel class. The widget * can also construct its own model if none is given to the * constructor. This data model contains 3 separate datatypes: * tiles which provide the background, vectors which * provide things like country borders and coastlines and * placemarks which can show points of interest, such as * cities, mountain tops or the poles. * * @see MarbleWidget * @see MarbleControlBox * @see MarbleModel */ class MARBLE_EXPORT MarbleMap : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.MarbleMap") public: friend class MarbleWidget; /** * @brief Construct a new MarbleMap. * * This constructor should be used when you will only use one * MarbleMap. The widget will create its own MarbleModel when * created. */ MarbleMap(); /** * @brief Construct a new MarbleMap. * @param model the data model for the widget. * * This constructor should be used when you plan to use more than * one MarbleMap for the same MarbleModel (not yet supported, * but will be soon). */ explicit MarbleMap( MarbleModel *model ); virtual ~MarbleMap(); /** * @brief Return the model that this view shows. */ MarbleModel *model() const; // Accessors to internal objects; ViewportParams *viewport(); const ViewportParams *viewport() const; /** * @brief Get the Projection used for the map * @return @c Spherical a Globe * @return @c Equirectangular a flat map * @return @c Mercator another flat map */ Projection projection() const; /** * @brief Get the ID of the current map theme * To ensure that a unique identifier is being used the theme does NOT * get represented by its name but the by relative location of the file * that specifies the theme: * * Example: * maptheme = "earth/bluemarble/bluemarble.dgml" */ QString mapThemeId() const; void setMapQualityForViewContext( MapQuality qualityForViewContext, ViewContext viewContext ); MapQuality mapQuality( ViewContext viewContext ) const; /** * @brief Return the current map quality. */ MapQuality mapQuality() const; void setViewContext( ViewContext viewContext ); ViewContext viewContext() const; void setSize( int width, int height ); void setSize( const QSize& size ); QSize size() const; int width() const; int height() const; /** * @brief Return the radius of the globe in pixels. */ int radius() const; int preferredRadiusCeil( int radius ); int preferredRadiusFloor( int radius ); int tileZoomLevel() const; /** * @brief return the minimum zoom value for the current map theme. */ int minimumZoom() const; /** * @brief return the minimum zoom value for the current map theme. */ int maximumZoom() const; bool discreteZoom() const; /** * @brief Get the screen coordinates corresponding to geographical coordinates in the map. * @param lon the lon coordinate of the requested pixel position * @param lat the lat coordinate of the requested pixel position * @param x the x coordinate of the pixel is returned through this parameter * @param y the y coordinate of the pixel is returned through this parameter * @return @c true if the geographical coordinates are visible on the screen * @c false if the geographical coordinates are not visible on the screen */ bool screenCoordinates( qreal lon, qreal lat, qreal& x, qreal& y ) const; /** * @brief Get the earth coordinates corresponding to a pixel in the map. * @param x the x coordinate of the pixel * @param y the y coordinate of the pixel * @param lon the longitude angle is returned through this parameter * @param lat the latitude angle is returned through this parameter * @return @c true if the pixel (x, y) is within the globe * @c false if the pixel (x, y) is outside the globe, i.e. in space. */ bool geoCoordinates( int x, int y, qreal& lon, qreal& lat, GeoDataCoordinates::Unit = GeoDataCoordinates::Degree ) const; /** * @brief Return the longitude of the center point. * @return The longitude of the center point in degree. */ qreal centerLongitude() const; /** * @brief Return the latitude of the center point. * @return The latitude of the center point in degree. */ qreal centerLatitude() const; QVector whichFeatureAt( const QPoint& ) const; /** * @brief Return the property value by name. * @return The property value (usually: visibility). */ bool propertyValue( const QString& name ) const; /** * @brief Return whether the overview map is visible. * @return The overview map visibility. */ bool showOverviewMap() const; /** * @brief Return whether the scale bar is visible. * @return The scale bar visibility. */ bool showScaleBar() const; /** * @brief Return whether the compass bar is visible. * @return The compass visibility. */ bool showCompass() const; /** * @brief Return whether the cloud cover is visible. * @return The cloud cover visibility. */ bool showClouds() const; /** * @brief Return whether the night shadow is visible. * @return visibility of night shadow */ bool showSunShading() const; /** * @brief Return whether the city lights are shown instead of the night shadow. * @return visibility of city lights */ bool showCityLights() const; /** * @brief Return whether the globe is locked to the sub solar point * @return if globe is locked to sub solar point */ bool isLockedToSubSolarPoint() const; /** * @brief Return whether the sun icon is shown in the sub solar point. * @return visibility of the sun icon in the sub solar point */ bool isSubSolarPointIconVisible() const; /** * @brief Return whether the atmospheric glow is visible. * @return The cloud cover visibility. */ bool showAtmosphere() const; /** * @brief Return whether the crosshairs are visible. * @return The crosshairs' visibility. */ bool showCrosshairs() const; /** * @brief Return whether the coordinate grid is visible. * @return The coordinate grid visibility. */ bool showGrid() const; /** * @brief Return whether the place marks are visible. * @return The place mark visibility. */ bool showPlaces() const; /** * @brief Return whether the city place marks are visible. * @return The city place mark visibility. */ bool showCities() const; /** * @brief Return whether the terrain place marks are visible. * @return The terrain place mark visibility. */ bool showTerrain() const; /** * @brief Return whether other places are visible. * @return The visibility of other places. */ bool showOtherPlaces() const; /** * @brief Return whether the relief is visible. * @return The relief visibility. */ bool showRelief() const; /** * @brief Return whether the ice layer is visible. * @return The ice layer visibility. */ bool showIceLayer() const; /** * @brief Return whether the borders are visible. * @return The border visibility. */ bool showBorders() const; /** * @brief Return whether the rivers are visible. * @return The rivers' visibility. */ bool showRivers() const; /** * @brief Return whether the lakes are visible. * @return The lakes' visibility. */ bool showLakes() const; /** * @brief Return whether the frame rate gets displayed. * @return the frame rates visibility */ bool showFrameRate() const; bool showBackground() const; /** * @brief Returns the limit in kilobytes of the volatile (in RAM) tile cache. * @return the limit of volatile tile cache in kilobytes. */ quint64 volatileTileCacheLimit() const; /** * @brief Returns a list of all RenderPlugins in the model, this includes float items * @return the list of RenderPlugins */ QList renderPlugins() const; QList floatItems() const; /** * @brief Returns a list of all FloatItems in the model * @return the list of the floatItems */ AbstractFloatItem * floatItem( const QString &nameId ) const; /** * @brief Returns a list of all DataPlugins on the layer * @return the list of DataPlugins */ QList dataPlugins() const; /** * @brief Returns all widgets of dataPlugins on the position curpos */ QList whichItemAt( const QPoint& curpos ) const; AngleUnit defaultAngleUnit() const; QFont defaultFont() const; TextureLayer *textureLayer() const; /** * @brief Add a layer to be included in rendering. */ void addLayer( LayerInterface *layer ); /** * @brief Adds a texture sublayer * @return Returns a key that identifies the texture sublayer */ QString addTextureLayer(GeoSceneTextureTileDataset *texture); /** * @brief Removes a texture sublayer * @param Key that was returned from corresponding addTextureLayer */ void removeTextureLayer(const QString &key); /** * @brief Remove a layer from being included in rendering. */ void removeLayer( LayerInterface *layer ); RenderStatus renderStatus() const; RenderState renderState() const; public Q_SLOTS: /** * @brief Paint the map using a give painter. * @param painter The painter to use. * @param dirtyRect the rectangle that actually needs repainting. */ void paint( GeoPainter &painter, const QRect &dirtyRect ); /** * @brief Set the radius of the globe in pixels. * @param radius The new globe radius value in pixels. */ void setRadius( int radius ); /** * @brief Rotate the view by the two angles phi and theta. * @param deltaLon an angle that specifies the change in terms of longitude * @param deltaLat an angle that specifies the change in terms of latitude * * This function rotates the view by two angles, * deltaLon ("theta") and deltaLat ("phi"). * If we start at (0, 0), the result will be the exact equivalent * of (lon, lat), otherwise the resulting angle will be the sum of * the previous position and the two offsets. */ void rotateBy( const qreal &deltaLon, const qreal &deltaLat ); /** * @brief Center the view on a geographical point * @param lat an angle parallel to the latitude lines * +90(N) - -90(S) * @param lon an angle parallel to the longitude lines * +180(W) - -180(E) */ void centerOn( const qreal lon, const qreal lat ); /** * @brief Set the latitude for the center point * @param lat the new value for the latitude in degree */ void setCenterLatitude( qreal lat ); /** * @brief Set the longitude for the center point * @param lon the new value for the longitude in degree */ void setCenterLongitude( qreal lon ); /** * @brief Set the Projection used for the map * @param projection projection type (e.g. Spherical, Equirectangular, Mercator) */ void setProjection( Projection projection ); /** * @brief Set a new map theme * @param maptheme The ID of the new maptheme. To ensure that a unique * identifier is being used the theme does NOT get represented by its * name but the by relative location of the file that specifies the theme: * * Example: * maptheme = "earth/bluemarble/bluemarble.dgml" */ void setMapThemeId( const QString& maptheme ); /** * @brief Sets the value of a map theme property * @param value value of the property (usually: visibility) * * Later on we might add a "setPropertyType and a QVariant * if needed. */ void setPropertyValue( const QString& name, bool value ); /** * @brief Set whether the overview map overlay is visible * @param visible visibility of the overview map */ void setShowOverviewMap( bool visible ); /** * @brief Set whether the scale bar overlay is visible * @param visible visibility of the scale bar */ void setShowScaleBar( bool visible ); /** * @brief Set whether the compass overlay is visible * @param visible visibility of the compass */ void setShowCompass( bool visible ); /** * @brief Set whether the cloud cover is visible * @param visible visibility of the cloud cover */ void setShowClouds( bool visible ); /** * @brief Set whether the night shadow is visible. * @param visibile visibility of shadow */ void setShowSunShading( bool visible ); /** * @brief Set whether city lights instead of night shadow are visible. * @param visible visibility of city lights */ void setShowCityLights( bool visible ); /** * @brief Set the globe locked to the sub solar point * @param vsible if globe is locked to the sub solar point */ void setLockToSubSolarPoint( bool visible ); /** * @brief Set whether the sun icon is shown in the sub solar point * @param visible if the sun icon is shown in the sub solar point */ void setSubSolarPointIconVisible( bool visible ); /** * @brief Set whether the is tile is visible * NOTE: This is part of the transitional debug API * and might be subject to changes until Marble 0.8 * @param visible visibility of the tile */ void setShowTileId( bool visible ); /** * @brief Set whether the atmospheric glow is visible * @param visible visibility of the atmospheric glow */ void setShowAtmosphere( bool visible ); /** * @brief Set whether the crosshairs are visible * @param visible visibility of the crosshairs */ void setShowCrosshairs( bool visible ); /** * @brief Set whether the coordinate grid overlay is visible * @param visible visibility of the coordinate grid */ void setShowGrid( bool visible ); /** * @brief Set whether the place mark overlay is visible * @param visible visibility of the place marks */ void setShowPlaces( bool visible ); /** * @brief Set whether the city place mark overlay is visible * @param visible visibility of the city place marks */ void setShowCities( bool visible ); /** * @brief Set whether the terrain place mark overlay is visible * @param visible visibility of the terrain place marks */ void setShowTerrain( bool visible ); /** * @brief Set whether the other places overlay is visible * @param visible visibility of other places */ void setShowOtherPlaces( bool visible ); /** * @brief Set whether the relief is visible * @param visible visibility of the relief */ void setShowRelief( bool visible ); /** * @brief Set whether the ice layer is visible * @param visible visibility of the ice layer */ void setShowIceLayer( bool visible ); /** * @brief Set whether the borders visible * @param visible visibility of the borders */ void setShowBorders( bool visible ); /** * @brief Set whether the rivers are visible * @param visible visibility of the rivers */ void setShowRivers( bool visible ); /** * @brief Set whether the lakes are visible * @param visible visibility of the lakes */ void setShowLakes( bool visible ); /** * @brief Set whether the frame rate gets shown * @param visible visibility of the frame rate */ void setShowFrameRate( bool visible ); void setShowRuntimeTrace( bool visible ); + /** + * @brief Set whether to enter the debug mode for + * polygon node drawing + * @param visible visibility of the node debug mode + */ + void setShowDebugPolygons( bool visible); + void setShowBackground( bool visible ); /** * @brief used to notify about the position of the mouse click */ void notifyMouseClick( int x, int y ); void clearVolatileTileCache(); /** * @brief Set the limit of the volatile (in RAM) tile cache. * @param bytes The limit in kilobytes. */ void setVolatileTileCacheLimit( quint64 kiloBytes ); void setDefaultAngleUnit( AngleUnit angleUnit ); void setDefaultFont( const QFont& font ); /** * @brief Reload the currently displayed map by reloading texture tiles * from the Internet. In the future this should be extended to all * kinds of data which is used in the map. */ void reload(); void downloadRegion( QVector const & ); Q_SIGNALS: void tileLevelChanged( int level ); /** * @brief Signal that the theme has changed * @param theme Name of the new theme. */ void themeChanged( const QString& theme ); void projectionChanged( Projection ); void radiusChanged( int radius ); void mouseMoveGeoPosition( const QString& ); void mouseClickGeoPosition( qreal lon, qreal lat, GeoDataCoordinates::Unit ); void framesPerSecond( qreal fps ); /** * This signal is emitted when the repaint of the view was requested. * If available with the @p dirtyRegion which is the region the view will change in. * If dirtyRegion.isEmpty() returns true, the whole viewport has to be repainted. */ void repaintNeeded( const QRegion& dirtyRegion = QRegion() ); /** * This signal is emitted when the visible region of the map changes. This typically happens * when the user moves the map around or zooms. */ void visibleLatLonAltBoxChanged( const GeoDataLatLonAltBox& visibleLatLonAltBox ); /** * @brief This signal is emit when the settings of a plugin changed. */ void pluginSettingsChanged(); /** * @brief Signal that a render item has been initialized */ void renderPluginInitialized( RenderPlugin *renderPlugin ); /** * @brief Emitted when the layer rendering status has changed * @param status New render status */ void renderStatusChanged( RenderStatus status ); void renderStateChanged( const RenderState &state ); void highlightedPlacemarksChanged( qreal, qreal, GeoDataCoordinates::Unit ); void viewContextChanged(ViewContext viewContext); protected: /** * @brief Enables custom drawing onto the MarbleMap straight after * @brief the globe and before all other layers have been rendered. * @param painter * * @deprecated implement LayerInterface and add it using @p addLayer() */ virtual void customPaint( GeoPainter *painter ); private: Q_PRIVATE_SLOT( d, void updateMapTheme() ) Q_PRIVATE_SLOT( d, void updateProperty( const QString &, bool ) ) Q_PRIVATE_SLOT( d, void setDocument(QString) ) Q_PRIVATE_SLOT( d, void updateTileLevel() ) private: Q_DISABLE_COPY( MarbleMap ) MarbleMapPrivate * const d; friend class MarbleMapPrivate; class CustomPaintLayer; friend class CustomPaintLayer; }; } #endif diff --git a/src/lib/marble/MarbleWidget.cpp b/src/lib/marble/MarbleWidget.cpp index 929af1f21..c36cc1676 100644 --- a/src/lib/marble/MarbleWidget.cpp +++ b/src/lib/marble/MarbleWidget.cpp @@ -1,1179 +1,1185 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2006-2007 Torsten Rahn // Copyright 2007 Inge Wallin // Copyright 2010-2012 Bernhard Beschow // Copyright 2012 Mohammed Nafees // #include "MarbleWidget.h" #include #include #include #include #include #include #include +#include #include #include #include #include #include "DataMigration.h" #include "FpsLayer.h" #include "FileManager.h" #include "GeoDataLatLonAltBox.h" #include "GeoDataPlacemark.h" #include "GeoPainter.h" #include "MarbleClock.h" #include "MarbleDebug.h" #include "MarbleDirs.h" #include "MarbleLocale.h" #include "MarbleMap.h" #include "MarbleModel.h" #include "MarbleWidgetInputHandler.h" #include "MarbleWidgetPopupMenu.h" #include "Planet.h" #include "PopupLayer.h" #include "RenderPlugin.h" #include "SunLocator.h" #include "TileCreatorDialog.h" #include "ViewportParams.h" #include "routing/RoutingLayer.h" #include "MarbleAbstractPresenter.h" namespace Marble { class MarbleWidget::CustomPaintLayer : public LayerInterface { public: explicit CustomPaintLayer( MarbleWidget *widget ) : m_widget( widget ) { } virtual QStringList renderPosition() const { return QStringList() << "USER_TOOLS"; } virtual bool render( GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer ) { Q_UNUSED( viewport ); Q_UNUSED( renderPos ); Q_UNUSED( layer ); painter->setPen( Qt::black ); m_widget->customPaint( painter ); return true; } virtual qreal zValue() const { return 1.0e7; } RenderState renderState() const { return RenderState( "Custom Widget Paint" ); } QString runtimeTrace() const { return QString( "MarbleWidget::CustomPaintLayer" ); } private: MarbleWidget *const m_widget; }; class MarbleWidgetPrivate { public: explicit MarbleWidgetPrivate( MarbleWidget *parent ) : m_widget( parent ), m_model(), m_map( &m_model ), m_presenter( &m_map ), m_inputhandler( 0 ), m_routingLayer( 0 ), m_mapInfoDialog( 0 ), m_customPaintLayer( parent ), m_popupmenu( 0 ), m_showFrameRate( false ) { } ~MarbleWidgetPrivate() { m_map.removeLayer( &m_customPaintLayer ); m_map.removeLayer( m_mapInfoDialog ); delete m_mapInfoDialog; delete m_popupmenu; } void construct(); void updateMapTheme(); void setInputHandler(); void setInputHandler( MarbleWidgetInputHandler *handler ); /** * @brief Update widget flags and cause a full repaint * * The background of the widget only needs to be redrawn in certain cases. This * method sets the widget flags accordingly and triggers a repaint. */ void updateSystemBackgroundAttribute(); MarbleWidget *const m_widget; MarbleModel m_model; MarbleMap m_map; MarbleAbstractPresenter m_presenter; MarbleWidgetInputHandler *m_inputhandler; RoutingLayer *m_routingLayer; PopupLayer *m_mapInfoDialog; MarbleWidget::CustomPaintLayer m_customPaintLayer; MarbleWidgetPopupMenu *m_popupmenu; bool m_showFrameRate; }; MarbleWidget::MarbleWidget(QWidget *parent) : QWidget( parent ), d( new MarbleWidgetPrivate( this ) ) { // setAttribute( Qt::WA_PaintOnScreen, true ); d->construct(); } MarbleWidget::~MarbleWidget() { // Remove and delete an existing InputHandler // initialized in d->construct() setInputHandler( 0 ); delete d; } void MarbleWidgetPrivate::construct() { QPointer dataMigration = new DataMigration( m_widget ); dataMigration->exec(); delete dataMigration; // Widget settings m_widget->setMinimumSize( 200, 300 ); m_widget->setFocusPolicy( Qt::WheelFocus ); m_widget->setFocus( Qt::OtherFocusReason ); // Set background: black. m_widget->setPalette( QPalette ( Qt::black ) ); // Set whether the black space gets displayed or the earth gets simply // displayed on the widget background. m_widget->setAutoFillBackground( true ); // Initialize the map and forward some signals. m_map.setSize( m_widget->width(), m_widget->height() ); m_map.setShowFrameRate( false ); // never let the map draw the frame rate, // we do this differently here in the widget m_widget->connect( &m_presenter, SIGNAL(regionSelected(QList)), m_widget, SIGNAL(regionSelected(QList)) ); m_widget->connect( &m_presenter, SIGNAL(zoomChanged(int)), m_widget, SIGNAL(zoomChanged(int)) ); m_widget->connect( &m_presenter, SIGNAL(distanceChanged(QString)), m_widget, SIGNAL(distanceChanged(QString)) ); // forward some signals of m_map m_widget->connect( &m_map, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)), m_widget, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)) ); m_widget->connect( &m_map, SIGNAL(projectionChanged(Projection)), m_widget, SIGNAL(projectionChanged(Projection)) ); m_widget->connect( &m_map, SIGNAL(tileLevelChanged(int)), m_widget, SIGNAL(tileLevelChanged(int)) ); m_widget->connect( &m_map, SIGNAL(framesPerSecond(qreal)), m_widget, SIGNAL(framesPerSecond(qreal)) ); m_widget->connect( &m_map, SIGNAL(viewContextChanged(ViewContext)), m_widget, SLOT(setViewContext(ViewContext)) ); m_widget->connect( &m_map, SIGNAL(pluginSettingsChanged()), m_widget, SIGNAL(pluginSettingsChanged()) ); m_widget->connect( &m_map, SIGNAL(renderPluginInitialized(RenderPlugin*)), m_widget, SIGNAL(renderPluginInitialized(RenderPlugin*)) ); // react to some signals of m_map m_widget->connect( &m_map, SIGNAL(themeChanged(QString)), m_widget, SLOT(updateMapTheme()) ); m_widget->connect( &m_map, SIGNAL(repaintNeeded(QRegion)), m_widget, SLOT(update()) ); m_widget->connect( &m_map, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)), m_widget, SLOT(updateSystemBackgroundAttribute()) ); m_widget->connect( &m_map, SIGNAL(renderStatusChanged(RenderStatus)), m_widget, SIGNAL(renderStatusChanged(RenderStatus)) ); m_widget->connect( &m_map, SIGNAL(renderStateChanged(RenderState)), m_widget, SIGNAL(renderStateChanged(RenderState)) ); m_widget->connect( m_model.fileManager(), SIGNAL(centeredDocument(GeoDataLatLonBox)), m_widget, SLOT(centerOn(GeoDataLatLonBox)) ); // Show a progress dialog when the model calculates new map tiles. m_widget->connect( &m_model, SIGNAL( creatingTilesStart( TileCreator*, const QString&, const QString& ) ), m_widget, SLOT( creatingTilesStart( TileCreator*, const QString&, const QString& ) ) ); m_popupmenu = new MarbleWidgetPopupMenu( m_widget, &m_model ); m_routingLayer = new RoutingLayer( m_widget, m_widget ); m_routingLayer->setPlacemarkModel( 0 ); QObject::connect( m_routingLayer, SIGNAL(repaintNeeded(QRect)), m_widget, SLOT(update()) ); m_mapInfoDialog = new PopupLayer( m_widget, m_widget ); m_mapInfoDialog->setVisible( false ); m_widget->connect( m_mapInfoDialog, SIGNAL(repaintNeeded()), m_widget, SLOT(update()) ); m_map.addLayer( m_mapInfoDialog ); setInputHandler(); m_widget->setMouseTracking( true ); m_map.addLayer( &m_customPaintLayer ); m_widget->connect( m_inputhandler, SIGNAL(mouseClickGeoPosition(qreal,qreal,GeoDataCoordinates::Unit)), m_widget, SIGNAL(highlightedPlacemarksChanged(qreal,qreal,GeoDataCoordinates::Unit)) ); m_widget->setHighlightEnabled( true ); } void MarbleWidgetPrivate::setInputHandler() { setInputHandler( new MarbleWidgetInputHandler( &m_presenter, m_widget ) ); } void MarbleWidgetPrivate::setInputHandler( MarbleWidgetInputHandler *handler ) { delete m_inputhandler; m_inputhandler = handler; if ( m_inputhandler ) { m_widget->installEventFilter( m_inputhandler ); QObject::connect( m_inputhandler, SIGNAL(mouseClickScreenPosition(int,int)), m_widget, SLOT(notifyMouseClick(int,int)) ); QObject::connect( m_inputhandler, SIGNAL(mouseMoveGeoPosition(QString)), m_widget, SIGNAL(mouseMoveGeoPosition(QString)) ); } } void MarbleWidgetPrivate::updateSystemBackgroundAttribute() { // We only have to repaint the background every time if the earth // doesn't cover the whole image. const bool isOn = m_map.viewport()->mapCoversViewport() && !m_model.mapThemeId().isEmpty(); m_widget->setAttribute( Qt::WA_NoSystemBackground, isOn ); } // ---------------------------------------------------------------- MarbleModel *MarbleWidget::model() { return &d->m_model; } const MarbleModel *MarbleWidget::model() const { return &d->m_model; } ViewportParams* MarbleWidget::viewport() { return d->m_map.viewport(); } const ViewportParams* MarbleWidget::viewport() const { return d->m_map.viewport(); } MarbleWidgetPopupMenu *MarbleWidget::popupMenu() { return d->m_popupmenu; } void MarbleWidget::setInputHandler( MarbleWidgetInputHandler *handler ) { d->setInputHandler(handler); } MarbleWidgetInputHandler *MarbleWidget::inputHandler() const { return d->m_inputhandler; } int MarbleWidget::radius() const { return d->m_map.radius(); } void MarbleWidget::setRadius( int radius ) { d->m_map.setRadius( radius ); } qreal MarbleWidget::moveStep() const { return d->m_presenter.moveStep(); } int MarbleWidget::zoom() const { return d->m_presenter.logzoom(); } int MarbleWidget::tileZoomLevel() const { return d->m_map.tileZoomLevel(); } int MarbleWidget::minimumZoom() const { return d->m_map.minimumZoom(); } int MarbleWidget::maximumZoom() const { return d->m_map.maximumZoom(); } QVector MarbleWidget::whichFeatureAt( const QPoint &curpos ) const { return d->m_map.whichFeatureAt( curpos ); } QList MarbleWidget::whichItemAt( const QPoint &curpos ) const { return d->m_map.whichItemAt( curpos ); } void MarbleWidget::addLayer( LayerInterface *layer ) { d->m_map.addLayer( layer ); } void MarbleWidget::removeLayer( LayerInterface *layer ) { d->m_map.removeLayer( layer ); } Marble::TextureLayer* MarbleWidget::textureLayer() const { return d->m_map.textureLayer(); } QPixmap MarbleWidget::mapScreenShot() { return QPixmap::grabWidget( this ); } RenderStatus MarbleWidget::renderStatus() const { return d->m_map.renderStatus(); } RenderState MarbleWidget::renderState() const { return d->m_map.renderState(); } void MarbleWidget::setHighlightEnabled(bool enabled) { if ( enabled ) { connect( this, SIGNAL(highlightedPlacemarksChanged(qreal,qreal,GeoDataCoordinates::Unit)), &d->m_map, SIGNAL(highlightedPlacemarksChanged(qreal,qreal,GeoDataCoordinates::Unit)), Qt::UniqueConnection ); } else { disconnect( this, SIGNAL(highlightedPlacemarksChanged(qreal,qreal,GeoDataCoordinates::Unit)), &d->m_map, SIGNAL(highlightedPlacemarksChanged(qreal,qreal,GeoDataCoordinates::Unit)) ); } } bool MarbleWidget::showOverviewMap() const { return d->m_map.showOverviewMap(); } bool MarbleWidget::showScaleBar() const { return d->m_map.showScaleBar(); } bool MarbleWidget::showCompass() const { return d->m_map.showCompass(); } bool MarbleWidget::showClouds() const { return d->m_map.showClouds(); } bool MarbleWidget::showSunShading() const { return d->m_map.showSunShading(); } bool MarbleWidget::showCityLights() const { return d->m_map.showCityLights(); } bool MarbleWidget::isLockedToSubSolarPoint() const { return d->m_map.isLockedToSubSolarPoint(); } bool MarbleWidget::isSubSolarPointIconVisible() const { return d->m_map.isSubSolarPointIconVisible(); } bool MarbleWidget::showAtmosphere() const { return d->m_map.showAtmosphere(); } bool MarbleWidget::showCrosshairs() const { return d->m_map.showCrosshairs(); } bool MarbleWidget::showGrid() const { return d->m_map.showGrid(); } bool MarbleWidget::showPlaces() const { return d->m_map.showPlaces(); } bool MarbleWidget::showCities() const { return d->m_map.showCities(); } bool MarbleWidget::showTerrain() const { return d->m_map.showTerrain(); } bool MarbleWidget::showOtherPlaces() const { return d->m_map.showOtherPlaces(); } bool MarbleWidget::showRelief() const { return d->m_map.showRelief(); } bool MarbleWidget::showIceLayer() const { return d->m_map.showIceLayer(); } bool MarbleWidget::showBorders() const { return d->m_map.showBorders(); } bool MarbleWidget::showRivers() const { return d->m_map.showRivers(); } bool MarbleWidget::showLakes() const { return d->m_map.showLakes(); } bool MarbleWidget::showFrameRate() const { return d->m_showFrameRate; } bool MarbleWidget::showBackground() const { return d->m_map.showBackground(); } quint64 MarbleWidget::volatileTileCacheLimit() const { return d->m_map.volatileTileCacheLimit(); } void MarbleWidget::setZoom( int newZoom, FlyToMode mode ) { d->m_presenter.setZoom( newZoom, mode ); } void MarbleWidget::zoomView( int zoom, FlyToMode mode ) { d->m_presenter.zoomView( zoom, mode ); } void MarbleWidget::zoomViewBy( int zoomStep, FlyToMode mode ) { d->m_presenter.zoomViewBy( zoomStep, mode ); } void MarbleWidget::zoomIn( FlyToMode mode ) { d->m_presenter.zoomIn( mode ); } void MarbleWidget::zoomOut( FlyToMode mode ) { d->m_presenter.zoomOut( mode ); } void MarbleWidget::rotateBy( const qreal deltaLon, const qreal deltaLat, FlyToMode mode ) { d->m_presenter.rotateBy( deltaLon, deltaLat, mode ); } void MarbleWidget::centerOn( const qreal lon, const qreal lat, bool animated ) { d->m_presenter.centerOn( lon, lat, animated ); } void MarbleWidget::centerOn( const GeoDataCoordinates &position, bool animated ) { d->m_presenter.centerOn( position, animated ); } void MarbleWidget::centerOn( const GeoDataLatLonBox &box, bool animated ) { d->m_presenter.centerOn( box, animated ); } void MarbleWidget::centerOn( const GeoDataPlacemark& placemark, bool animated ) { d->m_presenter.centerOn( placemark, animated ); } void MarbleWidget::setCenterLatitude( qreal lat, FlyToMode mode ) { d->m_presenter.setCenterLatitude( lat, mode ); } void MarbleWidget::setCenterLongitude( qreal lon, FlyToMode mode ) { d->m_presenter.setCenterLongitude( lon, mode ); } Projection MarbleWidget::projection() const { return d->m_map.projection(); } void MarbleWidget::setProjection( Projection projection ) { d->m_map.setProjection( projection ); } void MarbleWidget::setProjection( int projection ) { setProjection( Projection( qAbs( projection ) % (Mercator+1) ) ); } void MarbleWidget::moveLeft( FlyToMode mode ) { d->m_presenter.moveByStep( -1, 0, mode ); } void MarbleWidget::moveRight( FlyToMode mode ) { d->m_presenter.moveByStep( 1, 0, mode ); } void MarbleWidget::moveUp( FlyToMode mode ) { d->m_presenter.moveByStep( 0, -1, mode ); } void MarbleWidget::moveDown( FlyToMode mode ) { d->m_presenter.moveByStep( 0, 1, mode ); } void MarbleWidget::leaveEvent( QEvent* ) { emit mouseMoveGeoPosition( QCoreApplication::translate( "Marble", NOT_AVAILABLE ) ); } void MarbleWidget::resizeEvent( QResizeEvent *event ) { setUpdatesEnabled( false ); d->m_map.setSize( event->size() ); setUpdatesEnabled( true ); QWidget::resizeEvent( event ); } void MarbleWidget::connectNotify( const QMetaMethod &signal ) { if ( d->m_inputhandler && signal == QMetaMethod::fromSignal( &MarbleWidget::mouseMoveGeoPosition ) ) { d->m_inputhandler->setPositionSignalConnected( true ); } } void MarbleWidget::disconnectNotify( const QMetaMethod &signal ) { if ( d->m_inputhandler && signal == QMetaMethod::fromSignal( &MarbleWidget::mouseMoveGeoPosition ) ) { d->m_inputhandler->setPositionSignalConnected( false ); } } bool MarbleWidget::screenCoordinates( qreal lon, qreal lat, qreal& x, qreal& y ) const { return d->m_map.screenCoordinates( lon, lat, x, y ); } bool MarbleWidget::geoCoordinates( int x, int y, qreal& lon, qreal& lat, GeoDataCoordinates::Unit unit ) const { return d->m_map.geoCoordinates( x, y, lon, lat, unit ); } qreal MarbleWidget::centerLatitude() const { return d->m_map.centerLatitude(); } qreal MarbleWidget::centerLongitude() const { return d->m_map.centerLongitude(); } QRegion MarbleWidget::mapRegion() const { return viewport()->mapRegion(); } void MarbleWidget::paintEvent( QPaintEvent *evt ) { QTime t; t.start(); QPaintDevice *paintDevice = this; QImage image; if (!isEnabled()) { // If the globe covers fully the screen then we can use the faster // RGB32 as there are no translucent areas involved. QImage::Format imageFormat = ( d->m_map.viewport()->mapCoversViewport() ) ? QImage::Format_RGB32 : QImage::Format_ARGB32_Premultiplied; // Paint to an intermediate image image = QImage( rect().size(), imageFormat ); image.fill( Qt::transparent ); paintDevice = ℑ } { // FIXME: Better way to get the GeoPainter // Create a painter that will do the painting. GeoPainter geoPainter( paintDevice, d->m_map.viewport(), d->m_map.mapQuality() ); d->m_map.paint( geoPainter, evt->rect() ); } if ( !isEnabled() ) { // Draw a grayscale version of the intermediate image QRgb* pixel = reinterpret_cast( image.scanLine( 0 )); for (int i=0; im_showFrameRate ) { QPainter painter( this ); FpsLayer fpsPainter( &t ); fpsPainter.paint( &painter ); const qreal fps = 1000.0 / (qreal)( t.elapsed() + 1 ); emit framesPerSecond( fps ); } } void MarbleWidget::customPaint( GeoPainter *painter ) { Q_UNUSED( painter ); /* This is a NOOP in the base class*/ } void MarbleWidget::goHome( FlyToMode mode ) { d->m_presenter.goHome( mode ); } QString MarbleWidget::mapThemeId() const { return d->m_model.mapThemeId(); } void MarbleWidget::setMapThemeId( const QString& mapThemeId ) { d->m_map.setMapThemeId( mapThemeId ); } void MarbleWidgetPrivate::updateMapTheme() { m_map.removeLayer( m_routingLayer ); m_widget->setRadius( m_widget->radius() ); // Corrects zoom range, if needed if ( m_model.planetId() == "earth" ) { m_map.addLayer( m_routingLayer ); } emit m_widget->themeChanged( m_map.mapThemeId() ); // Now we want a full repaint as the atmosphere might differ m_widget->setAttribute( Qt::WA_NoSystemBackground, false ); m_widget->update(); } GeoSceneDocument *MarbleWidget::mapTheme() const { return d->m_model.mapTheme(); } void MarbleWidget::setPropertyValue( const QString& name, bool value ) { mDebug() << "In MarbleWidget the property " << name << "was set to " << value; d->m_map.setPropertyValue( name, value ); } void MarbleWidget::setShowOverviewMap( bool visible ) { d->m_map.setShowOverviewMap( visible ); } void MarbleWidget::setShowScaleBar( bool visible ) { d->m_map.setShowScaleBar( visible ); } void MarbleWidget::setShowCompass( bool visible ) { d->m_map.setShowCompass( visible ); } void MarbleWidget::setShowClouds( bool visible ) { d->m_map.setShowClouds( visible ); } void MarbleWidget::setShowSunShading( bool visible ) { d->m_map.setShowSunShading( visible ); } void MarbleWidget::setShowCityLights( bool visible ) { d->m_map.setShowCityLights( visible ); } void MarbleWidget::setLockToSubSolarPoint( bool visible ) { if ( d->m_map.isLockedToSubSolarPoint() != visible ) { // Toggling input modifies event filters, so avoid that if not needed d->m_map.setLockToSubSolarPoint( visible ); setInputEnabled( !d->m_map.isLockedToSubSolarPoint() ); } } void MarbleWidget::setSubSolarPointIconVisible( bool visible ) { if ( d->m_map.isSubSolarPointIconVisible() != visible ) { d->m_map.setSubSolarPointIconVisible( visible ); } QList pluginList = renderPlugins(); QList::const_iterator i = pluginList.constBegin(); QList::const_iterator const end = pluginList.constEnd(); for (; i != end; ++i ) { if ( (*i)->nameId() == "sun" ) { (*i)->setVisible( visible ); } } } void MarbleWidget::setShowAtmosphere( bool visible ) { d->m_map.setShowAtmosphere( visible ); } void MarbleWidget::setShowCrosshairs( bool visible ) { d->m_map.setShowCrosshairs( visible ); } void MarbleWidget::setShowGrid( bool visible ) { d->m_map.setShowGrid( visible ); } void MarbleWidget::setShowPlaces( bool visible ) { d->m_map.setShowPlaces( visible ); } void MarbleWidget::setShowCities( bool visible ) { d->m_map.setShowCities( visible ); } void MarbleWidget::setShowTerrain( bool visible ) { d->m_map.setShowTerrain( visible ); } void MarbleWidget::setShowOtherPlaces( bool visible ) { d->m_map.setShowOtherPlaces( visible ); } void MarbleWidget::setShowRelief( bool visible ) { d->m_map.setShowRelief( visible ); } void MarbleWidget::setShowIceLayer( bool visible ) { d->m_map.setShowIceLayer( visible ); } void MarbleWidget::setShowBorders( bool visible ) { d->m_map.setShowBorders( visible ); } void MarbleWidget::setShowRivers( bool visible ) { d->m_map.setShowRivers( visible ); } void MarbleWidget::setShowLakes( bool visible ) { d->m_map.setShowLakes( visible ); } void MarbleWidget::setShowFrameRate( bool visible ) { d->m_showFrameRate = visible; update(); } void MarbleWidget::setShowBackground( bool visible ) { d->m_map.setShowBackground( visible ); } void MarbleWidget::setShowRuntimeTrace( bool visible ) { d->m_map.setShowRuntimeTrace( visible ); } +void MarbleWidget::setShowDebugPolygons( bool visible) +{ + d->m_map.setShowDebugPolygons( visible ); +} + void MarbleWidget::setShowTileId( bool visible ) { d->m_map.setShowTileId( visible ); } void MarbleWidget::notifyMouseClick( int x, int y) { qreal lon = 0; qreal lat = 0; bool const valid = geoCoordinates( x, y, lon, lat, GeoDataCoordinates::Radian ); if ( valid ) { emit mouseClickGeoPosition( lon, lat, GeoDataCoordinates::Radian ); } } void MarbleWidget::clearVolatileTileCache() { mDebug() << "About to clear VolatileTileCache"; d->m_map.clearVolatileTileCache(); } void MarbleWidget::setVolatileTileCacheLimit( quint64 kiloBytes ) { d->m_map.setVolatileTileCacheLimit( kiloBytes ); } // This slot will called when the Globe starts to create the tiles. void MarbleWidget::creatingTilesStart( TileCreator *creator, const QString &name, const QString &description ) { QPointer dialog = new TileCreatorDialog( creator, this ); dialog->setSummary( name, description ); dialog->exec(); delete dialog; } MapQuality MarbleWidget::mapQuality( ViewContext viewContext ) const { return d->m_map.mapQuality( viewContext ); } void MarbleWidget::setMapQualityForViewContext( MapQuality quality, ViewContext viewContext ) { d->m_map.setMapQualityForViewContext( quality, viewContext ); } ViewContext MarbleWidget::viewContext() const { return d->m_map.viewContext(); } void MarbleWidget::setViewContext( ViewContext viewContext ) { // Inform routing layer about view context change. If not done, // the routing layer causes severe performance problems when dragging the // map. So either do not remove this line, or keep a similar call in place // when you refactor it and test your changes wrt drag performance at // high zoom level with long routes! d->m_routingLayer->setViewContext( viewContext ); d->m_map.setViewContext( viewContext ); } bool MarbleWidget::animationsEnabled() const { return d->m_presenter.animationsEnabled(); } void MarbleWidget::setAnimationsEnabled( bool enabled ) { d->m_presenter.setAnimationsEnabled( enabled ); } AngleUnit MarbleWidget::defaultAngleUnit() const { return d->m_map.defaultAngleUnit(); } void MarbleWidget::setDefaultAngleUnit( AngleUnit angleUnit ) { d->m_map.setDefaultAngleUnit( angleUnit ); } QFont MarbleWidget::defaultFont() const { return d->m_map.defaultFont(); } void MarbleWidget::setDefaultFont( const QFont& font ) { d->m_map.setDefaultFont( font ); } void MarbleWidget::setSelection( const QRect& region ) { d->m_presenter.setSelection( region ); } qreal MarbleWidget::distance() const { return d->m_presenter.distance(); } void MarbleWidget::setDistance( qreal newDistance ) { d->m_presenter.setDistance( newDistance ); } QString MarbleWidget::distanceString() const { return d->m_presenter.distanceString(); } void MarbleWidget::setInputEnabled( bool enabled ) { //if input is set as enabled if ( enabled ) { if ( !d->m_inputhandler ) { d->setInputHandler(); } else { installEventFilter( d->m_inputhandler ); } } else // input is disabled { mDebug() << "MarbleWidget::disableInput"; removeEventFilter( d->m_inputhandler ); setCursor( Qt::ArrowCursor ); } } QList MarbleWidget::renderPlugins() const { return d->m_map.renderPlugins(); } void MarbleWidget::readPluginSettings( QSettings& settings ) { foreach( RenderPlugin *plugin, renderPlugins() ) { settings.beginGroup( QString( "plugin_" ) + plugin->nameId() ); QHash hash; foreach ( const QString& key, settings.childKeys() ) { hash.insert( key, settings.value( key ) ); } plugin->setSettings( hash ); settings.endGroup(); } } void MarbleWidget::writePluginSettings( QSettings& settings ) const { foreach( RenderPlugin *plugin, renderPlugins() ) { settings.beginGroup( QString( "plugin_" ) + plugin->nameId() ); QHash hash = plugin->settings(); QHash::iterator it = hash.begin(); while( it != hash.end() ) { settings.setValue( it.key(), it.value() ); ++it; } settings.endGroup(); } } QList MarbleWidget::floatItems() const { return d->m_map.floatItems(); } AbstractFloatItem * MarbleWidget::floatItem( const QString &nameId ) const { return d->m_map.floatItem( nameId ); } void MarbleWidget::changeEvent( QEvent * event ) { if ( event->type() == QEvent::EnabledChange ) { setInputEnabled(isEnabled()); } QWidget::changeEvent(event); } void MarbleWidget::flyTo( const GeoDataLookAt &newLookAt, FlyToMode mode ) { d->m_presenter.flyTo( newLookAt, mode ); } void MarbleWidget::reloadMap() { d->m_map.reload(); } void MarbleWidget::downloadRegion( QVector const & pyramid ) { d->m_map.downloadRegion( pyramid ); } GeoDataLookAt MarbleWidget::lookAt() const { return d->m_presenter.lookAt(); } GeoDataCoordinates MarbleWidget::focusPoint() const { return d->m_map.viewport()->focusPoint(); } void MarbleWidget::setFocusPoint( const GeoDataCoordinates &focusPoint ) { d->m_map.viewport()->setFocusPoint( focusPoint ); } void MarbleWidget::resetFocusPoint() { d->m_map.viewport()->resetFocusPoint(); } qreal MarbleWidget::radiusFromDistance( qreal distance ) const { return d->m_presenter.radiusFromDistance( distance ); } qreal MarbleWidget::distanceFromRadius( qreal radius ) const { return d->m_presenter.distanceFromRadius( radius ); } qreal MarbleWidget::zoomFromDistance( qreal distance ) const { return d->m_presenter.zoomFromDistance( distance ); } qreal MarbleWidget::distanceFromZoom( qreal zoom ) const { return d->m_presenter.distanceFromZoom( zoom ); } RoutingLayer* MarbleWidget::routingLayer() { return d->m_routingLayer; } PopupLayer *MarbleWidget::popupLayer() { return d->m_mapInfoDialog; } } #include "moc_MarbleWidget.cpp" diff --git a/src/lib/marble/MarbleWidget.h b/src/lib/marble/MarbleWidget.h index db7d789f3..c66f3766e 100644 --- a/src/lib/marble/MarbleWidget.h +++ b/src/lib/marble/MarbleWidget.h @@ -1,1116 +1,1123 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2006-2008 Torsten Rahn // Copyright 2007 Inge Wallin // #ifndef MARBLE_MARBLEWIDGET_H #define MARBLE_MARBLEWIDGET_H /** @file * This file contains the headers for MarbleWidget. * * @author Torsten Rahn * @author Inge Wallin */ #include #include #include "GeoDataCoordinates.h" #include "GeoDataLookAt.h" #include "MarbleGlobal.h" // types needed in all of marble. #include "marble_export.h" #include "RenderState.h" // Qt class QAbstractItemModel; class QItemSelectionModel; class QSettings; namespace Marble { class AbstractDataPluginItem; class AbstractFloatItem; class GeoDataLatLonAltBox; class GeoDataLatLonBox; class GeoDataFeature; class GeoDataPlacemark; class GeoPainter; class GeoSceneDocument; class LayerInterface; class MarbleModel; class MarbleWidgetPopupMenu; class MarbleWidgetInputHandler; class MarbleWidgetPrivate; class RenderPlugin; class RoutingLayer; class TextureLayer; class TileCoordsPyramid; class TileCreator; class ViewportParams; class PopupLayer; /** * @short A widget class that displays a view of the earth. * * This widget displays a view of the earth or any other globe, * depending on which dataset is used. The user can navigate the * globe using either a control widget, e.g. the MarbleControlBox, or * the mouse. The mouse and keyboard control is done through a * MarbleWidgetInputHandler. Only some aspects of the widget can be * controlled by the mouse and/or keyboard. * * By clicking on the globe and moving the mouse, the position can be * changed. The user can also zoom by using the scroll wheel of the * mouse in the widget. The zoom value is not tied to any units, but * is an abstract value without any physical meaning. A value around * 1000 shows the full globe in a normal-sized window. Higher zoom * values give a more zoomed-in view. * * The MarbleWidget owns a data model to work. This model is contained * in the MarbleModel class, and it is painted by using a MarbleMap. * The widget takes care of creating the map and model. A MarbleModel * contains several datatypes, among them tiles which provide the * background, vectors which provide things like country * borders and coastlines and placemarks which can show points * of interest, such as cities, mountain tops or the poles. * * In addition to navigating with the mouse, you can also use it to * get information about items on the map. You can either click on a * placemark with the left mouse button or with the right mouse button * anywhere on the map. * * The left mouse button opens up a menu with all the placemarks * within a certain distance from the mouse pointer. When you choose * one item from the menu, Marble will open up a dialog window with * some information about the placemark and also try to connect to * Wikipedia to retrieve an article about it. If there is such an * article, you will get a mini-browser window with the article in a tab. * * @see MarbleControlBox * @see MarbleMap * @see MarbleModel */ class MARBLE_EXPORT MarbleWidget : public QWidget { Q_OBJECT #ifdef MARBLE_DBUS Q_CLASSINFO("D-Bus Interface", "org.kde.MarbleWidget") #endif Q_PROPERTY(int zoom READ zoom WRITE setZoom) Q_PROPERTY(QString mapThemeId READ mapThemeId WRITE setMapThemeId) Q_PROPERTY(int projection READ projection WRITE setProjection) Q_PROPERTY(qreal longitude READ centerLongitude WRITE setCenterLongitude) Q_PROPERTY(qreal latitude READ centerLatitude WRITE setCenterLatitude) Q_PROPERTY(bool showOverviewMap READ showOverviewMap WRITE setShowOverviewMap) Q_PROPERTY(bool showScaleBar READ showScaleBar WRITE setShowScaleBar) Q_PROPERTY(bool showCompass READ showCompass WRITE setShowCompass) Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid) Q_PROPERTY(bool showClouds READ showClouds WRITE setShowClouds) Q_PROPERTY(bool showSunShading READ showSunShading WRITE setShowSunShading) Q_PROPERTY(bool showCityLights READ showCityLights WRITE setShowCityLights) Q_PROPERTY(bool isLockedToSubSolarPoint READ isLockedToSubSolarPoint WRITE setLockToSubSolarPoint) Q_PROPERTY(bool isSubSolarPointIconVisible READ isSubSolarPointIconVisible WRITE setSubSolarPointIconVisible) Q_PROPERTY(bool showAtmosphere READ showAtmosphere WRITE setShowAtmosphere) Q_PROPERTY(bool showCrosshairs READ showCrosshairs WRITE setShowCrosshairs) Q_PROPERTY(bool showPlaces READ showPlaces WRITE setShowPlaces) Q_PROPERTY(bool showCities READ showCities WRITE setShowCities) Q_PROPERTY(bool showTerrain READ showTerrain WRITE setShowTerrain) Q_PROPERTY(bool showOtherPlaces READ showOtherPlaces WRITE setShowOtherPlaces) Q_PROPERTY(bool showRelief READ showRelief WRITE setShowRelief) Q_PROPERTY(bool showIceLayer READ showIceLayer WRITE setShowIceLayer) Q_PROPERTY(bool showBorders READ showBorders WRITE setShowBorders) Q_PROPERTY(bool showRivers READ showRivers WRITE setShowRivers) Q_PROPERTY(bool showLakes READ showLakes WRITE setShowLakes) Q_PROPERTY( RenderStatus renderStatus READ renderStatus NOTIFY renderStatusChanged ) Q_PROPERTY(quint64 volatileTileCacheLimit READ volatileTileCacheLimit WRITE setVolatileTileCacheLimit) public: /** * @brief Construct a new MarbleWidget. * @param parent the parent widget * * This constructor should be used when you will only use one * MarbleWidget. The widget will create its own MarbleModel when * created. */ explicit MarbleWidget( QWidget *parent = 0 ); virtual ~MarbleWidget(); /// @name Access to helper objects //@{ /** * @brief Return the model that this view shows. */ MarbleModel *model(); const MarbleModel *model() const; ViewportParams *viewport(); const ViewportParams *viewport() const; MarbleWidgetPopupMenu *popupMenu(); /** * Returns the current input handler */ MarbleWidgetInputHandler *inputHandler() const; /** * @brief Set the input handler */ void setInputHandler( MarbleWidgetInputHandler *handler ); /** * @brief Returns a list of all RenderPlugins on the widget, this includes float items * @return the list of RenderPlugins */ QList renderPlugins() const; /** * @brief Returns a list of all FloatItems on the widget * @return the list of the floatItems */ QList floatItems() const; /** * @brief Returns the FloatItem with the given id * @return The pointer to the requested floatItem, * * If no item is found the null pointer is returned. */ AbstractFloatItem * floatItem( const QString &nameId ) const; /** * Reads the plugin settings from the passed QSettings. * You shouldn't use this in a KDE application as these use KConfig. Here you could * use MarblePart which is handling this automatically. * @param settings The QSettings object to be used. */ void readPluginSettings( QSettings& settings ); /** * Writes the plugin settings in the passed QSettings. * You shouldn't use this in a KDE application as these use KConfig. Here you could * use MarblePart which is handling this automatically. * @param settings The QSettings object to be used. */ void writePluginSettings( QSettings& settings ) const; /** * @brief Retrieve the view context (i.e. still or animated map) */ ViewContext viewContext() const; /** * @brief Get the GeoSceneDocument object of the current map theme */ GeoSceneDocument * mapTheme() const; /** * @brief Returns all widgets of dataPlugins on the position curpos */ QList whichItemAt( const QPoint& curpos ) const; /** * @brief Add a layer to be included in rendering. */ void addLayer( LayerInterface *layer ); /** * @brief Remove a layer from being included in rendering. */ void removeLayer( LayerInterface *layer ); RoutingLayer* routingLayer(); PopupLayer* popupLayer(); /** * @brief Get the Projection used for the map * @return @c Spherical a Globe * @return @c Equirectangular a flat map * @return @c Mercator another flat map */ Projection projection() const; // int projection() const; //@} /// @name Visible map area //@{ /** * @brief Get the ID of the current map theme * To ensure that a unique identifier is being used the theme does NOT * get represented by its name but the by relative location of the file * that specifies the theme: * * Example: * mapThemeId = "earth/bluemarble/bluemarble.dgml" */ QString mapThemeId() const; /** * @brief Return the projected region which describes the (shape of the) projected surface. */ QRegion mapRegion() const; /** * @brief Return the radius of the globe in pixels. */ int radius() const; /** * @brief Return the current zoom amount. */ int zoom() const; int tileZoomLevel() const; /** * @brief Return the current distance. */ qreal distance() const; /** * @brief Return the current distance string. */ QString distanceString() const; /** * @brief Return the minimum zoom value for the current map theme. */ int minimumZoom() const; /** * @brief Return the minimum zoom value for the current map theme. */ int maximumZoom() const; //@} /// @name Position management //@{ /** * @brief Get the screen coordinates corresponding to geographical coordinates in the widget. * @param lon the lon coordinate of the requested pixel position * @param lat the lat coordinate of the requested pixel position * @param x the x coordinate of the pixel is returned through this parameter * @param y the y coordinate of the pixel is returned through this parameter * @return @c true if the geographical coordinates are visible on the screen * @c false if the geographical coordinates are not visible on the screen */ bool screenCoordinates( qreal lon, qreal lat, qreal& x, qreal& y ) const; /** * @brief Get the earth coordinates corresponding to a pixel in the widget. * @param x the x coordinate of the pixel * @param y the y coordinate of the pixel * @param lon the longitude angle is returned through this parameter * @param lat the latitude angle is returned through this parameter * @return @c true if the pixel (x, y) is within the globe * @c false if the pixel (x, y) is outside the globe, i.e. in space. */ bool geoCoordinates( int x, int y, qreal& lon, qreal& lat, GeoDataCoordinates::Unit = GeoDataCoordinates::Degree ) const; /** * @brief Return the longitude of the center point. * @return The longitude of the center point in degree. */ qreal centerLongitude() const; /** * @brief Return the latitude of the center point. * @return The latitude of the center point in degree. */ qreal centerLatitude() const; /** * @brief Return how much the map will move if one of the move slots are called. * @return The move step. */ qreal moveStep() const; /** * @brief Return the lookAt */ GeoDataLookAt lookAt() const; /** * @return The current point of focus, e.g. the point that is not moved * when changing the zoom level. If not set, it defaults to the * center point. * @see centerLongitude centerLatitude setFocusPoint resetFocusPoint */ GeoDataCoordinates focusPoint() const; /** * @brief Change the point of focus, overridding any previously set focus point. * @param focusPoint New focus point * @see focusPoint resetFocusPoint */ void setFocusPoint( const GeoDataCoordinates &focusPoint ); /** * @brief Invalidate any focus point set with @ref setFocusPoint. * @see focusPoint setFocusPoint */ void resetFocusPoint(); /** * @brief Return the globe radius (pixel) for the given distance (km) */ qreal radiusFromDistance( qreal distance ) const; /** * @brief Return the distance (km) at the given globe radius (pixel) */ qreal distanceFromRadius( qreal radius ) const; /** * Returns the zoom value (no unit) corresponding to the given camera distance (km) */ qreal zoomFromDistance( qreal distance ) const; /** * Returns the distance (km) corresponding to the given zoom value */ qreal distanceFromZoom( qreal zoom ) const; //@} /// @name Placemark management //@{ QVector whichFeatureAt( const QPoint& ) const; //@} /// @name Float items and map appearance //@{ /** * @brief Return whether the overview map is visible. * @return The overview map visibility. */ bool showOverviewMap() const; /** * @brief Return whether the scale bar is visible. * @return The scale bar visibility. */ bool showScaleBar() const; /** * @brief Return whether the compass bar is visible. * @return The compass visibility. */ bool showCompass() const; /** * @brief Return whether the cloud cover is visible. * @return The cloud cover visibility. */ bool showClouds() const; /** * @brief Return whether the night shadow is visible. * @return visibility of night shadow */ bool showSunShading() const; /** * @brief Return whether the city lights are shown instead of the night shadow. * @return visibility of city lights */ bool showCityLights() const; /** * @brief Return whether the globe is locked to the sub solar point * @return if globe is locked to sub solar point */ bool isLockedToSubSolarPoint() const; /** * @brief Return whether the sun icon is shown in the sub solar point. * @return visibility of the sun icon in the sub solar point */ bool isSubSolarPointIconVisible() const; /** * @brief Return whether the atmospheric glow is visible. * @return The cloud cover visibility. */ bool showAtmosphere() const; /** * @brief Return whether the crosshairs are visible. * @return The crosshairs' visibility. */ bool showCrosshairs() const; /** * @brief Return whether the coordinate grid is visible. * @return The coordinate grid visibility. */ bool showGrid() const; /** * @brief Return whether the place marks are visible. * @return The place mark visibility. */ bool showPlaces() const; /** * @brief Return whether the city place marks are visible. * @return The city place mark visibility. */ bool showCities() const; /** * @brief Return whether the terrain place marks are visible. * @return The terrain place mark visibility. */ bool showTerrain() const; /** * @brief Return whether other places are visible. * @return The visibility of other places. */ bool showOtherPlaces() const; /** * @brief Return whether the relief is visible. * @return The relief visibility. */ bool showRelief() const; /** * @brief Return whether the ice layer is visible. * @return The ice layer visibility. */ bool showIceLayer() const; /** * @brief Return whether the borders are visible. * @return The border visibility. */ bool showBorders() const; /** * @brief Return whether the rivers are visible. * @return The rivers' visibility. */ bool showRivers() const; /** * @brief Return whether the lakes are visible. * @return The lakes' visibility. */ bool showLakes() const; /** * @brief Return whether the frame rate gets displayed. * @return the frame rates visibility */ bool showFrameRate() const; bool showBackground() const; /** * @brief Retrieve the map quality depending on the view context */ MapQuality mapQuality( ViewContext = Still ) const; /** * @brief Retrieve whether travels to a point should get animated */ bool animationsEnabled() const; AngleUnit defaultAngleUnit() const; void setDefaultAngleUnit( AngleUnit angleUnit ); QFont defaultFont() const; void setDefaultFont( const QFont& font ); //@} /// @name Tile management //@{ /** * @brief Returns the limit in kilobytes of the volatile (in RAM) tile cache. * @return the limit of volatile tile cache */ quint64 volatileTileCacheLimit() const; //@} /// @name Miscellaneous //@{ /** * @brief Return a QPixmap with the current contents of the widget. */ QPixmap mapScreenShot(); //@} /// @todo Enable this instead of the zoomView slot below for proper deprecation warnings /// around Marble 1.8 // @deprecated Please use setZoom //MARBLE_DEPRECATED( void zoomView( int zoom, FlyToMode mode = Instant ) ); /** * Summarized render status of the current map view * @see renderState */ RenderStatus renderStatus() const; /** * Detailed render status of the current map view */ RenderState renderState() const; /** * Toggle whether regions are highlighted when user selects them */ void setHighlightEnabled( bool enabled ); public Q_SLOTS: /// @name Position management slots //@{ /** * @brief Set the radius of the globe in pixels. * @param radius The new globe radius value in pixels. */ void setRadius( int radius ); /** * @brief Zoom the view to a certain zoomlevel * @param zoom the new zoom level. * * The zoom level is an abstract value without physical * interpretation. A zoom value around 1000 lets the viewer see * all of the earth in the default window. */ void setZoom( int zoom, FlyToMode mode = Instant ); /** * @deprecated To be removed soon. Please use setZoom instead. Same parameters. */ void zoomView( int zoom, FlyToMode mode = Instant ); /** * @brief Zoom the view by a certain step * @param zoomStep the difference between the old zoom and the new */ void zoomViewBy( int zoomStep, FlyToMode mode = Instant ); /** * @brief Zoom in by the amount zoomStep. */ void zoomIn( FlyToMode mode = Automatic ); /** * @brief Zoom out by the amount zoomStep. */ void zoomOut( FlyToMode mode = Automatic ); /** * @brief Set the distance of the observer to the globe in km. * @param distance The new distance in km. */ void setDistance( qreal distance ); /** * @brief Rotate the view by the two angles phi and theta. * @param deltaLon an angle that specifies the change in terms of longitude * @param deltaLat an angle that specifies the change in terms of latitude * * This function rotates the view by two angles, * deltaLon ("theta") and deltaLat ("phi"). * If we start at (0, 0), the result will be the exact equivalent * of (lon, lat), otherwise the resulting angle will be the sum of * the previous position and the two offsets. */ void rotateBy( const qreal deltaLon, const qreal deltaLat, FlyToMode mode = Instant ); /** * @brief Center the view on a geographical point * @param lat an angle in degrees parallel to the latitude lines * +90(N) - -90(S) * @param lon an angle in degrees parallel to the longitude lines * +180(W) - -180(E) */ void centerOn( const qreal lon, const qreal lat, bool animated = false ); /** * @brief Center the view on a point * This method centers the Marble map on the point described by the latitude * and longitude in the GeoDataCoordinate parameter @c point. It also zooms * the map to be at the elevation described by the altitude. If this is * not the desired functionality or you do not have an accurate altitude * then use @see centerOn(qreal, qreal, bool) * @param point the point in 3 dimensions above the globe to move the view * to. It will always be looking vertically down. */ void centerOn( const GeoDataCoordinates &point, bool animated = false ); /** * @brief Center the view on a bounding box so that it completely fills the viewport * This method not only centers on the center of the GeoDataLatLon box but it also * adjusts the zoom of the marble widget so that the LatLon box provided fills * the viewport. * @param box The GeoDataLatLonBox to zoom and move the MarbleWidget to. */ void centerOn( const GeoDataLatLonBox& box, bool animated = false ); /** * @brief Center the view on a placemark according to the following logic: * - if the placemark has a lookAt, zoom and center on that lookAt * - otherwise use the placemark geometry's latLonAltBox * @param box The GeoDataPlacemark to zoom and move the MarbleWidget to. */ void centerOn( const GeoDataPlacemark& placemark, bool animated = false ); /** * @brief Set the latitude for the center point * @param lat the new value for the latitude in degree. * @param mode the FlyToMode that will be used. */ void setCenterLatitude( qreal lat, FlyToMode mode = Instant ); /** * @brief Set the longitude for the center point * @param lon the new value for the longitude in degree. * @param mode the FlyToMode that will be used. */ void setCenterLongitude( qreal lon, FlyToMode mode = Instant ); /** * @brief Move left by the moveStep. */ void moveLeft( FlyToMode mode = Automatic ); /** * @brief Move right by the moveStep. */ void moveRight( FlyToMode mode = Automatic ); /** * @brief Move up by the moveStep. */ void moveUp( FlyToMode mode = Automatic ); /** * @brief Move down by the moveStep. */ void moveDown( FlyToMode mode = Automatic ); /** * @brief Center the view on the default start point with the default zoom. */ void goHome( FlyToMode mode = Automatic ); /** * @brief Change the camera position to the given position. * @param lookAt New camera position. Changing the camera position means * that both the current center position as well as the zoom value may change * @param mode Interpolation type for intermediate camera positions. Automatic * (default) chooses a suitable interpolation among Instant, Lenar and Jump. * Instant will directly set the new zoom and position values, while * Linear results in a linear interpolation of intermediate center coordinates * along the sphere and a linear interpolation of changes in the camera distance * to the ground. Finally, Jump will behave the same as Linear with regard to * the center position interpolation, but use a parabolic height increase * towards the middle point of the intermediate positions. This appears * like a jump of the camera. */ void flyTo( const GeoDataLookAt &lookAt, FlyToMode mode = Automatic ); //@} /// @name Float items and map appearance slots //@{ /** * @brief Set the Projection used for the map * @param projection projection type (e.g. Spherical, Equirectangular, Mercator) */ void setProjection( int projection ); void setProjection( Projection projection ); /** * @brief Set a new map theme * @param maptheme The ID of the new maptheme. To ensure that a unique * identifier is being used the theme does NOT get represented by its * name but the by relative location of the file that specifies the theme: * * Example: * maptheme = "earth/bluemarble/bluemarble.dgml" */ void setMapThemeId( const QString& maptheme ); /** * @brief Sets the value of a map theme property * @param value value of the property (usually: visibility) * * Later on we might add a "setPropertyType and a QVariant * if needed. */ void setPropertyValue( const QString& name, bool value ); /** * @brief Set whether the overview map overlay is visible * @param visible visibility of the overview map */ void setShowOverviewMap( bool visible ); /** * @brief Set whether the scale bar overlay is visible * @param visible visibility of the scale bar */ void setShowScaleBar( bool visible ); /** * @brief Set whether the compass overlay is visible * @param visible visibility of the compass */ void setShowCompass( bool visible ); /** * @brief Set whether the cloud cover is visible * @param visible visibility of the cloud cover */ void setShowClouds( bool visible ); /** * @brief Set whether the night shadow is visible. * @param visibile visibility of shadow */ void setShowSunShading( bool visible ); /** * @brief Set whether city lights instead of night shadow are visible. * @param visible visibility of city lights */ void setShowCityLights( bool visible ); /** * @brief Set the globe locked to the sub solar point * @param vsible if globe is locked to the sub solar point */ void setLockToSubSolarPoint( bool visible ); /** * @brief Set whether the sun icon is shown in the sub solar point * @param visible if the sun icon is shown in the sub solar point */ void setSubSolarPointIconVisible( bool visible ); /** * @brief Set whether the atmospheric glow is visible * @param visible visibility of the atmospheric glow */ void setShowAtmosphere( bool visible ); /** * @brief Set whether the crosshairs are visible * @param visible visibility of the crosshairs */ void setShowCrosshairs( bool visible ); /** * @brief Set whether the coordinate grid overlay is visible * @param visible visibility of the coordinate grid */ void setShowGrid( bool visible ); /** * @brief Set whether the place mark overlay is visible * @param visible visibility of the place marks */ void setShowPlaces( bool visible ); /** * @brief Set whether the city place mark overlay is visible * @param visible visibility of the city place marks */ void setShowCities( bool visible ); /** * @brief Set whether the terrain place mark overlay is visible * @param visible visibility of the terrain place marks */ void setShowTerrain( bool visible ); /** * @brief Set whether the other places overlay is visible * @param visible visibility of other places */ void setShowOtherPlaces( bool visible ); /** * @brief Set whether the relief is visible * @param visible visibility of the relief */ void setShowRelief( bool visible ); /** * @brief Set whether the ice layer is visible * @param visible visibility of the ice layer */ void setShowIceLayer( bool visible ); /** * @brief Set whether the borders visible * @param visible visibility of the borders */ void setShowBorders( bool visible ); /** * @brief Set whether the rivers are visible * @param visible visibility of the rivers */ void setShowRivers( bool visible ); /** * @brief Set whether the lakes are visible * @param visible visibility of the lakes */ void setShowLakes( bool visible ); /** * @brief Set whether the frame rate gets shown * @param visible visibility of the frame rate */ void setShowFrameRate( bool visible ); void setShowBackground( bool visible ); /** * @brief Set whether the is tile is visible * NOTE: This is part of the transitional debug API * and might be subject to changes until Marble 0.8 * @param visible visibility of the tile */ void setShowTileId( bool visible ); /** * @brief Set whether the runtime tracing for layers gets shown * @param visible visibility of the runtime tracing */ void setShowRuntimeTrace( bool visible ); + /** + * @brief Set whether to enter the debug mode for + * polygon node drawing + * @param visible visibility of the node debug mode + */ + void setShowDebugPolygons( bool visible); + /** * @brief Set the map quality for the specified view context. * * @param quality map quality for the specified view context * @param viewContext view context whose map quality should be set */ void setMapQualityForViewContext( MapQuality quality, ViewContext viewContext ); /** * @brief Set the view context (i.e. still or animated map) */ void setViewContext( ViewContext viewContext ); /** * @brief Set whether travels to a point should get animated */ void setAnimationsEnabled( bool enabled ); //@} /// @name Tile management slots //@{ void clearVolatileTileCache(); /** * @brief Set the limit of the volatile (in RAM) tile cache. * @param kilobytes The limit in kilobytes. */ void setVolatileTileCacheLimit( quint64 kiloBytes ); /** * @brief A slot that is called when the model starts to create new tiles. * @param creator the tile creator object. * @param name the name of the created theme. * @param description a descriptive text that can be shown in a dialog. * @see creatingTilesProgress * * This function is connected to the models signal with the same * name. When the model needs to create a cache of tiles in * several different resolutions, it will emit creatingTilesStart * once with a name of the theme and a descriptive text. The * widget can then pop up a dialog to explain why there is a * delay. The model will then call creatingTilesProgress several * times until the parameter reaches 100 (100%), after which the * creation process is finished. After this there will be no more * calls to creatingTilesProgress, and the poup dialog can then be * closed. */ void creatingTilesStart( TileCreator *creator, const QString& name, const QString& description ); /** * @brief Re-download all visible tiles. */ void reloadMap(); void downloadRegion( QVector const & ); //@} /// @name Miscellaneous slots //@{ /** * @brief Used to notify about the position of the mouse click */ void notifyMouseClick( int x, int y ); void setSelection( const QRect& region ); void setInputEnabled( bool ); TextureLayer *textureLayer() const; //@} Q_SIGNALS: /** * @brief Signal that the zoom has changed, and to what. * @param zoom The new zoom value. * @see setZoom() */ void zoomChanged( int zoom ); void distanceChanged( const QString& distanceString ); void tileLevelChanged( int level ); /** * @brief Signal that the theme has changed * @param theme Name of the new theme. */ void themeChanged( const QString& theme ); void projectionChanged( Projection ); void mouseMoveGeoPosition( const QString& ); void mouseClickGeoPosition( qreal lon, qreal lat, GeoDataCoordinates::Unit ); void framesPerSecond( qreal fps ); /** This signal is emit when a new rectangle region is selected over the map * The list of double values include coordinates in degrees using this order: * lon1, lat1, lon2, lat2 (or West, North, East, South) as left/top, right/bottom rectangle. */ void regionSelected( const QList& ); /** * This signal is emit when the settings of a plugin changed. */ void pluginSettingsChanged(); /** * @brief Signal that a render item has been initialized */ void renderPluginInitialized( RenderPlugin *renderPlugin ); /** * This signal is emitted when the visible region of the map changes. This typically happens * when the user moves the map around or zooms. */ void visibleLatLonAltBoxChanged( const GeoDataLatLonAltBox& visibleLatLonAltBox ); /** * @brief Emitted when the layer rendering status has changed * @param status New render status */ void renderStatusChanged( RenderStatus status ); void renderStateChanged( const RenderState &state ); void highlightedPlacemarksChanged( qreal lon, qreal lat, GeoDataCoordinates::Unit unit ); protected: /** * @brief Reimplementation of the leaveEvent() function in QWidget. */ virtual void leaveEvent( QEvent *event ); /** * @brief Reimplementation of the paintEvent() function in QWidget. */ virtual void paintEvent( QPaintEvent *event ); /** * @brief Reimplementation of the resizeEvent() function in QWidget. */ virtual void resizeEvent( QResizeEvent *event ); virtual void connectNotify(const QMetaMethod &signal); virtual void disconnectNotify(const QMetaMethod &signal); /** * @brief Reimplementation of the changeEvent() function in QWidget to * react to changes of the enabled state */ virtual void changeEvent( QEvent * event ); /** * @brief Enables custom drawing onto the MarbleWidget straight after * @brief the globe and before all other layers has been rendered. * @param painter * * @deprecated implement LayerInterface and add it using @p addLayer() */ virtual void customPaint( GeoPainter *painter ); private: Q_PRIVATE_SLOT( d, void updateMapTheme() ) Q_PRIVATE_SLOT( d, void updateSystemBackgroundAttribute() ) private: Q_DISABLE_COPY( MarbleWidget ) MarbleWidgetPrivate * const d; friend class MarbleWidgetPrivate; class CustomPaintLayer; friend class CustomPaintLayer; friend class MarbleWidgetDefaultInputHandler; }; } #endif