Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[snapping widget] add advanced config widget in toolbar fix #16596
  • Loading branch information
3nids committed Jan 20, 2018
1 parent 42ca70b commit 6885da4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 22 deletions.
84 changes: 62 additions & 22 deletions src/app/qgssnappingwidget.cpp
Expand Up @@ -27,6 +27,7 @@

#include "qgsapplication.h"
#include "qgsdoublespinbox.h"
#include "qgsfloatingwidget.h"
#include "qgslayertreegroup.h"
#include "qgslayertree.h"
#include "qgslayertreeview.h"
Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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 );
Expand All @@ -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
{
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
}
8 changes: 8 additions & 0 deletions src/app/qgssnappingwidget.h
Expand Up @@ -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>
Expand Down Expand Up @@ -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();

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

0 comments on commit 6885da4

Please sign in to comment.