Skip to content

Commit cdd23e6

Browse files
committedDec 18, 2018
[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
1 parent 5acd7ff commit cdd23e6

10 files changed

+171
-29
lines changed
 

‎python/gui/auto_generated/layout/qgslayoutdesignerinterface.sip.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ open layout designer dialogs.
4444
%End
4545
public:
4646

47+
enum StandardTool
48+
{
49+
ToolMoveItemContent,
50+
ToolMoveItemNodes,
51+
};
52+
4753
QgsLayoutDesignerInterface( QObject *parent /TransferThis/ = 0 );
4854
%Docstring
4955
Constructor for QgsLayoutDesignerInterface.
@@ -389,6 +395,13 @@ Removes the specified ``dock`` widget from layout designer (without deleting it)
389395

390396

391397
.. versionadded:: 3.4
398+
%End
399+
400+
virtual void activateTool( StandardTool tool ) = 0;
401+
%Docstring
402+
Activates a standard layout designer ``tool``.
403+
404+
.. versionadded:: 3.6
392405
%End
393406

394407
public slots:

‎python/gui/auto_generated/layout/qgslayoutitemwidget.sip.in

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212

13-
1413
class QgsLayoutConfigObject: QObject
1514
{
1615
%Docstring
@@ -99,6 +98,14 @@ Sets the ``string`` to use to describe the current report type (e.g.
9998
"atlas" or "report").
10099
Subclasses which display this text to users should override this
101100
and update their widget labels accordingly.
101+
%End
102+
103+
virtual void setDesignerInterface( QgsLayoutDesignerInterface *iface );
104+
%Docstring
105+
Sets the the layout designer interface in which the widget is
106+
being shown.
107+
108+
.. versionadded:: 3.6
102109
%End
103110

104111
protected:

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ void QgsAppLayoutDesignerInterface::removeDockWidget( QDockWidget *dock )
214214
mDesigner->removeDockWidget( dock );
215215
}
216216

217+
void QgsAppLayoutDesignerInterface::activateTool( QgsLayoutDesignerInterface::StandardTool tool )
218+
{
219+
switch ( tool )
220+
{
221+
case QgsLayoutDesignerInterface::ToolMoveItemContent:
222+
if ( !mDesigner->mActionMoveItemContent->isChecked() )
223+
mDesigner->mActionMoveItemContent->trigger();
224+
break;
225+
226+
case QgsLayoutDesignerInterface::ToolMoveItemNodes:
227+
if ( !mDesigner->mActionEditNodesItem->isChecked() )
228+
mDesigner->mActionEditNodesItem->trigger();
229+
break;
230+
231+
}
232+
}
233+
217234
void QgsAppLayoutDesignerInterface::close()
218235
{
219236
mDesigner->close();
@@ -1096,6 +1113,7 @@ void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item, bool bringPa
10961113
if ( ! widget )
10971114
return;
10981115

1116+
widget->setDesignerInterface( iface() );
10991117
widget->setReportTypeString( reportTypeString() );
11001118

11011119
if ( QgsLayoutPagePropertiesWidget *ppWidget = qobject_cast< QgsLayoutPagePropertiesWidget * >( widget.get() ) )

‎src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
7777
QToolBar *atlasToolbar() override;
7878
void addDockWidget( Qt::DockWidgetArea area, QDockWidget *dock ) override;
7979
void removeDockWidget( QDockWidget *dock ) override;
80+
void activateTool( StandardTool tool ) override;
8081

8182
public slots:
8283

‎src/app/layout/qgslayoutmapwidget.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "qgsstyle.h"
3131
#include "qgslayoutundostack.h"
3232
#include "qgslayoutatlas.h"
33+
#include "qgslayoutdesignerinterface.h"
3334
#include <QMenu>
3435
#include <QMessageBox>
3536

@@ -41,9 +42,9 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
4142

4243
setupUi( this );
4344
connect( mScaleLineEdit, &QLineEdit::editingFinished, this, &QgsLayoutMapWidget::mScaleLineEdit_editingFinished );
44-
connect( mSetToMapCanvasExtentButton, &QPushButton::clicked, this, &QgsLayoutMapWidget::mSetToMapCanvasExtentButton_clicked );
45-
connect( mViewExtentInCanvasButton, &QPushButton::clicked, this, &QgsLayoutMapWidget::mViewExtentInCanvasButton_clicked );
46-
connect( mUpdatePreviewButton, &QPushButton::clicked, this, &QgsLayoutMapWidget::mUpdatePreviewButton_clicked );
45+
connect( mActionSetToCanvasExtent, &QAction::triggered, this, &QgsLayoutMapWidget::setToMapCanvasExtent );
46+
connect( mActionViewExtentInCanvas, &QAction::triggered, this, &QgsLayoutMapWidget::viewExtentInCanvas );
47+
connect( mActionUpdatePreview, &QAction::triggered, this, &QgsLayoutMapWidget::updatePreview );
4748
connect( mFollowVisibilityPresetCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMapWidget::mFollowVisibilityPresetCheckBox_stateChanged );
4849
connect( mKeepLayerListCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMapWidget::mKeepLayerListCheckBox_stateChanged );
4950
connect( mKeepLayerStylesCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMapWidget::mKeepLayerStylesCheckBox_stateChanged );
@@ -77,9 +78,12 @@ QgsLayoutMapWidget::QgsLayoutMapWidget( QgsLayoutItemMap *item )
7778
connect( mOverviewListWidget, &QListWidget::itemChanged, this, &QgsLayoutMapWidget::mOverviewListWidget_itemChanged );
7879
connect( mLabelSettingsButton, &QPushButton::clicked, this, &QgsLayoutMapWidget::showLabelSettings );
7980

81+
connect( mActionMoveContent, &QAction::triggered, this, &QgsLayoutMapWidget::switchToMoveContentTool );
8082
setPanelTitle( tr( "Map Properties" ) );
8183
mMapRotationSpinBox->setClearValue( 0 );
8284

85+
mDockToolbar->setIconSize( QgisApp::instance()->iconSize( true ) );
86+
8387
//add widget for general composer item properties
8488
mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, item );
8589
mainLayout->addWidget( mItemPropertiesWidget );
@@ -163,6 +167,11 @@ void QgsLayoutMapWidget::setReportTypeString( const QString &string )
163167
mAtlasPredefinedScaleRadio->setToolTip( tr( "Use one of the predefined scales of the project where the %1 feature best fits." ).arg( string ) );
164168
}
165169

170+
void QgsLayoutMapWidget::setDesignerInterface( QgsLayoutDesignerInterface *iface )
171+
{
172+
mInterface = iface;
173+
}
174+
166175
bool QgsLayoutMapWidget::setNewItem( QgsLayoutItem *item )
167176
{
168177
if ( item->type() != QgsLayoutItemRegistry::LayoutMap )
@@ -352,6 +361,12 @@ void QgsLayoutMapWidget::showLabelSettings()
352361
openPanel( w );
353362
}
354363

364+
void QgsLayoutMapWidget::switchToMoveContentTool()
365+
{
366+
if ( mInterface )
367+
mInterface->activateTool( QgsLayoutDesignerInterface::ToolMoveItemContent );
368+
}
369+
355370
void QgsLayoutMapWidget::mAtlasCheckBox_toggled( bool checked )
356371
{
357372
if ( !mMapItem )
@@ -512,7 +527,7 @@ void QgsLayoutMapWidget::rotationChanged( double value )
512527
mMapItem->invalidateCache();
513528
}
514529

515-
void QgsLayoutMapWidget::mSetToMapCanvasExtentButton_clicked()
530+
void QgsLayoutMapWidget::setToMapCanvasExtent()
516531
{
517532
if ( !mMapItem )
518533
{
@@ -543,7 +558,7 @@ void QgsLayoutMapWidget::mSetToMapCanvasExtentButton_clicked()
543558
mMapItem->layout()->undoStack()->endCommand();
544559
}
545560

546-
void QgsLayoutMapWidget::mViewExtentInCanvasButton_clicked()
561+
void QgsLayoutMapWidget::viewExtentInCanvas()
547562
{
548563
if ( !mMapItem )
549564
{
@@ -779,8 +794,8 @@ void QgsLayoutMapWidget::blockAllSignals( bool b )
779794
mFollowVisibilityPresetCombo->blockSignals( b );
780795
mKeepLayerListCheckBox->blockSignals( b );
781796
mKeepLayerStylesCheckBox->blockSignals( b );
782-
mSetToMapCanvasExtentButton->blockSignals( b );
783-
mUpdatePreviewButton->blockSignals( b );
797+
mActionSetToCanvasExtent->blockSignals( b );
798+
mActionUpdatePreview->blockSignals( b );
784799

785800
blockOverviewItemsSignals( b );
786801
}
@@ -830,7 +845,7 @@ void QgsLayoutMapWidget::handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::B
830845
mMapItem->layout()->undoStack()->endCommand();
831846
}
832847

833-
void QgsLayoutMapWidget::mUpdatePreviewButton_clicked()
848+
void QgsLayoutMapWidget::updatePreview()
834849
{
835850
if ( !mMapItem )
836851
{

‎src/app/layout/qgslayoutmapwidget.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM
3939
explicit QgsLayoutMapWidget( QgsLayoutItemMap *item );
4040

4141
void setReportTypeString( const QString &string ) override;
42+
void setDesignerInterface( QgsLayoutDesignerInterface *iface ) override;
4243

4344
public slots:
4445
void mScaleLineEdit_editingFinished();
45-
void mSetToMapCanvasExtentButton_clicked();
46-
void mViewExtentInCanvasButton_clicked();
47-
void mUpdatePreviewButton_clicked();
46+
void setToMapCanvasExtent();
47+
void viewExtentInCanvas();
48+
void updatePreview();
4849
void mFollowVisibilityPresetCheckBox_stateChanged( int state );
4950
void mKeepLayerListCheckBox_stateChanged( int state );
5051
void mKeepLayerStylesCheckBox_stateChanged( int state );
@@ -118,9 +119,12 @@ class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutM
118119
void mapCrsChanged( const QgsCoordinateReferenceSystem &crs );
119120
void overviewSymbolChanged();
120121
void showLabelSettings();
122+
void switchToMoveContentTool();
123+
121124
private:
122125
QPointer< QgsLayoutItemMap > mMapItem;
123126
QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr;
127+
QgsLayoutDesignerInterface *mInterface = nullptr;
124128

125129
//! Sets extent of composer map from line edits
126130
void updateComposerExtentFromGui();

‎src/gui/layout/qgslayoutdesignerinterface.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class GUI_EXPORT QgsLayoutDesignerInterface: public QObject
6666

6767
public:
6868

69+
//! Standard designer tools which are always available for use
70+
enum StandardTool
71+
{
72+
ToolMoveItemContent, //!< Move item content tool
73+
ToolMoveItemNodes, //!< Move item nodes tool
74+
};
75+
6976
/**
7077
* Constructor for QgsLayoutDesignerInterface.
7178
*/
@@ -329,6 +336,13 @@ class GUI_EXPORT QgsLayoutDesignerInterface: public QObject
329336
*/
330337
virtual void removeDockWidget( QDockWidget *dock ) = 0;
331338

339+
/**
340+
* Activates a standard layout designer \a tool.
341+
*
342+
* \since QGIS 3.6
343+
*/
344+
virtual void activateTool( StandardTool tool ) = 0;
345+
332346
public slots:
333347

334348
/**

‎src/gui/layout/qgslayoutitemwidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ void QgsLayoutItemBaseWidget::setReportTypeString( const QString & )
180180
{
181181
}
182182

183+
void QgsLayoutItemBaseWidget::setDesignerInterface( QgsLayoutDesignerInterface * )
184+
{
185+
186+
}
187+
183188
void QgsLayoutItemBaseWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property )
184189
{
185190
mConfigObject->initializeDataDefinedButton( button, property );

‎src/gui/layout/qgslayoutitemwidget.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <QObject>
2424
#include <QPointer>
2525

26-
26+
class QgsLayoutDesignerInterface;
2727
class QgsPropertyOverrideButton;
2828

2929
// NOTE - the inheritance here is tricky, as we need to avoid the multiple inheritance
@@ -151,6 +151,14 @@ class GUI_EXPORT QgsLayoutItemBaseWidget: public QgsPanelWidget
151151
*/
152152
virtual void setReportTypeString( const QString &string );
153153

154+
/**
155+
* Sets the the layout designer interface in which the widget is
156+
* being shown.
157+
*
158+
* \since QGIS 3.6
159+
*/
160+
virtual void setDesignerInterface( QgsLayoutDesignerInterface *iface );
161+
154162
protected:
155163

156164
/**

‎src/ui/layout/qgslayoutmapwidgetbase.ui

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@
5151
</property>
5252
</widget>
5353
</item>
54+
<item>
55+
<widget class="QToolBar" name="mDockToolbar">
56+
<property name="iconSize">
57+
<size>
58+
<width>16</width>
59+
<height>16</height>
60+
</size>
61+
</property>
62+
<property name="floatable">
63+
<bool>false</bool>
64+
</property>
65+
<addaction name="mActionUpdatePreview"/>
66+
<addaction name="separator"/>
67+
<addaction name="mActionSetToCanvasExtent"/>
68+
<addaction name="mActionViewExtentInCanvas"/>
69+
<addaction name="separator"/>
70+
<addaction name="mActionMoveContent"/>
71+
</widget>
72+
</item>
5473
<item>
5574
<widget class="QgsScrollArea" name="scrollArea">
5675
<property name="frameShape">
@@ -97,7 +116,7 @@
97116
</property>
98117
</widget>
99118
</item>
100-
<item row="2" column="1">
119+
<item row="1" column="1">
101120
<layout class="QHBoxLayout" name="horizontalLayout_7">
102121
<item>
103122
<widget class="QgsDoubleSpinBox" name="mMapRotationSpinBox">
@@ -124,14 +143,14 @@
124143
</item>
125144
</layout>
126145
</item>
127-
<item row="5" column="0" colspan="2">
146+
<item row="4" column="0" colspan="2">
128147
<widget class="QCheckBox" name="mDrawCanvasItemsCheckBox">
129148
<property name="text">
130149
<string>Draw map canvas items</string>
131150
</property>
132151
</widget>
133152
</item>
134-
<item row="1" column="1">
153+
<item row="0" column="1">
135154
<layout class="QHBoxLayout" name="horizontalLayout_6">
136155
<item>
137156
<widget class="QLineEdit" name="mScaleLineEdit">
@@ -149,7 +168,7 @@
149168
</item>
150169
</layout>
151170
</item>
152-
<item row="1" column="0">
171+
<item row="0" column="0">
153172
<widget class="QLabel" name="label_2">
154173
<property name="text">
155174
<string>Scale</string>
@@ -159,27 +178,20 @@
159178
</property>
160179
</widget>
161180
</item>
162-
<item row="3" column="1">
181+
<item row="2" column="1">
163182
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
164183
<property name="focusPolicy">
165184
<enum>Qt::StrongFocus</enum>
166185
</property>
167186
</widget>
168187
</item>
169-
<item row="2" column="0">
188+
<item row="1" column="0">
170189
<widget class="QLabel" name="mMapRotationLabel">
171190
<property name="text">
172191
<string>Map rotation</string>
173192
</property>
174193
</widget>
175194
</item>
176-
<item row="0" column="0" colspan="2">
177-
<widget class="QPushButton" name="mUpdatePreviewButton">
178-
<property name="text">
179-
<string>Update Preview</string>
180-
</property>
181-
</widget>
182-
</item>
183195
</layout>
184196
</widget>
185197
</item>
@@ -790,6 +802,54 @@
790802
</widget>
791803
</item>
792804
</layout>
805+
<action name="mActionUpdatePreview">
806+
<property name="icon">
807+
<iconset resource="../../../images/images.qrc">
808+
<normaloff>:/images/themes/default/mActionRefresh.svg</normaloff>:/images/themes/default/mActionRefresh.svg</iconset>
809+
</property>
810+
<property name="text">
811+
<string>Update Preview</string>
812+
</property>
813+
<property name="toolTip">
814+
<string>Update Map Preview</string>
815+
</property>
816+
</action>
817+
<action name="mActionSetToCanvasExtent">
818+
<property name="icon">
819+
<iconset resource="../../../images/images.qrc">
820+
<normaloff>:/images/themes/default/mActionZoomFullExtent.svg</normaloff>:/images/themes/default/mActionZoomFullExtent.svg</iconset>
821+
</property>
822+
<property name="text">
823+
<string>Set to Map Canvas Extent</string>
824+
</property>
825+
<property name="toolTip">
826+
<string>Set Map Extent to Match Main Canvas Extent</string>
827+
</property>
828+
</action>
829+
<action name="mActionViewExtentInCanvas">
830+
<property name="icon">
831+
<iconset resource="../../../images/images.qrc">
832+
<normaloff>:/images/themes/default/mActionZoomToLayer.svg</normaloff>:/images/themes/default/mActionZoomToLayer.svg</iconset>
833+
</property>
834+
<property name="text">
835+
<string>View Extent in Map Canvas</string>
836+
</property>
837+
<property name="toolTip">
838+
<string>View Current Map Extent in Main Canvas</string>
839+
</property>
840+
</action>
841+
<action name="mActionMoveContent">
842+
<property name="icon">
843+
<iconset resource="../../../images/images.qrc">
844+
<normaloff>:/images/themes/default/mActionMoveItemContent.svg</normaloff>:/images/themes/default/mActionMoveItemContent.svg</iconset>
845+
</property>
846+
<property name="text">
847+
<string>Move Map Content</string>
848+
</property>
849+
<property name="toolTip">
850+
<string>Interactively Edit Map Extent</string>
851+
</property>
852+
</action>
793853
</widget>
794854
<layoutdefault spacing="6" margin="11"/>
795855
<customwidgets>
@@ -845,7 +905,6 @@
845905
<tabstops>
846906
<tabstop>scrollArea</tabstop>
847907
<tabstop>groupBox</tabstop>
848-
<tabstop>mUpdatePreviewButton</tabstop>
849908
<tabstop>mScaleLineEdit</tabstop>
850909
<tabstop>mScaleDDBtn</tabstop>
851910
<tabstop>mMapRotationSpinBox</tabstop>
@@ -868,8 +927,6 @@
868927
<tabstop>mXMaxDDBtn</tabstop>
869928
<tabstop>mYMaxLineEdit</tabstop>
870929
<tabstop>mYMaxDDBtn</tabstop>
871-
<tabstop>mSetToMapCanvasExtentButton</tabstop>
872-
<tabstop>mViewExtentInCanvasButton</tabstop>
873930
<tabstop>mLabelSettingsButton</tabstop>
874931
<tabstop>mAtlasCheckBox</tabstop>
875932
<tabstop>mAtlasMarginRadio</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.