~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kchart/kdchart/examples/Lines/Parameters/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <QtGui>
2
 
#include <KDChartChart>
3
 
#include <KDChartLineDiagram>
4
 
#include <KDChartDataValueAttributes>
5
 
 
6
 
using namespace KDChart;
7
 
 
8
 
class ChartWidget : public QWidget {
9
 
  Q_OBJECT
10
 
public:
11
 
  explicit ChartWidget(QWidget* parent=0)
12
 
    : QWidget(parent)
13
 
  {
14
 
 
15
 
    m_model.insertRows( 0,5, QModelIndex() );
16
 
    m_model.insertColumns( 0,5, QModelIndex() );
17
 
    double increase = 1.15;
18
 
    for( int i = 0; i < 5; ++i ) {
19
 
        increase += 0.06;
20
 
        for( int j = 0; j < 5; ++j ) {
21
 
            m_model.setData( m_model.index( i,j,QModelIndex() ),
22
 
                             ( increase + i ) * j * (1.0 + 0.1 * (rand() % 10)) );
23
 
        }
24
 
    }
25
 
 
26
 
    LineDiagram* diagram = new LineDiagram;
27
 
    diagram->setModel(&m_model);
28
 
 
29
 
    // Display values
30
 
    // 1 - Call the relevant attributes
31
 
    DataValueAttributes dva( diagram->dataValueAttributes() );
32
 
 
33
 
    // 2 - We want to configure the font and colors
34
 
    //     for the data values text.
35
 
    TextAttributes ta( dva.textAttributes() );
36
 
    dva.setDecimalDigits( 2 );
37
 
 
38
 
    // Append a prefix/suffix to the
39
 
    // data value labels being displayed
40
 
    //
41
 
    //dva.setPrefix( "* " );
42
 
    dva.setSuffix( " Ohm" );
43
 
 
44
 
    //rotate if you wish
45
 
    //ta.setRotation( 0 );
46
 
    // 3 - Set up your text attributes
47
 
    ta.setFont( QFont( "Comic") );
48
 
    ta .setPen( QPen( QColor( Qt::darkGreen ) ) );
49
 
    ta.setVisible( true );
50
 
    // font size
51
 
    Measure me( ta.fontSize() );
52
 
    me.setValue( me.value() * 0.25 );
53
 
    ta.setFontSize( me );
54
 
 
55
 
    // 4 - Assign the text attributes to your
56
 
    //     DataValuesAttributes
57
 
    dva.setTextAttributes( ta );
58
 
    dva.setVisible( true );
59
 
    // 5 - Assign to the diagram
60
 
    diagram->setDataValueAttributes( dva );
61
 
 
62
 
    // Set thick line widths for all datasets
63
 
    for( int i=0; i<m_model.rowCount(); ++i ){
64
 
        QPen pen( diagram->pen( i ) );
65
 
        pen.setWidth( 17 );
66
 
        diagram->setPen( i, pen );
67
 
    }
68
 
 
69
 
    // Draw one of the sections of a line differently.
70
 
    // 1 - Retrieve the pen for the dataset and change
71
 
    //    its style.
72
 
    //    This allow us to keep the line original color.
73
 
    QPen linePen(  diagram->pen( 1 ) );
74
 
    linePen.setColor( Qt::yellow );
75
 
    linePen.setWidth( 7 );
76
 
    linePen.setStyle( Qt::DashLine );
77
 
    // 2 - Change the Pen for a section within a line
78
 
    //     while assigning it to the diagram
79
 
    diagram->setPen( m_model.index( 1, 1, QModelIndex() ), linePen );
80
 
    // 3 - Assign to the chart
81
 
    m_chart.coordinatePlane()->replaceDiagram(diagram);
82
 
    m_chart.setGlobalLeadingRight(  50  );
83
 
 
84
 
    QVBoxLayout* l = new QVBoxLayout(this);
85
 
    l->addWidget(&m_chart);
86
 
    setLayout(l);
87
 
  }
88
 
 
89
 
private:
90
 
  Chart m_chart;
91
 
  QStandardItemModel m_model;
92
 
};
93
 
 
94
 
int main( int argc, char** argv ) {
95
 
    QApplication app( argc, argv );
96
 
 
97
 
    ChartWidget w;
98
 
    w.show();
99
 
 
100
 
    return app.exec();
101
 
}
102
 
 
103
 
#include "main.moc"