Skip to content

Commit

Permalink
Allow map unit scale dialog to retrieve current map scale
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 16, 2015
1 parent 8f0ed61 commit 49401d5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/app/qgslabelinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
13 changes: 13 additions & 0 deletions src/gui/qgsunitselectionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down Expand Up @@ -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();
Expand Down
18 changes: 18 additions & 0 deletions src/gui/qgsunitselectionwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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
38 changes: 23 additions & 15 deletions src/ui/qgsmapunitscaledialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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">
Expand All @@ -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>
Expand Down

0 comments on commit 49401d5

Please sign in to comment.