20#include "moc_qgsuserinputwidget.cpp"
27 QFrame *f =
new QFrame();
28 f->setObjectName( QStringLiteral(
"mUserInputContainer" ) );
30 QPalette
pal = palette();
31 pal.setBrush( backgroundRole(),
pal.window() );
33 f->setAutoFillBackground(
true );
34 f->setFrameShape( QFrame::StyledPanel );
35 f->setFrameShadow( QFrame::Plain );
37 mLayout =
new QBoxLayout( QBoxLayout::TopToBottom );
38 mLayout->setAlignment( Qt::AlignRight | Qt::AlignTop );
39 f->setLayout( mLayout );
41 QBoxLayout *topLayout =
new QBoxLayout( QBoxLayout::TopToBottom );
42 topLayout->setContentsMargins( 0, 0, 0, 0 );
43 topLayout->addWidget( f );
44 setLayout( topLayout );
47 topLayout->setSizeConstraint( QLayout::SetFixedSize );
48 mLayout->setSizeConstraint( QLayout::SetFixedSize );
50 setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
56 QFrame *line =
nullptr;
57 if ( mWidgetList.count() > 0 )
59 line =
new QFrame(
this );
60 line->setFrameShadow( QFrame::Sunken );
61 line->setFrameShape( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
62 mLayout->addWidget( line );
64 mLayout->addWidget( widget );
66 connect( widget, &QObject::destroyed,
this, &QgsUserInputWidget::widgetDestroyed );
68 mWidgetList.insert( widget, line );
75void QgsUserInputWidget::widgetDestroyed( QObject *obj )
77 if ( obj->isWidgetType() )
79 QWidget *w = qobject_cast<QWidget *>( obj );
80 const auto it = mWidgetList.find( w );
81 if ( it != mWidgetList.end() )
83 if ( QFrame *frame = it.value() )
87 mWidgetList.erase( it );
90 if ( mWidgetList.count() == 0 )
96void QgsUserInputWidget::setLayoutDirection( QBoxLayout::Direction direction )
98 mLayout->setDirection( direction );
100 const bool horizontal = direction == QBoxLayout::LeftToRight || direction == QBoxLayout::RightToLeft;
101 QMap<QWidget *, QFrame *>::const_iterator i = mWidgetList.constBegin();
102 while ( i != mWidgetList.constEnd() )
104 if (
auto *lValue = i.value() )
106 lValue->setFrameShape( horizontal ? QFrame::VLine : QFrame::HLine );
116 if ( mWidgetList.count() == 0 )