mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
[snapping widget] add advanced config widget in toolbar fix #16596
This commit is contained in:
parent
42ca70b948
commit
6885da4043
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgsdoublespinbox.h"
|
#include "qgsdoublespinbox.h"
|
||||||
|
#include "qgsfloatingwidget.h"
|
||||||
#include "qgslayertreegroup.h"
|
#include "qgslayertreegroup.h"
|
||||||
#include "qgslayertree.h"
|
#include "qgslayertree.h"
|
||||||
#include "qgslayertreeview.h"
|
#include "qgslayertreeview.h"
|
||||||
@ -91,6 +92,13 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
|
|||||||
}
|
}
|
||||||
connect( mModeButton, &QToolButton::triggered, this, &QgsSnappingWidget::modeButtonTriggered );
|
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
|
// type button
|
||||||
mTypeButton = new QToolButton();
|
mTypeButton = new QToolButton();
|
||||||
mTypeButton->setToolTip( tr( "Snapping Type" ) );
|
mTypeButton->setToolTip( tr( "Snapping Type" ) );
|
||||||
@ -150,6 +158,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
|
|||||||
mEnableTracingAction->setShortcut( tr( "T", "Keyboard shortcut: Enable tracing" ) );
|
mEnableTracingAction->setShortcut( tr( "T", "Keyboard shortcut: Enable tracing" ) );
|
||||||
mEnableTracingAction->setObjectName( QStringLiteral( "EnableTracingAction" ) );
|
mEnableTracingAction->setObjectName( QStringLiteral( "EnableTracingAction" ) );
|
||||||
|
|
||||||
|
// tracing offset
|
||||||
mTracingOffsetSpinBox = new QgsDoubleSpinBox;
|
mTracingOffsetSpinBox = new QgsDoubleSpinBox;
|
||||||
mTracingOffsetSpinBox->setRange( -1000000, 1000000 );
|
mTracingOffsetSpinBox->setRange( -1000000, 1000000 );
|
||||||
mTracingOffsetSpinBox->setDecimals( 6 );
|
mTracingOffsetSpinBox->setDecimals( 6 );
|
||||||
@ -166,18 +175,53 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
|
|||||||
tracingMenu->addAction( widgetAction );
|
tracingMenu->addAction( widgetAction );
|
||||||
mEnableTracingAction->setMenu( tracingMenu );
|
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
|
// layout
|
||||||
if ( mDisplayMode == ToolBar )
|
if ( mDisplayMode == ToolBar )
|
||||||
{
|
{
|
||||||
// hiding widget in a toolbar is not possible, actions are required
|
// hiding widget in a toolbar is not possible, actions are required
|
||||||
tb->addAction( mEnabledAction );
|
tb->addAction( mEnabledAction );
|
||||||
mModeAction = tb->addWidget( mModeButton );
|
mModeAction = tb->addWidget( mModeButton );
|
||||||
|
mAdvancedDropDownAction = tb->addWidget( mAdvancedDropDownButton );
|
||||||
mTypeAction = tb->addWidget( mTypeButton );
|
mTypeAction = tb->addWidget( mTypeButton );
|
||||||
mToleranceAction = tb->addWidget( mToleranceSpinBox );
|
mToleranceAction = tb->addWidget( mToleranceSpinBox );
|
||||||
mUnitAction = tb->addWidget( mUnitsComboBox );
|
mUnitAction = tb->addWidget( mUnitsComboBox );
|
||||||
tb->addAction( mTopologicalEditingAction );
|
tb->addAction( mTopologicalEditingAction );
|
||||||
tb->addAction( mIntersectionSnappingAction );
|
tb->addAction( mIntersectionSnappingAction );
|
||||||
tb->addAction( mEnableTracingAction );
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -210,28 +254,6 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
|
|||||||
layout->setAlignment( Qt::AlignRight );
|
layout->setAlignment( Qt::AlignRight );
|
||||||
layout->setSpacing( mDisplayMode == Widget ? 3 : 0 );
|
layout->setSpacing( mDisplayMode == Widget ? 3 : 0 );
|
||||||
|
|
||||||
mLayerTreeView = new QTreeView();
|
|
||||||
QgsSnappingLayerTreeModel *model = new QgsSnappingLayerTreeModel( mProject, this );
|
|
||||||
model->setLayerTreeModel( new QgsLayerTreeModel( mProject->layerTreeRoot(), model ) );
|
|
||||||
|
|
||||||
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 ) );
|
|
||||||
|
|
||||||
QGridLayout *topLayout = new QGridLayout();
|
QGridLayout *topLayout = new QGridLayout();
|
||||||
topLayout->addLayout( layout, 0, 0, Qt::AlignLeft | Qt::AlignTop );
|
topLayout->addLayout( layout, 0, 0, Qt::AlignLeft | Qt::AlignTop );
|
||||||
topLayout->addWidget( mLayerTreeView, 1, 0 );
|
topLayout->addWidget( mLayerTreeView, 1, 0 );
|
||||||
@ -431,6 +453,13 @@ void QgsSnappingWidget::typeButtonTriggered( QAction *action )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsSnappingWidget::advancedDropDownButtonClicked()
|
||||||
|
{
|
||||||
|
mAdvancedConfigContainer->show();
|
||||||
|
mAdvancedConfigContainer->raise();
|
||||||
|
mAdvancedConfigContainer->adjustSize();
|
||||||
|
}
|
||||||
|
|
||||||
void QgsSnappingWidget::updateToleranceDecimals()
|
void QgsSnappingWidget::updateToleranceDecimals()
|
||||||
{
|
{
|
||||||
if ( mConfig.units() == QgsTolerance::Pixels )
|
if ( mConfig.units() == QgsTolerance::Pixels )
|
||||||
@ -513,3 +542,14 @@ void QgsSnappingWidget::cleanGroup( QgsLayerTreeNode *node )
|
|||||||
Q_FOREACH ( QgsLayerTreeNode *child, toRemove )
|
Q_FOREACH ( QgsLayerTreeNode *child, toRemove )
|
||||||
group->removeChildNode( child );
|
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 );
|
||||||
|
}
|
||||||
|
@ -25,12 +25,14 @@ class QToolButton;
|
|||||||
class QTreeView;
|
class QTreeView;
|
||||||
|
|
||||||
class QgsDoubleSpinBox;
|
class QgsDoubleSpinBox;
|
||||||
|
class QgsFloatingWidget;
|
||||||
class QgsLayerTreeGroup;
|
class QgsLayerTreeGroup;
|
||||||
class QgsLayerTreeNode;
|
class QgsLayerTreeNode;
|
||||||
class QgsLayerTreeView;
|
class QgsLayerTreeView;
|
||||||
class QgsMapCanvas;
|
class QgsMapCanvas;
|
||||||
class QgsProject;
|
class QgsProject;
|
||||||
|
|
||||||
|
|
||||||
#include "qgssnappingconfig.h"
|
#include "qgssnappingconfig.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@ -83,6 +85,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
|
|||||||
//! Returns spin box used to set offset for tracing
|
//! Returns spin box used to set offset for tracing
|
||||||
QgsDoubleSpinBox *tracingOffsetSpinBox() { return mTracingOffsetSpinBox; }
|
QgsDoubleSpinBox *tracingOffsetSpinBox() { return mTracingOffsetSpinBox; }
|
||||||
|
|
||||||
|
bool eventFilter( QObject *obj, QEvent *event ) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void snappingConfigChanged();
|
void snappingConfigChanged();
|
||||||
|
|
||||||
@ -106,6 +110,7 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
|
|||||||
|
|
||||||
void modeButtonTriggered( QAction *action );
|
void modeButtonTriggered( QAction *action );
|
||||||
void typeButtonTriggered( QAction *action );
|
void typeButtonTriggered( QAction *action );
|
||||||
|
void advancedDropDownButtonClicked();
|
||||||
|
|
||||||
//! number of decimals of the tolerance spin box depends on map units
|
//! number of decimals of the tolerance spin box depends on map units
|
||||||
void updateToleranceDecimals();
|
void updateToleranceDecimals();
|
||||||
@ -133,6 +138,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
|
|||||||
QAction *mAllLayersAction = nullptr;
|
QAction *mAllLayersAction = nullptr;
|
||||||
QAction *mActiveLayerAction = nullptr;
|
QAction *mActiveLayerAction = nullptr;
|
||||||
QAction *mAdvancedModeAction = nullptr;
|
QAction *mAdvancedModeAction = nullptr;
|
||||||
|
QToolButton *mAdvancedDropDownButton = nullptr;
|
||||||
|
QAction *mAdvancedDropDownAction = nullptr; // hide widget does not work on toolbar, action needed
|
||||||
QToolButton *mTypeButton = nullptr;
|
QToolButton *mTypeButton = nullptr;
|
||||||
QAction *mTypeAction; // hide widget does not work on toolbar, action needed
|
QAction *mTypeAction; // hide widget does not work on toolbar, action needed
|
||||||
QAction *mVertexAction = nullptr;
|
QAction *mVertexAction = nullptr;
|
||||||
@ -147,6 +154,7 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
|
|||||||
QAction *mEnableTracingAction = nullptr;
|
QAction *mEnableTracingAction = nullptr;
|
||||||
QgsDoubleSpinBox *mTracingOffsetSpinBox = nullptr;
|
QgsDoubleSpinBox *mTracingOffsetSpinBox = nullptr;
|
||||||
QTreeView *mLayerTreeView = nullptr;
|
QTreeView *mLayerTreeView = nullptr;
|
||||||
|
QgsFloatingWidget *mAdvancedConfigContainer;
|
||||||
|
|
||||||
void cleanGroup( QgsLayerTreeNode *node );
|
void cleanGroup( QgsLayerTreeNode *node );
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user