Skip to content

Commit

Permalink
Fix for #7993 again, fields are listed twice in labeling data defined…
Browse files Browse the repository at this point in the history
… menu

- Reverts 0192e37
- Move code from init() to ctor for fix and to ensure connections are not duplicated
- New code also fixes previously unknown issue when loading .qml style
  • Loading branch information
dakcarto committed Jun 4, 2013
1 parent 5d68c30 commit a29f2ba
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 49 deletions.
98 changes: 50 additions & 48 deletions src/gui/qgsdatadefinedbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,51 @@ QgsDataDefinedButton::QgsDataDefinedButton( QWidget* parent,
QString description )
: QToolButton( parent )
{
// set up static icons
if ( mIconDataDefine.isNull() )
{
mIconDataDefine = QgsApplication::getThemeIcon( "/mIconDataDefine.svg" );
mIconDataDefineOn = QgsApplication::getThemeIcon( "/mIconDataDefineOn.svg" );
mIconDataDefineError = QgsApplication::getThemeIcon( "/mIconDataDefineError.svg" );
mIconDataDefineExpression = QgsApplication::getThemeIcon( "/mIconDataDefineExpression.svg" );
mIconDataDefineExpressionOn = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionOn.svg" );
mIconDataDefineExpressionError = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionError.svg" );
}

// set default tool button icon properties
setFixedSize( 28, 24 );
setStyleSheet( QString( "QToolButton{ background: none; border: none;}" ) );
setIconSize( QSize( 24, 24 ) );
setPopupMode( QToolButton::InstantPopup );

mDefineMenu = new QMenu( this );
connect( mDefineMenu, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowMenu() ) );
connect( mDefineMenu, SIGNAL( triggered( QAction* ) ), this, SLOT( menuActionTriggered( QAction* ) ) );
setMenu( mDefineMenu );

mFieldsMenu = new QMenu( this );

mActionDataTypes = new QAction( this );
// list fields and types in submenu, since there may be many
mActionDataTypes->setMenu( mFieldsMenu );

mActionActive = new QAction( this );
QFont f = mActionActive->font();
f.setBold( true );
mActionActive->setFont( f );

mActionDescription = new QAction( tr( "Description..." ), this );

mActionExpDialog = new QAction( tr( "Edit..." ), this );
mActionExpression = 0;
mActionPasteExpr = new QAction( tr( "Paste" ), this );
mActionCopyExpr = new QAction( tr( "Copy" ), this );
mActionClearExpr = new QAction( tr( "Clear" ), this );

// set up sibling widget connections
connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( disableEnabledWidgets( bool ) ) );
connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( checkCheckedWidgets( bool ) ) );

init( vl, datadefined, datatypes, description );
}

Expand Down Expand Up @@ -74,49 +119,15 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
}

mDataTypes = datatypes;
mFieldNameList.clear();
mFieldTypeList.clear();

mInputDescription = description;
mFullDescription = QString( "" );
mUsageInfo = QString( "" );
mCurrentDefinition = QString( "" );

mActionExpression = 0;

if ( mIconDataDefine.isNull() )
{
mIconDataDefine = QgsApplication::getThemeIcon( "/mIconDataDefine.svg" );
mIconDataDefineOn = QgsApplication::getThemeIcon( "/mIconDataDefineOn.svg" );
mIconDataDefineError = QgsApplication::getThemeIcon( "/mIconDataDefineError.svg" );
mIconDataDefineExpression = QgsApplication::getThemeIcon( "/mIconDataDefineExpression.svg" );
mIconDataDefineExpressionOn = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionOn.svg" );
mIconDataDefineExpressionError = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionError.svg" );
}

// set default icon properties
setFixedSize( 28, 24 );
setStyleSheet( QString( "QToolButton{ background: none; border: none;}" ) );
setIconSize( QSize( 24, 24 ) );
setPopupMode( QToolButton::InstantPopup );

mDefineMenu = new QMenu( this );
connect( mDefineMenu, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowMenu() ) );
connect( mDefineMenu, SIGNAL( triggered( QAction* ) ), this, SLOT( menuActionTriggered( QAction* ) ) );

mFieldsMenu = new QMenu( this );

mActionActive = new QAction( this );
QFont f = mActionActive->font();
f.setBold( true );
mActionActive->setFont( f );

mActionDescription = new QAction( tr( "Description..." ), this );

mActionExpDialog = new QAction( tr( "Edit..." ), this );
mActionPasteExpr = new QAction( tr( "Paste" ), this );
mActionCopyExpr = new QAction( tr( "Copy" ), this );
mActionClearExpr = new QAction( tr( "Clear" ), this );

// set up data types string
mActionDataTypes = 0;
mDataTypesString = QString( "" );

QStringList ts;
Expand All @@ -136,7 +147,7 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
if ( !ts.isEmpty() )
{
mDataTypesString = ts.join( ", " );
mActionDataTypes = new QAction( tr( "Field type: " ) + mDataTypesString, this );
mActionDataTypes->setText( tr( "Field type: " ) + mDataTypesString );
}

if ( mVectorLayer )
Expand Down Expand Up @@ -176,12 +187,6 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
}
}

setMenu( mDefineMenu );

// set up sibling widget connections
connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( disableEnabledWidgets( bool ) ) );
connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( checkCheckedWidgets( bool ) ) );

updateGui();
}

Expand Down Expand Up @@ -243,7 +248,7 @@ void QgsDataDefinedButton::aboutToShowMenu()

mDefineMenu->addSeparator();

if ( mActionDataTypes )
if ( !mDataTypesString.isEmpty() )
{
QAction* fieldTitleAct = mDefineMenu->addAction( tr( "Attribute field" ) );
fieldTitleAct->setFont( titlefont );
Expand Down Expand Up @@ -274,9 +279,6 @@ void QgsDataDefinedButton::aboutToShowMenu()
act->setEnabled( false );
}

// list fields and types in submenu, since there may be many
mActionDataTypes->setMenu( mFieldsMenu );

mDefineMenu->addSeparator();
}

Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsdatadefinedbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton
QMap< QString, QString > mProperty;
QList< QPointer<QWidget> > mEnabledWidgets;
QList< QPointer<QWidget> > mCheckedWidgets;

QMenu* mDefineMenu;
QAction* mActionDataTypes;
QMenu* mFieldsMenu;

QAction* mActionActive;
Expand All @@ -260,7 +262,6 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton
QAction* mActionPasteExpr;
QAction* mActionCopyExpr;
QAction* mActionClearExpr;
QAction* mActionDataTypes;

DataTypes mDataTypes;
QString mDataTypesString;
Expand Down

0 comments on commit a29f2ba

Please sign in to comment.