6.5.3 clean
@ -0,0 +1,55 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(classwizard LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/classwizard")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(classwizard
|
||||
classwizard.cpp classwizard.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(classwizard PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(classwizard PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(classwizard_resource_files
|
||||
"images/background.png"
|
||||
"images/banner.png"
|
||||
"images/logo1.png"
|
||||
"images/logo2.png"
|
||||
"images/logo3.png"
|
||||
"images/watermark1.png"
|
||||
"images/watermark2.png"
|
||||
)
|
||||
|
||||
qt_add_resources(classwizard "classwizard"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${classwizard_resource_files}
|
||||
)
|
||||
|
||||
install(TARGETS classwizard
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
@ -0,0 +1,394 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "classwizard.h"
|
||||
|
||||
//! [0] //! [1]
|
||||
ClassWizard::ClassWizard(QWidget *parent)
|
||||
: QWizard(parent)
|
||||
{
|
||||
addPage(new IntroPage);
|
||||
addPage(new ClassInfoPage);
|
||||
addPage(new CodeStylePage);
|
||||
addPage(new OutputFilesPage);
|
||||
addPage(new ConclusionPage);
|
||||
//! [0]
|
||||
|
||||
setPixmap(QWizard::BannerPixmap, QPixmap(":/images/banner.png"));
|
||||
setPixmap(QWizard::BackgroundPixmap, QPixmap(":/images/background.png"));
|
||||
|
||||
setWindowTitle(tr("Class Wizard"));
|
||||
//! [2]
|
||||
}
|
||||
//! [1] //! [2]
|
||||
|
||||
//! [3]
|
||||
void ClassWizard::accept()
|
||||
//! [3] //! [4]
|
||||
{
|
||||
QByteArray className = field("className").toByteArray();
|
||||
QByteArray baseClass = field("baseClass").toByteArray();
|
||||
QByteArray macroName = field("macroName").toByteArray();
|
||||
QByteArray baseInclude = field("baseInclude").toByteArray();
|
||||
|
||||
QString outputDir = field("outputDir").toString();
|
||||
QString header = field("header").toString();
|
||||
QString implementation = field("implementation").toString();
|
||||
//! [4]
|
||||
|
||||
QByteArray block;
|
||||
|
||||
if (field("comment").toBool()) {
|
||||
block += "/*\n";
|
||||
block += " " + header.toLatin1() + '\n';
|
||||
block += "*/\n";
|
||||
block += '\n';
|
||||
}
|
||||
if (field("protect").toBool()) {
|
||||
block += "#ifndef " + macroName + '\n';
|
||||
block += "#define " + macroName + '\n';
|
||||
block += '\n';
|
||||
}
|
||||
if (field("includeBase").toBool()) {
|
||||
block += "#include " + baseInclude + '\n';
|
||||
block += '\n';
|
||||
}
|
||||
|
||||
block += "class " + className;
|
||||
if (!baseClass.isEmpty())
|
||||
block += " : public " + baseClass;
|
||||
block += '\n';
|
||||
block += "{\n";
|
||||
|
||||
/* qmake ignore Q_OBJECT */
|
||||
|
||||
if (field("qobjectMacro").toBool()) {
|
||||
block += " Q_OBJECT\n";
|
||||
block += '\n';
|
||||
}
|
||||
block += "public:\n";
|
||||
|
||||
if (field("qobjectCtor").toBool()) {
|
||||
block += " " + className + "(QObject *parent = nullptr);\n";
|
||||
} else if (field("qwidgetCtor").toBool()) {
|
||||
block += " " + className + "(QWidget *parent = nullptr);\n";
|
||||
} else if (field("defaultCtor").toBool()) {
|
||||
block += " " + className + "();\n";
|
||||
if (field("copyCtor").toBool()) {
|
||||
block += " " + className + "(const " + className + " &other);\n";
|
||||
block += '\n';
|
||||
block += " " + className + " &operator=" + "(const " + className
|
||||
+ " &other);\n";
|
||||
}
|
||||
}
|
||||
block += "};\n";
|
||||
|
||||
if (field("protect").toBool()) {
|
||||
block += '\n';
|
||||
block += "#endif\n";
|
||||
}
|
||||
|
||||
QFile headerFile(outputDir + '/' + header);
|
||||
if (!headerFile.open(QFile::WriteOnly | QFile::Text)) {
|
||||
QMessageBox::warning(nullptr, QObject::tr("Simple Wizard"),
|
||||
QObject::tr("Cannot write file %1:\n%2")
|
||||
.arg(headerFile.fileName())
|
||||
.arg(headerFile.errorString()));
|
||||
return;
|
||||
}
|
||||
headerFile.write(block);
|
||||
|
||||
block.clear();
|
||||
|
||||
if (field("comment").toBool()) {
|
||||
block += "/*\n";
|
||||
block += " " + implementation.toLatin1() + '\n';
|
||||
block += "*/\n";
|
||||
block += '\n';
|
||||
}
|
||||
block += "#include \"" + header.toLatin1() + "\"\n";
|
||||
block += '\n';
|
||||
|
||||
if (field("qobjectCtor").toBool()) {
|
||||
block += className + "::" + className + "(QObject *parent)\n";
|
||||
block += " : " + baseClass + "(parent)\n";
|
||||
block += "{\n";
|
||||
block += "}\n";
|
||||
} else if (field("qwidgetCtor").toBool()) {
|
||||
block += className + "::" + className + "(QWidget *parent)\n";
|
||||
block += " : " + baseClass + "(parent)\n";
|
||||
block += "{\n";
|
||||
block += "}\n";
|
||||
} else if (field("defaultCtor").toBool()) {
|
||||
block += className + "::" + className + "()\n";
|
||||
block += "{\n";
|
||||
block += " // missing code\n";
|
||||
block += "}\n";
|
||||
|
||||
if (field("copyCtor").toBool()) {
|
||||
block += "\n";
|
||||
block += className + "::" + className + "(const " + className
|
||||
+ " &other)\n";
|
||||
block += "{\n";
|
||||
block += " *this = other;\n";
|
||||
block += "}\n";
|
||||
block += '\n';
|
||||
block += className + " &" + className + "::operator=(const "
|
||||
+ className + " &other)\n";
|
||||
block += "{\n";
|
||||
if (!baseClass.isEmpty())
|
||||
block += " " + baseClass + "::operator=(other);\n";
|
||||
block += " // missing code\n";
|
||||
block += " return *this;\n";
|
||||
block += "}\n";
|
||||
}
|
||||
}
|
||||
|
||||
QFile implementationFile(outputDir + '/' + implementation);
|
||||
if (!implementationFile.open(QFile::WriteOnly | QFile::Text)) {
|
||||
QMessageBox::warning(nullptr, QObject::tr("Simple Wizard"),
|
||||
QObject::tr("Cannot write file %1:\n%2")
|
||||
.arg(implementationFile.fileName())
|
||||
.arg(implementationFile.errorString()));
|
||||
return;
|
||||
}
|
||||
implementationFile.write(block);
|
||||
|
||||
//! [5]
|
||||
QDialog::accept();
|
||||
//! [5] //! [6]
|
||||
}
|
||||
//! [6]
|
||||
|
||||
//! [7]
|
||||
IntroPage::IntroPage(QWidget *parent)
|
||||
: QWizardPage(parent)
|
||||
{
|
||||
setTitle(tr("Introduction"));
|
||||
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark1.png"));
|
||||
|
||||
label = new QLabel(tr("This wizard will generate a skeleton C++ class "
|
||||
"definition, including a few functions. You simply "
|
||||
"need to specify the class name and set a few "
|
||||
"options to produce a header file and an "
|
||||
"implementation file for your new C++ class."));
|
||||
label->setWordWrap(true);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->addWidget(label);
|
||||
setLayout(layout);
|
||||
}
|
||||
//! [7]
|
||||
|
||||
//! [8] //! [9]
|
||||
ClassInfoPage::ClassInfoPage(QWidget *parent)
|
||||
: QWizardPage(parent)
|
||||
{
|
||||
//! [8]
|
||||
setTitle(tr("Class Information"));
|
||||
setSubTitle(tr("Specify basic information about the class for which you "
|
||||
"want to generate skeleton source code files."));
|
||||
setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo1.png"));
|
||||
|
||||
//! [10]
|
||||
classNameLabel = new QLabel(tr("&Class name:"));
|
||||
classNameLineEdit = new QLineEdit;
|
||||
classNameLabel->setBuddy(classNameLineEdit);
|
||||
|
||||
baseClassLabel = new QLabel(tr("B&ase class:"));
|
||||
baseClassLineEdit = new QLineEdit;
|
||||
baseClassLabel->setBuddy(baseClassLineEdit);
|
||||
|
||||
qobjectMacroCheckBox = new QCheckBox(tr("Generate Q_OBJECT ¯o"));
|
||||
|
||||
//! [10]
|
||||
groupBox = new QGroupBox(tr("C&onstructor"));
|
||||
//! [9]
|
||||
|
||||
qobjectCtorRadioButton = new QRadioButton(tr("&QObject-style constructor"));
|
||||
qwidgetCtorRadioButton = new QRadioButton(tr("Q&Widget-style constructor"));
|
||||
defaultCtorRadioButton = new QRadioButton(tr("&Default constructor"));
|
||||
copyCtorCheckBox = new QCheckBox(tr("&Generate copy constructor and "
|
||||
"operator="));
|
||||
|
||||
defaultCtorRadioButton->setChecked(true);
|
||||
|
||||
connect(defaultCtorRadioButton, &QAbstractButton::toggled,
|
||||
copyCtorCheckBox, &QWidget::setEnabled);
|
||||
|
||||
//! [11] //! [12]
|
||||
registerField("className*", classNameLineEdit);
|
||||
registerField("baseClass", baseClassLineEdit);
|
||||
registerField("qobjectMacro", qobjectMacroCheckBox);
|
||||
//! [11]
|
||||
registerField("qobjectCtor", qobjectCtorRadioButton);
|
||||
registerField("qwidgetCtor", qwidgetCtorRadioButton);
|
||||
registerField("defaultCtor", defaultCtorRadioButton);
|
||||
registerField("copyCtor", copyCtorCheckBox);
|
||||
|
||||
QVBoxLayout *groupBoxLayout = new QVBoxLayout;
|
||||
//! [12]
|
||||
groupBoxLayout->addWidget(qobjectCtorRadioButton);
|
||||
groupBoxLayout->addWidget(qwidgetCtorRadioButton);
|
||||
groupBoxLayout->addWidget(defaultCtorRadioButton);
|
||||
groupBoxLayout->addWidget(copyCtorCheckBox);
|
||||
groupBox->setLayout(groupBoxLayout);
|
||||
|
||||
QGridLayout *layout = new QGridLayout;
|
||||
layout->addWidget(classNameLabel, 0, 0);
|
||||
layout->addWidget(classNameLineEdit, 0, 1);
|
||||
layout->addWidget(baseClassLabel, 1, 0);
|
||||
layout->addWidget(baseClassLineEdit, 1, 1);
|
||||
layout->addWidget(qobjectMacroCheckBox, 2, 0, 1, 2);
|
||||
layout->addWidget(groupBox, 3, 0, 1, 2);
|
||||
setLayout(layout);
|
||||
//! [13]
|
||||
}
|
||||
//! [13]
|
||||
|
||||
//! [14]
|
||||
CodeStylePage::CodeStylePage(QWidget *parent)
|
||||
: QWizardPage(parent)
|
||||
{
|
||||
setTitle(tr("Code Style Options"));
|
||||
setSubTitle(tr("Choose the formatting of the generated code."));
|
||||
setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo2.png"));
|
||||
|
||||
commentCheckBox = new QCheckBox(tr("&Start generated files with a "
|
||||
//! [14]
|
||||
"comment"));
|
||||
commentCheckBox->setChecked(true);
|
||||
|
||||
protectCheckBox = new QCheckBox(tr("&Protect header file against multiple "
|
||||
"inclusions"));
|
||||
protectCheckBox->setChecked(true);
|
||||
|
||||
macroNameLabel = new QLabel(tr("&Macro name:"));
|
||||
macroNameLineEdit = new QLineEdit;
|
||||
macroNameLabel->setBuddy(macroNameLineEdit);
|
||||
|
||||
includeBaseCheckBox = new QCheckBox(tr("&Include base class definition"));
|
||||
baseIncludeLabel = new QLabel(tr("Base class include:"));
|
||||
baseIncludeLineEdit = new QLineEdit;
|
||||
baseIncludeLabel->setBuddy(baseIncludeLineEdit);
|
||||
|
||||
connect(protectCheckBox, &QAbstractButton::toggled,
|
||||
macroNameLabel, &QWidget::setEnabled);
|
||||
connect(protectCheckBox, &QAbstractButton::toggled,
|
||||
macroNameLineEdit, &QWidget::setEnabled);
|
||||
connect(includeBaseCheckBox, &QAbstractButton::toggled,
|
||||
baseIncludeLabel, &QWidget::setEnabled);
|
||||
connect(includeBaseCheckBox, &QAbstractButton::toggled,
|
||||
baseIncludeLineEdit, &QWidget::setEnabled);
|
||||
|
||||
registerField("comment", commentCheckBox);
|
||||
registerField("protect", protectCheckBox);
|
||||
registerField("macroName", macroNameLineEdit);
|
||||
registerField("includeBase", includeBaseCheckBox);
|
||||
registerField("baseInclude", baseIncludeLineEdit);
|
||||
|
||||
QGridLayout *layout = new QGridLayout;
|
||||
layout->setColumnMinimumWidth(0, 20);
|
||||
layout->addWidget(commentCheckBox, 0, 0, 1, 3);
|
||||
layout->addWidget(protectCheckBox, 1, 0, 1, 3);
|
||||
layout->addWidget(macroNameLabel, 2, 1);
|
||||
layout->addWidget(macroNameLineEdit, 2, 2);
|
||||
layout->addWidget(includeBaseCheckBox, 3, 0, 1, 3);
|
||||
layout->addWidget(baseIncludeLabel, 4, 1);
|
||||
layout->addWidget(baseIncludeLineEdit, 4, 2);
|
||||
//! [15]
|
||||
setLayout(layout);
|
||||
}
|
||||
//! [15]
|
||||
|
||||
//! [16]
|
||||
void CodeStylePage::initializePage()
|
||||
{
|
||||
QString className = field("className").toString();
|
||||
macroNameLineEdit->setText(className.toUpper() + "_H");
|
||||
|
||||
QString baseClass = field("baseClass").toString();
|
||||
|
||||
includeBaseCheckBox->setChecked(!baseClass.isEmpty());
|
||||
includeBaseCheckBox->setEnabled(!baseClass.isEmpty());
|
||||
baseIncludeLabel->setEnabled(!baseClass.isEmpty());
|
||||
baseIncludeLineEdit->setEnabled(!baseClass.isEmpty());
|
||||
|
||||
QRegularExpression rx("Q[A-Z].*");
|
||||
if (baseClass.isEmpty()) {
|
||||
baseIncludeLineEdit->clear();
|
||||
} else if (rx.match(baseClass).hasMatch()) {
|
||||
baseIncludeLineEdit->setText('<' + baseClass + '>');
|
||||
} else {
|
||||
baseIncludeLineEdit->setText('"' + baseClass.toLower() + ".h\"");
|
||||
}
|
||||
}
|
||||
//! [16]
|
||||
|
||||
OutputFilesPage::OutputFilesPage(QWidget *parent)
|
||||
: QWizardPage(parent)
|
||||
{
|
||||
setTitle(tr("Output Files"));
|
||||
setSubTitle(tr("Specify where you want the wizard to put the generated "
|
||||
"skeleton code."));
|
||||
setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo3.png"));
|
||||
|
||||
outputDirLabel = new QLabel(tr("&Output directory:"));
|
||||
outputDirLineEdit = new QLineEdit;
|
||||
outputDirLabel->setBuddy(outputDirLineEdit);
|
||||
|
||||
headerLabel = new QLabel(tr("&Header file name:"));
|
||||
headerLineEdit = new QLineEdit;
|
||||
headerLabel->setBuddy(headerLineEdit);
|
||||
|
||||
implementationLabel = new QLabel(tr("&Implementation file name:"));
|
||||
implementationLineEdit = new QLineEdit;
|
||||
implementationLabel->setBuddy(implementationLineEdit);
|
||||
|
||||
registerField("outputDir*", outputDirLineEdit);
|
||||
registerField("header*", headerLineEdit);
|
||||
registerField("implementation*", implementationLineEdit);
|
||||
|
||||
QGridLayout *layout = new QGridLayout;
|
||||
layout->addWidget(outputDirLabel, 0, 0);
|
||||
layout->addWidget(outputDirLineEdit, 0, 1);
|
||||
layout->addWidget(headerLabel, 1, 0);
|
||||
layout->addWidget(headerLineEdit, 1, 1);
|
||||
layout->addWidget(implementationLabel, 2, 0);
|
||||
layout->addWidget(implementationLineEdit, 2, 1);
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
//! [17]
|
||||
void OutputFilesPage::initializePage()
|
||||
{
|
||||
QString className = field("className").toString();
|
||||
headerLineEdit->setText(className.toLower() + ".h");
|
||||
implementationLineEdit->setText(className.toLower() + ".cpp");
|
||||
outputDirLineEdit->setText(QDir::toNativeSeparators(QDir::tempPath()));
|
||||
}
|
||||
//! [17]
|
||||
|
||||
ConclusionPage::ConclusionPage(QWidget *parent)
|
||||
: QWizardPage(parent)
|
||||
{
|
||||
setTitle(tr("Conclusion"));
|
||||
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark2.png"));
|
||||
|
||||
label = new QLabel;
|
||||
label->setWordWrap(true);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->addWidget(label);
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void ConclusionPage::initializePage()
|
||||
{
|
||||
QString finishText = wizard()->buttonText(QWizard::FinishButton);
|
||||
finishText.remove('&');
|
||||
label->setText(tr("Click %1 to generate the class skeleton.")
|
||||
.arg(finishText));
|
||||
}
|
119
tests/manual/examples/widgets/dialogs/classwizard/classwizard.h
Normal file
@ -0,0 +1,119 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef CLASSWIZARD_H
|
||||
#define CLASSWIZARD_H
|
||||
|
||||
#include <QWizard>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QCheckBox;
|
||||
class QGroupBox;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QRadioButton;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
//! [0]
|
||||
class ClassWizard : public QWizard
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ClassWizard(QWidget *parent = nullptr);
|
||||
|
||||
void accept() override;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
//! [1]
|
||||
class IntroPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
IntroPage(QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QLabel *label;
|
||||
};
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
class ClassInfoPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ClassInfoPage(QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QLabel *classNameLabel;
|
||||
QLabel *baseClassLabel;
|
||||
QLineEdit *classNameLineEdit;
|
||||
QLineEdit *baseClassLineEdit;
|
||||
QCheckBox *qobjectMacroCheckBox;
|
||||
QGroupBox *groupBox;
|
||||
QRadioButton *qobjectCtorRadioButton;
|
||||
QRadioButton *qwidgetCtorRadioButton;
|
||||
QRadioButton *defaultCtorRadioButton;
|
||||
QCheckBox *copyCtorCheckBox;
|
||||
};
|
||||
//! [2]
|
||||
|
||||
//! [3]
|
||||
class CodeStylePage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CodeStylePage(QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void initializePage() override;
|
||||
|
||||
private:
|
||||
QCheckBox *commentCheckBox;
|
||||
QCheckBox *protectCheckBox;
|
||||
QCheckBox *includeBaseCheckBox;
|
||||
QLabel *macroNameLabel;
|
||||
QLabel *baseIncludeLabel;
|
||||
QLineEdit *macroNameLineEdit;
|
||||
QLineEdit *baseIncludeLineEdit;
|
||||
};
|
||||
//! [3]
|
||||
|
||||
class OutputFilesPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OutputFilesPage(QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void initializePage() override;
|
||||
|
||||
private:
|
||||
QLabel *outputDirLabel;
|
||||
QLabel *headerLabel;
|
||||
QLabel *implementationLabel;
|
||||
QLineEdit *outputDirLineEdit;
|
||||
QLineEdit *headerLineEdit;
|
||||
QLineEdit *implementationLineEdit;
|
||||
};
|
||||
|
||||
class ConclusionPage : public QWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ConclusionPage(QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void initializePage() override;
|
||||
|
||||
private:
|
||||
QLabel *label;
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,10 @@
|
||||
QT += widgets
|
||||
|
||||
HEADERS = classwizard.h
|
||||
SOURCES = classwizard.cpp \
|
||||
main.cpp
|
||||
RESOURCES = classwizard.qrc
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/classwizard
|
||||
INSTALLS += target
|
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>images/background.png</file>
|
||||
<file>images/banner.png</file>
|
||||
<file>images/logo1.png</file>
|
||||
<file>images/logo2.png</file>
|
||||
<file>images/logo3.png</file>
|
||||
<file>images/watermark1.png</file>
|
||||
<file>images/watermark2.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 15 KiB |
26
tests/manual/examples/widgets/dialogs/classwizard/main.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTranslator>
|
||||
#include <QLocale>
|
||||
#include <QLibraryInfo>
|
||||
|
||||
#include "classwizard.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
#ifndef QT_NO_TRANSLATION
|
||||
QString translatorFileName = QLatin1String("qtbase_");
|
||||
translatorFileName += QLocale::system().name();
|
||||
QTranslator *translator = new QTranslator(&app);
|
||||
if (translator->load(translatorFileName, QLibraryInfo::path(QLibraryInfo::TranslationsPath)))
|
||||
app.installTranslator(translator);
|
||||
#endif
|
||||
|
||||
ClassWizard wizard;
|
||||
wizard.show();
|
||||
return app.exec();
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(extension LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/extension")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(extension
|
||||
finddialog.cpp finddialog.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(extension PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(extension PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
install(TARGETS extension
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
@ -0,0 +1,9 @@
|
||||
QT += widgets
|
||||
|
||||
HEADERS = finddialog.h
|
||||
SOURCES = finddialog.cpp \
|
||||
main.cpp
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/extension
|
||||
INSTALLS += target
|
@ -0,0 +1,77 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "finddialog.h"
|
||||
|
||||
//! [0]
|
||||
FindDialog::FindDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
label = new QLabel(tr("Find &what:"));
|
||||
lineEdit = new QLineEdit;
|
||||
label->setBuddy(lineEdit);
|
||||
|
||||
caseCheckBox = new QCheckBox(tr("Match &case"));
|
||||
fromStartCheckBox = new QCheckBox(tr("Search from &start"));
|
||||
fromStartCheckBox->setChecked(true);
|
||||
|
||||
//! [1]
|
||||
findButton = new QPushButton(tr("&Find"));
|
||||
findButton->setDefault(true);
|
||||
|
||||
moreButton = new QPushButton(tr("&More"));
|
||||
moreButton->setCheckable(true);
|
||||
//! [0]
|
||||
moreButton->setAutoDefault(false);
|
||||
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
extension = new QWidget;
|
||||
|
||||
wholeWordsCheckBox = new QCheckBox(tr("&Whole words"));
|
||||
backwardCheckBox = new QCheckBox(tr("Search &backward"));
|
||||
searchSelectionCheckBox = new QCheckBox(tr("Search se&lection"));
|
||||
//! [2]
|
||||
|
||||
//! [3]
|
||||
buttonBox = new QDialogButtonBox(Qt::Vertical);
|
||||
buttonBox->addButton(findButton, QDialogButtonBox::ActionRole);
|
||||
buttonBox->addButton(moreButton, QDialogButtonBox::ActionRole);
|
||||
|
||||
connect(moreButton, &QAbstractButton::toggled, extension, &QWidget::setVisible);
|
||||
|
||||
QVBoxLayout *extensionLayout = new QVBoxLayout;
|
||||
extensionLayout->setContentsMargins(QMargins());
|
||||
extensionLayout->addWidget(wholeWordsCheckBox);
|
||||
extensionLayout->addWidget(backwardCheckBox);
|
||||
extensionLayout->addWidget(searchSelectionCheckBox);
|
||||
extension->setLayout(extensionLayout);
|
||||
//! [3]
|
||||
|
||||
//! [4]
|
||||
QHBoxLayout *topLeftLayout = new QHBoxLayout;
|
||||
topLeftLayout->addWidget(label);
|
||||
topLeftLayout->addWidget(lineEdit);
|
||||
|
||||
QVBoxLayout *leftLayout = new QVBoxLayout;
|
||||
leftLayout->addLayout(topLeftLayout);
|
||||
leftLayout->addWidget(caseCheckBox);
|
||||
leftLayout->addWidget(fromStartCheckBox);
|
||||
|
||||
QGridLayout *mainLayout = new QGridLayout;
|
||||
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
|
||||
mainLayout->addLayout(leftLayout, 0, 0);
|
||||
mainLayout->addWidget(buttonBox, 0, 1);
|
||||
mainLayout->addWidget(extension, 1, 0, 1, 2);
|
||||
mainLayout->setRowStretch(2, 1);
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Extension"));
|
||||
//! [4] //! [5]
|
||||
extension->hide();
|
||||
}
|
||||
//! [5]
|
41
tests/manual/examples/widgets/dialogs/extension/finddialog.h
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef FINDDIALOG_H
|
||||
#define FINDDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QCheckBox;
|
||||
class QDialogButtonBox;
|
||||
class QGroupBox;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
//! [0]
|
||||
class FindDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FindDialog(QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QLabel *label;
|
||||
QLineEdit *lineEdit;
|
||||
QCheckBox *caseCheckBox;
|
||||
QCheckBox *fromStartCheckBox;
|
||||
QCheckBox *wholeWordsCheckBox;
|
||||
QCheckBox *searchSelectionCheckBox;
|
||||
QCheckBox *backwardCheckBox;
|
||||
QDialogButtonBox *buttonBox;
|
||||
QPushButton *findButton;
|
||||
QPushButton *moreButton;
|
||||
QWidget *extension;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
#endif
|
16
tests/manual/examples/widgets/dialogs/extension/main.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "finddialog.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
FindDialog dialog;
|
||||
|
||||
dialog.show();
|
||||
|
||||
return app.exec();
|
||||
}
|