Skip to content
Permalink
Browse files
split 3dviewsmanager into 3dviews manager and dialog class
  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 12, 2022
1 parent f62db16 commit 89c661b35dbaeb10dc98f8e4bb88229891a10a02
@@ -12,7 +12,10 @@
QgsProject.FlagDontStoreOriginalStyles = QgsProject.ReadFlag.FlagDontStoreOriginalStyles
QgsProject.FlagDontStoreOriginalStyles.is_monkey_patched = True
QgsProject.ReadFlag.FlagDontStoreOriginalStyles.__doc__ = "Skip the initial XML style storage for layers. Useful for minimising project load times in non-interactive contexts."
QgsProject.ReadFlag.__doc__ = 'Flags which control project read behavior.\n\n.. versionadded:: 3.10\n\n' + '* ``FlagDontResolveLayers``: ' + QgsProject.ReadFlag.FlagDontResolveLayers.__doc__ + '\n' + '* ``FlagDontLoadLayouts``: ' + QgsProject.ReadFlag.FlagDontLoadLayouts.__doc__ + '\n' + '* ``FlagTrustLayerMetadata``: ' + QgsProject.ReadFlag.FlagTrustLayerMetadata.__doc__ + '\n' + '* ``FlagDontStoreOriginalStyles``: ' + QgsProject.ReadFlag.FlagDontStoreOriginalStyles.__doc__
QgsProject.FlagDontLoad3DViews = QgsProject.ReadFlag.FlagDontLoad3DViews
QgsProject.FlagDontLoad3DViews.is_monkey_patched = True
QgsProject.ReadFlag.FlagDontLoad3DViews.__doc__ = ""
QgsProject.ReadFlag.__doc__ = 'Flags which control project read behavior.\n\n.. versionadded:: 3.10\n\n' + '* ``FlagDontResolveLayers``: ' + QgsProject.ReadFlag.FlagDontResolveLayers.__doc__ + '\n' + '* ``FlagDontLoadLayouts``: ' + QgsProject.ReadFlag.FlagDontLoadLayouts.__doc__ + '\n' + '* ``FlagTrustLayerMetadata``: ' + QgsProject.ReadFlag.FlagTrustLayerMetadata.__doc__ + '\n' + '* ``FlagDontStoreOriginalStyles``: ' + QgsProject.ReadFlag.FlagDontStoreOriginalStyles.__doc__ + '\n' + '* ``FlagDontLoad3DViews``: ' + QgsProject.ReadFlag.FlagDontLoad3DViews.__doc__
# --
# monkey patching scoped based enum
QgsProject.FileFormat.Qgz.__doc__ = "Archive file format, supports auxiliary data"
@@ -15,7 +15,6 @@




class QgsProject : QObject, QgsExpressionContextGenerator, QgsExpressionContextScopeGenerator, QgsProjectTranslator
{
%Docstring(signature="appended")
@@ -43,6 +42,7 @@ open within the main QGIS application.
FlagDontLoadLayouts,
FlagTrustLayerMetadata,
FlagDontStoreOriginalStyles,
FlagDontLoad3DViews,
};
typedef QFlags<QgsProject::ReadFlag> ReadFlags;

@@ -745,6 +745,15 @@ the project.
%End


Qgs3DViewsManager *views3DManager();
%Docstring
Returns the project's 3D views manager, which manages 3D views
in the project.

.. versionadded:: 3.24
%End


QgsBookmarkManager *bookmarkManager();
%Docstring
Returns the project's bookmark manager, which manages bookmarks within
@@ -1,5 +1,5 @@
/***************************************************************************
qgs3dviewsmanager.cpp
qgs3dviewsmanagerdialog.cpp
--------------------------------------
Date : December 2021
Copyright : (C) 2021 by Belgacem Nedjima
@@ -13,14 +13,15 @@
* *
***************************************************************************/

#include "qgs3dviewsmanager.h"
#include "qgs3dviewsmanagerdialog.h"

#include "qgisapp.h"
#include "qgs3dmapcanvasdockwidget.h"
#include "qgsnewnamedialog.h"
#include "qgs3dmapcanvas.h"
#include "qgs3dviewsmanager.h"

Qgs3DViewsManager::Qgs3DViewsManager( QWidget *parent, Qt::WindowFlags f )
Qgs3DViewsManagerDialog::Qgs3DViewsManagerDialog( QWidget *parent, Qt::WindowFlags f )
: QDialog( parent, f )
{
setupUi( this );
@@ -31,19 +32,27 @@ Qgs3DViewsManager::Qgs3DViewsManager( QWidget *parent, Qt::WindowFlags f )
m3DViewsListView->setEditTriggers( QAbstractItemView::NoEditTriggers );
m3DViewsListView->setSelectionMode( QAbstractItemView::SingleSelection );

connect( mOpenButton, &QToolButton::clicked, this, &Qgs3DViewsManager::openClicked );
connect( mDuplicateButton, &QToolButton::clicked, this, &Qgs3DViewsManager::duplicateClicked );
connect( mRemoveButton, &QToolButton::clicked, this, &Qgs3DViewsManager::removeClicked );
connect( mRenameButton, &QToolButton::clicked, this, &Qgs3DViewsManager::renameClicked );
connect( mOpenButton, &QToolButton::clicked, this, &Qgs3DViewsManagerDialog::openClicked );
connect( mDuplicateButton, &QToolButton::clicked, this, &Qgs3DViewsManagerDialog::duplicateClicked );
connect( mRemoveButton, &QToolButton::clicked, this, &Qgs3DViewsManagerDialog::removeClicked );
connect( mRenameButton, &QToolButton::clicked, this, &Qgs3DViewsManagerDialog::renameClicked );

connect( QgsProject::instance()->views3DManager(), &Qgs3DViewsManager::viewsListChanged, this, &Qgs3DViewsManagerDialog::onViewsListChanged );
}

void Qgs3DViewsManagerDialog::onViewsListChanged()
{
reload();
}

void Qgs3DViewsManager::openClicked()
void Qgs3DViewsManagerDialog::openClicked()
{
if ( m3DViewsListView->selectionModel()->selectedRows().isEmpty() )
return;

QString viewName = m3DViewsListView->selectionModel()->selectedRows().at( 0 ).data( Qt::DisplayRole ).toString();
Qgs3DMapCanvasDockWidget *widget = m3DMapViewsWidgets->value( viewName, nullptr );

Qgs3DMapCanvasDockWidget *widget = QgisApp::instance()->findChild<Qgs3DMapCanvasDockWidget *>( viewName );
if ( !widget )
{
widget = QgisApp::instance()->open3DMapView( viewName );
@@ -56,7 +65,7 @@ void Qgs3DViewsManager::openClicked()
}
}

void Qgs3DViewsManager::duplicateClicked()
void Qgs3DViewsManagerDialog::duplicateClicked()
{
if ( m3DViewsListView->selectionModel()->selectedRows().isEmpty() )
return;
@@ -65,25 +74,21 @@ void Qgs3DViewsManager::duplicateClicked()
QString newViewName = askUserForATitle( existingViewName, tr( "Duplicate" ), false );

QgisApp::instance()->duplicate3DMapView( existingViewName, newViewName );
reload();
}

void Qgs3DViewsManager::removeClicked()
void Qgs3DViewsManagerDialog::removeClicked()
{
if ( m3DViewsListView->selectionModel()->selectedRows().isEmpty() )
return;

QString viewName = m3DViewsListView->selectionModel()->selectedRows().at( 0 ).data( Qt::DisplayRole ).toString();
m3DMapViewsDom->remove( viewName );
if ( Qgs3DMapCanvasDockWidget *w = m3DMapViewsWidgets->value( viewName, nullptr ) )
{
m3DMapViewsWidgets->remove( viewName );

QgsProject::instance()->views3DManager()->remove3DView( viewName );
if ( Qgs3DMapCanvasDockWidget *w = QgisApp::instance()->findChild<Qgs3DMapCanvasDockWidget *>( viewName + QStringLiteral( "ViewObject" ) ) )
w->close();
}
reload();
}

void Qgs3DViewsManager::renameClicked()
void Qgs3DViewsManagerDialog::renameClicked()
{
if ( m3DViewsListView->selectionModel()->selectedRows().isEmpty() )
return;
@@ -94,45 +99,25 @@ void Qgs3DViewsManager::renameClicked()
if ( newTitle.isEmpty() )
return;

QDomElement dom = m3DMapViewsDom->value( oldTitle );
QgsProject::instance()->views3DManager()->rename3DView( oldTitle, newTitle );

m3DMapViewsDom->remove( oldTitle );
m3DMapViewsDom->insert( newTitle, dom );

if ( Qgs3DMapCanvasDockWidget *widget = m3DMapViewsWidgets->value( oldTitle, nullptr ) )
if ( Qgs3DMapCanvasDockWidget *widget = QgisApp::instance()->findChild<Qgs3DMapCanvasDockWidget *>( oldTitle + QStringLiteral( "ViewObject" ) ) )
{
m3DMapViewsWidgets->remove( oldTitle );
m3DMapViewsWidgets->insert( newTitle, widget );
widget->setWindowTitle( newTitle );
widget->mapCanvas3D()->setObjectName( newTitle );
}
reload();
}

void Qgs3DViewsManager::reload()
{
if ( !m3DMapViewsDom || !m3DMapViewsWidgets )
return;

mListModel->setStringList( m3DMapViewsDom->keys() );
}

void Qgs3DViewsManager::set3DMapViewsDom( QMap<QString, QDomElement> &mapViews3DDom )
{
m3DMapViewsDom = &mapViews3DDom;
reload();
}

void Qgs3DViewsManager::set3DMapViewsWidgets( QMap<QString, Qgs3DMapCanvasDockWidget *> &mapViews3DWidgets )
void Qgs3DViewsManagerDialog::reload()
{
m3DMapViewsWidgets = &mapViews3DWidgets;
reload();
QStringList names = QgsProject::instance()->views3DManager()->get3DViewsNames();
mListModel->setStringList( names );
}

QString Qgs3DViewsManager::askUserForATitle( QString oldTitle, QString action, bool allowExistingTitle )
QString Qgs3DViewsManagerDialog::askUserForATitle( QString oldTitle, QString action, bool allowExistingTitle )
{
QString newTitle = oldTitle;
QStringList notAllowedTitles = m3DMapViewsDom->keys();
QStringList notAllowedTitles = mListModel->stringList();
if ( allowExistingTitle )
notAllowedTitles.removeOne( oldTitle );
QgsNewNameDialog dlg( tr( "3D view" ), newTitle, QStringList(), notAllowedTitles, Qt::CaseSensitive, this );
@@ -13,39 +13,36 @@
* *
***************************************************************************/

#ifndef QGS3DVIEWSMANAGER_H
#define QGS3DVIEWSMANAGER_H
#ifndef QGS3DVIEWSMANAGERDIALOG_H
#define QGS3DVIEWSMANAGERDIALOG_H

#include "ui_qgs3dviewsmanager.h"
#include "ui_qgs3dviewsmanagerdialog.h"

#include <QDialog>
#include <QStringListModel>
#include <QDomElement>

class Qgs3DMapCanvasDockWidget;

class Qgs3DViewsManager : public QDialog, private Ui::Qgs3DViewsManager
class Qgs3DViewsManagerDialog : public QDialog, private Ui::Qgs3DViewsManagerDialog
{
Q_OBJECT

public:
explicit Qgs3DViewsManager( QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );
explicit Qgs3DViewsManagerDialog( QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );

void reload();

void set3DMapViewsDom( QMap<QString, QDomElement> &mapViews3DDom );
void set3DMapViewsWidgets( QMap<QString, Qgs3DMapCanvasDockWidget *> &mapViews3DWidgets );
private slots:
void openClicked();
void duplicateClicked();
void removeClicked();
void renameClicked();

void onViewsListChanged();
private:
QStringListModel *mListModel = nullptr;

QMap<QString, QDomElement> *m3DMapViewsDom = nullptr;
QMap<QString, Qgs3DMapCanvasDockWidget *> *m3DMapViewsWidgets = nullptr;

QString askUserForATitle( QString oldTitle, QString action, bool allowExistingTitle );
};

@@ -326,7 +326,7 @@ if (WITH_3D)
3d/qgsshadowrenderingsettingswidget.cpp
3d/qgspointcloud3dsymbolwidget.cpp
3d/qgspointcloudlayer3drendererwidget.cpp
3d/qgs3dviewsmanager.cpp
3d/qgs3dviewsmanagerdialog.cpp
)
endif()

0 comments on commit 89c661b

Please sign in to comment.