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)
This commit is contained in:
Denis Rouzaud 2015-04-29 11:16:45 +02:00
parent 06180fe34d
commit a1dd7e8f8f
7 changed files with 156 additions and 18 deletions

View File

@ -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()
{

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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

View File

@ -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();
}
}

View File

@ -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