Logo Search packages:      
Sourcecode: koffice version File versions

void KDChartParams::setPrintDataValues ( bool  active,
uint  chart = KDCHART_ALL_CHARTS,
int  divPow10 = 0,
int  digitsBehindComma = DATA_VALUE_AUTO_DIGITS,
QFont *  font = 0,
uint  size = UINT_MAX,
QColor *  color = DATA_VALUE_AUTO_COLOR,
KDChartEnums::PositionFlag  negativePosition = KDChartEnums::PosCenter,
uint  negativeAlign = Qt::AlignCenter,
int  negativeDeltaX = 0,
int  negativeDeltaY = 0,
int  negativeRotation = 0,
KDChartEnums::PositionFlag  positivePosition = KDChartEnums::PosCenter,
uint  positiveAlign = Qt::AlignCenter,
int  positiveDeltaX = 0,
int  positiveDeltaY = 0,
int  positiveRotation = 0,
KDChartEnums::TextLayoutPolicy  policy = KDChartEnums::LayoutPolicyRotate 
)

Specifies if and how a chart will print the data value texts near their respective entries.

Data value texts will be printed immediately after drawing all of the chart data points (or bars, lines,...) but before drawing the legend and before drawing any custom boxes. If more than one chart ist to be drawn (sharing the same data area) printing of the data text values will take place after drawing all of the last charts data points, this enables us to see the texts even if their respective data representations are covered by the second charts drawings. The same covering/colliding problem might occur with Area charts if one area is (partially) covering another area. In such cases you might either want to specify an appropriate TextLayoutPolicy for getting a better looking result or specify an other text color for data value texts of the second chart since by default the first chart has black texts while the second chart shows its data value texts in dark blue color.

Note:
Only used if chartType() is neither HiLo nor BoxWhisker. To specify printing of data values in a HiLo chart please use setHiLoChartPrintLowValues, setHiLoChartPrintHighValues, setHiLoChartPrintOpenValues, setHiLoChartPrintCloseValues. To specify printing of data values in a BoxWhisker chart please use setBWChartPrintStatistics.
Calling setPrintDataValues( false ) will deactivate printing of the values.

Calling setPrintDataValuesWithDefaultFontParams( chart ) will reset the respective font size and colour and position parameters (but not the QFont itself) and activate printing of the values for the chart speficied (or for all charts by using KDChartParams::KDCHART_ALL_CHARTS, resp.).

Parameters:
active specifies whether the value texts are to be printed or not.
chart The number of the chart: 0 for the first chart, 1 for the second chart in case there are two charts to be drawn sharing the same data area. Use the special value KDChartParams::KDCHART_ALL_CHARTS to specify that your settings are to be taken for both charts.
divPow10 The power of 10 which the data value is to be divided by. A value of 2 means divide by 100, a value of -3 means multiply by 1000, and 0 (by definition) would result in multiplying by 1.
digitsBehindComma The number of digits to show behind the comma, to have this calculated automatically just use the default value KDChartParams::DATA_VALUE_AUTO_DIGITS.
font a Pointer to the font to be used, if zero the default data value texts font will be taken (this is a Times font since small Times digits are clearer than small Helvetica digits).
Changing of one or more of the following parameters automatically de-activates all future font parameter adjustments that would otherwise take place after each call of setChartType (or setAdditionalChartType, resp.). To re-enable this usefull feature you may call setPrintDataValuesWithDefaultFontParams at any time afterwards.

Parameters:
size (in per mille of the chart width) the dynamic size of the font to be used. If this parameter is zero the size of the font is used instead - regardless of the size of the chart! You may use setPrintDataValuesFontRelSize to change this parameter setting without affecting the other ones.
color the color to be used when printing the values. To have the color calculated automatically - useful when printing inside the bars (or pie slices, areas, ... resp.) - please use DATA_VALUE_AUTO_COLOR instead of a QColor*. You may use setPrintDataValuesColor to change this parameter setting without affecting the other ones.
The following parameters apply to values less than zero only:

Parameters:
negativePosition The anchor position which the text is to be aligned to.
negativeAlign The way how the text is to be aligned to the anchor. This must be a reasonable combination of Qt::AlignmentFlags.
negativeDeltaX The X distance between the anchor point -- specified by negativePosition (or positivePosition, resp.) -- and the internal alignment point of the text -- specified by negativeAlign (or positiveAlign, resp.). Note: For better compatibility to the dynamic font size this parameter is interpreted as being a per-cent value of the used font height. If greater 0, the X position is increased, if less than 0, it is reduced. Actual font size and thus also this delta value are calculated dynamically before painting based on the size of the chart and the specification made via parameter size.
negativeDeltaY The Y distance between the anchor point -- specified by negativePosition (or positivePosition, resp.) -- and the internal alignment point of the text -- specified by negativeAlign (or positiveAlign, resp.). Note: For better compatibility to the dynamic font size this parameter is interpreted as being a per-cent value of the used font height. If greater 0, the Y position is increased, if less than 0, it is reduced. Actual font size and thus also this delta value are calculated dynamically before painting based on the size of the chart and the specification made via parameter size.
negativeRotation The amount of degrees (using a circle of 360 degrees) taken to rotate the text. Positive values rotate clockwise, negative values rotate counter-clockwise. There are two special values that you might find usefull for Pie charts or for Ring charts: KDChartParams::SAGGITAL_ROTATION and KDChartParams::TANGENTIAL_ROTATION both leading to individual calculation of appropriate rotation for each data value. Rotation will be performed around the internal alignment point of the text -- specified by negativeAlign (or positiveAlign, resp.).
The following parameters apply to values greater than zero or equal zero:

Parameters:
positivePosition The anchor position which the text is to be aligned to.
positiveAlign The way how the text is to be aligned to the anchor. This must be a reasonable combination of Qt::AlignmentFlags.
negativeDeltaX The X distance between the anchor point -- specified by negativePosition (or positivePosition, resp.) -- and the internal alignment point of the text -- specified by negativeAlign (or positiveAlign, resp.). Note: For better compatibility to the dynamic font size this parameter is interpreted as being a per-cent value of the used font height. If greater 0, the X position is increased, if less than 0, it is reduced. Actual font size and thus also this delta value are calculated dynamically before painting based on the size of the chart and the specification made via parameter size.
positiveDeltaY The Y distance between the anchor point -- specified by negativePosition (or positivePosition, resp.) -- and the internal alignment point of the text -- specified by negativeAlign (or positiveAlign, resp.). Note: For better compatibility to the dynamic font size this parameter is interpreted as being a per-cent value of the used font height. If greater 0, the Y position is increased, if less than 0, it is reduced. Actual font size and thus also this delta value are calculated dynamically before painting based on the size of the chart and the specification made via parameter size.
positiveRotation The amount of degrees (using a circle of 360 degrees) taken to rotate the text. Positive values rotate clockwise, negative values rotate counter-clockwise. There are two special values that you might find usefull for Pie charts or for Ring charts: KDChartParams::SAGGITAL_ROTATION and KDChartParams::TANGENTIAL_ROTATION both leading to individual calculation of appropriate rotation for each data value. Rotation will be performed around the internal alignment point of the text -- specified by negativeAlign (or positiveAlign, resp.).
layoutPolicy The way to handle too narrow space conflicts: what to do if a data text covers a neighboring data text (or a neighboring data area, resp.).
See also:
printDataValues

setPrintDataValuesWithDefaultFontParams, printDataValuesWithDefaultFontParams

setPrintDataValuesFontRelSize, setPrintDataValuesColor

dataValuesDivPow10

dataValuesDigitsBehindComma

dataValuesFontUseRelSize

dataValuesFontRelSize

dataValuesFontColor

dataValuesAnchorPosition

dataValuesAnchorAlign

dataValuesAnchorDeltaX

dataValuesAnchorDeltaY

dataValuesRotation

dataValuesLayoutPolicy

Definition at line 941 of file KDChartParams.cpp.

References _printDataValuesSettings, _printDataValuesSettings2, additionalChartType(), areaChartSubType(), changed(), chartType(), polarMarker(), and setDefaultAxesTypes().

Referenced by KDChart::paint(), setAdditionalChartType(), setAreaChartSubType(), setChartType(), and setPrintDataValuesWithDefaultFontParams().

{
    uint count = (KDCHART_ALL_CHARTS == chart) ? 2 : 1;
    PrintDataValuesSettings * settings =    (( 1 < count ) || ( 0 == chart ))
        ? &_printDataValuesSettings
        : &_printDataValuesSettings2;
    for ( uint i = 0; i < count; ++i ) {
        settings->_printDataValues   = active;
        settings->_divPow10          = divPow10;
        settings->_digitsBehindComma = digitsBehindComma;

        const ChartType cType
            = (    ( 1  < count  &&  i )
                    || ( 1 == count  &&  0 < chart  &&  chart < 1000 ) )
            ? additionalChartType()
            : chartType();

        bool finished( false );
        if ( UINT_MAX == size ) {
            finished = true;
            switch ( cType ) {
                case NoType:
                case Bar: {
                              if ( font )
                                  settings->_dataValuesFont = *font;
                              else
                                  settings->_dataValuesFont = QFont( "times", 1, QFont::Bold );
                              settings->_dataValuesUseFontRelSize = true;
                              settings->_dataValuesFontRelSize = 22;
                              settings->_dataValuesAutoColor            = false;  //  !!!
                              settings->_dataValuesColor = QColor( Qt::darkBlue );
                              settings->_dataValuesBrush = QBrush( Qt::NoBrush );
                              // for values below zero:
                              settings->_dataValuesAnchorNegativePosition = KDChartEnums::PosBottomRight;
                              settings->_dataValuesAnchorNegativeAlign    = Qt::AlignBottom + Qt::AlignRight;
                              settings->_dataValuesAnchorNegativeDeltaX   =  20;
                              settings->_dataValuesAnchorNegativeDeltaY   =  55;
                              settings->_dataValuesNegativeRotation       = 300;
                              // for values greater/equal zero:
                              settings->_dataValuesAnchorPositivePosition = KDChartEnums::PosTopLeft;
                              settings->_dataValuesAnchorPositiveAlign    = Qt::AlignTop + Qt::AlignLeft;
                              settings->_dataValuesAnchorPositiveDeltaX   = - 20;
                              settings->_dataValuesAnchorPositiveDeltaY   = - 65;
                              settings->_dataValuesPositiveRotation       =  300;

                              settings->_dataValuesLayoutPolicy = KDChartEnums::LayoutPolicyRotate;
                          }
                          break;
                case Line: {
                               if ( font )
                                   settings->_dataValuesFont = *font;
                               else
                                   settings->_dataValuesFont = QFont( "times", 1, QFont::Normal );
                               settings->_dataValuesUseFontRelSize = true;
                               settings->_dataValuesFontRelSize = 22;
                               settings->_dataValuesAutoColor            = false;  //  !!!
                               settings->_dataValuesColor = QColor( Qt::darkBlue );
                               settings->_dataValuesBrush = QBrush( Qt::NoBrush );
                               // for values below zero:
                               settings->_dataValuesAnchorNegativePosition = KDChartEnums::PosBottomCenter;
                               settings->_dataValuesAnchorNegativeAlign    = Qt::AlignTop + Qt::AlignHCenter;
                               settings->_dataValuesAnchorNegativeDeltaX   =   0;
                               settings->_dataValuesAnchorNegativeDeltaY   =   0;
                               settings->_dataValuesNegativeRotation       =   0;
                               // for values greater/equal zero:
                               settings->_dataValuesAnchorPositivePosition = KDChartEnums::PosTopCenter;
                               settings->_dataValuesAnchorPositiveAlign    = Qt::AlignBottom + Qt::AlignHCenter;
                               settings->_dataValuesAnchorPositiveDeltaX   =    0;
                               settings->_dataValuesAnchorPositiveDeltaY   =    0;
                               settings->_dataValuesPositiveRotation       =    0;

                               settings->_dataValuesLayoutPolicy = KDChartEnums::LayoutPolicyRotate;
                           }
                           break;
                case Area: {
                               if ( font )
                                   settings->_dataValuesFont = *font;
                               else
                                   settings->_dataValuesFont = QFont( "times", 1, QFont::Bold );
                               settings->_dataValuesUseFontRelSize = true;
                               settings->_dataValuesFontRelSize = 29;
                               settings->_dataValuesAutoColor              = true;  //  !!!
                               settings->_dataValuesColor = QColor( Qt::black );
                               settings->_dataValuesBrush = QBrush( Qt::white );

                               bool bShowOutside = areaChartSubType() == AreaNormal;
                               // for values below zero:
                               settings->_dataValuesAnchorNegativePosition = KDChartEnums::PosBottomCenter;
                               settings->_dataValuesAnchorNegativeAlign    = Qt::AlignHCenter
                                                            + (bShowOutside ? Qt::AlignTop : Qt::AlignBottom);
                               settings->_dataValuesAnchorNegativeDeltaX   =   0;
                               settings->_dataValuesAnchorNegativeDeltaY   = bShowOutside ? 20 : -35;
                               settings->_dataValuesNegativeRotation       =   0;
                               // for values greater/equal zero:
                               settings->_dataValuesAnchorPositivePosition = KDChartEnums::PosTopCenter;
                               settings->_dataValuesAnchorPositiveAlign    = Qt::AlignHCenter
                                                            + (bShowOutside ? Qt::AlignBottom : Qt::AlignTop);
                               settings->_dataValuesAnchorPositiveDeltaX   =   0;
                               settings->_dataValuesAnchorPositiveDeltaY   = bShowOutside ? -20 : 35;
                               settings->_dataValuesPositiveRotation       =   0;

                               settings->_dataValuesLayoutPolicy = KDChartEnums::LayoutPolicyRotate;
                           }
                           break;
                case HiLo:
                case BoxWhisker:
                           // settings are not defined here because HiLo and BW charts
                           // are *not* set up using setPrintDataValues()
                           // but by using their own methods
                           break;
                case Pie: {
                              if ( font )
                                  settings->_dataValuesFont = *font;
                              else
                                  settings->_dataValuesFont = QFont( "times", 1, QFont::Bold );
                              settings->_dataValuesUseFontRelSize = true;
                              settings->_dataValuesFontRelSize = 35;
                              settings->_dataValuesAutoColor            = true;  //  !!!
                              settings->_dataValuesColor = QColor( Qt::black );
                              settings->_dataValuesBrush = QBrush( Qt::NoBrush );
                              // for values below zero:
                              settings->_dataValuesAnchorNegativePosition = KDChartEnums::PosTopCenter;
                              settings->_dataValuesAnchorNegativeAlign    = Qt::AlignTop + Qt::AlignHCenter;
                              settings->_dataValuesAnchorNegativeDeltaX   =  0;
                              settings->_dataValuesAnchorNegativeDeltaY   = 50;
                              settings->_dataValuesNegativeRotation       = TANGENTIAL_ROTATION;
                              // for values greater/equal zero:
                              settings->_dataValuesAnchorPositivePosition = KDChartEnums::PosTopCenter;
                              settings->_dataValuesAnchorPositiveAlign    = Qt::AlignTop + Qt::AlignHCenter;
                              settings->_dataValuesAnchorPositiveDeltaX   =  0;
                              settings->_dataValuesAnchorPositiveDeltaY   = 50;
                              settings->_dataValuesPositiveRotation       = TANGENTIAL_ROTATION;

                              settings->_dataValuesLayoutPolicy = KDChartEnums::LayoutPolicyRotate;
                          }
                          break;
                case Ring: {
                               if ( font )
                                   settings->_dataValuesFont = *font;
                               else
                                   settings->_dataValuesFont = QFont( "times", 1, QFont::Bold );
                               settings->_dataValuesUseFontRelSize = true;
                               settings->_dataValuesFontRelSize = 35;
                               settings->_dataValuesAutoColor            = true;  //  !!!
                               settings->_dataValuesColor = QColor( Qt::black );
                               settings->_dataValuesBrush = QBrush( Qt::NoBrush );
                               // for values below zero:
                               settings->_dataValuesAnchorNegativePosition = KDChartEnums::PosCenter;
                               settings->_dataValuesAnchorNegativeAlign    = Qt::AlignCenter;
                               settings->_dataValuesAnchorNegativeDeltaX   = 0;
                               settings->_dataValuesAnchorNegativeDeltaY   = 10;
                               settings->_dataValuesNegativeRotation       = TANGENTIAL_ROTATION;
                               // for values greater/equal zero:
                               settings->_dataValuesAnchorPositivePosition = KDChartEnums::PosCenter;
                               settings->_dataValuesAnchorPositiveAlign    = Qt::AlignCenter;
                               settings->_dataValuesAnchorPositiveDeltaX   = 0;
                               settings->_dataValuesAnchorPositiveDeltaY   = 10;
                               settings->_dataValuesPositiveRotation       = TANGENTIAL_ROTATION;

                               settings->_dataValuesLayoutPolicy = KDChartEnums::LayoutPolicyRotate;
                           }
                           break;

                case Polar: {
                              settings->_dataValuesFontRelSize = 26;
                                /*if ( font )
                                  settings->_dataValuesFont = *font;
                                  else
                                  settings->_dataValuesFont = QFont( "times", 1, QFont::Bold );
                                  settings->_dataValuesUseFontRelSize = true;
                                  settings->_dataValuesFontRelSize = 20;
                                  settings->_dataValuesAutoColor   = polarMarker();  //  !!!
                                  settings->_dataValuesColor = QColor( Qt::black );
                                  settings->_dataValuesBrush = QBrush( Qt::NoBrush );

                                // for values below zero:
                                settings->_dataValuesAnchorNegativePosition = KDChartEnums::PosCenter;
                                settings->_dataValuesAnchorNegativeAlign    = Qt::AlignCenter;
                                settings->_dataValuesAnchorNegativeDeltaX   = 0;
                                settings->_dataValuesAnchorNegativeDeltaY   = 0;
                                settings->_dataValuesNegativeRotation       = 0;
                                // for values greater/equal zero:
                                settings->_dataValuesAnchorNegativePosition = KDChartEnums::PosCenter;
                                settings->_dataValuesAnchorNegativeAlign    = Qt::AlignCenter;
                                settings->_dataValuesAnchorNegativeDeltaX   = 0;
                                settings->_dataValuesAnchorNegativeDeltaY   = 0;
                                settings->_dataValuesNegativeRotation       = 0;

                                settings->_dataValuesLayoutPolicy = KDChartEnums::LayoutPolicyShrinkFontSize;
                                */
                                setDefaultAxesTypes();
                                finished = false;  // use build-in default params, see KDChartParams.h::setPrintDataValues()
                            }
                            break;

                default: {
                             qDebug( "IMPLEMENTATION ERROR: Unknown chartType in setPrintDataValues()" );
                             finished = false;  // use build-in default params, see KDChartParams.h::setPrintDataValues()
                         }
            }
        }
        if ( !finished ) {
            settings->_useDefaultFontParams = false;

            if ( font )
                settings->_dataValuesFont = *font;
            else
                settings->_dataValuesFont = QFont( "times", 1, QFont::Bold );

            uint theSize( UINT_MAX == size ? 20 : size );
            settings->_dataValuesUseFontRelSize = ( 0 < theSize );
            settings->_dataValuesFontRelSize = theSize;
            if (    DATA_VALUE_AUTO_COLOR == color
                 && ( Polar != cType || polarMarker() ) ) {
                settings->_dataValuesAutoColor = true;  //  !!!
                settings->_dataValuesColor = QColor( Qt::black );
            }
            else {
                settings->_dataValuesAutoColor = false;
                if ( 0 == color )
                    settings->_dataValuesColor
                        = QColor( i ? Qt::darkBlue : Qt::black );
                else
                    settings->_dataValuesColor = *color;
            }
            settings->_dataValuesBrush = Qt::NoBrush;
            // for values below zero:
            settings->_dataValuesAnchorNegativePosition = negativePosition;
            settings->_dataValuesAnchorNegativeAlign    = negativeAlign;
            settings->_dataValuesAnchorNegativeDeltaX   = negativeDeltaX;
            settings->_dataValuesAnchorNegativeDeltaY   = negativeDeltaY;
            settings->_dataValuesNegativeRotation       = negativeRotation;
            // for values greater/equal zero:
            settings->_dataValuesAnchorPositivePosition = positivePosition;
            settings->_dataValuesAnchorPositiveAlign    = positiveAlign;
            settings->_dataValuesAnchorPositiveDeltaX   = positiveDeltaX;
            settings->_dataValuesAnchorPositiveDeltaY   = positiveDeltaY;
            settings->_dataValuesPositiveRotation       = positiveRotation;

            settings->_dataValuesLayoutPolicy = policy;
        }
        if ( 0 < chart )
            settings = &_printDataValuesSettings2;
    }
    emit changed();
}


Generated by  Doxygen 1.6.0   Back to index