Skip to content

Commit

Permalink
add advanced config to offset map tool widget
Browse files Browse the repository at this point in the history
fix #14750
  • Loading branch information
3nids committed Feb 13, 2018
1 parent e1d481f commit 79d224e
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 47 deletions.
87 changes: 50 additions & 37 deletions src/app/qgsmaptooloffsetcurve.cpp
Expand Up @@ -31,13 +31,12 @@
#include "qgssettings.h"
#include "qgisapp.h"

#include "qgisapp.h"
#include "qgslogger.h"

QgsMapToolOffsetCurve::QgsMapToolOffsetCurve( QgsMapCanvas *canvas )
: QgsMapToolEdit( canvas )
, mSnapIndicator( qgis::make_unique< QgsSnapIndicator >( canvas ) )
{
}
{}

QgsMapToolOffsetCurve::~QgsMapToolOffsetCurve()
{
Expand Down Expand Up @@ -241,6 +240,7 @@ void QgsMapToolOffsetCurve::cancel()
{
deleteUserInputWidget();
deleteRubberBandAndGeometry();
mCtrlHeldOnFirstClick = false;
mLayer = nullptr;
}

Expand Down Expand Up @@ -275,10 +275,6 @@ void QgsMapToolOffsetCurve::canvasMoveEvent( QgsMapMouseEvent *e )
mSnapIndicator->setMatch( e->mapPointMatch() );

double offset = calculateOffset( mapPoint );
if ( offset == 0.0 )
{
return;
}

if ( mUserInputWidget )
{
Expand Down Expand Up @@ -356,19 +352,18 @@ void QgsMapToolOffsetCurve::prepareGeometry( QgsVectorLayer *vl, const QgsPointL

void QgsMapToolOffsetCurve::createUserInputWidget()
{
if ( !mCanvas )
{
return;
}

deleteUserInputWidget();

mUserInputWidget = new QgsOffsetUserWidget();
mUserInputWidget->setPolygonMode( QgsWkbTypes::geometryType( mOriginalGeometry.wkbType() ) != QgsWkbTypes::LineGeometry );
QgisApp::instance()->addUserInputWidget( mUserInputWidget );
mUserInputWidget->setFocus( Qt::TabFocusReason );

connect( mUserInputWidget, &QgsOffsetUserWidget::offsetChanged, this, &QgsMapToolOffsetCurve::updateGeometryAndRubberBand );
connect( mUserInputWidget, &QgsOffsetUserWidget::offsetEditingFinished, this, &QgsMapToolOffsetCurve::applyOffset );
connect( mUserInputWidget, &QgsOffsetUserWidget::offsetEditingCanceled, this, &QgsMapToolOffsetCurve::cancel );

connect( mUserInputWidget, &QgsOffsetUserWidget::offsetConfigChanged, this, [ = ] {updateGeometryAndRubberBand( mUserInputWidget->offset() );} );
}

void QgsMapToolOffsetCurve::deleteUserInputWidget()
Expand Down Expand Up @@ -404,19 +399,21 @@ void QgsMapToolOffsetCurve::updateGeometryAndRubberBand( double offset )
return;
}

QgsGeometry offsetGeom;
QgsSettings s;
QgsGeometry::JoinStyle joinStyle = static_cast< QgsGeometry::JoinStyle >( s.value( QStringLiteral( "/qgis/digitizing/offset_join_style" ), 0 ).toInt() );
QgsGeometry::JoinStyle joinStyle = static_cast< QgsGeometry::JoinStyle >( s.value( QStringLiteral( "/qgis/digitizing/offset_join_style" ), QgsGeometry::JoinStyleRound ).toInt() );
int quadSegments = s.value( QStringLiteral( "/qgis/digitizing/offset_quad_seg" ), 8 ).toInt();
double miterLimit = s.value( QStringLiteral( "/qgis/digitizing/offset_miter_limit" ), 5.0 ).toDouble();
QgsGeometry::EndCapStyle capStyle = static_cast< QgsGeometry::EndCapStyle >( s.value( QStringLiteral( "/qgis/digitizing/offset_cap_style" ), QgsGeometry::CapRound ).toInt() );


QgsGeometry offsetGeom;
if ( QgsWkbTypes::geometryType( mOriginalGeometry.wkbType() ) == QgsWkbTypes::LineGeometry )
{
offsetGeom = mManipulatedGeometry.offsetCurve( offset, quadSegments, joinStyle, miterLimit );
}
else
{
offsetGeom = mManipulatedGeometry.buffer( offset, quadSegments, QgsGeometry::CapRound, joinStyle, miterLimit );
offsetGeom = mManipulatedGeometry.buffer( offset, quadSegments, capStyle, joinStyle, miterLimit );
}

if ( !offsetGeom )
Expand All @@ -441,26 +438,41 @@ void QgsMapToolOffsetCurve::updateGeometryAndRubberBand( double offset )
QgsOffsetUserWidget::QgsOffsetUserWidget( QWidget *parent )
: QWidget( parent )
{
mLayout = new QGridLayout( this );
mLayout->setContentsMargins( 0, 0, 0, 0 );
//mLayout->setAlignment( Qt::AlignLeft );
setLayout( mLayout );

QLabel *lbl = new QLabel( tr( "Offset" ), this );
lbl->setAlignment( Qt::AlignRight | Qt::AlignCenter );
mLayout->addWidget( lbl, 0, 0 );

mOffsetSpinBox = new QgsDoubleSpinBox();
mOffsetSpinBox->setMinimum( -99999999 );
mOffsetSpinBox->setMaximum( 99999999 );
mOffsetSpinBox->setDecimals( 6 );
mOffsetSpinBox->setClearValue( 0.0 );
mOffsetSpinBox->setShowClearButton( false );
mLayout->addWidget( mOffsetSpinBox, 0, 1 );
setupUi( this );

// fill comboboxes
mJoinStyleComboBox->addItem( tr( "round" ), QgsGeometry::JoinStyleRound );
mJoinStyleComboBox->addItem( tr( "miter" ), QgsGeometry::JoinStyleMiter );
mJoinStyleComboBox->addItem( tr( "bevel" ), QgsGeometry::JoinStyleBevel );
mCapStyleComboBox->addItem( tr( "round" ), QgsGeometry::CapRound );
mCapStyleComboBox->addItem( tr( "flat" ), QgsGeometry::CapFlat );
mCapStyleComboBox->addItem( tr( "square" ), QgsGeometry::CapSquare );

QgsSettings s;
QgsGeometry::JoinStyle joinStyle = static_cast< QgsGeometry::JoinStyle >( s.value( QStringLiteral( "/qgis/digitizing/offset_join_style" ), QgsGeometry::JoinStyleRound ).toInt() );
int quadSegments = s.value( QStringLiteral( "/qgis/digitizing/offset_quad_seg" ), 8 ).toInt();
double miterLimit = s.value( QStringLiteral( "/qgis/digitizing/offset_miter_limit" ), 5.0 ).toDouble();
QgsGeometry::EndCapStyle capStyle = static_cast< QgsGeometry::EndCapStyle >( s.value( QStringLiteral( "/qgis/digitizing/offset_cap_style" ), QgsGeometry::CapRound ).toInt() );

mJoinStyleComboBox->setCurrentIndex( mJoinStyleComboBox->findData( joinStyle ) );
mQuadrantSpinBox->setValue( quadSegments );
mMiterLimitSpinBox->setValue( miterLimit );
mCapStyleComboBox->setCurrentIndex( mCapStyleComboBox->findData( capStyle ) );

// connect signals
mOffsetSpinBox->installEventFilter( this );
connect( mOffsetSpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsOffsetUserWidget::offsetSpinBoxValueChanged );
connect( mOffsetSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsOffsetUserWidget::offsetChanged );

connect( mJoinStyleComboBox, static_cast < void ( QComboBox::* )( int ) > ( &QComboBox::currentIndexChanged ), this, [ = ] { QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/offset_join_style" ), mJoinStyleComboBox->currentData() ); emit offsetConfigChanged(); } );
connect( mQuadrantSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, [ = ]( const int quadSegments ) { QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/offset_quad_seg" ), quadSegments ); emit offsetConfigChanged(); } );
connect( mMiterLimitSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, [ = ]( const double & miterLimit ) { QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/offset_miter_limit" ), miterLimit ); emit offsetConfigChanged(); } );
connect( mCapStyleComboBox, static_cast < void ( QComboBox::* )( int ) > ( &QComboBox::currentIndexChanged ), this, [ = ] { QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/offset_cap_style" ), mCapStyleComboBox->currentData() ); emit offsetConfigChanged(); } );

bool showAdvanced = s.value( QStringLiteral( "/qgis/digitizing/offset_show_advanced" ), false ).toBool();
mShowAdvancedButton->setChecked( showAdvanced );
mAdvancedConfigWidget->setVisible( showAdvanced );
connect( mShowAdvancedButton, &QToolButton::clicked, mAdvancedConfigWidget, &QWidget::setVisible );
connect( mShowAdvancedButton, &QToolButton::clicked, this, [ = ]( const bool clicked ) {QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/offset_show_advanced" ), clicked );} );

// config focus
setFocusProxy( mOffsetSpinBox );
Expand All @@ -476,6 +488,12 @@ double QgsOffsetUserWidget::offset()
return mOffsetSpinBox->value();
}

void QgsOffsetUserWidget::setPolygonMode( bool polygon )
{
mCapStyleLabel->setEnabled( polygon );
mCapStyleComboBox->setEnabled( polygon );
}

bool QgsOffsetUserWidget::eventFilter( QObject *obj, QEvent *ev )
{
if ( obj == mOffsetSpinBox && ev->type() == QEvent::KeyPress )
Expand All @@ -495,8 +513,3 @@ bool QgsOffsetUserWidget::eventFilter( QObject *obj, QEvent *ev )

return false;
}

void QgsOffsetUserWidget::offsetSpinBoxValueChanged( double offset )
{
emit offsetChanged( offset );
}
15 changes: 5 additions & 10 deletions src/app/qgsmaptooloffsetcurve.h
Expand Up @@ -19,14 +19,15 @@
#include "qgsmaptooledit.h"
#include "qgsgeometry.h"
#include "qgis_app.h"
#include "ui_qgsoffsetuserinputwidget.h"

class QGridLayout;

class QgsSnapIndicator;
class QgsDoubleSpinBox;
class QGraphicsProxyWidget;

class APP_EXPORT QgsOffsetUserWidget : public QWidget
class APP_EXPORT QgsOffsetUserWidget : public QWidget, private Ui::QgsOffsetUserInputBase
{
Q_OBJECT

Expand All @@ -35,25 +36,19 @@ class APP_EXPORT QgsOffsetUserWidget : public QWidget
explicit QgsOffsetUserWidget( QWidget *parent = nullptr );

void setOffset( double offset );

double offset();
QDoubleSpinBox *editor() const {return mOffsetSpinBox;}

QgsDoubleSpinBox *editor() {return mOffsetSpinBox;}
void setPolygonMode( bool polygon );

signals:
void offsetChanged( double offset );
void offsetEditingFinished( double offset, const Qt::KeyboardModifiers &modifiers );
void offsetEditingCanceled();
void offsetConfigChanged();

protected:
bool eventFilter( QObject *obj, QEvent *ev ) override;

private slots:
void offsetSpinBoxValueChanged( double offset );

private:
QGridLayout *mLayout = nullptr;
QgsDoubleSpinBox *mOffsetSpinBox = nullptr;
};

class APP_EXPORT QgsMapToolOffsetCurve: public QgsMapToolEdit
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsuserinputwidget.cpp
Expand Up @@ -40,6 +40,10 @@ QgsUserInputWidget::QgsUserInputWidget( QWidget *parent )
topLayout->addWidget( f );
setLayout( topLayout );

// this allows the widget to be resized on demand
topLayout->setSizeConstraint( QLayout::SetFixedSize );
mLayout->setSizeConstraint( QLayout::SetFixedSize );

setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
hide();
}
Expand Down
169 changes: 169 additions & 0 deletions src/ui/qgsoffsetuserinputwidget.ui
@@ -0,0 +1,169 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsOffsetUserInputBase</class>
<widget class="QWidget" name="QgsOffsetUserInputBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>362</width>
<height>142</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="2">
<widget class="QDoubleSpinBox" name="mOffsetSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<double>-9999999.000000000000000</double>
</property>
<property name="maximum">
<double>999999.989999999990687</double>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Offset</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QToolButton" name="mShowAdvancedButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/settings.svg</normaloff>:/images/themes/default/propertyicons/settings.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QWidget" name="mAdvancedConfigWidget" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Join style</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mJoinStyleComboBox"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Quadrant segments</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QSpinBox" name="mQuadrantSpinBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Miter limit</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="mMiterLimitSpinBox"/>
</item>
<item row="1" column="2">
<widget class="QLabel" name="mCapStyleLabel">
<property name="text">
<string>Cap style</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QComboBox" name="mCapStyleComboBox"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit 79d224e

Please sign in to comment.