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 "qgsdoublespinbox.h"
|
||||
#include "qgsfloatingwidget.h"
|
||||
#include "qgslayertreegroup.h"
|
||||
#include "qgslayertree.h"
|
||||
#include "qgslayertreeview.h"
|
||||
@ -91,6 +92,13 @@ 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" ) );
|
||||
@ -150,6 +158,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
|
||||
mEnableTracingAction->setShortcut( tr( "T", "Keyboard shortcut: Enable tracing" ) );
|
||||
mEnableTracingAction->setObjectName( QStringLiteral( "EnableTracingAction" ) );
|
||||
|
||||
// tracing offset
|
||||
mTracingOffsetSpinBox = new QgsDoubleSpinBox;
|
||||
mTracingOffsetSpinBox->setRange( -1000000, 1000000 );
|
||||
mTracingOffsetSpinBox->setDecimals( 6 );
|
||||
@ -166,18 +175,53 @@ 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
|
||||
{
|
||||
@ -210,28 +254,6 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
|
||||
layout->setAlignment( Qt::AlignRight );
|
||||
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();
|
||||
topLayout->addLayout( layout, 0, 0, Qt::AlignLeft | Qt::AlignTop );
|
||||
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()
|
||||
{
|
||||
if ( mConfig.units() == QgsTolerance::Pixels )
|
||||
@ -513,3 +542,14 @@ 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 );
|
||||
}
|
||||
|
@ -25,12 +25,14 @@ class QToolButton;
|
||||
class QTreeView;
|
||||
|
||||
class QgsDoubleSpinBox;
|
||||
class QgsFloatingWidget;
|
||||
class QgsLayerTreeGroup;
|
||||
class QgsLayerTreeNode;
|
||||
class QgsLayerTreeView;
|
||||
class QgsMapCanvas;
|
||||
class QgsProject;
|
||||
|
||||
|
||||
#include "qgssnappingconfig.h"
|
||||
|
||||
#include <QWidget>
|
||||
@ -83,6 +85,8 @@ 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();
|
||||
|
||||
@ -106,6 +110,7 @@ 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();
|
||||
@ -133,6 +138,8 @@ 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
|
||||
QToolButton *mTypeButton = nullptr;
|
||||
QAction *mTypeAction; // hide widget does not work on toolbar, action needed
|
||||
QAction *mVertexAction = nullptr;
|
||||
@ -147,6 +154,7 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
|
||||
QAction *mEnableTracingAction = nullptr;
|
||||
QgsDoubleSpinBox *mTracingOffsetSpinBox = nullptr;
|
||||
QTreeView *mLayerTreeView = nullptr;
|
||||
QgsFloatingWidget *mAdvancedConfigContainer;
|
||||
|
||||
void cleanGroup( QgsLayerTreeNode *node );
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user