Skip to content
Permalink
Browse files
Show a 'no item selected' label in layer styling dock when no
annotation item is selected
  • Loading branch information
nyalldawson committed Sep 7, 2021
1 parent d16254e commit 590b7f265d177a4bed5e047a5e8fea4a794f3895
@@ -24,12 +24,28 @@
#include "qgsannotationitemguiregistry.h"
#include <QStackedWidget>
#include <QHBoxLayout>
#include <QLabel>

QgsAnnotationItemPropertiesWidget::QgsAnnotationItemPropertiesWidget( QgsAnnotationLayer *layer, QgsMapCanvas *canvas, QWidget *parent )
: QgsMapLayerConfigWidget( layer, canvas, parent )
{
mStack = new QStackedWidget();

mPageNoItem = new QWidget();
QSizePolicy sizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
sizePolicy.setHeightForWidth( mPageNoItem->sizePolicy().hasHeightForWidth() );
mPageNoItem->setSizePolicy( sizePolicy );
QVBoxLayout *verticalLayout = new QVBoxLayout();
verticalLayout->setContentsMargins( 0, 0, 0, 0 );
QLabel *label = new QLabel();
label->setText( tr( "No item selected." ) );
verticalLayout->addWidget( label );
mPageNoItem->setLayout( verticalLayout );
mStack->addWidget( mPageNoItem );
mStack->setCurrentWidget( mPageNoItem );

setDockMode( true );

QHBoxLayout *l = new QHBoxLayout();
@@ -92,7 +108,8 @@ void QgsAnnotationItemPropertiesWidget::setItemId( const QString &itemId )

// try to retrieve matching item
bool setItem = false;
if ( QgsAnnotationItem *item = mLayer->item( itemId ) )
QgsAnnotationItem *item = !itemId.isEmpty() ? mLayer->item( itemId ) : nullptr;
if ( item )
{
if ( mItemWidget )
{
@@ -109,10 +126,14 @@ void QgsAnnotationItemPropertiesWidget::setItemId( const QString &itemId )
setItem = true;

QWidget *prevWidget = mStack->currentWidget();
mStack->removeWidget( prevWidget );
delete prevWidget;
if ( prevWidget != mPageNoItem )
{
mStack->removeWidget( prevWidget );
delete prevWidget;
}

mStack->addWidget( mItemWidget );
mStack->setCurrentWidget( mItemWidget );
connect( mItemWidget, &QgsAnnotationItemBaseWidget::itemChanged, this, &QgsAnnotationItemPropertiesWidget::onChanged );
mItemWidget->setDockMode( dockMode() );
connect( mItemWidget, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );
@@ -122,7 +143,14 @@ void QgsAnnotationItemPropertiesWidget::setItemId( const QString &itemId )

if ( !setItem )
{
// show a "no item" widget
// show the "no item" widget
QWidget *prevWidget = mStack->currentWidget();
if ( prevWidget != mPageNoItem )
{
mStack->removeWidget( prevWidget );
delete prevWidget;
}
mStack->setCurrentWidget( mPageNoItem );
}
}

@@ -47,7 +47,8 @@ class QgsAnnotationItemPropertiesWidget : public QgsMapLayerConfigWidget

QStackedWidget *mStack = nullptr;
QPointer< QgsAnnotationLayer > mLayer;
QgsAnnotationItemBaseWidget *mItemWidget = nullptr;
QPointer< QgsAnnotationItemBaseWidget > mItemWidget;
QWidget *mPageNoItem = nullptr;

};

@@ -1667,6 +1667,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

connect( qobject_cast< QgsMapToolModifyAnnotation * >( mMapTools->mapTool( QgsAppMapTools::AnnotationEdit ) ), &QgsMapToolModifyAnnotation::itemSelected,
mMapStyleWidget, &QgsLayerStylingWidget::setAnnotationItem );
connect( qobject_cast< QgsMapToolModifyAnnotation * >( mMapTools->mapTool( QgsAppMapTools::AnnotationEdit ) ), &QgsMapToolModifyAnnotation::selectionCleared,
mMapStyleWidget, [this] { mMapStyleWidget->setAnnotationItem( nullptr, QString() ); } );

// request notification of FileOpen events (double clicking a file icon in Mac OS X Finder)
// should come after fileNewBlank to ensure project is properly set up to receive any data source files
@@ -703,7 +703,8 @@ void QgsLayerStylingWidget::setCurrentPage( QgsLayerStylingWidget::Page page )
void QgsLayerStylingWidget::setAnnotationItem( QgsAnnotationLayer *layer, const QString &itemId )
{
mContext.setAnnotationId( itemId );
setLayer( layer );
if ( layer )
setLayer( layer );

if ( QgsMapLayerConfigWidget *configWidget = qobject_cast< QgsMapLayerConfigWidget * >( mWidgetStack->mainPanel() ) )
{

0 comments on commit 590b7f2

Please sign in to comment.