Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 8e6051afcdb111a0317a58fb64c2abf5 > files > 623

qt4-doc-4.6.3-0.2mdv2010.2.i586.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Qt 4.6: classwizard.cpp Example File (dialogs/classwizard/classwizard.cpp)</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">classwizard.cpp Example File<br /><span class="small-subtitle">dialogs/classwizard/classwizard.cpp</span>
</h1>
<pre><span class="comment"> /****************************************************************************
 **
 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
 **
 ** This file is part of the examples of the Qt Toolkit.
 **
 ** $QT_BEGIN_LICENSE:LGPL$
 ** Commercial Usage
 ** Licensees holding valid Qt Commercial licenses may use this file in
 ** accordance with the Qt Commercial License Agreement provided with the
 ** Software or, alternatively, in accordance with the terms contained in
 ** a written agreement between you and Nokia.
 **
 ** GNU Lesser General Public License Usage
 ** Alternatively, this file may be used under the terms of the GNU Lesser
 ** General Public License version 2.1 as published by the Free Software
 ** Foundation and appearing in the file LICENSE.LGPL included in the
 ** packaging of this file.  Please review the following information to
 ** ensure the GNU Lesser General Public License version 2.1 requirements
 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 **
 ** In addition, as a special exception, Nokia gives you certain additional
 ** rights.  These rights are described in the Nokia Qt LGPL Exception
 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 **
 ** GNU General Public License Usage
 ** Alternatively, this file may be used under the terms of the GNU
 ** General Public License version 3.0 as published by the Free Software
 ** Foundation and appearing in the file LICENSE.GPL included in the
 ** packaging of this file.  Please review the following information to
 ** ensure the GNU General Public License version 3.0 requirements will be
 ** met: http://www.gnu.org/copyleft/gpl.html.
 **
 ** If you have questions regarding the use of this file, please contact
 ** Nokia at qt-info@nokia.com.
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/</span>

 #include &lt;QtGui&gt;

 #include &quot;classwizard.h&quot;

 ClassWizard::ClassWizard(QWidget *parent)
     : QWizard(parent)
 {
     addPage(new IntroPage);
     addPage(new ClassInfoPage);
     addPage(new CodeStylePage);
     addPage(new OutputFilesPage);
     addPage(new ConclusionPage);

     setPixmap(QWizard::BannerPixmap, QPixmap(&quot;:/images/banner.png&quot;));
     setPixmap(QWizard::BackgroundPixmap, QPixmap(&quot;:/images/background.png&quot;));

     setWindowTitle(tr(&quot;Class Wizard&quot;));
 }

 void ClassWizard::accept()
 {
     QByteArray className = field(&quot;className&quot;).toByteArray();
     QByteArray baseClass = field(&quot;baseClass&quot;).toByteArray();
     QByteArray macroName = field(&quot;macroName&quot;).toByteArray();
     QByteArray baseInclude = field(&quot;baseInclude&quot;).toByteArray();

     QString outputDir = field(&quot;outputDir&quot;).toString();
     QString header = field(&quot;header&quot;).toString();
     QString implementation = field(&quot;implementation&quot;).toString();

     QByteArray block;

     if (field(&quot;comment&quot;).toBool()) {
         block += &quot;<span class="comment">/*\n&quot;;
         block += &quot;    &quot; + header.toAscii() + &quot;\n&quot;;
         block += &quot;*/</span>\n&quot;;
         block += &quot;\n&quot;;
     }
     if (field(&quot;protect&quot;).toBool()) {
         block += &quot;#ifndef &quot; + macroName + &quot;\n&quot;;
         block += &quot;#define &quot; + macroName + &quot;\n&quot;;
         block += &quot;\n&quot;;
     }
     if (field(&quot;includeBase&quot;).toBool()) {
         block += &quot;#include &quot; + baseInclude + &quot;\n&quot;;
         block += &quot;\n&quot;;
     }

     block += &quot;class &quot; + className;
     if (!baseClass.isEmpty())
         block += &quot; : public &quot; + baseClass;
     block += &quot;\n&quot;;
     block += &quot;{\n&quot;;

     <span class="comment">/* qmake ignore Q_OBJECT */</span>

     if (field(&quot;qobjectMacro&quot;).toBool()) {
         block += &quot;    Q_OBJECT\n&quot;;
         block += &quot;\n&quot;;
     }
     block += &quot;public:\n&quot;;

     if (field(&quot;qobjectCtor&quot;).toBool()) {
         block += &quot;    &quot; + className + &quot;(QObject *parent = 0);\n&quot;;
     } else if (field(&quot;qwidgetCtor&quot;).toBool()) {
         block += &quot;    &quot; + className + &quot;(QWidget *parent = 0);\n&quot;;
     } else if (field(&quot;defaultCtor&quot;).toBool()) {
         block += &quot;    &quot; + className + &quot;();\n&quot;;
         if (field(&quot;copyCtor&quot;).toBool()) {
             block += &quot;    &quot; + className + &quot;(const &quot; + className + &quot; &amp;other);\n&quot;;
             block += &quot;\n&quot;;
             block += &quot;    &quot; + className + &quot; &amp;operator=&quot; + &quot;(const &quot; + className
                      + &quot; &amp;other);\n&quot;;
         }
     }
     block += &quot;};\n&quot;;

     if (field(&quot;protect&quot;).toBool()) {
         block += &quot;\n&quot;;
         block += &quot;#endif\n&quot;;
     }

     QFile headerFile(outputDir + &quot;/&quot; + header);
     if (!headerFile.open(QFile::WriteOnly | QFile::Text)) {
         QMessageBox::warning(0, QObject::tr(&quot;Simple Wizard&quot;),
                              QObject::tr(&quot;Cannot write file %1:\n%2&quot;)
                              .arg(headerFile.fileName())
                              .arg(headerFile.errorString()));
         return;
     }
     headerFile.write(block);

     block.clear();

     if (field(&quot;comment&quot;).toBool()) {
         block += &quot;<span class="comment">/*\n&quot;;
         block += &quot;    &quot; + implementation.toAscii() + &quot;\n&quot;;
         block += &quot;*/</span>\n&quot;;
         block += &quot;\n&quot;;
     }
     block += &quot;#include \&quot;&quot; + header.toAscii() + &quot;\&quot;\n&quot;;
     block += &quot;\n&quot;;

     if (field(&quot;qobjectCtor&quot;).toBool()) {
         block += className + &quot;::&quot; + className + &quot;(QObject *parent)\n&quot;;
         block += &quot;    : &quot; + baseClass + &quot;(parent)\n&quot;;
         block += &quot;{\n&quot;;
         block += &quot;}\n&quot;;
     } else if (field(&quot;qwidgetCtor&quot;).toBool()) {
         block += className + &quot;::&quot; + className + &quot;(QWidget *parent)\n&quot;;
         block += &quot;    : &quot; + baseClass + &quot;(parent)\n&quot;;
         block += &quot;{\n&quot;;
         block += &quot;}\n&quot;;
     } else if (field(&quot;defaultCtor&quot;).toBool()) {
         block += className + &quot;::&quot; + className + &quot;()\n&quot;;
         block += &quot;{\n&quot;;
         block += &quot;    <span class="comment">// missing code\n&quot;;</span>
         block += &quot;}\n&quot;;

         if (field(&quot;copyCtor&quot;).toBool()) {
             block += &quot;\n&quot;;
             block += className + &quot;::&quot; + className + &quot;(const &quot; + className
                      + &quot; &amp;other)\n&quot;;
             block += &quot;{\n&quot;;
             block += &quot;    *this = other;\n&quot;;
             block += &quot;}\n&quot;;
             block += &quot;\n&quot;;
             block += className + &quot; &amp;&quot; + className + &quot;::operator=(const &quot;
                      + className + &quot; &amp;other)\n&quot;;
             block += &quot;{\n&quot;;
             if (!baseClass.isEmpty())
                 block += &quot;    &quot; + baseClass + &quot;::operator=(other);\n&quot;;
             block += &quot;    <span class="comment">// missing code\n&quot;;</span>
             block += &quot;    return *this;\n&quot;;
             block += &quot;}\n&quot;;
         }
     }

     QFile implementationFile(outputDir + &quot;/&quot; + implementation);
     if (!implementationFile.open(QFile::WriteOnly | QFile::Text)) {
         QMessageBox::warning(0, QObject::tr(&quot;Simple Wizard&quot;),
                              QObject::tr(&quot;Cannot write file %1:\n%2&quot;)
                              .arg(implementationFile.fileName())
                              .arg(implementationFile.errorString()));
         return;
     }
     implementationFile.write(block);

     QDialog::accept();
 }

 IntroPage::IntroPage(QWidget *parent)
     : QWizardPage(parent)
 {
     setTitle(tr(&quot;Introduction&quot;));
     setPixmap(QWizard::WatermarkPixmap, QPixmap(&quot;:/images/watermark1.png&quot;));

     label = new QLabel(tr(&quot;This wizard will generate a skeleton C++ class &quot;
                           &quot;definition, including a few functions. You simply &quot;
                           &quot;need to specify the class name and set a few &quot;
                           &quot;options to produce a header file and an &quot;
                           &quot;implementation file for your new C++ class.&quot;));
     label-&gt;setWordWrap(true);

     QVBoxLayout *layout = new QVBoxLayout;
     layout-&gt;addWidget(label);
     setLayout(layout);
 }

 ClassInfoPage::ClassInfoPage(QWidget *parent)
     : QWizardPage(parent)
 {
     setTitle(tr(&quot;Class Information&quot;));
     setSubTitle(tr(&quot;Specify basic information about the class for which you &quot;
                    &quot;want to generate skeleton source code files.&quot;));
     setPixmap(QWizard::LogoPixmap, QPixmap(&quot;:/images/logo1.png&quot;));

     classNameLabel = new QLabel(tr(&quot;&amp;Class name:&quot;));
     classNameLineEdit = new QLineEdit;
     classNameLabel-&gt;setBuddy(classNameLineEdit);

     baseClassLabel = new QLabel(tr(&quot;B&amp;ase class:&quot;));
     baseClassLineEdit = new QLineEdit;
     baseClassLabel-&gt;setBuddy(baseClassLineEdit);

     qobjectMacroCheckBox = new QCheckBox(tr(&quot;Generate Q_OBJECT &amp;macro&quot;));

     groupBox = new QGroupBox(tr(&quot;C&amp;onstructor&quot;));

     qobjectCtorRadioButton = new QRadioButton(tr(&quot;&amp;QObject-style constructor&quot;));
     qwidgetCtorRadioButton = new QRadioButton(tr(&quot;Q&amp;Widget-style constructor&quot;));
     defaultCtorRadioButton = new QRadioButton(tr(&quot;&amp;Default constructor&quot;));
     copyCtorCheckBox = new QCheckBox(tr(&quot;&amp;Generate copy constructor and &quot;
                                         &quot;operator=&quot;));

     defaultCtorRadioButton-&gt;setChecked(true);

     connect(defaultCtorRadioButton, SIGNAL(toggled(bool)),
             copyCtorCheckBox, SLOT(setEnabled(bool)));

     registerField(&quot;className*&quot;, classNameLineEdit);
     registerField(&quot;baseClass&quot;, baseClassLineEdit);
     registerField(&quot;qobjectMacro&quot;, qobjectMacroCheckBox);
     registerField(&quot;qobjectCtor&quot;, qobjectCtorRadioButton);
     registerField(&quot;qwidgetCtor&quot;, qwidgetCtorRadioButton);
     registerField(&quot;defaultCtor&quot;, defaultCtorRadioButton);
     registerField(&quot;copyCtor&quot;, copyCtorCheckBox);

     QVBoxLayout *groupBoxLayout = new QVBoxLayout;
     groupBoxLayout-&gt;addWidget(qobjectCtorRadioButton);
     groupBoxLayout-&gt;addWidget(qwidgetCtorRadioButton);
     groupBoxLayout-&gt;addWidget(defaultCtorRadioButton);
     groupBoxLayout-&gt;addWidget(copyCtorCheckBox);
     groupBox-&gt;setLayout(groupBoxLayout);

     QGridLayout *layout = new QGridLayout;
     layout-&gt;addWidget(classNameLabel, 0, 0);
     layout-&gt;addWidget(classNameLineEdit, 0, 1);
     layout-&gt;addWidget(baseClassLabel, 1, 0);
     layout-&gt;addWidget(baseClassLineEdit, 1, 1);
     layout-&gt;addWidget(qobjectMacroCheckBox, 2, 0, 1, 2);
     layout-&gt;addWidget(groupBox, 3, 0, 1, 2);
     setLayout(layout);
 }

 CodeStylePage::CodeStylePage(QWidget *parent)
     : QWizardPage(parent)
 {
     setTitle(tr(&quot;Code Style Options&quot;));
     setSubTitle(tr(&quot;Choose the formatting of the generated code.&quot;));
     setPixmap(QWizard::LogoPixmap, QPixmap(&quot;:/images/logo2.png&quot;));

     commentCheckBox = new QCheckBox(tr(&quot;&amp;Start generated files with a &quot;
                                        &quot;comment&quot;));
     commentCheckBox-&gt;setChecked(true);

     protectCheckBox = new QCheckBox(tr(&quot;&amp;Protect header file against multiple &quot;
                                        &quot;inclusions&quot;));
     protectCheckBox-&gt;setChecked(true);

     macroNameLabel = new QLabel(tr(&quot;&amp;Macro name:&quot;));
     macroNameLineEdit = new QLineEdit;
     macroNameLabel-&gt;setBuddy(macroNameLineEdit);

     includeBaseCheckBox = new QCheckBox(tr(&quot;&amp;Include base class definition&quot;));
     baseIncludeLabel = new QLabel(tr(&quot;Base class include:&quot;));
     baseIncludeLineEdit = new QLineEdit;
     baseIncludeLabel-&gt;setBuddy(baseIncludeLineEdit);

     connect(protectCheckBox, SIGNAL(toggled(bool)),
             macroNameLabel, SLOT(setEnabled(bool)));
     connect(protectCheckBox, SIGNAL(toggled(bool)),
             macroNameLineEdit, SLOT(setEnabled(bool)));
     connect(includeBaseCheckBox, SIGNAL(toggled(bool)),
             baseIncludeLabel, SLOT(setEnabled(bool)));
     connect(includeBaseCheckBox, SIGNAL(toggled(bool)),
             baseIncludeLineEdit, SLOT(setEnabled(bool)));

     registerField(&quot;comment&quot;, commentCheckBox);
     registerField(&quot;protect&quot;, protectCheckBox);
     registerField(&quot;macroName&quot;, macroNameLineEdit);
     registerField(&quot;includeBase&quot;, includeBaseCheckBox);
     registerField(&quot;baseInclude&quot;, baseIncludeLineEdit);

     QGridLayout *layout = new QGridLayout;
     layout-&gt;setColumnMinimumWidth(0, 20);
     layout-&gt;addWidget(commentCheckBox, 0, 0, 1, 3);
     layout-&gt;addWidget(protectCheckBox, 1, 0, 1, 3);
     layout-&gt;addWidget(macroNameLabel, 2, 1);
     layout-&gt;addWidget(macroNameLineEdit, 2, 2);
     layout-&gt;addWidget(includeBaseCheckBox, 3, 0, 1, 3);
     layout-&gt;addWidget(baseIncludeLabel, 4, 1);
     layout-&gt;addWidget(baseIncludeLineEdit, 4, 2);
     setLayout(layout);
 }

 void CodeStylePage::initializePage()
 {
     QString className = field(&quot;className&quot;).toString();
     macroNameLineEdit-&gt;setText(className.toUpper() + &quot;_H&quot;);

     QString baseClass = field(&quot;baseClass&quot;).toString();

     includeBaseCheckBox-&gt;setChecked(!baseClass.isEmpty());
     includeBaseCheckBox-&gt;setEnabled(!baseClass.isEmpty());
     baseIncludeLabel-&gt;setEnabled(!baseClass.isEmpty());
     baseIncludeLineEdit-&gt;setEnabled(!baseClass.isEmpty());

     if (baseClass.isEmpty()) {
         baseIncludeLineEdit-&gt;clear();
     } else if (QRegExp(&quot;Q[A-Z].*&quot;).exactMatch(baseClass)) {
         baseIncludeLineEdit-&gt;setText(&quot;&lt;&quot; + baseClass + &quot;&gt;&quot;);
     } else {
         baseIncludeLineEdit-&gt;setText(&quot;\&quot;&quot; + baseClass.toLower() + &quot;.h\&quot;&quot;);
     }
 }

 OutputFilesPage::OutputFilesPage(QWidget *parent)
     : QWizardPage(parent)
 {
     setTitle(tr(&quot;Output Files&quot;));
     setSubTitle(tr(&quot;Specify where you want the wizard to put the generated &quot;
                    &quot;skeleton code.&quot;));
     setPixmap(QWizard::LogoPixmap, QPixmap(&quot;:/images/logo3.png&quot;));

     outputDirLabel = new QLabel(tr(&quot;&amp;Output directory:&quot;));
     outputDirLineEdit = new QLineEdit;
     outputDirLabel-&gt;setBuddy(outputDirLineEdit);

     headerLabel = new QLabel(tr(&quot;&amp;Header file name:&quot;));
     headerLineEdit = new QLineEdit;
     headerLabel-&gt;setBuddy(headerLineEdit);

     implementationLabel = new QLabel(tr(&quot;&amp;Implementation file name:&quot;));
     implementationLineEdit = new QLineEdit;
     implementationLabel-&gt;setBuddy(implementationLineEdit);

     registerField(&quot;outputDir*&quot;, outputDirLineEdit);
     registerField(&quot;header*&quot;, headerLineEdit);
     registerField(&quot;implementation*&quot;, implementationLineEdit);

     QGridLayout *layout = new QGridLayout;
     layout-&gt;addWidget(outputDirLabel, 0, 0);
     layout-&gt;addWidget(outputDirLineEdit, 0, 1);
     layout-&gt;addWidget(headerLabel, 1, 0);
     layout-&gt;addWidget(headerLineEdit, 1, 1);
     layout-&gt;addWidget(implementationLabel, 2, 0);
     layout-&gt;addWidget(implementationLineEdit, 2, 1);
     setLayout(layout);
 }

 void OutputFilesPage::initializePage()
 {
     QString className = field(&quot;className&quot;).toString();
     headerLineEdit-&gt;setText(className.toLower() + &quot;.h&quot;);
     implementationLineEdit-&gt;setText(className.toLower() + &quot;.cpp&quot;);
     outputDirLineEdit-&gt;setText(QDir::convertSeparators(QDir::tempPath()));
 }

 ConclusionPage::ConclusionPage(QWidget *parent)
     : QWizardPage(parent)
 {
     setTitle(tr(&quot;Conclusion&quot;));
     setPixmap(QWizard::WatermarkPixmap, QPixmap(&quot;:/images/watermark2.png&quot;));

     label = new QLabel;
     label-&gt;setWordWrap(true);

     QVBoxLayout *layout = new QVBoxLayout;
     layout-&gt;addWidget(label);
     setLayout(layout);
 }

 void ConclusionPage::initializePage()
 {
     QString finishText = wizard()-&gt;buttonText(QWizard::FinishButton);
     finishText.remove('&amp;');
     label-&gt;setText(tr(&quot;Click %1 to generate the class skeleton.&quot;)
                    .arg(finishText));
 }</pre>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="40%" align="left">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="40%" align="right"><div align="right">Qt 4.6.3</div></td>
</tr></table></div></address></body>
</html>