Skip to content
Permalink
Browse files
various fixes
  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 12, 2022
1 parent 8211fa0 commit 33ee137c329eab446d6a7142642167da33151377
@@ -88,7 +88,7 @@ Renames the 3D view named ``oldTitle`` to ``newTitle``
Sets the configuration of the 3D view named ``name`` to being opened
%End

void viewClosed( const QString &name );
void viewClosed( const QString &name, const QDomElement &dom );
%Docstring
Sets the configuration of the 3D view named ``name`` to being closed
%End
@@ -21,6 +21,8 @@
#include "qgs3dmapcanvas.h"
#include "qgs3dviewsmanager.h"

#include <QMessageBox>

Qgs3DViewsManagerDialog::Qgs3DViewsManagerDialog( QWidget *parent, Qt::WindowFlags f )
: QDialog( parent, f )
{
@@ -32,11 +34,17 @@ Qgs3DViewsManagerDialog::Qgs3DViewsManagerDialog( QWidget *parent, Qt::WindowFla
m3DViewsListView->setEditTriggers( QAbstractItemView::NoEditTriggers );
m3DViewsListView->setSelectionMode( QAbstractItemView::SingleSelection );

connect( mOpenButton, &QToolButton::clicked, this, &Qgs3DViewsManagerDialog::openClicked );
connect( mCloseButton, &QToolButton::clicked, this, &Qgs3DViewsManagerDialog::closeClicked );
connect( mButtonBox, &QDialogButtonBox::rejected, this, &QWidget::close );

connect( mShowButton, &QToolButton::clicked, this, &Qgs3DViewsManagerDialog::showClicked );
connect( mHideButton, &QToolButton::clicked, this, &Qgs3DViewsManagerDialog::hideClicked );
connect( mDuplicateButton, &QToolButton::clicked, this, &Qgs3DViewsManagerDialog::duplicateClicked );
connect( mRemoveButton, &QToolButton::clicked, this, &Qgs3DViewsManagerDialog::removeClicked );
connect( mRenameButton, &QToolButton::clicked, this, &Qgs3DViewsManagerDialog::renameClicked );
mShowButton->setEnabled( false );
mHideButton->setEnabled( false );

connect( m3DViewsListView->selectionModel(), &QItemSelectionModel::currentChanged, this, &Qgs3DViewsManagerDialog::showHideButtonStateChanged );

connect( QgsProject::instance()->views3DManager(), &Qgs3DViewsManager::viewsListChanged, this, &Qgs3DViewsManagerDialog::onViewsListChanged );
}
@@ -46,38 +54,42 @@ void Qgs3DViewsManagerDialog::onViewsListChanged()
reload();
}

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

QString viewName = m3DViewsListView->selectionModel()->selectedRows().at( 0 ).data( Qt::DisplayRole ).toString();

Qgs3DMapCanvasDockWidget *widget = QgisApp::instance()->findChild<Qgs3DMapCanvasDockWidget *>( viewName + QStringLiteral( "ViewObject" ) );
Qgs3DMapCanvasDockWidget *widget = QgisApp::instance()->findChild<Qgs3DMapCanvasDockWidget *>( viewName + QStringLiteral( "DockObject" ) );

if ( !widget )
{
widget = QgisApp::instance()->open3DMapView( viewName );
}

if ( widget )
{
widget->show();
widget->activateWindow();
widget->raise();
QgsProject::instance()->setDirty();
}

}

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

QString viewName = m3DViewsListView->selectionModel()->selectedRows().at( 0 ).data( Qt::DisplayRole ).toString();

Qgs3DMapCanvasDockWidget *widget = QgisApp::instance()->findChild<Qgs3DMapCanvasDockWidget *>( viewName + QStringLiteral( "ViewObject" ) );
Qgs3DMapCanvasDockWidget *widget = QgisApp::instance()->findChild<Qgs3DMapCanvasDockWidget *>( viewName + QStringLiteral( "DockObject" ) );
if ( widget )
{
widget->close();
}

QgsProject::instance()->setDirty();
}

void Qgs3DViewsManagerDialog::duplicateClicked()
@@ -89,18 +101,28 @@ void Qgs3DViewsManagerDialog::duplicateClicked()
QString newViewName = askUserForATitle( existingViewName, tr( "Duplicate" ), false );

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

QgsProject::instance()->setDirty();
}

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

QString warningTitle = tr( "Remove 3D View" );
QString warningMessage = tr( "Do you really want to remove selected 3D view?" );

if ( QMessageBox::warning( this, warningTitle, warningMessage, QMessageBox::Ok | QMessageBox::Cancel ) != QMessageBox::Ok )
return;

QString viewName = m3DViewsListView->selectionModel()->selectedRows().at( 0 ).data( Qt::DisplayRole ).toString();

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

QgsProject::instance()->setDirty();
}

void Qgs3DViewsManagerDialog::renameClicked()
@@ -116,11 +138,29 @@ void Qgs3DViewsManagerDialog::renameClicked()

QgsProject::instance()->views3DManager()->rename3DView( oldTitle, newTitle );

if ( Qgs3DMapCanvasDockWidget *widget = QgisApp::instance()->findChild<Qgs3DMapCanvasDockWidget *>( oldTitle + QStringLiteral( "ViewObject" ) ) )
if ( Qgs3DMapCanvasDockWidget *widget = QgisApp::instance()->findChild<Qgs3DMapCanvasDockWidget *>( oldTitle + QStringLiteral( "DockObject" ) ) )
{
widget->setWindowTitle( newTitle );
widget->setObjectName( newTitle + QStringLiteral( "DockObject" ) );
widget->mapCanvas3D()->setObjectName( newTitle );
}

QgsProject::instance()->setDirty();
}

void Qgs3DViewsManagerDialog::showHideButtonStateChanged( const QModelIndex &current, const QModelIndex &previous )
{
if ( !current.isValid() )
{
mShowButton->setEnabled( false );
mHideButton->setEnabled( false );
return;
}

QString viewName = current.data( Qt::DisplayRole ).toString();
bool isOpen = QgsProject::instance()->views3DManager()->get3DViewSettings( viewName ).attribute( QStringLiteral( "isOpen" ), QStringLiteral( "0" ) ).toInt() == 1;
mShowButton->setEnabled( !isOpen );
mHideButton->setEnabled( isOpen );
}

void Qgs3DViewsManagerDialog::reload()
@@ -34,12 +34,14 @@ class Qgs3DViewsManagerDialog : public QDialog, private Ui::Qgs3DViewsManagerDia
void reload();

private slots:
void openClicked();
void closeClicked();
void showClicked();
void hideClicked();
void duplicateClicked();
void removeClicked();
void renameClicked();

void showHideButtonStateChanged( const QModelIndex &current, const QModelIndex &previous );

void onViewsListChanged();
private:
QStringListModel *mListModel = nullptr;
@@ -9897,34 +9897,29 @@ void QgisApp::setupLayoutManagerConnections()
} );
}

Qgs3DMapCanvasDockWidget *QgisApp::open3DMapView( const QString &mapName )
Qgs3DMapCanvasDockWidget *QgisApp::open3DMapView( const QString &viewName )
{
#ifdef HAVE_3D
QgsReadWriteContext readWriteContext;
readWriteContext.setPathResolver( QgsProject::instance()->pathResolver() );

QDomElement elem3DMap = QgsProject::instance()->views3DManager()->get3DViewSettings( mapName );
QDomElement elem3DMap = QgsProject::instance()->views3DManager()->get3DViewSettings( viewName );

if ( elem3DMap.isNull() )
return nullptr;

Qgs3DMapCanvasDockWidget *mapCanvasDock3D = createNew3DMapCanvasDock( mapName );
Qgs3DMapCanvasDockWidget *mapCanvasDock3D = createNew3DMapCanvasDock( viewName );
if ( !mapCanvasDock3D )
return nullptr;

read3DMapViewSettings( mapCanvasDock3D, elem3DMap );
mPanelMenu->removeAction( mapCanvasDock3D->toggleViewAction() );

QgsProject::instance()->views3DManager()->viewOpened( mapName );

connect( mapCanvasDock3D, &Qgs3DMapCanvasDockWidget::closed, [ &, mapName]()
{
QgsProject::instance()->views3DManager()->viewClosed( mapName );
} );
QgsProject::instance()->views3DManager()->viewOpened( viewName );

return mapCanvasDock3D;
#else
Q_UNUSED( mapName );
Q_UNUSED( viewName );
return nullptr;
#endif
}
@@ -9947,7 +9942,7 @@ Qgs3DMapCanvasDockWidget *QgisApp::duplicate3DMapView( const QString &existingVi

// If the 3D view is open, copy its configuration to the duplicate widget, otherwise just use the recorded
// settings from m3DMapViewsWidgets
if ( Qgs3DMapCanvasDockWidget *w = findChild<Qgs3DMapCanvasDockWidget *>( existingViewName + QStringLiteral( "ViewObject" ) ) )
if ( Qgs3DMapCanvasDockWidget *w = findChild<Qgs3DMapCanvasDockWidget *>( existingViewName + QStringLiteral( "DockObject" ) ) )
{
Qgs3DMapSettings *map = new Qgs3DMapSettings( *w->mapCanvas3D()->map() );
mapCanvasDock3D->setMapSettings( map );
@@ -9966,6 +9961,7 @@ Qgs3DMapCanvasDockWidget *QgisApp::duplicate3DMapView( const QString &existingVi
mapCanvasDock3D->setMapSettings( map );

QDomElement elem = QgsProject::instance()->views3DManager()->get3DViewSettings( existingViewName );
elem.setAttribute( QStringLiteral( "name" ), newViewName );
read3DMapViewSettings( mapCanvasDock3D, elem );
}

@@ -10096,7 +10092,7 @@ void QgisApp::populate3DMapviewsMenu( QMenu *menu )
}
else
{
if ( Qgs3DMapCanvasDockWidget *w = QgisApp::instance()->findChild<Qgs3DMapCanvasDockWidget *>( viewName + QStringLiteral( "ViewObject" ) ) )
if ( Qgs3DMapCanvasDockWidget *w = QgisApp::instance()->findChild<Qgs3DMapCanvasDockWidget *>( viewName + QStringLiteral( "DockObject" ) ) )
{
w->close();
}
@@ -13956,13 +13952,29 @@ Qgs3DMapCanvasDockWidget *QgisApp::createNew3DMapCanvasDock( const QString &name
markDirty();

Qgs3DMapCanvasDockWidget *map3DWidget = new Qgs3DMapCanvasDockWidget( this );
map3DWidget->setObjectName( name + QStringLiteral( "ViewObject" ) );
map3DWidget->setObjectName( name + QStringLiteral( "DockObject" ) );
map3DWidget->setAllowedAreas( Qt::AllDockWidgetAreas );
map3DWidget->setWindowTitle( name );
map3DWidget->mapCanvas3D()->setObjectName( name );
map3DWidget->setMainCanvas( mMapCanvas );
map3DWidget->mapCanvas3D()->setTemporalController( mTemporalControllerWidget->temporalController() );

connect( map3DWidget, &Qgs3DMapCanvasDockWidget::closed, [ = ]()
{
QDomImplementation DomImplementation;
QDomDocumentType documentType =
DomImplementation.createDocumentType(
QStringLiteral( "qgis" ), QStringLiteral( "http://mrcc.com/qgis.dtd" ), QStringLiteral( "SYSTEM" ) );
QDomDocument doc( documentType );

QDomElement elem3DMap;
elem3DMap = doc.createElement( QStringLiteral( "view" ) );
write3DMapViewSettings( map3DWidget, doc, elem3DMap );

QString viewName = map3DWidget->mapCanvas3D()->objectName();
QgsProject::instance()->views3DManager()->viewClosed( viewName, elem3DMap );
} );

return map3DWidget;
#else
Q_UNUSED( name )
@@ -14064,11 +14076,6 @@ void QgisApp::new3DMapCanvas()
QgsProject::instance()->views3DManager()->register3DViewSettings( name, elem3DMap );
QgsProject::instance()->views3DManager()->viewOpened( name );

connect( dock, &Qgs3DMapCanvasDockWidget::closed, [ &, name]()
{
QgsProject::instance()->views3DManager()->viewClosed( name );
} );

mPanelMenu->removeAction( dock->toggleViewAction() );
}
#endif
@@ -16890,11 +16897,6 @@ void QgisApp::readProject( const QDomDocument &doc )
Qgs3DMapCanvasDockWidget *mapCanvasDock3D = createNew3DMapCanvasDock( viewName );
read3DMapViewSettings( mapCanvasDock3D, viewConfig );

connect( mapCanvasDock3D, &Qgs3DMapCanvasDockWidget::closed, [ &, viewName]()
{
QgsProject::instance()->views3DManager()->viewClosed( viewName );
} );

mPanelMenu->removeAction( mapCanvasDock3D->toggleViewAction() );
}
#endif
@@ -2330,8 +2330,18 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

#ifdef HAVE_3D

/**
* Reads 3D view settings from DOM element
* \since QGIS 3.24
* \sa write3DMapViewSettings()
*/
void read3DMapViewSettings( Qgs3DMapCanvasDockWidget *widget, QDomElement &elem3DMap );

/**
* Writes 3D view settings into DOM element
* \since QGIS 3.24
* \sa read3DMapViewSettings()
*/
void write3DMapViewSettings( Qgs3DMapCanvasDockWidget *widget, QDomDocument &doc, QDomElement &elem3DMap );
#endif

@@ -76,6 +76,9 @@ QWidget *QgsAppWindowManager::openApplicationDialog( QgsAppWindowManager::Applic
}
m3DMapViewsManagerDialog->show();
m3DMapViewsManagerDialog->reload();
m3DMapViewsManagerDialog->raise();
m3DMapViewsManagerDialog->setWindowState( m3DMapViewsManagerDialog->windowState() & ~Qt::WindowMinimized );
m3DMapViewsManagerDialog->activateWindow();
return m3DMapViewsManagerDialog;
#endif
}
@@ -96,10 +96,13 @@ void Qgs3DViewsManager::rename3DView( const QString &oldTitle, const QString &ne
emit viewsListChanged();
}

void Qgs3DViewsManager::viewClosed( const QString &name )
void Qgs3DViewsManager::viewClosed( const QString &name, const QDomElement &dom )
{
if ( m3DMapViewsDom.contains( name ) )
{
m3DMapViewsDom[ name ] = dom;
m3DMapViewsDom[ name ].setAttribute( "isOpen", 0 );
}
}

void Qgs3DViewsManager::viewOpened( const QString &name )
@@ -87,7 +87,7 @@ class CORE_EXPORT Qgs3DViewsManager : public QObject
void viewOpened( const QString &name );

//! Sets the configuration of the 3D view named \a name to being closed
void viewClosed( const QString &name );
void viewClosed( const QString &name, const QDomElement &dom );

signals:
//! Emitted when the views list has changed (whenever a 3D view was removed, added, renamed..)

0 comments on commit 33ee137

Please sign in to comment.