Skip to content
Permalink
Browse files

Use symbol button in annotation config widgets

  • Loading branch information
nyalldawson committed Jul 23, 2017
1 parent 46f6f83 commit 041479478756f4bb1f129a9ba552312e8bb2cb5e
@@ -28,7 +28,6 @@
QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWidget *parent, Qt::WindowFlags f )
: QWidget( parent, f )
, mItem( item )
, mMarkerSymbol( nullptr )
{
setupUi( this );
mLayerComboBox->setAllowEmptyLayer( true );
@@ -57,14 +56,12 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWid
const QgsMarkerSymbol *symbol = annotation->markerSymbol();
if ( symbol )
{
mMarkerSymbol.reset( symbol->clone() );
updateCenterIcon();
mMapMarkerButton->setSymbol( symbol->clone() );
}
const QgsFillSymbol *fill = annotation->fillSymbol();
if ( fill )
{
mFillSymbol.reset( fill->clone() );
updateFillIcon();
mFrameStyleButton->setSymbol( fill->clone() );
}

blockAllSignals( false );
@@ -83,8 +80,8 @@ void QgsAnnotationWidget::apply()
if ( annotation )
{
annotation->setHasFixedMapPosition( mMapPositionFixedCheckBox->checkState() == Qt::Checked );
annotation->setFillSymbol( mFillSymbol->clone() );
annotation->setMarkerSymbol( mMarkerSymbol->clone() );
annotation->setFillSymbol( mFrameStyleButton->clonedSymbol<QgsFillSymbol>() );
annotation->setMarkerSymbol( mMapMarkerButton->clonedSymbol<QgsMarkerSymbol>() );
annotation->setMapLayer( mLayerComboBox->currentLayer() );
annotation->setContentsMargin( QgsMargins( mSpinLeftMargin->value(),
mSpinTopMargin->value(),
@@ -101,63 +98,3 @@ void QgsAnnotationWidget::blockAllSignals( bool block )
mMapMarkerButton->blockSignals( block );
mLayerComboBox->blockSignals( block );
}

void QgsAnnotationWidget::on_mMapMarkerButton_clicked()
{
if ( !mMarkerSymbol )
{
return;
}
QgsMarkerSymbol *markerSymbol = mMarkerSymbol->clone();
QgsSymbolSelectorDialog dlg( markerSymbol, QgsStyle::defaultStyle(), nullptr, this );
if ( dlg.exec() == QDialog::Rejected )
{
delete markerSymbol;
}
else
{
mMarkerSymbol.reset( markerSymbol );
updateCenterIcon();
}
}

void QgsAnnotationWidget::on_mFrameStyleButton_clicked()
{
if ( !mFillSymbol )
{
return;
}
QgsFillSymbol *fillSymbol = mFillSymbol->clone();
QgsSymbolSelectorDialog dlg( fillSymbol, QgsStyle::defaultStyle(), nullptr, this );
if ( dlg.exec() == QDialog::Rejected )
{
delete fillSymbol;
}
else
{
mFillSymbol.reset( fillSymbol );
updateFillIcon();
backgroundColorChanged( fillSymbol->color() );
}
}

void QgsAnnotationWidget::updateCenterIcon()
{
if ( !mMarkerSymbol )
{
return;
}
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mMarkerSymbol.get(), mMapMarkerButton->iconSize() );
mMapMarkerButton->setIcon( icon );
}

void QgsAnnotationWidget::updateFillIcon()
{
if ( !mFillSymbol )
{
return;
}
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mFillSymbol.get(), mFrameStyleButton->iconSize() );
mFrameStyleButton->setIcon( icon );
}

@@ -42,14 +42,8 @@ class APP_EXPORT QgsAnnotationWidget: public QWidget, private Ui::QgsAnnotationW
//! Emitted when the background color of the annotation is changed
void backgroundColorChanged( const QColor &color );

private slots:
void on_mMapMarkerButton_clicked();
void on_mFrameStyleButton_clicked();

private:
QgsMapCanvasAnnotationItem *mItem = nullptr;
std::unique_ptr< QgsMarkerSymbol > mMarkerSymbol;
std::unique_ptr< QgsFillSymbol > mFillSymbol;

void blockAllSignals( bool block );
void updateCenterIcon();
@@ -22,6 +22,7 @@
#include <QFileDialog>
#include <QFileInfo>
#include <QGraphicsScene>
#include <QPushButton>

QgsFormAnnotationDialog::QgsFormAnnotationDialog( QgsMapCanvasAnnotationItem *item, QWidget *parent, Qt::WindowFlags f )
: QDialog( parent, f )
@@ -22,6 +22,7 @@
#include <QFileDialog>
#include <QFileInfo>
#include <QGraphicsScene>
#include <QPushButton>

QgsHtmlAnnotationDialog::QgsHtmlAnnotationDialog( QgsMapCanvasAnnotationItem *item, QWidget *parent, Qt::WindowFlags f )
: QDialog( parent, f )
@@ -24,6 +24,7 @@
#include <QFileDialog>
#include <QFileInfo>
#include <QGraphicsScene>
#include <QPushButton>

QgsSvgAnnotationDialog::QgsSvgAnnotationDialog( QgsMapCanvasAnnotationItem *item, QWidget *parent, Qt::WindowFlags f )
: QDialog( parent, f )
@@ -15,7 +15,13 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<widget class="QPushButton" name="mFrameStyleButton">
<widget class="QgsSymbolButton" name="mFrameStyleButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
@@ -206,7 +212,13 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="mMapMarkerButton">
<widget class="QgsSymbolButton" name="mMapMarkerButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
@@ -241,6 +253,11 @@
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsSymbolButton</class>
<extends>QToolButton</extends>
<header>qgssymbolbutton.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mMapPositionFixedCheckBox</tabstop>

0 comments on commit 0414794

Please sign in to comment.
You can’t perform that action at this time.