Skip to content

Commit

Permalink
Port decoration buttons to QgsSymbolButton
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 24, 2017
1 parent 6398b74 commit 67b2724
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 189 deletions.
3 changes: 3 additions & 0 deletions src/app/qgsannotationwidget.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgssymbollayerutils.h"
#include "qgssymbol.h"
#include "qgssymbolselectordialog.h"
#include "qgisapp.h"
#include <QColorDialog>


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

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

QgsAnnotationWidget::~QgsAnnotationWidget()
Expand Down
85 changes: 6 additions & 79 deletions src/app/qgsdecorationgriddialog.cpp
Expand Up @@ -31,8 +31,6 @@
QgsDecorationGridDialog::QgsDecorationGridDialog( QgsDecorationGrid &deco, QWidget *parent )
: QDialog( parent )
, mDeco( deco )
, mLineSymbol( nullptr )
, mMarkerSymbol( nullptr )
{
setupUi( this );

Expand Down Expand Up @@ -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()
Expand All @@ -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() );

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 0 additions & 4 deletions src/app/qgsdecorationgriddialog.h
Expand Up @@ -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();

Expand All @@ -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();
Expand Down
39 changes: 4 additions & 35 deletions src/app/qgsdecorationlayoutextentdialog.cpp
Expand Up @@ -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() );
}
Expand All @@ -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 );
}
}
}
2 changes: 0 additions & 2 deletions src/app/qgsdecorationlayoutextentdialog.h
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/gui/symbology-ng/qgsnullsymbolrendererwidget.h
Expand Up @@ -20,7 +20,6 @@
#include "qgis_gui.h"

class QgsNullSymbolRenderer;
class QgsSymbolSelectorDialog;

class QMenu;

Expand Down
1 change: 0 additions & 1 deletion src/gui/symbology-ng/qgsrendererwidget.h
Expand Up @@ -28,7 +28,6 @@ class QgsDataDefinedSizeLegendWidget;
class QgsVectorLayer;
class QgsStyle;
class QgsFeatureRenderer;
class QgsSymbolSelectorDialog;
class QgsMapCanvas;

/** \ingroup gui
Expand Down
93 changes: 49 additions & 44 deletions src/ui/qgsdecorationgriddialog.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 67b2724

Please sign in to comment.