mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Color ramp dialogs no longer edit ramps in place
Now the dialogs use a copy of the ramp, and the edited ramp is retrieved by calling ramp() on the dialog after it is executed. Avoids pointer lifetime issues by storing and working on a ramp pointer which the dialog does not have ownership on. Also fix a bunch of leaks relating to cloning color ramps.
This commit is contained in:
parent
7413db79b0
commit
cf9292cc6d
@ -295,6 +295,13 @@ variant instead.</li>
|
||||
<li>GenericDataSourceURI has been renamed to GenericDataSourceUri</li>
|
||||
</ul>
|
||||
|
||||
\subsection qgis_api_break_3_0_QgsColorBrewerColorRampDialog QgsColorBrewerColorRampDialog
|
||||
|
||||
<ul>
|
||||
<li>The dialog no longer edits a color ramp in place. Instead, a copy of the ramp is edited
|
||||
and the new ramp can be retrieved after executing the dialog by calling ramp().</li>
|
||||
</ul>
|
||||
|
||||
\subsection qgis_api_break_3_0_QgsComposerLabel QgsComposerLabel
|
||||
|
||||
<ul>
|
||||
@ -389,6 +396,13 @@ plugins calling these methods will need to be updated.</li>
|
||||
be returned in place of a null pointer.</li>
|
||||
</ul>
|
||||
|
||||
\subsection qgis_api_break_3_0_QgsCptCityColorRampDialog QgsCptCityColorRampDialog
|
||||
|
||||
<ul>
|
||||
<li>The dialog no longer edits a color ramp in place. Instead, a copy of the ramp is edited
|
||||
and the new ramp can be retrieved after executing the dialog by calling ramp().</li>
|
||||
</ul>
|
||||
|
||||
\subsection qgis_api_break_3_0_QgsCptCitySelectionItem QgsCptCitySelectionItem
|
||||
|
||||
<ul>
|
||||
@ -559,6 +573,13 @@ method to determine if a geometry is valid.</li>
|
||||
a QgsGeometry value rather than a pointer.</li>
|
||||
</ul>
|
||||
|
||||
\subsection qgis_api_break_3_0_QgsGradientColorRampDialog QgsGradientColorRampDialog
|
||||
|
||||
<ul>
|
||||
<li>The dialog no longer edits a color ramp in place. Instead, a copy of the ramp is edited
|
||||
and the new ramp can be retrieved after executing the dialog by calling ramp().</li>
|
||||
</ul>
|
||||
|
||||
\subsection qgis_api_break_3_0_QgsGraphBuilderInterface QgsGraphBuilderInterface
|
||||
|
||||
<ul>
|
||||
@ -604,6 +625,13 @@ plugins calling this method will need to be updated.</li>
|
||||
<li>writeCommonXML() has been renamed to writeCommonXml()</li>
|
||||
</ul>
|
||||
|
||||
\subsection qgis_api_break_3_0_QgsLimitedRandomRampDialog QgsLimitedRandomColorRampDialog
|
||||
|
||||
<ul>
|
||||
<li>The dialog no longer edits a color ramp in place. Instead, a copy of the ramp is edited
|
||||
and the new ramp can be retrieved after executing the dialog by calling ramp().</li>
|
||||
</ul>
|
||||
|
||||
\subsection qgis_api_break_3_0_QgsMapCanvas QgsMapCanvas
|
||||
|
||||
<ul>
|
||||
|
@ -16,11 +16,10 @@ class QgsStyle : QObject
|
||||
*/
|
||||
enum StyleEntity { SymbolEntity, GroupEntity, TagEntity, ColorrampEntity, SmartgroupEntity };
|
||||
|
||||
//! add color ramp to style. takes ramp's ownership
|
||||
/*!
|
||||
/** Adds a color ramp to the style. Calling this method takes the ramp's ownership.
|
||||
* \note Adding a color ramp with the name of existing one replaces it.
|
||||
* \param name is the name of the color ramp being added or updated
|
||||
* \param colorRamp is the color ramp
|
||||
* \param colorRamp is the color ramp. Ownership is transferred.
|
||||
* \param update set to true when the style DB has to be updated, by default it is false
|
||||
* \return success status of the operation
|
||||
*/
|
||||
@ -71,8 +70,10 @@ class QgsStyle : QObject
|
||||
//! remove all contents of the style
|
||||
void clear();
|
||||
|
||||
//! return a NEW copy of color ramp
|
||||
QgsColorRamp* colorRamp( const QString& name ) /Factory/;
|
||||
/** Returns a new copy of the specified color ramp. The caller
|
||||
* takes responsibility for deleting the returned object.
|
||||
*/
|
||||
QgsColorRamp* colorRamp( const QString& name ) const /Factory/;
|
||||
|
||||
//! return count of color ramps
|
||||
int colorRampCount();
|
||||
|
@ -5,7 +5,9 @@ class QgsColorBrewerColorRampDialog : QDialog
|
||||
%End
|
||||
|
||||
public:
|
||||
QgsColorBrewerColorRampDialog( QgsColorBrewerColorRamp* ramp, QWidget* parent /TransferThis/ = NULL );
|
||||
QgsColorBrewerColorRampDialog( const QgsColorBrewerColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );
|
||||
|
||||
QgsColorBrewerColorRamp ramp() const;
|
||||
|
||||
public slots:
|
||||
void setSchemeName();
|
||||
|
@ -5,7 +5,10 @@ class QgsGradientColorRampDialog : QDialog
|
||||
%End
|
||||
|
||||
public:
|
||||
QgsGradientColorRampDialog( QgsGradientColorRamp* ramp, QWidget* parent /TransferThis/ = NULL );
|
||||
QgsGradientColorRampDialog( const QgsGradientColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );
|
||||
~QgsGradientColorRampDialog();
|
||||
|
||||
QgsGradientColorRamp ramp() const;
|
||||
|
||||
public slots:
|
||||
void setColor1( const QColor& color );
|
||||
|
@ -5,7 +5,9 @@ class QgsLimitedRandomColorRampDialog : QDialog
|
||||
%End
|
||||
|
||||
public:
|
||||
QgsLimitedRandomColorRampDialog( QgsLimitedRandomColorRamp* ramp, QWidget* parent /TransferThis/ = NULL );
|
||||
QgsLimitedRandomColorRampDialog( const QgsLimitedRandomColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );
|
||||
|
||||
QgsLimitedRandomColorRamp ramp() const;
|
||||
|
||||
public slots:
|
||||
void setCount( int val );
|
||||
|
@ -11,11 +11,18 @@ class QgsColorRampComboBox : QComboBox
|
||||
//! initialize the combo box with color ramps from the style
|
||||
void populate( QgsStyle* style );
|
||||
|
||||
//! add/select color ramp which was used previously by the renderer
|
||||
void setSourceColorRamp( QgsColorRamp* sourceRamp );
|
||||
/** Adds or selects the current color ramp to show in the combo box. The ramp appears
|
||||
* in the combo box as the "source" ramp.
|
||||
* @param sourceRamp color ramp, ownership is transferred.
|
||||
* @see currentColorRamp()
|
||||
*/
|
||||
void setSourceColorRamp( QgsColorRamp* sourceRamp /Transfer/ );
|
||||
|
||||
//! return new instance of the current color ramp or NULL if there is no active color ramp
|
||||
QgsColorRamp* currentColorRamp();
|
||||
/** Returns a new instance of the current color ramp or NULL if there is no active color ramp.
|
||||
* The caller takes responsibility for deleting the returned value.
|
||||
* @see setSourceColorRamp()
|
||||
*/
|
||||
QgsColorRamp* currentColorRamp() const /Factory/;
|
||||
|
||||
/** Returns true if the current selection in the combo box is the option for creating
|
||||
* a new color ramp
|
||||
|
@ -5,9 +5,13 @@ class QgsCptCityColorRampDialog : QDialog
|
||||
%End
|
||||
|
||||
public:
|
||||
QgsCptCityColorRampDialog( QgsCptCityColorRamp* ramp, QWidget* parent /TransferThis/ = NULL );
|
||||
|
||||
QgsCptCityColorRampDialog( const QgsCptCityColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );
|
||||
~QgsCptCityColorRampDialog();
|
||||
|
||||
QgsCptCityColorRamp ramp() const;
|
||||
|
||||
|
||||
QString selectedName() const;
|
||||
|
||||
bool saveAsGradientRamp() const;
|
||||
|
@ -1713,10 +1713,9 @@ void QgsProjectProperties::populateStyles()
|
||||
for ( int i = 0; i < colorRamps.count(); ++i )
|
||||
{
|
||||
QString name = colorRamps[i];
|
||||
QgsColorRamp* ramp = mStyle->colorRamp( name );
|
||||
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp, cboStyleColorRamp->iconSize() );
|
||||
QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
|
||||
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), cboStyleColorRamp->iconSize() );
|
||||
cboStyleColorRamp->addItem( icon, name );
|
||||
delete ramp;
|
||||
}
|
||||
|
||||
// set current index if found
|
||||
|
@ -254,7 +254,7 @@ bool QgsStyle::removeColorRamp( const QString& name )
|
||||
return true;
|
||||
}
|
||||
|
||||
QgsColorRamp* QgsStyle::colorRamp( const QString& name )
|
||||
QgsColorRamp* QgsStyle::colorRamp( const QString& name ) const
|
||||
{
|
||||
const QgsColorRamp *ramp = colorRampRef( name );
|
||||
return ramp ? ramp->clone() : nullptr;
|
||||
@ -1536,7 +1536,8 @@ bool QgsStyle::updateSymbol( StyleEntity type, const QString& name )
|
||||
return false;
|
||||
}
|
||||
|
||||
symEl = QgsSymbolLayerUtils::saveColorRamp( name, colorRamp( name ), doc );
|
||||
QScopedPointer< QgsColorRamp > ramp( colorRamp( name ) );
|
||||
symEl = QgsSymbolLayerUtils::saveColorRamp( name, ramp.data(), doc );
|
||||
if ( symEl.isNull() )
|
||||
{
|
||||
QgsDebugMsg( "Couldn't convert color ramp to valid XML!" );
|
||||
|
@ -82,11 +82,10 @@ class CORE_EXPORT QgsStyle : public QObject
|
||||
*/
|
||||
enum StyleEntity { SymbolEntity, GroupEntity, TagEntity, ColorrampEntity, SmartgroupEntity };
|
||||
|
||||
//! add color ramp to style. takes ramp's ownership
|
||||
/*!
|
||||
/** Adds a color ramp to the style. Calling this method takes the ramp's ownership.
|
||||
* \note Adding a color ramp with the name of existing one replaces it.
|
||||
* \param name is the name of the color ramp being added or updated
|
||||
* \param colorRamp is the Vector color ramp
|
||||
* \param colorRamp is the color ramp. Ownership is transferred.
|
||||
* \param update set to true when the style DB has to be updated, by default it is false
|
||||
* \return success status of the operation
|
||||
*/
|
||||
@ -137,8 +136,10 @@ class CORE_EXPORT QgsStyle : public QObject
|
||||
//! remove all contents of the style
|
||||
void clear();
|
||||
|
||||
//! return a NEW copy of color ramp
|
||||
QgsColorRamp* colorRamp( const QString& name );
|
||||
/** Returns a new copy of the specified color ramp. The caller
|
||||
* takes responsibility for deleting the returned object.
|
||||
*/
|
||||
QgsColorRamp* colorRamp( const QString& name ) const;
|
||||
|
||||
//! return count of color ramps
|
||||
int colorRampCount();
|
||||
|
@ -31,7 +31,7 @@ static void updateColorButton( QAbstractButton* button, QColor color )
|
||||
/////////
|
||||
|
||||
|
||||
QgsColorBrewerColorRampDialog::QgsColorBrewerColorRampDialog( QgsColorBrewerColorRamp* ramp, QWidget* parent )
|
||||
QgsColorBrewerColorRampDialog::QgsColorBrewerColorRampDialog( const QgsColorBrewerColorRamp& ramp, QWidget* parent )
|
||||
: QDialog( parent )
|
||||
, mRamp( ramp )
|
||||
{
|
||||
@ -51,9 +51,9 @@ QgsColorBrewerColorRampDialog::QgsColorBrewerColorRampDialog( QgsColorBrewerColo
|
||||
cboSchemeName->addItem( icon, schemeName );
|
||||
}
|
||||
|
||||
cboSchemeName->setCurrentIndex( cboSchemeName->findText( ramp->schemeName() ) );
|
||||
cboSchemeName->setCurrentIndex( cboSchemeName->findText( mRamp.schemeName() ) );
|
||||
populateVariants();
|
||||
cboColors->setCurrentIndex( cboColors->findText( QString::number( ramp->colors() ) ) );
|
||||
cboColors->setCurrentIndex( cboColors->findText( QString::number( mRamp.colors() ) ) );
|
||||
|
||||
connect( cboSchemeName, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setSchemeName() ) );
|
||||
connect( cboColors, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setColors() ) );
|
||||
@ -86,7 +86,7 @@ void QgsColorBrewerColorRampDialog::populateVariants()
|
||||
void QgsColorBrewerColorRampDialog::updatePreview()
|
||||
{
|
||||
QSize size( 300, 40 );
|
||||
lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( mRamp, size ) );
|
||||
lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size ) );
|
||||
}
|
||||
|
||||
void QgsColorBrewerColorRampDialog::setSchemeName()
|
||||
@ -94,13 +94,13 @@ void QgsColorBrewerColorRampDialog::setSchemeName()
|
||||
// populate list of variants
|
||||
populateVariants();
|
||||
|
||||
mRamp->setSchemeName( cboSchemeName->currentText() );
|
||||
mRamp.setSchemeName( cboSchemeName->currentText() );
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
void QgsColorBrewerColorRampDialog::setColors()
|
||||
{
|
||||
int num = cboColors->currentText().toInt();
|
||||
mRamp->setColors( num );
|
||||
mRamp.setColors( num );
|
||||
updatePreview();
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "qgscolorramp.h"
|
||||
#include "ui_qgscolorbrewercolorrampdialogbase.h"
|
||||
|
||||
class QgsColorBrewerColorRamp;
|
||||
@ -30,7 +31,9 @@ class GUI_EXPORT QgsColorBrewerColorRampDialog : public QDialog, private Ui::Qgs
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QgsColorBrewerColorRampDialog( QgsColorBrewerColorRamp* ramp, QWidget* parent = nullptr );
|
||||
QgsColorBrewerColorRampDialog( const QgsColorBrewerColorRamp& ramp, QWidget* parent = nullptr );
|
||||
|
||||
QgsColorBrewerColorRamp ramp() const { return mRamp; }
|
||||
|
||||
public slots:
|
||||
void setSchemeName();
|
||||
@ -42,7 +45,7 @@ class GUI_EXPORT QgsColorBrewerColorRampDialog : public QDialog, private Ui::Qgs
|
||||
|
||||
void updatePreview();
|
||||
|
||||
QgsColorBrewerColorRamp* mRamp;
|
||||
QgsColorBrewerColorRamp mRamp;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include <qwt_symbol.h>
|
||||
#include <qwt_legend.h>
|
||||
|
||||
QgsGradientColorRampDialog::QgsGradientColorRampDialog( QgsGradientColorRamp* ramp, QWidget* parent )
|
||||
QgsGradientColorRampDialog::QgsGradientColorRampDialog( const QgsGradientColorRamp& ramp, QWidget* parent )
|
||||
: QDialog( parent )
|
||||
, mRamp( ramp )
|
||||
, mCurrentPlotColorComponent( -1 )
|
||||
@ -70,16 +70,16 @@ QgsGradientColorRampDialog::QgsGradientColorRampDialog( QgsGradientColorRamp* ra
|
||||
cboType->blockSignals( true );
|
||||
cboType->addItem( tr( "Discrete" ) );
|
||||
cboType->addItem( tr( "Continuous" ) );
|
||||
if ( mRamp->isDiscrete() )
|
||||
if ( mRamp.isDiscrete() )
|
||||
cboType->setCurrentIndex( 0 );
|
||||
else
|
||||
cboType->setCurrentIndex( 1 );
|
||||
cboType->blockSignals( false );
|
||||
|
||||
if ( mRamp->info().isEmpty() )
|
||||
if ( mRamp.info().isEmpty() )
|
||||
btnInformation->setEnabled( false );
|
||||
|
||||
mStopEditor->setGradientRamp( *mRamp );
|
||||
mStopEditor->setGradientRamp( mRamp );
|
||||
connect( mStopEditor, SIGNAL( changed() ), this, SLOT( updateRampFromStopEditor() ) );
|
||||
|
||||
connect( mColorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SLOT( colorWidgetChanged( QColor ) ) );
|
||||
@ -157,10 +157,10 @@ QgsGradientColorRampDialog::~QgsGradientColorRampDialog()
|
||||
|
||||
void QgsGradientColorRampDialog::on_cboType_currentIndexChanged( int index )
|
||||
{
|
||||
if (( index == 0 && mRamp->isDiscrete() ) ||
|
||||
( index == 1 && !mRamp->isDiscrete() ) )
|
||||
if (( index == 0 && mRamp.isDiscrete() ) ||
|
||||
( index == 1 && !mRamp.isDiscrete() ) )
|
||||
return;
|
||||
mRamp->convertToDiscrete( index == 0 );
|
||||
mRamp.convertToDiscrete( index == 0 );
|
||||
updateColorButtons();
|
||||
updateStopEditor();
|
||||
updatePlot();
|
||||
@ -168,7 +168,7 @@ void QgsGradientColorRampDialog::on_cboType_currentIndexChanged( int index )
|
||||
|
||||
void QgsGradientColorRampDialog::on_btnInformation_pressed()
|
||||
{
|
||||
if ( mRamp->info().isEmpty() )
|
||||
if ( mRamp.info().isEmpty() )
|
||||
return;
|
||||
|
||||
QgsDialog *dlg = new QgsDialog( this );
|
||||
@ -178,10 +178,10 @@ void QgsGradientColorRampDialog::on_btnInformation_pressed()
|
||||
QTableWidget *tableInfo = new QTableWidget( dlg );
|
||||
tableInfo->verticalHeader()->hide();
|
||||
tableInfo->horizontalHeader()->hide();
|
||||
tableInfo->setRowCount( mRamp->info().count() );
|
||||
tableInfo->setRowCount( mRamp.info().count() );
|
||||
tableInfo->setColumnCount( 2 );
|
||||
int i = 0;
|
||||
QgsStringMap rampInfo = mRamp->info();
|
||||
QgsStringMap rampInfo = mRamp.info();
|
||||
for ( QgsStringMap::const_iterator it = rampInfo.constBegin();
|
||||
it != rampInfo.constEnd(); ++it )
|
||||
{
|
||||
@ -202,7 +202,7 @@ void QgsGradientColorRampDialog::on_btnInformation_pressed()
|
||||
dlg->layout()->addSpacing( 5 );
|
||||
|
||||
// gradient file
|
||||
QString gradientFile = mRamp->info().value( "cpt-city-gradient" );
|
||||
QString gradientFile = mRamp.info().value( "cpt-city-gradient" );
|
||||
if ( ! gradientFile.isNull() )
|
||||
{
|
||||
QString fileName = gradientFile;
|
||||
@ -219,7 +219,7 @@ void QgsGradientColorRampDialog::on_btnInformation_pressed()
|
||||
}
|
||||
|
||||
// license file
|
||||
QString licenseFile = mRamp->info().value( "cpt-city-license" );
|
||||
QString licenseFile = mRamp.info().value( "cpt-city-license" );
|
||||
if ( !licenseFile.isNull() )
|
||||
{
|
||||
QString fileName = licenseFile;
|
||||
@ -255,17 +255,17 @@ void QgsGradientColorRampDialog::on_btnInformation_pressed()
|
||||
void QgsGradientColorRampDialog::updateColorButtons()
|
||||
{
|
||||
btnColor1->blockSignals( true );
|
||||
btnColor1->setColor( mRamp->color1() );
|
||||
btnColor1->setColor( mRamp.color1() );
|
||||
btnColor1->blockSignals( false );
|
||||
btnColor2->blockSignals( true );
|
||||
btnColor2->setColor( mRamp->color2() );
|
||||
btnColor2->setColor( mRamp.color2() );
|
||||
btnColor2->blockSignals( false );
|
||||
}
|
||||
|
||||
void QgsGradientColorRampDialog::updateStopEditor()
|
||||
{
|
||||
mStopEditor->blockSignals( true );
|
||||
mStopEditor->setGradientRamp( *mRamp );
|
||||
mStopEditor->setGradientRamp( mRamp );
|
||||
mStopEditor->blockSignals( false );
|
||||
}
|
||||
|
||||
@ -278,7 +278,7 @@ void QgsGradientColorRampDialog::selectedStopChanged( const QgsGradientStop& sto
|
||||
mPositionSpinBox->setValue( stop.offset * 100 );
|
||||
mPositionSpinBox->blockSignals( false );
|
||||
|
||||
if (( stop.offset == 0 && stop.color == mRamp->color1() ) || ( stop.offset == 1.0 && stop.color == mRamp->color2() ) )
|
||||
if (( stop.offset == 0 && stop.color == mRamp.color1() ) || ( stop.offset == 1.0 && stop.color == mRamp.color2() ) )
|
||||
{
|
||||
//first/last stop can't be repositioned
|
||||
mPositionSpinBox->setDisabled( true );
|
||||
@ -336,24 +336,24 @@ void QgsGradientColorRampDialog::plotMousePress( QPointF point )
|
||||
mCurrentPlotMarkerIndex = -1;
|
||||
// first color
|
||||
|
||||
for ( int i = 0; i < mRamp->count(); ++i )
|
||||
for ( int i = 0; i < mRamp.count(); ++i )
|
||||
{
|
||||
QColor currentCol;
|
||||
double currentOff = 0.0;
|
||||
if ( i == 0 )
|
||||
{
|
||||
currentOff = 0.0;
|
||||
currentCol = mRamp->color1();
|
||||
currentCol = mRamp.color1();
|
||||
}
|
||||
else if ( i == mRamp->count() - 1 )
|
||||
else if ( i == mRamp.count() - 1 )
|
||||
{
|
||||
currentOff = 1.0;
|
||||
currentCol = mRamp->color2();
|
||||
currentCol = mRamp.color2();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentOff = mRamp->stops().at( i - 1 ).offset;
|
||||
currentCol = mRamp->stops().at( i - 1 ).color;
|
||||
currentOff = mRamp.stops().at( i - 1 ).offset;
|
||||
currentCol = mRamp.stops().at( i - 1 ).color;
|
||||
}
|
||||
|
||||
double currentDist;
|
||||
@ -476,14 +476,14 @@ void QgsGradientColorRampDialog::updatePlot()
|
||||
QPolygonF huePoints;
|
||||
QPolygonF saturationPoints;
|
||||
QPolygonF alphaPoints;
|
||||
lightnessPoints << QPointF( 0.0, mRamp->color1().lightnessF() );
|
||||
huePoints << QPointF( 0.0, mRamp->color1().hslHueF() );
|
||||
saturationPoints << QPointF( 0.0, mRamp->color1().hslSaturationF() );
|
||||
alphaPoints << QPointF( 0.0, mRamp->color1().alphaF() );
|
||||
addMarkersForColor( 0, mRamp->color1(), mCurrentPlotMarkerIndex == 0 );
|
||||
lightnessPoints << QPointF( 0.0, mRamp.color1().lightnessF() );
|
||||
huePoints << QPointF( 0.0, mRamp.color1().hslHueF() );
|
||||
saturationPoints << QPointF( 0.0, mRamp.color1().hslSaturationF() );
|
||||
alphaPoints << QPointF( 0.0, mRamp.color1().alphaF() );
|
||||
addMarkersForColor( 0, mRamp.color1(), mCurrentPlotMarkerIndex == 0 );
|
||||
|
||||
int i = 1;
|
||||
Q_FOREACH ( const QgsGradientStop& stop, mRamp->stops() )
|
||||
Q_FOREACH ( const QgsGradientStop& stop, mRamp.stops() )
|
||||
{
|
||||
lightnessPoints << QPointF( stop.offset, stop.color.lightnessF() );
|
||||
huePoints << QPointF( stop.offset, stop.color.hslHueF() );
|
||||
@ -497,18 +497,18 @@ void QgsGradientColorRampDialog::updatePlot()
|
||||
//add extra intermediate points
|
||||
for ( double p = 0.001; p < 1.0; p += 0.001 )
|
||||
{
|
||||
QColor c = mRamp->color( p );
|
||||
QColor c = mRamp.color( p );
|
||||
lightnessPoints << QPointF( p, c.lightnessF() );
|
||||
huePoints << QPointF( p, c.hslHueF() );
|
||||
saturationPoints << QPointF( p, c.hslSaturationF() );
|
||||
alphaPoints << QPointF( p, c.alphaF() );
|
||||
}
|
||||
|
||||
lightnessPoints << QPointF( 1.0, mRamp->color2().lightnessF() );
|
||||
huePoints << QPointF( 1.0, mRamp->color2().hslHueF() );
|
||||
saturationPoints << QPointF( 1.0, mRamp->color2().hslSaturationF() );
|
||||
alphaPoints << QPointF( 1.0, mRamp->color2().alphaF() );
|
||||
addMarkersForColor( 1.0, mRamp->color2(), mCurrentPlotMarkerIndex == i );
|
||||
lightnessPoints << QPointF( 1.0, mRamp.color2().lightnessF() );
|
||||
huePoints << QPointF( 1.0, mRamp.color2().hslHueF() );
|
||||
saturationPoints << QPointF( 1.0, mRamp.color2().hslSaturationF() );
|
||||
alphaPoints << QPointF( 1.0, mRamp.color2().alphaF() );
|
||||
addMarkersForColor( 1.0, mRamp.color2(), mCurrentPlotMarkerIndex == i );
|
||||
|
||||
qSort( lightnessPoints.begin(), lightnessPoints.end(), byX );
|
||||
qSort( huePoints.begin(), huePoints.end(), byX );
|
||||
@ -531,7 +531,7 @@ void QgsGradientColorRampDialog::updatePlot()
|
||||
|
||||
void QgsGradientColorRampDialog::updateRampFromStopEditor()
|
||||
{
|
||||
*mRamp = mStopEditor->gradientRamp();
|
||||
mRamp = mStopEditor->gradientRamp();
|
||||
mPositionSpinBox->blockSignals( true );
|
||||
mPositionSpinBox->setValue( mStopEditor->selectedStop().offset * 100 );
|
||||
mPositionSpinBox->blockSignals( false );
|
||||
|
@ -34,9 +34,11 @@ class GUI_EXPORT QgsGradientColorRampDialog : public QDialog, private Ui::QgsGra
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QgsGradientColorRampDialog( QgsGradientColorRamp* ramp, QWidget* parent = nullptr );
|
||||
QgsGradientColorRampDialog( const QgsGradientColorRamp& ramp, QWidget* parent = nullptr );
|
||||
~QgsGradientColorRampDialog();
|
||||
|
||||
QgsGradientColorRamp ramp() const { return mRamp; }
|
||||
|
||||
public slots:
|
||||
void setColor1( const QColor& color );
|
||||
void setColor2( const QColor& color );
|
||||
@ -46,7 +48,7 @@ class GUI_EXPORT QgsGradientColorRampDialog : public QDialog, private Ui::QgsGra
|
||||
void on_btnInformation_pressed();
|
||||
|
||||
protected:
|
||||
QgsGradientColorRamp* mRamp;
|
||||
QgsGradientColorRamp mRamp;
|
||||
|
||||
private slots:
|
||||
|
||||
|
@ -21,19 +21,19 @@
|
||||
#include <QColorDialog>
|
||||
|
||||
|
||||
QgsLimitedRandomColorRampDialog::QgsLimitedRandomColorRampDialog( QgsLimitedRandomColorRamp* ramp, QWidget* parent )
|
||||
QgsLimitedRandomColorRampDialog::QgsLimitedRandomColorRampDialog( const QgsLimitedRandomColorRamp& ramp, QWidget* parent )
|
||||
: QDialog( parent )
|
||||
, mRamp( ramp )
|
||||
{
|
||||
setupUi( this );
|
||||
|
||||
spinCount->setValue( ramp->count() );
|
||||
spinHue1->setValue( ramp->hueMin() );
|
||||
spinHue2->setValue( ramp->hueMax() );
|
||||
spinSat1->setValue( ramp->satMin() );
|
||||
spinSat2->setValue( ramp->satMax() );
|
||||
spinVal1->setValue( ramp->valMin() );
|
||||
spinVal2->setValue( ramp->valMax() );
|
||||
spinCount->setValue( mRamp.count() );
|
||||
spinHue1->setValue( mRamp.hueMin() );
|
||||
spinHue2->setValue( mRamp.hueMax() );
|
||||
spinSat1->setValue( mRamp.satMin() );
|
||||
spinSat2->setValue( mRamp.satMax() );
|
||||
spinVal1->setValue( mRamp.valMin() );
|
||||
spinVal2->setValue( mRamp.valMax() );
|
||||
|
||||
connect( spinCount, SIGNAL( valueChanged( int ) ), this, SLOT( setCount( int ) ) );
|
||||
connect( spinHue1, SIGNAL( valueChanged( int ) ), this, SLOT( setHue1( int ) ) );
|
||||
@ -48,50 +48,50 @@ QgsLimitedRandomColorRampDialog::QgsLimitedRandomColorRampDialog( QgsLimitedRand
|
||||
|
||||
void QgsLimitedRandomColorRampDialog::updatePreview()
|
||||
{
|
||||
mRamp->updateColors();
|
||||
mRamp.updateColors();
|
||||
|
||||
QSize size( 300, 40 );
|
||||
lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( mRamp, size ) );
|
||||
lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size ) );
|
||||
}
|
||||
|
||||
void QgsLimitedRandomColorRampDialog::setCount( int val )
|
||||
{
|
||||
mRamp->setCount( val );
|
||||
mRamp.setCount( val );
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
void QgsLimitedRandomColorRampDialog::setHue1( int val )
|
||||
{
|
||||
mRamp->setHueMin( val );
|
||||
mRamp.setHueMin( val );
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
void QgsLimitedRandomColorRampDialog::setHue2( int val )
|
||||
{
|
||||
mRamp->setHueMax( val );
|
||||
mRamp.setHueMax( val );
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
void QgsLimitedRandomColorRampDialog::setSat1( int val )
|
||||
{
|
||||
mRamp->setSatMin( val );
|
||||
mRamp.setSatMin( val );
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
void QgsLimitedRandomColorRampDialog::setSat2( int val )
|
||||
{
|
||||
mRamp->setSatMax( val );
|
||||
mRamp.setSatMax( val );
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
void QgsLimitedRandomColorRampDialog::setVal1( int val )
|
||||
{
|
||||
mRamp->setValMin( val );
|
||||
mRamp.setValMin( val );
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
void QgsLimitedRandomColorRampDialog::setVal2( int val )
|
||||
{
|
||||
mRamp->setValMax( val );
|
||||
mRamp.setValMax( val );
|
||||
updatePreview();
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
#define QGsLIMITEDRANDOMCOLORRAMPDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "qgscolorramp.h"
|
||||
#include "ui_qgslimitedrandomcolorrampdialogbase.h"
|
||||
|
||||
class QgsLimitedRandomColorRamp;
|
||||
@ -30,7 +30,9 @@ class GUI_EXPORT QgsLimitedRandomColorRampDialog : public QDialog, private Ui::Q
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QgsLimitedRandomColorRampDialog( QgsLimitedRandomColorRamp* ramp, QWidget* parent = nullptr );
|
||||
QgsLimitedRandomColorRampDialog( const QgsLimitedRandomColorRamp& ramp, QWidget* parent = nullptr );
|
||||
|
||||
QgsLimitedRandomColorRamp ramp() const { return mRamp; }
|
||||
|
||||
public slots:
|
||||
void setCount( int val );
|
||||
@ -45,7 +47,7 @@ class GUI_EXPORT QgsLimitedRandomColorRampDialog : public QDialog, private Ui::Q
|
||||
|
||||
void updatePreview();
|
||||
|
||||
QgsLimitedRandomColorRamp* mRamp;
|
||||
QgsLimitedRandomColorRamp mRamp;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -515,7 +515,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexC
|
||||
QSettings settings;
|
||||
settings.setValue( "/Raster/defaultPalette", mColorRampComboBox->currentText() );
|
||||
|
||||
QgsColorRamp* ramp = mColorRampComboBox->currentColorRamp();
|
||||
QScopedPointer< QgsColorRamp > ramp( mColorRampComboBox->currentColorRamp() );
|
||||
if ( !ramp )
|
||||
return;
|
||||
|
||||
|
@ -764,8 +764,9 @@ void QgsCategorizedSymbolRendererWidget::addCategories()
|
||||
r->setScaleMethod( mRenderer->scaleMethod() );
|
||||
r->setSizeScaleField( mRenderer->sizeScaleField() );
|
||||
r->setInvertedColorRamp( cbxInvertedColorRamp->isChecked() );
|
||||
QgsColorRamp* ramp = getColorRamp();
|
||||
if ( ramp ) r->setSourceColorRamp( ramp->clone() );
|
||||
QScopedPointer< QgsColorRamp > ramp( getColorRamp() );
|
||||
if ( ramp )
|
||||
r->setSourceColorRamp( ramp->clone() );
|
||||
|
||||
if ( mModel )
|
||||
{
|
||||
@ -773,8 +774,8 @@ void QgsCategorizedSymbolRendererWidget::addCategories()
|
||||
}
|
||||
delete mRenderer;
|
||||
mRenderer = r;
|
||||
if ( ! keepExistingColors && ramp ) applyColorRamp();
|
||||
delete ramp;
|
||||
if ( ! keepExistingColors && ramp )
|
||||
applyColorRamp();
|
||||
emit widgetChanged();
|
||||
}
|
||||
|
||||
|
@ -51,15 +51,14 @@ void QgsColorRampComboBox::populate( QgsStyle* style )
|
||||
QStringList rampNames = mStyle->colorRampNames();
|
||||
for ( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it )
|
||||
{
|
||||
QgsColorRamp* ramp = style->colorRamp( *it );
|
||||
QScopedPointer< QgsColorRamp > ramp( style->colorRamp( *it ) );
|
||||
|
||||
if ( !mShowGradientOnly || ramp->type() == "gradient" )
|
||||
{
|
||||
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp, rampIconSize );
|
||||
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), rampIconSize );
|
||||
|
||||
addItem( icon, *it );
|
||||
}
|
||||
delete ramp;
|
||||
}
|
||||
|
||||
if ( !mShowGradientOnly )
|
||||
@ -68,7 +67,7 @@ void QgsColorRampComboBox::populate( QgsStyle* style )
|
||||
connect( this, SIGNAL( activated( int ) ), SLOT( colorRampChanged( int ) ) );
|
||||
}
|
||||
|
||||
QgsColorRamp* QgsColorRampComboBox::currentColorRamp()
|
||||
QgsColorRamp* QgsColorRampComboBox::currentColorRamp() const
|
||||
{
|
||||
QString rampName = currentText();
|
||||
|
||||
@ -120,15 +119,13 @@ void QgsColorRampComboBox::colorRampChanged( int index )
|
||||
return;
|
||||
|
||||
// put newly added ramp into the combo
|
||||
QgsColorRamp* ramp = mStyle->colorRamp( rampName );
|
||||
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp, rampIconSize );
|
||||
QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( rampName ) );
|
||||
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), rampIconSize );
|
||||
|
||||
blockSignals( true ); // avoid calling this method again!
|
||||
insertItem( index, icon, rampName );
|
||||
blockSignals( false );
|
||||
|
||||
delete ramp;
|
||||
|
||||
// ... and set it as active
|
||||
setCurrentIndex( index );
|
||||
|
||||
@ -138,49 +135,54 @@ void QgsColorRampComboBox::colorRampChanged( int index )
|
||||
|
||||
void QgsColorRampComboBox::editSourceRamp()
|
||||
{
|
||||
QgsColorRamp* currentRamp = currentColorRamp();
|
||||
QScopedPointer< QgsColorRamp > currentRamp( currentColorRamp() );
|
||||
if ( !currentRamp )
|
||||
return;
|
||||
|
||||
QScopedPointer<QgsColorRamp> newRamp( currentRamp->clone() );
|
||||
|
||||
if ( newRamp->type() == "gradient" )
|
||||
if ( currentRamp->type() == "gradient" )
|
||||
{
|
||||
QgsGradientColorRamp* gradRamp = static_cast<QgsGradientColorRamp*>( newRamp.data() );
|
||||
QgsGradientColorRampDialog dlg( gradRamp, this );
|
||||
if ( dlg.exec() && gradRamp )
|
||||
{
|
||||
setSourceColorRamp( gradRamp );
|
||||
emit sourceRampEdited();
|
||||
}
|
||||
}
|
||||
else if ( newRamp->type() == "random" )
|
||||
{
|
||||
QgsLimitedRandomColorRamp* randRamp = static_cast<QgsLimitedRandomColorRamp*>( newRamp.data() );
|
||||
QgsLimitedRandomColorRampDialog dlg( randRamp, this );
|
||||
QgsGradientColorRamp* gradRamp = static_cast<QgsGradientColorRamp*>( currentRamp.data() );
|
||||
QgsGradientColorRampDialog dlg( *gradRamp, this );
|
||||
if ( dlg.exec() )
|
||||
{
|
||||
setSourceColorRamp( randRamp );
|
||||
setSourceColorRamp( dlg.ramp().clone() );
|
||||
emit sourceRampEdited();
|
||||
}
|
||||
}
|
||||
else if ( newRamp->type() == "colorbrewer" )
|
||||
else if ( currentRamp->type() == "random" )
|
||||
{
|
||||
QgsColorBrewerColorRamp* brewerRamp = static_cast<QgsColorBrewerColorRamp*>( newRamp.data() );
|
||||
QgsColorBrewerColorRampDialog dlg( brewerRamp, this );
|
||||
QgsLimitedRandomColorRamp* randRamp = static_cast<QgsLimitedRandomColorRamp*>( currentRamp.data() );
|
||||
QgsLimitedRandomColorRampDialog dlg( *randRamp, this );
|
||||
if ( dlg.exec() )
|
||||
{
|
||||
setSourceColorRamp( brewerRamp );
|
||||
setSourceColorRamp( dlg.ramp().clone() );
|
||||
emit sourceRampEdited();
|
||||
}
|
||||
}
|
||||
else if ( newRamp->type() == "cpt-city" )
|
||||
else if ( currentRamp->type() == "colorbrewer" )
|
||||
{
|
||||
QgsCptCityColorRamp* cptCityRamp = static_cast<QgsCptCityColorRamp*>( newRamp.data() );
|
||||
QgsCptCityColorRampDialog dlg( cptCityRamp, this );
|
||||
if ( dlg.exec() && cptCityRamp )
|
||||
QgsColorBrewerColorRamp* brewerRamp = static_cast<QgsColorBrewerColorRamp*>( currentRamp.data() );
|
||||
QgsColorBrewerColorRampDialog dlg( *brewerRamp, this );
|
||||
if ( dlg.exec() )
|
||||
{
|
||||
setSourceColorRamp( cptCityRamp );
|
||||
setSourceColorRamp( dlg.ramp().clone() );
|
||||
emit sourceRampEdited();
|
||||
}
|
||||
}
|
||||
else if ( currentRamp->type() == "cpt-city" )
|
||||
{
|
||||
QgsCptCityColorRamp* cptCityRamp = static_cast<QgsCptCityColorRamp*>( currentRamp.data() );
|
||||
QgsCptCityColorRampDialog dlg( *cptCityRamp, this );
|
||||
if ( dlg.exec() )
|
||||
{
|
||||
if ( dlg.saveAsGradientRamp() )
|
||||
{
|
||||
setSourceColorRamp( dlg.ramp().cloneGradientRamp() );
|
||||
}
|
||||
else
|
||||
{
|
||||
setSourceColorRamp( dlg.ramp().clone() );
|
||||
}
|
||||
emit sourceRampEdited();
|
||||
}
|
||||
}
|
||||
|
@ -34,11 +34,18 @@ class GUI_EXPORT QgsColorRampComboBox : public QComboBox
|
||||
//! initialize the combo box with color ramps from the style
|
||||
void populate( QgsStyle* style );
|
||||
|
||||
//! add/select color ramp which was used previously by the renderer
|
||||
/** Adds or selects the current color ramp to show in the combo box. The ramp appears
|
||||
* in the combo box as the "source" ramp.
|
||||
* @param sourceRamp color ramp, ownership is transferred.
|
||||
* @see currentColorRamp()
|
||||
*/
|
||||
void setSourceColorRamp( QgsColorRamp* sourceRamp );
|
||||
|
||||
//! return new instance of the current color ramp or NULL if there is no active color ramp
|
||||
QgsColorRamp* currentColorRamp();
|
||||
/** Returns a new instance of the current color ramp or NULL if there is no active color ramp.
|
||||
* The caller takes responsibility for deleting the returned value.
|
||||
* @see setSourceColorRamp()
|
||||
*/
|
||||
QgsColorRamp* currentColorRamp() const;
|
||||
|
||||
/** Returns true if the current selection in the combo box is the option for creating
|
||||
* a new color ramp
|
||||
|
@ -36,9 +36,9 @@
|
||||
// - fix crash on Diverging?
|
||||
|
||||
|
||||
QgsCptCityColorRampDialog::QgsCptCityColorRampDialog( QgsCptCityColorRamp* ramp, QWidget* parent )
|
||||
QgsCptCityColorRampDialog::QgsCptCityColorRampDialog( const QgsCptCityColorRamp& ramp, QWidget* parent )
|
||||
: QDialog( parent )
|
||||
, mRamp( nullptr )
|
||||
, mRamp( ramp )
|
||||
, mArchiveViewType( QgsCptCityBrowserModel::Selections )
|
||||
{
|
||||
setupUi( this );
|
||||
@ -90,16 +90,7 @@ QgsCptCityColorRampDialog::QgsCptCityColorRampDialog( QgsCptCityColorRamp* ramp,
|
||||
return;
|
||||
QgsDebugMsg( "archive: " + mArchive->archiveName() );
|
||||
|
||||
if ( ramp )
|
||||
{
|
||||
mRamp = ramp;
|
||||
}
|
||||
else
|
||||
{
|
||||
mRamp = new QgsCptCityColorRamp( "", "", false );
|
||||
ramp = mRamp;
|
||||
}
|
||||
QgsDebugMsg( QString( "ramp name= %1 variant= %2 - %3 variants" ).arg( ramp->schemeName(), ramp->variantName() ).arg( ramp->variantList().count() ) );
|
||||
QgsDebugMsg( QString( "ramp name= %1 variant= %2 - %3 variants" ).arg( mRamp.schemeName(), mRamp.variantName() ).arg( mRamp.variantList().count() ) );
|
||||
|
||||
// model / view
|
||||
QgsDebugMsg( "loading model/view objects" );
|
||||
@ -123,8 +114,8 @@ QgsCptCityColorRampDialog::QgsCptCityColorRampDialog( QgsCptCityColorRamp* ramp,
|
||||
lblPreview->installEventFilter( this ); // mouse click on preview label shows svg render
|
||||
|
||||
// look for item, if not found in selections archive, look for in authors
|
||||
QgsDebugMsg( "looking for ramp " + mRamp->schemeName() );
|
||||
if ( mRamp->schemeName() != "" )
|
||||
QgsDebugMsg( "looking for ramp " + mRamp.schemeName() );
|
||||
if ( mRamp.schemeName() != "" )
|
||||
{
|
||||
bool found = updateRamp();
|
||||
if ( ! found )
|
||||
@ -159,9 +150,9 @@ QgsCptCityColorRampDialog::~QgsCptCityColorRampDialog()
|
||||
|
||||
void QgsCptCityColorRampDialog::populateVariants()
|
||||
{
|
||||
QStringList variantList = mRamp->variantList();
|
||||
QStringList variantList = mRamp.variantList();
|
||||
|
||||
QgsDebugMsg( QString( "ramp %1%2 has %3 variants" ).arg( mRamp->schemeName(), mRamp->variantName() ).arg( variantList.count() ) );
|
||||
QgsDebugMsg( QString( "ramp %1%2 has %3 variants" ).arg( mRamp.schemeName(), mRamp.variantName() ).arg( variantList.count() ) );
|
||||
|
||||
cboVariantName->blockSignals( true );
|
||||
cboVariantName->clear();
|
||||
@ -176,7 +167,7 @@ void QgsCptCityColorRampDialog::populateVariants()
|
||||
{
|
||||
// populate variant combobox
|
||||
QString oldVariant = cboVariantName->currentText();
|
||||
QgsCptCityColorRamp ramp( mRamp->schemeName(), mRamp->variantList(), QString() );
|
||||
QgsCptCityColorRamp ramp( mRamp.schemeName(), mRamp.variantList(), QString() );
|
||||
QPixmap blankPixmap( cboVariantName->iconSize() );
|
||||
blankPixmap.fill( Qt::white );
|
||||
QIcon blankIcon( blankPixmap );
|
||||
@ -204,8 +195,8 @@ void QgsCptCityColorRampDialog::populateVariants()
|
||||
|
||||
// try to set the original variant again (if exists)
|
||||
int idx = -1;
|
||||
QString newVariant = mRamp->variantName();
|
||||
QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp->variantName() ).arg( mRamp->variantList().count() ) );
|
||||
QString newVariant = mRamp.variantName();
|
||||
QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp.variantName() ).arg( mRamp.variantList().count() ) );
|
||||
if ( newVariant != QString() )
|
||||
{
|
||||
if ( newVariant.startsWith( '-' ) || newVariant.startsWith( '_' ) )
|
||||
@ -252,8 +243,8 @@ void QgsCptCityColorRampDialog::updateTreeView( QgsCptCityDataItem *item, bool r
|
||||
{
|
||||
if ( resetRamp )
|
||||
{
|
||||
mRamp->setName( "", "" );
|
||||
QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp->variantName() ).arg( mRamp->variantList().count() ) );
|
||||
mRamp.setName( "", "" );
|
||||
QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp.variantName() ).arg( mRamp.variantList().count() ) );
|
||||
lblSchemeName->setText( "" );
|
||||
populateVariants();
|
||||
}
|
||||
@ -289,8 +280,8 @@ void QgsCptCityColorRampDialog::on_mListWidget_itemClicked( QListWidgetItem * it
|
||||
{
|
||||
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
|
||||
lblSchemeName->setText( QFileInfo( rampItem->name() ).fileName() );
|
||||
mRamp->copy( &rampItem->ramp() );
|
||||
QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp->variantName() ).arg( mRamp->variantList().count() ) );
|
||||
mRamp.copy( &rampItem->ramp() );
|
||||
QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp.variantName() ).arg( mRamp.variantList().count() ) );
|
||||
populateVariants();
|
||||
}
|
||||
else
|
||||
@ -303,7 +294,7 @@ void QgsCptCityColorRampDialog::on_mListWidget_itemSelectionChanged()
|
||||
{
|
||||
if ( mListWidget->selectedItems().isEmpty() )
|
||||
{
|
||||
mRamp->setName( "", "" );
|
||||
mRamp.setName( "", "" );
|
||||
}
|
||||
}
|
||||
|
||||
@ -406,7 +397,7 @@ void QgsCptCityColorRampDialog::updatePreview( bool clear )
|
||||
{
|
||||
QSize size = lblPreview->size();
|
||||
|
||||
if ( clear || mRamp->schemeName() == "" )
|
||||
if ( clear || mRamp.schemeName() == "" )
|
||||
{
|
||||
lblSchemeName->setText( "" );
|
||||
lblSchemePath->setText( "" );
|
||||
@ -417,18 +408,18 @@ void QgsCptCityColorRampDialog::updatePreview( bool clear )
|
||||
return;
|
||||
}
|
||||
|
||||
mRamp->loadFile();
|
||||
mRamp.loadFile();
|
||||
|
||||
lblSchemePath->setText( mRamp->schemeName() + mRamp->variantName() );
|
||||
lblSchemePath->setText( mRamp.schemeName() + mRamp.variantName() );
|
||||
|
||||
// update pixmap
|
||||
// TODO draw checker-board/transparent background
|
||||
// for transparent, add [ pixmap.fill( Qt::transparent ); ] to QgsSymbolLayerUtils::colorRampPreviewPixmap
|
||||
QPixmap pixmap = QgsSymbolLayerUtils::colorRampPreviewPixmap( mRamp, size );
|
||||
QPixmap pixmap = QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size );
|
||||
lblPreview->setPixmap( pixmap );
|
||||
|
||||
// add copyright information from COPYING.xml file
|
||||
updateCopyingInfo( mRamp->copyingInfo() );
|
||||
updateCopyingInfo( mRamp.copyingInfo() );
|
||||
}
|
||||
|
||||
void QgsCptCityColorRampDialog::clearCopyingInfo()
|
||||
@ -465,8 +456,8 @@ void QgsCptCityColorRampDialog::on_cboVariantName_currentIndexChanged( int index
|
||||
{
|
||||
Q_UNUSED( index );
|
||||
if ( cboVariantName->currentIndex() != -1 )
|
||||
mRamp->setVariantName( cboVariantName->itemData( cboVariantName->currentIndex(), Qt::UserRole ).toString() );
|
||||
QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp->variantName() ).arg( mRamp->variantList().count() ) );
|
||||
mRamp.setVariantName( cboVariantName->itemData( cboVariantName->currentIndex(), Qt::UserRole ).toString() );
|
||||
QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp.variantName() ).arg( mRamp.variantList().count() ) );
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
@ -542,7 +533,7 @@ bool QgsCptCityColorRampDialog::eventFilter( QObject *obj, QEvent *event )
|
||||
if ( event->type() == QEvent::MouseButtonPress )
|
||||
{
|
||||
// create preview from svg file if supported - depends on file versions
|
||||
QPixmap pixmap( mRamp->fileName() );
|
||||
QPixmap pixmap( mRamp.fileName() );
|
||||
if ( ! pixmap.isNull() )
|
||||
lblPreview->setPixmap( pixmap.scaled( size ) );
|
||||
return true;
|
||||
@ -550,7 +541,7 @@ bool QgsCptCityColorRampDialog::eventFilter( QObject *obj, QEvent *event )
|
||||
else if ( event->type() == QEvent::MouseButtonRelease )
|
||||
{
|
||||
// restore preview
|
||||
QPixmap pixmap = QgsSymbolLayerUtils::colorRampPreviewPixmap( mRamp, size );
|
||||
QPixmap pixmap = QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size );
|
||||
lblPreview->setPixmap( pixmap );
|
||||
return true;
|
||||
}
|
||||
@ -572,15 +563,15 @@ bool QgsCptCityColorRampDialog::updateRamp()
|
||||
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
|
||||
updatePreview( true );
|
||||
|
||||
QgsDebugMsg( "schemeName= " + mRamp->schemeName() );
|
||||
if ( mRamp->schemeName() == "" )
|
||||
QgsDebugMsg( "schemeName= " + mRamp.schemeName() );
|
||||
if ( mRamp.schemeName() == "" )
|
||||
{
|
||||
showAll();
|
||||
return false;
|
||||
}
|
||||
|
||||
// search for item in model
|
||||
QModelIndex modelIndex = mModel->findPath( mRamp->schemeName() );
|
||||
QModelIndex modelIndex = mModel->findPath( mRamp.schemeName() );
|
||||
if ( modelIndex == QModelIndex() )
|
||||
{
|
||||
return false;
|
||||
@ -589,16 +580,16 @@ bool QgsCptCityColorRampDialog::updateRamp()
|
||||
dynamic_cast<QgsCptCityColorRampItem*>( mModel->dataItem( modelIndex ) );
|
||||
if ( ! childItem )
|
||||
return false;
|
||||
if ( mRamp->schemeName() != childItem->ramp().schemeName() )
|
||||
if ( mRamp.schemeName() != childItem->ramp().schemeName() )
|
||||
return false;
|
||||
|
||||
// found child, set mRamp variantList
|
||||
// mRamp->copy( &childItem->ramp() );
|
||||
mRamp->setVariantList( childItem->ramp().variantList() );
|
||||
// mRamp.copy( &childItem->ramp() );
|
||||
mRamp.setVariantList( childItem->ramp().variantList() );
|
||||
|
||||
// found child, update tree
|
||||
QgsDebugMsg( QString( "found item %1" ).arg( mRamp->schemeName() ) );
|
||||
lblSchemeName->setText( QFileInfo( mRamp->schemeName() ).fileName() );
|
||||
QgsDebugMsg( QString( "found item %1" ).arg( mRamp.schemeName() ) );
|
||||
lblSchemeName->setText( QFileInfo( mRamp.schemeName() ).fileName() );
|
||||
QModelIndex parentIndex = modelIndex.parent();
|
||||
QModelIndex selIndex = mTreeFilter->mapFromSource( parentIndex );
|
||||
|
||||
|
@ -39,11 +39,13 @@ class GUI_EXPORT QgsCptCityColorRampDialog : public QDialog, private Ui::QgsCptC
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QgsCptCityColorRampDialog( QgsCptCityColorRamp* ramp, QWidget* parent = nullptr );
|
||||
QgsCptCityColorRampDialog( const QgsCptCityColorRamp& ramp, QWidget* parent = nullptr );
|
||||
~QgsCptCityColorRampDialog();
|
||||
|
||||
QgsCptCityColorRamp ramp() const { return mRamp; }
|
||||
|
||||
QString selectedName() const
|
||||
{ return mRamp ? QFileInfo( mRamp->schemeName() ).baseName() + mRamp->variantName() : QString(); }
|
||||
{ return QFileInfo( mRamp.schemeName() ).baseName() + mRamp.variantName(); }
|
||||
|
||||
bool saveAsGradientRamp() const;
|
||||
|
||||
@ -69,7 +71,7 @@ class GUI_EXPORT QgsCptCityColorRampDialog : public QDialog, private Ui::QgsCptC
|
||||
void updateListWidget( QgsCptCityDataItem *item );
|
||||
bool eventFilter( QObject *obj, QEvent *event ) override;
|
||||
|
||||
QgsCptCityColorRamp* mRamp;
|
||||
QgsCptCityColorRamp mRamp;
|
||||
QgsCptCityArchive* mArchive;
|
||||
QgsCptCityBrowserModel::ViewType mArchiveViewType;
|
||||
|
||||
|
@ -742,7 +742,7 @@ void QgsGraduatedSymbolRendererWidget::classifyGraduated()
|
||||
|
||||
int nclasses = spinGraduatedClasses->value();
|
||||
|
||||
QSharedPointer<QgsColorRamp> ramp( cboGraduatedColorRamp->currentColorRamp() );
|
||||
QScopedPointer<QgsColorRamp> ramp( cboGraduatedColorRamp->currentColorRamp() );
|
||||
if ( !ramp )
|
||||
{
|
||||
if ( cboGraduatedColorRamp->count() == 0 )
|
||||
@ -779,8 +779,6 @@ void QgsGraduatedSymbolRendererWidget::classifyGraduated()
|
||||
|
||||
if ( methodComboBox->currentIndex() == 0 )
|
||||
{
|
||||
QgsColorRamp* ramp = cboGraduatedColorRamp->currentColorRamp();
|
||||
|
||||
if ( !ramp )
|
||||
{
|
||||
if ( cboGraduatedColorRamp->count() == 0 )
|
||||
@ -789,7 +787,7 @@ void QgsGraduatedSymbolRendererWidget::classifyGraduated()
|
||||
QMessageBox::critical( this, tr( "Error" ), tr( "The selected color ramp is not available." ) );
|
||||
return;
|
||||
}
|
||||
mRenderer->setSourceColorRamp( ramp );
|
||||
mRenderer->setSourceColorRamp( ramp.take() );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -811,11 +809,11 @@ void QgsGraduatedSymbolRendererWidget::classifyGraduated()
|
||||
|
||||
void QgsGraduatedSymbolRendererWidget::reapplyColorRamp()
|
||||
{
|
||||
QgsColorRamp* ramp = cboGraduatedColorRamp->currentColorRamp();
|
||||
QScopedPointer< QgsColorRamp > ramp( cboGraduatedColorRamp->currentColorRamp() );
|
||||
if ( !ramp )
|
||||
return;
|
||||
|
||||
mRenderer->updateColorRamp( ramp, cbxInvertedColorRamp->isChecked() );
|
||||
mRenderer->updateColorRamp( ramp.take(), cbxInvertedColorRamp->isChecked() );
|
||||
mRenderer->updateSymbols( mGraduatedSymbol );
|
||||
refreshSymbolView();
|
||||
}
|
||||
|
@ -203,13 +203,12 @@ bool QgsStyleExportImportDialog::populateStyles( QgsStyle* style )
|
||||
for ( int i = 0; i < styleNames.count(); ++i )
|
||||
{
|
||||
name = styleNames[i];
|
||||
QgsColorRamp* ramp = style->colorRamp( name );
|
||||
QScopedPointer< QgsColorRamp > ramp( style->colorRamp( name ) );
|
||||
|
||||
QStandardItem* item = new QStandardItem( name );
|
||||
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp, listItems->iconSize() );
|
||||
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), listItems->iconSize() );
|
||||
item->setIcon( icon );
|
||||
model->appendRow( item );
|
||||
delete ramp;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -292,16 +292,15 @@ void QgsStyleManagerDialog::populateColorRamps( const QStringList& colorRamps, b
|
||||
for ( int i = 0; i < colorRamps.count(); ++i )
|
||||
{
|
||||
QString name = colorRamps[i];
|
||||
QgsColorRamp* ramp = mStyle->colorRamp( name );
|
||||
QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
|
||||
|
||||
QStandardItem* item = new QStandardItem( name );
|
||||
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp, listItems->iconSize() );
|
||||
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), listItems->iconSize() );
|
||||
item->setIcon( icon );
|
||||
item->setData( name ); // used to find out original name when user edited the name
|
||||
item->setCheckable( check );
|
||||
item->setToolTip( name );
|
||||
model->appendRow( item );
|
||||
delete ramp;
|
||||
}
|
||||
selectedSymbolsChanged( QItemSelection(), QItemSelection() );
|
||||
symbolSelected( listItems->currentIndex() );
|
||||
@ -454,62 +453,53 @@ QString QgsStyleManagerDialog::addColorRampStatic( QWidget* parent, QgsStyle* st
|
||||
|
||||
QString name = tr( "new ramp" );
|
||||
|
||||
QgsColorRamp *ramp = nullptr;
|
||||
QScopedPointer< QgsColorRamp > ramp;
|
||||
if ( rampType == tr( "Gradient" ) )
|
||||
{
|
||||
QgsGradientColorRamp* gradRamp = new QgsGradientColorRamp();
|
||||
QgsGradientColorRampDialog dlg( gradRamp, parent );
|
||||
QgsGradientColorRampDialog dlg( QgsGradientColorRamp(), parent );
|
||||
if ( !dlg.exec() )
|
||||
{
|
||||
delete gradRamp;
|
||||
return QString();
|
||||
}
|
||||
ramp = gradRamp;
|
||||
ramp.reset( dlg.ramp().clone() );
|
||||
name = tr( "new gradient ramp" );
|
||||
}
|
||||
else if ( rampType == tr( "Random" ) )
|
||||
{
|
||||
QgsLimitedRandomColorRamp* randRamp = new QgsLimitedRandomColorRamp();
|
||||
QgsLimitedRandomColorRampDialog dlg( randRamp, parent );
|
||||
QgsLimitedRandomColorRampDialog dlg( QgsLimitedRandomColorRamp(), parent );
|
||||
if ( !dlg.exec() )
|
||||
{
|
||||
delete randRamp;
|
||||
return QString();
|
||||
}
|
||||
ramp = randRamp;
|
||||
ramp.reset( dlg.ramp().clone() );
|
||||
name = tr( "new random ramp" );
|
||||
}
|
||||
else if ( rampType == tr( "ColorBrewer" ) )
|
||||
{
|
||||
QgsColorBrewerColorRamp* brewerRamp = new QgsColorBrewerColorRamp();
|
||||
QgsColorBrewerColorRampDialog dlg( brewerRamp, parent );
|
||||
QgsColorBrewerColorRampDialog dlg( QgsColorBrewerColorRamp(), parent );
|
||||
if ( !dlg.exec() )
|
||||
{
|
||||
delete brewerRamp;
|
||||
return QString();
|
||||
}
|
||||
ramp = brewerRamp;
|
||||
name = brewerRamp->schemeName() + QString::number( brewerRamp->colors() );
|
||||
ramp.reset( dlg.ramp().clone() );
|
||||
name = dlg.ramp().schemeName() + QString::number( dlg.ramp().colors() );
|
||||
}
|
||||
else if ( rampType == tr( "cpt-city" ) )
|
||||
{
|
||||
QgsCptCityColorRamp* cptCityRamp = new QgsCptCityColorRamp( "", "" );
|
||||
QgsCptCityColorRampDialog dlg( cptCityRamp, parent );
|
||||
QgsCptCityColorRampDialog dlg( QgsCptCityColorRamp( "", "" ), parent );
|
||||
if ( !dlg.exec() )
|
||||
{
|
||||
delete cptCityRamp;
|
||||
return QString();
|
||||
}
|
||||
// name = dlg.selectedName();
|
||||
name = QFileInfo( cptCityRamp->schemeName() ).baseName() + cptCityRamp->variantName();
|
||||
name = QFileInfo( dlg.ramp().schemeName() ).baseName() + dlg.ramp().variantName();
|
||||
if ( dlg.saveAsGradientRamp() )
|
||||
{
|
||||
ramp = cptCityRamp->cloneGradientRamp();
|
||||
delete cptCityRamp;
|
||||
ramp.reset( dlg.ramp().cloneGradientRamp() );
|
||||
}
|
||||
else
|
||||
{
|
||||
ramp = cptCityRamp;
|
||||
ramp.reset( dlg.ramp().clone() );
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -531,7 +521,6 @@ QString QgsStyleManagerDialog::addColorRampStatic( QWidget* parent, QgsStyle* st
|
||||
QLineEdit::Normal, name, &ok );
|
||||
if ( !ok )
|
||||
{
|
||||
delete ramp;
|
||||
return QString();
|
||||
}
|
||||
// validate name
|
||||
@ -559,7 +548,7 @@ QString QgsStyleManagerDialog::addColorRampStatic( QWidget* parent, QgsStyle* st
|
||||
}
|
||||
|
||||
// add new symbol to style and re-populate the list
|
||||
style->addColorRamp( name, ramp, true );
|
||||
style->addColorRamp( name, ramp.take(), true );
|
||||
// TODO groups and tags, using saveColorRamp
|
||||
return name;
|
||||
}
|
||||
@ -633,51 +622,53 @@ bool QgsStyleManagerDialog::editColorRamp()
|
||||
if ( name.isEmpty() )
|
||||
return false;
|
||||
|
||||
QgsColorRamp* ramp = mStyle->colorRamp( name );
|
||||
QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
|
||||
|
||||
if ( ramp->type() == "gradient" )
|
||||
{
|
||||
QgsGradientColorRamp* gradRamp = static_cast<QgsGradientColorRamp*>( ramp );
|
||||
QgsGradientColorRampDialog dlg( gradRamp, this );
|
||||
QgsGradientColorRamp* gradRamp = static_cast<QgsGradientColorRamp*>( ramp.data() );
|
||||
QgsGradientColorRampDialog dlg( *gradRamp, this );
|
||||
if ( !dlg.exec() )
|
||||
{
|
||||
delete ramp;
|
||||
return false;
|
||||
}
|
||||
ramp.reset( dlg.ramp().clone() );
|
||||
}
|
||||
else if ( ramp->type() == "random" )
|
||||
{
|
||||
QgsLimitedRandomColorRamp* randRamp = static_cast<QgsLimitedRandomColorRamp*>( ramp );
|
||||
QgsLimitedRandomColorRampDialog dlg( randRamp, this );
|
||||
QgsLimitedRandomColorRamp* randRamp = static_cast<QgsLimitedRandomColorRamp*>( ramp.data() );
|
||||
QgsLimitedRandomColorRampDialog dlg( *randRamp, this );
|
||||
if ( !dlg.exec() )
|
||||
{
|
||||
delete ramp;
|
||||
return false;
|
||||
}
|
||||
ramp.reset( dlg.ramp().clone() );
|
||||
}
|
||||
else if ( ramp->type() == "colorbrewer" )
|
||||
{
|
||||
QgsColorBrewerColorRamp* brewerRamp = static_cast<QgsColorBrewerColorRamp*>( ramp );
|
||||
QgsColorBrewerColorRampDialog dlg( brewerRamp, this );
|
||||
QgsColorBrewerColorRamp* brewerRamp = static_cast<QgsColorBrewerColorRamp*>( ramp.data() );
|
||||
QgsColorBrewerColorRampDialog dlg( *brewerRamp, this );
|
||||
if ( !dlg.exec() )
|
||||
{
|
||||
delete ramp;
|
||||
return false;
|
||||
}
|
||||
ramp.reset( dlg.ramp().clone() );
|
||||
}
|
||||
else if ( ramp->type() == "cpt-city" )
|
||||
{
|
||||
QgsCptCityColorRamp* cptCityRamp = static_cast<QgsCptCityColorRamp*>( ramp );
|
||||
QgsCptCityColorRampDialog dlg( cptCityRamp, this );
|
||||
QgsCptCityColorRamp* cptCityRamp = static_cast<QgsCptCityColorRamp*>( ramp.data() );
|
||||
QgsCptCityColorRampDialog dlg( *cptCityRamp, this );
|
||||
if ( !dlg.exec() )
|
||||
{
|
||||
delete ramp;
|
||||
return false;
|
||||
}
|
||||
if ( dlg.saveAsGradientRamp() )
|
||||
{
|
||||
ramp = cptCityRamp->cloneGradientRamp();
|
||||
delete cptCityRamp;
|
||||
ramp.reset( dlg.ramp().cloneGradientRamp() );
|
||||
}
|
||||
else
|
||||
{
|
||||
ramp.reset( dlg.ramp().clone() );
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -685,7 +676,7 @@ bool QgsStyleManagerDialog::editColorRamp()
|
||||
Q_ASSERT( 0 && "invalid ramp type" );
|
||||
}
|
||||
|
||||
mStyle->addColorRamp( name, ramp, true );
|
||||
mStyle->addColorRamp( name, ramp.take(), true );
|
||||
mModified = true;
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user