Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix dock checkbox and remove unecessary close event
  • Loading branch information
NEDJIMAbelgacem committed Jan 17, 2022
1 parent fccfeff commit 0ada56d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 41 deletions.
3 changes: 0 additions & 3 deletions src/app/3d/qgs3danimationwidget.cpp
Expand Up @@ -62,9 +62,6 @@ Qgs3DAnimationWidget::Qgs3DAnimationWidget( QWidget *parent )
connect( cboKeyframe, qOverload<int>( &QComboBox::currentIndexChanged ), this, &Qgs3DAnimationWidget::onKeyframeChanged );
}

Qgs3DAnimationWidget::~Qgs3DAnimationWidget() = default;


void Qgs3DAnimationWidget::setCameraController( QgsCameraController *cameraController )
{
mCameraController = cameraController;
Expand Down
1 change: 0 additions & 1 deletion src/app/3d/qgs3danimationwidget.h
Expand Up @@ -31,7 +31,6 @@ class Qgs3DAnimationWidget : public QWidget, private Ui::Animation3DWidget
Q_OBJECT
public:
explicit Qgs3DAnimationWidget( QWidget *parent = nullptr );
~Qgs3DAnimationWidget() override;

void setCameraController( QgsCameraController *cameraController );

Expand Down
8 changes: 2 additions & 6 deletions src/app/3d/qgs3dmapcanvaswidget.cpp
Expand Up @@ -138,7 +138,7 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( bool isDocked )
mDockUnDockBtn->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mDockify.svg" ) ) );
mDockUnDockBtn->setToolTip( tr( "Dock 3D Map View" ) );
mDockUnDockBtn->setCheckable( true );
mDockUnDockBtn->setChecked( true );
mDockUnDockBtn->setChecked( isDocked );
mDockUnDockBtn->setEnabled( true );
connect( mDockUnDockBtn, &QToolButton::toggled, this, &Qgs3DMapCanvasWidget::toggleDockModeRequested );

Expand Down Expand Up @@ -232,6 +232,7 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( bool isDocked )
Qgs3DMapCanvasWidget::~Qgs3DMapCanvasWidget()
{
this->setParent( QgisApp::instance() );
mDockableWidget->setWidget( nullptr );
delete mDockableWidget;
}

Expand Down Expand Up @@ -288,11 +289,6 @@ void Qgs3DMapCanvasWidget::measureLine()
mCanvas->setMapTool( action->isChecked() ? mMapToolMeasureLine : nullptr );
}

void Qgs3DMapCanvasWidget::setDocked( bool docked )
{
mDockUnDockBtn->setChecked( docked );
}

void Qgs3DMapCanvasWidget::setWindowTitle( const QString &title )
{
QWidget::setWindowTitle( title );
Expand Down
2 changes: 0 additions & 2 deletions src/app/3d/qgs3dmapcanvaswidget.h
Expand Up @@ -54,8 +54,6 @@ class APP_EXPORT Qgs3DMapCanvasWidget : public QWidget

QgsDockableWidgetHelper *dockableWidget() { return mDockableWidget; }

void setDocked( bool docked );

void setWindowTitle( const QString &title );

signals:
Expand Down
10 changes: 3 additions & 7 deletions src/app/qgisapp.cpp
Expand Up @@ -4799,8 +4799,7 @@ void QgisApp::closeAdditional3DMapCanvases()
QSet<Qgs3DMapCanvasWidget *> openDocks = mOpen3DMapViews;
for ( Qgs3DMapCanvasWidget *w : openDocks )
{
w->dockableWidget()->close();
delete w;
close3DMapView( w->windowTitle() );
}
#endif
}
Expand Down Expand Up @@ -9933,6 +9932,7 @@ void QgisApp::close3DMapView( const QString &viewName )
Qgs3DMapCanvasWidget *widget = get3DMapView( viewName );
if ( !widget )
return;
mOpen3DMapViews.remove( widget );

QDomImplementation DomImplementation;
QDomDocumentType documentType =
Expand All @@ -9949,7 +9949,6 @@ void QgisApp::close3DMapView( const QString &viewName )
QgsProject::instance()->viewsManager()->register3DViewSettings( viewName, elem3DMap );
QgsProject::instance()->viewsManager()->set3DViewInitiallyVisible( viewName, false );
}
mOpen3DMapViews.remove( widget );
delete widget;
#else
Q_UNUSED( viewName );
Expand Down Expand Up @@ -16700,7 +16699,6 @@ void QgisApp::projectChanged( const QDomDocument &doc )
#ifdef HAVE_3D
void QgisApp::write3DMapViewSettings( Qgs3DMapCanvasWidget *widget, QDomDocument &doc, QDomElement &elem3DMap )
{
QgsDockableWidgetHelper *w = widget->dockableWidget();
QgsReadWriteContext readWriteContext;
readWriteContext.setPathResolver( QgsProject::instance()->pathResolver() );
elem3DMap.setAttribute( QStringLiteral( "name" ), widget->mapCanvas3D()->objectName() );
Expand All @@ -16711,6 +16709,7 @@ void QgisApp::write3DMapViewSettings( Qgs3DMapCanvasWidget *widget, QDomDocument
QDomElement elemAnimation = widget->animationWidget()->animation().writeXml( doc );
elem3DMap.appendChild( elemAnimation );

QgsDockableWidgetHelper *w = widget->dockableWidget();
elem3DMap.setAttribute( QStringLiteral( "isDocked" ), w->isDocked() );

QRect dockGeom = w->dockGeometry();
Expand Down Expand Up @@ -16790,9 +16789,6 @@ void QgisApp::read3DMapViewSettings( Qgs3DMapCanvasWidget *widget, QDomElement &

widget->dockableWidget()->setDockGeometry( QRect( x, y, w, h ), floating, area );
}

bool isDocked = elem3DMap.attribute( QStringLiteral( "isDocked" ), "1" ).toInt() == 1;
widget->setDocked( isDocked );
}
#endif

Expand Down
34 changes: 15 additions & 19 deletions src/app/qgsdockablewidgethelper.cpp
Expand Up @@ -28,8 +28,6 @@ QgsDockableWidgetHelper::QgsDockableWidgetHelper( bool isDocked, QWidget *widget
, mIsDockFloating( true )
, mDockArea( Qt::RightDockWidgetArea )
{
mWidget->setParent( this );

toggleDockMode( isDocked );
}

Expand Down Expand Up @@ -59,6 +57,11 @@ QgsDockableWidgetHelper::~QgsDockableWidgetHelper()

void QgsDockableWidgetHelper::setWidget( QWidget *widget )
{
// Make sure the old mWidget is not stuck as a child of mDialog or mDock
if ( mWidget )
{
mWidget->setParent( QgisApp::instance() );
}
if ( mDialog )
{
mDialog->layout()->removeWidget( mWidget );
Expand All @@ -79,8 +82,13 @@ bool QgsDockableWidgetHelper::isDocked() const

void QgsDockableWidgetHelper::toggleDockMode( bool docked )
{
mWidget->setParent( this );
// Make sure the old mWidget is not stuck as a child of mDialog or mDock
if ( mWidget )
{
mWidget->setParent( QgisApp::instance() );
}

// Remove both the dialog and the dock widget first
if ( mDock )
{
mDockGeometry = mDock->geometry();
Expand All @@ -104,6 +112,10 @@ void QgsDockableWidgetHelper::toggleDockMode( bool docked )

mIsDocked = docked;

// If there is no widget set, do not create a dock or a dialog
if ( mWidget == nullptr )
return;

if ( docked )
{
// going from window -> dock
Expand Down Expand Up @@ -201,22 +213,6 @@ Qt::DockWidgetArea QgsDockableWidgetHelper::dockFloatingArea() const
return mDockArea;
}

void QgsDockableWidgetHelper::closeEvent( QCloseEvent *e )
{
if ( mDialog )
{
mDialog->layout()->removeWidget( mWidget );
}
if ( mDock )
{
mDock->setWidget( nullptr );
}
mWidget->setParent( this );

emit closed();
QWidget::closeEvent( e );
}

void QgsDockableWidgetHelper::setupDockWidget()
{
if ( !mDock )
Expand Down
3 changes: 0 additions & 3 deletions src/app/qgsdockablewidgethelper.h
Expand Up @@ -53,9 +53,6 @@ class APP_EXPORT QgsDockableWidgetHelper : public QWidget
bool isDockFloating() const;
Qt::DockWidgetArea dockFloatingArea() const;

protected:
void closeEvent( QCloseEvent * ) override;

signals:
void closed();

Expand Down

0 comments on commit 0ada56d

Please sign in to comment.