Respect background color from project's main canvas

This commit is contained in:
Martin Dobias 2017-08-01 14:16:13 +02:00
parent 63adb73f55
commit f7c942c879
13 changed files with 63 additions and 6 deletions

View File

@ -718,6 +718,11 @@ Emitted when the extents of the map change
void magnificationChanged( double );
%Docstring
.. versionadded:: 2.16
%End
void canvasColorChanged();
%Docstring
.. versionadded:: 3.0
%End
void renderComplete( QPainter * );

View File

@ -16,8 +16,8 @@ Map3D::Map3D()
: originX( 0 )
, originY( 0 )
, originZ( 0 )
, backgroundColor( Qt::black )
, skybox( false )
, mBackgroundColor( Qt::black )
, mTerrainVerticalScale( 1 )
, mMapTileResolution( 512 )
, mMaxTerrainScreenError( 3.f )
@ -33,10 +33,10 @@ Map3D::Map3D( const Map3D &other )
, originY( other.originY )
, originZ( other.originZ )
, crs( other.crs )
, backgroundColor( other.backgroundColor )
, skybox( other.skybox )
, skyboxFileBase( other.skyboxFileBase )
, skyboxFileExtension( other.skyboxFileExtension )
, mBackgroundColor( other.mBackgroundColor )
, mTerrainVerticalScale( other.mTerrainVerticalScale )
, mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
, mMapTileResolution( other.mMapTileResolution )
@ -209,6 +209,20 @@ void Map3D::resolveReferences( const QgsProject &project )
}
}
void Map3D::setBackgroundColor( const QColor &color )
{
if ( color == mBackgroundColor )
return;
mBackgroundColor = color;
emit backgroundColorChanged();
}
QColor Map3D::backgroundColor() const
{
return mBackgroundColor;
}
void Map3D::setTerrainVerticalScale( double zScale )
{
if ( zScale == mTerrainVerticalScale )

View File

@ -39,7 +39,9 @@ class _3D_EXPORT Map3D : public QObject
double originX, originY, originZ; //!< Coordinates in map CRS at which our 3D world has origin (0,0,0)
QgsCoordinateReferenceSystem crs; //!< Destination coordinate system of the world (TODO: not needed? can be
QColor backgroundColor; //!< Background color of the scene
void setBackgroundColor( const QColor &color );
QColor backgroundColor() const;
//
// terrain related config
@ -80,6 +82,7 @@ class _3D_EXPORT Map3D : public QObject
bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
signals:
void backgroundColorChanged();
void layersChanged();
void terrainGeneratorChanged();
void terrainVerticalScaleChanged();
@ -90,6 +93,7 @@ class _3D_EXPORT Map3D : public QObject
void showTerrainTilesInfoChanged();
private:
QColor mBackgroundColor; //!< Background color of the scene
double mTerrainVerticalScale; //!< Multiplier of terrain heights to make the terrain shape more pronounced
std::unique_ptr<TerrainGenerator> mTerrainGenerator; //!< Implementation of the terrain generation
int mMapTileResolution; //!< Size of map textures of tiles in pixels (width/height)

View File

@ -28,8 +28,11 @@ Scene::Scene( const Map3D &map, Qt3DExtras::QForwardRenderer *defaultFrameGraph,
: Qt3DCore::QEntity( parent )
, mMap( map )
, mTerrain( nullptr )
, mForwardRenderer( defaultFrameGraph )
{
defaultFrameGraph->setClearColor( map.backgroundColor );
connect( &map, &Map3D::backgroundColorChanged, this, &Scene::onBackgroundColorChanged );
onBackgroundColorChanged();
// TODO: strange - setting OnDemand render policy still keeps QGIS busy (Qt 5.9.0)
// actually it is more busy than with the default "Always" policy although there are no changes in the scene.
@ -226,6 +229,11 @@ void Scene::createTerrainDeferred()
mTerrainUpdateScheduled = false;
}
void Scene::onBackgroundColorChanged()
{
mForwardRenderer->setClearColor( mMap.backgroundColor() );
}
void Scene::onLayerRenderer3DChanged()
{
QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );

View File

@ -46,6 +46,7 @@ class _3D_EXPORT Scene : public Qt3DCore::QEntity
void onLayerRenderer3DChanged();
void onLayersChanged();
void createTerrainDeferred();
void onBackgroundColorChanged();
private:
void addLayerEntity( QgsMapLayer *layer );
@ -57,6 +58,8 @@ class _3D_EXPORT Scene : public Qt3DCore::QEntity
Qt3DLogic::QFrameAction *mFrameAction;
CameraController *mCameraController;
Terrain *mTerrain;
//! Forward renderer provided by 3D window
Qt3DExtras::QForwardRenderer *mForwardRenderer;
QList<ChunkedEntity *> chunkEntities;
//! Keeps track of entities that belong to a particular layer
QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;

View File

@ -113,6 +113,6 @@ QgsMapSettings MapTextureGenerator::baseMapSettings()
mapSettings.setLayers( map.layers() );
mapSettings.setOutputSize( QSize( map.mapTileResolution(), map.mapTileResolution() ) );
mapSettings.setDestinationCrs( map.crs );
mapSettings.setBackgroundColor( Qt::gray );
mapSettings.setBackgroundColor( map.backgroundColor() );
return mapSettings;
}

View File

@ -46,6 +46,7 @@ Terrain::Terrain( int maxLevel, const Map3D &map, Qt3DCore::QNode *parent )
connect( &map, &Map3D::showTerrainBoundingBoxesChanged, this, &Terrain::onShowBoundingBoxesChanged );
connect( &map, &Map3D::showTerrainTilesInfoChanged, this, &Terrain::invalidateMapImages );
connect( &map, &Map3D::layersChanged, this, &Terrain::onLayersChanged );
connect( &map, &Map3D::backgroundColorChanged, this, &Terrain::invalidateMapImages );
connectToLayersRepaintRequest();

View File

@ -21,6 +21,8 @@ Qgs3DMapCanvas::Qgs3DMapCanvas( QWidget *parent )
QHBoxLayout *hLayout = new QHBoxLayout( this );
hLayout->setMargin( 0 );
hLayout->addWidget( mContainer, 1 );
mWindow3D->setCursor( Qt::OpenHandCursor );
}
Qgs3DMapCanvas::~Qgs3DMapCanvas()

View File

@ -43,6 +43,7 @@ void Qgs3DMapCanvasDockWidget::setMainCanvas( QgsMapCanvas *canvas )
mMainCanvas = canvas;
connect( mMainCanvas, &QgsMapCanvas::layersChanged, this, &Qgs3DMapCanvasDockWidget::onMainCanvasLayersChanged );
connect( mMainCanvas, &QgsMapCanvas::canvasColorChanged, this, &Qgs3DMapCanvasDockWidget::onMainCanvasColorChanged );
}
void Qgs3DMapCanvasDockWidget::resetView()
@ -72,3 +73,8 @@ void Qgs3DMapCanvasDockWidget::onMainCanvasLayersChanged()
{
mCanvas->map()->setLayers( mMainCanvas->layers() );
}
void Qgs3DMapCanvasDockWidget::onMainCanvasColorChanged()
{
mCanvas->map()->setBackgroundColor( mMainCanvas->canvasColor() );
}

View File

@ -25,6 +25,7 @@ class Qgs3DMapCanvasDockWidget : public QgsDockWidget
void configure();
void onMainCanvasLayersChanged();
void onMainCanvasColorChanged();
private:
Qgs3DMapCanvas *mCanvas;

View File

@ -9910,7 +9910,7 @@ void QgisApp::new3DMapCanvas()
map->crs = prj->crs();
map->originX = fullExtent.center().x();
map->originY = fullExtent.center().y();
map->backgroundColor = mMapCanvas->canvasColor();
map->setBackgroundColor( mMapCanvas->canvasColor() );
map->setLayers( mMapCanvas->layers() );
FlatTerrainGenerator *flatTerrain = new FlatTerrainGenerator;

View File

@ -187,6 +187,10 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
setInteractive( false );
// make sure we have the same default in QgsMapSettings and the scene's background brush
// (by default map settings has white bg color, scene background brush is black)
setCanvasColor( mSettings.backgroundColor() );
refresh();
} // QgsMapCanvas ctor
@ -1560,6 +1564,9 @@ void QgsMapCanvas::unsetMapTool( QgsMapTool *tool )
void QgsMapCanvas::setCanvasColor( const QColor &color )
{
if ( canvasColor() == color )
return;
// background of map's pixmap
mSettings.setBackgroundColor( color );
@ -1574,6 +1581,8 @@ void QgsMapCanvas::setCanvasColor( const QColor &color )
// background of QGraphicsScene
mScene->setBackgroundBrush( bgBrush );
emit canvasColorChanged();
}
QColor QgsMapCanvas::canvasColor() const

View File

@ -636,6 +636,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! \since QGIS 2.16
void magnificationChanged( double );
//! Emitted when canvas background color changes
//! \since QGIS 3.0
void canvasColorChanged();
/** Emitted when the canvas has rendered.
* Passes a pointer to the painter on which the map was drawn. This is
* useful for plugins that wish to draw on the map after it has been