Skip to content

Commit

Permalink
address martin reviews Round2
Browse files Browse the repository at this point in the history
  • Loading branch information
NEDJIMAbelgacem committed Jan 18, 2022
1 parent fce2c45 commit 0a0a773
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 113 deletions.
11 changes: 5 additions & 6 deletions src/app/3d/qgs3dmapcanvaswidget.cpp
Expand Up @@ -216,18 +216,17 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( const QString &name, bool isDocked )

onTotalPendingJobsCountChanged();

mDockableWidget = new QgsDockableWidgetHelper( isDocked, mCanvasName, this, QgisApp::instance() );
toolBar->addWidget( mDockableWidget->toggleButton() );
connect( mDockableWidget, &QgsDockableWidgetHelper::closed, [ = ]()
mDockableWidgetHelper = new QgsDockableWidgetHelper( isDocked, mCanvasName, this, QgisApp::instance() );
toolBar->addWidget( mDockableWidgetHelper->createDockUndockToolButton() );
connect( mDockableWidgetHelper, &QgsDockableWidgetHelper::closed, [ = ]()
{
QgisApp::instance()->close3DMapView( canvasName() );
} );
}

Qgs3DMapCanvasWidget::~Qgs3DMapCanvasWidget()
{
mDockableWidget->setWidget( nullptr );
delete mDockableWidget;
delete mDockableWidgetHelper;
}

void Qgs3DMapCanvasWidget::saveAsImage()
Expand Down Expand Up @@ -286,7 +285,7 @@ void Qgs3DMapCanvasWidget::measureLine()
void Qgs3DMapCanvasWidget::setCanvasName( const QString &name )
{
mCanvasName = name;
mDockableWidget->setWindowTitle( name );
mDockableWidgetHelper->setWindowTitle( name );
}

void Qgs3DMapCanvasWidget::toggleNavigationWidget( bool visibility )
Expand Down
4 changes: 2 additions & 2 deletions src/app/3d/qgs3dmapcanvaswidget.h
Expand Up @@ -52,7 +52,7 @@ class APP_EXPORT Qgs3DMapCanvasWidget : public QWidget

Qgs3DMapToolMeasureLine *measurementLineTool() { return mMapToolMeasureLine; }

QgsDockableWidgetHelper *dockableWidgetHelper() { return mDockableWidget; }
QgsDockableWidgetHelper *dockableWidgetHelper() { return mDockableWidgetHelper; }

void setCanvasName( const QString &name );
QString canvasName() const { return mCanvasName; }
Expand Down Expand Up @@ -100,7 +100,7 @@ class APP_EXPORT Qgs3DMapCanvasWidget : public QWidget
QAction *mActionEnableShadows = nullptr;
QAction *mActionEnableEyeDome = nullptr;
QToolButton *mBtnOptions = nullptr;
QgsDockableWidgetHelper *mDockableWidget = nullptr;
QgsDockableWidgetHelper *mDockableWidgetHelper = nullptr;
};

#endif // QGS3DMAPCANVASWIDGET_H
36 changes: 2 additions & 34 deletions src/app/qgisapp.cpp
Expand Up @@ -16706,22 +16706,7 @@ void QgisApp::write3DMapViewSettings( Qgs3DMapCanvasWidget *widget, QDomDocument
QDomElement elemAnimation = widget->animationWidget()->animation().writeXml( doc );
elem3DMap.appendChild( elemAnimation );

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

QRect dockGeom = w->dockGeometry();
elem3DMap.setAttribute( QStringLiteral( "x" ), dockGeom.x() );
elem3DMap.setAttribute( QStringLiteral( "y" ), dockGeom.y() );
elem3DMap.setAttribute( QStringLiteral( "width" ), dockGeom.width() );
elem3DMap.setAttribute( QStringLiteral( "height" ), dockGeom.height() );
elem3DMap.setAttribute( QStringLiteral( "floating" ), w->isDockFloating() );
elem3DMap.setAttribute( QStringLiteral( "area" ), w->dockFloatingArea() );

QRect dialogGeom = w->dialogGeometry();
elem3DMap.setAttribute( QStringLiteral( "d_x" ), dialogGeom.x() );
elem3DMap.setAttribute( QStringLiteral( "d_y" ), dialogGeom.y() );
elem3DMap.setAttribute( QStringLiteral( "d_width" ), dialogGeom.width() );
elem3DMap.setAttribute( QStringLiteral( "d_height" ), dialogGeom.height() );
widget->dockableWidgetHelper()->writeXml( elem3DMap );
}

void QgisApp::read3DMapViewSettings( Qgs3DMapCanvasWidget *widget, QDomElement &elem3DMap )
Expand Down Expand Up @@ -16768,24 +16753,7 @@ void QgisApp::read3DMapViewSettings( Qgs3DMapCanvasWidget *widget, QDomElement &
widget->animationWidget()->setAnimation( animationSettings );
}

{
int dx = elem3DMap.attribute( QStringLiteral( "d_x" ), "0" ).toInt();
int dy = elem3DMap.attribute( QStringLiteral( "d_x" ), "0" ).toInt();
int dw = elem3DMap.attribute( QStringLiteral( "d_width" ), "200" ).toInt();
int dh = elem3DMap.attribute( QStringLiteral( "d_height" ), "200" ).toInt();
widget->dockableWidgetHelper()->setDialogGeometry( QRect( dx, dy, dw, dh ) );
}

{
int x = elem3DMap.attribute( QStringLiteral( "x" ), QStringLiteral( "0" ) ).toInt();
int y = elem3DMap.attribute( QStringLiteral( "y" ), QStringLiteral( "0" ) ).toInt();
int w = elem3DMap.attribute( QStringLiteral( "width" ), QStringLiteral( "200" ) ).toInt();
int h = elem3DMap.attribute( QStringLiteral( "height" ), QStringLiteral( "200" ) ).toInt();
bool floating = elem3DMap.attribute( QStringLiteral( "floating" ), QStringLiteral( "0" ) ).toInt();
Qt::DockWidgetArea area = static_cast< Qt::DockWidgetArea >( elem3DMap.attribute( QStringLiteral( "area" ), QString::number( Qt::RightDockWidgetArea ) ).toInt() );

widget->dockableWidgetHelper()->setDockGeometry( QRect( x, y, w, h ), floating, area );
}
widget->dockableWidgetHelper()->readXml( elem3DMap );
}
#endif

Expand Down
111 changes: 52 additions & 59 deletions src/app/qgsdockablewidgethelper.cpp
Expand Up @@ -31,17 +31,11 @@ QgsDockableWidgetHelper::QgsDockableWidgetHelper( bool isDocked, const QString &
, mOwnerWindow( ownerWindow )
{
toggleDockMode( isDocked );
mToggleButton.setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mDockify.svg" ) ) );
mToggleButton.setToolTip( tr( "Dock 3D Map View" ) );
mToggleButton.setCheckable( true );
mToggleButton.setChecked( isDocked );
mToggleButton.setEnabled( true );

connect( &mToggleButton, &QToolButton::toggled, this, &QgsDockableWidgetHelper::toggleDockMode );
}

QgsDockableWidgetHelper::~QgsDockableWidgetHelper()
{
setWidget( nullptr );
if ( mDock )
{
mDockGeometry = mDock->geometry();
Expand All @@ -64,6 +58,47 @@ QgsDockableWidgetHelper::~QgsDockableWidgetHelper()
}
}

void QgsDockableWidgetHelper::writeXml( QDomElement &viewDom )
{
viewDom.setAttribute( QStringLiteral( "isDocked" ), mIsDocked );

viewDom.setAttribute( QStringLiteral( "x" ), mDockGeometry.x() );
viewDom.setAttribute( QStringLiteral( "y" ), mDockGeometry.y() );
viewDom.setAttribute( QStringLiteral( "width" ), mDockGeometry.width() );
viewDom.setAttribute( QStringLiteral( "height" ), mDockGeometry.height() );
viewDom.setAttribute( QStringLiteral( "floating" ), mIsDockFloating );
viewDom.setAttribute( QStringLiteral( "area" ), mDockArea );

viewDom.setAttribute( QStringLiteral( "d_x" ), mDialogGeometry.x() );
viewDom.setAttribute( QStringLiteral( "d_y" ), mDialogGeometry.y() );
viewDom.setAttribute( QStringLiteral( "d_width" ), mDialogGeometry.width() );
viewDom.setAttribute( QStringLiteral( "d_height" ), mDialogGeometry.height() );
}

void QgsDockableWidgetHelper::readXml( QDomElement &viewDom )
{
{
int x = viewDom.attribute( QStringLiteral( "d_x" ), "0" ).toInt();
int y = viewDom.attribute( QStringLiteral( "d_x" ), "0" ).toInt();
int w = viewDom.attribute( QStringLiteral( "d_width" ), "200" ).toInt();
int h = viewDom.attribute( QStringLiteral( "d_height" ), "200" ).toInt();
mDialogGeometry = QRect( x, y, w, h );
if ( mDialog )
mDialog->setGeometry( mDialogGeometry );
}

{
int x = viewDom.attribute( QStringLiteral( "x" ), QStringLiteral( "0" ) ).toInt();
int y = viewDom.attribute( QStringLiteral( "y" ), QStringLiteral( "0" ) ).toInt();
int w = viewDom.attribute( QStringLiteral( "width" ), QStringLiteral( "200" ) ).toInt();
int h = viewDom.attribute( QStringLiteral( "height" ), QStringLiteral( "200" ) ).toInt();
mDockGeometry = QRect( x, y, w, h );
mIsDockFloating = viewDom.attribute( QStringLiteral( "floating" ), QStringLiteral( "0" ) ).toInt();
mDockArea = static_cast< Qt::DockWidgetArea >( viewDom.attribute( QStringLiteral( "area" ), QString::number( Qt::RightDockWidgetArea ) ).toInt() );
setupDockWidget();
}
}

void QgsDockableWidgetHelper::setWidget( QWidget *widget )
{
// Make sure the old mWidget is not stuck as a child of mDialog or mDock
Expand All @@ -84,11 +119,6 @@ void QgsDockableWidgetHelper::setWidget( QWidget *widget )
toggleDockMode( mIsDocked );
}

bool QgsDockableWidgetHelper::isDocked() const
{
return mIsDocked;
}

void QgsDockableWidgetHelper::toggleDockMode( bool docked )
{
// Make sure the old mWidget is not stuck as a child of mDialog or mDock
Expand Down Expand Up @@ -177,51 +207,6 @@ void QgsDockableWidgetHelper::setWindowTitle( const QString &title )
}
}

void QgsDockableWidgetHelper::setDialogGeometry( const QRect &geom )
{
mDialogGeometry = geom;
if ( !mDialog )
return;
mDialog->setGeometry( geom );
}

void QgsDockableWidgetHelper::setDockGeometry( const QRect &geom, bool isFloating, Qt::DockWidgetArea area )
{
mDockGeometry = geom;
mIsDockFloating = isFloating;
mDockArea = area;

setupDockWidget();
}

QRect QgsDockableWidgetHelper::dialogGeometry() const
{
if ( mDialog )
return mDialog->geometry();
return mDialogGeometry;
}

QRect QgsDockableWidgetHelper::dockGeometry() const
{
if ( mDock )
return mDock->geometry();
return mDockGeometry;
}

bool QgsDockableWidgetHelper::isDockFloating() const
{
if ( mDock )
return mDock->isFloating();
return mIsDockFloating;
}

Qt::DockWidgetArea QgsDockableWidgetHelper::dockFloatingArea() const
{
if ( mDock )
return mOwnerWindow->dockWidgetArea( mDock );
return mDockArea;
}

void QgsDockableWidgetHelper::setupDockWidget()
{
if ( !mDock )
Expand Down Expand Up @@ -252,7 +237,15 @@ void QgsDockableWidgetHelper::setupDockWidget()
}
}

QToolButton *QgsDockableWidgetHelper::toggleButton()
QToolButton *QgsDockableWidgetHelper::createDockUndockToolButton()
{
return &mToggleButton;
QToolButton *toggleButton = new QToolButton;
toggleButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mDockify.svg" ) ) );
toggleButton->setToolTip( tr( "Dock 3D Map View" ) );
toggleButton->setCheckable( true );
toggleButton->setChecked( mIsDocked );
toggleButton->setEnabled( true );

connect( toggleButton, &QToolButton::toggled, this, &QgsDockableWidgetHelper::toggleDockMode );
return toggleButton;
}
21 changes: 9 additions & 12 deletions src/app/qgsdockablewidgethelper.h
Expand Up @@ -21,6 +21,7 @@
#include <QDialog>
#include <QToolButton>
#include <QMainWindow>
#include <QDomElement>

#define SIP_NO_FILE

Expand All @@ -40,6 +41,9 @@ class APP_EXPORT QgsDockableWidgetHelper : public QObject
QgsDockableWidgetHelper( bool isDocked, const QString &windowTitle, QWidget *widget, QMainWindow *ownerWindow );
~QgsDockableWidgetHelper();

void writeXml( QDomElement &viewDom );
void readXml( QDomElement &viewDom );

void setWidget( QWidget *widget );

QWidget *widget() { return mWidget; }
Expand All @@ -48,20 +52,14 @@ class APP_EXPORT QgsDockableWidgetHelper : public QObject

QDialog *dialog() { return mDialog; }

bool isDocked() const;

void setWindowTitle( const QString &title );
QString windowTitle() const { return mWindowTitle; }

void setDialogGeometry( const QRect &geom );
void setDockGeometry( const QRect &geom, bool isFloating, Qt::DockWidgetArea area );

QRect dialogGeometry() const;
QRect dockGeometry() const;
bool isDockFloating() const;
Qt::DockWidgetArea dockFloatingArea() const;

QToolButton *toggleButton();
/**
* Create a tool button for docking/undocking the widget
* \note The ownership of the tool button is managed by the caller
*/
QToolButton *createDockUndockToolButton();

signals:
void closed();
Expand All @@ -84,7 +82,6 @@ class APP_EXPORT QgsDockableWidgetHelper : public QObject
Qt::DockWidgetArea mDockArea;

QString mWindowTitle;
QToolButton mToggleButton;
QMainWindow *mOwnerWindow;
};

Expand Down

0 comments on commit 0a0a773

Please sign in to comment.