Skip to content
Permalink
Browse files
cleanup qgs3dmapviewsmanager
  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 12, 2022
1 parent f49a268 commit 0fe8905d73d7270ab5dc34c163e425e9d252cb56
Showing with 102 additions and 95 deletions.
  1. +78 −80 src/app/3d/qgs3dviewsmanager.cpp
  2. +5 −2 src/app/3d/qgs3dviewsmanager.h
  3. +15 −10 src/app/qgisapp.cpp
  4. +3 −2 src/app/qgisapp.h
  5. +1 −1 src/ui/3d/qgs3dviewsmanager.ui
@@ -14,98 +14,96 @@ Qgs3DViewsManager::Qgs3DViewsManager( QWidget *parent, Qt::WindowFlags f )
m3DViewsListView->setEditTriggers( QAbstractItemView::NoEditTriggers );
m3DViewsListView->setSelectionMode( QAbstractItemView::SingleSelection );

connect( m3DViewsListView, &QListView::clicked, [&]( const QModelIndex & index )
{
mSelectedViewIndex = index.row();
} );
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( mShowButton, &QToolButton::clicked, [&]()
{
if ( mSelectedViewIndex == -1 )
return;
QString viewName = mListModel.stringList()[ mSelectedViewIndex ];
Qgs3DMapCanvasDockWidget *widget = m3DMapViewsWidgets->value( viewName, nullptr );
if ( !widget )
{
widget = QgisApp::instance()->open3DMapView( viewName );
}
if ( widget )
{
widget->show();
widget->activateWindow();
widget->raise();
}
} );

connect( mRenameButton, &QToolButton::clicked, [&]()
{
if ( mSelectedViewIndex == -1 )
return;
QString oldTitle = mListModel.stringList()[ mSelectedViewIndex ];

QString newTitle;
QgsNewNameDialog dlg( QStringLiteral( "3D view" ), newTitle, QStringList(), m3DMapViewsDom->keys(), Qt::CaseSensitive, this );
dlg.setWindowTitle( "Title" );
dlg.setHintString( "" );
dlg.setOverwriteEnabled( false );
dlg.setAllowEmptyName( false );
dlg.setConflictingNameWarning( tr( "Title already exists!" ) );

if ( dlg.exec() != QDialog::Accepted )
return;
newTitle = dlg.name();

QDomElement dom = m3DMapViewsDom->value( oldTitle );
m3DMapViewsDom->remove( oldTitle );
m3DMapViewsDom->insert( newTitle, dom );
Qgs3DMapCanvasDockWidget *widget = m3DMapViewsWidgets->value( oldTitle, nullptr );
if ( widget )
{
m3DMapViewsWidgets->remove( oldTitle );
m3DMapViewsWidgets->insert( newTitle, widget );
widget->setName( newTitle );
}
reloadListModel();
} );

connect( mDuplicateButton, &QToolButton::clicked, [&]()
void Qgs3DViewsManager::openClicked()
{
if ( m3DViewsListView->selectionModel()->selectedRows().isEmpty() )
return;

QString viewName = mListModel.stringList()[ m3DViewsListView->selectionModel()->selectedRows().at( 0 ).row() ];
Qgs3DMapCanvasDockWidget *widget = m3DMapViewsWidgets->value( viewName, nullptr );
if ( !widget )
{
if ( mSelectedViewIndex == -1 )
return;

QString viewName = mListModel.stringList()[ mSelectedViewIndex ] + "_";

Qgs3DMapCanvasDockWidget *widget = QgisApp::instance()->duplicate3DMapView( mListModel.stringList()[ mSelectedViewIndex ] );
if ( widget )
{
widget->show();
widget->activateWindow();
widget->raise();
}
reloadListModel();
} );

connect( mRemoveButton, &QToolButton::clicked, [&]()
widget = QgisApp::instance()->open3DMapView( viewName );
}
if ( widget )
{
if ( mSelectedViewIndex == -1 )
return;
QString viewName = mListModel.stringList()[ mSelectedViewIndex ];
m3DMapViewsDom->remove( viewName );
Qgs3DMapCanvasDockWidget *w = ( *m3DMapViewsWidgets )[ viewName ];
m3DMapViewsWidgets->remove( viewName );
w->close();
reloadListModel();
} );
widget->show();
widget->activateWindow();
widget->raise();
}
}

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

QString existingViewName = mListModel.stringList()[ m3DViewsListView->selectionModel()->selectedRows().at( 0 ).row() ];
QString newViewName = existingViewName + "_";

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

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

QString viewName = mListModel.stringList()[ m3DViewsListView->selectionModel()->selectedRows().at( 0 ).row() ];
m3DMapViewsDom->remove( viewName );
Qgs3DMapCanvasDockWidget *w = ( *m3DMapViewsWidgets )[ viewName ];
m3DMapViewsWidgets->remove( viewName );
w->close();
reloadListModel();
}

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

QString oldTitle = mListModel.stringList()[ m3DViewsListView->selectionModel()->selectedRows().at( 0 ).row() ];
QString newTitle = oldTitle;

QStringList notAllowedTitles = m3DMapViewsDom->keys();
notAllowedTitles.removeOne( oldTitle );
QgsNewNameDialog dlg( QStringLiteral( "3D view" ), newTitle, QStringList(), notAllowedTitles, Qt::CaseSensitive, this );
dlg.setWindowTitle( QStringLiteral( "Rename 3D Map View" ) );
dlg.setHintString( QStringLiteral( "Enter a unique 3D map view title" ) );
dlg.setOverwriteEnabled( false );
dlg.setAllowEmptyName( false );
dlg.setConflictingNameWarning( tr( "Title already exists!" ) );

if ( dlg.exec() != QDialog::Accepted )
return;
newTitle = dlg.name();

QDomElement dom = m3DMapViewsDom->value( oldTitle );
Qgs3DMapCanvasDockWidget *widget = m3DMapViewsWidgets->value( oldTitle, nullptr );

m3DMapViewsDom->remove( oldTitle );
m3DMapViewsDom->insert( newTitle, dom );
if ( widget )
{
m3DMapViewsWidgets->remove( oldTitle );
m3DMapViewsWidgets->insert( newTitle, widget );
widget->setName( newTitle );
}
reloadListModel();
}

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

reloadListModel();
}

@@ -15,15 +15,18 @@ class Qgs3DViewsManager : public QDialog, private Ui::Qgs3DViewsManager

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

void reload();

void set3DMapViewsDom( QMap<QString, QDomElement> &mapViews3DDom );
void set3DMapViewsWidgets( QMap<QString, Qgs3DMapCanvasDockWidget *> &mapViews3DWidgets );
private slots:
void openClicked();
void duplicateClicked();
void removeClicked();
void renameClicked();
private:
QStringListModel mListModel;
int mSelectedViewIndex = -1;

QMap<QString, QDomElement> *m3DMapViewsDom = nullptr;
QMap<QString, Qgs3DMapCanvasDockWidget *> *m3DMapViewsWidgets = nullptr;
@@ -9916,23 +9916,22 @@ Qgs3DMapCanvasDockWidget *QgisApp::open3DMapView( const QString &mapName )
return nullptr;
}

Qgs3DMapCanvasDockWidget *QgisApp::duplicate3DMapView( const QString &mapName )
Qgs3DMapCanvasDockWidget *QgisApp::duplicate3DMapView( const QString &existingViewName, const QString &newViewName )
{
#ifdef HAVE_3D
QString mapName2 = mapName + "_";
QgsReadWriteContext readWriteContext;
readWriteContext.setPathResolver( QgsProject::instance()->pathResolver() );

Qgs3DMapCanvasDockWidget *mapCanvasDock3D = createInitialized3DMapCanvasDock( mapName2 );
Qgs3DMapCanvasDockWidget *mapCanvasDock3D = createInitialized3DMapCanvasDock( newViewName );
if ( !mapCanvasDock3D )
return nullptr;

m3DMapViewsWidgets[ mapName2 ] = mapCanvasDock3D;
m3DMapViewsWidgets[ newViewName ] = mapCanvasDock3D;

// If the 3D view is open, copy its configuration to the duplicate widget, otherwise just use the recorded
// settings from m3DMapViewsWidgets
QDomElement elem3DMap;
if ( m3DMapViewsWidgets.contains( mapName ) )
if ( m3DMapViewsWidgets.contains( existingViewName ) )
{
QDomImplementation DomImplementation;
QDomDocumentType documentType =
@@ -9941,14 +9940,14 @@ Qgs3DMapCanvasDockWidget *QgisApp::duplicate3DMapView( const QString &mapName )
QDomDocument doc( documentType );
elem3DMap = doc.createElement( QStringLiteral( "view" ) );

write3DMapViewSettings( m3DMapViewsWidgets[ mapName ], doc, elem3DMap );
write3DMapViewSettings( m3DMapViewsWidgets[ existingViewName ], doc, elem3DMap );
}
else
{
elem3DMap = m3DMapViewsDom[ mapName ];
elem3DMap = m3DMapViewsDom[ existingViewName ];
}

m3DMapViewsDom[ mapName2 ] = elem3DMap;
m3DMapViewsDom[ newViewName ] = elem3DMap;
read3DMapViewSettings( mapCanvasDock3D, elem3DMap );

return mapCanvasDock3D;
@@ -13932,7 +13931,7 @@ void QgisApp::new3DMapCanvas()
}
}

Qgs3DMapCanvasDockWidget *dock = createInitialized3DMapCanvasDock( name );
createInitialized3DMapCanvasDock( name );
QWidget *dialog = static_cast< QgsAppWindowManager * >( QgsGui::windowManager() )->openApplicationDialog( QgsAppWindowManager::Dialog3DMapViewsManager );
Qgs3DViewsManager *manager = dynamic_cast< Qgs3DViewsManager *>( dialog );
manager->reload();
@@ -16748,7 +16747,10 @@ void QgisApp::writeProject( QDomDocument &doc )
m3DMapViewsDom[ w->mapCanvas3D()->objectName() ] = elem3DMap;
}
for ( QString viewName : m3DMapViewsDom.keys() )
{
QDomElement dom = m3DMapViewsDom[viewName];
elem3DMaps.appendChild( m3DMapViewsDom[viewName] );
}
qgisNode.appendChild( elem3DMaps );
#endif
projectChanged( doc );
@@ -16873,11 +16875,14 @@ void QgisApp::readProject( const QDomDocument &doc )
{
Qgs3DMapCanvasDockWidget *mapCanvasDock3D = createNew3DMapCanvasDock( mapName );
read3DMapViewSettings( mapCanvasDock3D, elem3DMap );
readDockWidgetSettings( mapCanvasDock3D, elem3DMap );
}

elem3DMap = elem3DMap.nextSiblingElement( QStringLiteral( "view" ) );
}
for ( QString viewName : m3DMapViewsDom.keys() )
{
readDockWidgetSettings( m3DMapViewsWidgets[ viewName ], m3DMapViewsDom[ viewName ] );
}
}
#endif

@@ -434,9 +434,10 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
Qgs3DMapCanvasDockWidget *open3DMapView( const QString &name );

/**
* Opens a second 3D view canvas for a 3D map view called \a name with the same configuration.
* Duplicates the 3D map view named \a existingViewName and adds it to the current project.
* The new 3D map view will be named \a newViewName
*/
Qgs3DMapCanvasDockWidget *duplicate3DMapView( const QString &name );
Qgs3DMapCanvasDockWidget *duplicate3DMapView( const QString &existingViewName, const QString &newViewName );

/**
* Duplicates a \a layout and adds it to the current project.
@@ -38,7 +38,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QToolButton" name="mShowButton">
<widget class="QToolButton" name="mOpenButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>

0 comments on commit 0fe8905

Please sign in to comment.