Skip to content

Commit 20722f4

Browse files
committedJan 16, 2018
[user input widget] use a floating widget rather than a dock
fix #15177
1 parent 34147af commit 20722f4

File tree

8 files changed

+77
-84
lines changed

8 files changed

+77
-84
lines changed
 

‎python/gui/gui_auto.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
%Include qgsrubberband.sip
1717
%Include qgssnapindicator.sip
1818
%Include qgstablewidgetitem.sip
19-
%Include qgsuserinputdockwidget.sip
19+
%Include qgsuserinputwidget.sip
2020
%Include qgsbrowserdockwidget.sip
2121
%Include qgsvertexmarker.sip
2222
%Include qgsabstractdatasourcewidget.sip

‎python/gui/qgsuserinputdockwidget.sip renamed to ‎python/gui/qgsuserinputwidget.sip

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/************************************************************************
22
* This file has been generated automatically from *
33
* *
4-
* src/gui/qgsuserinputdockwidget.h *
4+
* src/gui/qgsuserinputwidget.h *
55
* *
66
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
77
************************************************************************/
@@ -12,24 +12,24 @@
1212

1313

1414

15-
16-
class QgsUserInputDockWidget : QgsDockWidget
15+
class QgsUserInputWidget : QgsFloatingWidget
1716
{
1817
%Docstring
19-
The QgsUserInputDockWidget class is a dock widget that shall be used to display widgets for user inputs.
18+
The QgsUserInputWidget class is a floating widget that shall be used to display widgets for user inputs.
2019
It can be used by map tools, plugins, etc.
21-
Several widgets can be displayed at once, they will be separated by a separator. Widgets will be either layout horizontally or vertically.
22-
The dock is automatically hidden if it contains no widget.
20+
Several widgets can be displayed at once, they will be separated by a separator.
21+
Widgets will be either layout horizontally or vertically.
22+
The widget is automatically hidden if it contains no widget.
2323
%End
2424

2525
%TypeHeaderCode
26-
#include "qgsuserinputdockwidget.h"
26+
#include "qgsuserinputwidget.h"
2727
%End
2828
public:
2929

30-
QgsUserInputDockWidget( QWidget *parent /TransferThis/ = 0 );
30+
QgsUserInputWidget( QWidget *parent /TransferThis/ = 0 );
3131
%Docstring
32-
Constructor for QgsUserInputDockWidget
32+
Constructor for QgsUserInputWidget
3333
%End
3434

3535
void addUserInputWidget( QWidget *widget );
@@ -48,7 +48,7 @@ Add a widget to be displayed in the dock.
4848
/************************************************************************
4949
* This file has been generated automatically from *
5050
* *
51-
* src/gui/qgsuserinputdockwidget.h *
51+
* src/gui/qgsuserinputwidget.h *
5252
* *
5353
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
5454
************************************************************************/

‎src/app/qgisapp.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
283283
#include "qgssymbolselectordialog.h"
284284
#include "qgstextannotation.h"
285285
#include "qgsundowidget.h"
286-
#include "qgsuserinputdockwidget.h"
286+
#include "qgsuserinputwidget.h"
287287
#include "qgsvectordataprovider.h"
288288
#include "qgsvectorfilewriter.h"
289289
#include "qgsvectorlayer.h"
@@ -788,8 +788,12 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
788788

789789
startProfile( QStringLiteral( "User input dock" ) );
790790
// User Input Dock Widget
791-
mUserInputDockWidget = new QgsUserInputDockWidget( this );
791+
mUserInputDockWidget = new QgsUserInputWidget( mMapCanvas );
792792
mUserInputDockWidget->setObjectName( QStringLiteral( "UserInputDockWidget" ) );
793+
mUserInputDockWidget->setAnchorWidget( mMapCanvas );
794+
mUserInputDockWidget->setAnchorWidgetPoint( QgsFloatingWidget::TopRight );
795+
mUserInputDockWidget->setAnchorPoint( QgsFloatingWidget::TopRight );
796+
793797
endProfile();
794798

795799
//set the focus to the map canvas
@@ -959,9 +963,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
959963
addDockWidget( Qt::LeftDockWidgetArea, mBookMarksDockWidget );
960964
mBookMarksDockWidget->hide();
961965

962-
QMainWindow::addDockWidget( Qt::BottomDockWidgetArea, mUserInputDockWidget );
963-
mUserInputDockWidget->setFloating( true );
964-
965966
// create the GPS tool on starting QGIS - this is like the browser
966967
mpGpsWidget = new QgsGpsInformationWidget( mMapCanvas );
967968
//create the dock widget

‎src/app/qgisapp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class QgsStatusBarScaleWidget;
9494
class QgsTaskManagerStatusBarWidget;
9595
class QgsTransactionGroup;
9696
class QgsUndoWidget;
97-
class QgsUserInputDockWidget;
97+
class QgsUserInputWidget;
9898
class QgsVectorLayer;
9999
class QgsVectorLayerTools;
100100
class QgsWelcomePage;
@@ -2116,7 +2116,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
21162116
QWidget *mMacrosWarn = nullptr;
21172117

21182118
//! A tool bar for user input
2119-
QgsUserInputDockWidget *mUserInputDockWidget = nullptr;
2119+
QgsUserInputWidget *mUserInputDockWidget = nullptr;
21202120

21212121
QgsVectorLayerTools *mVectorLayerTools = nullptr;
21222122

‎src/app/qgsmaptoolrotatefeature.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ QgsAngleMagnetWidget::QgsAngleMagnetWidget( const QString &label, QWidget *paren
5858
mAngleSpinBox->setSingleStep( 1 );
5959
mAngleSpinBox->setValue( 0 );
6060
mAngleSpinBox->setShowClearButton( false );
61+
mAngleSpinBox->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
6162
mLayout->addWidget( mAngleSpinBox );
6263

6364
mMagnetSpinBox = new QgsSpinBox( this );
@@ -68,6 +69,7 @@ QgsAngleMagnetWidget::QgsAngleMagnetWidget( const QString &label, QWidget *paren
6869
mMagnetSpinBox->setSingleStep( 15 );
6970
mMagnetSpinBox->setValue( 0 );
7071
mMagnetSpinBox->setClearValue( 0, tr( "No snapping" ) );
72+
mMagnetSpinBox->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
7173
mLayout->addWidget( mMagnetSpinBox );
7274

7375
// connect signals

‎src/gui/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ SET(QGIS_GUI_SRCS
356356
qgstextpreview.cpp
357357
qgstreewidgetitem.cpp
358358
qgsunitselectionwidget.cpp
359-
qgsuserinputdockwidget.cpp
359+
qgsuserinputwidget.cpp
360360
qgsvariableeditorwidget.cpp
361361
qgsvertexmarker.cpp
362362
qgsfiledownloaderdialog.cpp
@@ -519,7 +519,7 @@ SET(QGIS_GUI_MOC_HDRS
519519
qgstextpreview.h
520520
qgstreewidgetitem.h
521521
qgsunitselectionwidget.h
522-
qgsuserinputdockwidget.h
522+
qgsuserinputwidget.h
523523
qgsvariableeditorwidget.h
524524
qgsfiledownloaderdialog.h
525525
qgsdatasourcemanagerdialog.h
@@ -734,7 +734,7 @@ SET(QGIS_GUI_HDRS
734734
qgssnapindicator.h
735735
qgssqlcomposerdialog.h
736736
qgstablewidgetitem.h
737-
qgsuserinputdockwidget.h
737+
qgsuserinputwidget.h
738738
qgsbrowserdockwidget.h
739739
qgsbrowserdockwidget_p.h
740740
qgsvertexmarker.h
Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgsuserinputdockwidget.h
2+
qgsuserinputwidget.h
33
--------------------------------------
44
Date : 04.2015
55
Copyright : (C) 2015 Denis Rouzaud
@@ -13,26 +13,38 @@
1313
* *
1414
***************************************************************************/
1515

16-
#include "qgsuserinputdockwidget.h"
16+
#include "qgsuserinputwidget.h"
1717

1818
#include <QFrame>
19-
#include <QBoxLayout>
2019

21-
QgsUserInputDockWidget::QgsUserInputDockWidget( QWidget *parent )
22-
: QgsDockWidget( tr( "User Input Panel" ), parent )
20+
QgsUserInputWidget::QgsUserInputWidget( QWidget *parent )
21+
: QgsFloatingWidget( parent ? parent->window() : nullptr )
2322
{
24-
QWidget *w = new QWidget( nullptr );
25-
mLayout = new QBoxLayout( QBoxLayout::LeftToRight );
26-
mLayout->setAlignment( Qt::AlignLeft | Qt::AlignTop );
27-
w->setLayout( mLayout );
28-
setWidget( w );
29-
30-
connect( this, &QDockWidget::dockLocationChanged, this, &QgsUserInputDockWidget::areaChanged );
31-
connect( this, &QDockWidget::topLevelChanged, this, &QgsUserInputDockWidget::floatingChanged );
23+
//TODO add title tr( "User Input Panel" )
24+
25+
QFrame *f = new QFrame();
26+
27+
QPalette pal = palette();
28+
pal.setBrush( backgroundRole(), pal.window() );
29+
f->setPalette( pal );
30+
f->setAutoFillBackground( true );
31+
f->setFrameShape( QFrame::StyledPanel );
32+
f->setFrameShadow( QFrame::Plain );
33+
34+
mLayout = new QBoxLayout( QBoxLayout::TopToBottom );
35+
mLayout->setAlignment( Qt::AlignRight | Qt::AlignTop );
36+
f->setLayout( mLayout );
37+
38+
QBoxLayout *topLayout = new QBoxLayout( QBoxLayout::TopToBottom );
39+
topLayout->setContentsMargins( 0, 0, 0, 0 );
40+
topLayout->addWidget( f );
41+
setLayout( topLayout );
42+
43+
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
3244
hide();
3345
}
3446

35-
void QgsUserInputDockWidget::addUserInputWidget( QWidget *widget )
47+
void QgsUserInputWidget::addUserInputWidget( QWidget *widget )
3648
{
3749
QFrame *line = nullptr;
3850
if ( mWidgetList.count() > 0 )
@@ -44,15 +56,15 @@ void QgsUserInputDockWidget::addUserInputWidget( QWidget *widget )
4456
}
4557
mLayout->addWidget( widget );
4658

47-
connect( widget, &QObject::destroyed, this, &QgsUserInputDockWidget::widgetDestroyed );
59+
connect( widget, &QObject::destroyed, this, &QgsUserInputWidget::widgetDestroyed );
4860

4961
mWidgetList.insert( widget, line );
5062

5163
show();
5264
adjustSize();
5365
}
5466

55-
void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
67+
void QgsUserInputWidget::widgetDestroyed( QObject *obj )
5668
{
5769
if ( obj->isWidgetType() )
5870
{
@@ -67,57 +79,38 @@ void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
6779
i = mWidgetList.erase( i );
6880
}
6981
}
70-
}
71-
72-
void QgsUserInputDockWidget::areaChanged( Qt::DockWidgetArea area )
73-
{
74-
bool newLayoutHorizontal = area & Qt::BottomDockWidgetArea || area & Qt::TopDockWidgetArea;
75-
if ( mLayoutHorizontal == newLayoutHorizontal )
76-
{
77-
// no change
78-
adjustSize();
79-
return;
80-
}
81-
mLayoutHorizontal = newLayoutHorizontal;
82-
updateLayoutDirection();
83-
}
84-
85-
void QgsUserInputDockWidget::floatingChanged( bool floating )
86-
{
87-
if ( mLayoutHorizontal == floating )
82+
if ( mWidgetList.count() == 0 )
8883
{
89-
adjustSize();
90-
return;
84+
hide();
9185
}
92-
mLayoutHorizontal = floating;
93-
updateLayoutDirection();
9486
}
9587

96-
void QgsUserInputDockWidget::updateLayoutDirection()
88+
void QgsUserInputWidget::setLayoutDirection( QBoxLayout::Direction direction)
9789
{
98-
mLayout->setDirection( mLayoutHorizontal ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom );
90+
mLayout->setDirection( direction );
9991

92+
bool horizontal = direction == QBoxLayout::LeftToRight || direction == QBoxLayout::RightToLeft;
10093
QMap<QWidget *, QFrame *>::const_iterator i = mWidgetList.constBegin();
10194
while ( i != mWidgetList.constEnd() )
10295
{
10396
if ( i.value() )
10497
{
105-
i.value()->setFrameShape( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
98+
i.value()->setFrameShape( horizontal ? QFrame::VLine : QFrame::HLine );
10699
}
107100
++i;
108101
}
109102

110103
adjustSize();
111104
}
112105

113-
void QgsUserInputDockWidget::paintEvent( QPaintEvent *event )
106+
void QgsUserInputWidget::paintEvent( QPaintEvent *event )
114107
{
115108
if ( mWidgetList.count() == 0 )
116109
{
117110
hide();
118111
}
119112
else
120113
{
121-
QgsDockWidget::paintEvent( event );
114+
QgsFloatingWidget::paintEvent( event );
122115
}
123116
}
Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgsuserinputdockwidget.h
2+
qgsuserinputwidget.h
33
--------------------------------------
44
Date : 04.2015
55
Copyright : (C) 2015 Denis Rouzaud
@@ -14,34 +14,35 @@
1414
***************************************************************************/
1515

1616

17+
#ifndef QGSUSERINPUTWIDGET_H
18+
#define QGSUSERINPUTWIDGET_H
1719

18-
#ifndef QGSUSERINPUTDOCKWIDGET_H
19-
#define QGSUSERINPUTDOCKWIDGET_H
20-
21-
#include "qgsdockwidget.h"
2220
#include "qgis.h"
23-
#include <QMap>
2421
#include "qgis_gui.h"
22+
#include "qgsfloatingwidget.h"
2523

24+
#include <QMap>
25+
#include <QBoxLayout>
2626

27-
class QFrame;
2827
class QBoxLayout;
28+
class QFrame;
2929

3030

3131
/**
3232
* \ingroup gui
33-
* \brief The QgsUserInputDockWidget class is a dock widget that shall be used to display widgets for user inputs.
33+
* \brief The QgsUserInputWidget class is a floating widget that shall be used to display widgets for user inputs.
3434
* It can be used by map tools, plugins, etc.
35-
* Several widgets can be displayed at once, they will be separated by a separator. Widgets will be either layout horizontally or vertically.
36-
* The dock is automatically hidden if it contains no widget.
35+
* Several widgets can be displayed at once, they will be separated by a separator.
36+
* Widgets will be either layout horizontally or vertically.
37+
* The widget is automatically hidden if it contains no widget.
3738
*/
38-
class GUI_EXPORT QgsUserInputDockWidget : public QgsDockWidget
39+
class GUI_EXPORT QgsUserInputWidget : public QgsFloatingWidget
3940
{
4041
Q_OBJECT
4142
public:
4243

43-
//! Constructor for QgsUserInputDockWidget
44-
QgsUserInputDockWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
44+
//! Constructor for QgsUserInputWidget
45+
QgsUserInputWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
4546

4647
/**
4748
* Add a widget to be displayed in the dock.
@@ -56,13 +57,9 @@ class GUI_EXPORT QgsUserInputDockWidget : public QgsDockWidget
5657
private slots:
5758
void widgetDestroyed( QObject *obj );
5859

59-
//! when area change, update the layout according to the new dock location
60-
void areaChanged( Qt::DockWidgetArea area );
61-
void floatingChanged( bool floating );
62-
6360
private:
64-
//! change layout according to dock location
65-
void updateLayoutDirection();
61+
//! change layout direction
62+
void setLayoutDirection( QBoxLayout::Direction direction );
6663

6764
// list of widget with their corresponding line separator
6865
QMap<QWidget *, QFrame *> mWidgetList;
@@ -71,4 +68,4 @@ class GUI_EXPORT QgsUserInputDockWidget : public QgsDockWidget
7168
QBoxLayout *mLayout = nullptr;
7269
};
7370

74-
#endif // QGSUSERINPUTDOCKWIDGET_H
71+
#endif // QGSUSERINPUTWIDGET_H

0 commit comments

Comments
 (0)
Please sign in to comment.