summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorPaul Wicking <paul.wicking@qt.io>2020-08-25 15:13:23 +0200
committerPaul Wicking <paul.wicking@qt.io>2020-08-28 12:08:23 +0200
commited3f50507aca6c9585232db7aff8c7908a5aa42e (patch)
tree5654c3152c4e5384f6470c2f6dd13df7de708c3f /src/gui
parent3dda54c02d48c8cc6684ecda5dd1a8d5fc5a07e9 (diff)
Doc: Compile GUI kernel snippets
Fix minor issues (e.g. whitespace, missing semi-colon) in passing. Change-Id: I103a81a1a5acbfa1ece083a467d23a8544cf647a Done-with: Nico Vertriest <nico.vertriest@qt.io> Task-number: QTBUG-81486 Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/doc/snippets/code/code.pro9
-rw-r--r--src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp43
-rw-r--r--src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp16
-rw-r--r--src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp13
-rw-r--r--src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp35
-rw-r--r--src/gui/doc/snippets/code/src_gui_kernel_qguiapplication_x11.cpp12
-rw-r--r--src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp15
-rw-r--r--src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp9
8 files changed, 146 insertions, 6 deletions
diff --git a/src/gui/doc/snippets/code/code.pro b/src/gui/doc/snippets/code/code.pro
index 55726ca277..c45e844e01 100644
--- a/src/gui/doc/snippets/code/code.pro
+++ b/src/gui/doc/snippets/code/code.pro
@@ -13,4 +13,11 @@ SOURCES = \
src_gui_image_qmovie.cpp \
src_gui_image_qpixmapcache.cpp \
src_gui_image_qpixmap.cpp \
- src_gui_itemviews_qstandarditemmodel.cpp
+ src_gui_itemviews_qstandarditemmodel.cpp \
+ src_gui_kernel_qapplication.cpp \
+ src_gui_kernel_qclipboard.cpp \
+ src_gui_kernel_qevent.cpp \
+ src_gui_kernel_qguiapplication.cpp \
+ src_gui_kernel_qguiapplication_x11.cpp \
+ src_gui_kernel_qkeysequence.cpp \
+ src_gui_kernel_qshortcutmap.cpp
diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp
index 1de6eb821a..fafffc3d08 100644
--- a/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp
+++ b/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp
@@ -47,9 +47,28 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <QApplication>
+#include <QStyleFactory>
+#include <QWidget>
+
+
+namespace src_gui_kernel_qapplication {
+struct MyWidget
+{
+ QSize sizeHint() const;
+
+ int foo = 0;
+ MyWidget operator- (MyWidget& other)
+ {
+ MyWidget tmp = other;
+ return tmp;
+ };
+ int manhattanLength() { return 0; }
+};
+
//! [0]
-QCoreApplication* createApplication(int &argc, char *argv[])
+QCoreApplication *createApplication(int &argc, char *argv[])
{
for (int i = 1; i < argc; ++i)
if (!qstrcmp(argv[i], "-no-gui"))
@@ -57,7 +76,7 @@ QCoreApplication* createApplication(int &argc, char *argv[])
return new QApplication(argc, argv);
}
-int main(int argc, char* argv[])
+int main(int argc, char *argv[])
{
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
@@ -72,10 +91,13 @@ int main(int argc, char* argv[])
//! [0]
+void wrapper0() {
+
//! [1]
QApplication::setStyle(QStyleFactory::create("fusion"));
//! [1]
+} // wrapper0
//! [3]
@@ -108,21 +130,38 @@ void updateAllWidgets()
//! [5]
+void startTheDrag() {};
+void wrapper1() {
+MyWidget startPos;
+MyWidget currentPos;
+int x = 0;
+int y = 0;
+
//! [6]
if ((startPos - currentPos).manhattanLength() >=
QApplication::startDragDistance())
startTheDrag();
//! [6]
+
//! [7]
QWidget *widget = qApp->widgetAt(x, y);
if (widget)
widget = widget->window();
//! [7]
+} // wrapper1
+
+
+void wrapper2() {
+QPoint point;
//! [8]
QWidget *widget = qApp->widgetAt(point);
if (widget)
widget = widget->window();
//! [8]
+
+
+} // wrapper2
+} // src_gui_kernel_qapplication
diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp
index 8581510133..55e24c3be3 100644
--- a/src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp
+++ b/src/gui/doc/snippets/code/src_gui_kernel_qclipboard.cpp
@@ -47,11 +47,21 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <QClipboard>
+#include <QGuiApplication>
+#include <QMimeData>
+
+namespace src_gui_kernel_qclipboard {
+void wrapper() {
+QString newText;
+QString image;
+QClipboard::Mode mode = QClipboard::Mode::Clipboard;
+
//! [0]
QClipboard *clipboard = QGuiApplication::clipboard();
QString originalText = clipboard->text();
-...
+// etc.
clipboard->setText(newText);
//! [0]
@@ -61,3 +71,7 @@ QMimeData *data = new QMimeData;
data->setImageData(image);
clipboard->setMimeData(data, mode);
//! [1]
+
+
+} // wrapper
+} // src_gui_kernel_qclipboard
diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp
index 44ce54a9bb..7ae0444d06 100644
--- a/src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp
+++ b/src/gui/doc/snippets/code/src_gui_kernel_qevent.cpp
@@ -47,6 +47,16 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <QWheelEvent>
+
+namespace src_gui_kernel_qevent {
+class MyWidget //: public QWidget
+{
+ void wheelEvent(QWheelEvent *event);
+ void scrollWithPixels(QPoint point);
+ void scrollWithDegrees(QPoint point);
+};
+
//! [0]
void MyWidget::wheelEvent(QWheelEvent *event)
@@ -64,3 +74,6 @@ void MyWidget::wheelEvent(QWheelEvent *event)
event->accept();
}
//! [0]
+
+
+} // src_gui_kernel_qevent
diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp
index a399d444e1..7f901ecd8d 100644
--- a/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp
+++ b/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp
@@ -47,13 +47,30 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <QApplication>
+#include <QMessageBox>
+#include <QSessionManager>
+#include <QWidget>
+
+namespace src_gui_kernel_qguiapplication {
+struct MyMainWidget : public QWidget
+{
+ MyMainWidget(QWidget *parent);
+ void commitData(QSessionManager& manager);
+ bool saveDocument() { return true; };
+ QStringList restartCommand() { return QStringList(); };
+ QStringList discardCommand() { return QStringList(); };
+};
+MyMainWidget *mainWindow = nullptr;
+void do_something(QString command) { Q_UNUSED(command); };
+MyMainWidget mySession(nullptr);
//! [0]
int main(int argc, char *argv[])
{
QApplication::setDesktopSettingsAware(false);
QApplication app(argc, argv);
- ...
+ // ...
return app.exec();
}
//! [0]
@@ -61,7 +78,7 @@ int main(int argc, char *argv[])
//! [1]
MyMainWidget::MyMainWidget(QWidget *parent)
- :QWidget(parent)
+ : QWidget(parent)
{
QGuiApplication::setFallbackSessionManagementEnabled(false);
connect(qApp, &QGuiApplication::commitDataRequest,
@@ -97,10 +114,17 @@ void MyMainWidget::commitData(QSessionManager& manager)
//! [1]
+/* wrap snippet 2
+
//! [2]
appname -session id
//! [2]
+*/ // wrap snippet 2
+
+
+void wrapper0() {
+
//! [3]
const QStringList commands = mySession.restartCommand();
@@ -108,9 +132,16 @@ for (const QString &command : commands)
do_something(command);
//! [3]
+} // wrapper0
+
+void wrapper1() {
//! [4]
const QStringList commands = mySession.discardCommand();
for (const QString &command : mySession.discardCommand())
do_something(command);
//! [4]
+
+
+} // wrapper1
+} // src_gui_kernel_qguiapplication
diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication_x11.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication_x11.cpp
index 961ecd6cde..1030cc71e2 100644
--- a/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication_x11.cpp
+++ b/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication_x11.cpp
@@ -47,9 +47,21 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <QCursor>
+#include <QGuiApplication>
+
+namespace src_gui_kernel_qguiapplication_x11 {
+void calculateHugeMandelbrot();
+
+void wrapper() {
+
//! [0]
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
calculateHugeMandelbrot(); // lunch time...
QGuiApplication::restoreOverrideCursor();
//! [0]
+
+
+} // wrapper
+} // src_gui_kernel_qguiapplication_x11
diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp
index 2c49dd2d3d..2994bb60cf 100644
--- a/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp
+++ b/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp
@@ -47,6 +47,16 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <QKeySequence>
+#include <QMenu>
+#include <QTranslator>
+
+
+namespace src_gui_kernel_qkeysequence {
+struct Wrapper : public QWidget
+{ void wrapper(); };
+
+/* Wrap non-compilable code snippet
//! [0]
QKeySequence(QKeySequence::Print);
@@ -61,9 +71,14 @@ QKeySequence(tr("Ctrl+X, Ctrl+C"));
QKeySequence(Qt::CTRL + Qt::Key_X, Qt::CTRL + Qt::Key_C);
//! [1]
+*/ // Wrap non-compilable code snippet
+void Wrapper::wrapper() {
//! [2]
QMenu *file = new QMenu(this);
file->addAction(tr("&Open..."), this, SLOT(open()),
QKeySequence(tr("Ctrl+O", "File|Open")));
//! [2]
+
+} // Wrapper::wrapper
+} // src_gui_kernel_qkeysequence
diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp
index 8bb0726c77..06a51ef128 100644
--- a/src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp
+++ b/src/gui/doc/snippets/code/src_gui_kernel_qshortcutmap.cpp
@@ -47,7 +47,16 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <QKeySequence>
+
+namespace src_gui_kernel_qshortcutmap {
+
+void wrapper() {
+QKeySequence key;
//! [0]
key = QKeySequence();
//! [0]
+
+} // wrapper
+} // src_gui_kernel_qshortcutmap