Skip to content
Permalink
Browse files
Add implementations of widgets for modifying the symbol of polygon,
line and marker annotation items
  • Loading branch information
nyalldawson committed Sep 7, 2021
1 parent c7c7b6d commit fcbc243c5b7091f742163bbe5fda6416c65c7649
@@ -96,6 +96,7 @@ set(QGIS_GUI_SRCS

annotations/qgsannotationitemguiregistry.cpp
annotations/qgsannotationitemwidget.cpp
annotations/qgsannotationitemwidget_impl.cpp
annotations/qgsmaptoolmodifyannotation.cpp

auth/qgsauthauthoritieseditor.cpp
@@ -18,6 +18,7 @@
#include "qgsannotationitemregistry.h"
#include "qgsannotationitem.h"

#include "qgsannotationitemwidget_impl.h"

QgsAnnotationItem *QgsAnnotationItemAbstractGuiMetadata::createItem()
{
@@ -34,6 +35,7 @@ QgsAnnotationItemGuiRegistry::QgsAnnotationItemGuiRegistry( QObject *parent )
{
}


QgsAnnotationItemGuiRegistry::~QgsAnnotationItemGuiRegistry()
{
qDeleteAll( mMetadata );
@@ -0,0 +1,207 @@
/***************************************************************************
qgsannotationitemwidget_impl.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 "qgsannotationitemwidget_impl.h"

#include "qgssymbolselectordialog.h"
#include "qgsstyle.h"
#include "qgsfillsymbol.h"
#include "qgslinesymbol.h"
#include "qgsmarkersymbol.h"
#include "qgsannotationpolygonitem.h"
#include "qgsannotationlineitem.h"
#include "qgsannotationmarkeritem.h"

QgsAnnotationPolygonItemWidget::QgsAnnotationPolygonItemWidget( QWidget *parent )
: QgsAnnotationItemBaseWidget( parent )
{
// setup ui
mSelector = new QgsSymbolSelectorWidget( mSymbol.get(), QgsStyle::defaultStyle(), nullptr, nullptr );
mSelector->setDockMode( dockMode() );
connect( mSelector, &QgsSymbolSelectorWidget::symbolModified, this, [ = ]
{
if ( !mBlockChangedSignal )
emit itemChanged();
} );
connect( mSelector, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );

QVBoxLayout *layout = new QVBoxLayout( this );
layout->setContentsMargins( 0, 0, 0, 0 );
layout->addWidget( mSelector );
}

QgsAnnotationItem *QgsAnnotationPolygonItemWidget::createItem()
{
QgsAnnotationPolygonItem *newItem = mItem->clone();
newItem->setSymbol( mSymbol->clone() );
return newItem;
}

void QgsAnnotationPolygonItemWidget::setDockMode( bool dockMode )
{
QgsAnnotationItemBaseWidget::setDockMode( dockMode );
if ( mSelector )
mSelector->setDockMode( dockMode );
}

QgsAnnotationPolygonItemWidget::~QgsAnnotationPolygonItemWidget() = default;

bool QgsAnnotationPolygonItemWidget::setNewItem( QgsAnnotationItem *item )
{
QgsAnnotationPolygonItem *polygonItem = dynamic_cast< QgsAnnotationPolygonItem * >( item );
if ( !polygonItem )
return false;

mItem.reset( polygonItem->clone() );
if ( mItem->symbol() )
{
mSymbol.reset( mItem->symbol()->clone() );
}
else
{
mSymbol.reset( QgsFillSymbol::createSimple( {} ) );
}
mBlockChangedSignal = true;
mSelector->loadSymbol( mSymbol.get() );
mSelector->updatePreview();
mBlockChangedSignal = false;

return true;
}


//
// QgsAnnotationLineItemWidget
//

QgsAnnotationLineItemWidget::QgsAnnotationLineItemWidget( QWidget *parent )
: QgsAnnotationItemBaseWidget( parent )
{
// setup ui
mSelector = new QgsSymbolSelectorWidget( mSymbol.get(), QgsStyle::defaultStyle(), nullptr, nullptr );
mSelector->setDockMode( dockMode() );
connect( mSelector, &QgsSymbolSelectorWidget::symbolModified, this, [ = ]
{
if ( !mBlockChangedSignal )
emit itemChanged();
} );
connect( mSelector, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );

QVBoxLayout *layout = new QVBoxLayout( this );
layout->setContentsMargins( 0, 0, 0, 0 );
layout->addWidget( mSelector );
}

QgsAnnotationItem *QgsAnnotationLineItemWidget::createItem()
{
QgsAnnotationLineItem *newItem = mItem->clone();
newItem->setSymbol( mSymbol->clone() );
return newItem;
}

void QgsAnnotationLineItemWidget::setDockMode( bool dockMode )
{
QgsAnnotationItemBaseWidget::setDockMode( dockMode );
if ( mSelector )
mSelector->setDockMode( dockMode );
}

QgsAnnotationLineItemWidget::~QgsAnnotationLineItemWidget() = default;

bool QgsAnnotationLineItemWidget::setNewItem( QgsAnnotationItem *item )
{
QgsAnnotationLineItem *lineItem = dynamic_cast< QgsAnnotationLineItem * >( item );
if ( !lineItem )
return false;

mItem.reset( lineItem->clone() );
if ( mItem->symbol() )
{
mSymbol.reset( mItem->symbol()->clone() );
}
else
{
mSymbol.reset( QgsLineSymbol::createSimple( {} ) );
}
mBlockChangedSignal = true;
mSelector->loadSymbol( mSymbol.get() );
mSelector->updatePreview();
mBlockChangedSignal = false;

return true;
}


//
// QgsAnnotationMarkerItemWidget
//

QgsAnnotationMarkerItemWidget::QgsAnnotationMarkerItemWidget( QWidget *parent )
: QgsAnnotationItemBaseWidget( parent )
{
// setup ui
mSelector = new QgsSymbolSelectorWidget( mSymbol.get(), QgsStyle::defaultStyle(), nullptr, nullptr );
mSelector->setDockMode( dockMode() );
connect( mSelector, &QgsSymbolSelectorWidget::symbolModified, this, [ = ]
{
if ( !mBlockChangedSignal )
emit itemChanged();
} );
connect( mSelector, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );

QVBoxLayout *layout = new QVBoxLayout( this );
layout->setContentsMargins( 0, 0, 0, 0 );
layout->addWidget( mSelector );
}

QgsAnnotationItem *QgsAnnotationMarkerItemWidget::createItem()
{
QgsAnnotationMarkerItem *newItem = mItem->clone();
newItem->setSymbol( mSymbol->clone() );
return newItem;
}

void QgsAnnotationMarkerItemWidget::setDockMode( bool dockMode )
{
QgsAnnotationItemBaseWidget::setDockMode( dockMode );
if ( mSelector )
mSelector->setDockMode( dockMode );
}

QgsAnnotationMarkerItemWidget::~QgsAnnotationMarkerItemWidget() = default;

bool QgsAnnotationMarkerItemWidget::setNewItem( QgsAnnotationItem *item )
{
QgsAnnotationMarkerItem *markerItem = dynamic_cast< QgsAnnotationMarkerItem * >( item );
if ( !markerItem )
return false;

mItem.reset( markerItem->clone() );
if ( mItem->symbol() )
{
mSymbol.reset( mItem->symbol()->clone() );
}
else
{
mSymbol.reset( QgsMarkerSymbol::createSimple( {} ) );
}
mBlockChangedSignal = true;
mSelector->loadSymbol( mSymbol.get() );
mSelector->updatePreview();
mBlockChangedSignal = false;

return true;
}


@@ -0,0 +1,94 @@
/***************************************************************************
qgsannotationitemwidget_impl.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 QGSANNOTATIONITEMWIDGETIMPL_H
#define QGSANNOTATIONITEMWIDGETIMPL_H

#include "qgsannotationitemwidget.h"
#include "qgis_sip.h"
#include "qgis_gui.h"
#include <memory>

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

class QgsAnnotationPolygonItemWidget : public QgsAnnotationItemBaseWidget
{
Q_OBJECT

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

protected:
bool setNewItem( QgsAnnotationItem *item ) override;

private:

QgsSymbolSelectorWidget *mSelector = nullptr;
std::unique_ptr< QgsFillSymbol > mSymbol;
bool mBlockChangedSignal = false;
std::unique_ptr< QgsAnnotationPolygonItem> mItem;
};

class QgsAnnotationLineItemWidget : public QgsAnnotationItemBaseWidget
{
Q_OBJECT

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

protected:
bool setNewItem( QgsAnnotationItem *item ) override;

private:

QgsSymbolSelectorWidget *mSelector = nullptr;
std::unique_ptr< QgsLineSymbol > mSymbol;
bool mBlockChangedSignal = false;
std::unique_ptr< QgsAnnotationLineItem> mItem;
};

class QgsAnnotationMarkerItemWidget : public QgsAnnotationItemBaseWidget
{
Q_OBJECT

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

protected:
bool setNewItem( QgsAnnotationItem *item ) override;

private:

QgsSymbolSelectorWidget *mSelector = nullptr;
std::unique_ptr< QgsMarkerSymbol > mSymbol;
bool mBlockChangedSignal = false;
std::unique_ptr< QgsAnnotationMarkerItem> mItem;
};

#endif // QGSANNOTATIONITEMWIDGETIMPL_H

0 comments on commit fcbc243

Please sign in to comment.