qwt_abstract_scale_draw.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
11 #include "qwt_text.h"
12 #include "qwt_painter.h"
13 #include "qwt_scale_map.h"
14 #include "qwt_math.h"
15 
16 #include <qpainter.h>
17 #include <qpalette.h>
18 #include <qmap.h>
19 #include <qlist.h>
20 #include <qlocale.h>
21 
23 {
24 public:
26  spacing( 4.0 ),
27  penWidthF( 0.0 ),
28  minExtent( 0.0 )
29  {
33 
37  }
38 
40 
43 
44  double spacing;
46  qreal penWidthF;
47 
48  double minExtent;
49 
51 };
52 
61 {
63 }
64 
67 {
68  delete d_data;
69 }
70 
80  ScaleComponent component, bool enable )
81 {
82  if ( enable )
83  d_data->components |= component;
84  else
85  d_data->components &= ~component;
86 }
87 
96 {
97  return ( d_data->components & component );
98 }
99 
105 {
107  d_data->map.setScaleInterval( scaleDiv.lowerBound(), scaleDiv.upperBound() );
108  d_data->labelCache.clear();
109 }
110 
116  QwtTransform *transformation )
117 {
118  d_data->map.setTransformation( transformation );
119 }
120 
123 {
124  return d_data->map;
125 }
126 
129 {
130  return d_data->map;
131 }
132 
135 {
136  return d_data->scaleDiv;
137 }
138 
146 {
147  if ( width < 0.0 )
148  width = 0.0;
149 
150  d_data->penWidthF = width;
151 }
152 
158 {
159  return d_data->penWidthF;
160 }
161 
170 void QwtAbstractScaleDraw::draw( QPainter *painter,
171  const QPalette& palette ) const
172 {
173  painter->save();
174 
175  QPen pen = painter->pen();
176  pen.setWidthF( d_data->penWidthF );
177 
178  painter->setPen( pen );
179 
181  {
182  painter->save();
183  painter->setPen( palette.color( QPalette::Text ) ); // ignore pen style
184 
185  const QList<double> &majorTicks =
187 
188  for ( int i = 0; i < majorTicks.count(); i++ )
189  {
190  const double v = majorTicks[i];
191  if ( d_data->scaleDiv.contains( v ) )
192  drawLabel( painter, v );
193  }
194 
195  painter->restore();
196  }
197 
199  {
200  painter->save();
201 
202  pen = painter->pen();
203  pen.setColor( palette.color( QPalette::WindowText ) );
204  pen.setCapStyle( Qt::FlatCap );
205 
206  painter->setPen( pen );
207 
208  for ( int tickType = QwtScaleDiv::MinorTick;
209  tickType < QwtScaleDiv::NTickTypes; tickType++ )
210  {
211  const double tickLen = d_data->tickLength[tickType];
212  if ( tickLen <= 0.0 )
213  continue;
214 
215  const QList<double> &ticks = d_data->scaleDiv.ticks( tickType );
216  for ( int i = 0; i < ticks.count(); i++ )
217  {
218  const double v = ticks[i];
219  if ( d_data->scaleDiv.contains( v ) )
220  drawTick( painter, v, tickLen );
221  }
222  }
223 
224  painter->restore();
225  }
226 
228  {
229  painter->save();
230 
231  pen = painter->pen();
232  pen.setColor( palette.color( QPalette::WindowText ) );
233  pen.setCapStyle( Qt::FlatCap );
234 
235  painter->setPen( pen );
236 
237  drawBackbone( painter );
238 
239  painter->restore();
240  }
241 
242  painter->restore();
243 }
244 
256 {
257  if ( spacing < 0 )
258  spacing = 0;
259 
261 }
262 
273 {
274  return d_data->spacing;
275 }
276 
291 {
292  if ( minExtent < 0.0 )
293  minExtent = 0.0;
294 
296 }
297 
304 {
305  return d_data->minExtent;
306 }
307 
317  QwtScaleDiv::TickType tickType, double length )
318 {
319  if ( tickType < QwtScaleDiv::MinorTick ||
320  tickType > QwtScaleDiv::MajorTick )
321  {
322  return;
323  }
324 
325  if ( length < 0.0 )
326  length = 0.0;
327 
328  const double maxTickLen = 1000.0;
329  if ( length > maxTickLen )
330  length = maxTickLen;
331 
332  d_data->tickLength[tickType] = length;
333 }
334 
340 {
341  if ( tickType < QwtScaleDiv::MinorTick ||
342  tickType > QwtScaleDiv::MajorTick )
343  {
344  return 0;
345  }
346 
347  return d_data->tickLength[tickType];
348 }
349 
357 {
358  double length = 0.0;
359  for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ )
360  length = qwtMaxF( length, d_data->tickLength[i] );
361 
362  return length;
363 }
364 
377 {
378  auto str = QLocale().toString( value, 'f', 3 );
379  str.remove( QRegExp("0+$") ); // Remove any number of trailing 0's
380  str.remove( QRegExp("\\.$") ); // If the last character is just a '.' then remove it
381  return str;
382 }
383 
398  const QFont &font, double value ) const
399 {
400  QMap<double, QwtText>::const_iterator it1 = d_data->labelCache.constFind( value );
401  if ( it1 != d_data->labelCache.constEnd() )
402  return *it1;
403 
404  QwtText lbl = label( value );
405  lbl.setRenderFlags( 0 );
407 
408  ( void )lbl.textSize( font ); // initialize the internal cache
409 
410  QMap<double, QwtText>::iterator it2 = d_data->labelCache.insert( value, lbl );
411  return *it2;
412 }
413 
422 {
423  d_data->labelCache.clear();
424 }
virtual ~QwtAbstractScaleDraw()
Destructor.
virtual void drawBackbone(QPainter *painter) const =0
enum MQTTPropertyCodes value
QSizeF textSize() const
Definition: qwt_text.cpp:547
void setRenderFlags(int)
Change the render flags.
Definition: qwt_text.cpp:281
QWT_CONSTEXPR float qwtMaxF(float a, float b)
Definition: qwt_math.h:123
virtual void drawTick(QPainter *painter, double value, double len) const =0
A class representing a scale division.
Definition: qwt_scale_div.h:33
const QwtScaleMap & scaleMap() const
virtual void drawLabel(QPainter *painter, double value) const =0
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
TickType
Scale tick types.
Definition: qwt_scale_div.h:37
double upperBound() const
bool contains(double value) const
const QwtScaleDiv & scaleDiv() const
double lowerBound() const
void setTransformation(QwtTransform *)
void setLayoutAttribute(LayoutAttribute, bool on=true)
Definition: qwt_text.cpp:471
A transformation between coordinate systems.
Definition: qwt_transform.h:35
A class representing a text.
Definition: qwt_text.h:51
void setScaleDiv(const QwtScaleDiv &)
Backbone = the line where the ticks are located.
j template void())
Definition: json.hpp:3707
virtual QwtText label(double) const
Convert a value into its representing label.
A scale map.
Definition: qwt_scale_map.h:26
Number of valid tick types.
Definition: qwt_scale_div.h:52
void setTickLength(QwtScaleDiv::TickType, double length)
double tickLength[QwtScaleDiv::NTickTypes]
void enableComponent(ScaleComponent, bool enable=true)
const QwtText & tickLabel(const QFont &, double value) const
Convert a value into its representing label and cache it.
virtual void draw(QPainter *, const QPalette &) const
Draw the scale.
void setMinimumExtent(double)
Set a minimum for the extent.
std::enable_if_t< all< Args... >::value, enable_t > enable
Definition: sol.hpp:1726
bool hasComponent(ScaleComponent) const
void setTransformation(QwtTransform *)
void setPenWidthF(qreal width)
Specify the width of the scale pen.
void setSpacing(double)
Set the spacing between tick and labels.
QList< double > ticks(int tickType) const
double tickLength(QwtScaleDiv::TickType) const
double spacing() const
Get the spacing.
QFlags< ScaleComponent > ScaleComponents
Scale components.


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10