Skip to content
Permalink
Browse files

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
  • Loading branch information
3nids committed May 6, 2015
1 parent b49b492 commit a7a29ca9bd352f621d3ce140b8770aba4f88737f
Showing with 46 additions and 28 deletions.
  1. +3 −2 src/app/qgisapp.cpp
  2. +37 −23 src/gui/qgsuserinputdockwidget.cpp
  3. +6 −3 src/gui/qgsuserinputdockwidget.h
@@ -582,7 +582,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,

// User Input Dock Widget
mUserInputDockWidget = new QgsUserInputDockWidget( this );
mUserInputDockWidget->setObjectName( "UserInputToolBar" );
mUserInputDockWidget->setObjectName( "UserInputDockWidget" );

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

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

// create the GPS tool on starting QGIS - this is like the browser
mpGpsWidget = new QgsGPSInformationWidget( mMapCanvas );
@@ -20,16 +20,21 @@

QgsUserInputDockWidget::QgsUserInputDockWidget( QWidget *parent )
: QDockWidget( tr( "User input" ), parent )
, mDockArea( Qt::BottomDockWidgetArea )
, mLayoutHorizontal( true )
{
QWidget* w = new QWidget( this );
mLayout = new QBoxLayout( QBoxLayout::LeftToRight, this );
mLayout->setAlignment( Qt::AlignLeft | Qt::AlignTop );
w->setLayout( mLayout );
setWidget( w );

connect( this, SIGNAL( dockLocationChanged( Qt::DockWidgetArea ) ), this, SLOT( areaChanged( Qt::DockWidgetArea ) ) );
QPalette pal = palette();
pal.setColor( QPalette::Background, QColor( 231, 245, 254 ) );
setPalette( pal );
setAutoFillBackground( true );

connect( this, SIGNAL( dockLocationChanged( Qt::DockWidgetArea ) ), this, SLOT( areaChanged( Qt::DockWidgetArea ) ) );
connect( this, SIGNAL( topLevelChanged( bool ) ), this, SLOT( floatingChanged( bool ) ) );
hide();
}

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

mWidgetList.insert( widget, line );

adjustSize();
show();
adjustSize();
}

void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
@@ -73,48 +78,57 @@ void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
++i;
}
}
if ( mWidgetList.count() == 0 )
}

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

void QgsUserInputDockWidget::areaChanged( Qt::DockWidgetArea area )
void QgsUserInputDockWidget::floatingChanged( bool floating )
{
mDockArea = area;
if ( mLayoutHorizontal == floating )
{
adjustSize();
return;
}
mLayoutHorizontal = floating;
updateLayoutDirection();
}

mLayout->setDirection( isLayoutHorizontal() ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom );
void QgsUserInputDockWidget::updateLayoutDirection()
{
mLayout->setDirection( mLayoutHorizontal ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom );

QMap<QWidget*, QFrame*>::iterator i = mWidgetList.begin();
while ( i != mWidgetList.end() )
{
if ( i.value() )
{
i.value()->setFrameShape( isLayoutHorizontal() ? QFrame::VLine : QFrame::HLine );
i.value()->setFrameShape( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
}
++i;
}

adjustSize();
}

bool QgsUserInputDockWidget::isLayoutHorizontal()
{
if ( mDockArea & Qt::BottomDockWidgetArea || mDockArea & Qt::TopDockWidgetArea || mDockArea & Qt::NoDockWidgetArea )
{
return true;
}
else
{
return false;
}
}

void QgsUserInputDockWidget::paintEvent( QPaintEvent * event )
{
QDockWidget::paintEvent( event );
if ( mWidgetList.count() == 0 )
{
hide();
}
else
{
QDockWidget::paintEvent( event );
}
}
@@ -31,6 +31,7 @@ class GUI_EXPORT QgsUserInputDockWidget : public QDockWidget
QgsUserInputDockWidget( QWidget* parent = 0 );
~QgsUserInputDockWidget();

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

protected:
@@ -39,17 +40,19 @@ class GUI_EXPORT QgsUserInputDockWidget : public QDockWidget
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:
bool isLayoutHorizontal();

void createLayout();

void updateLayoutDirection();

// list of widget with their corresponding line separator
QMap<QWidget*, QFrame*> mWidgetList;

Qt::DockWidgetArea mDockArea;
bool mLayoutHorizontal;
QBoxLayout* mLayout;
};

0 comments on commit a7a29ca

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