| 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:9 -->
|
|---|
| 3 | <html>
|
|---|
| 4 | <head>
|
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|---|
| 6 | <title>chart/chartform.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.cpp Example File</h1>
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | <pre>#include "canvasview.h"
|
|---|
| 36 | #include "chartform.h"
|
|---|
| 37 | #include "optionsform.h"
|
|---|
| 38 | #include "setdataform.h"
|
|---|
| 39 |
|
|---|
| 40 | #include <<a href="qaction-h.html">qaction.h</a>>
|
|---|
| 41 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
|---|
| 42 | #include <<a href="qcombobox-h.html">qcombobox.h</a>>
|
|---|
| 43 | #include <<a href="qfile-h.html">qfile.h</a>>
|
|---|
| 44 | #include <<a href="qfiledialog-h.html">qfiledialog.h</a>>
|
|---|
| 45 | #include <<a href="qfont-h.html">qfont.h</a>>
|
|---|
| 46 | #include <<a href="qfontdialog-h.html">qfontdialog.h</a>>
|
|---|
| 47 | #include <<a href="qmenubar-h.html">qmenubar.h</a>>
|
|---|
| 48 | #include <<a href="qmessagebox-h.html">qmessagebox.h</a>>
|
|---|
| 49 | #include <<a href="qpixmap-h.html">qpixmap.h</a>>
|
|---|
| 50 | #include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>>
|
|---|
| 51 | #include <<a href="qprinter-h.html">qprinter.h</a>>
|
|---|
| 52 | #include <<a href="qradiobutton-h.html">qradiobutton.h</a>>
|
|---|
| 53 | #include <<a href="qsettings-h.html">qsettings.h</a>>
|
|---|
| 54 | #include <<a href="qspinbox-h.html">qspinbox.h</a>>
|
|---|
| 55 | #include <<a href="qstatusbar-h.html">qstatusbar.h</a>>
|
|---|
| 56 | #include <<a href="qtoolbar-h.html">qtoolbar.h</a>>
|
|---|
| 57 | #include <<a href="qtoolbutton-h.html">qtoolbutton.h</a>>
|
|---|
| 58 |
|
|---|
| 59 | #include "images/file_new.xpm"
|
|---|
| 60 | #include "images/file_open.xpm"
|
|---|
| 61 | #include "images/file_save.xpm"
|
|---|
| 62 | #include "images/file_print.xpm"
|
|---|
| 63 | #include "images/options_setdata.xpm"
|
|---|
| 64 | #include "images/options_setfont.xpm"
|
|---|
| 65 | #include "images/options_setoptions.xpm"
|
|---|
| 66 | #include "images/options_horizontalbarchart.xpm"
|
|---|
| 67 | #include "images/options_piechart.xpm"
|
|---|
| 68 | #include "images/options_verticalbarchart.xpm"
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | const <a href="qstring.html">QString</a> WINDOWS_REGISTRY = "/Trolltech/QtExamples";
|
|---|
| 72 | const <a href="qstring.html">QString</a> APP_KEY = "/Chart/";
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | <a name="f148"></a>ChartForm::ChartForm( const <a href="qstring.html">QString</a>& filename )
|
|---|
| 76 | : <a href="qmainwindow.html">QMainWindow</a>( 0, 0, WDestructiveClose )
|
|---|
| 77 | {
|
|---|
| 78 | <a href="qwidget.html#setIcon">setIcon</a>( QPixmap( options_piechart ) );
|
|---|
| 79 |
|
|---|
| 80 | <a href="qaction.html">QAction</a> *fileNewAction;
|
|---|
| 81 | <a href="qaction.html">QAction</a> *fileOpenAction;
|
|---|
| 82 | <a href="qaction.html">QAction</a> *fileSaveAction;
|
|---|
| 83 | <a href="qaction.html">QAction</a> *fileSaveAsAction;
|
|---|
| 84 | <a href="qaction.html">QAction</a> *fileSaveAsPixmapAction;
|
|---|
| 85 | <a href="qaction.html">QAction</a> *filePrintAction;
|
|---|
| 86 | <a href="qaction.html">QAction</a> *fileQuitAction;
|
|---|
| 87 | <a href="qaction.html">QAction</a> *optionsSetDataAction;
|
|---|
| 88 | <a href="qaction.html">QAction</a> *optionsSetFontAction;
|
|---|
| 89 | <a href="qaction.html">QAction</a> *optionsSetOptionsAction;
|
|---|
| 90 |
|
|---|
| 91 | fileNewAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 92 | "New Chart", QPixmap( file_new ),
|
|---|
| 93 | "&New", CTRL+Key_N, this, "new" );
|
|---|
| 94 | <a name="x2869"></a> <a href="qobject.html#connect">connect</a>( fileNewAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ), this, SLOT( fileNew() ) );
|
|---|
| 95 |
|
|---|
| 96 | fileOpenAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 97 | "Open Chart", QPixmap( file_open ),
|
|---|
| 98 | "&Open...", CTRL+Key_O, this, "open" );
|
|---|
| 99 | <a href="qobject.html#connect">connect</a>( fileOpenAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ), this, SLOT( fileOpen() ) );
|
|---|
| 100 |
|
|---|
| 101 | fileSaveAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 102 | "Save Chart", QPixmap( file_save ),
|
|---|
| 103 | "&Save", CTRL+Key_S, this, "save" );
|
|---|
| 104 | <a href="qobject.html#connect">connect</a>( fileSaveAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ), this, SLOT( fileSave() ) );
|
|---|
| 105 |
|
|---|
| 106 | fileSaveAsAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 107 | "Save Chart As", QPixmap( file_save ),
|
|---|
| 108 | "Save &As...", 0, this, "save as" );
|
|---|
| 109 | <a href="qobject.html#connect">connect</a>( fileSaveAsAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ),
|
|---|
| 110 | this, SLOT( fileSaveAs() ) );
|
|---|
| 111 |
|
|---|
| 112 | fileSaveAsPixmapAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 113 | "Save Chart As Bitmap", QPixmap( file_save ),
|
|---|
| 114 | "Save As &Bitmap...", CTRL+Key_B, this, "save as bitmap" );
|
|---|
| 115 | <a href="qobject.html#connect">connect</a>( fileSaveAsPixmapAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ),
|
|---|
| 116 | this, SLOT( fileSaveAsPixmap() ) );
|
|---|
| 117 |
|
|---|
| 118 | filePrintAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 119 | "Print Chart", QPixmap( file_print ),
|
|---|
| 120 | "&Print Chart...", CTRL+Key_P, this, "print chart" );
|
|---|
| 121 | <a href="qobject.html#connect">connect</a>( filePrintAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ),
|
|---|
| 122 | this, SLOT( filePrint() ) );
|
|---|
| 123 |
|
|---|
| 124 | optionsSetDataAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 125 | "Set Data", QPixmap( options_setdata ),
|
|---|
| 126 | "Set &Data...", CTRL+Key_D, this, "set data" );
|
|---|
| 127 | <a href="qobject.html#connect">connect</a>( optionsSetDataAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ),
|
|---|
| 128 | this, SLOT( optionsSetData() ) );
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 | <a href="qactiongroup.html">QActionGroup</a> *chartGroup = new <a href="qactiongroup.html">QActionGroup</a>( this ); // Connected later
|
|---|
| 132 | <a name="x2874"></a> chartGroup-><a href="qactiongroup.html#setExclusive">setExclusive</a>( TRUE );
|
|---|
| 133 |
|
|---|
| 134 | optionsPieChartAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 135 | "Pie Chart", QPixmap( options_piechart ),
|
|---|
| 136 | "&Pie Chart", CTRL+Key_I, chartGroup, "pie chart" );
|
|---|
| 137 | <a name="x2872"></a> optionsPieChartAction-><a href="qaction.html#setToggleAction">setToggleAction</a>( TRUE );
|
|---|
| 138 |
|
|---|
| 139 | optionsHorizontalBarChartAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 140 | "Horizontal Bar Chart", QPixmap( options_horizontalbarchart ),
|
|---|
| 141 | "&Horizontal Bar Chart", CTRL+Key_H, chartGroup,
|
|---|
| 142 | "horizontal bar chart" );
|
|---|
| 143 | optionsHorizontalBarChartAction-><a href="qaction.html#setToggleAction">setToggleAction</a>( TRUE );
|
|---|
| 144 |
|
|---|
| 145 | optionsVerticalBarChartAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 146 | "Vertical Bar Chart", QPixmap( options_verticalbarchart ),
|
|---|
| 147 | "&Vertical Bar Chart", CTRL+Key_V, chartGroup, "Vertical bar chart" );
|
|---|
| 148 | optionsVerticalBarChartAction-><a href="qaction.html#setToggleAction">setToggleAction</a>( TRUE );
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 | optionsSetFontAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 152 | "Set Font", QPixmap( options_setfont ),
|
|---|
| 153 | "Set &Font...", CTRL+Key_F, this, "set font" );
|
|---|
| 154 | <a href="qobject.html#connect">connect</a>( optionsSetFontAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ),
|
|---|
| 155 | this, SLOT( optionsSetFont() ) );
|
|---|
| 156 |
|
|---|
| 157 | optionsSetOptionsAction = new <a href="qaction.html">QAction</a>(
|
|---|
| 158 | "Set Options", QPixmap( options_setoptions ),
|
|---|
| 159 | "Set &Options...", 0, this, "set options" );
|
|---|
| 160 | <a href="qobject.html#connect">connect</a>( optionsSetOptionsAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ),
|
|---|
| 161 | this, SLOT( optionsSetOptions() ) );
|
|---|
| 162 |
|
|---|
| 163 | fileQuitAction = new <a href="qaction.html">QAction</a>( "Quit", "&Quit", CTRL+Key_Q, this, "quit" );
|
|---|
| 164 | <a href="qobject.html#connect">connect</a>( fileQuitAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ), this, SLOT( fileQuit() ) );
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 | <a href="qtoolbar.html">QToolBar</a>* fileTools = new <a href="qtoolbar.html">QToolBar</a>( this, "file operations" );
|
|---|
| 168 | <a name="x2895"></a> fileTools-><a href="qtoolbar.html#setLabel">setLabel</a>( "File Operations" );
|
|---|
| 169 | <a name="x2870"></a> fileNewAction-><a href="qaction.html#addTo">addTo</a>( fileTools );
|
|---|
| 170 | fileOpenAction-><a href="qaction.html#addTo">addTo</a>( fileTools );
|
|---|
| 171 | fileSaveAction-><a href="qaction.html#addTo">addTo</a>( fileTools );
|
|---|
| 172 | <a name="x2894"></a> fileTools-><a href="qtoolbar.html#addSeparator">addSeparator</a>();
|
|---|
| 173 | filePrintAction-><a href="qaction.html#addTo">addTo</a>( fileTools );
|
|---|
| 174 |
|
|---|
| 175 | <a href="qtoolbar.html">QToolBar</a> *optionsTools = new <a href="qtoolbar.html">QToolBar</a>( this, "options operations" );
|
|---|
| 176 | optionsTools-><a href="qtoolbar.html#setLabel">setLabel</a>( "Options Operations" );
|
|---|
| 177 | optionsSetDataAction-><a href="qaction.html#addTo">addTo</a>( optionsTools );
|
|---|
| 178 | optionsTools-><a href="qtoolbar.html#addSeparator">addSeparator</a>();
|
|---|
| 179 | optionsPieChartAction-><a href="qaction.html#addTo">addTo</a>( optionsTools );
|
|---|
| 180 | optionsHorizontalBarChartAction-><a href="qaction.html#addTo">addTo</a>( optionsTools );
|
|---|
| 181 | optionsVerticalBarChartAction-><a href="qaction.html#addTo">addTo</a>( optionsTools );
|
|---|
| 182 | optionsTools-><a href="qtoolbar.html#addSeparator">addSeparator</a>();
|
|---|
| 183 | optionsSetFontAction-><a href="qaction.html#addTo">addTo</a>( optionsTools );
|
|---|
| 184 | optionsTools-><a href="qtoolbar.html#addSeparator">addSeparator</a>();
|
|---|
| 185 | optionsSetOptionsAction-><a href="qaction.html#addTo">addTo</a>( optionsTools );
|
|---|
| 186 |
|
|---|
| 187 | fileMenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
|---|
| 188 | <a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&File", fileMenu );
|
|---|
| 189 | fileNewAction-><a href="qaction.html#addTo">addTo</a>( fileMenu );
|
|---|
| 190 | fileOpenAction-><a href="qaction.html#addTo">addTo</a>( fileMenu );
|
|---|
| 191 | fileSaveAction-><a href="qaction.html#addTo">addTo</a>( fileMenu );
|
|---|
| 192 | fileSaveAsAction-><a href="qaction.html#addTo">addTo</a>( fileMenu );
|
|---|
| 193 | fileMenu-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
|---|
| 194 | fileSaveAsPixmapAction-><a href="qaction.html#addTo">addTo</a>( fileMenu );
|
|---|
| 195 | fileMenu-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
|---|
| 196 | filePrintAction-><a href="qaction.html#addTo">addTo</a>( fileMenu );
|
|---|
| 197 | fileMenu-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
|---|
| 198 | fileQuitAction-><a href="qaction.html#addTo">addTo</a>( fileMenu );
|
|---|
| 199 |
|
|---|
| 200 | optionsMenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
|---|
| 201 | <a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&Options", optionsMenu );
|
|---|
| 202 | optionsSetDataAction-><a href="qaction.html#addTo">addTo</a>( optionsMenu );
|
|---|
| 203 | optionsMenu-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
|---|
| 204 | optionsPieChartAction-><a href="qaction.html#addTo">addTo</a>( optionsMenu );
|
|---|
| 205 | optionsHorizontalBarChartAction-><a href="qaction.html#addTo">addTo</a>( optionsMenu );
|
|---|
| 206 | optionsVerticalBarChartAction-><a href="qaction.html#addTo">addTo</a>( optionsMenu );
|
|---|
| 207 | optionsMenu-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
|---|
| 208 | optionsSetFontAction-><a href="qaction.html#addTo">addTo</a>( optionsMenu );
|
|---|
| 209 | optionsMenu-><a href="qmenudata.html#insertSeparator">insertSeparator</a>();
|
|---|
| 210 | optionsSetOptionsAction-><a href="qaction.html#addTo">addTo</a>( optionsMenu );
|
|---|
| 211 |
|
|---|
| 212 | <a href="qmainwindow.html#menuBar">menuBar</a>()->insertSeparator();
|
|---|
| 213 |
|
|---|
| 214 | <a href="qpopupmenu.html">QPopupMenu</a> *helpMenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
|
|---|
| 215 | <a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&Help", helpMenu );
|
|---|
| 216 | helpMenu-><a href="qmenudata.html#insertItem">insertItem</a>( "&Help", this, SLOT(helpHelp()), Key_F1 );
|
|---|
| 217 | helpMenu-><a href="qmenudata.html#insertItem">insertItem</a>( "&About", this, SLOT(helpAbout()) );
|
|---|
| 218 | helpMenu-><a href="qmenudata.html#insertItem">insertItem</a>( "About &Qt", this, SLOT(helpAboutQt()) );
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 | m_printer = 0;
|
|---|
| 222 | m_elements.resize( MAX_ELEMENTS );
|
|---|
| 223 |
|
|---|
| 224 | <a href="qsettings.html">QSettings</a> settings;
|
|---|
| 225 | <a name="x2890"></a> settings.<a href="qsettings.html#insertSearchPath">insertSearchPath</a>( QSettings::Windows, WINDOWS_REGISTRY );
|
|---|
| 226 | int windowWidth = settings.<a href="qsettings.html#readNumEntry">readNumEntry</a>( APP_KEY + "WindowWidth", 460 );
|
|---|
| 227 | int windowHeight = settings.<a href="qsettings.html#readNumEntry">readNumEntry</a>( APP_KEY + "WindowHeight", 530 );
|
|---|
| 228 | int windowX = settings.<a href="qsettings.html#readNumEntry">readNumEntry</a>( APP_KEY + "WindowX", -1 );
|
|---|
| 229 | int windowY = settings.<a href="qsettings.html#readNumEntry">readNumEntry</a>( APP_KEY + "WindowY", -1 );
|
|---|
| 230 | setChartType( ChartType(
|
|---|
| 231 | settings.<a href="qsettings.html#readNumEntry">readNumEntry</a>( APP_KEY + "ChartType", int(PIE) ) ) );
|
|---|
| 232 | m_addValues = AddValuesType(
|
|---|
| 233 | settings.<a href="qsettings.html#readNumEntry">readNumEntry</a>( APP_KEY + "AddValues", int(NO) ));
|
|---|
| 234 | m_decimalPlaces = settings.<a href="qsettings.html#readNumEntry">readNumEntry</a>( APP_KEY + "Decimals", 2 );
|
|---|
| 235 | m_font = QFont( "Helvetica", 18, QFont::Bold );
|
|---|
| 236 | m_font.fromString(
|
|---|
| 237 | settings.<a href="qsettings.html#readEntry">readEntry</a>( APP_KEY + "Font", m_font.toString() ) );
|
|---|
| 238 | for ( int i = 0; i < MAX_RECENTFILES; ++i ) {
|
|---|
| 239 | <a href="qstring.html">QString</a> filename = settings.<a href="qsettings.html#readEntry">readEntry</a>( APP_KEY + "File" +
|
|---|
| 240 | <a name="x2893"></a> QString::<a href="qstring.html#number">number</a>( i + 1 ) );
|
|---|
| 241 | <a name="x2892"></a> if ( !filename.<a href="qstring.html#isEmpty">isEmpty</a>() )
|
|---|
| 242 | m_recentFiles.push_back( filename );
|
|---|
| 243 | }
|
|---|
| 244 | if ( m_recentFiles.count() )
|
|---|
| 245 | updateRecentFilesMenu();
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 | // Connect *after* we've set the chart type on so we don't call
|
|---|
| 249 | // drawElements() prematurely.
|
|---|
| 250 | <a name="x2873"></a> <a href="qobject.html#connect">connect</a>( chartGroup, SIGNAL( <a href="qactiongroup.html#selected">selected</a>(QAction*) ),
|
|---|
| 251 | this, SLOT( updateChartType(QAction*) ) );
|
|---|
| 252 |
|
|---|
| 253 | <a href="qwidget.html#resize">resize</a>( windowWidth, windowHeight );
|
|---|
| 254 | if ( windowX != -1 || windowY != -1 )
|
|---|
| 255 | <a href="qwidget.html#move">move</a>( windowX, windowY );
|
|---|
| 256 |
|
|---|
| 257 | m_canvas = new <a href="qcanvas.html">QCanvas</a>( this );
|
|---|
| 258 | <a name="x2876"></a> m_canvas-><a href="qcanvas.html#resize">resize</a>( <a href="qwidget.html#width">width</a>(), height() );
|
|---|
| 259 | m_canvasView = new CanvasView( m_canvas, &m_elements, this );
|
|---|
| 260 | <a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>( m_canvasView );
|
|---|
| 261 | m_canvasView-><a href="qwidget.html#show">show</a>();
|
|---|
| 262 |
|
|---|
| 263 | if ( !filename.<a href="qstring.html#isEmpty">isEmpty</a>() )
|
|---|
| 264 | load( filename );
|
|---|
| 265 | else {
|
|---|
| 266 | init();
|
|---|
| 267 | m_elements[0].set( 20, red, 14, "Red" );
|
|---|
| 268 | m_elements[1].set( 70, cyan, 2, "Cyan", darkGreen );
|
|---|
| 269 | m_elements[2].set( 35, blue, 11, "Blue" );
|
|---|
| 270 | m_elements[3].set( 55, yellow, 1, "Yellow", darkBlue );
|
|---|
| 271 | m_elements[4].set( 80, magenta, 1, "Magenta" );
|
|---|
| 272 | drawElements();
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Ready", 2000 );
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 | ChartForm::~ChartForm()
|
|---|
| 280 | {
|
|---|
| 281 | delete m_printer;
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 | void <a name="f149"></a>ChartForm::init()
|
|---|
| 286 | {
|
|---|
| 287 | <a href="qwidget.html#setCaption">setCaption</a>( "Chart" );
|
|---|
| 288 | m_filename = QString::null;
|
|---|
| 289 | m_changed = FALSE;
|
|---|
| 290 |
|
|---|
| 291 | m_elements[0] = Element( Element::INVALID, red );
|
|---|
| 292 | m_elements[1] = Element( Element::INVALID, cyan );
|
|---|
| 293 | m_elements[2] = Element( Element::INVALID, blue );
|
|---|
| 294 | m_elements[3] = Element( Element::INVALID, yellow );
|
|---|
| 295 | m_elements[4] = Element( Element::INVALID, green );
|
|---|
| 296 | m_elements[5] = Element( Element::INVALID, magenta );
|
|---|
| 297 | m_elements[6] = Element( Element::INVALID, darkYellow );
|
|---|
| 298 | m_elements[7] = Element( Element::INVALID, darkRed );
|
|---|
| 299 | m_elements[8] = Element( Element::INVALID, darkCyan );
|
|---|
| 300 | m_elements[9] = Element( Element::INVALID, darkGreen );
|
|---|
| 301 | m_elements[10] = Element( Element::INVALID, darkMagenta );
|
|---|
| 302 | m_elements[11] = Element( Element::INVALID, darkBlue );
|
|---|
| 303 | for ( int i = 12; i < MAX_ELEMENTS; ++i ) {
|
|---|
| 304 | double x = (double(i) / MAX_ELEMENTS) * 360;
|
|---|
| 305 | int y = (int(x * 256) % 105) + 151;
|
|---|
| 306 | int z = ((i * 17) % 105) + 151;
|
|---|
| 307 | m_elements[i] = Element( Element::INVALID, QColor( int(x), y, z, QColor::Hsv ) );
|
|---|
| 308 | }
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | <a name="x2896"></a>void ChartForm::<a href="qwidget.html#closeEvent">closeEvent</a>( <a href="qcloseevent.html">QCloseEvent</a> * )
|
|---|
| 312 | {
|
|---|
| 313 | fileQuit();
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 | void <a name="f150"></a>ChartForm::fileNew()
|
|---|
| 318 | {
|
|---|
| 319 | if ( okToClear() ) {
|
|---|
| 320 | init();
|
|---|
| 321 | drawElements();
|
|---|
| 322 | }
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 | void <a name="f151"></a>ChartForm::fileOpen()
|
|---|
| 327 | {
|
|---|
| 328 | if ( !okToClear() )
|
|---|
| 329 | return;
|
|---|
| 330 |
|
|---|
| 331 | <a href="qstring.html">QString</a> filename = QFileDialog::<a href="qfiledialog.html#getOpenFileName">getOpenFileName</a>(
|
|---|
| 332 | QString::null, "Charts (*.cht)", this,
|
|---|
| 333 | "file open", "Chart -- File Open" );
|
|---|
| 334 | if ( !filename.<a href="qstring.html#isEmpty">isEmpty</a>() )
|
|---|
| 335 | load( filename );
|
|---|
| 336 | else
|
|---|
| 337 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "File Open abandoned", 2000 );
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 | void <a name="f152"></a>ChartForm::fileSaveAs()
|
|---|
| 342 | {
|
|---|
| 343 | <a href="qstring.html">QString</a> filename = QFileDialog::<a href="qfiledialog.html#getSaveFileName">getSaveFileName</a>(
|
|---|
| 344 | QString::null, "Charts (*.cht)", this,
|
|---|
| 345 | "file save as", "Chart -- File Save As" );
|
|---|
| 346 | if ( !filename.<a href="qstring.html#isEmpty">isEmpty</a>() ) {
|
|---|
| 347 | int answer = 0;
|
|---|
| 348 | <a name="x2878"></a> if ( QFile::<a href="qfile.html#exists">exists</a>( filename ) )
|
|---|
| 349 | <a name="x2889"></a> answer = QMessageBox::<a href="qmessagebox.html#warning">warning</a>(
|
|---|
| 350 | this, "Chart -- Overwrite File",
|
|---|
| 351 | QString( "Overwrite\n\'%1\'?" ).
|
|---|
| 352 | arg( filename ),
|
|---|
| 353 | "&Yes", "&No", QString::null, 1, 1 );
|
|---|
| 354 | if ( answer == 0 ) {
|
|---|
| 355 | m_filename = filename;
|
|---|
| 356 | updateRecentFiles( filename );
|
|---|
| 357 | fileSave();
|
|---|
| 358 | return;
|
|---|
| 359 | }
|
|---|
| 360 | }
|
|---|
| 361 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Saving abandoned", 2000 );
|
|---|
| 362 | }
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 | void <a name="f153"></a>ChartForm::fileOpenRecent( int index )
|
|---|
| 366 | {
|
|---|
| 367 | if ( !okToClear() )
|
|---|
| 368 | return;
|
|---|
| 369 |
|
|---|
| 370 | load( m_recentFiles[index] );
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 | void <a name="f154"></a>ChartForm::updateRecentFiles( const <a href="qstring.html">QString</a>& filename )
|
|---|
| 375 | {
|
|---|
| 376 | if ( m_recentFiles.find( filename ) != m_recentFiles.end() )
|
|---|
| 377 | return;
|
|---|
| 378 |
|
|---|
| 379 | m_recentFiles.push_back( filename );
|
|---|
| 380 | if ( m_recentFiles.count() > MAX_RECENTFILES )
|
|---|
| 381 | m_recentFiles.pop_front();
|
|---|
| 382 |
|
|---|
| 383 | updateRecentFilesMenu();
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 | void <a name="f155"></a>ChartForm::updateRecentFilesMenu()
|
|---|
| 388 | {
|
|---|
| 389 | for ( int i = 0; i < MAX_RECENTFILES; ++i ) {
|
|---|
| 390 | <a name="x2882"></a> if ( fileMenu-><a href="qmenudata.html#findItem">findItem</a>( i ) )
|
|---|
| 391 | <a name="x2885"></a> fileMenu-><a href="qmenudata.html#removeItem">removeItem</a>( i );
|
|---|
| 392 | if ( i < int(m_recentFiles.count()) )
|
|---|
| 393 | fileMenu-><a href="qmenudata.html#insertItem">insertItem</a>( QString( "&%1 %2" ).
|
|---|
| 394 | arg( i + 1 ).arg( m_recentFiles[i] ),
|
|---|
| 395 | this, SLOT( fileOpenRecent(int) ),
|
|---|
| 396 | 0, i );
|
|---|
| 397 | }
|
|---|
| 398 | }
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 | void <a name="f156"></a>ChartForm::fileQuit()
|
|---|
| 402 | {
|
|---|
| 403 | if ( okToClear() ) {
|
|---|
| 404 | saveOptions();
|
|---|
| 405 | <a name="x2875"></a> qApp-><a href="qapplication.html#exit">exit</a>( 0 );
|
|---|
| 406 | }
|
|---|
| 407 | }
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 | bool <a name="f157"></a>ChartForm::okToClear()
|
|---|
| 411 | {
|
|---|
| 412 | if ( m_changed ) {
|
|---|
| 413 | <a href="qstring.html">QString</a> msg;
|
|---|
| 414 | if ( m_filename.isEmpty() )
|
|---|
| 415 | msg = "Unnamed chart ";
|
|---|
| 416 | else
|
|---|
| 417 | msg = QString( "Chart '%1'\n" ).arg( m_filename );
|
|---|
| 418 | msg += "has been changed.";
|
|---|
| 419 |
|
|---|
| 420 | int x = QMessageBox::<a href="qmessagebox.html#information">information</a>( this, "Chart -- Unsaved Changes",
|
|---|
| 421 | msg, "&Save", "Cancel", "&Abandon",
|
|---|
| 422 | 0, 1 );
|
|---|
| 423 | switch( x ) {
|
|---|
| 424 | case 0: // Save
|
|---|
| 425 | fileSave();
|
|---|
| 426 | break;
|
|---|
| 427 | case 1: // Cancel
|
|---|
| 428 | default:
|
|---|
| 429 | return FALSE;
|
|---|
| 430 | case 2: // Abandon
|
|---|
| 431 | break;
|
|---|
| 432 | }
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 | return TRUE;
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 | void <a name="f158"></a>ChartForm::saveOptions()
|
|---|
| 440 | {
|
|---|
| 441 | <a href="qsettings.html">QSettings</a> settings;
|
|---|
| 442 | settings.<a href="qsettings.html#insertSearchPath">insertSearchPath</a>( QSettings::Windows, WINDOWS_REGISTRY );
|
|---|
| 443 | <a name="x2891"></a> settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "WindowWidth", width() );
|
|---|
| 444 | settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "WindowHeight", height() );
|
|---|
| 445 | settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "WindowX", x() );
|
|---|
| 446 | settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "WindowY", y() );
|
|---|
| 447 | settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "ChartType", int(m_chartType) );
|
|---|
| 448 | settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "AddValues", int(m_addValues) );
|
|---|
| 449 | settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "Decimals", m_decimalPlaces );
|
|---|
| 450 | settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "Font", m_font.toString() );
|
|---|
| 451 | for ( int i = 0; i < int(m_recentFiles.count()); ++i )
|
|---|
| 452 | settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "File" + QString::number( i + 1 ),
|
|---|
| 453 | m_recentFiles[i] );
|
|---|
| 454 | }
|
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 | void <a name="f159"></a>ChartForm::optionsSetData()
|
|---|
| 458 | {
|
|---|
| 459 | SetDataForm *setDataForm = new SetDataForm( &m_elements, m_decimalPlaces, this );
|
|---|
| 460 | <a name="x2877"></a> if ( setDataForm-><a href="qdialog.html#exec">exec</a>() ) {
|
|---|
| 461 | m_changed = TRUE;
|
|---|
| 462 | drawElements();
|
|---|
| 463 | }
|
|---|
| 464 | delete setDataForm;
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 | void <a name="f160"></a>ChartForm::setChartType( ChartType chartType )
|
|---|
| 469 | {
|
|---|
| 470 | m_chartType = chartType;
|
|---|
| 471 | switch ( m_chartType ) {
|
|---|
| 472 | case PIE:
|
|---|
| 473 | <a name="x2871"></a> optionsPieChartAction-><a href="qaction.html#setOn">setOn</a>( TRUE );
|
|---|
| 474 | break;
|
|---|
| 475 | case VERTICAL_BAR:
|
|---|
| 476 | optionsVerticalBarChartAction-><a href="qaction.html#setOn">setOn</a>( TRUE );
|
|---|
| 477 | break;
|
|---|
| 478 | case HORIZONTAL_BAR:
|
|---|
| 479 | optionsHorizontalBarChartAction-><a href="qaction.html#setOn">setOn</a>( TRUE );
|
|---|
| 480 | break;
|
|---|
| 481 | }
|
|---|
| 482 | }
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 | void <a name="f161"></a>ChartForm::updateChartType( <a href="qaction.html">QAction</a> *action )
|
|---|
| 486 | {
|
|---|
| 487 | if ( action == optionsPieChartAction ) {
|
|---|
| 488 | m_chartType = PIE;
|
|---|
| 489 | }
|
|---|
| 490 | else if ( action == optionsHorizontalBarChartAction ) {
|
|---|
| 491 | m_chartType = HORIZONTAL_BAR;
|
|---|
| 492 | }
|
|---|
| 493 | else if ( action == optionsVerticalBarChartAction ) {
|
|---|
| 494 | m_chartType = VERTICAL_BAR;
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | drawElements();
|
|---|
| 498 | }
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 | void <a name="f162"></a>ChartForm::optionsSetFont()
|
|---|
| 502 | {
|
|---|
| 503 | bool ok;
|
|---|
| 504 | <a name="x2881"></a> <a href="qfont.html">QFont</a> font = QFontDialog::<a href="qfontdialog.html#getFont">getFont</a>( &ok, m_font, this );
|
|---|
| 505 | if ( ok ) {
|
|---|
| 506 | m_font = font;
|
|---|
| 507 | drawElements();
|
|---|
| 508 | }
|
|---|
| 509 | }
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 | void <a name="f163"></a>ChartForm::optionsSetOptions()
|
|---|
| 513 | {
|
|---|
| 514 | OptionsForm *optionsForm = new OptionsForm( this );
|
|---|
| 515 | optionsForm->chartTypeComboBox->setCurrentItem( m_chartType );
|
|---|
| 516 | optionsForm-><a href="qwidget.html#setFont">setFont</a>( m_font );
|
|---|
| 517 | switch ( m_addValues ) {
|
|---|
| 518 | case NO:
|
|---|
| 519 | optionsForm->noRadioButton->setChecked( TRUE );
|
|---|
| 520 | break;
|
|---|
| 521 | case YES:
|
|---|
| 522 | optionsForm->yesRadioButton->setChecked( TRUE );
|
|---|
| 523 | break;
|
|---|
| 524 | case AS_PERCENTAGE:
|
|---|
| 525 | optionsForm->asPercentageRadioButton->setChecked( TRUE );
|
|---|
| 526 | break;
|
|---|
| 527 | }
|
|---|
| 528 | optionsForm->decimalPlacesSpinBox->setValue( m_decimalPlaces );
|
|---|
| 529 | if ( optionsForm-><a href="qdialog.html#exec">exec</a>() ) {
|
|---|
| 530 | setChartType( ChartType(
|
|---|
| 531 | optionsForm->chartTypeComboBox->currentItem()) );
|
|---|
| 532 | <a name="x2897"></a> m_font = optionsForm-><a href="qwidget.html#font">font</a>();
|
|---|
| 533 | if ( optionsForm->noRadioButton->isChecked() )
|
|---|
| 534 | m_addValues = NO;
|
|---|
| 535 | else if ( optionsForm->yesRadioButton->isChecked() )
|
|---|
| 536 | m_addValues = YES;
|
|---|
| 537 | else if ( optionsForm->asPercentageRadioButton->isChecked() )
|
|---|
| 538 | m_addValues = AS_PERCENTAGE;
|
|---|
| 539 | m_decimalPlaces = optionsForm->decimalPlacesSpinBox->value();
|
|---|
| 540 | drawElements();
|
|---|
| 541 | }
|
|---|
| 542 | delete optionsForm;
|
|---|
| 543 | }
|
|---|
| 544 |
|
|---|
| 545 |
|
|---|
| 546 | void <a name="f164"></a>ChartForm::helpHelp()
|
|---|
| 547 | {
|
|---|
| 548 | <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Help is not implemented yet", 2000 );
|
|---|
| 549 | }
|
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 | void <a name="f165"></a>ChartForm::helpAbout()
|
|---|
| 553 | {
|
|---|
| 554 | <a name="x2886"></a> QMessageBox::<a href="qmessagebox.html#about">about</a>( this, "Chart -- About",
|
|---|
| 555 | "<center><h1><font color=blue>Chart<font></h1></center>"
|
|---|
| 556 | "<p>Chart your data with <i>chart</i>.</p>"
|
|---|
| 557 | );
|
|---|
| 558 | }
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 | void <a name="f166"></a>ChartForm::helpAboutQt()
|
|---|
| 562 | {
|
|---|
| 563 | <a name="x2887"></a> QMessageBox::<a href="qmessagebox.html#aboutQt">aboutQt</a>( this, "Chart -- About Qt" );
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 | </pre><!-- eof -->
|
|---|
| 567 | <p><address><hr><div align=center>
|
|---|
| 568 | <table width=100% cellspacing=0 border=0><tr>
|
|---|
| 569 | <td>Copyright © 2007
|
|---|
| 570 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
|---|
| 571 | <td align=right><div align=right>Qt 3.3.8</div>
|
|---|
| 572 | </table></div></address></body>
|
|---|
| 573 | </html>
|
|---|