Skip to content
Permalink
Browse files

Port decoration buttons to QgsSymbolButton

  • Loading branch information
nyalldawson committed Jul 23, 2017
1 parent 6398b74 commit 67b272406eddf0dbae4475b79dfee5cb280c8b13
@@ -22,6 +22,7 @@
#include "qgssymbollayerutils.h"
#include "qgssymbol.h"
#include "qgssymbolselectordialog.h"
#include "qgisapp.h"
#include <QColorDialog>


@@ -66,6 +67,8 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWid

blockAllSignals( false );
}
mMapMarkerButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
mFrameStyleButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
}

QgsAnnotationWidget::~QgsAnnotationWidget()
@@ -31,8 +31,6 @@
QgsDecorationGridDialog::QgsDecorationGridDialog( QgsDecorationGrid &deco, QWidget *parent )
: QDialog( parent )
, mDeco( deco )
, mLineSymbol( nullptr )
, mMarkerSymbol( nullptr )
{
setupUi( this );

@@ -65,6 +63,8 @@ QgsDecorationGridDialog::QgsDecorationGridDialog( QgsDecorationGrid &deco, QWidg

connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsDecorationGridDialog::apply );
connect( mAnnotationFontButton, &QgsFontButton::changed, this, &QgsDecorationGridDialog::annotationFontChanged );

mMarkerSymbolButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
}

void QgsDecorationGridDialog::updateGuiElements()
@@ -88,22 +88,8 @@ void QgsDecorationGridDialog::updateGuiElements()
// mLineWidthSpinBox->setValue( gridPen.widthF() );
// mLineColorButton->setColor( gridPen.color() );

if ( mLineSymbol )
delete mLineSymbol;
if ( mDeco.lineSymbol() )
{
mLineSymbol = static_cast<QgsLineSymbol *>( mDeco.lineSymbol()->clone() );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mLineSymbol, mLineSymbolButton->iconSize() );
mLineSymbolButton->setIcon( icon );
}
if ( mMarkerSymbol )
delete mMarkerSymbol;
if ( mDeco.markerSymbol() )
{
mMarkerSymbol = static_cast<QgsMarkerSymbol *>( mDeco.markerSymbol()->clone() );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mMarkerSymbol, mMarkerSymbolButton->iconSize() );
mMarkerSymbolButton->setIcon( icon );
}
mLineSymbolButton->setSymbol( mDeco.lineSymbol()->clone() );
mMarkerSymbolButton->setSymbol( mDeco.markerSymbol()->clone() );

whileBlocking( mAnnotationFontButton )->setCurrentFont( mDeco.gridAnnotationFont() );

@@ -157,26 +143,14 @@ void QgsDecorationGridDialog::updateDecoFromGui()
mDeco.setGridAnnotationDirection( QgsDecorationGrid::BoundaryDirection );
}
mDeco.setGridAnnotationPrecision( mCoordinatePrecisionSpinBox->value() );
if ( mLineSymbol )
{
mDeco.setLineSymbol( mLineSymbol );
mLineSymbol = mDeco.lineSymbol()->clone();
}
if ( mMarkerSymbol )
{
mDeco.setMarkerSymbol( mMarkerSymbol );
mMarkerSymbol = mDeco.markerSymbol()->clone();
}
mDeco.setLineSymbol( mLineSymbolButton->clonedSymbol< QgsLineSymbol >() );
mDeco.setMarkerSymbol( mMarkerSymbolButton->clonedSymbol< QgsMarkerSymbol >() );
}

QgsDecorationGridDialog::~QgsDecorationGridDialog()
{
QgsSettings settings;
settings.setValue( QStringLiteral( "/Windows/DecorationGrid/geometry" ), saveGeometry() );
if ( mLineSymbol )
delete mLineSymbol;
if ( mMarkerSymbol )
delete mMarkerSymbol;
}

void QgsDecorationGridDialog::on_buttonBox_helpRequested()
@@ -210,53 +184,6 @@ void QgsDecorationGridDialog::on_mGridTypeComboBox_currentIndexChanged( int inde
mMarkerSymbolButton->setEnabled( index == QgsDecorationGrid::Marker );
}


void QgsDecorationGridDialog::on_mLineSymbolButton_clicked()
{
if ( ! mLineSymbol )
return;

QgsLineSymbol *lineSymbol = mLineSymbol->clone();
QgsSymbolSelectorDialog dlg( lineSymbol, QgsStyle::defaultStyle(), nullptr, this );
if ( dlg.exec() == QDialog::Rejected )
{
delete lineSymbol;
}
else
{
delete mLineSymbol;
mLineSymbol = lineSymbol;
if ( mLineSymbol )
{
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mLineSymbol, mLineSymbolButton->iconSize() );
mLineSymbolButton->setIcon( icon );
}
}
}

void QgsDecorationGridDialog::on_mMarkerSymbolButton_clicked()
{
if ( ! mMarkerSymbol )
return;

QgsMarkerSymbol *markerSymbol = mMarkerSymbol->clone();
QgsSymbolSelectorDialog dlg( markerSymbol, QgsStyle::defaultStyle(), nullptr, this );
if ( dlg.exec() == QDialog::Rejected )
{
delete markerSymbol;
}
else
{
delete mMarkerSymbol;
mMarkerSymbol = markerSymbol;
if ( mMarkerSymbol )
{
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mMarkerSymbol, mMarkerSymbolButton->iconSize() );
mMarkerSymbolButton->setIcon( icon );
}
}
}

void QgsDecorationGridDialog::on_mPbtnUpdateFromExtents_clicked()
{
updateInterval( true );
@@ -40,8 +40,6 @@ class APP_EXPORT QgsDecorationGridDialog : public QDialog, private Ui::QgsDecora
void on_buttonBox_rejected();
void on_buttonBox_helpRequested();
void on_mGridTypeComboBox_currentIndexChanged( int index );
void on_mLineSymbolButton_clicked();
void on_mMarkerSymbolButton_clicked();
void on_mPbtnUpdateFromExtents_clicked();
void on_mPbtnUpdateFromLayer_clicked();

@@ -51,8 +49,6 @@ class APP_EXPORT QgsDecorationGridDialog : public QDialog, private Ui::QgsDecora

private:
QgsDecorationGrid &mDeco;
QgsLineSymbol *mLineSymbol = nullptr;
QgsMarkerSymbol *mMarkerSymbol = nullptr;

void updateGuiElements();
void updateDecoFromGui();
@@ -44,31 +44,22 @@ QgsDecorationLayoutExtentDialog::QgsDecorationLayoutExtentDialog( QgsDecorationL

updateGuiElements();
connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsDecorationLayoutExtentDialog::apply );
connect( mSymbolButton, &QPushButton::clicked, this, &QgsDecorationLayoutExtentDialog::changeSymbol );

mSymbolButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
}

void QgsDecorationLayoutExtentDialog::updateGuiElements()
{
grpEnable->setChecked( mDeco.enabled() );

if ( mDeco.symbol() )
{
mSymbol.reset( static_cast<QgsFillSymbol *>( mDeco.symbol()->clone() ) );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mSymbol.get(), mSymbolButton->iconSize() );
mSymbolButton->setIcon( icon );
}
mSymbolButton->setSymbol( mDeco.symbol()->clone() );
mButtonFontStyle->setTextFormat( mDeco.textFormat() );
mCheckBoxLabelExtents->setChecked( mDeco.labelExtents() );
}

void QgsDecorationLayoutExtentDialog::updateDecoFromGui()
{
mDeco.setEnabled( grpEnable->isChecked() );

if ( mSymbol )
{
mDeco.setSymbol( mSymbol->clone() );
}
mDeco.setSymbol( mSymbolButton->clonedSymbol< QgsFillSymbol >() );
mDeco.setTextFormat( mButtonFontStyle->textFormat() );
mDeco.setLabelExtents( mCheckBoxLabelExtents->isChecked() );
}
@@ -95,25 +86,3 @@ void QgsDecorationLayoutExtentDialog::on_buttonBox_rejected()
{
reject();
}

void QgsDecorationLayoutExtentDialog::changeSymbol()
{
if ( !mSymbol )
return;

QgsFillSymbol *symbol = mSymbol->clone();
QgsSymbolSelectorDialog dlg( symbol, QgsStyle::defaultStyle(), nullptr, this );
if ( dlg.exec() == QDialog::Rejected )
{
delete symbol;
}
else
{
mSymbol.reset( symbol );
if ( mSymbol )
{
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mSymbol.get(), mSymbolButton->iconSize() );
mSymbolButton->setIcon( icon );
}
}
}
@@ -39,11 +39,9 @@ class APP_EXPORT QgsDecorationLayoutExtentDialog : public QDialog, private Ui::Q
void on_buttonBox_accepted();
void on_buttonBox_rejected();

void changeSymbol();

private:
QgsDecorationLayoutExtent &mDeco;
std::unique_ptr< QgsFillSymbol > mSymbol;

void updateGuiElements();
void updateDecoFromGui();
@@ -20,7 +20,6 @@
#include "qgis_gui.h"

class QgsNullSymbolRenderer;
class QgsSymbolSelectorDialog;

class QMenu;

@@ -28,7 +28,6 @@ class QgsDataDefinedSizeLegendWidget;
class QgsVectorLayer;
class QgsStyle;
class QgsFeatureRenderer;
class QgsSymbolSelectorDialog;
class QgsMapCanvas;

/** \ingroup gui
@@ -180,57 +180,13 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QPushButton" name="mLineSymbolButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="mMarkerSymbolLabel">
<property name="text">
<string>Marker symbol</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="mMarkerSymbolButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="Line" name="line_3">
<property name="orientation">
@@ -300,6 +256,50 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QgsSymbolButton" name="mLineSymbolButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QgsSymbolButton" name="mMarkerSymbolButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
<zorder>mOffsetYEdit</zorder>
<zorder>mOffsetXEdit</zorder>
@@ -334,6 +334,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsSymbolButton</class>
<extends>QToolButton</extends>
<header>qgssymbolbutton.h</header>
</customwidget>
<customwidget>
<class>QgsFontButton</class>
<extends>QToolButton</extends>

0 comments on commit 67b2724

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