Skip to content
Permalink
Browse files

Allow map unit scale dialog to retrieve current map scale

  • Loading branch information
nyalldawson committed Sep 16, 2015
1 parent 8f0ed61 commit 49401d5f6f0ed83c20b4c1b07464265f06a09e3e
@@ -75,6 +75,10 @@ QgsLabelingGui::QgsLabelingGui( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas,

mFieldExpressionWidget->registerGetExpressionContextCallback( &_getExpressionContext, mLayer );

Q_FOREACH ( QgsUnitSelectionWidget* unitWidget, findChildren<QgsUnitSelectionWidget*>() )
{
unitWidget->setMapCanvas( mMapCanvas );
}
mFontSizeUnitWidget->setUnits( QStringList() << tr( "Points" ) << tr( "Map unit" ), 1 );
mBufferUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit );
mShapeSizeUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit );
@@ -40,6 +40,14 @@ void QgsMapUnitScaleDialog::setMapUnitScale( const QgsMapUnitScale &scale )
mComboBoxMaxScale->setEnabled( scale.maxScale > 0.0 );
}

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

void QgsMapUnitScaleDialog::configureMinComboBox()
{
mComboBoxMinScale->setEnabled( mCheckBoxMinScale->isChecked() );
@@ -144,6 +152,11 @@ void QgsUnitSelectionWidget::setUnit( QgsSymbolV2::OutputUnit unit )
mUnitCombo->setCurrentIndex( idx == -1 ? 0 : idx );
}

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

void QgsUnitSelectionWidget::showDialog()
{
QgsMapUnitScale scale = mUnitScaleDialog->getMapUnitScale();
@@ -23,6 +23,8 @@
#include "ui_qgsunitselectionwidget.h"
#include "ui_qgsmapunitscaledialog.h"

class QgsMapCanvas;

/** Dialog allowing the user to choose the minimum and maximum scale of an object in map units */
class GUI_EXPORT QgsMapUnitScaleDialog : public QDialog, private Ui::QgsMapUnitScaleDialog
{
@@ -36,9 +38,17 @@ class GUI_EXPORT QgsMapUnitScaleDialog : public QDialog, private Ui::QgsMapUnitS
/** Sets the map unit scale */
void setMapUnitScale( const QgsMapUnitScale& scale );

/** Sets the map canvas associated with the dialog. This allows the dialog to retrieve the current
* map scale from the canvas.
* @param canvas map canvas
* @note added in QGIS 2.12
*/
void setMapCanvas( QgsMapCanvas* canvas );

private slots:
void configureMinComboBox();
void configureMaxComboBox();

};

/** Widget displaying a combobox allowing the user to choose between millimeter and map units
@@ -91,12 +101,20 @@ class GUI_EXPORT QgsUnitSelectionWidget : public QWidget, private Ui::QgsUnitSel
/** Sets the map unit scale */
void setMapUnitScale( const QgsMapUnitScale& scale ) { mUnitScaleDialog->setMapUnitScale( 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
* @note added in QGIS 2.12
*/
void setMapCanvas( QgsMapCanvas* canvas );

signals:
void changed();

private slots:
void showDialog();
void toggleUnitRangeButton();

};

#endif // QGSUNITSELECTIONWIDGET_H
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>320</width>
<height>134</height>
<width>329</width>
<height>155</height>
</rect>
</property>
<property name="windowTitle">
@@ -33,20 +33,18 @@
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QgsScaleComboBox" name="mComboBoxMaxScale"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<widget class="QgsScaleWidget" name="mComboBoxMaxScale" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QgsScaleComboBox" name="mComboBoxMinScale"/>
<widget class="QgsScaleWidget" name="mComboBoxMinScale" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label">
@@ -58,13 +56,23 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsScaleComboBox</class>
<extends>QComboBox</extends>
<header>qgsscalecombobox.h</header>
<class>QgsScaleWidget</class>
<extends>QWidget</extends>
<header>qgsscalewidget.h</header>
</customwidget>
</customwidgets>
<tabstops>

0 comments on commit 49401d5

Please sign in to comment.
You can’t perform that action at this time.