Skip to content
Permalink
Browse files

Port conditional formatting symbol button to QgsSymbolButton

  • Loading branch information
nyalldawson committed Jul 23, 2017
1 parent 67b2724 commit f7ada8138ff91085127005f48be6f97f76f3e52c
@@ -26,7 +26,6 @@ QgsFieldConditionalFormatWidget::QgsFieldConditionalFormatWidget( QWidget *paren
, mLayer( nullptr )
, mEditIndex( 0 )
, mEditing( false )
, mSymbol( nullptr )
{
setupUi( this );
mDeleteButton->hide();
@@ -38,7 +37,6 @@ QgsFieldConditionalFormatWidget::QgsFieldConditionalFormatWidget( QWidget *paren
connect( mCancelButton, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::cancelRule );
connect( mDeleteButton, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::deleteRule );
connect( listView, &QAbstractItemView::clicked, this, &QgsFieldConditionalFormatWidget::ruleClicked );
connect( btnChangeIcon, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::updateIcon );
connect( btnBuildExpression, &QAbstractButton::clicked, this, &QgsFieldConditionalFormatWidget::setExpression );
connect( mPresetsList, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsFieldConditionalFormatWidget::presetSet );
btnBackgroundColor->setAllowOpacity( true );
@@ -49,27 +47,13 @@ QgsFieldConditionalFormatWidget::QgsFieldConditionalFormatWidget( QWidget *paren
mModel = new QStandardItemModel( listView );
listView->setModel( mModel );
mPresetsList->setModel( mPresetsModel );
btnChangeIcon->setSymbol( QgsSymbol::defaultSymbol( QgsWkbTypes::PointGeometry ) );

setPresets( defaultPresets() );
}

QgsFieldConditionalFormatWidget::~QgsFieldConditionalFormatWidget()
{
delete mSymbol;
}

void QgsFieldConditionalFormatWidget::updateIcon()
{
mSymbol = QgsSymbol::defaultSymbol( QgsWkbTypes::PointGeometry );

QgsSymbolSelectorDialog dlg( mSymbol, QgsStyle::defaultStyle(), nullptr, this );
if ( !dlg.exec() )
{
return;
}

QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mSymbol, btnChangeIcon->iconSize() );
btnChangeIcon->setIcon( icon );
}

void QgsFieldConditionalFormatWidget::setExpression()
@@ -130,24 +114,14 @@ void QgsFieldConditionalFormatWidget::setFormattingFromStyle( const QgsCondition
{
btnBackgroundColor->setColor( style.backgroundColor() );
btnTextColor->setColor( style.textColor() );
if ( !style.icon().isNull() )
if ( style.symbol() )
{
btnChangeIcon->setSymbol( style.symbol()->clone() );
checkIcon->setChecked( true );
QIcon icon( style.icon() );
btnChangeIcon->setIcon( icon );
}
else
{
checkIcon->setChecked( false );
btnChangeIcon->setIcon( QIcon() );
}
if ( style.symbol() )
{
mSymbol = style.symbol()->clone();
}
else
{
mSymbol = nullptr;
}
QFont font = style.font();
mFontBoldBtn->setChecked( font.bold() );
@@ -206,7 +180,6 @@ void QgsFieldConditionalFormatWidget::addNewRule()

void QgsFieldConditionalFormatWidget::reset()
{
mSymbol = nullptr;
mNameEdit->clear();
mRuleEdit->clear();
if ( fieldRadio->isChecked() )
@@ -297,9 +270,9 @@ void QgsFieldConditionalFormatWidget::saveRule()
style.setFont( font );
style.setBackgroundColor( backColor );
style.setTextColor( fontColor );
if ( mSymbol && checkIcon->isChecked() )
if ( checkIcon->isChecked() )
{
style.setSymbol( mSymbol );
style.setSymbol( btnChangeIcon->clonedSymbol< QgsMarkerSymbol >() );
}
else
{
@@ -96,7 +96,6 @@ class GUI_EXPORT QgsFieldConditionalFormatWidget : public QWidget, private Ui::Q
bool mEditing;
QStandardItemModel *mModel = nullptr;
QStandardItemModel *mPresetsModel = nullptr;
QgsSymbol *mSymbol = nullptr;
QList<QgsConditionalStyle> mPresets;

QList<QgsConditionalStyle> getStyles();
@@ -105,7 +104,6 @@ class GUI_EXPORT QgsFieldConditionalFormatWidget : public QWidget, private Ui::Q

private slots:
void setExpression();
void updateIcon();
void presetSet( int index );
bool isCustomSet();
void ruleClicked( const QModelIndex &index );
@@ -357,7 +357,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="btnChangeIcon">
<widget class="QgsSymbolButton" name="btnChangeIcon">
<property name="enabled">
<bool>false</bool>
</property>
@@ -384,19 +384,6 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
@@ -599,6 +586,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsSymbolButton</class>
<extends>QToolButton</extends>
<header>qgssymbolbutton.h</header>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>

0 comments on commit f7ada81

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