1
0
mirror of https://github.com/qgis/QGIS.git synced 2025-04-28 00:05:04 -04:00

Use a proper panel widget for conditional formatting configuration widget

Fixes a number of UI issues, including poor hi-dpi compatibility.
This commit is contained in:
Nyall Dawson 2019-09-25 18:02:50 +10:00
parent b9b690caac
commit a8d145a80a
9 changed files with 590 additions and 853 deletions

@ -8,7 +8,7 @@
class QgsFieldConditionalFormatWidget : QWidget class QgsFieldConditionalFormatWidget : QgsPanelWidget
{ {
%Docstring %Docstring
A widget for customizing conditional formatting options. A widget for customizing conditional formatting options.
@ -26,50 +26,48 @@ A widget for customizing conditional formatting options.
Constructor for QgsFieldConditionalFormatWidget. Constructor for QgsFieldConditionalFormatWidget.
%End %End
void viewRules(); void viewRules() /Deprecated/;
%Docstring %Docstring
Switches the widget to the rules page. Switches the widget to the rules page.
.. deprecated:: no longer used, will be removed in QGIS 4.0
%End %End
void setLayer( QgsVectorLayer *layer ); void setLayer( QgsVectorLayer *layer );
%Docstring %Docstring
Sets the vector layer associated with the widget. Sets the vector ``layer`` associated with the widget.
:param layer: vector layer
%End %End
void editStyle( int index, const QgsConditionalStyle &style ); void editStyle( int index, const QgsConditionalStyle &style );
%Docstring %Docstring
Switches the widget to the edit style mode for the specified style. Switches the widget to the edit style mode for the specified style,
where ``index`` is the index of the conditional style to edit
:param index: index of conditional style to edit and ``style`` is the initial definition of the style.
:param style: initial conditional styling options
%End %End
void loadStyle( const QgsConditionalStyle &style ); void loadStyle( const QgsConditionalStyle &style ) /Deprecated/;
%Docstring %Docstring
:param style: initial conditional styling options .. deprecated:: no longer used, use QgsEditConditionalFormatRuleWidget.loadStyle instead.
%End %End
void reset(); void reset() /Deprecated/;
%Docstring %Docstring
Resets the formatting options to their default state. Resets the formatting options to their default state.
.. deprecated:: no longer used, will be removed in QGIS 4.0
%End %End
void setPresets( const QList<QgsConditionalStyle> &styles ); void setPresets( const QList<QgsConditionalStyle> &styles );
%Docstring %Docstring
Set the presets that can be used for quick pick Sets the preset ``styles`` that can be used for quick pick.
:param styles: A list of styles used as presets
%End %End
QList<QgsConditionalStyle> defaultPresets() const; static QList<QgsConditionalStyle> defaultPresets();
%Docstring %Docstring
The default presets for the widget. Normally set when the widget is Returns a list of the default presets. Normally used when the widget is
created however called setPresets will override the default styles. created, however calling setPresets() will override the default styles.
:return: List of default presets.
%End %End
signals: signals:
@ -78,10 +76,76 @@ created however called setPresets will override the default styles.
%Docstring %Docstring
Emitted when the conditional styling rules are updated. Emitted when the conditional styling rules are updated.
:param fieldName: name of field whose rules have been modified. The ``fieldName`` argument indicates the name of the field whose rules
have been modified, or an empty ``fieldName`` indicates that a row-based
rule was updated.
%End %End
public slots: };
class QgsEditConditionalFormatRuleWidget : QgsPanelWidget
{
%Docstring
A widget for customizing an individual conditional formatting rule.
.. versionadded:: 3.10
%End
%TypeHeaderCode
#include "qgsfieldconditionalformatwidget.h"
%End
public:
explicit QgsEditConditionalFormatRuleWidget( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for :py:class:`QgsFieldConditionalFormatWidget`, with the specified ``parent`` widget.
%End
void setLayer( QgsVectorLayer *layer );
%Docstring
Sets the vector ``layer`` associated with the widget.
%End
void setPresets( const QList<QgsConditionalStyle> &styles );
%Docstring
Sets the preset ``styles`` that can be used for quick pick.
%End
void loadStyle( const QgsConditionalStyle &style );
%Docstring
Sets the widget to match the settings from the specified ``style``.
.. seealso:: :py:func:`currentStyle`
%End
QgsConditionalStyle currentStyle() const;
%Docstring
Returns the current style defined by the widget.
.. seealso:: :py:func:`loadStyle`
%End
void setRule( const QString &rule );
%Docstring
Sets the current expression ``rule`` to show in the widget.
%End
signals:
void ruleSaved();
%Docstring
Emitted when a user has opted to save the current rule.
%End
void ruleDeleted();
%Docstring
Emitted when a user has opted to deleted the current rule.
%End
void cancelled();
%Docstring
Emitted when a user has opted to cancel the rule modification.
%End
}; };

@ -42,6 +42,7 @@
#include "qgsgui.h" #include "qgsgui.h"
#include "qgsexpressioncontextutils.h" #include "qgsexpressioncontextutils.h"
#include "qgsshortcutsmanager.h" #include "qgsshortcutsmanager.h"
#include "qgsfieldconditionalformatwidget.h"
QgsDualView::QgsDualView( QWidget *parent ) QgsDualView::QgsDualView( QWidget *parent )
@ -52,7 +53,10 @@ QgsDualView::QgsDualView( QWidget *parent )
connect( mFeatureListView, &QgsFeatureListView::currentEditSelectionChanged, this, &QgsDualView::featureListCurrentEditSelectionChanged ); connect( mFeatureListView, &QgsFeatureListView::currentEditSelectionChanged, this, &QgsDualView::featureListCurrentEditSelectionChanged );
connect( mFeatureListView, &QgsFeatureListView::currentEditSelectionProgressChanged, this, &QgsDualView::updateEditSelectionProgress ); connect( mFeatureListView, &QgsFeatureListView::currentEditSelectionProgressChanged, this, &QgsDualView::updateEditSelectionProgress );
mConditionalFormatWidget->hide(); mConditionalFormatWidgetStack->hide();
mConditionalFormatWidget = new QgsFieldConditionalFormatWidget( this );
mConditionalFormatWidgetStack->setMainPanel( mConditionalFormatWidget );
mConditionalFormatWidget->setDockMode( true );
QgsSettings settings; QgsSettings settings;
mConditionalSplitter->restoreState( settings.value( QStringLiteral( "/qgis/attributeTable/splitterState" ), QByteArray() ).toByteArray() ); mConditionalSplitter->restoreState( settings.value( QStringLiteral( "/qgis/attributeTable/splitterState" ), QByteArray() ).toByteArray() );
@ -556,8 +560,7 @@ bool QgsDualView::saveEditChanges()
void QgsDualView::openConditionalStyles() void QgsDualView::openConditionalStyles()
{ {
mConditionalFormatWidget->setVisible( !mConditionalFormatWidget->isVisible() ); mConditionalFormatWidgetStack->setVisible( !mConditionalFormatWidgetStack->isVisible() );
mConditionalFormatWidget->viewRules();
} }
void QgsDualView::setMultiEditEnabled( bool enabled ) void QgsDualView::setMultiEditEnabled( bool enabled )

@ -29,6 +29,7 @@ class QgsFeatureRequest;
class QSignalMapper; class QSignalMapper;
class QgsMapLayerAction; class QgsMapLayerAction;
class QgsScrollArea; class QgsScrollArea;
class QgsFieldConditionalFormatWidget;
/** /**
* \ingroup gui * \ingroup gui
@ -388,6 +389,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
void updateEditSelectionProgress( int progress, int count ); void updateEditSelectionProgress( int progress, int count );
void panOrZoomToFeature( const QgsFeatureIds &featureset ); void panOrZoomToFeature( const QgsFeatureIds &featureset );
QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr;
QgsAttributeEditorContext mEditorContext; QgsAttributeEditorContext mEditorContext;
QgsAttributeTableModel *mMasterModel = nullptr; QgsAttributeTableModel *mMasterModel = nullptr;
QgsAttributeTableFilterModel *mFilterModel = nullptr; QgsAttributeTableFilterModel *mFilterModel = nullptr;

@ -22,58 +22,26 @@
#include "qgsvectorlayer.h" #include "qgsvectorlayer.h"
#include "qgsexpressioncontextutils.h" #include "qgsexpressioncontextutils.h"
//
// QgsFieldConditionalFormatWidget
//
QgsFieldConditionalFormatWidget::QgsFieldConditionalFormatWidget( QWidget *parent ) QgsFieldConditionalFormatWidget::QgsFieldConditionalFormatWidget( QWidget *parent )
: QWidget( parent ) : QgsPanelWidget( parent )
{ {
setupUi( this ); setupUi( this );
mDeleteButton->hide(); setPanelTitle( tr( "Conditional Styles" ) );
connect( mFieldCombo, &QgsFieldComboBox::fieldChanged, this, &QgsFieldConditionalFormatWidget::fieldChanged ); connect( mFieldCombo, &QgsFieldComboBox::fieldChanged, this, &QgsFieldConditionalFormatWidget::fieldChanged );
connect( fieldRadio, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::reloadStyles ); connect( fieldRadio, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::reloadStyles );
connect( rowRadio, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::reloadStyles ); connect( rowRadio, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::reloadStyles );
connect( mNewButton, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::addNewRule ); connect( mNewButton, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::addNewRule );
connect( mSaveRule, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::saveRule );
connect( mCancelButton, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::cancelRule );
connect( mDeleteButton, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::deleteRule );
connect( listView, &QAbstractItemView::clicked, this, &QgsFieldConditionalFormatWidget::ruleClicked ); connect( listView, &QAbstractItemView::clicked, this, &QgsFieldConditionalFormatWidget::ruleClicked );
connect( btnBuildExpression, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::setExpression );
connect( mPresetsList, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsFieldConditionalFormatWidget::presetSet );
btnBackgroundColor->setAllowOpacity( true );
btnBackgroundColor->setShowNoColor( true );
btnTextColor->setAllowOpacity( true );
btnTextColor->setShowNoColor( true );
mPresetsModel = new QStandardItemModel( listView );
mModel = new QStandardItemModel( listView ); mModel = new QStandardItemModel( listView );
listView->setModel( mModel ); listView->setModel( mModel );
mPresetsList->setModel( mPresetsModel );
btnChangeIcon->setSymbolType( QgsSymbol::Marker );
btnChangeIcon->setSymbol( QgsSymbol::defaultSymbol( QgsWkbTypes::PointGeometry ) );
setPresets( defaultPresets() ); connect( fieldRadio, &QRadioButton::toggled, mFieldCombo, &QWidget::setEnabled );
}
void QgsFieldConditionalFormatWidget::setExpression() mPresets = defaultPresets();
{
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
context.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "value" ), 0, true ) );
context.setHighlightedVariables( QStringList() << QStringLiteral( "value" ) );
QgsExpressionBuilderDialog dlg( mLayer, mRuleEdit->text(), this, QStringLiteral( "generic" ), context );
dlg.setWindowTitle( tr( "Conditional Style Rule Expression" ) );
if ( dlg.exec() )
{
QString expression = dlg.expressionBuilder()->expressionText();
mRuleEdit->setText( expression );
}
}
void QgsFieldConditionalFormatWidget::presetSet( int index )
{
if ( index == -1 || mPresets.isEmpty() )
return;
QgsConditionalStyle style = mPresets.at( index );
setFormattingFromStyle( style );
} }
void QgsFieldConditionalFormatWidget::setLayer( QgsVectorLayer *layer ) void QgsFieldConditionalFormatWidget::setLayer( QgsVectorLayer *layer )
@ -92,38 +60,76 @@ void QgsFieldConditionalFormatWidget::ruleClicked( const QModelIndex &index )
void QgsFieldConditionalFormatWidget::editStyle( int editIndex, const QgsConditionalStyle &style ) void QgsFieldConditionalFormatWidget::editStyle( int editIndex, const QgsConditionalStyle &style )
{ {
pages->setCurrentIndex( 1 );
mEditIndex = editIndex; mEditIndex = editIndex;
mEditing = true; mEditing = editIndex >= 0;
mDeleteButton->show(); mPanelHandled = false;
loadStyle( style );
QgsEditConditionalFormatRuleWidget *ruleWidget = new QgsEditConditionalFormatRuleWidget();
ruleWidget->setLayer( mLayer );
ruleWidget->setPresets( mPresets );
ruleWidget->loadStyle( style );
ruleWidget->setDockMode( true );
if ( fieldRadio->isChecked() )
{
ruleWidget->setRule( QStringLiteral( "@value " ) );
}
connect( ruleWidget, &QgsEditConditionalFormatRuleWidget::panelAccepted, this, [ = ]
{
if ( mPanelHandled )
{
// already handled the result of the panel, and the panel is being dismissed as a result
// of an already dealt with action
return;
}
QList<QgsConditionalStyle> styles = getStyles();
if ( mEditing )
{
styles.replace( mEditIndex, ruleWidget->currentStyle() );
}
else
{
styles.append( ruleWidget->currentStyle() );
}
QString fieldName;
if ( fieldRadio->isChecked() )
{
fieldName = mFieldCombo->currentField();
mLayer->conditionalStyles()->setFieldStyles( fieldName, styles );
}
if ( rowRadio->isChecked() )
{
mLayer->conditionalStyles()->setRowStyles( styles );
}
reloadStyles();
emit rulesUpdated( fieldName );
} );
connect( ruleWidget, &QgsEditConditionalFormatRuleWidget::ruleSaved, this, [ = ]
{
ruleWidget->acceptPanel();
} );
connect( ruleWidget, &QgsEditConditionalFormatRuleWidget::cancelled, this, [ = ]
{
mPanelHandled = true;
ruleWidget->acceptPanel();
} );
connect( ruleWidget, &QgsEditConditionalFormatRuleWidget::ruleDeleted, this, [ = ]
{
deleteCurrentRule();
mPanelHandled = true;
ruleWidget->acceptPanel();
} );
showPanel( ruleWidget );
} }
void QgsFieldConditionalFormatWidget::loadStyle( const QgsConditionalStyle &style ) void QgsFieldConditionalFormatWidget::loadStyle( const QgsConditionalStyle & )
{ {
mRuleEdit->setText( style.rule() );
mNameEdit->setText( style.name() );
setFormattingFromStyle( style );
}
void QgsFieldConditionalFormatWidget::setFormattingFromStyle( const QgsConditionalStyle &style )
{
btnBackgroundColor->setColor( style.backgroundColor() );
btnTextColor->setColor( style.textColor() );
if ( style.symbol() )
{
btnChangeIcon->setSymbol( style.symbol()->clone() );
checkIcon->setChecked( true );
}
else
{
checkIcon->setChecked( false );
}
QFont font = style.font();
mFontBoldBtn->setChecked( font.bold() );
mFontItalicBtn->setChecked( font.italic() );
mFontStrikethroughBtn->setChecked( font.strikeOut() );
mFontUnderlineBtn->setChecked( font.underline() );
mFontFamilyCmbBx->setFont( font );
} }
QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles() QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
@ -140,89 +146,21 @@ QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
return styles; return styles;
} }
void QgsFieldConditionalFormatWidget::deleteRule()
{
QList<QgsConditionalStyle> styles = getStyles();
styles.removeAt( mEditIndex );
QString fieldName;
if ( fieldRadio->isChecked() )
{
fieldName = mFieldCombo->currentField();
mLayer->conditionalStyles()->setFieldStyles( fieldName, styles );
}
if ( rowRadio->isChecked() )
{
mLayer->conditionalStyles()->setRowStyles( styles );
}
pages->setCurrentIndex( 0 );
reloadStyles();
emit rulesUpdated( fieldName );
}
void QgsFieldConditionalFormatWidget::cancelRule()
{
pages->setCurrentIndex( 0 );
reloadStyles();
reset();
}
void QgsFieldConditionalFormatWidget::addNewRule() void QgsFieldConditionalFormatWidget::addNewRule()
{ {
pages->setCurrentIndex( 1 ); editStyle( -1, QgsConditionalStyle() );
reset();
} }
void QgsFieldConditionalFormatWidget::reset() void QgsFieldConditionalFormatWidget::reset()
{ {
mNameEdit->clear();
mRuleEdit->clear();
if ( fieldRadio->isChecked() )
{
mRuleEdit->setText( QStringLiteral( "@value " ) );
}
btnBackgroundColor->setColor( QColor() );
btnTextColor->setColor( QColor() );
mPresetsList->setCurrentIndex( 0 );
mDeleteButton->hide();
mEditing = false;
checkIcon->setChecked( false );
btnChangeIcon->setIcon( QIcon() );
btnBackgroundColor->setToNoColor();
btnTextColor->setToNoColor();
mFontBoldBtn->setChecked( false );
mFontItalicBtn->setChecked( false );
mFontStrikethroughBtn->setChecked( false );
mFontUnderlineBtn->setChecked( false );
} }
void QgsFieldConditionalFormatWidget::setPresets( const QList<QgsConditionalStyle> &styles ) void QgsFieldConditionalFormatWidget::setPresets( const QList<QgsConditionalStyle> &styles )
{ {
mPresets.clear(); mPresets = styles;
mPresetsModel->clear();
const auto constStyles = styles;
for ( const QgsConditionalStyle &style : constStyles )
{
if ( style.isValid() )
{
QStandardItem *item = new QStandardItem( QStringLiteral( "abc - 123" ) );
if ( style.validBackgroundColor() )
item->setBackground( style.backgroundColor() );
if ( style.validTextColor() )
item->setForeground( style.textColor() );
if ( style.symbol() )
item->setIcon( style.icon() );
item->setFont( style.font() );
mPresetsModel->appendRow( item );
mPresets.append( style );
}
}
mPresetsList->setCurrentIndex( 0 );
} }
QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::defaultPresets() const QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::defaultPresets()
{ {
QList<QgsConditionalStyle> styles; QList<QgsConditionalStyle> styles;
QgsConditionalStyle style = QgsConditionalStyle(); QgsConditionalStyle style = QgsConditionalStyle();
@ -246,11 +184,109 @@ QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::defaultPresets() con
return styles; return styles;
} }
void QgsFieldConditionalFormatWidget::saveRule() void QgsFieldConditionalFormatWidget::reloadStyles()
{ {
QList<QgsConditionalStyle> styles = getStyles(); mModel->clear();
QgsConditionalStyle style = QgsConditionalStyle(); const auto constGetStyles = getStyles();
for ( const QgsConditionalStyle &style : constGetStyles )
{
QStandardItem *item = new QStandardItem( style.displayText() );
item->setIcon( QIcon( style.renderPreview() ) );
mModel->appendRow( item );
}
}
void QgsFieldConditionalFormatWidget::fieldChanged( const QString &fieldName )
{
Q_UNUSED( fieldName )
reloadStyles();
}
void QgsFieldConditionalFormatWidget::deleteCurrentRule()
{
if ( !mEditing )
return;
QList<QgsConditionalStyle> styles = getStyles();
styles.removeAt( mEditIndex );
QString fieldName;
if ( fieldRadio->isChecked() )
{
fieldName = mFieldCombo->currentField();
mLayer->conditionalStyles()->setFieldStyles( fieldName, styles );
}
if ( rowRadio->isChecked() )
{
mLayer->conditionalStyles()->setRowStyles( styles );
}
reloadStyles();
emit rulesUpdated( fieldName );
}
void QgsFieldConditionalFormatWidget::viewRules()
{
}
//
// QgsEditConditionalFormatRuleWidget
//
QgsEditConditionalFormatRuleWidget::QgsEditConditionalFormatRuleWidget( QWidget *parent )
: QgsPanelWidget( parent )
{
setupUi( this );
setPanelTitle( tr( "Edit Rule" ) );
btnBackgroundColor->setColor( QColor() );
btnTextColor->setColor( QColor() );
checkIcon->setChecked( false );
btnChangeIcon->setIcon( QIcon() );
btnBackgroundColor->setToNoColor();
btnTextColor->setToNoColor();
mFontBoldBtn->setChecked( false );
mFontItalicBtn->setChecked( false );
mFontStrikethroughBtn->setChecked( false );
mFontUnderlineBtn->setChecked( false );
connect( mSaveRule, &QAbstractButton::clicked, this, &QgsEditConditionalFormatRuleWidget::ruleSaved );
connect( mCancelButton, &QAbstractButton::clicked, this, &QgsEditConditionalFormatRuleWidget::cancelled );
connect( mDeleteButton, &QAbstractButton::clicked, this, &QgsEditConditionalFormatRuleWidget::ruleDeleted );
connect( btnBuildExpression, &QAbstractButton::clicked, this, &QgsEditConditionalFormatRuleWidget::setExpression );
connect( mPresetsList, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEditConditionalFormatRuleWidget::presetSet );
btnBackgroundColor->setAllowOpacity( true );
btnBackgroundColor->setShowNoColor( true );
btnTextColor->setAllowOpacity( true );
btnTextColor->setShowNoColor( true );
mPresetsModel = new QStandardItemModel( mPresetsList );
mPresetsList->setModel( mPresetsModel );
btnChangeIcon->setSymbolType( QgsSymbol::Marker );
btnChangeIcon->setSymbol( QgsSymbol::defaultSymbol( QgsWkbTypes::PointGeometry ) );
connect( checkIcon, &QCheckBox::toggled, btnChangeIcon, &QWidget::setEnabled );
}
void QgsEditConditionalFormatRuleWidget::setLayer( QgsVectorLayer *layer )
{
mLayer = layer;
}
void QgsEditConditionalFormatRuleWidget::loadStyle( const QgsConditionalStyle &style )
{
mRuleEdit->setText( style.rule() );
mNameEdit->setText( style.name() );
setFormattingFromStyle( style );
}
QgsConditionalStyle QgsEditConditionalFormatRuleWidget::currentStyle() const
{
QgsConditionalStyle style;
style.setRule( mRuleEdit->text() ); style.setRule( mRuleEdit->text() );
style.setName( mNameEdit->text() ); style.setName( mNameEdit->text() );
@ -274,56 +310,90 @@ void QgsFieldConditionalFormatWidget::saveRule()
{ {
style.setSymbol( nullptr ); style.setSymbol( nullptr );
} }
if ( mEditing ) return style;
}
void QgsEditConditionalFormatRuleWidget::setExpression()
{
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
context.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "value" ), 0, true ) );
context.setHighlightedVariables( QStringList() << QStringLiteral( "value" ) );
QgsExpressionBuilderDialog dlg( mLayer, mRuleEdit->text(), this, QStringLiteral( "generic" ), context );
dlg.setWindowTitle( tr( "Conditional Style Rule Expression" ) );
if ( dlg.exec() )
{ {
styles.replace( mEditIndex, style ); QString expression = dlg.expressionBuilder()->expressionText();
mRuleEdit->setText( expression );
}
}
void QgsEditConditionalFormatRuleWidget::presetSet( int index )
{
if ( index == -1 || mPresets.isEmpty() )
return;
const int styleIndex = mPresetsList->currentData( Qt::UserRole + 1 ).toInt();
QgsConditionalStyle style = mPresets.at( styleIndex );
setFormattingFromStyle( style );
}
void QgsEditConditionalFormatRuleWidget::setFormattingFromStyle( const QgsConditionalStyle &style )
{
btnBackgroundColor->setColor( style.backgroundColor() );
btnTextColor->setColor( style.textColor() );
if ( style.symbol() )
{
btnChangeIcon->setSymbol( style.symbol()->clone() );
checkIcon->setChecked( true );
} }
else else
{ {
styles.append( style ); checkIcon->setChecked( false );
} }
QFont font = style.font();
QString fieldName; mFontBoldBtn->setChecked( font.bold() );
if ( fieldRadio->isChecked() ) mFontItalicBtn->setChecked( font.italic() );
{ mFontStrikethroughBtn->setChecked( font.strikeOut() );
fieldName = mFieldCombo->currentField(); mFontUnderlineBtn->setChecked( font.underline() );
mLayer->conditionalStyles()->setFieldStyles( fieldName, styles ); mFontFamilyCmbBx->setFont( font );
}
if ( rowRadio->isChecked() )
{
mLayer->conditionalStyles()->setRowStyles( styles );
}
pages->setCurrentIndex( 0 );
reloadStyles();
emit rulesUpdated( fieldName );
reset();
} }
void QgsFieldConditionalFormatWidget::reloadStyles() void QgsEditConditionalFormatRuleWidget::setPresets( const QList<QgsConditionalStyle> &styles )
{ {
mModel->clear(); mPresets.clear();
mPresetsModel->clear();
const auto constGetStyles = getStyles(); QStandardItem *item = new QStandardItem( QString() );
for ( const QgsConditionalStyle &style : constGetStyles ) mPresetsModel->appendRow( item );
int i = 0;
for ( const QgsConditionalStyle &style : styles )
{ {
QStandardItem *item = new QStandardItem( style.displayText() ); if ( style.isValid() )
item->setIcon( QIcon( style.renderPreview() ) ); {
mModel->appendRow( item ); QStandardItem *item = new QStandardItem( QStringLiteral( "abc - 123" ) );
if ( style.validBackgroundColor() )
item->setBackground( style.backgroundColor() );
if ( style.validTextColor() )
item->setForeground( style.textColor() );
if ( style.symbol() )
item->setIcon( style.icon() );
item->setFont( style.font() );
item->setData( i, Qt::UserRole + 1 );
mPresetsModel->appendRow( item );
mPresets.append( style );
i++;
}
} }
mPresetsList->setCurrentIndex( 0 );
} }
void QgsFieldConditionalFormatWidget::fieldChanged( const QString &fieldName ) void QgsEditConditionalFormatRuleWidget::setRule( const QString &rule )
{ {
Q_UNUSED( fieldName ) mRuleEdit->setText( rule );
reloadStyles();
} }
void QgsFieldConditionalFormatWidget::viewRules() bool QgsEditConditionalFormatRuleWidget::isCustomSet()
{
pages->setCurrentIndex( 0 );
}
bool QgsFieldConditionalFormatWidget::isCustomSet()
{ {
return ( btnBackgroundColor->color().isValid() return ( btnBackgroundColor->color().isValid()
|| btnTextColor->color().isValid() || btnTextColor->color().isValid()

@ -18,8 +18,11 @@
#include <QWidget> #include <QWidget>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QStandardItem> #include <QStandardItem>
#include "qgspanelwidget.h"
#include "qgspanelwidgetstack.h"
#include "ui_qgsfieldconditionalformatwidget.h" #include "ui_qgsfieldconditionalformatwidget.h"
#include "ui_qgseditconditionalformatrulewidget.h"
#include "qgsconditionalstyle.h" #include "qgsconditionalstyle.h"
#include "qgis_gui.h" #include "qgis_gui.h"
@ -29,7 +32,7 @@
* A widget for customizing conditional formatting options. * A widget for customizing conditional formatting options.
* \since QGIS 2.12 * \since QGIS 2.12
*/ */
class GUI_EXPORT QgsFieldConditionalFormatWidget : public QWidget, private Ui::QgsFieldConditionalWidget class GUI_EXPORT QgsFieldConditionalFormatWidget : public QgsPanelWidget, private Ui::QgsFieldConditionalWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -41,54 +44,142 @@ class GUI_EXPORT QgsFieldConditionalFormatWidget : public QWidget, private Ui::Q
/** /**
* Switches the widget to the rules page. * Switches the widget to the rules page.
*
* \deprecated no longer used, will be removed in QGIS 4.0
*/ */
void viewRules(); Q_DECL_DEPRECATED void viewRules() SIP_DEPRECATED;
/** /**
* Sets the vector layer associated with the widget. * Sets the vector \a layer associated with the widget.
* \param layer vector layer */
*/
void setLayer( QgsVectorLayer *layer ); void setLayer( QgsVectorLayer *layer );
// TODO QGIS 4.0 - make private
/** /**
* Switches the widget to the edit style mode for the specified style. * Switches the widget to the edit style mode for the specified style,
* \param index index of conditional style to edit * where \a index is the index of the conditional style to edit
* \param style initial conditional styling options * and \a style is the initial definition of the style.
*/ */
void editStyle( int index, const QgsConditionalStyle &style ); void editStyle( int index, const QgsConditionalStyle &style );
/** /**
* \param style initial conditional styling options * \deprecated no longer used, use QgsEditConditionalFormatRuleWidget::loadStyle instead.
*/ */
void loadStyle( const QgsConditionalStyle &style ); Q_DECL_DEPRECATED void loadStyle( const QgsConditionalStyle &style ) SIP_DEPRECATED;
/** /**
* Resets the formatting options to their default state. * Resets the formatting options to their default state.
*
* \deprecated no longer used, will be removed in QGIS 4.0
*/ */
void reset(); Q_DECL_DEPRECATED void reset() SIP_DEPRECATED;
/** /**
* \brief Set the presets that can be used for quick pick * Sets the preset \a styles that can be used for quick pick.
* \param styles A list of styles used as presets
*/ */
void setPresets( const QList<QgsConditionalStyle> &styles ); void setPresets( const QList<QgsConditionalStyle> &styles );
/** /**
* \brief The default presets for the widget. Normally set when the widget is * Returns a list of the default presets. Normally used when the widget is
* created however called setPresets will override the default styles. * created, however calling setPresets() will override the default styles.
* \returns List of default presets.
*/ */
QList<QgsConditionalStyle> defaultPresets() const; static QList<QgsConditionalStyle> defaultPresets();
signals: signals:
/** /**
* Emitted when the conditional styling rules are updated. * Emitted when the conditional styling rules are updated.
* \param fieldName name of field whose rules have been modified. *
* The \a fieldName argument indicates the name of the field whose rules
* have been modified, or an empty \a fieldName indicates that a row-based
* rule was updated.
*/ */
void rulesUpdated( const QString &fieldName ); void rulesUpdated( const QString &fieldName );
public slots: private:
QgsVectorLayer *mLayer = nullptr;
int mEditIndex = -1;
bool mEditing = false;
bool mPanelHandled = false;
QStandardItemModel *mModel = nullptr;
QList<QgsConditionalStyle> mPresets;
QList<QgsConditionalStyle> getStyles();
private slots:
void ruleClicked( const QModelIndex &index );
void reloadStyles();
void addNewRule();
void fieldChanged( const QString &fieldName );
void deleteCurrentRule();
};
/**
* \ingroup gui
* \class QgsEditConditionalFormatRuleWidget
* A widget for customizing an individual conditional formatting rule.
* \since QGIS 3.10
*/
class GUI_EXPORT QgsEditConditionalFormatRuleWidget : public QgsPanelWidget, private Ui::QgsEditConditionalRuleWidget
{
Q_OBJECT
public:
/**
* Constructor for QgsFieldConditionalFormatWidget, with the specified \a parent widget.
*/
explicit QgsEditConditionalFormatRuleWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
/**
* Sets the vector \a layer associated with the widget.
*/
void setLayer( QgsVectorLayer *layer );
/**
* Sets the preset \a styles that can be used for quick pick.
*/
void setPresets( const QList<QgsConditionalStyle> &styles );
/**
* Sets the widget to match the settings from the specified \a style.
*
* \see currentStyle()
*/
void loadStyle( const QgsConditionalStyle &style );
/**
* Returns the current style defined by the widget.
*
* \see loadStyle()
*/
QgsConditionalStyle currentStyle() const;
/**
* Sets the current expression \a rule to show in the widget.
*/
void setRule( const QString &rule );
signals:
/**
* Emitted when a user has opted to save the current rule.
*/
void ruleSaved();
/**
* Emitted when a user has opted to deleted the current rule.
*/
void ruleDeleted();
/**
* Emitted when a user has opted to cancel the rule modification.
*/
void cancelled();
private: private:
QgsVectorLayer *mLayer = nullptr; QgsVectorLayer *mLayer = nullptr;
@ -98,21 +189,12 @@ class GUI_EXPORT QgsFieldConditionalFormatWidget : public QWidget, private Ui::Q
QStandardItemModel *mPresetsModel = nullptr; QStandardItemModel *mPresetsModel = nullptr;
QList<QgsConditionalStyle> mPresets; QList<QgsConditionalStyle> mPresets;
QList<QgsConditionalStyle> getStyles();
void setFormattingFromStyle( const QgsConditionalStyle &style ); void setFormattingFromStyle( const QgsConditionalStyle &style );
private slots: private slots:
void setExpression(); void setExpression();
void presetSet( int index ); void presetSet( int index );
bool isCustomSet(); bool isCustomSet();
void ruleClicked( const QModelIndex &index );
void reloadStyles();
void cancelRule();
void deleteRule();
void saveRule();
void addNewRule();
void fieldChanged( const QString &fieldName );
}; };

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="mPageTableView"> <widget class="QWidget" name="mPageTableView">
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
@ -40,7 +40,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
<widget class="QgsFieldConditionalFormatWidget" name="mConditionalFormatWidget" native="true"> <widget class="QgsPanelWidgetStack" name="mConditionalFormatWidgetStack" native="true">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -407,9 +407,9 @@
<header>attributetable/qgsfeaturelistview.h</header> <header>attributetable/qgsfeaturelistview.h</header>
</customwidget> </customwidget>
<customwidget> <customwidget>
<class>QgsFieldConditionalFormatWidget</class> <class>QgsPanelWidgetStack</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>attributetable/qgsfieldconditionalformatwidget.h</header> <header>qgspanelwidgetstack.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>

@ -16,653 +16,102 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="maximumSize">
<size>
<width>400</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="label_4"> <layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0,2">
<property name="text"> <property name="sizeConstraint">
<string>Conditional Format Rules</string> <enum>QLayout::SetDefaultConstraint</enum>
</property> </property>
<property name="alignment"> <property name="topMargin">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="pages">
<property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="page"> <item row="0" column="3" rowspan="2">
<layout class="QGridLayout" name="gridLayout"> <widget class="QPushButton" name="mNewButton">
<property name="leftMargin"> <property name="sizePolicy">
<number>0</number> <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="text">
<string>New Rule</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin"> <property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <item>
<number>0</number> <widget class="QgsFieldComboBox" name="mFieldCombo"/>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0" colspan="2">
<widget class="QListView" name="listView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0,2">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item row="0" column="3" rowspan="2">
<widget class="QPushButton" name="mNewButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>New Rule</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QgsFieldComboBox" name="mFieldCombo"/>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="fieldRadio">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Field</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="rowRadio">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Full row</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </item>
<widget class="QWidget" name="page_2"> <item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_3"> <widget class="QRadioButton" name="fieldRadio">
<item row="3" column="0"> <property name="sizePolicy">
<layout class="QHBoxLayout" name="horizontalLayout_5"> <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<item> <horstretch>0</horstretch>
<widget class="QLineEdit" name="mRuleEdit"> <verstretch>0</verstretch>
<property name="text"> </sizepolicy>
<string>@value</string> </property>
</property> <property name="text">
</widget> <string>Field</string>
</item> </property>
<item> <property name="checked">
<widget class="QToolButton" name="btnBuildExpression"> <bool>true</bool>
<property name="text"> </property>
<string>…</string> </widget>
</property> </item>
<property name="icon"> <item row="1" column="0">
<iconset resource="../../images/images.qrc"> <widget class="QRadioButton" name="rowRadio">
<normaloff>:/images/themes/default/mIconExpression.svg</normaloff>:/images/themes/default/mIconExpression.svg</iconset> <property name="sizePolicy">
</property> <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
</widget> <horstretch>0</horstretch>
</item> <verstretch>0</verstretch>
</layout> </sizepolicy>
</item> </property>
<item row="2" column="0"> <property name="text">
<widget class="QLabel" name="label"> <string>Full row</string>
<property name="sizePolicy"> </property>
<sizepolicy hsizetype="Minimum" vsizetype="Preferred"> </widget>
<horstretch>0</horstretch> </item>
<verstretch>0</verstretch> </layout>
</sizepolicy> </item>
</property> <item>
<property name="text"> <widget class="QListView" name="listView">
<string>Condition</string> <property name="editTriggers">
</property> <set>QAbstractItemView::NoEditTriggers</set>
</widget> </property>
</item> <property name="iconSize">
<item row="8" column="0"> <size>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <width>64</width>
<item> <height>32</height>
<widget class="QPushButton" name="mSaveRule"> </size>
<property name="text"> </property>
<string>Done</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mCancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="mDeleteButton">
<property name="text">
<string>Delete</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionDeleteSelected.svg</normaloff>:/images/themes/default/mActionDeleteSelected.svg</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="0">
<widget class="QFrame" name="horizontalFrame_2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Background</string>
</property>
</widget>
</item>
<item>
<widget class="QgsColorButton" name="btnBackgroundColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Text</string>
</property>
</widget>
</item>
<item>
<widget class="QgsColorButton" name="btnTextColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QCheckBox" name="checkIcon">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Icon</string>
</property>
</widget>
</item>
<item>
<widget class="QgsSymbolButton" name="btnChangeIcon">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QToolButton" name="mFontBoldBtn">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="font">
<font>
<pointsize>13</pointsize>
</font>
</property>
<property name="toolTip">
<string>Bold text
(data defined only, overrides Style)</string>
</property>
<property name="text">
<string>B</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">mFontButtons</string>
</attribute>
</widget>
</item>
<item>
<widget class="QToolButton" name="mFontItalicBtn">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="font">
<font>
<pointsize>13</pointsize>
<italic>true</italic>
</font>
</property>
<property name="toolTip">
<string>Italic text
(data defined only, overrides Style)</string>
</property>
<property name="text">
<string>I</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">mFontButtons</string>
</attribute>
</widget>
</item>
<item>
<widget class="QToolButton" name="mFontUnderlineBtn">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="font">
<font>
<pointsize>13</pointsize>
<underline>true</underline>
</font>
</property>
<property name="toolTip">
<string>Underlined text</string>
</property>
<property name="text">
<string>U</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">mFontButtons</string>
</attribute>
</widget>
</item>
<item>
<widget class="QToolButton" name="mFontStrikethroughBtn">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="font">
<font>
<pointsize>13</pointsize>
<strikeout>true</strikeout>
</font>
</property>
<property name="toolTip">
<string>Strikeout text</string>
</property>
<property name="text">
<string>S</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">mFontButtons</string>
</attribute>
</widget>
</item>
<item>
<widget class="QFontComboBox" name="mFontFamilyCmbBx">
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="mNameEdit">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Preset</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QComboBox" name="mPresetsList"/>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget>
<class>QgsSymbolButton</class>
<extends>QToolButton</extends>
<header>qgssymbolbutton.h</header>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget> <customwidget>
<class>QgsFieldComboBox</class> <class>QgsFieldComboBox</class>
<extends>QComboBox</extends> <extends>QComboBox</extends>
<header>qgsfieldcombobox.h</header> <header>qgsfieldcombobox.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops>
<tabstop>fieldRadio</tabstop>
<tabstop>mFieldCombo</tabstop>
<tabstop>rowRadio</tabstop>
<tabstop>mNewButton</tabstop>
<tabstop>listView</tabstop>
<tabstop>mNameEdit</tabstop>
<tabstop>mRuleEdit</tabstop>
<tabstop>btnBuildExpression</tabstop>
<tabstop>mPresetsList</tabstop>
<tabstop>btnBackgroundColor</tabstop>
<tabstop>btnTextColor</tabstop>
<tabstop>checkIcon</tabstop>
<tabstop>btnChangeIcon</tabstop>
<tabstop>mFontBoldBtn</tabstop>
<tabstop>mFontItalicBtn</tabstop>
<tabstop>mFontUnderlineBtn</tabstop>
<tabstop>mFontStrikethroughBtn</tabstop>
<tabstop>mFontFamilyCmbBx</tabstop>
<tabstop>mSaveRule</tabstop>
<tabstop>mCancelButton</tabstop>
<tabstop>mDeleteButton</tabstop>
</tabstops>
<resources> <resources>
<include location="../../images/images.qrc"/> <include location="../../images/images.qrc"/>
</resources> </resources>
<connections> <connections/>
<connection>
<sender>fieldRadio</sender>
<signal>toggled(bool)</signal>
<receiver>mFieldCombo</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>14</x>
<y>27</y>
</hint>
<hint type="destinationlabel">
<x>102</x>
<y>48</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkIcon</sender>
<signal>toggled(bool)</signal>
<receiver>btnChangeIcon</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>48</x>
<y>215</y>
</hint>
<hint type="destinationlabel">
<x>76</x>
<y>215</y>
</hint>
</hints>
</connection>
</connections>
<buttongroups> <buttongroups>
<buttongroup name="mFontButtons"> <buttongroup name="mFontButtons">
<property name="exclusive"> <property name="exclusive">

@ -36,6 +36,7 @@ ADD_PYTHON_TEST(PyQgsColorRamp test_qgscolorramp.py)
ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py) ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py)
ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.py) ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.py)
ADD_PYTHON_TEST(PyQgsCoordinateFormatter test_qgscoordinateformatter.py) ADD_PYTHON_TEST(PyQgsCoordinateFormatter test_qgscoordinateformatter.py)
ADD_PYTHON_TEST(PyQgsConditionalFormatWidgets test_qgsconditionalformatwidgets.py)
ADD_PYTHON_TEST(PyQgsConditionalStyle test_qgsconditionalstyle.py) ADD_PYTHON_TEST(PyQgsConditionalStyle test_qgsconditionalstyle.py)
ADD_PYTHON_TEST(PyQgsCoordinateTransformContext test_qgscoordinatetransformcontext.py) ADD_PYTHON_TEST(PyQgsCoordinateTransformContext test_qgscoordinatetransformcontext.py)
ADD_PYTHON_TEST(PyQgsDefaultValue test_qgsdefaultvalue.py) ADD_PYTHON_TEST(PyQgsDefaultValue test_qgsdefaultvalue.py)

@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for the conditional format widgets.
.. note:: 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.
"""
__author__ = 'Nyall Dawson'
__date__ = '2019-09-25'
__copyright__ = 'Copyright 2019, The QGIS Project'
from qgis.core import (QgsConditionalStyle,
QgsMarkerSymbol)
from qgis.gui import QgsEditConditionalFormatRuleWidget
from qgis.testing import (start_app,
unittest,
)
from utilities import unitTestDataPath
from qgis.PyQt.QtGui import QColor
start_app()
TEST_DATA_DIR = unitTestDataPath()
class TestPyQgsConditionalFormatWidgets(unittest.TestCase):
def testEditorWidget(self):
c = QgsConditionalStyle()
c.setName('')
w = QgsEditConditionalFormatRuleWidget()
w.loadStyle(c)
self.assertEqual(w.currentStyle(), c)
w.setRule('my rule')
self.assertEqual(w.currentStyle().rule(), 'my rule')
c.setName('n')
w = QgsEditConditionalFormatRuleWidget()
w.loadStyle(c)
self.assertEqual(w.currentStyle(), c)
c.setRule('1=1')
w = QgsEditConditionalFormatRuleWidget()
w.loadStyle(c)
self.assertEqual(w.currentStyle(), c)
c.setBackgroundColor(QColor(255, 0, 0))
w = QgsEditConditionalFormatRuleWidget()
w.loadStyle(c)
self.assertEqual(w.currentStyle(), c)
c.setTextColor(QColor(0, 255, 0))
w = QgsEditConditionalFormatRuleWidget()
w.loadStyle(c)
self.assertEqual(w.currentStyle(), c)
c.setSymbol(QgsMarkerSymbol.createSimple({}))
w = QgsEditConditionalFormatRuleWidget()
w.loadStyle(c)
self.assertEqual(w.currentStyle(), c)
if __name__ == '__main__':
unittest.main()