Skip to content

Commit a7a29ca

Browse files
committed
user input fixes
* fix crash when entering value from widget in rotation map tool use * initially display as floating * use same background color as info bar * fix auto adjust
1 parent b49b492 commit a7a29ca

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

src/app/qgisapp.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
582582

583583
// User Input Dock Widget
584584
mUserInputDockWidget = new QgsUserInputDockWidget( this );
585-
mUserInputDockWidget->setObjectName( "UserInputToolBar" );
585+
mUserInputDockWidget->setObjectName( "UserInputDockWidget" );
586586

587587
//set the focus to the map canvas
588588
mMapCanvas->setFocus();
@@ -642,7 +642,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
642642
addDockWidget( Qt::LeftDockWidgetArea, mAdvancedDigitizingDockWidget );
643643
mAdvancedDigitizingDockWidget->hide();
644644

645-
addDockWidget( Qt::BottomDockWidgetArea, mUserInputDockWidget );
645+
QMainWindow::addDockWidget( Qt::BottomDockWidgetArea, mUserInputDockWidget );
646+
mUserInputDockWidget->setFloating( true );
646647

647648
// create the GPS tool on starting QGIS - this is like the browser
648649
mpGpsWidget = new QgsGPSInformationWidget( mMapCanvas );

src/gui/qgsuserinputdockwidget.cpp

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@
2020

2121
QgsUserInputDockWidget::QgsUserInputDockWidget( QWidget *parent )
2222
: QDockWidget( tr( "User input" ), parent )
23-
, mDockArea( Qt::BottomDockWidgetArea )
23+
, mLayoutHorizontal( true )
2424
{
2525
QWidget* w = new QWidget( this );
2626
mLayout = new QBoxLayout( QBoxLayout::LeftToRight, this );
2727
mLayout->setAlignment( Qt::AlignLeft | Qt::AlignTop );
2828
w->setLayout( mLayout );
2929
setWidget( w );
3030

31-
connect( this, SIGNAL( dockLocationChanged( Qt::DockWidgetArea ) ), this, SLOT( areaChanged( Qt::DockWidgetArea ) ) );
31+
QPalette pal = palette();
32+
pal.setColor( QPalette::Background, QColor( 231, 245, 254 ) );
33+
setPalette( pal );
34+
setAutoFillBackground( true );
3235

36+
connect( this, SIGNAL( dockLocationChanged( Qt::DockWidgetArea ) ), this, SLOT( areaChanged( Qt::DockWidgetArea ) ) );
37+
connect( this, SIGNAL( topLevelChanged( bool ) ), this, SLOT( floatingChanged( bool ) ) );
3338
hide();
3439
}
3540

@@ -44,7 +49,7 @@ void QgsUserInputDockWidget::addUserInputWidget( QWidget *widget )
4449
{
4550
line = new QFrame( this );
4651
line->setFrameShadow( QFrame::Sunken );
47-
line->setFrameShape( isLayoutHorizontal() ? QFrame::VLine : QFrame::HLine );
52+
line->setFrameShape( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
4853
mLayout->addWidget( line );
4954
}
5055
mLayout->addWidget( widget );
@@ -53,8 +58,8 @@ void QgsUserInputDockWidget::addUserInputWidget( QWidget *widget )
5358

5459
mWidgetList.insert( widget, line );
5560

56-
adjustSize();
5761
show();
62+
adjustSize();
5863
}
5964

6065
void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
@@ -73,48 +78,57 @@ void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
7378
++i;
7479
}
7580
}
76-
if ( mWidgetList.count() == 0 )
81+
}
82+
83+
void QgsUserInputDockWidget::areaChanged( Qt::DockWidgetArea area )
84+
{
85+
bool newLayoutHorizontal = area & Qt::BottomDockWidgetArea || area & Qt::TopDockWidgetArea;
86+
if ( mLayoutHorizontal == newLayoutHorizontal )
7787
{
78-
hide();
88+
// no change
89+
adjustSize();
90+
return;
7991
}
92+
mLayoutHorizontal = newLayoutHorizontal;
93+
updateLayoutDirection();
8094
}
8195

82-
void QgsUserInputDockWidget::areaChanged( Qt::DockWidgetArea area )
96+
void QgsUserInputDockWidget::floatingChanged( bool floating )
8397
{
84-
mDockArea = area;
98+
if ( mLayoutHorizontal == floating )
99+
{
100+
adjustSize();
101+
return;
102+
}
103+
mLayoutHorizontal = floating;
104+
updateLayoutDirection();
105+
}
85106

86-
mLayout->setDirection( isLayoutHorizontal() ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom );
107+
void QgsUserInputDockWidget::updateLayoutDirection()
108+
{
109+
mLayout->setDirection( mLayoutHorizontal ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom );
87110

88111
QMap<QWidget*, QFrame*>::iterator i = mWidgetList.begin();
89112
while ( i != mWidgetList.end() )
90113
{
91114
if ( i.value() )
92115
{
93-
i.value()->setFrameShape( isLayoutHorizontal() ? QFrame::VLine : QFrame::HLine );
116+
i.value()->setFrameShape( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
94117
}
95118
++i;
96119
}
97120

98121
adjustSize();
99122
}
100123

101-
bool QgsUserInputDockWidget::isLayoutHorizontal()
102-
{
103-
if ( mDockArea & Qt::BottomDockWidgetArea || mDockArea & Qt::TopDockWidgetArea || mDockArea & Qt::NoDockWidgetArea )
104-
{
105-
return true;
106-
}
107-
else
108-
{
109-
return false;
110-
}
111-
}
112-
113124
void QgsUserInputDockWidget::paintEvent( QPaintEvent * event )
114125
{
115-
QDockWidget::paintEvent( event );
116126
if ( mWidgetList.count() == 0 )
117127
{
118128
hide();
119129
}
130+
else
131+
{
132+
QDockWidget::paintEvent( event );
133+
}
120134
}

src/gui/qgsuserinputdockwidget.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class GUI_EXPORT QgsUserInputDockWidget : public QDockWidget
3131
QgsUserInputDockWidget( QWidget* parent = 0 );
3232
~QgsUserInputDockWidget();
3333

34+
//! add a widget to be displayed in the dock
3435
void addUserInputWidget( QWidget* widget );
3536

3637
protected:
@@ -39,17 +40,19 @@ class GUI_EXPORT QgsUserInputDockWidget : public QDockWidget
3940
private slots:
4041
void widgetDestroyed( QObject* obj );
4142

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

4447
private:
45-
bool isLayoutHorizontal();
46-
4748
void createLayout();
4849

50+
void updateLayoutDirection();
51+
4952
// list of widget with their corresponding line separator
5053
QMap<QWidget*, QFrame*> mWidgetList;
5154

52-
Qt::DockWidgetArea mDockArea;
55+
bool mLayoutHorizontal;
5356
QBoxLayout* mLayout;
5457
};
5558

0 commit comments

Comments
 (0)