QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgsuserinputwidget.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsuserinputwidget.h
3
--------------------------------------
4
Date : 04.2015
5
Copyright : (C) 2015 Denis Rouzaud
6
Email : denis.rouzaud@gmail.com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#include "
qgsuserinputwidget.h
"
17
18
#include <QFrame>
19
#include <QString>
20
21
#include "moc_qgsuserinputwidget.cpp"
22
23
using namespace
Qt::StringLiterals;
24
25
QgsUserInputWidget::QgsUserInputWidget
( QWidget *parent )
26
:
QgsFloatingWidget
( parent ? parent->window() : nullptr )
27
{
28
//TODO add title tr( "User Input Panel" )
29
30
QFrame *f =
new
QFrame();
31
f->setObjectName( u
"mUserInputContainer"
_s );
32
33
QPalette
pal
= palette();
34
pal
.setBrush( backgroundRole(),
pal
.window() );
35
f->setPalette(
pal
);
36
f->setAutoFillBackground(
true
);
37
f->setFrameShape( QFrame::StyledPanel );
38
f->setFrameShadow( QFrame::Plain );
39
40
mLayout =
new
QBoxLayout( QBoxLayout::TopToBottom );
41
mLayout->setAlignment( Qt::AlignRight | Qt::AlignTop );
42
f->setLayout( mLayout );
43
44
QBoxLayout *topLayout =
new
QBoxLayout( QBoxLayout::TopToBottom );
45
topLayout->setContentsMargins( 0, 0, 0, 0 );
46
topLayout->addWidget( f );
47
setLayout( topLayout );
48
49
// this allows the widget to be resized on demand
50
topLayout->setSizeConstraint( QLayout::SetFixedSize );
51
mLayout->setSizeConstraint( QLayout::SetFixedSize );
52
53
setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
54
hide();
55
}
56
57
void
QgsUserInputWidget::addUserInputWidget
( QWidget *widget )
58
{
59
QFrame *line =
nullptr
;
60
if
( mWidgetList.count() > 0 )
61
{
62
line =
new
QFrame(
this
);
63
line->setFrameShadow( QFrame::Sunken );
64
line->setFrameShape( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
65
mLayout->addWidget( line );
66
}
67
mLayout->addWidget( widget );
68
69
connect( widget, &QObject::destroyed,
this
, &QgsUserInputWidget::widgetDestroyed );
70
71
mWidgetList.insert( widget, line );
72
73
show();
74
raise();
75
adjustSize();
76
}
77
78
void
QgsUserInputWidget::widgetDestroyed( QObject *obj )
79
{
80
if
( obj->isWidgetType() )
81
{
82
QWidget *w = qobject_cast<QWidget *>( obj );
83
const
auto
it = mWidgetList.find( w );
84
if
( it != mWidgetList.end() )
85
{
86
if
( QFrame *frame = it.value() )
87
{
88
frame->deleteLater();
89
}
90
mWidgetList.erase( it );
91
}
92
}
93
if
( mWidgetList.count() == 0 )
94
{
95
hide();
96
}
97
}
98
99
void
QgsUserInputWidget::setLayoutDirection( QBoxLayout::Direction direction )
100
{
101
mLayout->setDirection( direction );
102
103
const
bool
horizontal = direction == QBoxLayout::LeftToRight || direction == QBoxLayout::RightToLeft;
104
QMap<QWidget *, QFrame *>::const_iterator i = mWidgetList.constBegin();
105
while
( i != mWidgetList.constEnd() )
106
{
107
if
(
auto
*lValue = i.value() )
108
{
109
lValue->setFrameShape( horizontal ? QFrame::VLine : QFrame::HLine );
110
}
111
++i;
112
}
113
114
adjustSize();
115
}
116
117
void
QgsUserInputWidget::paintEvent
( QPaintEvent *event )
118
{
119
if
( mWidgetList.count() == 0 )
120
{
121
hide();
122
}
123
else
124
{
125
QgsFloatingWidget::paintEvent
( event );
126
}
127
}
QgsFloatingWidget::QgsFloatingWidget
QgsFloatingWidget(QWidget *parent=nullptr)
Constructor for QgsFloatingWidget.
Definition
qgsfloatingwidget.cpp:28
QgsFloatingWidget::paintEvent
void paintEvent(QPaintEvent *e) override
Definition
qgsfloatingwidget.cpp:95
QgsUserInputWidget::paintEvent
void paintEvent(QPaintEvent *event) override
Definition
qgsuserinputwidget.cpp:117
QgsUserInputWidget::QgsUserInputWidget
QgsUserInputWidget(QWidget *parent=nullptr)
Constructor for QgsUserInputWidget.
Definition
qgsuserinputwidget.cpp:25
QgsUserInputWidget::addUserInputWidget
void addUserInputWidget(QWidget *widget)
Add a widget to be displayed in the dock.
Definition
qgsuserinputwidget.cpp:57
pal
Definition
qgsdiagramrenderer.h:51
qgsuserinputwidget.h
Generated on
for QGIS API Documentation by
1.17.0