Commit 40a99af6 authored by Jan Niklas Hasse's avatar Jan Niklas Hasse Committed by Torsten Rahn
Browse files

Avoid the need to set Qt::WA_DeleteOnClose on widgets using Marble

I've noticed that when using MarbleWidget in my app, closing the top
level widget will no longer quit the QApplication. This is because the
PopupLayer is still alive and has Qt::WA_QuitOnClose set, but is never
closed.

When unsetting it, MarbleWidget can be used in a window without having
to set Qt::WA_DeleteOnClose. This allows the window to be created on the
stack - also how it's done in Qt's examples:
https://doc.qt.io/qt-5/qtwidgets-mainwindows-application-example.html
parent 64de32f4
......@@ -384,32 +384,31 @@ int main ( int argc, char *argv[] )
MarbleGlobal::getInstance()->setProfiles( profiles );
QString marbleDataPath = parser.value( dataPathOption );
MainWindow *window = new MainWindow( marbleDataPath );
window->setAttribute( Qt::WA_DeleteOnClose, true );
window->show();
MainWindow window( marbleDataPath );
window.show();
if ( parser.isSet( timeOption ) ) {
window->resize(900, 640);
MarbleTest test( window->marbleWidget() );
window.resize(900, 640);
MarbleTest test( window.marbleWidget() );
test.timeDemo();
return 0;
}
if ( parser.isSet( fpsOption ) ) {
window->marbleControl()->marbleWidget()->setShowFrameRate( true );
window.marbleControl()->marbleWidget()->setShowFrameRate( true );
}
if (parser.isSet(levelOption)) {
window->marbleWidget()->setDebugLevelTags(true);
window.marbleWidget()->setDebugLevelTags(true);
}
if ( parser.isSet( tileOption ) ) {
window->marbleControl()->marbleWidget()->setShowTileId( true );
window.marbleControl()->marbleWidget()->setShowTileId( true );
}
const QString map = parser.value( mapIdOption );
if ( !map.isEmpty() ) {
window->marbleWidget()->setMapThemeId(map);
window.marbleWidget()->setMapThemeId(map);
}
const QString coordinatesString = parser.value( coordinatesOption );
......@@ -419,13 +418,13 @@ int main ( int argc, char *argv[] )
if ( success ) {
const qreal longitude = coordinates.longitude(GeoDataCoordinates::Degree);
const qreal latitude = coordinates.latitude(GeoDataCoordinates::Degree);
window->marbleWidget()->centerOn(longitude, latitude);
window.marbleWidget()->centerOn(longitude, latitude);
}
}
const QString geoUriString = parser.value( geoUriOption );
if ( !geoUriString.isEmpty() ) {
window->marbleControl()->openGeoUri( geoUriString );
window.marbleControl()->openGeoUri( geoUriString );
}
const QString distance = parser.value( distanceOption );
......@@ -433,14 +432,14 @@ int main ( int argc, char *argv[] )
bool success = false;
const qreal distanceValue = distance.toDouble(&success);
if ( success )
window->marbleWidget()->setDistance(distanceValue);
window.marbleWidget()->setDistance(distanceValue);
}
// Read the files that are given on the command line.
for( const QString &file: parser.positionalArguments() ) {
// FIXME: Use openUrl( args->url(i) ) instead?
if ( QFile::exists( file ) ) {
window->marbleControl()->addGeoDataFile( file );
window.marbleControl()->addGeoDataFile( file );
}
}
......
......@@ -265,42 +265,41 @@ int main(int argc, char *argv[])
cmdLineSettings.insert( QLatin1String("geo-uri"), QVariant(geoUriString) );
MainWindow *window = new MainWindow( marbleDataPath, cmdLineSettings );
window->setAttribute( Qt::WA_DeleteOnClose, true );
MainWindow window( marbleDataPath, cmdLineSettings );
// window->marbleWidget()->rotateTo( 0, 0, -90 );
// window->show();
// window.marbleWidget()->rotateTo( 0, 0, -90 );
// window.show();
for ( int i = 1; i < args.count(); ++i ) {
const QString arg = args.at(i);
if (arg == QLatin1String("--timedemo")) {
window->resize(900, 640);
MarbleTest marbleTest( window->marbleWidget() );
window.resize(900, 640);
MarbleTest marbleTest( window.marbleWidget() );
marbleTest.timeDemo();
return 0;
}
if (arg == QLatin1String("--fps")) {
window->marbleControl()->marbleWidget()->setShowFrameRate( true );
window.marbleControl()->marbleWidget()->setShowFrameRate( true );
}
else if (arg == QLatin1String("--tile-id")) {
window->marbleControl()->marbleWidget()->setShowTileId(true);
window.marbleControl()->marbleWidget()->setShowTileId(true);
}
else if (arg == QLatin1String("--runtimeTrace")) {
window->marbleControl()->marbleWidget()->setShowRuntimeTrace( true );
window.marbleControl()->marbleWidget()->setShowRuntimeTrace( true );
}
else if (arg == QLatin1String("--debug-polygons")) {
window->marbleControl()->marbleWidget()->setShowDebugPolygons( true );
window.marbleControl()->marbleWidget()->setShowDebugPolygons( true );
}
else if ( i != dataPathIndex && QFile::exists( arg ) ) {
window->addGeoDataFile(arg);
window.addGeoDataFile(arg);
}
else if (arg == QLatin1String("--debug-levels")) {
window->marbleWidget()->setDebugLevelTags(true);
window.marbleWidget()->setDebugLevelTags(true);
}
}
auto const marbleWidget = window->marbleControl()->marbleWidget();
auto const marbleWidget = window.marbleControl()->marbleWidget();
bool const debugModeEnabled = marbleWidget->showRuntimeTrace() || marbleWidget->showDebugPolygons() ||
marbleWidget->debugLevelTags() || MarbleDebug::isEnabled();
marbleWidget->inputHandler()->setDebugModeEnabled(debugModeEnabled);
......
......@@ -63,6 +63,7 @@ PopupItem::PopupItem( QObject* parent ) :
m_widget->setVisible(true);
m_widget->setAttribute(Qt::WA_DontShowOnScreen);
m_widget->setAttribute( Qt::WA_NoSystemBackground, true );
m_widget->setAttribute(Qt::WA_QuitOnClose, false);
QPalette palette = m_ui.webView->palette();
palette.setBrush(QPalette::Base, Qt::transparent);
#ifndef MARBLE_NO_WEBKITWIDGETS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment