QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsmapviewsmanager.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmapviewsmanager.cpp
3 ------------------
4 Date : December 2021
5 Copyright : (C) 2021 Belgacem Nedjima
6 Email : gb underscore nedjima at esi dot dz
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsmapviewsmanager.h"
17#include "moc_qgsmapviewsmanager.cpp"
18#include "qgsproject.h"
19
21 : QObject( project )
22{
23
24}
25
26bool QgsMapViewsManager::readXml( const QDomElement &element, const QDomDocument &doc )
27{
28 Q_UNUSED( doc );
29 clear();
30
31 QgsReadWriteContext readWriteContext;
32 readWriteContext.setPathResolver( QgsProject::instance()->pathResolver() ); // skip-keyword-check
33 QDomElement elem3DMaps = element.firstChildElement( QStringLiteral( "mapViewDocks3D" ) );
34 if ( !elem3DMaps.isNull() )
35 {
36 QDomElement elem3DMap = elem3DMaps.firstChildElement( QStringLiteral( "view" ) );
37 while ( !elem3DMap.isNull() )
38 {
39 QString mapName = elem3DMap.attribute( QStringLiteral( "name" ) );
40 m3DMapViewsDom.insert( mapName, elem3DMap );
41
42 elem3DMap = elem3DMap.nextSiblingElement( QStringLiteral( "view" ) );
43 }
44 }
45
46 return true;
47}
48
49QDomElement QgsMapViewsManager::writeXml( QDomDocument &doc ) const
50{
51 QDomElement dom = doc.createElement( "mapViewDocks3D" );
52 for ( QDomElement d : m3DMapViewsDom )
53 dom.appendChild( d );
54 return dom;
55}
56
58{
59 m3DMapViewsDom.clear();
60 emit views3DListChanged();
61}
62
63QDomElement QgsMapViewsManager::get3DViewSettings( const QString &name ) const
64{
65 return m3DMapViewsDom.value( name, QDomElement() );
66}
67
68QList<QDomElement> QgsMapViewsManager::get3DViews() const
69{
70 return m3DMapViewsDom.values();
71}
72
73void QgsMapViewsManager::register3DViewSettings( const QString &name, const QDomElement &dom )
74{
75 m3DMapViewsDom.insert( name, dom );
76 emit views3DListChanged();
77}
78
80{
81 return m3DMapViewsDom.keys();
82}
83
84void QgsMapViewsManager::remove3DView( const QString &name )
85{
86 m3DMapViewsDom.remove( name );
87 emit views3DListChanged();
88}
89
90void QgsMapViewsManager::rename3DView( const QString &oldTitle, const QString &newTitle )
91{
92 QDomElement elem = m3DMapViewsDom.value( oldTitle );
93 m3DMapViewsDom.remove( oldTitle );
94 m3DMapViewsDom[ newTitle ] = elem;
95 m3DMapViewsDom[ newTitle ].setAttribute( QStringLiteral( "name" ), newTitle );
96 emit views3DListChanged();
97}
98
99void QgsMapViewsManager::set3DViewInitiallyVisible( const QString &name, bool visible )
100{
101 if ( m3DMapViewsDom.contains( name ) )
102 {
103 m3DMapViewsDom[ name ].setAttribute( QStringLiteral( "isOpen" ), visible );
104 }
105}
106
107bool QgsMapViewsManager::is3DViewOpen( const QString &name )
108{
109 return m3DMapViewsDom.value( name, QDomElement() ).attribute( QStringLiteral( "isOpen" ), QStringLiteral( "1" ) ).toInt() == 1;
110}
bool is3DViewOpen(const QString &name)
Returns whether the 3D view named name will is opened.
QDomElement writeXml(QDomDocument &doc) const
Returns a DOM element representing the state of the manager.
void remove3DView(const QString &name)
Removes the configuration of the 3D view named name.
void clear()
Removes and deletes all views from the manager.
QStringList get3DViewsNames() const
Returns the names of all 3D views added to the manager.
void rename3DView(const QString &oldTitle, const QString &newTitle)
Renames the 3D view named oldTitle to newTitle.
QList< QDomElement > get3DViews() const
Returns the list of configurations of 3D views added to the manager.
void views3DListChanged()
Emitted when the views list has changed (whenever a view was removed, added, renamed....
bool readXml(const QDomElement &element, const QDomDocument &doc)
Reads the manager's state from a DOM element, restoring all views present in the XML document.
void register3DViewSettings(const QString &name, const QDomElement &dom)
Adds a new 3D view named name to the manager with the configuration DOM dom.
QgsMapViewsManager(QgsProject *project)
Constructor for QgsMapViewsManager.
void set3DViewInitiallyVisible(const QString &name, bool visible)
Sets whether the 3D view named name will be initially visible when the project is opened.
QDomElement get3DViewSettings(const QString &name) const
Returns the DOM element representing the settings of the 3D view named name.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
static QgsProject * instance()
Returns the QgsProject singleton instance.
The class is used as a container of context for various read/write operations on other objects.
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.