1 /*************************************************************************** 2 qgsunitselectionwidget.h 3 ------------------- 4 begin : Mar 24, 2014 5 copyright : (C) 2014 Sandro Mani 6 email : smani@sourcepole.ch 7 8 ***************************************************************************/ 9 10 /*************************************************************************** 11 * * 12 * This program is free software; you can redistribute it and/or modify * 13 * it under the terms of the GNU General Public License as published by * 14 * the Free Software Foundation; either version 2 of the License, or * 15 * (at your option) any later version. * 16 * * 17 ***************************************************************************/ 18 #ifndef QGSUNITSELECTIONWIDGET_H 19 #define QGSUNITSELECTIONWIDGET_H 20 21 #include <QWidget> 22 #include "qgis_sip.h" 23 #include <QDialog> 24 #include "qgspanelwidget.h" 25 #include "qgsmapunitscale.h" 26 #include "qgsunittypes.h" 27 28 #include "ui_qgsunitselectionwidget.h" 29 #include "ui_qgsmapunitscalewidgetbase.h" 30 #include "qgis_gui.h" 31 32 class QgsMapCanvas; 33 34 /** 35 * \class QgsMapUnitScaleWidget 36 * \ingroup gui 37 * \brief A widget which allows the user to choose the minimum and maximum scale of an object in map units 38 * and millimeters. This widget is designed to allow users to edit the properties of a 39 * QgsMapUnitScale object. 40 * \see QgsMapUnitScaleDialog 41 * \see QgsUnitSelectionWidget 42 * \since QGIS 3.0 43 */ 44 class GUI_EXPORT QgsMapUnitScaleWidget : public QgsPanelWidget, private Ui::QgsMapUnitScaleWidgetBase 45 { 46 Q_OBJECT 47 Q_PROPERTY( QgsMapUnitScale mapUnitScale READ mapUnitScale WRITE setMapUnitScale NOTIFY mapUnitScaleChanged ) 48 49 public: 50 51 /** 52 * Constructor for QgsMapUnitScaleWidget. 53 * \param parent parent widget 54 */ 55 QgsMapUnitScaleWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr ); 56 57 /** 58 * Returns a QgsMapUnitScale representing the settings shown in the 59 * widget. 60 * \see setMapUnitScale() 61 * \see mapUnitScaleChanged() 62 */ 63 QgsMapUnitScale mapUnitScale() const; 64 65 /** 66 * Updates the widget to reflect the settings from the specified 67 * QgsMapUnitScale object. 68 * \param scale map unit scale to show in widget 69 * \see mapUnitScale() 70 * \see mapUnitScaleChanged() 71 */ 72 void setMapUnitScale( const QgsMapUnitScale &scale ); 73 74 /** 75 * Sets the map canvas associated with the widget. This allows the 76 * widget to retrieve the current map scale from the canvas. 77 * \param canvas map canvas 78 */ 79 void setMapCanvas( QgsMapCanvas *canvas ); 80 81 signals: 82 83 /** 84 * Emitted when the settings in the widget are modified. 85 * \param scale QgsMapUnitScale reflecting new settings from the widget 86 */ 87 void mapUnitScaleChanged( const QgsMapUnitScale &scale ); 88 89 private slots: 90 void configureMinComboBox(); 91 void configureMaxComboBox(); 92 void settingsChanged(); 93 94 private: 95 96 bool mBlockSignals = true; 97 98 }; 99 100 /** 101 * \class QgsMapUnitScaleDialog 102 * \ingroup gui 103 * \brief A dialog which allows the user to choose the minimum and maximum scale of an object in map units 104 * and millimeters. This dialog is designed to allow users to edit the properties of a 105 * QgsMapUnitScale object. 106 * \see QgsMapUnitScaleWidget 107 * \see QgsUnitSelectionWidget 108 */ 109 class GUI_EXPORT QgsMapUnitScaleDialog : public QDialog 110 { 111 Q_OBJECT 112 Q_PROPERTY( QgsMapUnitScale mapUnitScale READ getMapUnitScale WRITE setMapUnitScale ) 113 114 public: 115 116 /** 117 * Constructor for QgsMapUnitScaleDialog. 118 * \param parent parent widget 119 */ 120 QgsMapUnitScaleDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr ); 121 122 /** 123 * Returns a QgsMapUnitScale representing the settings shown in the 124 * dialog. 125 * \see setMapUnitScale() 126 */ 127 QgsMapUnitScale getMapUnitScale() const; 128 129 /** 130 * Updates the dialog to reflect the settings from the specified 131 * QgsMapUnitScale object. 132 * \param scale map unit scale to show in dialog 133 * \see mapUnitScale() 134 */ 135 void setMapUnitScale( const QgsMapUnitScale &scale ); 136 137 /** 138 * Sets the map canvas associated with the dialog. This allows the dialog to retrieve the current 139 * map scale from the canvas. 140 * \param canvas map canvas 141 * \since QGIS 2.12 142 */ 143 void setMapCanvas( QgsMapCanvas *canvas ); 144 145 private slots: 146 147 void showHelp(); 148 149 150 private: 151 152 QgsMapUnitScaleWidget *mWidget = nullptr; 153 154 }; 155 156 /** 157 * \class QgsUnitSelectionWidget 158 * \ingroup gui 159 * \brief A widget displaying a combobox allowing the user to choose between various display units, 160 * such as millimeters or map unit. If the user chooses map units, a button appears allowing 161 * adjustment of minimum and maximum scaling. 162 * \see QgsMapUnitScaleWidget 163 * \see QgsMapUnitScaleDialog 164 */ 165 class GUI_EXPORT QgsUnitSelectionWidget : public QWidget, private Ui::QgsUnitSelectionWidget 166 { 167 Q_OBJECT 168 169 public: 170 171 /** 172 * Constructor for QgsUnitSelectionWidget. 173 * \param parent parent widget 174 */ 175 QgsUnitSelectionWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr ); 176 177 /** 178 * Sets the units which the user can choose from in the combobox. 179 * \param units list of strings for custom units to display in the widget 180 * \param mapUnitIdx specifies which entry corresponds to the map units, or -1 if none 181 */ 182 void setUnits( const QStringList &units, int mapUnitIdx ); 183 184 /** 185 * Sets the units which the user can choose from in the combobox. Clears any existing units. 186 * \param units list of valid units 187 * \since QGIS 2.9 188 */ 189 void setUnits( const QgsUnitTypes::RenderUnitList &units ); 190 191 //! Gets the selected unit index getUnit()192 int getUnit() const { return mUnitCombo->currentIndex(); } 193 194 /** 195 * Returns the current predefined selected unit (if applicable). 196 * \returns selected output unit, or QgsUnitTypes::RenderUnknownUnit if the widget was populated with custom unit types 197 * \since QGIS 2.9 198 */ 199 QgsUnitTypes::RenderUnit unit() const; 200 201 /** 202 * Sets the selected unit index 203 * \param unitIndex index of unit to set as current 204 * \note available in Python bindings as setUnitIndex 205 */ 206 void setUnit( int unitIndex ) SIP_PYNAME( setUnitIndex ); 207 208 /** 209 * Sets the selected unit 210 * \param unit predefined unit to set as current 211 */ 212 void setUnit( QgsUnitTypes::RenderUnit unit ); 213 214 //! Returns the map unit scale getMapUnitScale()215 QgsMapUnitScale getMapUnitScale() const { return mMapUnitScale; } 216 217 //! Sets the map unit scale setMapUnitScale(const QgsMapUnitScale & scale)218 void setMapUnitScale( const QgsMapUnitScale &scale ) { mMapUnitScale = scale; } 219 220 /** 221 * Sets the map canvas associated with the widget. This allows the widget to retrieve the current 222 * map scale from the canvas. 223 * \param canvas map canvas 224 * \since QGIS 2.12 225 */ 226 void setMapCanvas( QgsMapCanvas *canvas ); 227 228 /** 229 * Returns TRUE if the widget can show the map scale button when the Map Units option is selected. 230 * 231 * \see setShowMapScaleButton() 232 * \since QGIS 3.22 233 */ 234 bool showMapScaleButton() const; 235 236 /** 237 * Sets whether the widget can show the map scale button when the Map Units option is selected. 238 * 239 * \see showMapScaleButton() 240 * \since QGIS 3.22 241 */ 242 void setShowMapScaleButton( bool show ); 243 244 signals: 245 void changed(); 246 247 private slots: 248 void showDialog(); 249 void toggleUnitRangeButton(); 250 void widgetChanged( const QgsMapUnitScale &scale ); 251 252 private: 253 QgsMapUnitScale mMapUnitScale; 254 int mMapUnitIdx; 255 QgsMapCanvas *mCanvas = nullptr; 256 bool mShowMapScaleButton = true; 257 258 }; 259 260 #endif // QGSUNITSELECTIONWIDGET_H 261