From ea318d1431c89e647598c510c4245c6571aa5f46 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 26 Jan 2012 23:32:43 -0600 Subject: Update to latest tqt3 automated conversion --- doc/html/tutorial2-05.html | 194 ++++++++++++++++++++++----------------------- 1 file changed, 97 insertions(+), 97 deletions(-) (limited to 'doc/html/tutorial2-05.html') diff --git a/doc/html/tutorial2-05.html b/doc/html/tutorial2-05.html index 23e6c76d9..22d1e7bee 100644 --- a/doc/html/tutorial2-05.html +++ b/doc/html/tutorial2-05.html @@ -40,7 +40,7 @@ conventional document-centric style.

(Extracts from chartform.h.)

-

    class ChartForm: public TQMainWindow
+
    class ChartForm: public TQMainWindow
     {
         Q_OBJECT
     public:
@@ -49,14 +49,14 @@ conventional document-centric style.
         enum ChartType { PIE, VERTICAL_BAR, HORIZONTAL_BAR };
         enum AddValuesType { NO, YES, AS_PERCENTAGE };
 
-        ChartForm( const TQString& filename );
+        ChartForm( const TQString& filename );
         ~ChartForm();
 
         int chartType() { return m_chartType; }
         void setChanged( bool changed = TRUE ) { m_changed = changed; }
         void drawElements();
 
-        TQPopupMenu *optionsMenu; // Why public? See canvasview.cpp
+        TQPopupMenu *optionsMenu; // Why public? See canvasview.cpp
 
     protected:
         virtual void closeEvent( TQCloseEvent * );
@@ -71,7 +71,7 @@ conventional document-centric style.
         void filePrint();
         void fileQuit();
         void optionsSetData();
-        void updateChartType( TQAction *action );
+        void updateChartType( TQAction *action );
         void optionsSetFont();
         void optionsSetOptions();
         void helpHelp();
@@ -81,35 +81,35 @@ conventional document-centric style.
 
     private:
         void init();
-        void load( const TQString& filename );
+        void load( const TQString& filename );
         bool okToClear();
         void drawPieChart( const double scales[], double total, int count );
         void drawVerticalBarChart( const double scales[], double total, int count );
         void drawHorizontalBarChart( const double scales[], double total, int count );
 
-        TQString valueLabel( const TQString& label, double value, double total );
-        void updateRecentFiles( const TQString& filename );
+        TQString valueLabel( const TQString& label, double value, double total );
+        void updateRecentFiles( const TQString& filename );
         void updateRecentFilesMenu();
         void setChartType( ChartType chartType );
 
-        TQPopupMenu *fileMenu;
-        TQAction *optionsPieChartAction;
-        TQAction *optionsHorizontalBarChartAction;
-        TQAction *optionsVerticalBarChartAction;
-        TQString m_filename;
-        TQStringList m_recentFiles;
-        TQCanvas *m_canvas;
+        TQPopupMenu *fileMenu;
+        TQAction *optionsPieChartAction;
+        TQAction *optionsHorizontalBarChartAction;
+        TQAction *optionsVerticalBarChartAction;
+        TQString m_filename;
+        TQStringList m_recentFiles;
+        TQCanvas *m_canvas;
         CanvasView *m_canvasView;
         bool m_changed;
         ElementVector m_elements;
-        TQPrinter *m_printer;
+        TQPrinter *m_printer;
         ChartType m_chartType;
         AddValuesType m_addValues;
         int m_decimalPlaces;
-        TQFont m_font;
+        TQFont m_font;
     };
 
-

We create a ChartForm subclass of TQMainWindow. Our subclass uses +

We create a ChartForm subclass of TQMainWindow. Our subclass uses the Q_OBJECT macro to support TQt's signals and slots mechanism.

The public interface is very small; the type of chart being displayed can be retrieved, the chart can be marked 'changed' (so that the user @@ -119,7 +119,7 @@ because we are also going to use this menu as the canvas view's context menu.

-
The TQCanvas class is used for drawing 2D vector graphics. The +The TQCanvas class is used for drawing 2D vector graphics. The TQCanvasView class is used to present a view of a canvas in an application's GUI. All our drawing operations take place on the canvas; but events (e.g. mouse clicks) take place on the canvas view. @@ -143,14 +143,14 @@ GUI, chartform_canvas.cpp for the canvas handling and chartform_fil which we've placed in the images subdirectory.

The Constructor

-

    ChartForm::ChartForm( const TQString& filename )
-        : TQMainWindow( 0, 0, WDestructiveClose )
+

    ChartForm::ChartForm( const TQString& filename )
+        : TQMainWindow( 0, 0, WDestructiveClose )
 
... -
        TQAction *fileNewAction;
-        TQAction *fileOpenAction;
-        TQAction *fileSaveAction;
+
        TQAction *fileNewAction;
+        TQAction *fileOpenAction;
+        TQAction *fileSaveAction;
 
-

For each user action we declare a TQAction pointer. Some actions are +

For each user action we declare a TQAction pointer. Some actions are declared in the header file because they need to be referred to outside of the constructor.

@@ -160,10 +160,10 @@ buttons. TQt allows us to create a single TQAction which can be added to both a menu and a toolbar. This approach ensures that menu items and toolbar buttons stay in sync and saves duplicating code.
-

        fileNewAction = new TQAction(
+

        fileNewAction = new TQAction(
                 "New Chart", TQPixmap( file_new ),
                 "&New", CTRL+Key_N, this, "new" );
-        connect( fileNewAction, SIGNAL( activated() ), this, SLOT( fileNew() ) );
+        connect( fileNewAction, SIGNAL( activated() ), this, SLOT( fileNew() ) );
 

When we construct an action we give it a name, an optional icon, a menu text, and an accelerator short-cut key (or 0 if no accelerator is @@ -182,10 +182,10 @@ chart type actions in the group.

The action group becomes a child of the form (this) and the exlusive behaviour is achieved by the setExclusive() call. -

        optionsPieChartAction = new TQAction(
+

        optionsPieChartAction = new TQAction(
                 "Pie Chart", TQPixmap( options_piechart ),
                 "&Pie Chart", CTRL+Key_I, chartGroup, "pie chart" );
-        optionsPieChartAction->setToggleAction( TRUE );
+        optionsPieChartAction->setToggleAction( TRUE );
 

Each action in the group is created in the same way as other actions, except that the action's parent is the group rather than the form. @@ -205,44 +205,44 @@ canvas type we will connect the group.

Once we've created all our user actions we can create the toolbars and menu options that will allow the user to invoke them. -

        TQToolBar* fileTools = new TQToolBar( this, "file operations" );
-        fileTools->setLabel( "File Operations" );
-        fileNewAction->addTo( fileTools );
-        fileOpenAction->addTo( fileTools );
-        fileSaveAction->addTo( fileTools );
+

        TQToolBar* fileTools = new TQToolBar( this, "file operations" );
+        fileTools->setLabel( "File Operations" );
+        fileNewAction->addTo( fileTools );
+        fileOpenAction->addTo( fileTools );
+        fileSaveAction->addTo( fileTools );
 
... -
        fileMenu = new TQPopupMenu( this );
-        menuBar()->insertItem( "&File", fileMenu );
-        fileNewAction->addTo( fileMenu );
-        fileOpenAction->addTo( fileMenu );
-        fileSaveAction->addTo( fileMenu );
+
        fileMenu = new TQPopupMenu( this );
+        menuBar()->insertItem( "&File", fileMenu );
+        fileNewAction->addTo( fileMenu );
+        fileOpenAction->addTo( fileMenu );
+        fileSaveAction->addTo( fileMenu );
 

Toolbar actions and menu options are easily created from TQActions.

As a convenience to our users we will restore the last window position and size and list their recently used files. This is achieved by writing out their settings when the application is closed and reading them back when we construct the form. -

        TQSettings settings;
-        settings.insertSearchPath( TQSettings::Windows, WINDOWS_REGISTRY );
-        int windowWidth = settings.readNumEntry( APP_KEY + "WindowWidth", 460 );
-        int windowHeight = settings.readNumEntry( APP_KEY + "WindowHeight", 530 );
-        int windowX = settings.readNumEntry( APP_KEY + "WindowX", -1 );
-        int windowY = settings.readNumEntry( APP_KEY + "WindowY", -1 );
+

        TQSettings settings;
+        settings.insertSearchPath( TQSettings::Windows, WINDOWS_REGISTRY );
+        int windowWidth = settings.readNumEntry( APP_KEY + "WindowWidth", 460 );
+        int windowHeight = settings.readNumEntry( APP_KEY + "WindowHeight", 530 );
+        int windowX = settings.readNumEntry( APP_KEY + "WindowX", -1 );
+        int windowY = settings.readNumEntry( APP_KEY + "WindowY", -1 );
         setChartType( ChartType(
-                settings.readNumEntry( APP_KEY + "ChartType", int(PIE) ) ) );
+                settings.readNumEntry( APP_KEY + "ChartType", int(PIE) ) ) );
 
        m_font = TQFont( "Helvetica", 18, TQFont::Bold );
         m_font.fromString(
-                settings.readEntry( APP_KEY + "Font", m_font.toString() ) );
+                settings.readEntry( APP_KEY + "Font", m_font.toString() ) );
         for ( int i = 0; i < MAX_RECENTFILES; ++i ) {
-            TQString filename = settings.readEntry( APP_KEY + "File" +
-                                                   TQString::number( i + 1 ) );
-            if ( !filename.isEmpty() )
+            TQString filename = settings.readEntry( APP_KEY + "File" +
+                                                   TQString::number( i + 1 ) );
+            if ( !filename.isEmpty() )
                 m_recentFiles.push_back( filename );
         }
         if ( m_recentFiles.count() )
             updateRecentFilesMenu();
 
-

The TQSettings class handles user settings in a platform-independent +

The TQSettings class handles user settings in a platform-independent way. We simply read and write settings, leaving TQSettings to handle the platform dependencies. The insertSearchPath() call does nothing except under Windows so does not have to be #ifdefed. @@ -257,29 +257,29 @@ the settings. We attempt to read each possible file entry ("File1" to "File9"), and add each non-empty entry to the list of recently used files. If there are one or more recently used files we update the File menu by calling updateRecentFilesMenu(); (we'll review this later on). -

        connect( chartGroup, SIGNAL( selected(TQAction*) ),
+

        connect( chartGroup, SIGNAL( selected(TQAction*) ),
                  this, SLOT( updateChartType(TQAction*) ) );
 

Now that we have set the chart type (when we read it in as a user setting) it is safe to connect the chart group to our updateChartType() slot. -

        resize( windowWidth, windowHeight );
+

        resize( windowWidth, windowHeight );
         if ( windowX != -1 || windowY != -1 )
-            move( windowX, windowY );
+            move( windowX, windowY );
 

And now that we know the window size and position we can resize and move the chart form's window accordingly. -

        m_canvas = new TQCanvas( this );
-        m_canvas->resize( width(), height() );
+

        m_canvas = new TQCanvas( this );
+        m_canvas->resize( width(), height() );
         m_canvasView = new CanvasView( m_canvas, &m_elements, this );
-        setCentralWidget( m_canvasView );
-        m_canvasView->show();
+        setCentralWidget( m_canvasView );
+        m_canvasView->show();
 
-

We create a new TQCanvas and set its size to that of the chart form +

We create a new TQCanvas and set its size to that of the chart form window's client area. We also create a CanvasView (our own subclass of TQCanvasView) to display the TQCanvas. We make the canvas view the chart form's main widget and show it. -

        if ( !filename.isEmpty() )
+

        if ( !filename.isEmpty() )
             load( filename );
         else {
             init();
@@ -293,7 +293,7 @@ chart form's main widget and show it.
 

If we have a file to load we load it; otherwise we initialise our elements vector and draw a sample chart. -

        statusBar()->message( "Ready", 2000 );
+

        statusBar()->message( "Ready", 2000 );
 

It is vital that we call statusBar() in the constructor, since the call ensures that a status bar is created for this main window. @@ -301,8 +301,8 @@ call ensures that a status bar is created for this main window.

    void ChartForm::init()
     {
-        setCaption( "Chart" );
-        m_filename = TQString::null;
+        setCaption( "Chart" );
+        m_filename = TQString::null;
         m_changed = FALSE;
 
         m_elements[0]  = Element( Element::INVALID, red );
@@ -325,14 +325,14 @@ already have a unique color (which they can change of course).
 

    bool ChartForm::okToClear()
     {
         if ( m_changed ) {
-            TQString msg;
+            TQString msg;
             if ( m_filename.isEmpty() )
                 msg = "Unnamed chart ";
             else
                 msg = TQString( "Chart '%1'\n" ).arg( m_filename );
             msg += "has been changed.";
 
-            int x = TQMessageBox::information( this, "Chart -- Unsaved Changes",
+            int x = TQMessageBox::information( this, "Chart -- Unsaved Changes",
                                               msg, "&Save", "Cancel", "&Abandon",
                                               0, 1 );
             switch( x ) {
@@ -383,29 +383,29 @@ added a call to optionsSetData() and see which you prefer.
         if ( !okToClear() )
             return;
 
-        TQString filename = TQFileDialog::getOpenFileName(
+        TQString filename = TQFileDialog::getOpenFileName(
                                 TQString::null, "Charts (*.cht)", this,
                                 "file open", "Chart -- File Open" );
-        if ( !filename.isEmpty() )
+        if ( !filename.isEmpty() )
             load( filename );
         else
-            statusBar()->message( "File Open abandoned", 2000 );
+            statusBar()->message( "File Open abandoned", 2000 );
     }
 

We check that it is okToClear(). If it is we use the static -TQFileDialog::getOpenFileName() function to get the name of the file +TQFileDialog::getOpenFileName() function to get the name of the file the user wishes to load. If we get a filename we call load().

fileSaveAs()

    void ChartForm::fileSaveAs()
     {
-        TQString filename = TQFileDialog::getSaveFileName(
+        TQString filename = TQFileDialog::getSaveFileName(
                                 TQString::null, "Charts (*.cht)", this,
                                 "file save as", "Chart -- File Save As" );
-        if ( !filename.isEmpty() ) {
+        if ( !filename.isEmpty() ) {
             int answer = 0;
-            if ( TQFile::exists( filename ) )
-                answer = TQMessageBox::warning(
+            if ( TQFile::exists( filename ) )
+                answer = TQMessageBox::warning(
                                 this, "Chart -- Overwrite File",
                                 TQString( "Overwrite\n\'%1\'?" ).
                                     arg( filename ),
@@ -417,19 +417,19 @@ the user wishes to load. If we get a filename we call load().
                 return;
             }
         }
-        statusBar()->message( "Saving abandoned", 2000 );
+        statusBar()->message( "Saving abandoned", 2000 );
     }
 
-

This function calls the static TQFileDialog::getSaveFileName() to get +

This function calls the static TQFileDialog::getSaveFileName() to get the name of the file to save the data in. If the file exists we use a -TQMessageBox::warning() to notify the user and give them the option of +TQMessageBox::warning() to notify the user and give them the option of abandoning the save. If the file is to be saved we update the recently opened files list and call fileSave() (covered in File Handling) to perform the save.

Managing a list of Recently Opened Files

-

        TQStringList m_recentFiles;
+
        TQStringList m_recentFiles;
 

We hold the list of recently opened files in a string list.

@@ -437,10 +437,10 @@ opened files list and call fileSave() (covered in Fi

    void ChartForm::updateRecentFilesMenu()
     {
         for ( int i = 0; i < MAX_RECENTFILES; ++i ) {
-            if ( fileMenu->findItem( i ) )
-                fileMenu->removeItem( i );
+            if ( fileMenu->findItem( i ) )
+                fileMenu->removeItem( i );
             if ( i < int(m_recentFiles.count()) )
-                fileMenu->insertItem( TQString( "&%1 %2" ).
+                fileMenu->insertItem( TQString( "&%1 %2" ).
                                         arg( i + 1 ).arg( m_recentFiles[i] ),
                                       this, SLOT( fileOpenRecent(int) ),
                                       0, i );
@@ -460,7 +460,7 @@ other file menu items had ids created by TQt (all of which are < 0);
 whereas the menu items we're creating all have ids >= 0.
 

-

    void ChartForm::updateRecentFiles( const TQString& filename )
+
    void ChartForm::updateRecentFiles( const TQString& filename )
     {
         if ( m_recentFiles.find( filename ) != m_recentFiles.end() )
             return;
@@ -499,7 +499,7 @@ item id.
     {
         if ( okToClear() ) {
             saveOptions();
-            qApp->exit( 0 );
+            qApp->exit( 0 );
         }
     }
 
@@ -508,22 +508,22 @@ data (okToClear()) then save their options, e.g. window size and position, chart type, etc., before terminating.

    void ChartForm::saveOptions()
     {
-        TQSettings settings;
-        settings.insertSearchPath( TQSettings::Windows, WINDOWS_REGISTRY );
-        settings.writeEntry( APP_KEY + "WindowWidth", width() );
-        settings.writeEntry( APP_KEY + "WindowHeight", height() );
-        settings.writeEntry( APP_KEY + "WindowX", x() );
-        settings.writeEntry( APP_KEY + "WindowY", y() );
-        settings.writeEntry( APP_KEY + "ChartType", int(m_chartType) );
-        settings.writeEntry( APP_KEY + "AddValues", int(m_addValues) );
-        settings.writeEntry( APP_KEY + "Decimals", m_decimalPlaces );
-        settings.writeEntry( APP_KEY + "Font", m_font.toString() );
+        TQSettings settings;
+        settings.insertSearchPath( TQSettings::Windows, WINDOWS_REGISTRY );
+        settings.writeEntry( APP_KEY + "WindowWidth", width() );
+        settings.writeEntry( APP_KEY + "WindowHeight", height() );
+        settings.writeEntry( APP_KEY + "WindowX", x() );
+        settings.writeEntry( APP_KEY + "WindowY", y() );
+        settings.writeEntry( APP_KEY + "ChartType", int(m_chartType) );
+        settings.writeEntry( APP_KEY + "AddValues", int(m_addValues) );
+        settings.writeEntry( APP_KEY + "Decimals", m_decimalPlaces );
+        settings.writeEntry( APP_KEY + "Font", m_font.toString() );
         for ( int i = 0; i < int(m_recentFiles.count()); ++i )
-            settings.writeEntry( APP_KEY + "File" + TQString::number( i + 1 ),
+            settings.writeEntry( APP_KEY + "File" + TQString::number( i + 1 ),
                                  m_recentFiles[i] );
     }
 
-

Saving the user's options using TQSettings is straight-forward. +

Saving the user's options using TQSettings is straight-forward.

Custom Dialogs

We want the user to be able to set some options manually and to create @@ -534,11 +534,11 @@ and edit values, value colors, etc. { OptionsForm *optionsForm = new OptionsForm( this ); optionsForm->chartTypeComboBox->setCurrentItem( m_chartType ); - optionsForm->setFont( m_font ); -

        if ( optionsForm->exec() ) {
+        optionsForm->setFont( m_font );
+
        if ( optionsForm->exec() ) {
             setChartType( ChartType(
                     optionsForm->chartTypeComboBox->currentItem()) );
-            m_font = optionsForm->font();
+            m_font = optionsForm->font();
 
            drawElements();
         }
         delete optionsForm;
@@ -555,7 +555,7 @@ elements.
 
    void ChartForm::optionsSetData()
     {
         SetDataForm *setDataForm = new SetDataForm( &m_elements, m_decimalPlaces, this );
-        if ( setDataForm->exec() ) {
+        if ( setDataForm->exec() ) {
             m_changed = TRUE;
             drawElements();
         }
-- 
cgit v1.2.1