Skip to content
Permalink
Browse files

Respect the "showLabel" flag on attribute editor elements

  • Loading branch information
m-kuhn committed Aug 19, 2016
1 parent f10f4a5 commit 08349385d7f8a1eaadfeeab26eed9a238d7cf16f
@@ -23,11 +23,33 @@ class QgsRelationWidgetWrapper : QgsWidgetWrapper
public:
explicit QgsRelationWidgetWrapper( QgsVectorLayer* vl, const QgsRelation& relation, QWidget* editor = 0, QWidget* parent /TransferThis/ = 0 );

/**
* Defines if a title lable should be shown for this widget.
* Only has an effect after widget() has been called at least once.
*
* @note Added in QGIS 2.18
*/
bool showLabel() const;

/**
* Defines if a title lable should be shown for this widget.
* Only has an effect after widget() has been called at least once.
*
* @note Added in QGIS 2.18
*/
void setShowLabel(bool showLabel);

protected:
QWidget* createWidget( QWidget* parent );
void initWidget( QWidget* editor );
bool valid() const;

public slots:
void setFeature( const QgsFeature& feature );

/** Sets the visibility of the wrapper's widget.
* @param visible set to true to show widget, false to hide widget
* @note added in QGIS 2.16
*/
void setVisible( bool visible );
};
@@ -65,4 +65,18 @@ class QgsRelationEditorWidget : QgsCollapsibleGroupBox
* which are currently being edited.
*/
QgsIFeatureSelectionManager* featureSelectionManager();

/**
* Defines if a title label should be shown for this widget.
*
* @note Added in QGIS 2.18
*/
bool showLabel() const;

/**
* Defines if a title label should be shown for this widget.
*
* @note Added in QGIS 2.18
*/
void setShowLabel(bool showLabel);
};
@@ -45,6 +45,20 @@ void QgsRelationWidgetWrapper::setVisible( bool visible )
mWidget->setVisible( visible );
}

bool QgsRelationWidgetWrapper::showLabel() const
{
if ( mWidget )
return mWidget->showLabel();
else
return false;
}

void QgsRelationWidgetWrapper::setShowLabel( bool showLabel )
{
if ( mWidget )
mWidget->setShowLabel( showLabel );
}

void QgsRelationWidgetWrapper::initWidget( QWidget* editor )
{
QgsRelationEditorWidget* w = dynamic_cast<QgsRelationEditorWidget*>( editor );
@@ -32,6 +32,22 @@ class GUI_EXPORT QgsRelationWidgetWrapper : public QgsWidgetWrapper
public:
explicit QgsRelationWidgetWrapper( QgsVectorLayer* vl, const QgsRelation& relation, QWidget* editor = nullptr, QWidget* parent = nullptr );

/**
* Defines if a title lable should be shown for this widget.
* Only has an effect after widget() has been called at least once.
*
* @note Added in QGIS 2.18
*/
bool showLabel() const;

/**
* Defines if a title lable should be shown for this widget.
* Only has an effect after widget() has been called at least once.
*
* @note Added in QGIS 2.18
*/
void setShowLabel( bool showLabel );

protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
@@ -1145,7 +1145,15 @@ void QgsAttributeForm::init()

label->setBuddy( widgetInfo.widget );

if ( widgetInfo.labelOnTop )
if ( !widgetInfo.showLabel )
{
QVBoxLayout* c = new QVBoxLayout();
label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
c->addWidget( widgetInfo.widget );
layout->addLayout( c, row, column, 1, 2 );
column += 2;
}
else if ( widgetInfo.labelOnTop )
{
QVBoxLayout* c = new QVBoxLayout();
label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
@@ -1511,6 +1519,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt

newWidgetInfo.labelOnTop = mLayer->editFormConfig()->labelOnTop( fieldDef->idx() );
newWidgetInfo.labelText = mLayer->attributeDisplayName( fieldDef->idx() );
newWidgetInfo.showLabel = widgetDef->showLabel();

break;
}
@@ -1524,6 +1533,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
rww->setConfig( cfg );
rww->setContext( context );
newWidgetInfo.widget = rww->widget();
rww->setShowLabel( relDef->showLabel() );
mWidgets.append( rww );
newWidgetInfo.labelText = QString::null;
newWidgetInfo.labelOnTop = true;
@@ -1545,7 +1555,8 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
if ( container->isGroupBox() )
{
QGroupBox* groupBox = new QGroupBox( parent );
groupBox->setTitle( container->name() );
if ( container->showLabel() )
groupBox->setTitle( container->name() );
myContainer = groupBox;
newWidgetInfo.widget = myContainer;
}
@@ -1633,6 +1644,8 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
break;
}

newWidgetInfo.showLabel = widgetDef->showLabel();

return newWidgetInfo;
}

@@ -288,12 +288,14 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
: widget( nullptr )
, labelOnTop( false )
, labelAlignRight( false )
, showLabel( true )
{}

QWidget* widget;
QString labelText;
bool labelOnTop;
bool labelAlignRight;
bool showLabel;
};

WidgetInfo createWidgetFromDef( const QgsAttributeEditorElement* widgetDef, QWidget* parent, QgsVectorLayer* vl, QgsAttributeEditorContext& context );
@@ -33,6 +33,7 @@
QgsRelationEditorWidget::QgsRelationEditorWidget( QWidget* parent )
: QgsCollapsibleGroupBox( parent )
, mViewMode( QgsDualView::AttributeEditor )
, mShowLabel( true )
, mVisible( false )
{
QVBoxLayout* topLayout = new QVBoxLayout( this );
@@ -151,7 +152,8 @@ void QgsRelationEditorWidget::setRelationFeature( const QgsRelation& relation, c
connect( mRelation.referencingLayer(), SIGNAL( editingStarted() ), this, SLOT( updateButtons() ) );
connect( mRelation.referencingLayer(), SIGNAL( editingStopped() ), this, SLOT( updateButtons() ) );

setTitle( relation.name() );
if ( mShowLabel )
setTitle( relation.name() );

QgsVectorLayer* lyr = relation.referencingLayer();

@@ -539,3 +541,18 @@ void QgsRelationEditorWidget::updateUi()
}
}
}

bool QgsRelationEditorWidget::showLabel() const
{
return mShowLabel;
}

void QgsRelationEditorWidget::setShowLabel( bool showLabel )
{
mShowLabel = showLabel;

if ( mShowLabel && mRelation.isValid() )
setTitle( mRelation.name() );
else
setTitle( QString() );
}
@@ -38,6 +38,7 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsCollapsibleGroupBox
{
Q_OBJECT
Q_PROPERTY( QgsDualView::ViewMode viewMode READ viewMode WRITE setViewMode )
Q_PROPERTY( bool showLabel READ showLabel WRITE setShowLabel )

public:
/**
@@ -74,6 +75,20 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsCollapsibleGroupBox
*/
QgsIFeatureSelectionManager* featureSelectionManager();

/**
* Defines if a title label should be shown for this widget.
*
* @note Added in QGIS 2.18
*/
bool showLabel() const;

/**
* Defines if a title label should be shown for this widget.
*
* @note Added in QGIS 2.18
*/
void setShowLabel( bool showLabel );

private slots:
void setViewMode( int mode ) {setViewMode( static_cast<QgsDualView::ViewMode>( mode ) );}
void updateButtons();
@@ -108,6 +123,7 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsCollapsibleGroupBox
QGridLayout* mRelationLayout;
QButtonGroup* mViewModeButtonGroup;

bool mShowLabel;
bool mVisible;
};

0 comments on commit 0834938

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