Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When the modify annotation tool is used to select an annotation item,
show a panel in the layer styling dock allowing users to modify the appearance of the annotation
- Loading branch information
1 parent
38b8b82
commit 4871520
Showing
12 changed files
with
274 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
src/app/annotations/qgsannotationitempropertieswidget.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/*************************************************************************** | ||
qgsannotationitempropertieswidget.cpp | ||
--------------------- | ||
begin : December 2020 | ||
copyright : (C) 2020 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsannotationitempropertieswidget.h" | ||
#include "qgsstyle.h" | ||
#include "qgsapplication.h" | ||
#include "qgsmaplayer.h" | ||
#include "qgsannotationlayer.h" | ||
#include "qgsannotationitemwidget.h" | ||
#include "qgsannotationitem.h" | ||
#include "qgsgui.h" | ||
#include "qgsannotationitemguiregistry.h" | ||
#include <QStackedWidget> | ||
#include <QHBoxLayout> | ||
|
||
QgsAnnotationItemPropertiesWidget::QgsAnnotationItemPropertiesWidget( QgsAnnotationLayer *layer, QgsMapCanvas *canvas, QWidget *parent ) | ||
: QgsMapLayerConfigWidget( layer, canvas, parent ) | ||
{ | ||
mStack = new QStackedWidget(); | ||
|
||
setDockMode( true ); | ||
|
||
QHBoxLayout *l = new QHBoxLayout(); | ||
l->setContentsMargins( 0, 0, 0, 0 ); | ||
l->addWidget( mStack ); | ||
setLayout( l ); | ||
|
||
syncToLayer( layer ); | ||
} | ||
|
||
void QgsAnnotationItemPropertiesWidget::syncToLayer( QgsMapLayer *layer ) | ||
{ | ||
if ( layer == mLayer ) | ||
return; | ||
|
||
mLayer = qobject_cast< QgsAnnotationLayer * >( layer ); | ||
if ( !mLayer ) | ||
return; | ||
|
||
// check context | ||
setItemId( mContext.annotationId() ); | ||
} | ||
|
||
void QgsAnnotationItemPropertiesWidget::setContext( const QgsMapLayerConfigWidgetContext &context ) | ||
{ | ||
QgsMapLayerConfigWidget::setContext( context ); | ||
setItemId( context.annotationId() ); | ||
} | ||
|
||
void QgsAnnotationItemPropertiesWidget::setDockMode( bool dockMode ) | ||
{ | ||
QgsMapLayerConfigWidget::setDockMode( dockMode ); | ||
if ( mItemWidget ) | ||
mItemWidget->setDockMode( dockMode ); | ||
} | ||
|
||
void QgsAnnotationItemPropertiesWidget::apply() | ||
{ | ||
if ( !mLayer ) | ||
return; | ||
|
||
mLayer->triggerRepaint(); | ||
} | ||
|
||
void QgsAnnotationItemPropertiesWidget::onChanged() | ||
{ | ||
// set the annotation layer's item's properties to match the widget | ||
std::unique_ptr< QgsAnnotationItem > newItem( mItemWidget->createItem() ); | ||
|
||
mLayer->replaceItem( mContext.annotationId(), newItem.release() ); | ||
} | ||
|
||
void QgsAnnotationItemPropertiesWidget::setItemId( const QString &itemId ) | ||
{ | ||
// try to retrieve matching item | ||
bool setItem = false; | ||
if ( QgsAnnotationItem *item = mLayer->item( itemId ) ) | ||
{ | ||
if ( mItemWidget ) | ||
{ | ||
setItem = mItemWidget->setItem( item ); | ||
} | ||
|
||
if ( !setItem ) | ||
{ | ||
// create new item | ||
mItemWidget = QgsGui::annotationItemGuiRegistry()->createItemWidget( item ); | ||
|
||
if ( mItemWidget ) | ||
{ | ||
setItem = true; | ||
|
||
QWidget *prevWidget = mStack->currentWidget(); | ||
mStack->removeWidget( prevWidget ); | ||
delete prevWidget; | ||
|
||
mStack->addWidget( mItemWidget ); | ||
connect( mItemWidget, &QgsAnnotationItemBaseWidget::itemChanged, this, &QgsAnnotationItemPropertiesWidget::onChanged ); | ||
mItemWidget->setDockMode( dockMode() ); | ||
connect( mItemWidget, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel ); | ||
} | ||
} | ||
} | ||
|
||
if ( !setItem ) | ||
{ | ||
// show a "no item" widget | ||
} | ||
} | ||
|
||
// | ||
// QgsAnnotationItemPropertiesWidgetFactory | ||
// | ||
|
||
QgsAnnotationItemPropertiesWidgetFactory::QgsAnnotationItemPropertiesWidgetFactory( QObject *parent ) | ||
: QObject( parent ) | ||
{ | ||
setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/symbology.svg" ) ) ); | ||
setTitle( tr( "Annotation" ) ); | ||
} | ||
|
||
QgsMapLayerConfigWidget *QgsAnnotationItemPropertiesWidgetFactory::createWidget( QgsMapLayer *layer, QgsMapCanvas *canvas, bool, QWidget *parent ) const | ||
{ | ||
return new QgsAnnotationItemPropertiesWidget( qobject_cast< QgsAnnotationLayer * >( layer ), canvas, parent ); | ||
} | ||
|
||
bool QgsAnnotationItemPropertiesWidgetFactory::supportLayerPropertiesDialog() const | ||
{ | ||
return false; | ||
} | ||
|
||
bool QgsAnnotationItemPropertiesWidgetFactory::supportsStyleDock() const | ||
{ | ||
return true; | ||
} | ||
|
||
bool QgsAnnotationItemPropertiesWidgetFactory::supportsLayer( QgsMapLayer *layer ) const | ||
{ | ||
return layer->type() == QgsMapLayerType::AnnotationLayer; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*************************************************************************** | ||
qgsannotationitempropertieswidget.h | ||
--------------------- | ||
begin : September 2021 | ||
copyright : (C) 2021 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSANNOTATIONITEMPROPERTIESWIDGET_H | ||
#define QGSANNOTATIONITEMPROPERTIESWIDGET_H | ||
|
||
#include "qgsmaplayerconfigwidget.h" | ||
#include "qgsmaplayerconfigwidgetfactory.h" | ||
|
||
class QgsAnnotationLayer; | ||
class QgsAnnotationItemBaseWidget; | ||
class QStackedWidget; | ||
|
||
class QgsAnnotationItemPropertiesWidget : public QgsMapLayerConfigWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
|
||
QgsAnnotationItemPropertiesWidget( QgsAnnotationLayer *layer, QgsMapCanvas *canvas, QWidget *parent ); | ||
|
||
void syncToLayer( QgsMapLayer *layer ) override; | ||
void setContext( const QgsMapLayerConfigWidgetContext &context ) override; | ||
void setDockMode( bool dockMode ) override; | ||
|
||
public slots: | ||
void apply() override; | ||
|
||
private slots: | ||
|
||
void onChanged(); | ||
private: | ||
|
||
void setItemId( const QString &itemId ); | ||
|
||
QStackedWidget *mStack = nullptr; | ||
QgsAnnotationLayer *mLayer = nullptr; | ||
QgsAnnotationItemBaseWidget *mItemWidget = nullptr; | ||
|
||
}; | ||
|
||
|
||
class QgsAnnotationItemPropertiesWidgetFactory : public QObject, public QgsMapLayerConfigWidgetFactory | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit QgsAnnotationItemPropertiesWidgetFactory( QObject *parent = nullptr ); | ||
|
||
QgsMapLayerConfigWidget *createWidget( QgsMapLayer *layer, QgsMapCanvas *canvas, bool dockWidget, QWidget *parent ) const override; | ||
bool supportLayerPropertiesDialog() const override; | ||
bool supportsStyleDock() const override; | ||
bool supportsLayer( QgsMapLayer *layer ) const override; | ||
}; | ||
|
||
|
||
|
||
#endif // QGSANNOTATIONITEMPROPERTIESWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters