Skip to content

Commit

Permalink
Merge pull request #3427 from nyalldawson/inline_map_unit
Browse files Browse the repository at this point in the history
[FEATURE] Make map unit scaling dialog show inline in style dock
  • Loading branch information
nyalldawson committed Aug 23, 2016
2 parents 005147b + 5735be1 commit 5d38dcb
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 137 deletions.
91 changes: 86 additions & 5 deletions python/gui/qgsunitselectionwidget.sip
@@ -1,16 +1,87 @@
/** Dialog allowing the user to choose the minimum and maximum scale of an object in map units */
/** \class QgsMapUnitScaleWidget
* \ingroup gui
* A widget which allows the user to choose the minimum and maximum scale of an object in map units
* and millimetres. This widget is designed to allow users to edit the properties of a
* QgsMapUnitScale object.
* \note added in QGIS 3.0
* \see QgsMapUnitScaleDialog
* \see QgsUnitSelectionWidget
*/
class QgsMapUnitScaleWidget : QgsPanelWidget
{
%TypeHeaderCode
#include <qgsunitselectionwidget.h>
%End
public:

/** Constructor for QgsMapUnitScaleWidget.
* @param parent parent widget
*/
QgsMapUnitScaleWidget( QWidget* parent /TransferThis/ = nullptr );

/** Returns a QgsMapUnitScale representing the settings shown in the
* widget.
* @see setMapUnitScale()
* @see mapUnitScaleChanged()
*/
QgsMapUnitScale mapUnitScale() const;

/** Updates the widget to reflect the settings from the specified
* QgsMapUnitScale object.
* @param scale map unit scale to show in widget
* @see mapUnitScale()
* @see mapUnitScaleChanged()
*/
void setMapUnitScale( const QgsMapUnitScale& scale );

/** Sets the map canvas associated with the widget. This allows the
* widget to retrieve the current map scale from the canvas.
* @param canvas map canvas
*/
void setMapCanvas( QgsMapCanvas* canvas );

signals:

/** Emitted when the settings in the widget are modified.
* @param scale QgsMapUnitScale reflecting new settings from the widget
*/
void mapUnitScaleChanged( const QgsMapUnitScale& scale );

};


/** \class QgsMapUnitScaleDialog
* \ingroup gui
* A dialog which allows the user to choose the minimum and maximum scale of an object in map units
* and millimetres. This dialog is designed to allow users to edit the properties of a
* QgsMapUnitScale object.
* \see QgsMapUnitScaleWidget
* \see QgsUnitSelectionWidget
*/
class QgsMapUnitScaleDialog : QDialog
{
%TypeHeaderCode
#include <qgsunitselectionwidget.h>
%End

public:

/** Constructor for QgsMapUnitScaleDialog.
* @param parent parent widget
*/
QgsMapUnitScaleDialog( QWidget* parent /TransferThis/ = 0);

/** Returns the map unit scale */
/** Returns a QgsMapUnitScale representing the settings shown in the
* dialog.
* @see setMapUnitScale()
*/
QgsMapUnitScale getMapUnitScale() const;
/** Sets the map unit scale */

/** Updates the dialog to reflect the settings from the specified
* QgsMapUnitScale object.
* @param scale map unit scale to show in dialog
* @see mapUnitScale()
*/
void setMapUnitScale( const QgsMapUnitScale& scale );

/** Sets the map canvas associated with the dialog. This allows the dialog to retrieve the current
Expand All @@ -22,15 +93,25 @@ class QgsMapUnitScaleDialog : QDialog

};

/** Widget displaying a combobox allowing the user to choose between millimeter and map units
* If the user chooses map units, a button appears allowing the specification of minimum and maximum scale */
/** \class QgsUnitSelectionWidget
* \ingroup gui
* A widget displaying a combobox allowing the user to choose between various display units,
* such as millimeters or map unit. If the user chooses map units, a button appears allowing
* adjustment of minimum and maximum scaling.
* \see QgsMapUnitScaleWidget
* \see QgsMapUnitScaleDialog
*/
class QgsUnitSelectionWidget : QWidget
{
%TypeHeaderCode
#include <qgsunitselectionwidget.h>
%End

public:

/** Constructor for QgsUnitSelectionWidget.
* @param parent parent widget
*/
QgsUnitSelectionWidget( QWidget* parent /TransferThis/ = 0 );

/** Sets the units which the user can choose from in the combobox.
Expand Down
105 changes: 90 additions & 15 deletions src/gui/qgsunitselectionwidget.cpp
Expand Up @@ -17,9 +17,11 @@
***************************************************************************/

#include "qgsunitselectionwidget.h"
#include <QDialogButtonBox>

QgsMapUnitScaleDialog::QgsMapUnitScaleDialog( QWidget* parent )
: QDialog( parent )
QgsMapUnitScaleWidget::QgsMapUnitScaleWidget( QWidget* parent )
: QgsPanelWidget( parent )
, mBlockSignals( true )
{
setupUi( this );
mComboBoxMinScale->setScale( 0.0000001 );
Expand All @@ -34,10 +36,24 @@ QgsMapUnitScaleDialog::QgsMapUnitScaleDialog( QWidget* parent )

connect( mCheckBoxMinSize, SIGNAL( toggled( bool ) ), mSpinBoxMinSize, SLOT( setEnabled( bool ) ) );
connect( mCheckBoxMaxSize, SIGNAL( toggled( bool ) ), mSpinBoxMaxSize, SLOT( setEnabled( bool ) ) );

// notification of setting changes
connect( mCheckBoxMinScale, SIGNAL( toggled( bool ) ), this, SLOT( settingsChanged() ) );
connect( mCheckBoxMaxScale, SIGNAL( toggled( bool ) ), this, SLOT( settingsChanged() ) );
connect( mComboBoxMinScale, SIGNAL( scaleChanged( double ) ), this, SLOT( settingsChanged() ) );
connect( mComboBoxMaxScale, SIGNAL( scaleChanged( double ) ), this, SLOT( settingsChanged() ) );
connect( mCheckBoxMinSize, SIGNAL( toggled( bool ) ), this, SLOT( settingsChanged() ) );
connect( mCheckBoxMaxSize, SIGNAL( toggled( bool ) ), this, SLOT( settingsChanged() ) );
connect( mSpinBoxMinSize, SIGNAL( valueChanged( double ) ), this, SLOT( settingsChanged() ) );
connect( mSpinBoxMaxSize, SIGNAL( valueChanged( double ) ), this, SLOT( settingsChanged() ) );
mBlockSignals = false;
}

void QgsMapUnitScaleDialog::setMapUnitScale( const QgsMapUnitScale &scale )
void QgsMapUnitScaleWidget::setMapUnitScale( const QgsMapUnitScale &scale )
{
// can't block signals on the widgets themselves, some use them to update
// internal states
mBlockSignals = true;
mComboBoxMinScale->setScale( scale.minScale > 0.0 ? scale.minScale : 0.0000001 );
mCheckBoxMinScale->setChecked( scale.minScale > 0.0 );
mComboBoxMinScale->setEnabled( scale.minScale > 0.0 );
Expand All @@ -52,17 +68,20 @@ void QgsMapUnitScaleDialog::setMapUnitScale( const QgsMapUnitScale &scale )
mCheckBoxMaxSize->setChecked( scale.maxSizeMMEnabled );
mSpinBoxMaxSize->setEnabled( scale.maxSizeMMEnabled );
mSpinBoxMaxSize->setValue( scale.maxSizeMM );
mBlockSignals = false;

settingsChanged();
}

void QgsMapUnitScaleDialog::setMapCanvas( QgsMapCanvas *canvas )
void QgsMapUnitScaleWidget::setMapCanvas( QgsMapCanvas *canvas )
{
mComboBoxMinScale->setMapCanvas( canvas );
mComboBoxMinScale->setShowCurrentScaleButton( true );
mComboBoxMaxScale->setMapCanvas( canvas );
mComboBoxMaxScale->setShowCurrentScaleButton( true );
}

void QgsMapUnitScaleDialog::configureMinComboBox()
void QgsMapUnitScaleWidget::configureMinComboBox()
{
mComboBoxMinScale->setEnabled( mCheckBoxMinScale->isChecked() );
if ( mCheckBoxMinScale->isChecked() && mComboBoxMinScale->scale() > mComboBoxMaxScale->scale() )
Expand All @@ -71,7 +90,7 @@ void QgsMapUnitScaleDialog::configureMinComboBox()
}
}

void QgsMapUnitScaleDialog::configureMaxComboBox()
void QgsMapUnitScaleWidget::configureMaxComboBox()
{
mComboBoxMaxScale->setEnabled( mCheckBoxMaxScale->isChecked() );
if ( mCheckBoxMaxScale->isChecked() && mComboBoxMaxScale->scale() < mComboBoxMinScale->scale() )
Expand All @@ -80,7 +99,15 @@ void QgsMapUnitScaleDialog::configureMaxComboBox()
}
}

QgsMapUnitScale QgsMapUnitScaleDialog::getMapUnitScale() const
void QgsMapUnitScaleWidget::settingsChanged()
{
if ( mBlockSignals )
return;

emit mapUnitScaleChanged( mapUnitScale() );
}

QgsMapUnitScale QgsMapUnitScaleWidget::mapUnitScale() const
{
QgsMapUnitScale scale;
scale.minScale = mCheckBoxMinScale->isChecked() ? mComboBoxMinScale->scale() : 0;
Expand All @@ -92,11 +119,14 @@ QgsMapUnitScale QgsMapUnitScaleDialog::getMapUnitScale() const
return scale;
}





QgsUnitSelectionWidget::QgsUnitSelectionWidget( QWidget *parent )
: QWidget( parent )
{
mMapUnitIdx = -1;
mUnitScaleDialog = new QgsMapUnitScaleDialog( this );

setupUi( this );
mMapScaleButton->setVisible( false );
Expand Down Expand Up @@ -175,21 +205,31 @@ void QgsUnitSelectionWidget::setUnit( QgsUnitTypes::RenderUnit unit )

void QgsUnitSelectionWidget::setMapCanvas( QgsMapCanvas *canvas )
{
mUnitScaleDialog->setMapCanvas( canvas );
mCanvas = canvas;
}

void QgsUnitSelectionWidget::showDialog()
{
QgsMapUnitScale scale = mUnitScaleDialog->getMapUnitScale();
if ( mUnitScaleDialog->exec() != QDialog::Accepted )
QgsPanelWidget* panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
mUnitScaleDialog->setMapUnitScale( scale );
QgsMapUnitScaleWidget* widget = new QgsMapUnitScaleWidget( panel );
widget->setPanelTitle( tr( "Adjust scaling range" ) );
widget->setMapCanvas( mCanvas );
widget->setMapUnitScale( mMapUnitScale );
connect( widget, SIGNAL( mapUnitScaleChanged( QgsMapUnitScale ) ), this, SLOT( widgetChanged( QgsMapUnitScale ) ) );
panel->openPanel( widget );
return;
}
else

QgsMapUnitScaleDialog dlg( this );
dlg.setMapUnitScale( mMapUnitScale );
dlg.setMapCanvas( mCanvas );
if ( dlg.exec() == QDialog::Accepted )
{
QgsMapUnitScale newScale = mUnitScaleDialog->getMapUnitScale();
if ( scale != newScale )
if ( mMapUnitScale != dlg.getMapUnitScale() )
{
mMapUnitScale = dlg.getMapUnitScale();
emit changed();
}
}
Expand All @@ -207,3 +247,38 @@ void QgsUnitSelectionWidget::toggleUnitRangeButton()
}
}

void QgsUnitSelectionWidget::widgetChanged( const QgsMapUnitScale& scale )
{
mMapUnitScale = scale;
emit changed();
}


QgsMapUnitScaleDialog::QgsMapUnitScaleDialog( QWidget* parent )
: QDialog( parent )
, mWidget( nullptr )
{
QVBoxLayout* vLayout = new QVBoxLayout();
mWidget = new QgsMapUnitScaleWidget();
vLayout->addWidget( mWidget );
QDialogButtonBox* bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
connect( bbox, SIGNAL( accepted() ), this, SLOT( accept() ) );
connect( bbox, SIGNAL( rejected() ), this, SLOT( reject() ) );
vLayout->addWidget( bbox );
setLayout( vLayout );
}

QgsMapUnitScale QgsMapUnitScaleDialog::getMapUnitScale() const
{
return mWidget->mapUnitScale();
}

void QgsMapUnitScaleDialog::setMapUnitScale( const QgsMapUnitScale& scale )
{
mWidget->setMapUnitScale( scale );
}

void QgsMapUnitScaleDialog::setMapCanvas( QgsMapCanvas* canvas )
{
mWidget->setMapCanvas( canvas );
}

0 comments on commit 5d38dcb

Please sign in to comment.