Skip to content
Permalink
Browse files

Use unique_ptr for owned object, and cleanup include in header

which was causing of cascade of unnecessary includes
  • Loading branch information
nyalldawson committed May 19, 2020
1 parent f49067c commit 62268e2b89096f7535e023109fff8dc85e930ddf
@@ -34,7 +34,6 @@
#include <QMenu>
#include <QPainter>
#include <QPushButton>
#include <QWidget>

QgsColorRampButton::QgsColorRampButton( QWidget *parent, const QString &dialogTitle )
: QToolButton( parent )
@@ -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
{
@@ -177,7 +172,7 @@ void QgsColorRampButton::setToDefaultColorRamp()
return;
}

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

void QgsColorRampButton::setToNull()
@@ -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 );
}
@@ -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 );
@@ -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() )
@@ -506,7 +500,7 @@ void QgsColorRampButton::setButtonBackground( QgsColorRamp *colorramp )
QgsColorRamp *backgroundColorRamp = colorramp;
if ( !colorramp )
{
backgroundColorRamp = mColorRamp;
backgroundColorRamp = mColorRamp.get();
}

QSize currentIconSize;
@@ -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 )
@@ -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
@@ -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
@@ -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.
@@ -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;
@@ -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,
@@ -15,6 +15,7 @@
#include "qgsellipsesymbollayerwidget.h"
#include "qgsellipsesymbollayer.h"
#include "qgsvectorlayer.h"
#include "qgssymbollayerutils.h"
#include <QColorDialog>

QgsEllipseSymbolLayerWidget::QgsEllipseSymbolLayerWidget( QgsVectorLayer *vl, QWidget *parent )
@@ -41,6 +41,7 @@
#include "qgsexpressioncontextutils.h"
#include "qgsmasksymbollayerwidget.h"
#include "qgstemporalcontroller.h"
#include "qgssymbollayerutils.h"

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

0 comments on commit 62268e2

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