Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
change user input toolbar to a user input dockwidget
  • Loading branch information
3nids committed May 5, 2015
1 parent 0967510 commit f028b83
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 105 deletions.
16 changes: 8 additions & 8 deletions src/app/qgisapp.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -980,8 +986,6 @@ QgisApp::~QgisApp()
delete mMapTools.mSvgAnnotation;
delete mMapTools.mTextAnnotation;

delete mUserInputToolBar;

delete mpMaptip;

delete mpGpsWidget;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -2411,7 +2411,7 @@ QgsMessageBar* QgisApp::messageBar()

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


Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.h
Expand Up @@ -62,7 +62,7 @@ class QgsPythonUtils;
class QgsRectangle;
class QgsSnappingUtils;
class QgsUndoWidget;
class QgsUserInputToolBar;
class QgsUserInputDockWidget;
class QgsVectorLayer;
class QgsVectorLayerTools;
class QgsDoubleSpinBox;
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/gui/CMakeLists.txt
Expand Up @@ -227,7 +227,7 @@ qgsslider.cpp
qgssublayersdialog.cpp
qgssvgannotationitem.cpp
qgstextannotationitem.cpp
qgsuserinputtoolbar.cpp
qgsuserinputdockwidget.cpp
qgsvertexmarker.cpp
qgsunitselectionwidget.cpp
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -466,7 +466,7 @@ SET(QGIS_GUI_HDRS
qgsrubberband.h
qgssvgannotationitem.h
qgstextannotationitem.h
qgsuserinputtoolbar.h
qgsuserinputdockwidget.h
qgsvectorlayertools.h
qgsvertexmarker.h

Expand Down
120 changes: 120 additions & 0 deletions src/gui/qgsuserinputdockwidget.cpp
@@ -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();
}
}
32 changes: 22 additions & 10 deletions src/gui/qgsuserinputtoolbar.h → src/gui/qgsuserinputdockwidget.h
@@ -1,5 +1,5 @@
/***************************************************************************
qgsuserinputtoolbar.h
qgsuserinputdockwidget.h
--------------------------------------
Date : 04.2015
Copyright : (C) 2015 Denis Rouzaud
Expand All @@ -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 );

Expand All @@ -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
82 changes: 0 additions & 82 deletions src/gui/qgsuserinputtoolbar.cpp

This file was deleted.

4 comments on commit f028b83

@3nids
Copy link
Member Author

@3nids 3nids commented on f028b83 May 5, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Member

@NathanW2 NathanW2 commented on f028b83 May 6, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@3nids
Copy link
Member Author

@3nids 3nids commented on f028b83 May 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.