Skip to content
Permalink
Browse files
Implement annotation item widget for point text annotation items
  • Loading branch information
nyalldawson committed Sep 7, 2021
1 parent ac4d252 commit 8e18629d4b12bbf2755520af4bd6bafbcc848d12
@@ -153,6 +153,16 @@ void QgsAnnotationItemGuiRegistry::addDefaultItems()
widget->setItem( item );
return widget;
} ) );

addAnnotationItemGuiMetadata( new QgsAnnotationItemGuiMetadata( QStringLiteral( "pointtext" ),
QObject::tr( "Text at Point" ),
QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddImage.svg" ) ),
[ = ]( QgsAnnotationItem * item )->QgsAnnotationItemBaseWidget *
{
QgsAnnotationPointTextItemWidget *widget = new QgsAnnotationPointTextItemWidget( nullptr );
widget->setItem( item );
return widget;
} ) );
}

QgsAnnotationItem *QgsAnnotationItemGuiMetadata::createItem()
@@ -22,6 +22,8 @@
#include "qgsannotationpolygonitem.h"
#include "qgsannotationlineitem.h"
#include "qgsannotationmarkeritem.h"
#include "qgsannotationpointtextitem.h"
#include "qgstextformatwidget.h"

///@cond PRIVATE

@@ -206,5 +208,71 @@ bool QgsAnnotationMarkerItemWidget::setNewItem( QgsAnnotationItem *item )
return true;
}



//
// QgsAnnotationPointTextItemWidget
//

QgsAnnotationPointTextItemWidget::QgsAnnotationPointTextItemWidget( QWidget *parent )
: QgsAnnotationItemBaseWidget( parent )
{
setupUi( this );

mTextFormatWidget = new QgsTextFormatWidget();
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->setContentsMargins( 0, 0, 0, 0 );
vLayout->addWidget( mTextFormatWidget );
mTextFormatWidgetContainer->setLayout( vLayout );

mTextEdit->setMaximumHeight( mTextEdit->fontMetrics().height() * 10 );

mTextFormatWidget->setDockMode( dockMode() );
connect( mTextFormatWidget, &QgsTextFormatWidget::widgetChanged, this, [ = ]
{
if ( !mBlockChangedSignal )
emit itemChanged();
} );
connect( mTextEdit, &QPlainTextEdit::textChanged, this, [ = ]
{
if ( !mBlockChangedSignal )
emit itemChanged();
} );

}

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

void QgsAnnotationPointTextItemWidget::setDockMode( bool dockMode )
{
QgsAnnotationItemBaseWidget::setDockMode( dockMode );
if ( mTextFormatWidget )
mTextFormatWidget->setDockMode( dockMode );
}

QgsAnnotationPointTextItemWidget::~QgsAnnotationPointTextItemWidget() = default;

bool QgsAnnotationPointTextItemWidget::setNewItem( QgsAnnotationItem *item )
{
QgsAnnotationPointTextItem *textItem = dynamic_cast< QgsAnnotationPointTextItem * >( item );
if ( !textItem )
return false;

mItem.reset( textItem->clone() );

mBlockChangedSignal = true;
mTextFormatWidget->setFormat( mItem->format() );
mTextEdit->setPlainText( mItem->text() );
mBlockChangedSignal = false;

return true;
}

///@endcond PRIVATE

@@ -18,15 +18,20 @@
#include "qgsannotationitemwidget.h"
#include "qgis_sip.h"
#include "qgis_gui.h"
#include "qgstextformat.h"
#include <memory>

#include "ui_qgsannotationpointtextwidgetbase.h"

class QgsSymbolSelectorWidget;
class QgsFillSymbol;
class QgsLineSymbol;
class QgsMarkerSymbol;
class QgsAnnotationPolygonItem;
class QgsAnnotationLineItem;
class QgsAnnotationMarkerItem;
class QgsAnnotationPointTextItem;
class QgsTextFormatWidget;

#define SIP_NO_FILE

@@ -95,6 +100,27 @@ class QgsAnnotationMarkerItemWidget : public QgsAnnotationItemBaseWidget
std::unique_ptr< QgsAnnotationMarkerItem> mItem;
};


class QgsAnnotationPointTextItemWidget : public QgsAnnotationItemBaseWidget, private Ui_QgsAnnotationPointTextWidgetBase
{
Q_OBJECT

public:
QgsAnnotationPointTextItemWidget( QWidget *parent );
~QgsAnnotationPointTextItemWidget() override;
QgsAnnotationItem *createItem() override;
void setDockMode( bool dockMode ) override;

protected:
bool setNewItem( QgsAnnotationItem *item ) override;

private:

QgsTextFormatWidget *mTextFormatWidget = nullptr;
bool mBlockChangedSignal = false;
std::unique_ptr< QgsAnnotationPointTextItem> mItem;
};

///@endcond

#endif // QGSANNOTATIONITEMWIDGETIMPL_H
@@ -16,6 +16,7 @@ file(GLOB CALLOUT_UIS "${CMAKE_CURRENT_SOURCE_DIR}/callouts/*.ui")
file(GLOB NUMERICFORMAT_UIS "${CMAKE_CURRENT_SOURCE_DIR}/numericformats/*.ui")
file(GLOB ATTRIBUTEFORMCONFIG_UIS "${CMAKE_CURRENT_SOURCE_DIR}/attributeformconfig/*.ui")
file(GLOB GEOREFERENCER_UIS "${CMAKE_CURRENT_SOURCE_DIR}/georeferencer/*.ui")
file(GLOB ANNOTATION_UIS "${CMAKE_CURRENT_SOURCE_DIR}/annotations/*.ui")

if (WITH_QT6)
QT6_WRAP_UI(QGIS_UIS_H
@@ -36,6 +37,7 @@ if (WITH_QT6)
${NUMERICFORMAT_UIS}
${ATTRIBUTEFORMCONFIG_UIS}
${GEOREFERENCER_UIS}
${ANNOTATION_UIS}
)
else()
QT5_WRAP_UI(QGIS_UIS_H
@@ -56,6 +58,7 @@ else()
${NUMERICFORMAT_UIS}
${ATTRIBUTEFORMCONFIG_UIS}
${GEOREFERENCER_UIS}
${ANNOTATION_UIS}
)
endif()

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsAnnotationPointTextWidgetBase</class>
<widget class="QWidget" name="QgsAnnotationPointTextWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>321</width>
<height>278</height>
</rect>
</property>
<property name="windowTitle">
<string>Point Text Annotation</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="QPlainTextEdit" name="mTextEdit">
<property name="minimumSize">
<size>
<width>0</width>
<height>150</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QWidget" name="mTextFormatWidgetContainer" native="true"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -14,6 +14,18 @@
<string>Layer Labeling Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<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="1" column="0">
<widget class="QFrame" name="mLabelingFrame">
<property name="minimumSize">

0 comments on commit 8e18629

Please sign in to comment.