Skip to content

Commit

Permalink
Port conditional formatting symbol button to QgsSymbolButton
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 24, 2017
1 parent 67b2724 commit f7ada81
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 48 deletions.
37 changes: 5 additions & 32 deletions src/gui/attributetable/qgsfieldconditionalformatwidget.cpp
Expand Up @@ -26,7 +26,6 @@ QgsFieldConditionalFormatWidget::QgsFieldConditionalFormatWidget( QWidget *paren
, mLayer( nullptr )
, mEditIndex( 0 )
, mEditing( false )
, mSymbol( nullptr )
{
setupUi( this );
mDeleteButton->hide();
Expand All @@ -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 );
Expand All @@ -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()
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -206,7 +180,6 @@ void QgsFieldConditionalFormatWidget::addNewRule()

void QgsFieldConditionalFormatWidget::reset()
{
mSymbol = nullptr;
mNameEdit->clear();
mRuleEdit->clear();
if ( fieldRadio->isChecked() )
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 0 additions & 2 deletions src/gui/attributetable/qgsfieldconditionalformatwidget.h
Expand Up @@ -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();
Expand All @@ -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 );
Expand Down
20 changes: 6 additions & 14 deletions src/ui/qgsfieldconditionalformatwidget.ui
Expand Up @@ -357,7 +357,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="btnChangeIcon">
<widget class="QgsSymbolButton" name="btnChangeIcon">
<property name="enabled">
<bool>false</bool>
</property>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit f7ada81

Please sign in to comment.