Skip to content

Commit 49401d5

Browse files
committedSep 16, 2015
Allow map unit scale dialog to retrieve current map scale
1 parent 8f0ed61 commit 49401d5

File tree

4 files changed

+58
-15
lines changed

4 files changed

+58
-15
lines changed
 

‎src/app/qgslabelinggui.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ QgsLabelingGui::QgsLabelingGui( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas,
7575

7676
mFieldExpressionWidget->registerGetExpressionContextCallback( &_getExpressionContext, mLayer );
7777

78+
Q_FOREACH ( QgsUnitSelectionWidget* unitWidget, findChildren<QgsUnitSelectionWidget*>() )
79+
{
80+
unitWidget->setMapCanvas( mMapCanvas );
81+
}
7882
mFontSizeUnitWidget->setUnits( QStringList() << tr( "Points" ) << tr( "Map unit" ), 1 );
7983
mBufferUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit );
8084
mShapeSizeUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit );

‎src/gui/qgsunitselectionwidget.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ void QgsMapUnitScaleDialog::setMapUnitScale( const QgsMapUnitScale &scale )
4040
mComboBoxMaxScale->setEnabled( scale.maxScale > 0.0 );
4141
}
4242

43+
void QgsMapUnitScaleDialog::setMapCanvas( QgsMapCanvas *canvas )
44+
{
45+
mComboBoxMinScale->setMapCanvas( canvas );
46+
mComboBoxMinScale->setShowCurrentScaleButton( true );
47+
mComboBoxMaxScale->setMapCanvas( canvas );
48+
mComboBoxMaxScale->setShowCurrentScaleButton( true );
49+
}
50+
4351
void QgsMapUnitScaleDialog::configureMinComboBox()
4452
{
4553
mComboBoxMinScale->setEnabled( mCheckBoxMinScale->isChecked() );
@@ -144,6 +152,11 @@ void QgsUnitSelectionWidget::setUnit( QgsSymbolV2::OutputUnit unit )
144152
mUnitCombo->setCurrentIndex( idx == -1 ? 0 : idx );
145153
}
146154

155+
void QgsUnitSelectionWidget::setMapCanvas( QgsMapCanvas *canvas )
156+
{
157+
mUnitScaleDialog->setMapCanvas( canvas );
158+
}
159+
147160
void QgsUnitSelectionWidget::showDialog()
148161
{
149162
QgsMapUnitScale scale = mUnitScaleDialog->getMapUnitScale();

‎src/gui/qgsunitselectionwidget.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "ui_qgsunitselectionwidget.h"
2424
#include "ui_qgsmapunitscaledialog.h"
2525

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

41+
/** Sets the map canvas associated with the dialog. This allows the dialog to retrieve the current
42+
* map scale from the canvas.
43+
* @param canvas map canvas
44+
* @note added in QGIS 2.12
45+
*/
46+
void setMapCanvas( QgsMapCanvas* canvas );
47+
3948
private slots:
4049
void configureMinComboBox();
4150
void configureMaxComboBox();
51+
4252
};
4353

4454
/** 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
91101
/** Sets the map unit scale */
92102
void setMapUnitScale( const QgsMapUnitScale& scale ) { mUnitScaleDialog->setMapUnitScale( scale ); }
93103

104+
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
105+
* map scale from the canvas.
106+
* @param canvas map canvas
107+
* @note added in QGIS 2.12
108+
*/
109+
void setMapCanvas( QgsMapCanvas* canvas );
110+
94111
signals:
95112
void changed();
96113

97114
private slots:
98115
void showDialog();
99116
void toggleUnitRangeButton();
117+
100118
};
101119

102120
#endif // QGSUNITSELECTIONWIDGET_H

‎src/ui/qgsmapunitscaledialog.ui

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>320</width>
10-
<height>134</height>
9+
<width>329</width>
10+
<height>155</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -33,20 +33,18 @@
3333
</widget>
3434
</item>
3535
<item row="1" column="1" colspan="2">
36-
<widget class="QgsScaleComboBox" name="mComboBoxMaxScale"/>
37-
</item>
38-
<item row="4" column="0" colspan="2">
39-
<widget class="QDialogButtonBox" name="mButtonBox">
40-
<property name="orientation">
41-
<enum>Qt::Horizontal</enum>
42-
</property>
43-
<property name="standardButtons">
44-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
36+
<widget class="QgsScaleWidget" name="mComboBoxMaxScale" native="true">
37+
<property name="focusPolicy">
38+
<enum>Qt::StrongFocus</enum>
4539
</property>
4640
</widget>
4741
</item>
4842
<item row="2" column="1" colspan="2">
49-
<widget class="QgsScaleComboBox" name="mComboBoxMinScale"/>
43+
<widget class="QgsScaleWidget" name="mComboBoxMinScale" native="true">
44+
<property name="focusPolicy">
45+
<enum>Qt::StrongFocus</enum>
46+
</property>
47+
</widget>
5048
</item>
5149
<item row="0" column="0" colspan="3">
5250
<widget class="QLabel" name="label">
@@ -58,13 +56,23 @@
5856
</property>
5957
</widget>
6058
</item>
59+
<item row="4" column="0" colspan="3">
60+
<widget class="QDialogButtonBox" name="mButtonBox">
61+
<property name="orientation">
62+
<enum>Qt::Horizontal</enum>
63+
</property>
64+
<property name="standardButtons">
65+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
66+
</property>
67+
</widget>
68+
</item>
6169
</layout>
6270
</widget>
6371
<customwidgets>
6472
<customwidget>
65-
<class>QgsScaleComboBox</class>
66-
<extends>QComboBox</extends>
67-
<header>qgsscalecombobox.h</header>
73+
<class>QgsScaleWidget</class>
74+
<extends>QWidget</extends>
75+
<header>qgsscalewidget.h</header>
6876
</customwidget>
6977
</customwidgets>
7078
<tabstops>

0 commit comments

Comments
 (0)
Please sign in to comment.