mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -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:
parent
b9b690caac
commit
a8d145a80a
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class QgsFieldConditionalFormatWidget : QWidget
|
||||
class QgsFieldConditionalFormatWidget : QgsPanelWidget
|
||||
{
|
||||
%Docstring
|
||||
A widget for customizing conditional formatting options.
|
||||
@ -26,50 +26,48 @@ A widget for customizing conditional formatting options.
|
||||
Constructor for QgsFieldConditionalFormatWidget.
|
||||
%End
|
||||
|
||||
void viewRules();
|
||||
void viewRules() /Deprecated/;
|
||||
%Docstring
|
||||
Switches the widget to the rules page.
|
||||
|
||||
.. deprecated:: no longer used, will be removed in QGIS 4.0
|
||||
%End
|
||||
|
||||
void setLayer( QgsVectorLayer *layer );
|
||||
%Docstring
|
||||
Sets the vector layer associated with the widget.
|
||||
|
||||
:param layer: vector layer
|
||||
Sets the vector ``layer`` associated with the widget.
|
||||
%End
|
||||
|
||||
|
||||
void editStyle( int index, const QgsConditionalStyle &style );
|
||||
%Docstring
|
||||
Switches the widget to the edit style mode for the specified style.
|
||||
|
||||
:param index: index of conditional style to edit
|
||||
:param style: initial conditional styling options
|
||||
Switches the widget to the edit style mode for the specified style,
|
||||
where ``index`` is the index of the conditional style to edit
|
||||
and ``style`` is the initial definition of the style.
|
||||
%End
|
||||
|
||||
void loadStyle( const QgsConditionalStyle &style );
|
||||
void loadStyle( const QgsConditionalStyle &style ) /Deprecated/;
|
||||
%Docstring
|
||||
|
||||
:param style: initial conditional styling options
|
||||
.. deprecated:: no longer used, use QgsEditConditionalFormatRuleWidget.loadStyle instead.
|
||||
%End
|
||||
|
||||
void reset();
|
||||
void reset() /Deprecated/;
|
||||
%Docstring
|
||||
Resets the formatting options to their default state.
|
||||
|
||||
.. deprecated:: no longer used, will be removed in QGIS 4.0
|
||||
%End
|
||||
|
||||
void setPresets( const QList<QgsConditionalStyle> &styles );
|
||||
%Docstring
|
||||
Set the presets that can be used for quick pick
|
||||
|
||||
:param styles: A list of styles used as presets
|
||||
Sets the preset ``styles`` that can be used for quick pick.
|
||||
%End
|
||||
|
||||
QList<QgsConditionalStyle> defaultPresets() const;
|
||||
static QList<QgsConditionalStyle> defaultPresets();
|
||||
%Docstring
|
||||
The default presets for the widget. Normally set when the widget is
|
||||
created however called setPresets will override the default styles.
|
||||
|
||||
:return: List of default presets.
|
||||
Returns a list of the default presets. Normally used when the widget is
|
||||
created, however calling setPresets() will override the default styles.
|
||||
%End
|
||||
|
||||
signals:
|
||||
@ -78,10 +76,76 @@ created however called setPresets will override the default styles.
|
||||
%Docstring
|
||||
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
|
||||
|
||||
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 "qgsexpressioncontextutils.h"
|
||||
#include "qgsshortcutsmanager.h"
|
||||
#include "qgsfieldconditionalformatwidget.h"
|
||||
|
||||
|
||||
QgsDualView::QgsDualView( QWidget *parent )
|
||||
@ -52,7 +53,10 @@ QgsDualView::QgsDualView( QWidget *parent )
|
||||
connect( mFeatureListView, &QgsFeatureListView::currentEditSelectionChanged, this, &QgsDualView::featureListCurrentEditSelectionChanged );
|
||||
connect( mFeatureListView, &QgsFeatureListView::currentEditSelectionProgressChanged, this, &QgsDualView::updateEditSelectionProgress );
|
||||
|
||||
mConditionalFormatWidget->hide();
|
||||
mConditionalFormatWidgetStack->hide();
|
||||
mConditionalFormatWidget = new QgsFieldConditionalFormatWidget( this );
|
||||
mConditionalFormatWidgetStack->setMainPanel( mConditionalFormatWidget );
|
||||
mConditionalFormatWidget->setDockMode( true );
|
||||
|
||||
QgsSettings settings;
|
||||
mConditionalSplitter->restoreState( settings.value( QStringLiteral( "/qgis/attributeTable/splitterState" ), QByteArray() ).toByteArray() );
|
||||
@ -556,8 +560,7 @@ bool QgsDualView::saveEditChanges()
|
||||
|
||||
void QgsDualView::openConditionalStyles()
|
||||
{
|
||||
mConditionalFormatWidget->setVisible( !mConditionalFormatWidget->isVisible() );
|
||||
mConditionalFormatWidget->viewRules();
|
||||
mConditionalFormatWidgetStack->setVisible( !mConditionalFormatWidgetStack->isVisible() );
|
||||
}
|
||||
|
||||
void QgsDualView::setMultiEditEnabled( bool enabled )
|
||||
|
@ -29,6 +29,7 @@ class QgsFeatureRequest;
|
||||
class QSignalMapper;
|
||||
class QgsMapLayerAction;
|
||||
class QgsScrollArea;
|
||||
class QgsFieldConditionalFormatWidget;
|
||||
|
||||
/**
|
||||
* \ingroup gui
|
||||
@ -388,6 +389,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
|
||||
void updateEditSelectionProgress( int progress, int count );
|
||||
void panOrZoomToFeature( const QgsFeatureIds &featureset );
|
||||
|
||||
QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr;
|
||||
QgsAttributeEditorContext mEditorContext;
|
||||
QgsAttributeTableModel *mMasterModel = nullptr;
|
||||
QgsAttributeTableFilterModel *mFilterModel = nullptr;
|
||||
|
@ -22,58 +22,26 @@
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsexpressioncontextutils.h"
|
||||
|
||||
//
|
||||
// QgsFieldConditionalFormatWidget
|
||||
//
|
||||
|
||||
QgsFieldConditionalFormatWidget::QgsFieldConditionalFormatWidget( QWidget *parent )
|
||||
: QWidget( parent )
|
||||
: QgsPanelWidget( parent )
|
||||
{
|
||||
setupUi( this );
|
||||
mDeleteButton->hide();
|
||||
setPanelTitle( tr( "Conditional Styles" ) );
|
||||
connect( mFieldCombo, &QgsFieldComboBox::fieldChanged, this, &QgsFieldConditionalFormatWidget::fieldChanged );
|
||||
connect( fieldRadio, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::reloadStyles );
|
||||
connect( rowRadio, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::reloadStyles );
|
||||
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( 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 );
|
||||
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()
|
||||
{
|
||||
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 );
|
||||
mPresets = defaultPresets();
|
||||
}
|
||||
|
||||
void QgsFieldConditionalFormatWidget::setLayer( QgsVectorLayer *layer )
|
||||
@ -92,38 +60,76 @@ void QgsFieldConditionalFormatWidget::ruleClicked( const QModelIndex &index )
|
||||
|
||||
void QgsFieldConditionalFormatWidget::editStyle( int editIndex, const QgsConditionalStyle &style )
|
||||
{
|
||||
pages->setCurrentIndex( 1 );
|
||||
mEditIndex = editIndex;
|
||||
mEditing = true;
|
||||
mDeleteButton->show();
|
||||
loadStyle( style );
|
||||
mEditing = editIndex >= 0;
|
||||
mPanelHandled = false;
|
||||
|
||||
QgsEditConditionalFormatRuleWidget *ruleWidget = new QgsEditConditionalFormatRuleWidget();
|
||||
ruleWidget->setLayer( mLayer );
|
||||
ruleWidget->setPresets( mPresets );
|
||||
ruleWidget->loadStyle( style );
|
||||
ruleWidget->setDockMode( true );
|
||||
|
||||
if ( fieldRadio->isChecked() )
|
||||
{
|
||||
ruleWidget->setRule( QStringLiteral( "@value " ) );
|
||||
}
|
||||
|
||||
void QgsFieldConditionalFormatWidget::loadStyle( const QgsConditionalStyle &style )
|
||||
connect( ruleWidget, &QgsEditConditionalFormatRuleWidget::panelAccepted, this, [ = ]
|
||||
{
|
||||
mRuleEdit->setText( style.rule() );
|
||||
mNameEdit->setText( style.name() );
|
||||
setFormattingFromStyle( style );
|
||||
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;
|
||||
}
|
||||
void QgsFieldConditionalFormatWidget::setFormattingFromStyle( const QgsConditionalStyle &style )
|
||||
|
||||
QList<QgsConditionalStyle> styles = getStyles();
|
||||
if ( mEditing )
|
||||
{
|
||||
btnBackgroundColor->setColor( style.backgroundColor() );
|
||||
btnTextColor->setColor( style.textColor() );
|
||||
if ( style.symbol() )
|
||||
{
|
||||
btnChangeIcon->setSymbol( style.symbol()->clone() );
|
||||
checkIcon->setChecked( true );
|
||||
styles.replace( mEditIndex, ruleWidget->currentStyle() );
|
||||
}
|
||||
else
|
||||
{
|
||||
checkIcon->setChecked( false );
|
||||
styles.append( ruleWidget->currentStyle() );
|
||||
}
|
||||
QFont font = style.font();
|
||||
mFontBoldBtn->setChecked( font.bold() );
|
||||
mFontItalicBtn->setChecked( font.italic() );
|
||||
mFontStrikethroughBtn->setChecked( font.strikeOut() );
|
||||
mFontUnderlineBtn->setChecked( font.underline() );
|
||||
mFontFamilyCmbBx->setFont( font );
|
||||
|
||||
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 & )
|
||||
{
|
||||
}
|
||||
|
||||
QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
|
||||
@ -140,89 +146,21 @@ QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
|
||||
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()
|
||||
{
|
||||
pages->setCurrentIndex( 1 );
|
||||
reset();
|
||||
editStyle( -1, QgsConditionalStyle() );
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
mPresets.clear();
|
||||
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 );
|
||||
mPresets = styles;
|
||||
}
|
||||
|
||||
QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::defaultPresets() const
|
||||
QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::defaultPresets()
|
||||
{
|
||||
QList<QgsConditionalStyle> styles;
|
||||
QgsConditionalStyle style = QgsConditionalStyle();
|
||||
@ -246,11 +184,109 @@ QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::defaultPresets() con
|
||||
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.setName( mNameEdit->text() );
|
||||
@ -274,56 +310,90 @@ void QgsFieldConditionalFormatWidget::saveRule()
|
||||
{
|
||||
style.setSymbol( nullptr );
|
||||
}
|
||||
if ( mEditing )
|
||||
return style;
|
||||
}
|
||||
|
||||
void QgsEditConditionalFormatRuleWidget::setExpression()
|
||||
{
|
||||
styles.replace( mEditIndex, style );
|
||||
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 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
|
||||
{
|
||||
styles.append( style );
|
||||
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 );
|
||||
}
|
||||
|
||||
QString fieldName;
|
||||
if ( fieldRadio->isChecked() )
|
||||
void QgsEditConditionalFormatRuleWidget::setPresets( const QList<QgsConditionalStyle> &styles )
|
||||
{
|
||||
fieldName = mFieldCombo->currentField();
|
||||
mLayer->conditionalStyles()->setFieldStyles( fieldName, styles );
|
||||
}
|
||||
if ( rowRadio->isChecked() )
|
||||
mPresets.clear();
|
||||
mPresetsModel->clear();
|
||||
QStandardItem *item = new QStandardItem( QString() );
|
||||
mPresetsModel->appendRow( item );
|
||||
int i = 0;
|
||||
for ( const QgsConditionalStyle &style : styles )
|
||||
{
|
||||
mLayer->conditionalStyles()->setRowStyles( styles );
|
||||
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() );
|
||||
item->setData( i, Qt::UserRole + 1 );
|
||||
mPresetsModel->appendRow( item );
|
||||
mPresets.append( style );
|
||||
i++;
|
||||
}
|
||||
pages->setCurrentIndex( 0 );
|
||||
reloadStyles();
|
||||
emit rulesUpdated( fieldName );
|
||||
reset();
|
||||
}
|
||||
mPresetsList->setCurrentIndex( 0 );
|
||||
}
|
||||
|
||||
void QgsFieldConditionalFormatWidget::reloadStyles()
|
||||
void QgsEditConditionalFormatRuleWidget::setRule( const QString &rule )
|
||||
{
|
||||
mModel->clear();
|
||||
|
||||
const auto constGetStyles = getStyles();
|
||||
for ( const QgsConditionalStyle &style : constGetStyles )
|
||||
{
|
||||
QStandardItem *item = new QStandardItem( style.displayText() );
|
||||
item->setIcon( QIcon( style.renderPreview() ) );
|
||||
mModel->appendRow( item );
|
||||
}
|
||||
mRuleEdit->setText( rule );
|
||||
}
|
||||
|
||||
void QgsFieldConditionalFormatWidget::fieldChanged( const QString &fieldName )
|
||||
{
|
||||
Q_UNUSED( fieldName )
|
||||
reloadStyles();
|
||||
}
|
||||
|
||||
void QgsFieldConditionalFormatWidget::viewRules()
|
||||
{
|
||||
pages->setCurrentIndex( 0 );
|
||||
}
|
||||
|
||||
bool QgsFieldConditionalFormatWidget::isCustomSet()
|
||||
bool QgsEditConditionalFormatRuleWidget::isCustomSet()
|
||||
{
|
||||
return ( btnBackgroundColor->color().isValid()
|
||||
|| btnTextColor->color().isValid()
|
||||
|
@ -18,8 +18,11 @@
|
||||
#include <QWidget>
|
||||
#include <QStandardItemModel>
|
||||
#include <QStandardItem>
|
||||
#include "qgspanelwidget.h"
|
||||
#include "qgspanelwidgetstack.h"
|
||||
|
||||
#include "ui_qgsfieldconditionalformatwidget.h"
|
||||
#include "ui_qgseditconditionalformatrulewidget.h"
|
||||
#include "qgsconditionalstyle.h"
|
||||
#include "qgis_gui.h"
|
||||
|
||||
@ -29,7 +32,7 @@
|
||||
* A widget for customizing conditional formatting options.
|
||||
* \since QGIS 2.12
|
||||
*/
|
||||
class GUI_EXPORT QgsFieldConditionalFormatWidget : public QWidget, private Ui::QgsFieldConditionalWidget
|
||||
class GUI_EXPORT QgsFieldConditionalFormatWidget : public QgsPanelWidget, private Ui::QgsFieldConditionalWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -41,54 +44,142 @@ class GUI_EXPORT QgsFieldConditionalFormatWidget : public QWidget, private Ui::Q
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* \param layer vector layer
|
||||
* Sets the vector \a layer associated with the widget.
|
||||
*/
|
||||
void setLayer( QgsVectorLayer *layer );
|
||||
|
||||
// TODO QGIS 4.0 - make private
|
||||
|
||||
/**
|
||||
* Switches the widget to the edit style mode for the specified style.
|
||||
* \param index index of conditional style to edit
|
||||
* \param style initial conditional styling options
|
||||
* Switches the widget to the edit style mode for the specified style,
|
||||
* where \a index is the index of the conditional style to edit
|
||||
* and \a style is the initial definition of the 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.
|
||||
*
|
||||
* \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
|
||||
* \param styles A list of styles used as presets
|
||||
* Sets the preset \a styles that can be used for quick pick.
|
||||
*/
|
||||
void setPresets( const QList<QgsConditionalStyle> &styles );
|
||||
|
||||
/**
|
||||
* \brief The default presets for the widget. Normally set when the widget is
|
||||
* created however called setPresets will override the default styles.
|
||||
* \returns List of default presets.
|
||||
* Returns a list of the default presets. Normally used when the widget is
|
||||
* created, however calling setPresets() will override the default styles.
|
||||
*/
|
||||
QList<QgsConditionalStyle> defaultPresets() const;
|
||||
static QList<QgsConditionalStyle> defaultPresets();
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
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:
|
||||
QgsVectorLayer *mLayer = nullptr;
|
||||
@ -98,21 +189,12 @@ class GUI_EXPORT QgsFieldConditionalFormatWidget : public QWidget, private Ui::Q
|
||||
QStandardItemModel *mPresetsModel = nullptr;
|
||||
QList<QgsConditionalStyle> mPresets;
|
||||
|
||||
QList<QgsConditionalStyle> getStyles();
|
||||
|
||||
void setFormattingFromStyle( const QgsConditionalStyle &style );
|
||||
|
||||
private slots:
|
||||
void setExpression();
|
||||
void presetSet( int index );
|
||||
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>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="mPageTableView">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
@ -40,7 +40,7 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QgsFieldConditionalFormatWidget" name="mConditionalFormatWidget" native="true">
|
||||
<widget class="QgsPanelWidgetStack" name="mConditionalFormatWidgetStack" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@ -407,9 +407,9 @@
|
||||
<header>attributetable/qgsfeaturelistview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QgsFieldConditionalFormatWidget</class>
|
||||
<class>QgsPanelWidgetStack</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>attributetable/qgsfieldconditionalformatwidget.h</header>
|
||||
<header>qgspanelwidgetstack.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
@ -16,71 +16,11 @@
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<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>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Conditional Format Rules</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="pages">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</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>
|
||||
@ -146,523 +86,32 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_2">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="3" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="mRuleEdit">
|
||||
<property name="text">
|
||||
<string>@value</string>
|
||||
<widget class="QListView" name="listView">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnBuildExpression">
|
||||
<property name="text">
|
||||
<string>…</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../images/images.qrc">
|
||||
<normaloff>:/images/themes/default/mIconExpression.svg</normaloff>:/images/themes/default/mIconExpression.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Condition</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="mSaveRule">
|
||||
<property name="text">
|
||||
<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">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
<width>64</width>
|
||||
<height>32</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>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<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>
|
||||
<class>QgsFieldComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>qgsfieldcombobox.h</header>
|
||||
</customwidget>
|
||||
</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>
|
||||
<include location="../../images/images.qrc"/>
|
||||
</resources>
|
||||
<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>
|
||||
<connections/>
|
||||
<buttongroups>
|
||||
<buttongroup name="mFontButtons">
|
||||
<property name="exclusive">
|
||||
|
@ -36,6 +36,7 @@ ADD_PYTHON_TEST(PyQgsColorRamp test_qgscolorramp.py)
|
||||
ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py)
|
||||
ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.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(PyQgsCoordinateTransformContext test_qgscoordinatetransformcontext.py)
|
||||
ADD_PYTHON_TEST(PyQgsDefaultValue test_qgsdefaultvalue.py)
|
||||
|
66
tests/src/python/test_qgsconditionalformatwidgets.py
Normal file
66
tests/src/python/test_qgsconditionalformatwidgets.py
Normal file
@ -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()
|
Loading…
x
Reference in New Issue
Block a user