QDebug operator<<(QDebug dbg, const KDChart::FrameAttributes& fa)
{
    dbg << "KDChart::FrameAttributes("
	<< "visible="<<fa.isVisible()
	<< "pen="<<fa.pen()
	<< "padding="<<fa.padding()
	<< ")";
    return dbg;
}
示例#2
0
bool Surface::loadOdf( const KoXmlElement &surfaceElement, KoShapeLoadingContext &context )
{
    KoStyleStack &styleStack = context.odfLoadingContext().styleStack();
    styleStack.save();
    
    if ( surfaceElement.hasAttributeNS( KoXmlNS::chart, "style-name" ) )
    {
        KDChart::BackgroundAttributes backgroundAttributes = d->kdPlane->backgroundAttributes();
        KDChart::FrameAttributes frameAttributes = d->kdPlane->frameAttributes();
        
        styleStack.clear();
        context.odfLoadingContext().fillStyleStack( surfaceElement, KoXmlNS::chart, "style-name", "chart" );
        
        styleStack.setTypeProperties( "graphic" );
        
        if ( styleStack.hasProperty( KoXmlNS::draw, "stroke" ) )
        {
            frameAttributes.setVisible( true );
            QString stroke = styleStack.property( KoXmlNS::draw, "stroke" );
            if( stroke == "solid" || stroke == "dash" )
            {
                QPen pen = KoOdfGraphicStyles::loadOdfStrokeStyle( styleStack, stroke, context.odfLoadingContext().stylesReader() );
                frameAttributes.setPen( pen );
            }
        }
        
        if ( styleStack.hasProperty( KoXmlNS::draw, "fill" ) )
        {
            backgroundAttributes.setVisible( true );
            QBrush brush;
            QString fill = styleStack.property( KoXmlNS::draw, "fill" );
            if ( fill == "solid" || fill == "hatch" )
                brush = KoOdfGraphicStyles::loadOdfFillStyle( styleStack, fill, context.odfLoadingContext().stylesReader() );
            else if ( fill == "gradient" )
            {
                brush = KoOdfGraphicStyles::loadOdfGradientStyle( styleStack, context.odfLoadingContext().stylesReader(), QSizeF( 5.0, 60.0 ) );
            }
            else if ( fill == "bitmap" )
                brush = KoOdfGraphicStyles::loadOdfPatternStyle( styleStack, context.odfLoadingContext(), QSizeF( 5.0, 60.0 ) );
            backgroundAttributes.setBrush( brush );
        }
        
        d->kdPlane->setBackgroundAttributes( backgroundAttributes );
        d->kdPlane->setFrameAttributes( frameAttributes );
    }

    styleStack.restore();
    
    return true;
}
示例#3
0
bool Surface::loadOdf(const KoXmlElement &surfaceElement,
                       KoShapeLoadingContext &context)
{
    // Get the current style stack and save it's state.
    KoStyleStack &styleStack = context.odfLoadingContext().styleStack();

    bool brushLoaded = false;
    
    if (surfaceElement.hasAttributeNS(KoXmlNS::chart, "style-name")) {
        KDChart::BackgroundAttributes backgroundAttributes = d->kdPlane->backgroundAttributes();
        KDChart::FrameAttributes frameAttributes = d->kdPlane->frameAttributes();
        
        // Add the chart style to the style stack.
        styleStack.clear();
        context.odfLoadingContext().fillStyleStack(surfaceElement, KoXmlNS::chart, "style-name", "chart");
        
        styleStack.setTypeProperties("graphic");
        
        // If there is a "stroke" property, then get the stroke style
        // and set the pen accordingly.
        if (styleStack.hasProperty(KoXmlNS::draw, "stroke")) {
            frameAttributes.setVisible(true);

            QString  stroke = styleStack.property(KoXmlNS::draw, "stroke");
            QPen pen(Qt::NoPen);
            if (stroke == "solid" || stroke == "dash")
                pen = KoOdfGraphicStyles::loadOdfStrokeStyle(styleStack, stroke,
                                                             context.odfLoadingContext().stylesReader());

            frameAttributes.setPen(pen);
        }
        
        // If there is a "fill" property, then get the fill style, and
        // set the brush for the surface accordingly.
        if (styleStack.hasProperty(KoXmlNS::draw, "fill")) {
            backgroundAttributes.setVisible(true);

            QBrush   brush;
            QString  fill = styleStack.property(KoXmlNS::draw, "fill");
            if (fill == "solid" || fill == "hatch") {
                brushLoaded = true;
                brush = KoOdfGraphicStyles::loadOdfFillStyle(styleStack, fill,
                                                             context.odfLoadingContext().stylesReader());
            }
            else if (fill == "gradient") {
                brushLoaded = true;
                brush = KoOdfGraphicStyles::loadOdfGradientStyle(styleStack, context.odfLoadingContext().stylesReader(), QSizeF(5.0, 60.0));
            }
            else if (fill == "bitmap") {
                brushLoaded = true;
                brush = loadOdfPatternStyle(styleStack, context.odfLoadingContext(), QSizeF(5.0, 60.0));
            }

            backgroundAttributes.setBrush(brush);
        }
        
        // Finally actually set the attributes.
        d->kdPlane->setBackgroundAttributes(backgroundAttributes);
        d->kdPlane->setFrameAttributes(frameAttributes);
    }

#ifndef NWORKAROUND_ODF_BUGS
    if (!brushLoaded) {
        KDChart::BackgroundAttributes backgroundAttributes = d->kdPlane->backgroundAttributes();
        QColor fillColor = KoOdfWorkaround::fixMissingFillColor(surfaceElement, context);
        if (fillColor.isValid()) {
            backgroundAttributes.setVisible(true);
            backgroundAttributes.setBrush(fillColor);
            d->kdPlane->setBackgroundAttributes(backgroundAttributes);
        }
    }
#endif
    
    return true;
}
示例#4
0
int main(int argc, char *argv[]) {
	QApplication a(argc, argv);
	KDChart::Chart chart;

	QStandardItemModel model;

        const double offset = 600;
	model.setRowCount( 100 );
	model.setColumnCount( 2 ); // 1 data set
	for ( int i = 0; i < 100; ++i ) {
		double t = i + offset;
		double v = i + offset;
		QModelIndex index = model.index( i, 0 );
		model.setData( index, t );
		index = model.index( i, 1 );
		model.setData( index, v );
	}

	model.setHeaderData( 0, Qt::Horizontal, "Dataset 1" );

	// general chart layout
	KDChart::FrameAttributes fm = chart.frameAttributes();
	fm.setVisible( true );
	fm.setPen( QPen( Qt::black ) );
	chart.setFrameAttributes( fm );
	chart.setGlobalLeading( 10, 0, 10, 10 );

	KDChart::BackgroundAttributes chart_bg;
	chart_bg.setBrush( Qt::white );
	chart_bg.setVisible( true );
	chart.setBackgroundAttributes( chart_bg );

	// coordinate plane setup
	KDChart::AbstractCoordinatePlane * plane1 = chart.coordinatePlane();
	plane1->setRubberBandZoomingEnabled( true );

	// create cartesian diagrams
	KDChart::Plotter * plotter = new KDChart::Plotter;
	plotter->setAntiAliasing( false );
	plotter->setModel( &model );
	plane1->replaceDiagram( plotter );

	// customize grids
	KDChart::CartesianCoordinatePlane * cp1 = static_cast< KDChart::CartesianCoordinatePlane * >( plane1 );
	KDChart::GridAttributes gv = cp1->gridAttributes( Qt::Vertical );
	QPen gridPen( QColor( 200, 100, 100 ) );
	gridPen.setStyle( Qt::DashLine );
	gv.setGridPen( gridPen );
	gridPen.setStyle( Qt::DotLine );
	gridPen.setColor( QColor( 255,155,155 ) );
	gv.setSubGridPen( gridPen );
	cp1->setGridAttributes( Qt::Vertical,  gv );

        // Enable isometric scaling
        cp1->setIsometricScaling( true );

	// axis
	KDChart::CartesianAxis * xAxis = new KDChart::CartesianAxis( plotter );
	xAxis->setPosition( KDChart::CartesianAxis::Bottom );
	xAxis->setTitleText("X-Title");

	KDChart::TextAttributes att = xAxis->titleTextAttributes();
	QFont f = att.font();
	f.setBold( true );
	att.setFont( f );
	att.setAutoShrink( true );
	att.setFontSize( KDChart::Measure( 16 ) );
	xAxis->setTitleTextAttributes( att );

	KDChart::CartesianAxis * y1Axis = new KDChart::CartesianAxis( plotter );
	y1Axis->setPosition( KDChart::CartesianAxis::Left );
	y1Axis->setTitleText( "Y-Title" );

	att = y1Axis->titleTextAttributes();
	f = att.font();
	f.setBold( true );
	att.setFont( f );
	att.setAutoShrink( true );
	att.setFontSize( KDChart::Measure( 16 ) );
	y1Axis->setTitleTextAttributes( att );

	// add the axis to the plotter
	plotter->addAxis( xAxis );
	plotter->addAxis( y1Axis );

	// create legend
	KDChart::Legend * legend = new KDChart::Legend( plotter, &chart );
	chart.addLegend( legend );
	att = legend->textAttributes();
	f = att.font();
	f.setBold( false );
	att.setFont( f );
	att.setAutoShrink( true );
	legend->setTextAttributes( att );

	legend->setPosition( KDChart::Position::East );
	legend->setAlignment( Qt::AlignCenter );
	legend->setTitleText( "Curves" );
	att = legend->titleTextAttributes();
	f = att.font();
	f.setBold( true );
	att.setFont( f );
	att.setAutoShrink( true );
	att.setFontSize( KDChart::Measure( 16 ) );
	legend->setTitleTextAttributes( att );

	KDChart::BackgroundAttributes legend_bg;
	legend_bg.setBrush( Qt::white );
	legend_bg.setVisible( true );
	legend->setBackgroundAttributes( legend_bg );

	KDChart::DataValueAttributes attr = plotter->dataValueAttributes();
	KDChart::TextAttributes tattr = attr.textAttributes();
        tattr.setFontSize( KDChart::Measure( 12, KDChartEnums::MeasureCalculationModeAbsolute ) );
	tattr.setRotation( 0 );
	attr.setTextAttributes( tattr );
	plotter->setDataValueAttributes( attr );

	// customize marker properties

	// Dataset 1 : green, MarkerRing, no line
	QColor SERIES_1_OUTLINE = QColor( 0, 128, 0 );
	attr = plotter->dataValueAttributes( 0 );
	KDChart::MarkerAttributes mattr = attr.markerAttributes();
	mattr.setMarkerColor( SERIES_1_OUTLINE );
//        mattr.setMarkerStyle( KDChart::MarkerAttributes::MarkerRing );
	mattr.setMarkerSize( QSizeF( 6.0, 6.0 ) );
	mattr.setVisible( true );
	attr.setMarkerAttributes( mattr );
	attr.setVisible( true );
	plotter->setDataValueAttributes( 0, attr );
	plotter->setPen( 0, Qt::NoPen );

	chart.show();
	return a.exec();
}
示例#5
0
int main( int argc, char** argv )
{
    QApplication app( argc, argv );

    const int points = 420;
    const double xMin = 0;
    const double xMax = 20;
    const double step = ( xMax - xMin ) / ( points - 1 );

    QStandardItemModel model( points, 6 );

    double x = xMin;
    for ( int n = 0; n < points; ++n, x += step) {
        QModelIndex index = model.index( n, 0 );
        model.setData( index, x );
        index = model.index( n, 1 );
        model.setData( index, sin( x ) * 100.0 );

        index = model.index( n, 2 );
        model.setData( index, x );
        index = model.index( n, 3 );
        model.setData( index, x );

        index = model.index( n, 4 );
        model.setData( index, x );
        index = model.index( n, 5 );
        model.setData( index, x * x * x );
    }

    model.setHeaderData( 0, Qt::Horizontal, QString::fromLatin1( "100 * sin(x)" ) );
    model.setHeaderData( 2, Qt::Horizontal, QString::fromLatin1( "x" ) );
    model.setHeaderData( 4, Qt::Horizontal, QString::fromLatin1( "x^3" ) );

    KDChart::Chart* chart = new KDChart::Chart();

    KDChart::AbstractCartesianDiagram* diagram = new KDChart::Plotter;
    diagram->setModel( &model );
    chart->coordinatePlane()->replaceDiagram( diagram );

    KDChart::CartesianAxis* xAxis = new KDChart::CartesianAxis( diagram );
    KDChart::CartesianAxis* yAxis = new KDChart::CartesianAxis( diagram );
    xAxis->setPosition( KDChart::CartesianAxis::Bottom );
    yAxis->setPosition( KDChart::CartesianAxis::Left );
    diagram->addAxis( xAxis );
    diagram->addAxis( yAxis );

    KDChart::Legend* legend = new KDChart::Legend( diagram, chart );
    KDChart::FrameAttributes legendAtt = legend->frameAttributes();
    legendAtt.setCornerRadius( 9 );
    legend->setFrameAttributes( legendAtt );
    legend->setPosition( KDChart::Position::East );
    legend->setAlignment( Qt::AlignCenter );
    legend->setTitleText( "Legend" );
    chart->addLegend( legend );

    KDChart::CartesianCoordinatePlane* cart_plane = dynamic_cast<KDChart::CartesianCoordinatePlane*>(chart->coordinatePlane());
    Q_ASSERT(cart_plane);

    cart_plane->setAxesCalcModeX(KDChart::AbstractCoordinatePlane::Logarithmic);
    cart_plane->setAxesCalcModeY(KDChart::AbstractCoordinatePlane::Logarithmic);

    // Set the vertical range from 15 to 75 - with a logarithmic axis I actually get 1 to 100
    //cart_plane->setVerticalRange(QPair<qreal,qreal>( 0.005, 1000 ) );

    // Set the horizontal range from 1 to 9 - with a linear axis this works OK
    cart_plane->setHorizontalRange(QPair<qreal,qreal>( 0.001, 100 ) );

    chart->show();

    int ret = app.exec();

    delete chart;

    return ret;
}