Skip to content

Commit

Permalink
Show a 'no item selected' label in layer styling dock when no
Browse files Browse the repository at this point in the history
annotation item is selected
  • Loading branch information
nyalldawson committed Sep 7, 2021
1 parent d16254e commit 590b7f2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
36 changes: 32 additions & 4 deletions src/app/annotations/qgsannotationitempropertieswidget.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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 );
Expand All @@ -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 );
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/annotations/qgsannotationitempropertieswidget.h
Expand Up @@ -47,7 +47,8 @@ class QgsAnnotationItemPropertiesWidget : public QgsMapLayerConfigWidget

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

};

Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgslayerstylingwidget.cpp
Expand Up @@ -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() ) )
{
Expand Down

0 comments on commit 590b7f2

Please sign in to comment.