QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgsproject.h"
18 
20  : QObject( project )
21 {
22 
23 }
24 
25 bool QgsMapViewsManager::readXml( const QDomElement &element, const QDomDocument &doc )
26 {
27  Q_UNUSED( doc );
28  clear();
29 
30  QgsReadWriteContext readWriteContext;
31  readWriteContext.setPathResolver( QgsProject::instance()->pathResolver() );
32  QDomElement elem3DMaps = element.firstChildElement( QStringLiteral( "mapViewDocks3D" ) );
33  if ( !elem3DMaps.isNull() )
34  {
35  QDomElement elem3DMap = elem3DMaps.firstChildElement( QStringLiteral( "view" ) );
36  while ( !elem3DMap.isNull() )
37  {
38  QString mapName = elem3DMap.attribute( QStringLiteral( "name" ) );
39  m3DMapViewsDom.insert( mapName, elem3DMap );
40 
41  elem3DMap = elem3DMap.nextSiblingElement( QStringLiteral( "view" ) );
42  }
43  }
44 
45  return true;
46 }
47 
48 QDomElement QgsMapViewsManager::writeXml( QDomDocument &doc ) const
49 {
50  QDomElement dom = doc.createElement( "mapViewDocks3D" );
51  for ( QDomElement d : m3DMapViewsDom.values() )
52  dom.appendChild( d );
53  return dom;
54 }
55 
57 {
58  m3DMapViewsDom.clear();
59  emit views3DListChanged();
60 }
61 
62 QDomElement QgsMapViewsManager::get3DViewSettings( const QString &name ) const
63 {
64  return m3DMapViewsDom.value( name, QDomElement() );
65 }
66 
67 QList<QDomElement> QgsMapViewsManager::get3DViews() const
68 {
69  return m3DMapViewsDom.values();
70 }
71 
72 void QgsMapViewsManager::register3DViewSettings( const QString &name, const QDomElement &dom )
73 {
74  m3DMapViewsDom.insert( name, dom );
75  emit views3DListChanged();
76 }
77 
79 {
80  return m3DMapViewsDom.keys();
81 }
82 
83 void QgsMapViewsManager::remove3DView( const QString &name )
84 {
85  m3DMapViewsDom.remove( name );
86  emit views3DListChanged();
87 }
88 
89 void QgsMapViewsManager::rename3DView( const QString &oldTitle, const QString &newTitle )
90 {
91  QDomElement elem = m3DMapViewsDom.value( oldTitle );
92  m3DMapViewsDom.remove( oldTitle );
93  m3DMapViewsDom[ newTitle ] = elem;
94  m3DMapViewsDom[ newTitle ].setAttribute( QStringLiteral( "name" ), newTitle );
95  emit views3DListChanged();
96 }
97 
98 void QgsMapViewsManager::set3DViewInitiallyVisible( const QString &name, bool visible )
99 {
100  if ( m3DMapViewsDom.contains( name ) )
101  {
102  m3DMapViewsDom[ name ].setAttribute( QStringLiteral( "isOpen" ), visible );
103  }
104 }
105 
106 bool QgsMapViewsManager::is3DViewOpen( const QString &name )
107 {
108  return m3DMapViewsDom.value( name, QDomElement() ).attribute( QStringLiteral( "isOpen" ), QStringLiteral( "1" ) ).toInt() == 1;
109 }
QgsReadWriteContext::setPathResolver
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
Definition: qgsreadwritecontext.cpp:52
QgsMapViewsManager::remove3DView
void remove3DView(const QString &name)
Removes the configuration of the 3D view named name.
Definition: qgsmapviewsmanager.cpp:83
QgsMapViewsManager::get3DViews
QList< QDomElement > get3DViews() const
Returns the list of configurations of 3D views added to the manager.
Definition: qgsmapviewsmanager.cpp:67
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsMapViewsManager::readXml
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.
Definition: qgsmapviewsmanager.cpp:25
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsMapViewsManager::is3DViewOpen
bool is3DViewOpen(const QString &name)
Returns whether the 3D view named name will is opened.
Definition: qgsmapviewsmanager.cpp:106
QgsMapViewsManager::rename3DView
void rename3DView(const QString &oldTitle, const QString &newTitle)
Renames the 3D view named oldTitle to newTitle.
Definition: qgsmapviewsmanager.cpp:89
QgsMapViewsManager::clear
void clear()
Removes and deletes all views from the manager.
Definition: qgsmapviewsmanager.cpp:56
QgsMapViewsManager::get3DViewSettings
QDomElement get3DViewSettings(const QString &name) const
Returns the DOM element representing the settings of the 3D view named name.
Definition: qgsmapviewsmanager.cpp:62
QgsMapViewsManager::get3DViewsNames
QStringList get3DViewsNames() const
Returns the names of all 3D views added to the manager.
Definition: qgsmapviewsmanager.cpp:78
QgsMapViewsManager::set3DViewInitiallyVisible
void set3DViewInitiallyVisible(const QString &name, bool visible)
Sets whether the 3D view named name will be initially visible when the project is opened.
Definition: qgsmapviewsmanager.cpp:98
QgsMapViewsManager::QgsMapViewsManager
QgsMapViewsManager(QgsProject *project)
Constructor for QgsMapViewsManager.
Definition: qgsmapviewsmanager.cpp:19
qgsmapviewsmanager.h
QgsMapViewsManager::register3DViewSettings
void register3DViewSettings(const QString &name, const QDomElement &dom)
Adds a new 3D view named name to the manager with the configuration DOM dom.
Definition: qgsmapviewsmanager.cpp:72
QgsMapViewsManager::views3DListChanged
void views3DListChanged()
Emitted when the views list has changed (whenever a view was removed, added, renamed....
QgsMapViewsManager::writeXml
QDomElement writeXml(QDomDocument &doc) const
Returns a DOM element representing the state of the manager.
Definition: qgsmapviewsmanager.cpp:48
qgsproject.h