1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
/** \ingroup core
* A scale bar item that can be added to a map composition.
*/
class QgsComposerScaleBar: QgsComposerItem
{
%TypeHeaderCode
#include "qgscomposerscalebar.h"
%End
public:
enum Alignment
{
Left,
Middle,
Right
};
enum ScaleBarUnits
{
MapUnits,
Meters,
Feet,
NauticalMiles
};
/** Modes for setting size for scale bar segments
*/
enum SegmentSizeMode
{
SegmentSizeFixed, /*!< Scale bar segment size is fixed to a map unit*/
SegmentSizeFitWidth /*!< Scale bar segment size is calculated to fit a size range*/
};
QgsComposerScaleBar( QgsComposition* composition /TransferThis/ );
~QgsComposerScaleBar();
/** Return correct graphics item type. */
virtual int type() const;
/** \brief Reimplementation of QCanvasItem::paint*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
//getters and setters
int numSegments() const;
void setNumSegments( int nSegments );
int numSegmentsLeft() const;
void setNumSegmentsLeft( int nSegmentsLeft );
double numUnitsPerSegment() const;
void setNumUnitsPerSegment( double units );
/** Returns the size mode for scale bar segments.
* @see setSegmentSizeMode
* @see minBarWidth
* @see maxBarWidth
* @note added in QGIS 2.9
*/
SegmentSizeMode segmentSizeMode() const;
/** Sets the size mode for scale bar segments.
* @param mode size mode
* @see segmentSizeMode
* @see setMinBarWidth
* @see setMaxBarWidth
* @note added in QGIS 2.9
*/
void setSegmentSizeMode( SegmentSizeMode mode );
/** Returns the minimum size (in millimeters) for scale bar segments. This
* property is only effective if the @link segmentSizeMode @endlink is set
* to @link SegmentSizeFitWidth @endlink.
* @see segmentSizeMode
* @see setMinBarWidth
* @see maxBarWidth
* @note added in QGIS 2.9
*/
double minBarWidth() const;
/** Sets the minimum size (in millimeters) for scale bar segments. This
* property is only effective if the @link segmentSizeMode @endlink is set
* to @link SegmentSizeFitWidth @endlink.
* @param minWidth minimum width in millimeters
* @see minBarWidth
* @see setMaxBarWidth
* @see setSegmentSizeMode
* @note added in QGIS 2.9
*/
void setMinBarWidth( double minWidth );
/** Returns the maximum size (in millimeters) for scale bar segments. This
* property is only effective if the @link segmentSizeMode @endlink is set
* to @link SegmentSizeFitWidth @endlink.
* @see segmentSizeMode
* @see setMaxBarWidth
* @see minBarWidth
* @note added in QGIS 2.9
*/
double maxBarWidth() const;
/** Sets the maximum size (in millimeters) for scale bar segments. This
* property is only effective if the @link segmentSizeMode @endlink is set
* to @link SegmentSizeFitWidth @endlink.
* @param maxWidth maximum width in millimeters
* @see minBarWidth
* @see setMaxBarWidth
* @see setSegmentSizeMode
* @note added in QGIS 2.9
*/
void setMaxBarWidth( double maxWidth );
double numMapUnitsPerScaleBarUnit() const;
void setNumMapUnitsPerScaleBarUnit( double d );
QString unitLabeling() const;
void setUnitLabeling( const QString& label );
QFont font() const;
void setFont( const QFont& font );
/** Returns the color used for drawing text in the scalebar.
* @returns font color for scalebar.
* @see setFontColor
* @see font
*/
QColor fontColor() const;
/** Sets the color used for drawing text in the scalebar.
* @param c font color for scalebar.
* @see fontColor
* @see setFont
*/
void setFontColor( const QColor& c );
/** Returns the pen used for drawing the scalebar.
* @returns QPen used for drawing the scalebar outlines.
* @see setPen
* @see brush
*/
QPen pen() const;
/** Sets the pen used for drawing the scalebar.
* @param pen QPen to use for drawing the scalebar outlines.
* @see pen
* @see setBrush
*/
void setPen( const QPen& pen );
/** Returns the primary brush for the scalebar.
* @returns QBrush used for filling the scalebar
* @see setBrush
* @see brush2
* @see pen
*/
QBrush brush() const;
/** Sets primary brush for the scalebar.
* @param brush QBrush to use for filling the scalebar
* @see brush
* @see setBrush2
* @see setPen
*/
void setBrush( const QBrush& brush );
/** Returns the secondary brush for the scalebar. This is used for alternating color style scalebars, such
* as single and double box styles.
* @returns QBrush used for secondary color areas
* @see setBrush2
* @see brush
*/
QBrush brush2() const;
/** Sets secondary brush for the scalebar. This is used for alternating color style scalebars, such
* as single and double box styles.
* @param brush QBrush to use for secondary color areas
* @see brush2
* @see setBrush
*/
void setBrush2( const QBrush& brush );
double height() const;
void setHeight( double h );
void setComposerMap( const QgsComposerMap* map );
const QgsComposerMap* composerMap();
double labelBarSpace() const;
void setLabelBarSpace( double space );
double boxContentSpace() const;
void setBoxContentSpace( double space );
double segmentMillimeters() const;
/** Left / Middle/ Right */
Alignment alignment() const;
void setAlignment( Alignment a );
ScaleBarUnits units() const;
void setUnits( ScaleBarUnits u );
/** Returns the join style used for drawing lines in the scalebar
* @returns Join style for lines
* @note introduced in 2.3
* @see setLineJoinStyle
*/
Qt::PenJoinStyle lineJoinStyle() const;
/** Sets join style used when drawing the lines in the scalebar
* @param style Join style for lines
* @returns nothing
* @note introduced in 2.3
* @see lineJoinStyle
*/
void setLineJoinStyle( Qt::PenJoinStyle style );
/** Returns the cap style used for drawing lines in the scalebar
* @returns Cap style for lines
* @note introduced in 2.3
* @see setLineCapStyle
*/
Qt::PenCapStyle lineCapStyle() const;
/** Sets cap style used when drawing the lines in the scalebar
* @param style Cap style for lines
* @returns nothing
* @note introduced in 2.3
* @see lineCapStyle
*/
void setLineCapStyle( Qt::PenCapStyle style );
/** Apply default settings*/
void applyDefaultSettings();
/** Apply default size (scale bar 1/5 of map item width) */
void applyDefaultSize( ScaleBarUnits u = Meters );
/** Sets style by name
@param styleName (untranslated) style name. Possibilities are: 'Single Box', 'Double Box', 'Line Ticks Middle', 'Line Ticks Down', 'Line Ticks Up', 'Numeric'*/
void setStyle( const QString& styleName );
/** Returns style name*/
QString style() const;
/** Returns the x - positions of the segment borders (in item coordinates) and the width
* of the segment
* @note python bindings not available on android
*/
%If (!ARM)
%If (!QT5_SUPPORT)
void segmentPositions( QList<QPair<double, double> >& posWidthList ) const;
%End
%End
/** Sets box size suitable to content*/
void adjustBoxSize();
/** Adjusts box size and calls QgsComposerItem::update()*/
void update();
/** Returns string of first label (important for drawing, labeling, size calculation*/
QString firstLabelString() const;
/** Stores state in Dom element
* @param elem is Dom element corresponding to 'Composer' tag
* @param doc Dom document
*/
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
/** Sets state from Dom document
* @param itemElem is Dom node corresponding to item tag
* @param doc is Dom document
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
/** Moves scalebar position to the left / right depending on alignment and change in item width*/
void correctXPositionAlignment( double width, double widthAfter );
//overridden to apply minimum size
void setSceneRect( const QRectF &rectangle );
public slots:
void updateSegmentSize();
/** Sets mCompositionMap to 0 if the map is deleted*/
void invalidateCurrentMap();
protected:
/** Calculates with of a segment in mm and stores it in mSegmentMillimeters*/
void refreshSegmentMillimeters();
/** Returns diagonal of composer map in selected units (map units / meters / feet / nautical miles)*/
double mapWidth() const;
};
|