summaryrefslogtreecommitdiffstats
path: root/src/widgets/doc/snippets
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2020-01-04 15:32:34 +0100
committerLiang Qi <liang.qi@qt.io>2020-01-04 15:32:34 +0100
commita503bf54705d89204007e8f887b668fe5ef519fc (patch)
treeb2d1a452da39450eac78a1aeb1df116a73f64b23 /src/widgets/doc/snippets
parente65c43fd0ffa57248e7d750570b7deae171a82f5 (diff)
parent1f87fb359fdff14e42662384a9c8a0bcb3837671 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: src/corelib/tools/qvector.h Make QVector(DataPointer dd) public to be able to properly merge 5b4b437b30b320e2cd7c9a566999a39772e5d431 from 5.15 into dev. src/widgets/kernel/qapplication.cpp tests/auto/tools/moc/allmocs_baseline_in.json Done-With: Christian Ehrlicher <ch.ehrlicher@gmx.de> Change-Id: I929ba7c036d570382d0454c2c75f6f0d96ddbc01
Diffstat (limited to 'src/widgets/doc/snippets')
-rw-r--r--src/widgets/doc/snippets/code/doc_src_layout.cpp53
-rw-r--r--src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp21
-rw-r--r--src/widgets/doc/snippets/code/src_gui_itemviews_qtreewidget.cpp2
-rw-r--r--src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp7
-rw-r--r--src/widgets/doc/snippets/code/src_gui_kernel_qlayout.cpp5
-rw-r--r--src/widgets/doc/snippets/code/src_gui_kernel_qlayoutitem.cpp3
-rw-r--r--src/widgets/doc/snippets/code/src_gui_qproxystyle.cpp8
-rw-r--r--src/widgets/doc/snippets/code/src_gui_widgets_qmenubar.cpp2
-rw-r--r--src/widgets/doc/snippets/code/src_gui_widgets_qsplashscreen.cpp4
9 files changed, 53 insertions, 52 deletions
diff --git a/src/widgets/doc/snippets/code/doc_src_layout.cpp b/src/widgets/doc/snippets/code/doc_src_layout.cpp
index 5e9a740244..7bbd781bb2 100644
--- a/src/widgets/doc/snippets/code/doc_src_layout.cpp
+++ b/src/widgets/doc/snippets/code/doc_src_layout.cpp
@@ -53,14 +53,15 @@
#define CARD_H
#include <QtWidgets>
-#include <QList>
+#include <QVector>
class CardLayout : public QLayout
{
public:
- CardLayout(QWidget *parent, int dist): QLayout(parent, 0, dist) {}
- CardLayout(QLayout *parent, int dist): QLayout(parent, dist) {}
- CardLayout(int dist): QLayout(dist) {}
+ CardLayout(int spacing): QLayout()
+ { setSpacing(spacing); }
+ CardLayout(int spacing, QWidget *parent): QLayout(parent)
+ { setSpacing(spacing); }
~CardLayout();
void addItem(QLayoutItem *item) override;
@@ -72,7 +73,7 @@ public:
void setGeometry(const QRect &rect) override;
private:
- QList<QLayoutItem*> list;
+ QVector<QLayoutItem*> m_items;
};
#endif
//! [0]
@@ -85,23 +86,23 @@ private:
//! [2]
int CardLayout::count() const
{
- // QList::size() returns the number of QLayoutItems in the list
- return list.size();
+ // QVector::size() returns the number of QLayoutItems in m_items
+ return m_items.size();
}
//! [2]
//! [3]
QLayoutItem *CardLayout::itemAt(int idx) const
{
- // QList::value() performs index checking, and returns 0 if we are
+ // QVector::value() performs index checking, and returns nullptr if we are
// outside the valid range
- return list.value(idx);
+ return m_items.value(idx);
}
QLayoutItem *CardLayout::takeAt(int idx)
{
- // QList::take does not do index checking
- return idx >= 0 && idx < list.size() ? list.takeAt(idx) : 0;
+ // QVector::take does not do index checking
+ return idx >= 0 && idx < m_items.size() ? m_items.takeAt(idx) : 0;
}
//! [3]
@@ -109,7 +110,7 @@ QLayoutItem *CardLayout::takeAt(int idx)
//! [4]
void CardLayout::addItem(QLayoutItem *item)
{
- list.append(item);
+ m_items.append(item);
}
//! [4]
@@ -129,14 +130,14 @@ void CardLayout::setGeometry(const QRect &r)
{
QLayout::setGeometry(r);
- if (list.size() == 0)
+ if (m_items.size() == 0)
return;
- int w = r.width() - (list.count() - 1) * spacing();
- int h = r.height() - (list.count() - 1) * spacing();
+ int w = r.width() - (m_items.count() - 1) * spacing();
+ int h = r.height() - (m_items.count() - 1) * spacing();
int i = 0;
- while (i < list.size()) {
- QLayoutItem *o = list.at(i);
+ while (i < m_items.size()) {
+ QLayoutItem *o = m_items.at(i);
QRect geom(r.x() + i * spacing(), r.y() + i * spacing(), w, h);
o->setGeometry(geom);
++i;
@@ -148,29 +149,29 @@ void CardLayout::setGeometry(const QRect &r)
//! [7]
QSize CardLayout::sizeHint() const
{
- QSize s(0,0);
- int n = list.count();
+ QSize s(0, 0);
+ int n = m_items.count();
if (n > 0)
- s = QSize(100,70); //start with a nice default size
+ s = QSize(100, 70); //start with a nice default size
int i = 0;
while (i < n) {
- QLayoutItem *o = list.at(i);
+ QLayoutItem *o = m_items.at(i);
s = s.expandedTo(o->sizeHint());
++i;
}
- return s + n*QSize(spacing(), spacing());
+ return s + n * QSize(spacing(), spacing());
}
QSize CardLayout::minimumSize() const
{
- QSize s(0,0);
- int n = list.count();
+ QSize s(0, 0);
+ int n = m_items.count();
int i = 0;
while (i < n) {
- QLayoutItem *o = list.at(i);
+ QLayoutItem *o = m_items.at(i);
s = s.expandedTo(o->minimumSize());
++i;
}
- return s + n*QSize(spacing(), spacing());
+ return s + n * QSize(spacing(), spacing());
}
//! [7]
diff --git a/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp b/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp
index 7ccd827a04..ed6043564b 100644
--- a/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp
@@ -89,11 +89,10 @@ dialog.setNameFilter("*.cpp *.cc *.C *.cxx *.c++");
//! [7]
-QStringList filters;
-filters << "Image files (*.png *.xpm *.jpg)"
- << "Text files (*.txt)"
- << "Any files (*)";
-
+const QStringList filters({"Image files (*.png *.xpm *.jpg)",
+ "Text files (*.txt)",
+ "Any files (*)"
+ });
QFileDialog dialog(this);
dialog.setNameFilters(filters);
dialog.exec();
@@ -131,10 +130,10 @@ QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
//! [12]
//! [13]
-QStringList mimeTypeFilters;
-mimeTypeFilters << "image/jpeg" // will show "JPEG image (*.jpeg *.jpg *.jpe)
- << "image/png" // will show "PNG image (*.png)"
- << "application/octet-stream"; // will show "All files (*)"
+QStringList mimeTypeFilters({"image/jpeg", // will show "JPEG image (*.jpeg *.jpg *.jpe)
+ "image/png", // will show "PNG image (*.png)"
+ "application/octet-stream" // will show "All files (*)"
+ });
QFileDialog dialog(this);
dialog.setMimeTypeFilters(mimeTypeFilters);
@@ -146,13 +145,13 @@ dialog.exec();
//! [14]
//! [15]
-auto fileOpenCompleted = [](const QString &fileName, const QByteArray &fileContent) {
+auto fileContentReady = [](const QString &fileName, const QByteArray &fileContent) {
if (fileName.isEmpty()) {
// No file was selected
} else {
// Use fileName and fileContent
}
-}
+};
QFileDialog::getOpenFileContent("Images (*.png *.xpm *.jpg)", fileContentReady);
//! [15]
diff --git a/src/widgets/doc/snippets/code/src_gui_itemviews_qtreewidget.cpp b/src/widgets/doc/snippets/code/src_gui_itemviews_qtreewidget.cpp
index 792cc48ca7..f1e3b6ea45 100644
--- a/src/widgets/doc/snippets/code/src_gui_itemviews_qtreewidget.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_itemviews_qtreewidget.cpp
@@ -53,6 +53,6 @@ QTreeWidget *treeWidget = new QTreeWidget();
treeWidget->setColumnCount(1);
QList<QTreeWidgetItem *> items;
for (int i = 0; i < 10; ++i)
- items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i))));
+ items.append(new QTreeWidgetItem(static_cast<QTreeWidget *>(nullptr), QStringList(QString("item: %1").arg(i))));
treeWidget->insertTopLevelItems(0, items);
//! [0]
diff --git a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp
index 0a70c1d32a..5e1f0883e7 100644
--- a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp
@@ -51,9 +51,10 @@
//! [0]
QCoreApplication* createApplication(int &argc, char *argv[])
{
- for (int i = 1; i < argc; ++i)
+ for (int i = 1; i < argc; ++i) {
if (!qstrcmp(argv[i], "-no-gui"))
return new QCoreApplication(argc, argv);
+ }
return new QApplication(argc, argv);
}
@@ -187,14 +188,14 @@ for (const QString &command : commands)
//! [12]
-QWidget *widget = qApp->widgetAt(x, y);
+QWidget *widget = QApplication::widgetAt(x, y);
if (widget)
widget = widget->window();
//! [12]
//! [13]
-QWidget *widget = qApp->widgetAt(point);
+QWidget *widget = QApplication::widgetAt(point);
if (widget)
widget = widget->window();
//! [13]
diff --git a/src/widgets/doc/snippets/code/src_gui_kernel_qlayout.cpp b/src/widgets/doc/snippets/code/src_gui_kernel_qlayout.cpp
index 1a716029a9..c55834ebfb 100644
--- a/src/widgets/doc/snippets/code/src_gui_kernel_qlayout.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_kernel_qlayout.cpp
@@ -70,8 +70,9 @@ void MyWidget::paintEvent(QPaintEvent *)
//! [1]
QLayoutItem *child;
-while ((child = layout->takeAt(0)) != 0) {
+while ((child = layout->takeAt(0)) != nullptr) {
...
- delete child;
+ delete child->widget(); // delete the widget
+ delete child; // delete the layout item
}
//! [1]
diff --git a/src/widgets/doc/snippets/code/src_gui_kernel_qlayoutitem.cpp b/src/widgets/doc/snippets/code/src_gui_kernel_qlayoutitem.cpp
index d9f70b91ed..dd0f860c01 100644
--- a/src/widgets/doc/snippets/code/src_gui_kernel_qlayoutitem.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_kernel_qlayoutitem.cpp
@@ -52,8 +52,7 @@
int MyLayout::heightForWidth(int w) const
{
if (cache_dirty || cached_width != w) {
- // not all C++ compilers support "mutable"
- MyLayout *that = (MyLayout*)this;
+ MyLayout *that = const_cast<MyLayout *>(this);
int h = calculateHeightForWidth(w);
that->cached_hfw = h;
return h;
diff --git a/src/widgets/doc/snippets/code/src_gui_qproxystyle.cpp b/src/widgets/doc/snippets/code/src_gui_qproxystyle.cpp
index 3169d1c193..98dc0ff55b 100644
--- a/src/widgets/doc/snippets/code/src_gui_qproxystyle.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_qproxystyle.cpp
@@ -53,8 +53,8 @@ class MyProxyStyle : public QProxyStyle
{
public:
- int styleHint(StyleHint hint, const QStyleOption *option = 0,
- const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const override
+ int styleHint(StyleHint hint, const QStyleOption *option = nullptr,
+ const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const override
{
if (hint == QStyle::SH_UnderlineShortcut)
return 1;
@@ -72,8 +72,8 @@ public:
class MyProxyStyle : public QProxyStyle
{
public:
- int styleHint(StyleHint hint, const QStyleOption *option = 0,
- const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const override
+ int styleHint(StyleHint hint, const QStyleOption *option = nullptr,
+ const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const override
{
if (hint == QStyle::SH_UnderlineShortcut)
return 0;
diff --git a/src/widgets/doc/snippets/code/src_gui_widgets_qmenubar.cpp b/src/widgets/doc/snippets/code/src_gui_widgets_qmenubar.cpp
index b82c67b379..b52b0064ad 100644
--- a/src/widgets/doc/snippets/code/src_gui_widgets_qmenubar.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_widgets_qmenubar.cpp
@@ -54,5 +54,5 @@ menubar->addMenu(fileMenu);
//! [1]
-QMenuBar *menuBar = new QMenuBar(0);
+QMenuBar *menuBar = new QMenuBar(nullptr);
//! [1]
diff --git a/src/widgets/doc/snippets/code/src_gui_widgets_qsplashscreen.cpp b/src/widgets/doc/snippets/code/src_gui_widgets_qsplashscreen.cpp
index b9c0b1a38b..91aa8a9c4e 100644
--- a/src/widgets/doc/snippets/code/src_gui_widgets_qsplashscreen.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_widgets_qsplashscreen.cpp
@@ -56,10 +56,10 @@ splash->show();
... // Loading some items
splash->showMessage("Loaded modules");
-qApp->processEvents();
+QCoreApplication::processEvents();
... // Establishing connections
splash->showMessage("Established connections");
-qApp->processEvents();
+QCoreApplication::processEvents();
//! [0]