[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
This commit is contained in:
Nyall Dawson 2018-12-10 19:28:41 +10:00
parent 5acd7ffaef
commit cdd23e663e
10 changed files with 171 additions and 29 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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() ) )

View File

@ -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:

View File

@ -30,6 +30,7 @@
#include "qgsstyle.h"
#include "qgslayoutundostack.h"
#include "qgslayoutatlas.h"
#include "qgslayoutdesignerinterface.h"
#include <QMenu>
#include <QMessageBox>
@ -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 )
{

View File

@ -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();

View File

@ -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:
/**

View File

@ -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 );

View File

@ -23,7 +23,7 @@
#include <QObject>
#include <QPointer>
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:
/**

View File

@ -51,6 +51,25 @@
</property>
</widget>
</item>
<item>
<widget class="QToolBar" name="mDockToolbar">
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="floatable">
<bool>false</bool>
</property>
<addaction name="mActionUpdatePreview"/>
<addaction name="separator"/>
<addaction name="mActionSetToCanvasExtent"/>
<addaction name="mActionViewExtentInCanvas"/>
<addaction name="separator"/>
<addaction name="mActionMoveContent"/>
</widget>
</item>
<item>
<widget class="QgsScrollArea" name="scrollArea">
<property name="frameShape">
@ -97,7 +116,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QgsDoubleSpinBox" name="mMapRotationSpinBox">
@ -124,14 +143,14 @@
</item>
</layout>
</item>
<item row="5" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="mDrawCanvasItemsCheckBox">
<property name="text">
<string>Draw map canvas items</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLineEdit" name="mScaleLineEdit">
@ -149,7 +168,7 @@
</item>
</layout>
</item>
<item row="1" column="0">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Scale</string>
@ -159,27 +178,20 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="2" column="1">
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QLabel" name="mMapRotationLabel">
<property name="text">
<string>Map rotation</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QPushButton" name="mUpdatePreviewButton">
<property name="text">
<string>Update Preview</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -790,6 +802,54 @@
</widget>
</item>
</layout>
<action name="mActionUpdatePreview">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionRefresh.svg</normaloff>:/images/themes/default/mActionRefresh.svg</iconset>
</property>
<property name="text">
<string>Update Preview</string>
</property>
<property name="toolTip">
<string>Update Map Preview</string>
</property>
</action>
<action name="mActionSetToCanvasExtent">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionZoomFullExtent.svg</normaloff>:/images/themes/default/mActionZoomFullExtent.svg</iconset>
</property>
<property name="text">
<string>Set to Map Canvas Extent</string>
</property>
<property name="toolTip">
<string>Set Map Extent to Match Main Canvas Extent</string>
</property>
</action>
<action name="mActionViewExtentInCanvas">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionZoomToLayer.svg</normaloff>:/images/themes/default/mActionZoomToLayer.svg</iconset>
</property>
<property name="text">
<string>View Extent in Map Canvas</string>
</property>
<property name="toolTip">
<string>View Current Map Extent in Main Canvas</string>
</property>
</action>
<action name="mActionMoveContent">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionMoveItemContent.svg</normaloff>:/images/themes/default/mActionMoveItemContent.svg</iconset>
</property>
<property name="text">
<string>Move Map Content</string>
</property>
<property name="toolTip">
<string>Interactively Edit Map Extent</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
@ -845,7 +905,6 @@
<tabstops>
<tabstop>scrollArea</tabstop>
<tabstop>groupBox</tabstop>
<tabstop>mUpdatePreviewButton</tabstop>
<tabstop>mScaleLineEdit</tabstop>
<tabstop>mScaleDDBtn</tabstop>
<tabstop>mMapRotationSpinBox</tabstop>
@ -868,8 +927,6 @@
<tabstop>mXMaxDDBtn</tabstop>
<tabstop>mYMaxLineEdit</tabstop>
<tabstop>mYMaxDDBtn</tabstop>
<tabstop>mSetToMapCanvasExtentButton</tabstop>
<tabstop>mViewExtentInCanvasButton</tabstop>
<tabstop>mLabelSettingsButton</tabstop>
<tabstop>mAtlasCheckBox</tabstop>
<tabstop>mAtlasMarginRadio</tabstop>