Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Respect the "showLabel" flag on attribute editor elements
  • Loading branch information
m-kuhn committed Aug 19, 2016
1 parent f10f4a5 commit 0834938
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 3 deletions.
22 changes: 22 additions & 0 deletions python/gui/editorwidgets/qgsrelationwidgetwrapper.sip
Expand Up @@ -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 );
};
14 changes: 14 additions & 0 deletions python/gui/qgsrelationeditorwidget.sip
Expand Up @@ -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);
};
14 changes: 14 additions & 0 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
Expand Up @@ -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 );
Expand Down
16 changes: 16 additions & 0 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.h
Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -1633,6 +1644,8 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
break;
}

newWidgetInfo.showLabel = widgetDef->showLabel();

return newWidgetInfo;
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsattributeform.h
Expand Up @@ -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 );
Expand Down
19 changes: 18 additions & 1 deletion src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -33,6 +33,7 @@
QgsRelationEditorWidget::QgsRelationEditorWidget( QWidget* parent )
: QgsCollapsibleGroupBox( parent )
, mViewMode( QgsDualView::AttributeEditor )
, mShowLabel( true )
, mVisible( false )
{
QVBoxLayout* topLayout = new QVBoxLayout( this );
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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() );
}
16 changes: 16 additions & 0 deletions src/gui/qgsrelationeditorwidget.h
Expand Up @@ -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:
/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -108,6 +123,7 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsCollapsibleGroupBox
QGridLayout* mRelationLayout;
QButtonGroup* mViewModeButtonGroup;

bool mShowLabel;
bool mVisible;
};

Expand Down

0 comments on commit 0834938

Please sign in to comment.