Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 a1dd7e8
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 18 deletions.
13 changes: 12 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -979,6 +980,8 @@ QgisApp::~QgisApp()
delete mMapTools.mSvgAnnotation;
delete mMapTools.mTextAnnotation;

delete mUserInputToolBar;

delete mpMaptip;

delete mpGpsWidget;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -2403,6 +2409,11 @@ QgsMessageBar* QgisApp::messageBar()
return mInfoBar;
}

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


void QgisApp::initLayerTreeView()
{
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -62,6 +62,7 @@ class QgsPythonUtils;
class QgsRectangle;
class QgsSnappingUtils;
class QgsUndoWidget;
class QgsUserInputToolBar;
class QgsVectorLayer;
class QgsVectorLayerTools;
class QgsDoubleSpinBox;
Expand Down Expand Up @@ -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" );

Expand Down Expand Up @@ -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;
Expand Down
17 changes: 6 additions & 11 deletions src/app/qgsmaptoolrotatefeature.cpp
Expand Up @@ -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>
Expand All @@ -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 );
Expand Down Expand Up @@ -134,10 +135,8 @@ QgsMapToolRotateFeature::QgsMapToolRotateFeature( QgsMapCanvas* canvas )
, mRotationOffset( 0 )
, mAnchorPoint( 0 )
, mRotationActive( false )
, mRotationBarItem( 0 )
, mRotationWidget( 0 )
{

}

QgsMapToolRotateFeature::~QgsMapToolRotateFeature()
Expand Down Expand Up @@ -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 ) ) );
Expand All @@ -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;
}

Expand Down
8 changes: 2 additions & 6 deletions src/app/qgsmaptoolrotatefeature.h
Expand Up @@ -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
{
Expand Down Expand Up @@ -60,7 +58,7 @@ class APP_EXPORT QgsAngleMagnetWidget : public QWidget

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

Expand Down Expand Up @@ -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;
};
Expand Down
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -227,6 +227,7 @@ qgsslider.cpp
qgssublayersdialog.cpp
qgssvgannotationitem.cpp
qgstextannotationitem.cpp
qgsuserinputtoolbar.cpp
qgsvertexmarker.cpp
qgsunitselectionwidget.cpp
)
Expand Down Expand Up @@ -331,6 +332,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsslider.h
qgssublayersdialog.h
qgsunitselectionwidget.h
qgsuserinputtoolbar.h

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

Expand Down
82 changes: 82 additions & 0 deletions src/gui/qgsuserinputtoolbar.cpp
@@ -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();
}
}
44 changes: 44 additions & 0 deletions src/gui/qgsuserinputtoolbar.h
@@ -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
Copy link
Member Author

@3nids 3nids commented on a1dd7e8 Apr 29, 2015

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

@NathanW2 NathanW2 commented on a1dd7e8 Apr 29, 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 a1dd7e8 Apr 30, 2015

Choose a reason for hiding this comment

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

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

@3nids 3nids commented on a1dd7e8 May 4, 2015

Choose a reason for hiding this comment

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

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

@NathanW2
Copy link
Member

@NathanW2 NathanW2 commented on a1dd7e8 May 4, 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 a1dd7e8 May 4, 2015

Choose a reason for hiding this comment

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

Thanks, il will have a look at it !

Please sign in to comment.