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>
This commit is contained in:
Paul Wicking 2020-08-25 15:13:23 +02:00
parent 3dda54c02d
commit ed3f50507a
8 changed files with 146 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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