Skip to content
Permalink
Browse files

change user input toolbar to a user input dockwidget

  • Loading branch information
3nids committed May 5, 2015
1 parent 0967510 commit f028b831ff11dfcd26999dc8af417a7d569ed908
@@ -199,7 +199,7 @@
#include "qgstextannotationitem.h"
#include "qgstipgui.h"
#include "qgsundowidget.h"
#include "qgsuserinputtoolbar.h"
#include "qgsuserinputdockwidget.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorfilewriter.h"
#include "qgsvectorlayer.h"
@@ -580,6 +580,10 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
mInfoBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
centralLayout->addWidget( mInfoBar, 0, 0, 1, 1 );

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

//set the focus to the map canvas
mMapCanvas->setFocus();

@@ -638,6 +642,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
addDockWidget( Qt::LeftDockWidgetArea, mAdvancedDigitizingDockWidget );
mAdvancedDigitizingDockWidget->hide();

addDockWidget( Qt::BottomDockWidgetArea, mUserInputDockWidget );

// create the GPS tool on starting QGIS - this is like the browser
mpGpsWidget = new QgsGPSInformationWidget( mMapCanvas );
//create the dock widget
@@ -980,8 +986,6 @@ QgisApp::~QgisApp()
delete mMapTools.mSvgAnnotation;
delete mMapTools.mTextAnnotation;

delete mUserInputToolBar;

delete mpMaptip;

delete mpGpsWidget;
@@ -1731,10 +1735,6 @@ void QgisApp::createToolBars()

// Cad toolbar
mAdvancedDigitizeToolBar->insertAction( mActionUndo, mAdvancedDigitizingDockWidget->enableAction() );

// User Input Tool Bar
mUserInputToolBar = new QgsUserInputToolBar();
addToolBar( mUserInputToolBar, Qt::BottomToolBarArea );
}

void QgisApp::createStatusBar()
@@ -2411,7 +2411,7 @@ QgsMessageBar* QgisApp::messageBar()

void QgisApp::addUserInputWidget( QWidget *widget )
{
mUserInputToolBar->addUserInputWidget( widget );
mUserInputDockWidget->addUserInputWidget( widget );
}


@@ -62,7 +62,7 @@ class QgsPythonUtils;
class QgsRectangle;
class QgsSnappingUtils;
class QgsUndoWidget;
class QgsUserInputToolBar;
class QgsUserInputDockWidget;
class QgsVectorLayer;
class QgsVectorLayerTools;
class QgsDoubleSpinBox;
@@ -1653,7 +1653,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QWidget *mMacrosWarn;

//! A tool bar for user input
QgsUserInputToolBar* mUserInputToolBar;
QgsUserInputDockWidget* mUserInputDockWidget;

QgsVectorLayerTools* mVectorLayerTools;

@@ -227,7 +227,7 @@ qgsslider.cpp
qgssublayersdialog.cpp
qgssvgannotationitem.cpp
qgstextannotationitem.cpp
qgsuserinputtoolbar.cpp
qgsuserinputdockwidget.cpp
qgsvertexmarker.cpp
qgsunitselectionwidget.cpp
)
@@ -332,7 +332,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsslider.h
qgssublayersdialog.h
qgsunitselectionwidget.h
qgsuserinputtoolbar.h
qgsuserinputdockwidget.h

raster/qgsrasterminmaxwidget.h
raster/qgspalettedrendererwidget.h
@@ -466,7 +466,7 @@ SET(QGIS_GUI_HDRS
qgsrubberband.h
qgssvgannotationitem.h
qgstextannotationitem.h
qgsuserinputtoolbar.h
qgsuserinputdockwidget.h
qgsvectorlayertools.h
qgsvertexmarker.h

@@ -0,0 +1,120 @@
/***************************************************************************
qgsuserinputdockwidget.h
--------------------------------------
Date : 04.2015
Copyright : (C) 2015 Denis Rouzaud
Email : denis.rouzaud@gmail.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsuserinputdockwidget.h"

#include <QFrame>
#include <QBoxLayout>

QgsUserInputDockWidget::QgsUserInputDockWidget( QWidget *parent )
: QDockWidget( tr( "User input" ), parent )
, mDockArea( Qt::BottomDockWidgetArea )
{
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 ) ) );

hide();
}

QgsUserInputDockWidget::~QgsUserInputDockWidget()
{
}

void QgsUserInputDockWidget::addUserInputWidget( QWidget *widget )
{
QFrame* line = 0;
if ( mWidgetList.count() > 0 )
{
line = new QFrame( this );
line->setFrameShadow( QFrame::Sunken );
line->setFrameShape( isLayoutHorizontal() ? QFrame::VLine : QFrame::HLine );
mLayout->addWidget( line );
}
mLayout->addWidget( widget );

connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( widgetDestroyed( QObject* ) ) );

mWidgetList.insert( widget, line );

adjustSize();
show();
}

void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
{
if ( obj->isWidgetType() )
{
QWidget* w = qobject_cast<QWidget*>( obj );
QMap<QWidget*, QFrame*>::iterator i = mWidgetList.find( w );
while ( i != mWidgetList.end() )
{
if ( i.value() )
{
i.value()->deleteLater();
}
mWidgetList.remove( i.key() );
++i;
}
}
if ( mWidgetList.count() == 0 )
{
hide();
}
}

void QgsUserInputDockWidget::areaChanged( Qt::DockWidgetArea area )
{
mDockArea = area;

mLayout->setDirection( isLayoutHorizontal() ? 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;
}

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();
}
}
@@ -1,5 +1,5 @@
/***************************************************************************
qgsuserinputtoolbar.h
qgsuserinputdockwidget.h
--------------------------------------
Date : 04.2015
Copyright : (C) 2015 Denis Rouzaud
@@ -15,18 +15,21 @@



#ifndef QGSUSERINPUTTOOLBAR_H
#define QGSUSERINPUTTOOLBAR_H
#ifndef QGSUSERINPUTDOCKWIDGET_H
#define QGSUSERINPUTDOCKWIDGET_H

#include <QToolBar>
#include <QDockWidget>
#include <QMap>

class GUI_EXPORT QgsUserInputToolBar : public QToolBar
class QFrame;
class QBoxLayout;

class GUI_EXPORT QgsUserInputDockWidget : public QDockWidget
{
Q_OBJECT
public:
QgsUserInputToolBar( QWidget* parent = 0 );
~QgsUserInputToolBar();
QgsUserInputDockWidget( QWidget* parent = 0 );
~QgsUserInputDockWidget();

void addUserInputWidget( QWidget* widget );

@@ -36,9 +39,18 @@ class GUI_EXPORT QgsUserInputToolBar : public QToolBar
private slots:
void widgetDestroyed( QObject* obj );

void areaChanged( Qt::DockWidgetArea area );

private:
// list of widget with their corresponding separator
QMap<QWidget*, QAction*> mWidgetList;
bool isLayoutHorizontal();

void createLayout();

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

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

#endif // QGSUSERINPUTTOOLBAR_H
#endif // QGSUSERINPUTDOCKWIDGET_H

This file was deleted.

4 comments on commit f028b83

@3nids

This comment has been minimized.

Copy link
Member Author

@3nids 3nids replied May 5, 2015

@NathanW2 @nyalldawson any comment on the new implementation? I used a dock widget, so it doesn't go large, but still has the flexibility to be moved around.

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied May 6, 2015

@3nids looks much better, thanks! A couple more notes:

  • the default size is really tall, with a lot of empty space. Even when resized the title bar still takes up a lot of room and means there's a lot of wasted space above the widgets. I wonder if the title bar can be hidden to avoid this?
  • Can the panel be hidden from the panels menu? Otherwise there's an action which has no effect there.
  • A background colour would be great as well to make the widget stand out (like how the messagebar is coloured)
@NathanW2

This comment has been minimized.

Copy link
Member

@NathanW2 NathanW2 replied May 6, 2015

@3nids

This comment has been minimized.

Copy link
Member Author

@3nids 3nids replied May 6, 2015

thanks a lot for the comments.
these are partially solved in a7a29ca

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