Skip to content
Permalink
Browse files
Automatically open annotation properties and focus an appropriate
widget after creating a new annotation
  • Loading branch information
nyalldawson committed Sep 8, 2021
1 parent 303cb45 commit 24089aa34a81f7121c7ad459f406c741c8633d64
@@ -61,6 +61,13 @@ Sets the ``context`` in which the widget is shown, e.g., the associated map canv
Returns the context in which the widget is shown, e.g., the associated map canvas and expression contexts.

.. seealso:: :py:func:`setContext`
%End

public slots:

virtual void focusDefaultWidget();
%Docstring
Focuses the default widget for the page.
%End

signals:
@@ -127,6 +127,13 @@ Subclasses should take care to call the base class implementation when overridin
%Docstring
Called when changes to the layer need to be made.
Will be called when live update is enabled.
%End

virtual void focusDefaultWidget();
%Docstring
Focuses the default widget for the page.

.. versionadded:: 3.22
%End

signals:
@@ -98,6 +98,12 @@ void QgsAnnotationItemPropertiesWidget::apply()
mLayer->triggerRepaint();
}

void QgsAnnotationItemPropertiesWidget::focusDefaultWidget()
{
if ( mItemWidget )
mItemWidget->focusDefaultWidget();
}

void QgsAnnotationItemPropertiesWidget::onChanged()
{
if ( !mLayer )
@@ -37,6 +37,7 @@ class QgsAnnotationItemPropertiesWidget : public QgsMapLayerConfigWidget

public slots:
void apply() override;
void focusDefaultWidget() override;

private slots:

@@ -810,14 +810,16 @@ void QgisApp::annotationItemTypeAdded( int id )
connect( tool, &QgsCreateAnnotationItemMapTool::itemCreated, this, [ = ]
{
QgsAnnotationItem *item = tool->takeCreatedItem();
if ( QgsAnnotationLayer *layer = qobject_cast< QgsAnnotationLayer * >( activeLayer() ) )
{
layer->addItem( item );
}
else
{
QgsProject::instance()->mainAnnotationLayer()->addItem( item );
}
QgsAnnotationLayer *targetLayer = qobject_cast< QgsAnnotationLayer * >( activeLayer() );
if ( !targetLayer )
targetLayer = QgsProject::instance()->mainAnnotationLayer();

const QString itemId = targetLayer->addItem( item );
// automatically select item in layer styling panel
mMapStyleWidget->setAnnotationItem( targetLayer, itemId );
mMapStylingDock->setUserVisible( true );
mMapStyleWidget->focusDefaultWidget();

// TODO -- possibly automatically deactive the tool now?
} );
} );
@@ -712,6 +712,14 @@ void QgsLayerStylingWidget::setAnnotationItem( QgsAnnotationLayer *layer, const
}
}

void QgsLayerStylingWidget::focusDefaultWidget()
{
if ( QgsMapLayerConfigWidget *configWidget = qobject_cast< QgsMapLayerConfigWidget * >( mWidgetStack->mainPanel() ) )
{
configWidget->focusDefaultWidget();
}
}

void QgsLayerStylingWidget::layerAboutToBeRemoved( QgsMapLayer *layer )
{
if ( layer == mCurrentLayer )
@@ -135,6 +135,11 @@ class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerSty
*/
void setAnnotationItem( QgsAnnotationLayer *layer, const QString &itemId );

/**
* Focuses the default widget for the current page.
*/
void focusDefaultWidget();

private slots:

void layerAboutToBeRemoved( QgsMapLayer *layer );
@@ -36,6 +36,10 @@ QgsSymbolWidgetContext QgsAnnotationItemBaseWidget::context() const
return mContext;
}

void QgsAnnotationItemBaseWidget::focusDefaultWidget()
{
}

bool QgsAnnotationItemBaseWidget::setNewItem( QgsAnnotationItem * )
{
return false;
@@ -75,6 +75,13 @@ class GUI_EXPORT QgsAnnotationItemBaseWidget: public QgsPanelWidget
*/
QgsSymbolWidgetContext context() const;

public slots:

/**
* Focuses the default widget for the page.
*/
virtual void focusDefaultWidget();

signals:

/**
@@ -360,6 +360,12 @@ void QgsAnnotationPointTextItemWidget::setContext( const QgsSymbolWidgetContext
mPropertiesWidget->setContext( context );
}

void QgsAnnotationPointTextItemWidget::focusDefaultWidget()
{
mTextEdit->selectAll();
mTextEdit->setFocus();
}

QgsAnnotationPointTextItemWidget::~QgsAnnotationPointTextItemWidget() = default;

bool QgsAnnotationPointTextItemWidget::setNewItem( QgsAnnotationItem *item )
@@ -120,6 +120,10 @@ class QgsAnnotationPointTextItemWidget : public QgsAnnotationItemBaseWidget, pri
void setDockMode( bool dockMode ) override;
void setContext( const QgsSymbolWidgetContext &context ) override;

public slots:

void focusDefaultWidget() override;

protected:
bool setNewItem( QgsAnnotationItem *item ) override;

@@ -27,3 +27,7 @@ void QgsMapLayerConfigWidget::setMapLayerConfigWidgetContext( const QgsMapLayerC
{
mMapLayerConfigWidgetContext = context;
}

void QgsMapLayerConfigWidget::focusDefaultWidget()
{
}
@@ -137,6 +137,13 @@ class GUI_EXPORT QgsMapLayerConfigWidget : public QgsPanelWidget
*/
virtual void apply() = 0;

/**
* Focuses the default widget for the page.
*
* \since QGIS 3.22
*/
virtual void focusDefaultWidget();

signals:

#ifndef SIP_RUN

0 comments on commit 24089aa

Please sign in to comment.