Doc: Compile GUI util snippets

Fix minor issues (e.g. whitespace, missing semi-colon) in passing.

Change-Id: Ieec8deb8aaf4358ffc35502fae6ea7c043d34672
Done-with: Nico Vertriest <nico.vertriest@qt.io>
Task-number: QTBUG-81486
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
bb10
Paul Wicking 2020-08-28 14:43:14 +02:00
parent 323d2b57e0
commit 4074c54270
4 changed files with 66 additions and 6 deletions

View File

@ -40,4 +40,6 @@ SOURCES = \
src_gui_text_qtextcursor.cpp \
src_gui_text_qtextdocument.cpp \
src_gui_text_qtextdocumentwriter.cpp \
src_gui_text_qtextlayout.cpp
src_gui_text_qtextlayout.cpp \
src_gui_util_qdesktopservices.cpp \
src_gui_util_qvalidator.cpp

View File

@ -47,27 +47,49 @@
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QDesktopServices>
#include <QObject>
#include <QStandardPaths>
#include <QUrl>
namespace src_gui_util_qdesktopservices {
//! [0]
class MyHelpHandler : public QObject
{
Q_OBJECT
public:
...
// ...
public slots:
void showHelp(const QUrl &url);
};
QDesktopServices::setUrlHandler("help", helpInstance, "showHelp");
//! [0]
void wrapper0() {
MyHelpHandler *helpInstance = nullptr;
//! [setUrlHandler]
QDesktopServices::setUrlHandler("help", helpInstance, "showHelp");
//! [setUrlHandler]
} // wrapper
/* comment wrapper 1
//! [1]
mailto:user@foo.com?subject=Test&body=Just a test
//! [1]
*/ // comment wrapper 1
void wrapper1() {
//! [2]
QDesktopServices::openUrl(QUrl("file:///C:/Documents and Settings/All Users/Desktop", QUrl::TolerantMode));
//! [2]
}
/* comment wrapper 2
//! [3]
<key>LSApplicationQueriesSchemes</key>
@ -88,12 +110,18 @@ QDesktopServices::openUrl(QUrl("file:///C:/Documents and Settings/All Users/Desk
</array>
//! [4]
*/ // comment wrapper 2
void wrapper3() {
//! [6]
QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
"/data/organization/application"
"/data/organization/application";
//! [6]
} // wrapper3
/* comment wrapper 3
//! [7]
<key>com.apple.developer.associated-domains</key>
<array>
@ -115,3 +143,8 @@ QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
}
}
//! [8]
*/ // comment wrapper 3
} // src_gui_util_qdesktopservices

View File

@ -47,7 +47,19 @@
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QLineEdit>
#include <QValidator>
#include <QWidget>
namespace src_gui_util_qvalidator {
struct Wrapper : public QWidget {
void wrapper0();
void wrapper1();
void wrapper2();
};
void Wrapper::wrapper0() {
//! [0]
QValidator *validator = new QIntValidator(100, 999, this);
QLineEdit *edit = new QLineEdit(this);
@ -84,7 +96,11 @@ v.validate(str, pos); // returns Invalid
str = "12cm";
v.validate(str, pos); // returns Invalid
//! [1]
} // Wrapper::wrapper0
void Wrapper::wrapper1() {
QString s;
QIntValidator v(100, 900, this);
//! [2]
int pos = 0;
@ -98,6 +114,10 @@ v.validate(s, pos); // returns Intermediate
s = "50";
v.validate(s, pos); // returns Acceptable
//! [2]
} // Wrapper::wrapper1
void Wrapper::wrapper2() {
//! [5]
// regexp: optional '-' followed by between 1 and 3 digits
@ -133,7 +153,7 @@ s = "A12345Z"; v.validate(s, pos); // Returns Acceptable
s = "B12"; v.validate(s, pos); // Returns Intermediate
// match most 'readme' files
re.setPattern("read\\S?me(\.(txt|asc|1st))?");
re.setPattern("read\\S?me(\\.(txt|asc|1st))?");
re.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
v.setRegularExpression(re);
s = "readme"; v.validate(s, pos); // Returns Acceptable
@ -141,3 +161,7 @@ s = "README.1ST"; v.validate(s, pos); // Returns Acceptable
s = "read me.txt"; v.validate(s, pos); // Returns Invalid
s = "readm"; v.validate(s, pos); // Returns Intermediate
//! [6]
} // Wrapper::wrapper2
} // src_gui_util_qvalidator

View File

@ -135,6 +135,7 @@ void QOpenUrlHandlerRegistry::handlerDestroyed(QObject *handler)
inside the application:
\snippet code/src_gui_util_qdesktopservices.cpp 0
\snippet code/src_gui_util_qdesktopservices.cpp setUrlHandler
If inside the handler you decide that you can't open the requested
URL, you can just call QDesktopServices::openUrl() again with the