Skip to content
Permalink
Browse files

use widgetAction rather than floating widget

  • Loading branch information
3nids committed Jan 18, 2018
1 parent 6885da4 commit b6ffac3f2dddc38a9b6c16cb81255f3653241402
Showing with 53 additions and 67 deletions.
  1. +3 −2 src/app/qgisapp.h
  2. +49 −60 src/app/qgssnappingwidget.cpp
  3. +1 −5 src/app/qgssnappingwidget.h
@@ -939,6 +939,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
void showLayoutManager();

//! shows the snapping Options
void snappingOptions();

protected:

//! Handle state changes (WindowTitleChange)
@@ -1344,8 +1347,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void rotatePointSymbols();
//! activates the offset point symbol tool
void offsetPointSymbol();
//! shows the snapping Options
void snappingOptions();
//! activates the tool
void setMapTool( QgsMapTool *tool, bool clean = false );

@@ -25,6 +25,7 @@
#include <QToolButton>
#include <QWidgetAction>

#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsdoublespinbox.h"
#include "qgsfloatingwidget.h"
@@ -65,6 +66,30 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
setObjectName( QStringLiteral( "SnappingOptionDialog" ) );
}

// Advanced config layer tree view
mLayerTreeView = new QTreeView();
QgsSnappingLayerTreeModel *model = new QgsSnappingLayerTreeModel( mProject, this );
model->setLayerTreeModel( new QgsLayerTreeModel( mProject->layerTreeRoot(), model ) );
// connections
connect( model, &QgsSnappingLayerTreeModel::rowsInserted, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( model, &QgsSnappingLayerTreeModel::modelReset, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( model, &QgsSnappingLayerTreeModel::rowsRemoved, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( project, &QgsProject::readProject, this, [ = ]
{
model->resetLayerTreeModel();
} );
// model->setFlags( 0 );
mLayerTreeView->setModel( model );
mLayerTreeView->resizeColumnToContents( 0 );
mLayerTreeView->header()->show();
mLayerTreeView->setSelectionMode( QAbstractItemView::NoSelection );
// item delegates
mLayerTreeView->setEditTriggers( QAbstractItemView::AllEditTriggers );
mLayerTreeView->setItemDelegate( new QgsSnappingLayerDelegate( mCanvas, this ) );
mLayerTreeView->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
mLayerTreeView->setMinimumWidth( 500 );
mLayerTreeView->resizeColumnToContents( 0 );

// enable button
mEnabledAction = new QAction( this );
mEnabledAction->setCheckable( true );
@@ -84,6 +109,22 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
modeMenu->addAction( mAllLayersAction );
modeMenu->addAction( mActiveLayerAction );
modeMenu->addAction( mAdvancedModeAction );
if ( mDisplayMode == ToolBar )
{
QMenu *advConfigMenu = new QMenu( this );
QWidgetAction *advConfigWidgetAction = new QWidgetAction( advConfigMenu );
advConfigWidgetAction->setDefaultWidget( mLayerTreeView );
advConfigMenu->addAction( advConfigWidgetAction );
mEditAdvancedConfigAction = new QAction( tr( "Edit advanced configuration" ), modeMenu );
mEditAdvancedConfigAction->setMenu( advConfigMenu );

QAction *openDialogAction = new QAction( tr( "Open snapping options" ), modeMenu );
connect( openDialogAction, &QAction::triggered, QgisApp::instance(), &QgisApp::snappingOptions );

modeMenu->addSeparator();
modeMenu->addAction( mEditAdvancedConfigAction );
modeMenu->addAction( openDialogAction );
}
mModeButton->setMenu( modeMenu );
mModeButton->setObjectName( QStringLiteral( "SnappingModeButton" ) );
if ( mDisplayMode == Widget )
@@ -92,13 +133,6 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
}
connect( mModeButton, &QToolButton::triggered, this, &QgsSnappingWidget::modeButtonTriggered );

// advanced drop down button
mAdvancedDropDownButton = new QToolButton();
mAdvancedDropDownButton->setIcon( QIcon( QgsApplication::getThemeIcon( "/mIconSnappingIntersection.svg" ) ) );
mAdvancedDropDownButton->setToolTip( tr( "Avdanced configuration tool" ) );
mAdvancedDropDownButton->setObjectName( QStringLiteral( "AdvancedDropdownButton" ) );
connect( mAdvancedDropDownButton, &QToolButton::clicked, this, &QgsSnappingWidget::advancedDropDownButtonClicked );

// type button
mTypeButton = new QToolButton();
mTypeButton->setToolTip( tr( "Snapping Type" ) );
@@ -175,53 +209,18 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
tracingMenu->addAction( widgetAction );
mEnableTracingAction->setMenu( tracingMenu );

// Advanced config layer tree view
mLayerTreeView = new QTreeView();
QgsSnappingLayerTreeModel *model = new QgsSnappingLayerTreeModel( mProject, this );
model->setLayerTreeModel( new QgsLayerTreeModel( mProject->layerTreeRoot(), model ) );
// connections
connect( model, &QgsSnappingLayerTreeModel::rowsInserted, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( model, &QgsSnappingLayerTreeModel::modelReset, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( model, &QgsSnappingLayerTreeModel::rowsRemoved, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( project, &QgsProject::readProject, this, [ = ]
{
model->resetLayerTreeModel();
} );
// model->setFlags( 0 );
mLayerTreeView->setModel( model );
mLayerTreeView->resizeColumnToContents( 0 );
mLayerTreeView->header()->show();
mLayerTreeView->setSelectionMode( QAbstractItemView::NoSelection );
// item delegates
mLayerTreeView->setEditTriggers( QAbstractItemView::AllEditTriggers );
mLayerTreeView->setItemDelegate( new QgsSnappingLayerDelegate( mCanvas, this ) );


// layout
if ( mDisplayMode == ToolBar )
{
// hiding widget in a toolbar is not possible, actions are required
tb->addAction( mEnabledAction );
mModeAction = tb->addWidget( mModeButton );
mAdvancedDropDownAction = tb->addWidget( mAdvancedDropDownButton );
mTypeAction = tb->addWidget( mTypeButton );
mToleranceAction = tb->addWidget( mToleranceSpinBox );
mUnitAction = tb->addWidget( mUnitsComboBox );
tb->addAction( mTopologicalEditingAction );
tb->addAction( mIntersectionSnappingAction );
tb->addAction( mEnableTracingAction );

// setup floating container widget for advanced config
mAdvancedConfigContainer = new QgsFloatingWidget( parent ? parent->window() : nullptr );
mAdvancedConfigContainer->setAnchorWidget( mAdvancedDropDownButton );
mAdvancedConfigContainer->setAnchorPoint( QgsFloatingWidget::TopMiddle );
mAdvancedConfigContainer->setAnchorWidgetPoint( QgsFloatingWidget::BottomMiddle );
QGridLayout *layout = new QGridLayout();
layout->setContentsMargins( 0, 0, 0, 0 );
layout->addWidget( mLayerTreeView );
mAdvancedConfigContainer->setLayout( layout );
mAdvancedConfigContainer->hide();
mAdvancedConfigContainer->installEventFilter( this );
}
else
{
@@ -411,6 +410,13 @@ void QgsSnappingWidget::onSnappingTreeLayersChanged()

void QgsSnappingWidget::modeButtonTriggered( QAction *action )
{
if ( action != mAllLayersAction &&
action != mActiveLayerAction &&
action != mAdvancedModeAction )
{
return;
}

if ( action != mModeButton->defaultAction() )
{
mModeButton->setDefaultAction( action );
@@ -453,13 +459,6 @@ void QgsSnappingWidget::typeButtonTriggered( QAction *action )
}
}

void QgsSnappingWidget::advancedDropDownButtonClicked()
{
mAdvancedConfigContainer->show();
mAdvancedConfigContainer->raise();
mAdvancedConfigContainer->adjustSize();
}

void QgsSnappingWidget::updateToleranceDecimals()
{
if ( mConfig.units() == QgsTolerance::Pixels )
@@ -490,6 +489,7 @@ void QgsSnappingWidget::modeChanged()
mTypeAction->setVisible( !advanced );
mToleranceAction->setVisible( !advanced );
mUnitAction->setVisible( !advanced );
mEditAdvancedConfigAction->setVisible( advanced );
}
else
{
@@ -542,14 +542,3 @@ void QgsSnappingWidget::cleanGroup( QgsLayerTreeNode *node )
Q_FOREACH ( QgsLayerTreeNode *child, toRemove )
group->removeChildNode( child );
}

bool QgsSnappingWidget::eventFilter( QObject *obj, QEvent *event )
{
if ( event->type() == QEvent::FocusOut &&
( obj == mAdvancedConfigContainer ||
( obj == mLayerTreeView && mDisplayMode == ToolBar ) ) )
{
mAdvancedConfigContainer->hide();
}
return QWidget::eventFilter( obj, event );
}
@@ -85,8 +85,6 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
//! Returns spin box used to set offset for tracing
QgsDoubleSpinBox *tracingOffsetSpinBox() { return mTracingOffsetSpinBox; }

bool eventFilter( QObject *obj, QEvent *event ) override;

signals:
void snappingConfigChanged();

@@ -110,7 +108,6 @@ class APP_EXPORT QgsSnappingWidget : public QWidget

void modeButtonTriggered( QAction *action );
void typeButtonTriggered( QAction *action );
void advancedDropDownButtonClicked();

//! number of decimals of the tolerance spin box depends on map units
void updateToleranceDecimals();
@@ -138,8 +135,7 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
QAction *mAllLayersAction = nullptr;
QAction *mActiveLayerAction = nullptr;
QAction *mAdvancedModeAction = nullptr;
QToolButton *mAdvancedDropDownButton = nullptr;
QAction *mAdvancedDropDownAction = nullptr; // hide widget does not work on toolbar, action needed
QAction *mEditAdvancedConfigAction = nullptr;
QToolButton *mTypeButton = nullptr;
QAction *mTypeAction; // hide widget does not work on toolbar, action needed
QAction *mVertexAction = nullptr;

0 comments on commit b6ffac3

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