Skip to content
Permalink
Browse files

Add a widget for customizing color ramp legend settings

  • Loading branch information
nyalldawson committed Dec 18, 2020
1 parent a0accab commit 787f62fee21d53ecdcfa19419a68fad240e71086
@@ -0,0 +1,92 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgscolorramplegendnodewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/







class QgsColorRampLegendNodeWidget: QgsPanelWidget
{
%Docstring
A widget for properties relating to a QgsColorRampLegendNode (QgsColorRampLegendNodeSettings).

The current settings are set by a call to :py:func:`~setSettings`, and the settings defined by the
widget are retrieved by calling :py:func:`~settings`.

When changes are made the to settings by a user the :py:func:`~widgetChanged` signal is emitted.

.. versionadded:: 3.18
%End

%TypeHeaderCode
#include "qgscolorramplegendnodewidget.h"
%End
public:

QgsColorRampLegendNodeWidget( QWidget *parent = 0 );
%Docstring
Constructor for QgsColorRampLegendNodeWidget, with the specified ``parent`` widget.
%End

QgsColorRampLegendNodeSettings settings() const;
%Docstring
Returns the legend node settings as defined by the widget.

.. seealso:: :py:func:`setSettings`
%End

void setSettings( const QgsColorRampLegendNodeSettings &settings );
%Docstring
Sets the settings to show in the widget.

.. seealso:: :py:func:`settings`
%End

};

class QgsColorRampLegendNodeDialog : QDialog
{
%Docstring
A dialog for configuring a :py:class:`QgsColorRampLegendNode` (:py:class:`QgsColorRampLegendNodeSettings`).

.. versionadded:: 3.18
%End

%TypeHeaderCode
#include "qgscolorramplegendnodewidget.h"
%End
public:

QgsColorRampLegendNodeDialog( const QgsColorRampLegendNodeSettings &settings, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsColorRampLegendNodeDialog, initially showing the specified ``settings``.
%End

QgsColorRampLegendNodeSettings settings() const;
%Docstring
Returns the legend node settings as defined by the dialog.
%End

QDialogButtonBox *buttonBox() const;
%Docstring
Returns a reference to the dialog's button box.
%End

};



/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgscolorramplegendnodewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -29,6 +29,7 @@
%Include auto_generated/qgscolorbutton.sip
%Include auto_generated/qgscolordialog.sip
%Include auto_generated/qgscolorrampbutton.sip
%Include auto_generated/qgscolorramplegendnodewidget.sip
%Include auto_generated/qgscolorschemelist.sip
%Include auto_generated/qgscolorswatchgrid.sip
%Include auto_generated/qgscolorwidgets.sip
@@ -402,6 +402,7 @@ set(QGIS_GUI_SRCS
qgscolorbutton.cpp
qgscolorrampbutton.cpp
qgscolordialog.cpp
qgscolorramplegendnodewidget.cpp
qgscolorschemelist.cpp
qgscolorswatchgrid.cpp
qgscolorwidgets.cpp
@@ -639,6 +640,7 @@ set(QGIS_GUI_HDRS
qgscolorbutton.h
qgscolordialog.h
qgscolorrampbutton.h
qgscolorramplegendnodewidget.h
qgscolorschemelist.h
qgscolorswatchgrid.h
qgscolorwidgets.h
@@ -0,0 +1,114 @@
/***************************************************************************
qgscolorramplegendnodewidget.h
-----------------------
begin : December 2020
copyright : (C) 2020 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgscolorramplegendnodewidget.h"
#include "qgscolorramplegendnode.h"
#include "qgsnumericformatselectorwidget.h"
#include "qgsnumericformat.h"
#include <QDialogButtonBox>

QgsColorRampLegendNodeWidget::QgsColorRampLegendNodeWidget( QWidget *parent )
: QgsPanelWidget( parent )
{
setupUi( this );

mDirectionComboBox->addItem( tr( "Maximum on Top" ), QgsColorRampLegendNodeSettings::MinimumToMaximum );
mDirectionComboBox->addItem( tr( "Minimum on Top" ), QgsColorRampLegendNodeSettings::MaximumToMinimum );

mMinLabelLineEdit->setPlaceholderText( tr( "Default" ) );
mMaxLabelLineEdit->setPlaceholderText( tr( "Default" ) );

connect( mMinLabelLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
connect( mMaxLabelLineEdit, &QLineEdit::textChanged, this, &QgsColorRampLegendNodeWidget::onChanged );
connect( mDirectionComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsColorRampLegendNodeWidget::onChanged );
connect( mNumberFormatPushButton, &QPushButton::clicked, this, &QgsColorRampLegendNodeWidget::changeNumberFormat );
}

QgsColorRampLegendNodeSettings QgsColorRampLegendNodeWidget::settings() const
{
QgsColorRampLegendNodeSettings settings;
settings.setDirection( static_cast< QgsColorRampLegendNodeSettings::Direction >( mDirectionComboBox->currentData().toInt() ) );
settings.setMinimumLabel( mMinLabelLineEdit->text() );
settings.setMaximumLabel( mMaxLabelLineEdit->text() );
settings.setNumericFormat( mSettings.numericFormat()->clone() );
return settings;
}

void QgsColorRampLegendNodeWidget::setSettings( const QgsColorRampLegendNodeSettings &settings )
{
mBlockSignals = true;

mSettings = settings;
mMinLabelLineEdit->setText( settings.minimumLabel() );
mMaxLabelLineEdit->setText( settings.maximumLabel() );
mDirectionComboBox->setCurrentIndex( mDirectionComboBox->findData( settings.direction() ) );

mBlockSignals = false;
}

void QgsColorRampLegendNodeWidget::changeNumberFormat()
{
QgsNumericFormatSelectorWidget *widget = new QgsNumericFormatSelectorWidget( this );
widget->setPanelTitle( tr( "Number Format" ) );
widget->setFormat( mSettings.numericFormat() );
connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [ = ]
{
mSettings.setNumericFormat( widget->format() );
onChanged();
} );
openPanel( widget );
return;
}

void QgsColorRampLegendNodeWidget::onChanged()
{
if ( mBlockSignals )
return;

emit widgetChanged();
}

//
// QgsColorRampLegendNodeDialog
//

QgsColorRampLegendNodeDialog::QgsColorRampLegendNodeDialog( const QgsColorRampLegendNodeSettings &settings, QWidget *parent )
: QDialog( parent )
{
QVBoxLayout *vLayout = new QVBoxLayout();
mWidget = new QgsColorRampLegendNodeWidget( nullptr );
vLayout->addWidget( mWidget );
mButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok, Qt::Horizontal );
connect( mButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
connect( mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
connect( mWidget, &QgsPanelWidget::panelAccepted, this, &QDialog::reject );
vLayout->addWidget( mButtonBox );
setLayout( vLayout );
setWindowTitle( tr( "Legend Node Settings" ) );

mWidget->setSettings( settings );
}

QgsColorRampLegendNodeSettings QgsColorRampLegendNodeDialog::settings() const
{
return mWidget->settings();
}

QDialogButtonBox *QgsColorRampLegendNodeDialog::buttonBox() const
{
return mButtonBox;
}
@@ -0,0 +1,113 @@
/***************************************************************************
qgscolorramplegendnodewidget.h
-----------------------
begin : December 2020
copyright : (C) 2020 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSCOLORRAMPLEGENDNODEWIDGET_H
#define QGSCOLORRAMPLEGENDNODEWIDGET_H


#include "qgis_gui.h"
#include "ui_qgscolorramplegendnodewidgetbase.h"

#include "qgscolorramplegendnode.h"
#include <QDialog>

class QDialogButtonBox;

/**
* \ingroup gui
* A widget for properties relating to a QgsColorRampLegendNode (QgsColorRampLegendNodeSettings).
*
* The current settings are set by a call to setSettings(), and the settings defined by the
* widget are retrieved by calling settings().
*
* When changes are made the to settings by a user the widgetChanged() signal is emitted.
*
* \since QGIS 3.18
*/
class GUI_EXPORT QgsColorRampLegendNodeWidget: public QgsPanelWidget, private Ui::QgsColorRampLegendNodeWidgetBase
{
Q_OBJECT

public:

/**
* Constructor for QgsColorRampLegendNodeWidget, with the specified \a parent widget.
*/
QgsColorRampLegendNodeWidget( QWidget *parent = nullptr );

/**
* Returns the legend node settings as defined by the widget.
*
* \see setSettings()
*/
QgsColorRampLegendNodeSettings settings() const;

/**
* Sets the settings to show in the widget.
*
* \see settings()
*/
void setSettings( const QgsColorRampLegendNodeSettings &settings );

private slots:

void onChanged();
void changeNumberFormat();

private:

bool mBlockSignals = false;
QgsColorRampLegendNodeSettings mSettings;

};

/**
* \ingroup gui
* \brief A dialog for configuring a QgsColorRampLegendNode (QgsColorRampLegendNodeSettings).
* \since QGIS 3.18
*/
class GUI_EXPORT QgsColorRampLegendNodeDialog : public QDialog
{
Q_OBJECT

public:

/**
* Constructor for QgsColorRampLegendNodeDialog, initially showing the specified \a settings.
*/
QgsColorRampLegendNodeDialog( const QgsColorRampLegendNodeSettings &settings, QWidget *parent SIP_TRANSFERTHIS = nullptr );

/**
* Returns the legend node settings as defined by the dialog.
*/
QgsColorRampLegendNodeSettings settings() const;

/**
* Returns a reference to the dialog's button box.
*/
QDialogButtonBox *buttonBox() const;

private:

QgsColorRampLegendNodeWidget *mWidget = nullptr;
QDialogButtonBox *mButtonBox = nullptr;

};


#endif //QGSCOLORRAMPLEGENDNODEWIDGET_H

0 comments on commit 787f62f

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