⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwt_scldraw.cpp

📁 软件无线电的平台
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  \param rotation Angle in degrees. When changing the label rotation,                  the label alignment might be adjusted too.  \sa setLabelAlignment(), labelRotation(), labelAlignment().  \warning Rotation of labels is not implemented for round scales.*/void QwtScaleDraw::setLabelRotation(double rotation){    d_labelRotation = rotation;}/*!  \return the label rotation  \sa setLabelRotation(), labelAlignment()*/double QwtScaleDraw::labelRotation() const{    return d_labelRotation;}/*!  Labels are aligned to the point ticklength + margin away from the backbone.   The alignment is relative to the orientation of the label text.  In case of an alignment of 0 the label will be aligned   depending on the orientation of the scale:      QwtScaleDraw::Top: Qt::AlignHCenter | Qt::AlignTop\n      QwtScaleDraw::Bottom: Qt::AlignHCenter | Qt::AlignBottom\n      QwtScaleDraw::Left: Qt::AlignLeft | Qt::AlignVCenter\n      QwtScaleDraw::Right: Qt::AlignRight | Qt::AlignVCenter\n  Changing the alignment is often necessary for rotated labels.  \param alignment Or'd Qt::AlignmentFlags <see qnamespace.h>  \warning Alignment of labels is not implemented for round scales.  \sa QwtScaleDraw::setLabelRotation(), QwtScaleDraw::labelRotation(),       QwtScaleDraw::labelAlignment()*/  void QwtScaleDraw::setLabelAlignment(int alignment){    d_labelAlignment = alignment;}/*!  \return the label alignment  \sa setLabelAlignment(), labelRotation()*/int QwtScaleDraw::labelAlignment() const{    return d_labelAlignment;}/*!  \brief Adjust the baseline circle segment for round scales.  The baseline will be drawn from min(angle1,angle2) to max(angle1, angle2).  The settings have no effect if the scale orientation is not set to  QwtScaleDraw::Round. The default setting is [ -135, 135 ].  An angle of 0 degrees corresponds to the 12 o'clock position,  and positive angles count in a clockwise direction.  \param angle1  \param angle2 boundaries of the angle interval in degrees.  \warning <ul>  <li>The angle range is limited to [-360, 360] degrees. Angles exceeding      this range will be clipped.  <li>For angles more than 359 degrees above or below min(angle1, angle2),      scale marks will not be drawn.  <li>If you need a counterclockwise scale, use QwtScaleDiv::setRange  </ul>*/void QwtScaleDraw::setAngleRange(double angle1, double angle2){    angle1 = qwtLim(angle1, -360.0, 360.0);    angle2 = qwtLim(angle2, -360.0, 360.0);    int amin = int(floor (qwtMin(angle1, angle2) * 16.0 + 0.5));    int amax = int(floor (qwtMax(angle1, angle2) * 16.0 + 0.5));        if (amin == amax)    {        amin -= 1;        amax += 1;    }        d_minAngle = amin;    d_maxAngle = amax;    setIntRange(d_minAngle, d_maxAngle);}/*!  \brief Set the number format for the major scale labels  Format character and precision have the same meaning as for the  QString class.  \param f format character, 'g', 'e' or 'f'  \param prec precision(f) or significance(g)  \param fieldwidth fieldwidth  \sa QString::sprintf in the Qt manual*/void QwtScaleDraw::setLabelFormat(char f, int prec, int fieldwidth){    d_fmt = f;    d_prec = prec;    d_fieldwidth = fieldwidth;}/*!  Format character and precision have the same meaning as for the  QString class.  \retval f format character 'g', 'e', or 'f'  \retval prec precision(f), or siginificance(g)  \return the number format for the major scale labels  \sa QString::sprintf in the Qt manual*/void QwtScaleDraw::labelFormat(char &f, int &prec, int &fieldwidth) const{    f = d_fmt;    prec = d_prec;    fieldwidth = d_fieldwidth;}/*!    Set the margins of the ticks    \param hMargin Horizontal margin    \param vMargin Vertical margin*/void QwtScaleDraw::setMargin(uint hMargin, uint vMargin){    d_hpad = hMargin;    d_vpad = vMargin;}/*!    Set the length of the ticks*/void QwtScaleDraw::setTickLength(unsigned int minLen,     unsigned int medLen, unsigned int majLen){    const unsigned int maxTickLen = 1000;    d_minLen = QMIN(minLen, maxTickLen);    d_medLen = QMIN(medLen, maxTickLen);    d_majLen = QMIN(majLen, maxTickLen);}/*!    Return the length of the ticks    \sa QwtScaleDraw::majTickLength()*/void QwtScaleDraw::tickLength(unsigned int &minLen,        unsigned int &medLen, unsigned int &majLen) const{    minLen = d_minLen;    medLen = d_medLen;    majLen = d_majLen;}/*!    Return the length of the major ticks    \sa QwtScaleDraw::tickLength()*/unsigned int QwtScaleDraw::majTickLength() const{    return d_majLen;}/*!  \param fm QFontMetrics  \return the maximum width of a label*/int QwtScaleDraw::maxLabelWidth(const QFontMetrics &fm) const{    int maxWidth = 0;    for (uint i = 0; i < d_scldiv.majCnt(); i++)    {        double val = d_scldiv.majMark(i);        // correct rounding errors if val = 0        if ((!d_scldiv.logScale())             && (qwtAbs(val) < step_eps * qwtAbs(d_scldiv.majStep())))        {            val = 0.0;        }        const int w = labelBoundingRect(fm, val).width();        if ( w > maxWidth )            maxWidth = w;    }    return maxWidth;}/*!  \param fm QFontMetrics  \return the maximum width of a label*/int QwtScaleDraw::maxLabelHeight(const QFontMetrics &fm) const{    int maxHeight = 0;    for (uint i = 0; i < d_scldiv.majCnt(); i++)    {        double val = d_scldiv.majMark(i);        // correct rounding errors if val = 0        if ((!d_scldiv.logScale())             && (qwtAbs(val) < step_eps * qwtAbs(d_scldiv.majStep())))        {            val = 0.0;        }        const int h = labelBoundingRect(fm, val).height();        if ( h > maxHeight )            maxHeight = h;    }    return maxHeight;}/*!  Find the bounding rect for the label. The coordinates of  the rect are relative to margin + ticklength from the backbone  in direction of the tick.*/QRect QwtScaleDraw::labelBoundingRect(    const QFontMetrics &fm, double val) const{    QString zeroString;    if ( d_fieldwidth > 0 )        zeroString.fill('0', d_fieldwidth);    const QString lbl = label(val);    const QString &txt = fm.width(zeroString) > fm.width(lbl)         ? zeroString : lbl;    if ( txt.isEmpty() )        return QRect(0, 0, 0, 0);    QRect br;    QPoint pos;    int alignment;    double rotation;    labelPlacement(fm, val, pos, alignment, rotation);    if ( alignment )    {        // Don't use fm.boundingRect(txt), it cuts off pixels.        const int w = fm.boundingRect(0, 0,             QCOORD_MAX, QCOORD_MAX, 0, txt).width();        const int h = -(fm.ascent() - 2);        QWMatrix m = labelWorldMatrix(fm, pos, alignment, rotation, txt);        br = QwtMetricsMap::translate(m, QRect(0, 0, w, h));        br.moveBy(-pos.x(), -pos.y());    }    return br;}/*!  \brief Determine the minimum border distance  This member function returns the minimum space  needed to draw the mark labels at the scale's endpoints.  \param fm QFontMetrics  \param start start border distance  \param end end border distance*/void QwtScaleDraw::minBorderDist(const QFontMetrics &fm,    int &start, int &end ) const{    start = 0;    end = 0;    if ( d_scldiv.majCnt() > 0 )    {        const QRect labelRectMin = labelBoundingRect(fm, d_scldiv.majMark(0));        const QRect labelRectMax = labelBoundingRect(fm,             d_scldiv.majMark(d_scldiv.majCnt() - 1));        switch (d_orient)        {            case Left:            case Right:                end = -labelRectMin.y();                start = labelRectMax.height() + labelRectMax.y();                break;            case Top:            case Bottom:                start = -labelRectMin.x();                end = labelRectMax.width() + labelRectMax.x();                break;            case Round:                start = labelRectMin.width();                end = labelRectMax.width();                break;        }    }}/*!  Determine the minimum distance between two labels, that is necessairy  that the texts don't overlap.  \param fm QFontMetrics  \return the maximum width of a label  \warning Not implemented for round scales*/int QwtScaleDraw::minLabelDist(const QFontMetrics &fm) const{    if ( d_orient == Round ) // no implementation        return 0;    const bool vertical = (d_orient == Left || d_orient == Right);    QRect bRect1, bRect2;    int maxDist = 0;    for (uint i = 0; i < d_scldiv.majCnt() - 1; i++ )    {        if ( i == 0 )        {            bRect1 = labelBoundingRect(fm, d_scldiv.majMark(0));            if ( vertical )            {                bRect1.setRect(-bRect1.bottom(), 0,                     bRect1.height(), bRect1.width());            }        }        else            bRect1 = bRect2;        bRect2 = labelBoundingRect(fm, d_scldiv.majMark(i + 1));        if ( vertical )        {            bRect2.setRect(-bRect2.bottom(), 0,                bRect2.height(), bRect2.width());        }        int dist = fm.leading(); // space between the labels        if ( bRect1.right() > 0 )            dist += bRect1.right();        if ( bRect2.left() < 0 )            dist += -bRect2.left();        if ( dist > maxDist )            maxDist = dist;    }    double angle = d_labelRotation / 180.0 * M_PI;    if ( vertical )        angle += M_PI / 2;    if ( sin(angle) == 0.0 )        return maxDist;    const int fmHeight = fm.ascent() - 2;     // The distance we need until there is    // the height of the label font. This height is needed    // for the neighbour labal.    int labelDist = (int)(fmHeight / sin(angle) * cos(angle));    if ( labelDist < 0 )        labelDist = -labelDist;    // The cast above floored labelDist. We want to ceil.    labelDist++;     // For text orientations close to the scale orientation     if ( labelDist > maxDist )        labelDist = maxDist;    // For text orientations close to the opposite of the     // scale orientation    if ( labelDist < fmHeight )        labelDist = fmHeight;    return labelDist;}/*!  \param pen pen  \param fm font metrics  \return the minimum height required to draw the scale          including the minimum border distance*/int QwtScaleDraw::minHeight( const QPen &pen, const QFontMetrics &fm ) const{    const int pw = QMAX( 1, pen.width() );  // penwidth can be zero    int h = 0;    switch ( d_orient )    {        case Left:        case Right:        {            int bottomDist, topDist;            minBorderDist(fm, bottomDist, topDist);            h = bottomDist + topDist;            if ( d_scldiv.majCnt() >= 2 )                 h += minLabelDist(fm) * (d_scldiv.majCnt() - 1);            int th = 2 * (d_scldiv.majCnt() + d_scldiv.minCnt()) * pw;            if ( th > h )                h = th;            break;        }        case Round:            // compute the radial thickness            h = pw + d_vpad + d_majLen + maxLabelWidth(fm);            break;        case Top:        case Bottom:            h = pw + d_vpad + d_majLen + maxLabelHeight(fm);            break;    }    return h;}/*!  \param pen pen  \param fm font metrics  \return the minimum width required to draw the scale          including the minimum border distance*/int QwtScaleDraw::minWidth( const QPen &pen, const QFontMetrics &fm ) const{    const int pw = QMAX( 1, pen.width() );  // penwidth can be zero    int w = 0;    switch(d_orient)    {        case Left:        case Right:        {            w = pw + d_hpad + d_majLen + maxLabelWidth(fm);            break;        }        case Round:        {               w = pw + d_vpad + d_majLen + maxLabelWidth(fm);            break;        }        case Top:        case Bottom:        {            int leftDist, rightDist;            minBorderDist(fm, leftDist, rightDist);            w = leftDist + rightDist +                 minLabelDist(fm) * (d_scldiv.majCnt() - 1);            int tw = 2 * (d_scldiv.majCnt() + d_scldiv.minCnt()) * pw;            if ( tw > w )                w = tw;            break;        }    }    return w;}/*!  \brief Convert a value into its representing label using the          labelFormat.   \param value Value  \return Label string.  \sa QwtScaleDraw::setLabelFormat()*/QString QwtScaleDraw::label(double value) const{#if 1    if ( value == -0 )        value = 0;#endif    QString fmt;    fmt.sprintf("%%%d.%d%c", d_fieldwidth, d_prec, d_fmt);    QString text;    text.sprintf(fmt, value);    return text;}//! Return x originint QwtScaleDraw::x() const{    return d_xorg;}//! Return y originint QwtScaleDraw::y() const{    return d_yorg;}//! Return lengthint QwtScaleDraw::length() const{    return d_len;}//! Return scale orientation QwtScaleDraw::Orientation QwtScaleDraw::orientation() const {     return d_orient; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -