1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/tutorial2.doc:11 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>chart/chartform_files.cpp Example File</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>chart/chartform_files.cpp Example File</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 | <pre>#include "canvasview.h"
|
---|
36 | #include "chartform.h"
|
---|
37 |
|
---|
38 | #include <<a href="qfile-h.html">qfile.h</a>>
|
---|
39 | #include <<a href="qfiledialog-h.html">qfiledialog.h</a>>
|
---|
40 | #include <<a href="qpainter-h.html">qpainter.h</a>>
|
---|
41 | #include <<a href="qprinter-h.html">qprinter.h</a>>
|
---|
42 | #include <<a href="qstatusbar-h.html">qstatusbar.h</a>>
|
---|
43 |
|
---|
44 |
|
---|
45 | void <a name="f172"></a>ChartForm::load( const <a href="qstring.html">QString</a>& filename )
|
---|
46 | {
|
---|
47 | <a href="qfile.html">QFile</a> file( filename );
|
---|
48 | if ( !file.<a href="qfile.html#open">open</a>( IO_ReadOnly ) ) {
|
---|
49 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( QString( "Failed to load \'%1\'" ).
|
---|
50 | arg( filename ), 2000 );
|
---|
51 | return;
|
---|
52 | }
|
---|
53 |
|
---|
54 | init(); // Make sure we have colours
|
---|
55 | m_filename = filename;
|
---|
56 | <a href="qtextstream.html">QTextStream</a> ts( &file );
|
---|
57 | Element element;
|
---|
58 | int errors = 0;
|
---|
59 | int i = 0;
|
---|
60 | while ( !ts.<a href="qtextstream.html#eof">eof</a>() ) {
|
---|
61 | ts >> element;
|
---|
62 | if ( element.isValid() )
|
---|
63 | m_elements[i++] = element;
|
---|
64 | else
|
---|
65 | errors++;
|
---|
66 | if ( i == MAX_ELEMENTS ) {
|
---|
67 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message(
|
---|
68 | QString( "Read maximum number of elements (%1)"
|
---|
69 | " discarding others" ).arg( i ), 2000 );
|
---|
70 | break;
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | file.<a href="qfile.html#close">close</a>();
|
---|
75 |
|
---|
76 | <a href="qstring.html">QString</a> bad = "";
|
---|
77 | if ( errors ) {
|
---|
78 | bad = QString( "; skipped " ) + QString::number( errors ) + " bad record";
|
---|
79 | if ( errors > 1 )
|
---|
80 | bad += "s";
|
---|
81 | }
|
---|
82 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( QString( "Read %1 values from \'%2\'%3" ).
|
---|
83 | arg( i ).arg( filename ).arg( bad ), 3000 );
|
---|
84 |
|
---|
85 | <a href="qwidget.html#setCaption">setCaption</a>( QString( "Chart -- %1" ).arg( filename ) );
|
---|
86 | updateRecentFiles( filename );
|
---|
87 |
|
---|
88 | drawElements();
|
---|
89 | m_changed = FALSE;
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | void <a name="f173"></a>ChartForm::fileSave()
|
---|
94 | {
|
---|
95 | if ( m_filename.isEmpty() ) {
|
---|
96 | fileSaveAs();
|
---|
97 | return;
|
---|
98 | }
|
---|
99 |
|
---|
100 | <a href="qfile.html">QFile</a> file( m_filename );
|
---|
101 | if ( !file.<a href="qfile.html#open">open</a>( IO_WriteOnly ) ) {
|
---|
102 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( QString( "Failed to save \'%1\'" ).
|
---|
103 | arg( m_filename ), 2000 );
|
---|
104 | return;
|
---|
105 | }
|
---|
106 | <a href="qtextstream.html">QTextStream</a> ts( &file );
|
---|
107 | for ( int i = 0; i < MAX_ELEMENTS; ++i )
|
---|
108 | if ( m_elements[i].isValid() )
|
---|
109 | ts << m_elements[i];
|
---|
110 |
|
---|
111 | file.<a href="qfile.html#close">close</a>();
|
---|
112 |
|
---|
113 | <a href="qwidget.html#setCaption">setCaption</a>( QString( "Chart -- %1" ).arg( m_filename ) );
|
---|
114 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( QString( "Saved \'%1\'" ).arg( m_filename ), 2000 );
|
---|
115 | m_changed = FALSE;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | void <a name="f174"></a>ChartForm::fileSaveAsPixmap()
|
---|
120 | {
|
---|
121 | <a href="qstring.html">QString</a> filename = QFileDialog::<a href="qfiledialog.html#getSaveFileName">getSaveFileName</a>(
|
---|
122 | QString::null, "Images (*.png *.xpm *.jpg)",
|
---|
123 | this, "file save as bitmap",
|
---|
124 | "Chart -- File Save As Bitmap" );
|
---|
125 | if ( QPixmap::<a href="qpixmap.html#grabWidget">grabWidget</a>( m_canvasView ).
|
---|
126 | save( filename,
|
---|
127 | filename.<a href="qstring.html#mid">mid</a>( filename.<a href="qstring.html#findRev">findRev</a>( '.' ) + 1 ).upper() ) )
|
---|
128 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( QString( "Wrote \'%1\'" ).arg( filename ), 2000 );
|
---|
129 | else
|
---|
130 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( QString( "Failed to write \'%1\'" ).
|
---|
131 | arg( filename ), 2000 );
|
---|
132 | }
|
---|
133 |
|
---|
134 | void <a name="f175"></a>ChartForm::filePrint()
|
---|
135 | {
|
---|
136 | if ( !m_printer )
|
---|
137 | m_printer = new <a href="qprinter.html">QPrinter</a>;
|
---|
138 | if ( m_printer-><a href="qprinter.html#setup">setup</a>() ) {
|
---|
139 | <a href="qpainter.html">QPainter</a> painter( m_printer );
|
---|
140 | m_canvas->drawArea( QRect( 0, 0, m_canvas->width(), m_canvas->height() ),
|
---|
141 | &painter, FALSE );
|
---|
142 | if ( !m_printer-><a href="qprinter.html#outputFileName">outputFileName</a>().isEmpty() )
|
---|
143 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( QString( "Printed \'%1\'" ).
|
---|
144 | arg( m_printer-><a href="qprinter.html#outputFileName">outputFileName</a>() ), 2000 );
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | </pre><!-- eof -->
|
---|
149 | <p><address><hr><div align=center>
|
---|
150 | <table width=100% cellspacing=0 border=0><tr>
|
---|
151 | <td>Copyright © 2007
|
---|
152 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
153 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
154 | </table></div></address></body>
|
---|
155 | </html>
|
---|