📄 canvas-chart-example.html
字号:
}void <a name="f559"></a>ChartForm::fileSaveAs(){ <a href="qstring.html">QString</a> filename = QFileDialog::<a href="qfiledialog.html#getSaveFileName">getSaveFileName</a>( QString::null, "Charts (*.cht)", this, "file save as", "Chart -- File Save As" ); if ( !filename.<a href="qstring.html#isEmpty">isEmpty</a>() ) { int answer = 0;<a name="x2595"></a> if ( QFile::<a href="qfile.html#exists">exists</a>( filename ) )<a name="x2606"></a> answer = QMessageBox::<a href="qmessagebox.html#warning">warning</a>( this, "Chart -- Overwrite File", QString( "Overwrite\n\'%1\'?" ). arg( filename ), "&Yes", "&No", QString::null, 1, 1 ); if ( answer == 0 ) { m_filename = filename; updateRecentFiles( filename ); fileSave(); return; } } <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Saving abandoned", 2000 );}void <a name="f560"></a>ChartForm::fileOpenRecent( int index ){ if ( !okToClear() ) return; load( m_recentFiles[index] );}void <a name="f561"></a>ChartForm::updateRecentFiles( const <a href="qstring.html">QString</a>& filename ){ if ( m_recentFiles.find( filename ) != m_recentFiles.end() ) return; m_recentFiles.push_back( filename ); if ( m_recentFiles.count() > MAX_RECENTFILES ) m_recentFiles.pop_front(); updateRecentFilesMenu();}void <a name="f562"></a>ChartForm::updateRecentFilesMenu(){ for ( int i = 0; i < MAX_RECENTFILES; ++i ) {<a name="x2599"></a> if ( fileMenu-><a href="qmenudata.html#findItem">findItem</a>( i ) )<a name="x2602"></a> fileMenu-><a href="qmenudata.html#removeItem">removeItem</a>( i ); if ( i < int(m_recentFiles.count()) ) fileMenu-><a href="qmenudata.html#insertItem">insertItem</a>( QString( "&%1 %2" ). arg( i + 1 ).arg( m_recentFiles[i] ), this, SLOT( fileOpenRecent(int) ), 0, i ); }}void <a name="f563"></a>ChartForm::fileQuit(){ if ( okToClear() ) { saveOptions();<a name="x2592"></a> qApp-><a href="qapplication.html#exit">exit</a>( 0 ); }}bool <a name="f564"></a>ChartForm::okToClear(){ if ( m_changed ) { <a href="qstring.html">QString</a> msg; if ( m_filename.isEmpty() ) msg = "Unnamed chart "; else msg = QString( "Chart '%1'\n" ).arg( m_filename ); msg += "has been changed.";<a name="x2605"></a> switch( QMessageBox::<a href="qmessagebox.html#information">information</a>( this, "Chart -- Unsaved Changes", msg, "&Save", "Cancel", "&Abandon", 0, 1 ) ) { case 0: fileSave(); break; case 1: default: return false; break; case 2: break; } } return true;}void <a name="f565"></a>ChartForm::saveOptions(){ <a href="qsettings.html">QSettings</a> settings; settings.<a href="qsettings.html#insertSearchPath">insertSearchPath</a>( QSettings::Windows, WINDOWS_REGISTRY );<a name="x2610"></a> settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "WindowWidth", width() ); settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "WindowHeight", height() ); settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "WindowX", x() ); settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "WindowY", y() ); settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "ChartType", int(m_chartType) ); settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "AddValues", int(m_addValues) ); settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "Decimals", m_decimalPlaces ); settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "Font", m_font.toString() ); for ( int i = 0; i < int(m_recentFiles.count()); ++i ) settings.<a href="qsettings.html#writeEntry">writeEntry</a>( APP_KEY + "File" + QString::number( i + 1 ), m_recentFiles[i] );}void <a name="f566"></a>ChartForm::optionsSetData(){ SetDataForm *setDataForm = new SetDataForm( &m_elements, m_decimalPlaces, this );<a name="x2594"></a> if ( setDataForm-><a href="qdialog.html#exec">exec</a>() ) { m_changed = true; drawElements(); } delete setDataForm;}void <a name="f567"></a>ChartForm::setChartType( ChartType chartType ){ m_chartType = chartType; switch ( m_chartType ) { case PIE:<a name="x2588"></a> optionsPieChartAction-><a href="qaction.html#setOn">setOn</a>( true ); break; case VERTICAL_BAR: optionsVerticalBarChartAction-><a href="qaction.html#setOn">setOn</a>( true ); break; case HORIZONTAL_BAR: optionsHorizontalBarChartAction-><a href="qaction.html#setOn">setOn</a>( true ); break; }}void <a name="f568"></a>ChartForm::updateChartType( <a href="qaction.html">QAction</a> *action ){ if ( action == optionsPieChartAction ) { m_chartType = PIE; } else if ( action == optionsHorizontalBarChartAction ) { m_chartType = HORIZONTAL_BAR; } else if ( action == optionsVerticalBarChartAction ) { m_chartType = VERTICAL_BAR; } drawElements();}void <a name="f569"></a>ChartForm::optionsSetFont(){ bool ok;<a name="x2598"></a> <a href="qfont.html">QFont</a> font = QFontDialog::<a href="qfontdialog.html#getFont">getFont</a>( &ok, m_font, this ); if ( ok ) { m_font = font; drawElements(); }}void <a name="f570"></a>ChartForm::optionsSetOptions(){ OptionsForm *optionsForm = new OptionsForm( this ); optionsForm->chartTypeComboBox->setCurrentItem( m_chartType ); optionsForm-><a href="qwidget.html#setFont">setFont</a>( m_font ); switch ( m_addValues ) { case NO: optionsForm->noRadioButton->setChecked( true ); break; case YES: optionsForm->yesRadioButton->setChecked( true ); break; case AS_PERCENTAGE: optionsForm->asPercentageRadioButton->setChecked( true ); break; } optionsForm->decimalPlacesSpinBox->setValue( m_decimalPlaces ); if ( optionsForm-><a href="qdialog.html#exec">exec</a>() ) { setChartType( ChartType( optionsForm->chartTypeComboBox->currentItem()) );<a name="x2615"></a> m_font = optionsForm-><a href="qwidget.html#font">font</a>(); if ( optionsForm->noRadioButton->isChecked() ) m_addValues = NO; else if ( optionsForm->yesRadioButton->isChecked() ) m_addValues = YES; else if ( optionsForm->asPercentageRadioButton->isChecked() ) m_addValues = AS_PERCENTAGE; m_decimalPlaces = optionsForm->decimalPlacesSpinBox->value(); drawElements(); } delete optionsForm;}void <a name="f571"></a>ChartForm::helpHelp(){ <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Help is not implemented yet", 2000 );}void <a name="f572"></a>ChartForm::helpAbout(){<a name="x2603"></a> QMessageBox::<a href="qmessagebox.html#about">about</a>( this, "Chart -- About", "<center><h1><font color=blue>Chart<font></h1></center>" "<p>Chart your data with <i>chart</i>.</p>" );}void <a name="f573"></a>ChartForm::helpAboutQt(){<a name="x2604"></a> QMessageBox::<a href="qmessagebox.html#aboutQt">aboutQt</a>( this, "Chart -- About Qt" );}</pre><p> <hr><p> Main:<p> <pre>#include <<a href="qapplication-h.html">qapplication.h</a>>#include "chartform.h"int main( int argc, char *argv[] ){ <a href="qapplication.html">QApplication</a> app( argc, argv ); <a href="qstring.html">QString</a> filename;<a name="x2618"></a> if ( app.<a href="qapplication.html#argc">argc</a>() > 1 ) {<a name="x2619"></a> filename = app.<a href="qapplication.html#argv">argv</a>()[1];<a name="x2624"></a> if ( !filename.<a href="qstring.html#endsWith">endsWith</a>( ".cht" ) ) filename = QString::null; } ChartForm *cf = new ChartForm( filename ); app.<a href="qapplication.html#setMainWidget">setMainWidget</a>( cf ); cf-><a href="qwidget.html#show">show</a>();<a name="x2621"></a> app.<a href="qobject.html#connect">connect</a>( &app, SIGNAL(<a href="qapplication.html#lastWindowClosed">lastWindowClosed</a>()), cf, SLOT(fileQuit()) ); return app.<a href="qapplication.html#exec">exec</a>();}</pre><p> <p>See also <a href="step-by-step-examples.html">Step-by-step Examples</a>.<!-- eof --><p><address><hr><div align=center><table width=100% cellspacing=0 border=0><tr><td>Copyright © 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -