Skip to content

Commit

Permalink
use widgetAction rather than floating widget
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jan 20, 2018
1 parent 6885da4 commit b6ffac3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 67 deletions.
5 changes: 3 additions & 2 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 );

Expand Down
109 changes: 49 additions & 60 deletions src/app/qgssnappingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QToolButton>
#include <QWidgetAction>

#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsdoublespinbox.h"
#include "qgsfloatingwidget.h"
Expand Down Expand Up @@ -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 );
Expand All @@ -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 )
Expand All @@ -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" ) );
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -490,6 +489,7 @@ void QgsSnappingWidget::modeChanged()
mTypeAction->setVisible( !advanced );
mToleranceAction->setVisible( !advanced );
mUnitAction->setVisible( !advanced );
mEditAdvancedConfigAction->setVisible( advanced );
}
else
{
Expand Down Expand Up @@ -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 );
}
6 changes: 1 addition & 5 deletions src/app/qgssnappingwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

0 comments on commit b6ffac3

Please sign in to comment.