Skip to content
Permalink
Browse files

add a new tool bar for user input

rotation map tool now uses it instead of message bar
the idea of the user input toolbar can change (fixes crash when closing user input in message bar)
  • Loading branch information
3nids committed Apr 29, 2015
1 parent 06180fe commit a1dd7e8f8f457af90d6ccf2b67c791a96a7ece26
@@ -199,6 +199,7 @@
#include "qgstextannotationitem.h"
#include "qgstipgui.h"
#include "qgsundowidget.h"
#include "qgsuserinputtoolbar.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorfilewriter.h"
#include "qgsvectorlayer.h"
@@ -979,6 +980,8 @@ QgisApp::~QgisApp()
delete mMapTools.mSvgAnnotation;
delete mMapTools.mTextAnnotation;

delete mUserInputToolBar;

delete mpMaptip;

delete mpGpsWidget;
@@ -1722,13 +1725,16 @@ void QgisApp::createToolBars()
connect( bt, SIGNAL( triggered( QAction * ) ), this, SLOT( toolButtonActionTriggered( QAction * ) ) );

// Help Toolbar

QAction* actionWhatsThis = QWhatsThis::createAction( this );
actionWhatsThis->setIcon( QgsApplication::getThemeIcon( "/mActionWhatsThis.svg" ) );
mHelpToolBar->addAction( actionWhatsThis );

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

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

void QgisApp::createStatusBar()
@@ -2403,6 +2409,11 @@ QgsMessageBar* QgisApp::messageBar()
return mInfoBar;
}

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


void QgisApp::initLayerTreeView()
{
@@ -62,6 +62,7 @@ class QgsPythonUtils;
class QgsRectangle;
class QgsSnappingUtils;
class QgsUndoWidget;
class QgsUserInputToolBar;
class QgsVectorLayer;
class QgsVectorLayerTools;
class QgsDoubleSpinBox;
@@ -194,6 +195,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
/** Return the messageBar object which allows displaying unobtrusive messages to the user.*/
QgsMessageBar *messageBar();

/** Adds a widget to the user input tool br.*/
void addUserInputWidget( QWidget* widget );

//! Set theme (icons)
void setTheme( QString themeName = "default" );

@@ -1648,6 +1652,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsMessageBar *mInfoBar;
QWidget *mMacrosWarn;

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

QgsVectorLayerTools* mVectorLayerTools;

QToolButton* mBtnFilterLegend;
@@ -24,10 +24,10 @@
#include "qgsvertexmarker.h"
#include "qgisapp.h"
#include "qgsspinbox.h"
#include "qgsdoublespinbox.h"

#include <QMouseEvent>
#include <QSettings>
#include <QDoubleSpinBox>
#include <QEvent>
#include <QHBoxLayout>
#include <QKeyEvent>
@@ -49,16 +49,17 @@ QgsAngleMagnetWidget::QgsAngleMagnetWidget( QString label , QWidget *parent )
if ( !label.isNull() )
{
QLabel* lbl = new QLabel( label, this );
lbl->setAlignment( Qt::AlignRight );
lbl->setAlignment( Qt::AlignRight | Qt::AlignCenter );
mLayout->addWidget( lbl );
}

mAngleSpinBox = new QDoubleSpinBox( this );
mAngleSpinBox = new QgsDoubleSpinBox( this );
mAngleSpinBox->setMinimum( -360 );
mAngleSpinBox->setMaximum( 360 );
mAngleSpinBox->setSuffix( QString::fromUtf8( "°" ) );
mAngleSpinBox->setSingleStep( 1 );
mAngleSpinBox->setValue( 0 );
mAngleSpinBox->setShowClearButton( false );
mLayout->addWidget( mAngleSpinBox );

mMagnetSpinBox = new QgsSpinBox( this );
@@ -134,10 +135,8 @@ QgsMapToolRotateFeature::QgsMapToolRotateFeature( QgsMapCanvas* canvas )
, mRotationOffset( 0 )
, mAnchorPoint( 0 )
, mRotationActive( false )
, mRotationBarItem( 0 )
, mRotationWidget( 0 )
{

}

QgsMapToolRotateFeature::~QgsMapToolRotateFeature()
@@ -465,7 +464,7 @@ void QgsMapToolRotateFeature::createRotationWidget()
deleteRotationWidget();

mRotationWidget = new QgsAngleMagnetWidget( "Rotation:" );
mRotationBarItem = QgisApp::instance()->messageBar()->pushWidget( mRotationWidget );
QgisApp::instance()->addUserInputWidget( mRotationWidget );
mRotationWidget->setFocus( Qt::TabFocusReason );

QObject::connect( mRotationWidget, SIGNAL( angleChanged( double ) ), this, SLOT( updateRubberband( double ) ) );
@@ -479,12 +478,8 @@ void QgsMapToolRotateFeature::deleteRotationWidget()
QObject::disconnect( mRotationWidget, SIGNAL( angleChanged( double ) ), this, SLOT( updateRubberband( double ) ) );
QObject::disconnect( mRotationWidget, SIGNAL( angleEditingFinished( double ) ), this, SLOT( applyRotation( double ) ) );
mRotationWidget->releaseKeyboard();
mRotationWidget->deleteLater();
}
if ( mRotationBarItem )
{
QgisApp::instance()->messageBar()->popWidget( mRotationBarItem );
}
mRotationBarItem = 0;
mRotationWidget = 0;
}

@@ -22,12 +22,10 @@
#include "qgsvectorlayer.h"


class QDoubleSpinBox;
class QgsDoubleSpinBox;
class QHBoxLayout;
class QgsSpinBox;
class QgsVertexMarker;
class QgsMessageBarItem;


class APP_EXPORT QgsAngleMagnetWidget : public QWidget
{
@@ -60,7 +58,7 @@ class APP_EXPORT QgsAngleMagnetWidget : public QWidget

private:
QHBoxLayout* mLayout;
QDoubleSpinBox* mAngleSpinBox;
QgsDoubleSpinBox* mAngleSpinBox;
QgsSpinBox* mMagnetSpinBox;
};

@@ -112,8 +110,6 @@ class APP_EXPORT QgsMapToolRotateFeature: public QgsMapToolEdit

bool mRotationActive;

/** Message bar item for the angle magnet widget*/
QgsMessageBarItem* mRotationBarItem;
/** Shows current angle value and allows numerical editing*/
QgsAngleMagnetWidget* mRotationWidget;
};
@@ -227,6 +227,7 @@ qgsslider.cpp
qgssublayersdialog.cpp
qgssvgannotationitem.cpp
qgstextannotationitem.cpp
qgsuserinputtoolbar.cpp
qgsvertexmarker.cpp
qgsunitselectionwidget.cpp
)
@@ -331,6 +332,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsslider.h
qgssublayersdialog.h
qgsunitselectionwidget.h
qgsuserinputtoolbar.h

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

@@ -0,0 +1,82 @@
/***************************************************************************
qgsuserinputtoolbar.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 "qgsuserinputtoolbar.h"

#include <QAction>


QgsUserInputToolBar::QgsUserInputToolBar( QWidget *parent )
: QToolBar( tr( "User input tool bar" ), parent )
{
setAllowedAreas( Qt::BottomToolBarArea | Qt::TopToolBarArea );

// add spacer to align right
QWidget* spacer = new QWidget();
spacer->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
addWidget( spacer );
}

QgsUserInputToolBar::~QgsUserInputToolBar()
{

}

void QgsUserInputToolBar::addUserInputWidget( QWidget *widget )
{
QAction* sep = 0;
if ( mWidgetList.count() > 0 )
{
sep = addSeparator();
}
addWidget( widget );

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

mWidgetList.insert( widget, sep );

show();
}

void QgsUserInputToolBar::widgetDestroyed( QObject *obj )
{
if ( obj->isWidgetType() )
{
QWidget* w = qobject_cast<QWidget*>( obj );
QMap<QWidget*, QAction*>::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 QgsUserInputToolBar::paintEvent(QPaintEvent * event)
{
QToolBar::paintEvent(event);
if ( mWidgetList.count() == 0 )
{
hide();
}
}
@@ -0,0 +1,44 @@
/***************************************************************************
qgsuserinputtoolbar.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. *
* *
***************************************************************************/



#ifndef QGSUSERINPUTTOOLBAR_H
#define QGSUSERINPUTTOOLBAR_H

#include <QToolBar>
#include <QMap>

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

void addUserInputWidget( QWidget* widget );

protected:
void paintEvent(QPaintEvent *event);

private slots:
void widgetDestroyed( QObject* obj );

private:
// list of widget with their corresponding separator
QMap<QWidget*, QAction*> mWidgetList;
};

#endif // QGSUSERINPUTTOOLBAR_H

7 comments on commit a1dd7e8

@3nids

This comment has been minimized.

Copy link
Member Author

@3nids 3nids replied Apr 29, 2015

@nyalldawson @NathanW2 I quickly added this user input tool bar.
it inherits QToolBar: user can move it where he wants.
what do you think?

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Apr 29, 2015

@3nids I think it's on the right track, but I don't like how it behaves as a toolbar (eg, how it extends below the browser/layer panel in the default configuration). The widgets just get lost way to the right of were I'd expect them to be. I think instead it should use the same approach as the messagebar, but just always display at the bottom of the canvas. This would also avoid some oddness like how "user input tool bar" shows in the panels list but can't be activated.

What do you think?

@NathanW2

This comment has been minimized.

Copy link
Member

@NathanW2 NathanW2 replied Apr 29, 2015

@3nids

This comment has been minimized.

Copy link
Member Author

@3nids 3nids replied Apr 30, 2015

Thanks for the feedback.
I will implement it next week then.
By the way, would you allow to have several widgets at once in the bar?
I mean could a plug-in display a widget at a same than a map tool?

@3nids

This comment has been minimized.

Copy link
Member Author

@3nids 3nids replied May 4, 2015

@NathanW2 do you speak about the message bar or about the command bat? If it's the latter was it merged already?

@NathanW2

This comment has been minimized.

Copy link
Member

@NathanW2 NathanW2 replied May 4, 2015

@3nids

This comment has been minimized.

Copy link
Member Author

@3nids 3nids replied May 4, 2015

Thanks, il will have a look at it !

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