Skip to content

Commit

Permalink
[needs-docs][layouts] Move pushbutton actions for map items up to
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nyalldawson committed Dec 18, 2018
1 parent 5acd7ff commit cdd23e6
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 29 deletions.
13 changes: 13 additions & 0 deletions python/gui/auto_generated/layout/qgslayoutdesignerinterface.sip.in
Expand Up @@ -44,6 +44,12 @@ open layout designer dialogs.
%End
public:

enum StandardTool
{
ToolMoveItemContent,
ToolMoveItemNodes,
};

QgsLayoutDesignerInterface( QObject *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsLayoutDesignerInterface.
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion python/gui/auto_generated/layout/qgslayoutitemwidget.sip.in
Expand Up @@ -10,7 +10,6 @@




class QgsLayoutConfigObject: QObject
{
%Docstring
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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() ) )
Expand Down
1 change: 1 addition & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -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:

Expand Down
31 changes: 23 additions & 8 deletions src/app/layout/qgslayoutmapwidget.cpp
Expand Up @@ -30,6 +30,7 @@
#include "qgsstyle.h"
#include "qgslayoutundostack.h"
#include "qgslayoutatlas.h"
#include "qgslayoutdesignerinterface.h"
#include <QMenu>
#include <QMessageBox>

Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -512,7 +527,7 @@ void QgsLayoutMapWidget::rotationChanged( double value )
mMapItem->invalidateCache();
}

void QgsLayoutMapWidget::mSetToMapCanvasExtentButton_clicked()
void QgsLayoutMapWidget::setToMapCanvasExtent()
{
if ( !mMapItem )
{
Expand Down Expand Up @@ -543,7 +558,7 @@ void QgsLayoutMapWidget::mSetToMapCanvasExtentButton_clicked()
mMapItem->layout()->undoStack()->endCommand();
}

void QgsLayoutMapWidget::mViewExtentInCanvasButton_clicked()
void QgsLayoutMapWidget::viewExtentInCanvas()
{
if ( !mMapItem )
{
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -830,7 +845,7 @@ void QgsLayoutMapWidget::handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::B
mMapItem->layout()->undoStack()->endCommand();
}

void QgsLayoutMapWidget::mUpdatePreviewButton_clicked()
void QgsLayoutMapWidget::updatePreview()
{
if ( !mMapItem )
{
Expand Down
10 changes: 7 additions & 3 deletions src/app/layout/qgslayoutmapwidget.h
Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions src/gui/layout/qgslayoutdesignerinterface.h
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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:

/**
Expand Down
5 changes: 5 additions & 0 deletions src/gui/layout/qgslayoutitemwidget.cpp
Expand Up @@ -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 );
Expand Down
10 changes: 9 additions & 1 deletion src/gui/layout/qgslayoutitemwidget.h
Expand Up @@ -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
Expand Down Expand Up @@ -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:

/**
Expand Down

0 comments on commit cdd23e6

Please sign in to comment.