From cdd23e663e4572b59ee201395486dfd44a4ed4f0 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 10 Dec 2018 19:28:41 +1000 Subject: [PATCH] [needs-docs][layouts] Move pushbutton actions for map items up to a toolbar in the map item properties panel This moves the - refresh preview - set to map canvas extent - view extent in map canvas buttons from being oversized push buttons within the item properties panel up to a new toolbar at the top of this panel. Apart from looking better, it means these important actions are always visible regardless of the scroll position of the item properties panel itself. Additionally, it makes it possible to add MORE actions here without overloading the UI (e.g. "set canvas extent to item extent") TODO: better icons --- .../layout/qgslayoutdesignerinterface.sip.in | 13 +++ .../layout/qgslayoutitemwidget.sip.in | 9 +- src/app/layout/qgslayoutdesignerdialog.cpp | 18 ++++ src/app/layout/qgslayoutdesignerdialog.h | 1 + src/app/layout/qgslayoutmapwidget.cpp | 31 +++++-- src/app/layout/qgslayoutmapwidget.h | 10 ++- src/gui/layout/qgslayoutdesignerinterface.h | 14 +++ src/gui/layout/qgslayoutitemwidget.cpp | 5 ++ src/gui/layout/qgslayoutitemwidget.h | 10 ++- src/ui/layout/qgslayoutmapwidgetbase.ui | 89 +++++++++++++++---- 10 files changed, 171 insertions(+), 29 deletions(-) diff --git a/python/gui/auto_generated/layout/qgslayoutdesignerinterface.sip.in b/python/gui/auto_generated/layout/qgslayoutdesignerinterface.sip.in index a8795d2faaf..5fec513e307 100644 --- a/python/gui/auto_generated/layout/qgslayoutdesignerinterface.sip.in +++ b/python/gui/auto_generated/layout/qgslayoutdesignerinterface.sip.in @@ -44,6 +44,12 @@ open layout designer dialogs. %End public: + enum StandardTool + { + ToolMoveItemContent, + ToolMoveItemNodes, + }; + QgsLayoutDesignerInterface( QObject *parent /TransferThis/ = 0 ); %Docstring Constructor for QgsLayoutDesignerInterface. @@ -389,6 +395,13 @@ Removes the specified ``dock`` widget from layout designer (without deleting it) .. versionadded:: 3.4 +%End + + virtual void activateTool( StandardTool tool ) = 0; +%Docstring +Activates a standard layout designer ``tool``. + +.. versionadded:: 3.6 %End public slots: diff --git a/python/gui/auto_generated/layout/qgslayoutitemwidget.sip.in b/python/gui/auto_generated/layout/qgslayoutitemwidget.sip.in index 36f35ef6d49..26f6c068a10 100644 --- a/python/gui/auto_generated/layout/qgslayoutitemwidget.sip.in +++ b/python/gui/auto_generated/layout/qgslayoutitemwidget.sip.in @@ -10,7 +10,6 @@ - class QgsLayoutConfigObject: QObject { %Docstring @@ -99,6 +98,14 @@ Sets the ``string`` to use to describe the current report type (e.g. "atlas" or "report"). Subclasses which display this text to users should override this and update their widget labels accordingly. +%End + + virtual void setDesignerInterface( QgsLayoutDesignerInterface *iface ); +%Docstring +Sets the the layout designer interface in which the widget is +being shown. + +.. versionadded:: 3.6 %End protected: diff --git a/src/app/layout/qgslayoutdesignerdialog.cpp b/src/app/layout/qgslayoutdesignerdialog.cpp index 0faaeb183c3..07865fba1a2 100644 --- a/src/app/layout/qgslayoutdesignerdialog.cpp +++ b/src/app/layout/qgslayoutdesignerdialog.cpp @@ -214,6 +214,23 @@ void QgsAppLayoutDesignerInterface::removeDockWidget( QDockWidget *dock ) mDesigner->removeDockWidget( dock ); } +void QgsAppLayoutDesignerInterface::activateTool( QgsLayoutDesignerInterface::StandardTool tool ) +{ + switch ( tool ) + { + case QgsLayoutDesignerInterface::ToolMoveItemContent: + if ( !mDesigner->mActionMoveItemContent->isChecked() ) + mDesigner->mActionMoveItemContent->trigger(); + break; + + case QgsLayoutDesignerInterface::ToolMoveItemNodes: + if ( !mDesigner->mActionEditNodesItem->isChecked() ) + mDesigner->mActionEditNodesItem->trigger(); + break; + + } +} + void QgsAppLayoutDesignerInterface::close() { mDesigner->close(); @@ -1096,6 +1113,7 @@ void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item, bool bringPa if ( ! widget ) return; + widget->setDesignerInterface( iface() ); widget->setReportTypeString( reportTypeString() ); if ( QgsLayoutPagePropertiesWidget *ppWidget = qobject_cast< QgsLayoutPagePropertiesWidget * >( widget.get() ) ) diff --git a/src/app/layout/qgslayoutdesignerdialog.h b/src/app/layout/qgslayoutdesignerdialog.h index cbdd54fd2a7..b32d7d1e966 100644 --- a/src/app/layout/qgslayoutdesignerdialog.h +++ b/src/app/layout/qgslayoutdesignerdialog.h @@ -77,6 +77,7 @@ class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface QToolBar *atlasToolbar() override; void addDockWidget( Qt::DockWidgetArea area, QDockWidget *dock ) override; void removeDockWidget( QDockWidget *dock ) override; + void activateTool( StandardTool tool ) override; public slots: diff --git a/src/app/layout/qgslayoutmapwidget.cpp b/src/app/layout/qgslayoutmapwidget.cpp index 3d53a896a63..773006cda94 100644 --- a/src/app/layout/qgslayoutmapwidget.cpp +++ b/src/app/layout/qgslayoutmapwidget.cpp @@ -30,6 +30,7 @@ #include "qgsstyle.h" #include "qgslayoutundostack.h" #include "qgslayoutatlas.h" +#include "qgslayoutdesignerinterface.h" #include #include @@ -41,9 +42,9 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item ) setupUi( this ); connect( mScaleLineEdit, &QLineEdit::editingFinished, this, &QgsLayoutMapWidget::mScaleLineEdit_editingFinished ); - connect( mSetToMapCanvasExtentButton, &QPushButton::clicked, this, &QgsLayoutMapWidget::mSetToMapCanvasExtentButton_clicked ); - connect( mViewExtentInCanvasButton, &QPushButton::clicked, this, &QgsLayoutMapWidget::mViewExtentInCanvasButton_clicked ); - connect( mUpdatePreviewButton, &QPushButton::clicked, this, &QgsLayoutMapWidget::mUpdatePreviewButton_clicked ); + connect( mActionSetToCanvasExtent, &QAction::triggered, this, &QgsLayoutMapWidget::setToMapCanvasExtent ); + connect( mActionViewExtentInCanvas, &QAction::triggered, this, &QgsLayoutMapWidget::viewExtentInCanvas ); + connect( mActionUpdatePreview, &QAction::triggered, this, &QgsLayoutMapWidget::updatePreview ); connect( mFollowVisibilityPresetCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged ); connect( mKeepLayerListCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged ); connect( mKeepLayerStylesCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged ); @@ -77,9 +78,12 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item ) connect( mOverviewListWidget, &QListWidget::itemChanged, this, &QgsLayoutMapWidget::mOverviewListWidget_itemChanged ); connect( mLabelSettingsButton, &QPushButton::clicked, this, &QgsLayoutMapWidget::showLabelSettings ); + connect( mActionMoveContent, &QAction::triggered, this, &QgsLayoutMapWidget::switchToMoveContentTool ); setPanelTitle( tr( "Map Properties" ) ); mMapRotationSpinBox->setClearValue( 0 ); + mDockToolbar->setIconSize( QgisApp::instance()->iconSize( true ) ); + //add widget for general composer item properties mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, item ); mainLayout->addWidget( mItemPropertiesWidget ); @@ -163,6 +167,11 @@ void QgsLayoutMapWidget::setReportTypeString( const QString &string ) mAtlasPredefinedScaleRadio->setToolTip( tr( "Use one of the predefined scales of the project where the %1 feature best fits." ).arg( string ) ); } +void QgsLayoutMapWidget::setDesignerInterface( QgsLayoutDesignerInterface *iface ) +{ + mInterface = iface; +} + bool QgsLayoutMapWidget::setNewItem( QgsLayoutItem *item ) { if ( item->type() != QgsLayoutItemRegistry::LayoutMap ) @@ -352,6 +361,12 @@ void QgsLayoutMapWidget::showLabelSettings() openPanel( w ); } +void QgsLayoutMapWidget::switchToMoveContentTool() +{ + if ( mInterface ) + mInterface->activateTool( QgsLayoutDesignerInterface::ToolMoveItemContent ); +} + void QgsLayoutMapWidget::mAtlasCheckBox_toggled( bool checked ) { if ( !mMapItem ) @@ -512,7 +527,7 @@ void QgsLayoutMapWidget::rotationChanged( double value ) mMapItem->invalidateCache(); } -void QgsLayoutMapWidget::mSetToMapCanvasExtentButton_clicked() +void QgsLayoutMapWidget::setToMapCanvasExtent() { if ( !mMapItem ) { @@ -543,7 +558,7 @@ void QgsLayoutMapWidget::mSetToMapCanvasExtentButton_clicked() mMapItem->layout()->undoStack()->endCommand(); } -void QgsLayoutMapWidget::mViewExtentInCanvasButton_clicked() +void QgsLayoutMapWidget::viewExtentInCanvas() { if ( !mMapItem ) { @@ -779,8 +794,8 @@ void QgsLayoutMapWidget::blockAllSignals( bool b ) mFollowVisibilityPresetCombo->blockSignals( b ); mKeepLayerListCheckBox->blockSignals( b ); mKeepLayerStylesCheckBox->blockSignals( b ); - mSetToMapCanvasExtentButton->blockSignals( b ); - mUpdatePreviewButton->blockSignals( b ); + mActionSetToCanvasExtent->blockSignals( b ); + mActionUpdatePreview->blockSignals( b ); blockOverviewItemsSignals( b ); } @@ -830,7 +845,7 @@ void QgsLayoutMapWidget::handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::B mMapItem->layout()->undoStack()->endCommand(); } -void QgsLayoutMapWidget::mUpdatePreviewButton_clicked() +void QgsLayoutMapWidget::updatePreview() { if ( !mMapItem ) { diff --git a/src/app/layout/qgslayoutmapwidget.h b/src/app/layout/qgslayoutmapwidget.h index df9643ff3b9..241e8b75604 100644 --- a/src/app/layout/qgslayoutmapwidget.h +++ b/src/app/layout/qgslayoutmapwidget.h @@ -39,12 +39,13 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM explicit QgsLayoutMapWidget( QgsLayoutItemMap *item ); void setReportTypeString( const QString &string ) override; + void setDesignerInterface( QgsLayoutDesignerInterface *iface ) override; public slots: void mScaleLineEdit_editingFinished(); - void mSetToMapCanvasExtentButton_clicked(); - void mViewExtentInCanvasButton_clicked(); - void mUpdatePreviewButton_clicked(); + void setToMapCanvasExtent(); + void viewExtentInCanvas(); + void updatePreview(); void mFollowVisibilityPresetCheckBox_stateChanged( int state ); void mKeepLayerListCheckBox_stateChanged( int state ); void mKeepLayerStylesCheckBox_stateChanged( int state ); @@ -118,9 +119,12 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM void mapCrsChanged( const QgsCoordinateReferenceSystem &crs ); void overviewSymbolChanged(); void showLabelSettings(); + void switchToMoveContentTool(); + private: QPointer< QgsLayoutItemMap > mMapItem; QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr; + QgsLayoutDesignerInterface *mInterface = nullptr; //! Sets extent of composer map from line edits void updateComposerExtentFromGui(); diff --git a/src/gui/layout/qgslayoutdesignerinterface.h b/src/gui/layout/qgslayoutdesignerinterface.h index d1bc5eab0fc..4168b80b1a6 100644 --- a/src/gui/layout/qgslayoutdesignerinterface.h +++ b/src/gui/layout/qgslayoutdesignerinterface.h @@ -66,6 +66,13 @@ class GUI_EXPORT QgsLayoutDesignerInterface: public QObject public: + //! Standard designer tools which are always available for use + enum StandardTool + { + ToolMoveItemContent, //!< Move item content tool + ToolMoveItemNodes, //!< Move item nodes tool + }; + /** * Constructor for QgsLayoutDesignerInterface. */ @@ -329,6 +336,13 @@ class GUI_EXPORT QgsLayoutDesignerInterface: public QObject */ virtual void removeDockWidget( QDockWidget *dock ) = 0; + /** + * Activates a standard layout designer \a tool. + * + * \since QGIS 3.6 + */ + virtual void activateTool( StandardTool tool ) = 0; + public slots: /** diff --git a/src/gui/layout/qgslayoutitemwidget.cpp b/src/gui/layout/qgslayoutitemwidget.cpp index a55f062434b..d929cd308a3 100644 --- a/src/gui/layout/qgslayoutitemwidget.cpp +++ b/src/gui/layout/qgslayoutitemwidget.cpp @@ -180,6 +180,11 @@ void QgsLayoutItemBaseWidget::setReportTypeString( const QString & ) { } +void QgsLayoutItemBaseWidget::setDesignerInterface( QgsLayoutDesignerInterface * ) +{ + +} + void QgsLayoutItemBaseWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property ) { mConfigObject->initializeDataDefinedButton( button, property ); diff --git a/src/gui/layout/qgslayoutitemwidget.h b/src/gui/layout/qgslayoutitemwidget.h index fbca6bc3974..be1eb14fdfb 100644 --- a/src/gui/layout/qgslayoutitemwidget.h +++ b/src/gui/layout/qgslayoutitemwidget.h @@ -23,7 +23,7 @@ #include #include - +class QgsLayoutDesignerInterface; class QgsPropertyOverrideButton; // NOTE - the inheritance here is tricky, as we need to avoid the multiple inheritance @@ -151,6 +151,14 @@ class GUI_EXPORT QgsLayoutItemBaseWidget: public QgsPanelWidget */ virtual void setReportTypeString( const QString &string ); + /** + * Sets the the layout designer interface in which the widget is + * being shown. + * + * \since QGIS 3.6 + */ + virtual void setDesignerInterface( QgsLayoutDesignerInterface *iface ); + protected: /** diff --git a/src/ui/layout/qgslayoutmapwidgetbase.ui b/src/ui/layout/qgslayoutmapwidgetbase.ui index 3510a655b7c..373cdad45a7 100644 --- a/src/ui/layout/qgslayoutmapwidgetbase.ui +++ b/src/ui/layout/qgslayoutmapwidgetbase.ui @@ -51,6 +51,25 @@ + + + + + 16 + 16 + + + + false + + + + + + + + + @@ -97,7 +116,7 @@ - + @@ -124,14 +143,14 @@ - + Draw map canvas items - + @@ -149,7 +168,7 @@ - + Scale @@ -159,27 +178,20 @@ - + Qt::StrongFocus - + Map rotation - - - - Update Preview - - - @@ -790,6 +802,54 @@ + + + + :/images/themes/default/mActionRefresh.svg:/images/themes/default/mActionRefresh.svg + + + Update Preview + + + Update Map Preview + + + + + + :/images/themes/default/mActionZoomFullExtent.svg:/images/themes/default/mActionZoomFullExtent.svg + + + Set to Map Canvas Extent + + + Set Map Extent to Match Main Canvas Extent + + + + + + :/images/themes/default/mActionZoomToLayer.svg:/images/themes/default/mActionZoomToLayer.svg + + + View Extent in Map Canvas + + + View Current Map Extent in Main Canvas + + + + + + :/images/themes/default/mActionMoveItemContent.svg:/images/themes/default/mActionMoveItemContent.svg + + + Move Map Content + + + Interactively Edit Map Extent + + @@ -845,7 +905,6 @@ scrollArea groupBox - mUpdatePreviewButton mScaleLineEdit mScaleDDBtn mMapRotationSpinBox @@ -868,8 +927,6 @@ mXMaxDDBtn mYMaxLineEdit mYMaxDDBtn - mSetToMapCanvasExtentButton - mViewExtentInCanvasButton mLabelSettingsButton mAtlasCheckBox mAtlasMarginRadio