mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Respect background color from project's main canvas
This commit is contained in:
parent
63adb73f55
commit
f7c942c879
@ -718,6 +718,11 @@ Emitted when the extents of the map change
|
|||||||
void magnificationChanged( double );
|
void magnificationChanged( double );
|
||||||
%Docstring
|
%Docstring
|
||||||
.. versionadded:: 2.16
|
.. versionadded:: 2.16
|
||||||
|
%End
|
||||||
|
|
||||||
|
void canvasColorChanged();
|
||||||
|
%Docstring
|
||||||
|
.. versionadded:: 3.0
|
||||||
%End
|
%End
|
||||||
|
|
||||||
void renderComplete( QPainter * );
|
void renderComplete( QPainter * );
|
||||||
|
@ -16,8 +16,8 @@ Map3D::Map3D()
|
|||||||
: originX( 0 )
|
: originX( 0 )
|
||||||
, originY( 0 )
|
, originY( 0 )
|
||||||
, originZ( 0 )
|
, originZ( 0 )
|
||||||
, backgroundColor( Qt::black )
|
|
||||||
, skybox( false )
|
, skybox( false )
|
||||||
|
, mBackgroundColor( Qt::black )
|
||||||
, mTerrainVerticalScale( 1 )
|
, mTerrainVerticalScale( 1 )
|
||||||
, mMapTileResolution( 512 )
|
, mMapTileResolution( 512 )
|
||||||
, mMaxTerrainScreenError( 3.f )
|
, mMaxTerrainScreenError( 3.f )
|
||||||
@ -33,10 +33,10 @@ Map3D::Map3D( const Map3D &other )
|
|||||||
, originY( other.originY )
|
, originY( other.originY )
|
||||||
, originZ( other.originZ )
|
, originZ( other.originZ )
|
||||||
, crs( other.crs )
|
, crs( other.crs )
|
||||||
, backgroundColor( other.backgroundColor )
|
|
||||||
, skybox( other.skybox )
|
, skybox( other.skybox )
|
||||||
, skyboxFileBase( other.skyboxFileBase )
|
, skyboxFileBase( other.skyboxFileBase )
|
||||||
, skyboxFileExtension( other.skyboxFileExtension )
|
, skyboxFileExtension( other.skyboxFileExtension )
|
||||||
|
, mBackgroundColor( other.mBackgroundColor )
|
||||||
, mTerrainVerticalScale( other.mTerrainVerticalScale )
|
, mTerrainVerticalScale( other.mTerrainVerticalScale )
|
||||||
, mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
|
, mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
|
||||||
, mMapTileResolution( other.mMapTileResolution )
|
, 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 )
|
void Map3D::setTerrainVerticalScale( double zScale )
|
||||||
{
|
{
|
||||||
if ( zScale == mTerrainVerticalScale )
|
if ( zScale == mTerrainVerticalScale )
|
||||||
|
@ -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)
|
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
|
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
|
// terrain related config
|
||||||
@ -80,6 +82,7 @@ class _3D_EXPORT Map3D : public QObject
|
|||||||
bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
|
bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void backgroundColorChanged();
|
||||||
void layersChanged();
|
void layersChanged();
|
||||||
void terrainGeneratorChanged();
|
void terrainGeneratorChanged();
|
||||||
void terrainVerticalScaleChanged();
|
void terrainVerticalScaleChanged();
|
||||||
@ -90,6 +93,7 @@ class _3D_EXPORT Map3D : public QObject
|
|||||||
void showTerrainTilesInfoChanged();
|
void showTerrainTilesInfoChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QColor mBackgroundColor; //!< Background color of the scene
|
||||||
double mTerrainVerticalScale; //!< Multiplier of terrain heights to make the terrain shape more pronounced
|
double mTerrainVerticalScale; //!< Multiplier of terrain heights to make the terrain shape more pronounced
|
||||||
std::unique_ptr<TerrainGenerator> mTerrainGenerator; //!< Implementation of the terrain generation
|
std::unique_ptr<TerrainGenerator> mTerrainGenerator; //!< Implementation of the terrain generation
|
||||||
int mMapTileResolution; //!< Size of map textures of tiles in pixels (width/height)
|
int mMapTileResolution; //!< Size of map textures of tiles in pixels (width/height)
|
||||||
|
@ -28,8 +28,11 @@ Scene::Scene( const Map3D &map, Qt3DExtras::QForwardRenderer *defaultFrameGraph,
|
|||||||
: Qt3DCore::QEntity( parent )
|
: Qt3DCore::QEntity( parent )
|
||||||
, mMap( map )
|
, mMap( map )
|
||||||
, mTerrain( nullptr )
|
, 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)
|
// 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.
|
// 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;
|
mTerrainUpdateScheduled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Scene::onBackgroundColorChanged()
|
||||||
|
{
|
||||||
|
mForwardRenderer->setClearColor( mMap.backgroundColor() );
|
||||||
|
}
|
||||||
|
|
||||||
void Scene::onLayerRenderer3DChanged()
|
void Scene::onLayerRenderer3DChanged()
|
||||||
{
|
{
|
||||||
QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );
|
QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );
|
||||||
|
@ -46,6 +46,7 @@ class _3D_EXPORT Scene : public Qt3DCore::QEntity
|
|||||||
void onLayerRenderer3DChanged();
|
void onLayerRenderer3DChanged();
|
||||||
void onLayersChanged();
|
void onLayersChanged();
|
||||||
void createTerrainDeferred();
|
void createTerrainDeferred();
|
||||||
|
void onBackgroundColorChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addLayerEntity( QgsMapLayer *layer );
|
void addLayerEntity( QgsMapLayer *layer );
|
||||||
@ -57,6 +58,8 @@ class _3D_EXPORT Scene : public Qt3DCore::QEntity
|
|||||||
Qt3DLogic::QFrameAction *mFrameAction;
|
Qt3DLogic::QFrameAction *mFrameAction;
|
||||||
CameraController *mCameraController;
|
CameraController *mCameraController;
|
||||||
Terrain *mTerrain;
|
Terrain *mTerrain;
|
||||||
|
//! Forward renderer provided by 3D window
|
||||||
|
Qt3DExtras::QForwardRenderer *mForwardRenderer;
|
||||||
QList<ChunkedEntity *> chunkEntities;
|
QList<ChunkedEntity *> chunkEntities;
|
||||||
//! Keeps track of entities that belong to a particular layer
|
//! Keeps track of entities that belong to a particular layer
|
||||||
QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
|
QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
|
||||||
|
@ -113,6 +113,6 @@ QgsMapSettings MapTextureGenerator::baseMapSettings()
|
|||||||
mapSettings.setLayers( map.layers() );
|
mapSettings.setLayers( map.layers() );
|
||||||
mapSettings.setOutputSize( QSize( map.mapTileResolution(), map.mapTileResolution() ) );
|
mapSettings.setOutputSize( QSize( map.mapTileResolution(), map.mapTileResolution() ) );
|
||||||
mapSettings.setDestinationCrs( map.crs );
|
mapSettings.setDestinationCrs( map.crs );
|
||||||
mapSettings.setBackgroundColor( Qt::gray );
|
mapSettings.setBackgroundColor( map.backgroundColor() );
|
||||||
return mapSettings;
|
return mapSettings;
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ Terrain::Terrain( int maxLevel, const Map3D &map, Qt3DCore::QNode *parent )
|
|||||||
connect( &map, &Map3D::showTerrainBoundingBoxesChanged, this, &Terrain::onShowBoundingBoxesChanged );
|
connect( &map, &Map3D::showTerrainBoundingBoxesChanged, this, &Terrain::onShowBoundingBoxesChanged );
|
||||||
connect( &map, &Map3D::showTerrainTilesInfoChanged, this, &Terrain::invalidateMapImages );
|
connect( &map, &Map3D::showTerrainTilesInfoChanged, this, &Terrain::invalidateMapImages );
|
||||||
connect( &map, &Map3D::layersChanged, this, &Terrain::onLayersChanged );
|
connect( &map, &Map3D::layersChanged, this, &Terrain::onLayersChanged );
|
||||||
|
connect( &map, &Map3D::backgroundColorChanged, this, &Terrain::invalidateMapImages );
|
||||||
|
|
||||||
connectToLayersRepaintRequest();
|
connectToLayersRepaintRequest();
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ Qgs3DMapCanvas::Qgs3DMapCanvas( QWidget *parent )
|
|||||||
QHBoxLayout *hLayout = new QHBoxLayout( this );
|
QHBoxLayout *hLayout = new QHBoxLayout( this );
|
||||||
hLayout->setMargin( 0 );
|
hLayout->setMargin( 0 );
|
||||||
hLayout->addWidget( mContainer, 1 );
|
hLayout->addWidget( mContainer, 1 );
|
||||||
|
|
||||||
|
mWindow3D->setCursor( Qt::OpenHandCursor );
|
||||||
}
|
}
|
||||||
|
|
||||||
Qgs3DMapCanvas::~Qgs3DMapCanvas()
|
Qgs3DMapCanvas::~Qgs3DMapCanvas()
|
||||||
|
@ -43,6 +43,7 @@ void Qgs3DMapCanvasDockWidget::setMainCanvas( QgsMapCanvas *canvas )
|
|||||||
mMainCanvas = canvas;
|
mMainCanvas = canvas;
|
||||||
|
|
||||||
connect( mMainCanvas, &QgsMapCanvas::layersChanged, this, &Qgs3DMapCanvasDockWidget::onMainCanvasLayersChanged );
|
connect( mMainCanvas, &QgsMapCanvas::layersChanged, this, &Qgs3DMapCanvasDockWidget::onMainCanvasLayersChanged );
|
||||||
|
connect( mMainCanvas, &QgsMapCanvas::canvasColorChanged, this, &Qgs3DMapCanvasDockWidget::onMainCanvasColorChanged );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Qgs3DMapCanvasDockWidget::resetView()
|
void Qgs3DMapCanvasDockWidget::resetView()
|
||||||
@ -72,3 +73,8 @@ void Qgs3DMapCanvasDockWidget::onMainCanvasLayersChanged()
|
|||||||
{
|
{
|
||||||
mCanvas->map()->setLayers( mMainCanvas->layers() );
|
mCanvas->map()->setLayers( mMainCanvas->layers() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Qgs3DMapCanvasDockWidget::onMainCanvasColorChanged()
|
||||||
|
{
|
||||||
|
mCanvas->map()->setBackgroundColor( mMainCanvas->canvasColor() );
|
||||||
|
}
|
||||||
|
@ -25,6 +25,7 @@ class Qgs3DMapCanvasDockWidget : public QgsDockWidget
|
|||||||
void configure();
|
void configure();
|
||||||
|
|
||||||
void onMainCanvasLayersChanged();
|
void onMainCanvasLayersChanged();
|
||||||
|
void onMainCanvasColorChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Qgs3DMapCanvas *mCanvas;
|
Qgs3DMapCanvas *mCanvas;
|
||||||
|
@ -9910,7 +9910,7 @@ void QgisApp::new3DMapCanvas()
|
|||||||
map->crs = prj->crs();
|
map->crs = prj->crs();
|
||||||
map->originX = fullExtent.center().x();
|
map->originX = fullExtent.center().x();
|
||||||
map->originY = fullExtent.center().y();
|
map->originY = fullExtent.center().y();
|
||||||
map->backgroundColor = mMapCanvas->canvasColor();
|
map->setBackgroundColor( mMapCanvas->canvasColor() );
|
||||||
map->setLayers( mMapCanvas->layers() );
|
map->setLayers( mMapCanvas->layers() );
|
||||||
|
|
||||||
FlatTerrainGenerator *flatTerrain = new FlatTerrainGenerator;
|
FlatTerrainGenerator *flatTerrain = new FlatTerrainGenerator;
|
||||||
|
@ -187,6 +187,10 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
|
|||||||
|
|
||||||
setInteractive( false );
|
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();
|
refresh();
|
||||||
|
|
||||||
} // QgsMapCanvas ctor
|
} // QgsMapCanvas ctor
|
||||||
@ -1560,6 +1564,9 @@ void QgsMapCanvas::unsetMapTool( QgsMapTool *tool )
|
|||||||
|
|
||||||
void QgsMapCanvas::setCanvasColor( const QColor &color )
|
void QgsMapCanvas::setCanvasColor( const QColor &color )
|
||||||
{
|
{
|
||||||
|
if ( canvasColor() == color )
|
||||||
|
return;
|
||||||
|
|
||||||
// background of map's pixmap
|
// background of map's pixmap
|
||||||
mSettings.setBackgroundColor( color );
|
mSettings.setBackgroundColor( color );
|
||||||
|
|
||||||
@ -1574,6 +1581,8 @@ void QgsMapCanvas::setCanvasColor( const QColor &color )
|
|||||||
|
|
||||||
// background of QGraphicsScene
|
// background of QGraphicsScene
|
||||||
mScene->setBackgroundBrush( bgBrush );
|
mScene->setBackgroundBrush( bgBrush );
|
||||||
|
|
||||||
|
emit canvasColorChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QgsMapCanvas::canvasColor() const
|
QColor QgsMapCanvas::canvasColor() const
|
||||||
|
@ -636,6 +636,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
|||||||
//! \since QGIS 2.16
|
//! \since QGIS 2.16
|
||||||
void magnificationChanged( double );
|
void magnificationChanged( double );
|
||||||
|
|
||||||
|
//! Emitted when canvas background color changes
|
||||||
|
//! \since QGIS 3.0
|
||||||
|
void canvasColorChanged();
|
||||||
|
|
||||||
/** Emitted when the canvas has rendered.
|
/** Emitted when the canvas has rendered.
|
||||||
* Passes a pointer to the painter on which the map was drawn. This is
|
* 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
|
* useful for plugins that wish to draw on the map after it has been
|
||||||
|
Loading…
x
Reference in New Issue
Block a user