Skip to content

Commit

Permalink
Use unique_ptr for owned object, and cleanup include in header
Browse files Browse the repository at this point in the history
which was causing of cascade of unnecessary includes
  • Loading branch information
nyalldawson committed May 20, 2020
1 parent f49067c commit 62268e2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
39 changes: 21 additions & 18 deletions src/gui/qgscolorrampbutton.cpp
Expand Up @@ -34,7 +34,6 @@
#include <QMenu>
#include <QPainter>
#include <QPushButton>
#include <QWidget>

QgsColorRampButton::QgsColorRampButton( QWidget *parent, const QString &dialogTitle )
: QToolButton( parent )
Expand All @@ -57,11 +56,7 @@ QgsColorRampButton::QgsColorRampButton( QWidget *parent, const QString &dialogTi
mStyle = QgsStyle::defaultStyle();
}

QgsColorRampButton::~QgsColorRampButton()
{
delete mColorRamp;
delete mDefaultColorRamp;
}
QgsColorRampButton::~QgsColorRampButton() = default;

QSize QgsColorRampButton::sizeHint() const
{
Expand Down Expand Up @@ -177,7 +172,7 @@ void QgsColorRampButton::setToDefaultColorRamp()
return;
}

setColorRamp( mDefaultColorRamp );
setColorRamp( mDefaultColorRamp.get() );
}

void QgsColorRampButton::setToNull()
Expand Down Expand Up @@ -249,7 +244,7 @@ void QgsColorRampButton::prepareMenu()
if ( mDefaultColorRamp )
{
QAction *defaultColorRampAction = new QAction( tr( "Default Color Ramp" ), this );
defaultColorRampAction->setIcon( createMenuIcon( mDefaultColorRamp ) );
defaultColorRampAction->setIcon( createMenuIcon( mDefaultColorRamp.get() ) );
mMenu->addAction( defaultColorRampAction );
connect( defaultColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setToDefaultColorRamp );
}
Expand All @@ -262,7 +257,7 @@ void QgsColorRampButton::prepareMenu()
mMenu->addAction( randomColorRampAction );
connect( randomColorRampAction, &QAction::triggered, this, &QgsColorRampButton::setRandomColorRamp );

if ( isRandomColorRamp() || dynamic_cast<QgsLimitedRandomColorRamp *>( mColorRamp ) )
if ( isRandomColorRamp() || dynamic_cast<QgsLimitedRandomColorRamp *>( mColorRamp.get() ) )
{
QAction *shuffleRandomColorRampAction = new QAction( tr( "Shuffle Random Colors" ), this );
mMenu->addAction( shuffleRandomColorRampAction );
Expand Down Expand Up @@ -462,16 +457,15 @@ void QgsColorRampButton::resizeEvent( QResizeEvent *event )
QToolButton::resizeEvent( event );
//recalculate icon size and redraw icon
mIconSize = QSize();
setButtonBackground( mColorRamp );
setButtonBackground( mColorRamp.get() );
}

void QgsColorRampButton::setColorRamp( QgsColorRamp *colorramp )
{
if ( colorramp == mColorRamp )
if ( colorramp == mColorRamp.get() )
return;

delete mColorRamp;
mColorRamp = colorramp ? colorramp->clone() : nullptr;
mColorRamp.reset( colorramp ? colorramp->clone() : nullptr );

setButtonBackground();
if ( isEnabled() )
Expand Down Expand Up @@ -506,7 +500,7 @@ void QgsColorRampButton::setButtonBackground( QgsColorRamp *colorramp )
QgsColorRamp *backgroundColorRamp = colorramp;
if ( !colorramp )
{
backgroundColorRamp = mColorRamp;
backgroundColorRamp = mColorRamp.get();
}

QSize currentIconSize;
Expand Down Expand Up @@ -593,18 +587,27 @@ void QgsColorRampButton::setShowMenu( const bool showMenu )
setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
//force recalculation of icon size
mIconSize = QSize();
setButtonBackground( mColorRamp );
setButtonBackground( mColorRamp.get() );
}

bool QgsColorRampButton::showMenu() const
{
return menu() ? true : false;
}

void QgsColorRampButton::setDefaultColorRamp( QgsColorRamp *colorramp )
{
delete mDefaultColorRamp;
mDefaultColorRamp = colorramp->clone();
mDefaultColorRamp.reset( colorramp ? colorramp->clone() : nullptr );
}

QgsColorRamp *QgsColorRampButton::defaultColorRamp() const
{
return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr;
}

bool QgsColorRampButton::isRandomColorRamp() const
{
return dynamic_cast<QgsRandomColorRamp *>( mColorRamp );
return dynamic_cast<QgsRandomColorRamp *>( mColorRamp.get() );
}

void QgsColorRampButton::setShowNull( bool showNull )
Expand Down
21 changes: 10 additions & 11 deletions src/gui/qgscolorrampbutton.h
Expand Up @@ -15,16 +15,15 @@
#ifndef QGSCOLORRAMPBUTTON_H
#define QGSCOLORRAMPBUTTON_H

#include "qgscolorrampbutton.h"

#include "qgscolorramp.h"
#include "qgsstyle.h"

#include <QToolButton>
#include "qgis_gui.h"
#include "qgis_sip.h"

#include <QToolButton>
#include <memory>

class QgsPanelWidget;
class QgsColorRamp;
class QgsStyle;

/**
* \ingroup gui
Expand Down Expand Up @@ -104,7 +103,7 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
* \returns TRUE if drop-down menu is shown
* \see setShowMenu
*/
bool showMenu() const { return menu() ? true : false; }
bool showMenu() const;

/**
* Sets the default color ramp for the button, which is shown in the button's drop-down menu for the
Expand All @@ -119,10 +118,10 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
* Returns a copy of the default color ramp for the button, which is shown in the button's drop-down menu for the
* "default color ramp" option.
* \returns default color ramp for the button. Returns NULLPTR if the default color ramp
* option is disabled.
* option is disabled. Caller takes ownership of the returned object.
* \see setDefaultColorRamp
*/
QgsColorRamp *defaultColorRamp() const SIP_FACTORY { return mDefaultColorRamp ? mDefaultColorRamp->clone() : nullptr ; }
QgsColorRamp *defaultColorRamp() const SIP_FACTORY;

/**
* Sets whether a random colors option is shown in the button's drop-down menu.
Expand Down Expand Up @@ -284,11 +283,11 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton

QString mColorRampDialogTitle;
bool mShowGradientOnly = false;
QgsColorRamp *mColorRamp = nullptr;
std::unique_ptr< QgsColorRamp > mColorRamp;
QString mColorRampName;
QgsStyle *mStyle = nullptr;

QgsColorRamp *mDefaultColorRamp = nullptr;
std::unique_ptr< QgsColorRamp > mDefaultColorRamp;
QString mContext;
bool mAcceptLiveUpdates = true;
bool mShowRandomColorRamp = false;
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgspropertyassistantwidget.cpp
Expand Up @@ -23,6 +23,7 @@
#include "qgslayertreelayer.h"
#include "qgssymbollayerutils.h"
#include "qgsexpressioncontextutils.h"
#include "qgsstyle.h"

QgsPropertyAssistantWidget::QgsPropertyAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition, const QgsProperty &initialState,
Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology/qgsellipsesymbollayerwidget.cpp
Expand Up @@ -15,6 +15,7 @@
#include "qgsellipsesymbollayerwidget.h"
#include "qgsellipsesymbollayer.h"
#include "qgsvectorlayer.h"
#include "qgssymbollayerutils.h"
#include <QColorDialog>

QgsEllipseSymbolLayerWidget::QgsEllipseSymbolLayerWidget( QgsVectorLayer *vl, QWidget *parent )
Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology/qgslayerpropertieswidget.cpp
Expand Up @@ -41,6 +41,7 @@
#include "qgsexpressioncontextutils.h"
#include "qgsmasksymbollayerwidget.h"
#include "qgstemporalcontroller.h"
#include "qgssymbollayerutils.h"

static bool _initWidgetFunction( const QString &name, QgsSymbolLayerWidgetFunc f )
{
Expand Down

0 comments on commit 62268e2

Please sign in to comment.