Skip to content
Permalink
Browse files

[FEATURE] Make color brewer and limited random ramp editors show

inline in style panel
  • Loading branch information
nyalldawson committed Aug 24, 2016
1 parent 1d98b10 commit b225a82b3e425a93ab114c8c828d1ea9903b4682
@@ -1,3 +1,40 @@
/** \ingroup gui
* \class QgsColorBrewerColorRampDialog
* A widget which allows users to modify the properties of a QgsColorBrewerColorRamp.
* \note added in QGIS 3.0
*/

class QgsColorBrewerColorRampWidget : QgsPanelWidget
{
%TypeHeaderCode
#include <qgscolorbrewercolorrampdialog.h>
%End

public:

/** Constructor for QgsColorBrewerColorRampDialog.
* @param ramp initial ramp to show in dialog
* @param parent parent widget
*/
QgsColorBrewerColorRampWidget( const QgsColorBrewerColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );

/** Returns a color ramp representing the current settings from the dialog.
* @see setRamp()
*/
QgsColorBrewerColorRamp ramp() const;

/** Sets the color ramp to show in the dialog.
* @param ramp color ramp
* @see ramp()
*/
void setRamp( const QgsColorBrewerColorRamp& ramp );

signals:

//! Emitted when the dialog settings change
void changed();
};

/** \ingroup gui
* \class QgsColorBrewerColorRampDialog
* A dialog which allows users to modify the properties of a QgsColorBrewerColorRamp.
@@ -1,22 +1,22 @@
/** \ingroup gui
* \class QgsLimitedRandomColorRampDialog
* A dialog which allows users to modify the properties of a QgsLimitedRandomColorRamp.
* \class QgsLimitedRandomColorRampWidget
* A widget which allows users to modify the properties of a QgsLimitedRandomColorRamp.
* \note added in QGIS 3.0
*/

class QgsLimitedRandomColorRampDialog : QDialog
class QgsLimitedRandomColorRampWidget : QgsPanelWidget
{
%TypeHeaderCode
#include <qgslimitedrandomcolorrampdialog.h>
%End

public:

/** Constructor for QgsLimitedRandomColorRampDialog.
/** Constructor for QgsLimitedRandomColorRampWidget.
* @param ramp initial ramp to show in dialog
* @param parent parent widget
*/
QgsLimitedRandomColorRampDialog( const QgsLimitedRandomColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );
QgsLimitedRandomColorRampWidget( const QgsLimitedRandomColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );

/** Returns a color ramp representing the current settings from the dialog.
* @see setRamp()
@@ -51,3 +51,41 @@ class QgsLimitedRandomColorRampDialog : QDialog
//! Sets the maximum value for colors in the ramp
void setVal2( int val );
};

/** \ingroup gui
* \class QgsLimitedRandomColorRampDialog
* A dialog which allows users to modify the properties of a QgsLimitedRandomColorRamp.
* \note added in QGIS 3.0
*/

class QgsLimitedRandomColorRampDialog : QDialog
{
%TypeHeaderCode
#include <qgslimitedrandomcolorrampdialog.h>
%End

public:

/** Constructor for QgsLimitedRandomColorRampDialog.
* @param ramp initial ramp to show in dialog
* @param parent parent widget
*/
QgsLimitedRandomColorRampDialog( const QgsLimitedRandomColorRamp& ramp, QWidget* parent /TransferThis/ = nullptr );

/** Returns a color ramp representing the current settings from the dialog.
* @see setRamp()
*/
QgsLimitedRandomColorRamp ramp() const;

/** Sets the color ramp to show in the dialog.
* @param ramp color ramp
* @see ramp()
*/
void setRamp( const QgsLimitedRandomColorRamp& ramp );

signals:

//! Emitted when the dialog settings change
void changed();

};
@@ -18,6 +18,7 @@
#include "qgscolorramp.h"
#include "qgssymbollayerutils.h"
#include <QAbstractButton>
#include <QDialogButtonBox>

#if 0 // unused
static void updateColorButton( QAbstractButton* button, QColor color )
@@ -31,8 +32,8 @@ static void updateColorButton( QAbstractButton* button, QColor color )
/////////


QgsColorBrewerColorRampDialog::QgsColorBrewerColorRampDialog( const QgsColorBrewerColorRamp& ramp, QWidget* parent )
: QDialog( parent )
QgsColorBrewerColorRampWidget::QgsColorBrewerColorRampWidget( const QgsColorBrewerColorRamp& ramp, QWidget* parent )
: QgsPanelWidget( parent )
, mRamp( ramp )
{

@@ -56,14 +57,14 @@ QgsColorBrewerColorRampDialog::QgsColorBrewerColorRampDialog( const QgsColorBrew
connect( cboColors, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setColors() ) );
}

void QgsColorBrewerColorRampDialog::setRamp( const QgsColorBrewerColorRamp& ramp )
void QgsColorBrewerColorRampWidget::setRamp( const QgsColorBrewerColorRamp& ramp )
{
mRamp = ramp;
updateUi();
emit changed();
}

void QgsColorBrewerColorRampDialog::populateVariants()
void QgsColorBrewerColorRampWidget::populateVariants()
{
QString oldVariant = cboColors->currentText();

@@ -85,21 +86,21 @@ void QgsColorBrewerColorRampDialog::populateVariants()
cboColors->setCurrentIndex( idx );
}

void QgsColorBrewerColorRampDialog::updatePreview()
void QgsColorBrewerColorRampWidget::updatePreview()
{
QSize size( 300, 40 );
lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size ) );
}

void QgsColorBrewerColorRampDialog::updateUi()
void QgsColorBrewerColorRampWidget::updateUi()
{
whileBlocking( cboSchemeName )->setCurrentIndex( cboSchemeName->findText( mRamp.schemeName() ) );
populateVariants();
whileBlocking( cboColors )->setCurrentIndex( cboColors->findText( QString::number( mRamp.colors() ) ) );
updatePreview();
}

void QgsColorBrewerColorRampDialog::setSchemeName()
void QgsColorBrewerColorRampWidget::setSchemeName()
{
// populate list of variants
populateVariants();
@@ -109,10 +110,24 @@ void QgsColorBrewerColorRampDialog::setSchemeName()
emit changed();
}

void QgsColorBrewerColorRampDialog::setColors()
void QgsColorBrewerColorRampWidget::setColors()
{
int num = cboColors->currentText().toInt();
mRamp.setColors( num );
updatePreview();
emit changed();
}

QgsColorBrewerColorRampDialog::QgsColorBrewerColorRampDialog( const QgsColorBrewerColorRamp& ramp, QWidget* parent )
: QDialog( parent )
{
QVBoxLayout* vLayout = new QVBoxLayout();
mWidget = new QgsColorBrewerColorRampWidget( ramp );
vLayout->addWidget( mWidget );
QDialogButtonBox* bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
connect( bbox, SIGNAL( accepted() ), this, SLOT( accept() ) );
connect( bbox, SIGNAL( rejected() ), this, SLOT( reject() ) );
vLayout->addWidget( bbox );
setLayout( vLayout );
connect( mWidget, SIGNAL( changed() ), this, SIGNAL( changed() ) );
}
@@ -17,29 +17,29 @@
#define QGSCOLORBREWERCOLORRAMPDIALOG_H

#include <QDialog>

#include "qgspanelwidget.h"
#include "qgscolorramp.h"
#include "ui_qgscolorbrewercolorrampdialogbase.h"
#include "ui_qgscolorbrewercolorrampwidgetbase.h"

class QgsColorBrewerColorRamp;

/** \ingroup gui
* \class QgsColorBrewerColorRampDialog
* A dialog which allows users to modify the properties of a QgsColorBrewerColorRamp.
* \class QgsColorBrewerColorRampWidget
* A widget which allows users to modify the properties of a QgsColorBrewerColorRamp.
* \note added in QGIS 3.0
*/
class GUI_EXPORT QgsColorBrewerColorRampDialog : public QDialog, private Ui::QgsColorBrewerColorRampDialogBase
class GUI_EXPORT QgsColorBrewerColorRampWidget : public QgsPanelWidget, private Ui::QgsColorBrewerColorRampWidgetBase
{
Q_OBJECT
Q_PROPERTY( QgsColorBrewerColorRamp ramp READ ramp WRITE setRamp )

public:

/** Constructor for QgsColorBrewerColorRampDialog.
/** Constructor for QgsColorBrewerColorRampWidget.
* @param ramp initial ramp to show in dialog
* @param parent parent widget
*/
QgsColorBrewerColorRampDialog( const QgsColorBrewerColorRamp& ramp, QWidget* parent = nullptr );
QgsColorBrewerColorRampWidget( const QgsColorBrewerColorRamp& ramp, QWidget* parent = nullptr );

/** Returns a color ramp representing the current settings from the dialog.
* @see setRamp()
@@ -70,4 +70,44 @@ class GUI_EXPORT QgsColorBrewerColorRampDialog : public QDialog, private Ui::Qgs
QgsColorBrewerColorRamp mRamp;
};

/** \ingroup gui
* \class QgsColorBrewerColorRampDialog
* A dialog which allows users to modify the properties of a QgsColorBrewerColorRamp.
* \note added in QGIS 3.0
*/
class GUI_EXPORT QgsColorBrewerColorRampDialog : public QDialog
{
Q_OBJECT
Q_PROPERTY( QgsColorBrewerColorRamp ramp READ ramp WRITE setRamp )

public:

/** Constructor for QgsColorBrewerColorRampDialog.
* @param ramp initial ramp to show in dialog
* @param parent parent widget
*/
QgsColorBrewerColorRampDialog( const QgsColorBrewerColorRamp& ramp, QWidget* parent = nullptr );

/** Returns a color ramp representing the current settings from the dialog.
* @see setRamp()
*/
QgsColorBrewerColorRamp ramp() const { return mWidget->ramp(); }

/** Sets the color ramp to show in the dialog.
* @param ramp color ramp
* @see ramp()
*/
void setRamp( const QgsColorBrewerColorRamp& ramp ) { mWidget->setRamp( ramp ); }

signals:

//! Emitted when the dialog settings change
void changed();

private:

QgsColorBrewerColorRampWidget* mWidget;

};

#endif
@@ -19,10 +19,11 @@
#include "qgscolorramp.h"

#include <QColorDialog>
#include <QDialogButtonBox>


QgsLimitedRandomColorRampDialog::QgsLimitedRandomColorRampDialog( const QgsLimitedRandomColorRamp& ramp, QWidget* parent )
: QDialog( parent )
QgsLimitedRandomColorRampWidget::QgsLimitedRandomColorRampWidget( const QgsLimitedRandomColorRamp& ramp, QWidget* parent )
: QgsPanelWidget( parent )
, mRamp( ramp )
{
setupUi( this );
@@ -38,22 +39,22 @@ QgsLimitedRandomColorRampDialog::QgsLimitedRandomColorRampDialog( const QgsLimit
connect( spinVal2, SIGNAL( valueChanged( int ) ), this, SLOT( setVal2( int ) ) );
}

void QgsLimitedRandomColorRampDialog::setRamp( const QgsLimitedRandomColorRamp& ramp )
void QgsLimitedRandomColorRampWidget::setRamp( const QgsLimitedRandomColorRamp& ramp )
{
mRamp = ramp;
updateUi();
emit changed();
}

void QgsLimitedRandomColorRampDialog::updatePreview()
void QgsLimitedRandomColorRampWidget::updatePreview()
{
mRamp.updateColors();

QSize size( 300, 40 );
lblPreview->setPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( &mRamp, size ) );
}

void QgsLimitedRandomColorRampDialog::updateUi()
void QgsLimitedRandomColorRampWidget::updateUi()
{
spinCount->setValue( mRamp.count() );
spinHue1->setValue( mRamp.hueMin() );
@@ -65,51 +66,65 @@ void QgsLimitedRandomColorRampDialog::updateUi()
updatePreview();
}

void QgsLimitedRandomColorRampDialog::setCount( int val )
void QgsLimitedRandomColorRampWidget::setCount( int val )
{
mRamp.setCount( val );
updatePreview();
emit changed();
}

void QgsLimitedRandomColorRampDialog::setHue1( int val )
void QgsLimitedRandomColorRampWidget::setHue1( int val )
{
mRamp.setHueMin( val );
updatePreview();
emit changed();
}

void QgsLimitedRandomColorRampDialog::setHue2( int val )
void QgsLimitedRandomColorRampWidget::setHue2( int val )
{
mRamp.setHueMax( val );
updatePreview();
emit changed();
}

void QgsLimitedRandomColorRampDialog::setSat1( int val )
void QgsLimitedRandomColorRampWidget::setSat1( int val )
{
mRamp.setSatMin( val );
updatePreview();
emit changed();
}

void QgsLimitedRandomColorRampDialog::setSat2( int val )
void QgsLimitedRandomColorRampWidget::setSat2( int val )
{
mRamp.setSatMax( val );
updatePreview();
emit changed();
}

void QgsLimitedRandomColorRampDialog::setVal1( int val )
void QgsLimitedRandomColorRampWidget::setVal1( int val )
{
mRamp.setValMin( val );
updatePreview();
emit changed();
}

void QgsLimitedRandomColorRampDialog::setVal2( int val )
void QgsLimitedRandomColorRampWidget::setVal2( int val )
{
mRamp.setValMax( val );
updatePreview();
emit changed();
}

QgsLimitedRandomColorRampDialog::QgsLimitedRandomColorRampDialog( const QgsLimitedRandomColorRamp& ramp, QWidget* parent )
: QDialog( parent )
{
QVBoxLayout* vLayout = new QVBoxLayout();
mWidget = new QgsLimitedRandomColorRampWidget( ramp );
vLayout->addWidget( mWidget );
QDialogButtonBox* bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
connect( bbox, SIGNAL( accepted() ), this, SLOT( accept() ) );
connect( bbox, SIGNAL( rejected() ), this, SLOT( reject() ) );
vLayout->addWidget( bbox );
setLayout( vLayout );
connect( mWidget, SIGNAL( changed() ), this, SIGNAL( changed() ) );
}

0 comments on commit b225a82

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