QGIS API Documentation 3.99.0-Master (c4b875028a6)
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
18#include "qgsproject.h"
19
20#include <QString>
21
22#include "moc_qgsmapviewsmanager.cpp"
23
24using namespace Qt::StringLiterals;
25
27 : QObject( project )
28{
29
30}
31
32bool QgsMapViewsManager::readXml( const QDomElement &element, const QDomDocument &doc )
33{
34 Q_UNUSED( doc );
35 clear();
36
37 QgsReadWriteContext readWriteContext;
38 readWriteContext.setPathResolver( QgsProject::instance()->pathResolver() ); // skip-keyword-check
39 QDomElement elem3DMaps = element.firstChildElement( u"mapViewDocks3D"_s );
40 if ( !elem3DMaps.isNull() )
41 {
42 QDomElement elem3DMap = elem3DMaps.firstChildElement( u"view"_s );
43 while ( !elem3DMap.isNull() )
44 {
45 QString mapName = elem3DMap.attribute( u"name"_s );
46 m3DMapViewsDom.insert( mapName, elem3DMap );
47
48 elem3DMap = elem3DMap.nextSiblingElement( u"view"_s );
49 }
50 }
51
52 return true;
53}
54
55QDomElement QgsMapViewsManager::writeXml( QDomDocument &doc ) const
56{
57 QDomElement dom = doc.createElement( "mapViewDocks3D" );
58 for ( QDomElement d : m3DMapViewsDom )
59 dom.appendChild( d );
60 return dom;
61}
62
64{
65 m3DMapViewsDom.clear();
66 emit views3DListChanged();
67}
68
69QDomElement QgsMapViewsManager::get3DViewSettings( const QString &name ) const
70{
71 return m3DMapViewsDom.value( name, QDomElement() );
72}
73
74QList<QDomElement> QgsMapViewsManager::get3DViews() const
75{
76 return m3DMapViewsDom.values();
77}
78
79void QgsMapViewsManager::register3DViewSettings( const QString &name, const QDomElement &dom )
80{
81 m3DMapViewsDom.insert( name, dom );
82 emit views3DListChanged();
83}
84
86{
87 return m3DMapViewsDom.keys();
88}
89
90void QgsMapViewsManager::remove3DView( const QString &name )
91{
92 m3DMapViewsDom.remove( name );
93 emit views3DListChanged();
94}
95
96void QgsMapViewsManager::rename3DView( const QString &oldTitle, const QString &newTitle )
97{
98 QDomElement elem = m3DMapViewsDom.value( oldTitle );
99 m3DMapViewsDom.remove( oldTitle );
100 m3DMapViewsDom[ newTitle ] = elem;
101 m3DMapViewsDom[ newTitle ].setAttribute( u"name"_s, newTitle );
102 emit views3DListChanged();
103}
104
105void QgsMapViewsManager::set3DViewInitiallyVisible( const QString &name, bool visible )
106{
107 if ( m3DMapViewsDom.contains( name ) )
108 {
109 m3DMapViewsDom[ name ].setAttribute( u"isOpen"_s, visible );
110 }
111}
112
113bool QgsMapViewsManager::is3DViewOpen( const QString &name )
114{
115 return m3DMapViewsDom.value( name, QDomElement() ).attribute( u"isOpen"_s, u"1"_s ).toInt() == 1;
116}
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:113
static QgsProject * instance()
Returns the QgsProject singleton instance.
A container for the context for various read/write operations on objects.
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.