summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorNico Vertriest <nico.vertriest@qt.io>2017-12-04 16:07:23 +0100
committerNico Vertriest <nico.vertriest@qt.io>2018-03-14 12:44:20 +0000
commit421cfd9492ec04f5432c81b6cad93ebe45601974 (patch)
tree7dc440cdfe58ec44e6d06a31f5e985fd4849cf43 /examples/widgets
parent00304eac7b1ddd22b971da78aa84c86fe2919359 (diff)
Doc: Complete Dynamic Layouts Example
- add doc to code - replace old signal/slot syntax - more up-to-date screenshot Task-number: QTBUG-60635 Change-Id: Iec3d2c3d0d8b9c07ccd4446d74d5eca2d88e7e08 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/doc/src/dynamiclayouts.qdoc75
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dialog.cpp54
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dialog.h8
3 files changed, 108 insertions, 29 deletions
diff --git a/examples/widgets/doc/src/dynamiclayouts.qdoc b/examples/widgets/doc/src/dynamiclayouts.qdoc
index be59aa6ab9..0b9d43c98e 100644
--- a/examples/widgets/doc/src/dynamiclayouts.qdoc
+++ b/examples/widgets/doc/src/dynamiclayouts.qdoc
@@ -34,7 +34,82 @@
applications. The widget placement depends on whether \c Horizontal or \c
Vertical is chosen.
+ \borderedimage dynamiclayouts-example.png
For more information, visit the \l{Layout Management} page.
+ \section1 Dialog Constructor
+
+ To begin with, the application creates the UI components by calling the
+ following methods:
+
+ \list
+ \li createRotatableGroupBox()
+ \li createOptionsGroupBox()
+ \li createButtonBox()
+ \endlist
+
+ It then adds the UI components to a GridLayout (\c mainLayout).
+
+ Finally, \c Dialog::rotateWidgets() is called.
+
+ \quotefromfile layouts/dynamiclayouts/dialog.cpp
+ \skipuntil createRotatableGroupBox
+ \printuntil setWindowTitle
+
+ \section1 Creating the Main Widgets
+
+ The \c createRotatableGroupBox() method creates a rotatable group box,
+ then adds a series of widgets:
+
+ \list
+ \li QSpinBox
+ \li QSlider
+ \li QDial
+ \li QProgressBar
+ \endlist
+
+ It goes on to add signals and slots to each widget, and assigns
+ a QGridLayout called \a rotatableLayout.
+
+ \skipto Dialog::createRotatableGroupBox
+ \printuntil /^\}/
+
+ \section1 Adding Options
+
+ \c createOptionsGroupBox() creates the following widgets:
+ \list
+ \li \c optionsGroupBox
+ \li \c buttonsOrientationLabel
+ \li \c buttonsOrientationComboBox. The orientation of the ComboBox is either
+ \c horizontal (default value) or \c vertical. These two values
+ are added during the startup of the application. It is not possible
+ to leave the option empty.
+ \endlist
+
+ \skipto Dialog::createOptionsGroupBox()
+ \printuntil /^\}/
+
+ \section1 Adding Buttons
+
+ createButtonBox() constructs a QDialogButtonBox called \c buttonBox
+ to which are added a \c closeButton, a \c helpButton and a
+ \c rotateWidgetsButton.
+ It then assigns a signal and a slot to each button in \c buttonBox.
+
+ \skipto Dialog::createButtonBox()
+ \printuntil /^\}/
+
+
+ \section1 Rotating the Widgets
+
+ Removes the current widgets and activates the next widget.
+
+ \quotefromfile layouts/dynamiclayouts/dialog.cpp
+ \skipto Dialog::rotateWidgets()
+ \printuntil rotatableLayout->addWidget(rotatableWidgets[i]
+ \printuntil }
+ \printuntil }
+
\include examples-run.qdocinc
*/
+
diff --git a/examples/widgets/layouts/dynamiclayouts/dialog.cpp b/examples/widgets/layouts/dynamiclayouts/dialog.cpp
index 080d69204b..f46053372a 100644
--- a/examples/widgets/layouts/dynamiclayouts/dialog.cpp
+++ b/examples/widgets/layouts/dynamiclayouts/dialog.cpp
@@ -55,12 +55,12 @@
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
- createRotableGroupBox();
+ createRotatableGroupBox();
createOptionsGroupBox();
createButtonBox();
mainLayout = new QGridLayout;
- mainLayout->addWidget(rotableGroupBox, 0, 0);
+ mainLayout->addWidget(rotatableGroupBox, 0, 0);
mainLayout->addWidget(optionsGroupBox, 1, 0);
mainLayout->addWidget(buttonBox, 2, 0);
setLayout(mainLayout);
@@ -102,17 +102,17 @@ void Dialog::buttonsOrientationChanged(int index)
void Dialog::rotateWidgets()
{
- Q_ASSERT(rotableWidgets.count() % 2 == 0);
+ Q_ASSERT(rotatableWidgets.count() % 2 == 0);
- foreach (QWidget *widget, rotableWidgets)
- rotableLayout->removeWidget(widget);
+ foreach (QWidget *widget, rotatableWidgets)
+ rotatableLayout->removeWidget(widget);
- rotableWidgets.enqueue(rotableWidgets.dequeue());
+ rotatableWidgets.enqueue(rotatableWidgets.dequeue());
- const int n = rotableWidgets.count();
+ const int n = rotatableWidgets.count();
for (int i = 0; i < n / 2; ++i) {
- rotableLayout->addWidget(rotableWidgets[n - i - 1], 0, i);
- rotableLayout->addWidget(rotableWidgets[i], 1, i);
+ rotatableLayout->addWidget(rotatableWidgets[n - i - 1], 0, i);
+ rotatableLayout->addWidget(rotatableWidgets[i], 1, i);
}
}
@@ -123,23 +123,23 @@ void Dialog::help()
"dynamically."));
}
-void Dialog::createRotableGroupBox()
+void Dialog::createRotatableGroupBox()
{
- rotableGroupBox = new QGroupBox(tr("Rotable Widgets"));
+ rotatableGroupBox = new QGroupBox(tr("Rotatable Widgets"));
- rotableWidgets.enqueue(new QSpinBox);
- rotableWidgets.enqueue(new QSlider);
- rotableWidgets.enqueue(new QDial);
- rotableWidgets.enqueue(new QProgressBar);
+ rotatableWidgets.enqueue(new QSpinBox);
+ rotatableWidgets.enqueue(new QSlider);
+ rotatableWidgets.enqueue(new QDial);
+ rotatableWidgets.enqueue(new QProgressBar);
- int n = rotableWidgets.count();
+ int n = rotatableWidgets.count();
for (int i = 0; i < n; ++i) {
- connect(rotableWidgets[i], SIGNAL(valueChanged(int)),
- rotableWidgets[(i + 1) % n], SLOT(setValue(int)));
+ connect(rotatableWidgets[i], SIGNAL(valueChanged(int)),
+ rotatableWidgets[(i + 1) % n], SLOT(setValue(int)));
}
- rotableLayout = new QGridLayout;
- rotableGroupBox->setLayout(rotableLayout);
+ rotatableLayout = new QGridLayout;
+ rotatableGroupBox->setLayout(rotatableLayout);
rotateWidgets();
}
@@ -154,8 +154,10 @@ void Dialog::createOptionsGroupBox()
buttonsOrientationComboBox->addItem(tr("Horizontal"), Qt::Horizontal);
buttonsOrientationComboBox->addItem(tr("Vertical"), Qt::Vertical);
- connect(buttonsOrientationComboBox, SIGNAL(currentIndexChanged(int)),
- this, SLOT(buttonsOrientationChanged(int)));
+ connect(buttonsOrientationComboBox,
+ QOverload<int>::of(&QComboBox::currentIndexChanged),
+ this,
+ &Dialog::buttonsOrientationChanged);
optionsLayout = new QGridLayout;
optionsLayout->addWidget(buttonsOrientationLabel, 0, 0);
@@ -173,7 +175,9 @@ void Dialog::createButtonBox()
rotateWidgetsButton = buttonBox->addButton(tr("Rotate &Widgets"),
QDialogButtonBox::ActionRole);
- connect(rotateWidgetsButton, SIGNAL(clicked()), this, SLOT(rotateWidgets()));
- connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
- connect(helpButton, SIGNAL(clicked()), this, SLOT(help()));
+ connect(rotateWidgetsButton, &QPushButton::clicked, this, &Dialog::rotateWidgets);
+ connect(closeButton, &QPushButton::clicked, this, &Dialog::close);
+ connect(helpButton, &QPushButton::clicked, this, &Dialog::help);
}
+
+
diff --git a/examples/widgets/layouts/dynamiclayouts/dialog.h b/examples/widgets/layouts/dynamiclayouts/dialog.h
index 0ff0c12b38..923a6fe01b 100644
--- a/examples/widgets/layouts/dynamiclayouts/dialog.h
+++ b/examples/widgets/layouts/dynamiclayouts/dialog.h
@@ -76,12 +76,12 @@ private slots:
void help();
private:
- void createRotableGroupBox();
+ void createRotatableGroupBox();
void createOptionsGroupBox();
void createButtonBox();
- QGroupBox *rotableGroupBox;
- QQueue<QWidget *> rotableWidgets;
+ QGroupBox *rotatableGroupBox;
+ QQueue<QWidget *> rotatableWidgets;
QGroupBox *optionsGroupBox;
QLabel *buttonsOrientationLabel;
@@ -93,7 +93,7 @@ private:
QPushButton *rotateWidgetsButton;
QGridLayout *mainLayout;
- QGridLayout *rotableLayout;
+ QGridLayout *rotatableLayout;
QGridLayout *optionsLayout;
};