Skip to content
Permalink
Browse files

[user input widget] use a floating widget rather than a dock

fix #15177
  • Loading branch information
3nids committed Jan 13, 2018
1 parent 34147af commit 20722f4e5ff0a4c8b6b64c5d9ba55d8a96ee64f9
@@ -16,7 +16,7 @@
%Include qgsrubberband.sip
%Include qgssnapindicator.sip
%Include qgstablewidgetitem.sip
%Include qgsuserinputdockwidget.sip
%Include qgsuserinputwidget.sip
%Include qgsbrowserdockwidget.sip
%Include qgsvertexmarker.sip
%Include qgsabstractdatasourcewidget.sip
@@ -1,7 +1,7 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsuserinputdockwidget.h *
* src/gui/qgsuserinputwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -12,24 +12,24 @@




class QgsUserInputDockWidget : QgsDockWidget
class QgsUserInputWidget : QgsFloatingWidget
{
%Docstring
The QgsUserInputDockWidget class is a dock widget that shall be used to display widgets for user inputs.
The QgsUserInputWidget class is a floating widget that shall be used to display widgets for user inputs.
It can be used by map tools, plugins, etc.
Several widgets can be displayed at once, they will be separated by a separator. Widgets will be either layout horizontally or vertically.
The dock is automatically hidden if it contains no widget.
Several widgets can be displayed at once, they will be separated by a separator.
Widgets will be either layout horizontally or vertically.
The widget is automatically hidden if it contains no widget.
%End

%TypeHeaderCode
#include "qgsuserinputdockwidget.h"
#include "qgsuserinputwidget.h"
%End
public:

QgsUserInputDockWidget( QWidget *parent /TransferThis/ = 0 );
QgsUserInputWidget( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsUserInputDockWidget
Constructor for QgsUserInputWidget
%End

void addUserInputWidget( QWidget *widget );
@@ -48,7 +48,7 @@ Add a widget to be displayed in the dock.
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsuserinputdockwidget.h *
* src/gui/qgsuserinputwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -283,7 +283,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgssymbolselectordialog.h"
#include "qgstextannotation.h"
#include "qgsundowidget.h"
#include "qgsuserinputdockwidget.h"
#include "qgsuserinputwidget.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorfilewriter.h"
#include "qgsvectorlayer.h"
@@ -788,8 +788,12 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

startProfile( QStringLiteral( "User input dock" ) );
// User Input Dock Widget
mUserInputDockWidget = new QgsUserInputDockWidget( this );
mUserInputDockWidget = new QgsUserInputWidget( mMapCanvas );
mUserInputDockWidget->setObjectName( QStringLiteral( "UserInputDockWidget" ) );
mUserInputDockWidget->setAnchorWidget( mMapCanvas );
mUserInputDockWidget->setAnchorWidgetPoint( QgsFloatingWidget::TopRight );
mUserInputDockWidget->setAnchorPoint( QgsFloatingWidget::TopRight );

endProfile();

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

QMainWindow::addDockWidget( Qt::BottomDockWidgetArea, mUserInputDockWidget );
mUserInputDockWidget->setFloating( true );

// create the GPS tool on starting QGIS - this is like the browser
mpGpsWidget = new QgsGpsInformationWidget( mMapCanvas );
//create the dock widget
@@ -94,7 +94,7 @@ class QgsStatusBarScaleWidget;
class QgsTaskManagerStatusBarWidget;
class QgsTransactionGroup;
class QgsUndoWidget;
class QgsUserInputDockWidget;
class QgsUserInputWidget;
class QgsVectorLayer;
class QgsVectorLayerTools;
class QgsWelcomePage;
@@ -2116,7 +2116,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QWidget *mMacrosWarn = nullptr;

//! A tool bar for user input
QgsUserInputDockWidget *mUserInputDockWidget = nullptr;
QgsUserInputWidget *mUserInputDockWidget = nullptr;

QgsVectorLayerTools *mVectorLayerTools = nullptr;

@@ -58,6 +58,7 @@ QgsAngleMagnetWidget::QgsAngleMagnetWidget( const QString &label, QWidget *paren
mAngleSpinBox->setSingleStep( 1 );
mAngleSpinBox->setValue( 0 );
mAngleSpinBox->setShowClearButton( false );
mAngleSpinBox->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
mLayout->addWidget( mAngleSpinBox );

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

// connect signals
@@ -356,7 +356,7 @@ SET(QGIS_GUI_SRCS
qgstextpreview.cpp
qgstreewidgetitem.cpp
qgsunitselectionwidget.cpp
qgsuserinputdockwidget.cpp
qgsuserinputwidget.cpp
qgsvariableeditorwidget.cpp
qgsvertexmarker.cpp
qgsfiledownloaderdialog.cpp
@@ -519,7 +519,7 @@ SET(QGIS_GUI_MOC_HDRS
qgstextpreview.h
qgstreewidgetitem.h
qgsunitselectionwidget.h
qgsuserinputdockwidget.h
qgsuserinputwidget.h
qgsvariableeditorwidget.h
qgsfiledownloaderdialog.h
qgsdatasourcemanagerdialog.h
@@ -734,7 +734,7 @@ SET(QGIS_GUI_HDRS
qgssnapindicator.h
qgssqlcomposerdialog.h
qgstablewidgetitem.h
qgsuserinputdockwidget.h
qgsuserinputwidget.h
qgsbrowserdockwidget.h
qgsbrowserdockwidget_p.h
qgsvertexmarker.h
@@ -1,5 +1,5 @@
/***************************************************************************
qgsuserinputdockwidget.h
qgsuserinputwidget.h
--------------------------------------
Date : 04.2015
Copyright : (C) 2015 Denis Rouzaud
@@ -13,26 +13,38 @@
* *
***************************************************************************/

#include "qgsuserinputdockwidget.h"
#include "qgsuserinputwidget.h"

#include <QFrame>
#include <QBoxLayout>

QgsUserInputDockWidget::QgsUserInputDockWidget( QWidget *parent )
: QgsDockWidget( tr( "User Input Panel" ), parent )
QgsUserInputWidget::QgsUserInputWidget( QWidget *parent )
: QgsFloatingWidget( parent ? parent->window() : nullptr )
{
QWidget *w = new QWidget( nullptr );
mLayout = new QBoxLayout( QBoxLayout::LeftToRight );
mLayout->setAlignment( Qt::AlignLeft | Qt::AlignTop );
w->setLayout( mLayout );
setWidget( w );

connect( this, &QDockWidget::dockLocationChanged, this, &QgsUserInputDockWidget::areaChanged );
connect( this, &QDockWidget::topLevelChanged, this, &QgsUserInputDockWidget::floatingChanged );
//TODO add title tr( "User Input Panel" )

QFrame *f = new QFrame();

QPalette pal = palette();
pal.setBrush( backgroundRole(), pal.window() );
f->setPalette( pal );
f->setAutoFillBackground( true );
f->setFrameShape( QFrame::StyledPanel );
f->setFrameShadow( QFrame::Plain );

mLayout = new QBoxLayout( QBoxLayout::TopToBottom );
mLayout->setAlignment( Qt::AlignRight | Qt::AlignTop );
f->setLayout( mLayout );

QBoxLayout *topLayout = new QBoxLayout( QBoxLayout::TopToBottom );
topLayout->setContentsMargins( 0, 0, 0, 0 );
topLayout->addWidget( f );
setLayout( topLayout );

setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
hide();
}

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

connect( widget, &QObject::destroyed, this, &QgsUserInputDockWidget::widgetDestroyed );
connect( widget, &QObject::destroyed, this, &QgsUserInputWidget::widgetDestroyed );

mWidgetList.insert( widget, line );

show();
adjustSize();
}

void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
void QgsUserInputWidget::widgetDestroyed( QObject *obj )
{
if ( obj->isWidgetType() )
{
@@ -67,57 +79,38 @@ void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
i = mWidgetList.erase( i );
}
}
}

void QgsUserInputDockWidget::areaChanged( Qt::DockWidgetArea area )
{
bool newLayoutHorizontal = area & Qt::BottomDockWidgetArea || area & Qt::TopDockWidgetArea;
if ( mLayoutHorizontal == newLayoutHorizontal )
{
// no change
adjustSize();
return;
}
mLayoutHorizontal = newLayoutHorizontal;
updateLayoutDirection();
}

void QgsUserInputDockWidget::floatingChanged( bool floating )
{
if ( mLayoutHorizontal == floating )
if ( mWidgetList.count() == 0 )
{
adjustSize();
return;
hide();
}
mLayoutHorizontal = floating;
updateLayoutDirection();
}

void QgsUserInputDockWidget::updateLayoutDirection()
void QgsUserInputWidget::setLayoutDirection( QBoxLayout::Direction direction)
{
mLayout->setDirection( mLayoutHorizontal ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom );
mLayout->setDirection( direction );

bool horizontal = direction == QBoxLayout::LeftToRight || direction == QBoxLayout::RightToLeft;
QMap<QWidget *, QFrame *>::const_iterator i = mWidgetList.constBegin();
while ( i != mWidgetList.constEnd() )
{
if ( i.value() )
{
i.value()->setFrameShape( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
i.value()->setFrameShape( horizontal ? QFrame::VLine : QFrame::HLine );
}
++i;
}

adjustSize();
}

void QgsUserInputDockWidget::paintEvent( QPaintEvent *event )
void QgsUserInputWidget::paintEvent( QPaintEvent *event )
{
if ( mWidgetList.count() == 0 )
{
hide();
}
else
{
QgsDockWidget::paintEvent( event );
QgsFloatingWidget::paintEvent( event );
}
}
@@ -1,5 +1,5 @@
/***************************************************************************
qgsuserinputdockwidget.h
qgsuserinputwidget.h
--------------------------------------
Date : 04.2015
Copyright : (C) 2015 Denis Rouzaud
@@ -14,34 +14,35 @@
***************************************************************************/


#ifndef QGSUSERINPUTWIDGET_H
#define QGSUSERINPUTWIDGET_H

#ifndef QGSUSERINPUTDOCKWIDGET_H
#define QGSUSERINPUTDOCKWIDGET_H

#include "qgsdockwidget.h"
#include "qgis.h"
#include <QMap>
#include "qgis_gui.h"
#include "qgsfloatingwidget.h"

#include <QMap>
#include <QBoxLayout>

class QFrame;
class QBoxLayout;
class QFrame;


/**
* \ingroup gui
* \brief The QgsUserInputDockWidget class is a dock widget that shall be used to display widgets for user inputs.
* \brief The QgsUserInputWidget class is a floating widget that shall be used to display widgets for user inputs.
* It can be used by map tools, plugins, etc.
* Several widgets can be displayed at once, they will be separated by a separator. Widgets will be either layout horizontally or vertically.
* The dock is automatically hidden if it contains no widget.
* Several widgets can be displayed at once, they will be separated by a separator.
* Widgets will be either layout horizontally or vertically.
* The widget is automatically hidden if it contains no widget.
*/
class GUI_EXPORT QgsUserInputDockWidget : public QgsDockWidget
class GUI_EXPORT QgsUserInputWidget : public QgsFloatingWidget
{
Q_OBJECT
public:

//! Constructor for QgsUserInputDockWidget
QgsUserInputDockWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
//! Constructor for QgsUserInputWidget
QgsUserInputWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );

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

//! when area change, update the layout according to the new dock location
void areaChanged( Qt::DockWidgetArea area );
void floatingChanged( bool floating );

private:
//! change layout according to dock location
void updateLayoutDirection();
//! change layout direction
void setLayoutDirection( QBoxLayout::Direction direction );

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

#endif // QGSUSERINPUTDOCKWIDGET_H
#endif // QGSUSERINPUTWIDGET_H

0 comments on commit 20722f4

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