Skip to content
Permalink
Browse files
Add QgsAnnotationItemCommonPropertiesWidget widget for controlling
common properties of annotation items (e.g. reference scale, z order)

And include this in the point text item configuration widget
  • Loading branch information
nyalldawson committed Sep 7, 2021
1 parent d602f77 commit adcd793b89c6fac8c4eca6ecfaf11f601ae9bf45
@@ -0,0 +1,56 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/annotations/qgsannotationitemcommonpropertieswidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsAnnotationItemCommonPropertiesWidget: QWidget
{
%Docstring(signature="appended")

A widget for configuring common properties for :py:class:`QgsAnnotationItems`

.. versionadded:: 3.22
%End

%TypeHeaderCode
#include "qgsannotationitemcommonpropertieswidget.h"
%End
public:

QgsAnnotationItemCommonPropertiesWidget( QWidget *parent /TransferThis/ );
%Docstring
Constructor for QgsAnnotationItemCommonPropertiesWidget.
%End

void setItem( QgsAnnotationItem *item );
%Docstring
Sets the ``item`` whose properties should be shown in the widget.
%End

void updateItem( QgsAnnotationItem *item );
%Docstring
Updates an ``item``, setting the properties defined in the widget.
%End

signals:

void itemChanged();
%Docstring
Emitted when the annotation item definition in the widget is changed by the user.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/annotations/qgsannotationitemcommonpropertieswidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -26,7 +26,7 @@ All annotation item widgets should inherit from this base class.

QgsAnnotationItemBaseWidget( QWidget *parent /TransferThis/ );
%Docstring
Constructor for QgsAnnotationItemBaseWidget, linked with the specified annotation ``item``.
Constructor for QgsAnnotationItemBaseWidget.
%End

virtual QgsAnnotationItem *createItem() = 0 /Factory/;
@@ -224,6 +224,7 @@
%Include auto_generated/qgsvertexmarker.sip
%Include auto_generated/qgsvscrollarea.sip
%Include auto_generated/qgswindowmanagerinterface.sip
%Include auto_generated/annotations/qgsannotationitemcommonpropertieswidget.sip
%Include auto_generated/annotations/qgsannotationitemguiregistry.sip
%Include auto_generated/annotations/qgsannotationitemwidget.sip
%Include auto_generated/annotations/qgsmaptoolmodifyannotation.sip
@@ -94,6 +94,7 @@ set(QGIS_GUI_SRCS
attributetable/qgsorganizetablecolumnsdialog.cpp
attributetable/qgsfeaturefilterwidget.cpp

annotations/qgsannotationitemcommonpropertieswidget.cpp
annotations/qgsannotationitemguiregistry.cpp
annotations/qgsannotationitemwidget.cpp
annotations/qgsannotationitemwidget_impl.cpp
@@ -883,6 +884,7 @@ set(QGIS_GUI_HDRS
qgsvscrollarea.h
qgswindowmanagerinterface.h

annotations/qgsannotationitemcommonpropertieswidget.h
annotations/qgsannotationitemguiregistry.h
annotations/qgsannotationitemwidget.h
annotations/qgsmaptoolmodifyannotation.h
@@ -0,0 +1,55 @@
/***************************************************************************
qgsannotationitemcommonpropertieswidget.cpp
------------------------
Date : September 2021
Copyright : (C) 2021 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 "qgsannotationitemcommonpropertieswidget.h"
#include "qgsannotationitem.h"

QgsAnnotationItemCommonPropertiesWidget::QgsAnnotationItemCommonPropertiesWidget( QWidget *parent )
: QWidget( parent )
{
setupUi( this );

connect( mSpinZIndex, qOverload<int>( &QSpinBox::valueChanged ), this, [ = ]
{
if ( !mBlockChangedSignal )
emit itemChanged();
} );
mSpinZIndex->setClearValue( 0 );

connect( mReferenceScaleGroup, &QGroupBox::toggled, this, [ = ]
{
if ( !mBlockChangedSignal )
emit itemChanged();
} );
connect( mReferenceScaleWidget, &QgsScaleWidget::scaleChanged, this, [ = ]
{
if ( !mBlockChangedSignal )
emit itemChanged();
} );
}

void QgsAnnotationItemCommonPropertiesWidget::setItem( QgsAnnotationItem *item )
{
mSpinZIndex->setValue( item->zIndex() );
mReferenceScaleGroup->setChecked( item->useSymbologyReferenceScale() );
mReferenceScaleWidget->setScale( item->symbologyReferenceScale() );
}

void QgsAnnotationItemCommonPropertiesWidget::updateItem( QgsAnnotationItem *item )
{
item->setZIndex( mSpinZIndex->value() );
item->setUseSymbologyReferenceScale( mReferenceScaleGroup->isChecked() );
item->setSymbologyReferenceScale( mReferenceScaleWidget->scale() );
}
@@ -0,0 +1,67 @@
/***************************************************************************
qgsannotationitemcommonpropertieswidget.h
------------------------
Date : September 2021
Copyright : (C) 2021 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 QGSANNOTATIONITEMCOMMONPROPERTIESWIDGET_H
#define QGSANNOTATIONITEMCOMMONPROPERTIESWIDGET_H

#include "qgis_gui.h"
#include "qgis_sip.h"

#include "ui_qgsannotationcommonpropertieswidgetbase.h"

class QgsAnnotationItem;

/**
* \class QgsAnnotationItemCommonPropertiesWidget
* \ingroup gui
*
* \brief A widget for configuring common properties for QgsAnnotationItems
*
* \since QGIS 3.22
*/
class GUI_EXPORT QgsAnnotationItemCommonPropertiesWidget: public QWidget, private Ui::QgsAnnotationCommonPropertiesWidgetBase
{
Q_OBJECT

public:

/**
* Constructor for QgsAnnotationItemCommonPropertiesWidget.
*/
QgsAnnotationItemCommonPropertiesWidget( QWidget *parent SIP_TRANSFERTHIS );

/**
* Sets the \a item whose properties should be shown in the widget.
*/
void setItem( QgsAnnotationItem *item );

/**
* Updates an \a item, setting the properties defined in the widget.
*/
void updateItem( QgsAnnotationItem *item );

signals:

/**
* Emitted when the annotation item definition in the widget is changed by the user.
*/
void itemChanged();

private:

bool mBlockChangedSignal = false;

};

#endif // QGSANNOTATIONITEMCOMMONPROPERTIESWIDGET_H
@@ -38,7 +38,7 @@ class GUI_EXPORT QgsAnnotationItemBaseWidget: public QgsPanelWidget
public:

/**
* Constructor for QgsAnnotationItemBaseWidget, linked with the specified annotation \a item.
* Constructor for QgsAnnotationItemBaseWidget.
*/
QgsAnnotationItemBaseWidget( QWidget *parent SIP_TRANSFERTHIS );

@@ -256,14 +256,19 @@ QgsAnnotationPointTextItemWidget::QgsAnnotationPointTextItemWidget( QWidget *par
if ( !mBlockChangedSignal )
emit itemChanged();
} );

connect( mPropertiesWidget, &QgsAnnotationItemCommonPropertiesWidget::itemChanged, this, [ = ]
{
if ( !mBlockChangedSignal )
emit itemChanged();
} );
}

QgsAnnotationItem *QgsAnnotationPointTextItemWidget::createItem()
{
QgsAnnotationPointTextItem *newItem = mItem->clone();
newItem->setFormat( mTextFormatWidget->format() );
newItem->setText( mTextEdit->toPlainText() );
mPropertiesWidget->updateItem( newItem );
return newItem;
}

@@ -273,6 +278,7 @@ void QgsAnnotationPointTextItemWidget::updateItem( QgsAnnotationItem *item )
{
pointTextItem->setFormat( mTextFormatWidget->format() );
pointTextItem->setText( mTextEdit->toPlainText() );
mPropertiesWidget->updateItem( pointTextItem );
}
}

@@ -296,6 +302,7 @@ bool QgsAnnotationPointTextItemWidget::setNewItem( QgsAnnotationItem *item )
mBlockChangedSignal = true;
mTextFormatWidget->setFormat( mItem->format() );
mTextEdit->setPlainText( mItem->text() );
mPropertiesWidget->setItem( mItem.get() );
mBlockChangedSignal = false;

return true;
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsAnnotationCommonPropertiesWidgetBase</class>
<widget class="QWidget" name="QgsAnnotationCommonPropertiesWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>321</width>
<height>325</height>
</rect>
</property>
<property name="windowTitle">
<string>Annotation Properties</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QGroupBox" name="mReferenceScaleGroup">
<property name="title">
<string>Reference Scale</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QgsScaleWidget" name="mReferenceScaleWidget" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="toolTip">
<string>Minimum scale, i.e. most &quot;zoomed out&quot;.</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Rendering</string>
</property>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Z-index</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsSpinBox" name="mSpinZIndex"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsScaleWidget</class>
<extends>QWidget</extends>
<header>qgsscalewidget.h</header>
</customwidget>
<customwidget>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>321</width>
<height>278</height>
<height>325</height>
</rect>
</property>
<property name="windowTitle">
@@ -36,11 +36,22 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QgsAnnotationItemCommonPropertiesWidget" name="mPropertiesWidget" native="true"/>
</item>
<item row="1" column="0">
<widget class="QWidget" name="mTextFormatWidgetContainer" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsAnnotationItemCommonPropertiesWidget</class>
<extends>QWidget</extends>
<header>qgsannotationitemcommonpropertieswidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit adcd793

Please sign in to comment.